From 20cd756c880b35ffa0b6ba83db665865c21f14e8 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Wed, 15 Jan 2025 17:02:49 +1100 Subject: [PATCH] * Radio:: getLastSNR(), getLastRSSI() * MESH_PACKET_LOGGING --- examples/simple_secure_chat/main.cpp | 6 +++--- src/Dispatcher.cpp | 16 +++++++++++++--- src/Dispatcher.h | 3 +++ src/MeshCore.h | 4 ++-- src/helpers/RadioLibWrappers.cpp | 6 +++--- src/helpers/RadioLibWrappers.h | 4 ++-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index 5f39abf..3149006 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -41,9 +41,9 @@ #error "need to provide a 'board' object" #endif -#define FLOOD_SEND_TIMEOUT_MILLIS 6000 -#define DIRECT_TIMEOUT_BASE 1000 -#define DIRECT_TIMEOUT_FACTOR 400 // per hop millis +#define FLOOD_SEND_TIMEOUT_MILLIS 8000 +#define DIRECT_TIMEOUT_BASE 1500 +#define DIRECT_TIMEOUT_FACTOR 800 // per hop millis /* -------------------------------------------------------------------------------------- */ diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 870c4ab..02059cf 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -1,5 +1,9 @@ #include "Dispatcher.h" +#if MESH_PACKET_LOGGING + #include +#endif + namespace mesh { void Dispatcher::begin() { @@ -25,7 +29,6 @@ void Dispatcher::loop() { outbound = NULL; } else if (millisHasNowPassed(outbound_expiry)) { MESH_DEBUG_PRINTLN("Dispatcher::loop(): WARNING: outbound packed send timed out!"); - //Serial.println(" timed out"); _radio->onSendFinished(); releasePacket(outbound); // return to pool @@ -62,7 +65,6 @@ void Dispatcher::checkRecv() { return; } #endif - //Serial.print("LoRa recv: len="); Serial.println(len); pkt->header = raw[i++]; pkt->path_len = raw[i++]; @@ -83,6 +85,11 @@ void Dispatcher::checkRecv() { } } if (pkt) { + #if MESH_PACKET_LOGGING + Serial.printf("PACKET: recv, len=%d (type=%d, route=%s, payload_len=%d) SNR=%d RSSI=%d\n", + 2 + pkt->path_len + pkt->payload_len, pkt->getPayloadType(), pkt->isRouteDirect() ? "D" : "F", pkt->payload_len, + (int)_radio->getLastSNR(), (int)_radio->getLastRSSI()); + #endif DispatcherAction action = onRecvPacket(pkt); if (action == ACTION_RELEASE) { _mgr->free(pkt); @@ -126,7 +133,10 @@ void Dispatcher::checkSend() { _radio->startSendRaw(raw, len); outbound_expiry = futureMillis(max_airtime); - //Serial.print("LoRa send: len="); Serial.print(len); + #if MESH_PACKET_LOGGING + Serial.printf("PACKET: send, len=%d (type=%d, route=%s, payload_len=%d)\n", + len, outbound->getPayloadType(), outbound->isRouteDirect() ? "D" : "F", outbound->payload_len); + #endif } } } diff --git a/src/Dispatcher.h b/src/Dispatcher.h index f24ca80..ae33052 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -57,6 +57,9 @@ public: * \returns true if the radio is currently mid-receive of a packet. */ virtual bool isReceiving() { return false; } + + virtual float getLastRSSI() const { return 0; } + virtual float getLastSNR() const { return 0; } }; /** diff --git a/src/MeshCore.h b/src/MeshCore.h index 7fcb86e..b340f5a 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -21,8 +21,8 @@ #if MESH_DEBUG && ARDUINO #include - #define MESH_DEBUG_PRINT(...) Serial.printf(__VA_ARGS__) - #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf(F "\n", ##__VA_ARGS__) + #define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__) + #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__) #else #define MESH_DEBUG_PRINT(...) {} #define MESH_DEBUG_PRINTLN(...) {} diff --git a/src/helpers/RadioLibWrappers.cpp b/src/helpers/RadioLibWrappers.cpp index 0a0aac7..74d2181 100644 --- a/src/helpers/RadioLibWrappers.cpp +++ b/src/helpers/RadioLibWrappers.cpp @@ -37,7 +37,7 @@ int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { if (len > sz) { len = sz; } int err = _radio->readData(bytes, len); if (err != RADIOLIB_ERR_NONE) { - MESH_DEBUG_PRINTLN("RadioLibWrapper: error: readData()"); + MESH_DEBUG_PRINTLN("RadioLibWrapper: error: readData(%d)", err); } else { // Serial.print(" readData() -> "); Serial.println(len); } @@ -50,7 +50,7 @@ int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { if (state != STATE_RX) { int err = _radio->startReceive(); if (err != RADIOLIB_ERR_NONE) { - MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startReceive()"); + MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startReceive(%d)", err); } state = STATE_RX; } @@ -66,7 +66,7 @@ void RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) { _board->onBeforeTransmit(); int err = _radio->startTransmit((uint8_t *) bytes, len); if (err != RADIOLIB_ERR_NONE) { - MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startTransmit()"); + MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startTransmit(%d)", err); } } diff --git a/src/helpers/RadioLibWrappers.h b/src/helpers/RadioLibWrappers.h index 95c1f87..a888a93 100644 --- a/src/helpers/RadioLibWrappers.h +++ b/src/helpers/RadioLibWrappers.h @@ -21,8 +21,8 @@ public: uint32_t getPacketsRecv() const { return n_recv; } uint32_t getPacketsSent() const { return n_sent; } - virtual float getLastRSSI() const; - virtual float getLastSNR() const; + float getLastRSSI() const override; + float getLastSNR() const override; }; /**