From 7ffe601743db09bb964da8de4a2a8bdb967fb37f Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 20 Feb 2021 23:53:17 -0800 Subject: [PATCH 1/8] Changes to how airtime noise is gathered. --- src/mesh/RadioLibInterface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 63d7095c5..d7eaa8faa 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -114,7 +114,6 @@ ErrorCode RadioLibInterface::send(MeshPacket *p) // Count the packet toward our TX airtime utilization. // We only count it if it can be added to the TX queue. airTime->logAirtime(TX_LOG, xmitMsec); - // airTime.logAirtime(TX_LOG, xmitMsec); // We want all sending/receiving to be done by our daemon thread, We use a delay here because this packet might have been sent // in response to a packet we just received. So we want to make sure the other side has had a chance to reconfigure its radio @@ -245,13 +244,14 @@ void RadioLibInterface::handleReceiveInterrupt() size_t length = iface->getPacketLength(); xmitMsec = getPacketTime(length); - airTime->logAirtime(RX_ALL_LOG, xmitMsec); - // airTime.logAirtime(RX_ALL_LOG, xmitMsec); int state = iface->readData(radiobuf, length); if (state != ERR_NONE) { DEBUG_MSG("ignoring received packet due to error=%d\n", state); rxBad++; + + airTime->logAirtime(RX_ALL_LOG, xmitMsec); + } else { // Skip the 4 headers that are at the beginning of the rxBuf int32_t payloadLen = length - sizeof(PacketHeader); @@ -261,6 +261,7 @@ void RadioLibInterface::handleReceiveInterrupt() if (payloadLen < 0) { DEBUG_MSG("ignoring received packet too short\n"); rxBad++; + airTime->logAirtime(RX_ALL_LOG, xmitMsec); } else { const PacketHeader *h = (PacketHeader *)radiobuf; @@ -287,9 +288,8 @@ void RadioLibInterface::handleReceiveInterrupt() printPacket("Lora RX", mp); - xmitMsec = getPacketTime(mp); + //xmitMsec = getPacketTime(mp); airTime->logAirtime(RX_LOG, xmitMsec); - // airTime.logAirtime(RX_LOG, xmitMsec); deliverToReceiver(mp); } @@ -299,7 +299,7 @@ void RadioLibInterface::handleReceiveInterrupt() /** start an immediate transmit */ void RadioLibInterface::startSend(MeshPacket *txp) { - printPacket("Starting low level send", txp); + printPacket("Starting low level send", txp); if (disabled) { DEBUG_MSG("startSend is dropping tx packet because we are disabled\n"); packetPool.release(txp); From a4e5c7224fe0684371972ec0be44e9ddaac13109 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 20 Feb 2021 23:53:53 -0800 Subject: [PATCH 2/8] Add sawNodeReport to storeforwardplugin --- src/plugins/StoreForwardPlugin.cpp | 85 ++++++++++++++++++++++++++---- src/plugins/StoreForwardPlugin.h | 1 + 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/plugins/StoreForwardPlugin.cpp b/src/plugins/StoreForwardPlugin.cpp index af9bf5ecd..1396afd0f 100644 --- a/src/plugins/StoreForwardPlugin.cpp +++ b/src/plugins/StoreForwardPlugin.cpp @@ -4,6 +4,7 @@ #include "RTC.h" #include "Router.h" #include "configuration.h" +#include "mesh-pb-constants.h" #include #include @@ -22,8 +23,8 @@ int32_t StoreForwardPlugin::runOnce() without having to configure it from the PythonAPI or WebUI. */ - // radioConfig.preferences.store_forward_plugin_enabled = 1; - // radioConfig.preferences.is_router = 1; + radioConfig.preferences.store_forward_plugin_enabled = 1; + radioConfig.preferences.is_router = 1; if (radioConfig.preferences.store_forward_plugin_enabled) { @@ -42,6 +43,8 @@ int32_t StoreForwardPlugin::runOnce() firstTime = 0; + return (10 * 1000); + } else { DEBUG_MSG("Device has less than 1M of PSRAM free. Aborting startup.\n"); DEBUG_MSG("Store & Forward Plugin - Aborting Startup.\n"); @@ -69,6 +72,8 @@ int32_t StoreForwardPlugin::runOnce() // What do we do if it's not our first time? // Maybe some cleanup functions? + this->sawNodeReport(); + return (10 * 1000); } } else { @@ -94,12 +99,12 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). */ - DEBUG_MSG("looking for node - %i\n", node); + DEBUG_MSG("looking for node - %u\n", node); for (int i = 0; i < 50; i++) { - DEBUG_MSG("Iterating through the seen nodes - %d %d %d\n", i, receivedRecord[i][0], receivedRecord[i][1]); + //DEBUG_MSG("Iterating through the seen nodes - %u %u %u\n", i, receivedRecord[i][0], receivedRecord[i][1]); // First time seeing that node. if (receivedRecord[i][0] == 0) { - DEBUG_MSG("New node! Woohoo! Win!\n"); + //DEBUG_MSG("New node! Woohoo! Win!\n"); receivedRecord[i][0] = node; receivedRecord[i][1] = millis(); @@ -108,7 +113,7 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) // We've seen this node before. if (receivedRecord[i][0] == node) { - DEBUG_MSG("We've seen this node before\n"); + //DEBUG_MSG("We've seen this node before\n"); uint32_t lastSaw = receivedRecord[i][1]; receivedRecord[i][1] = millis(); return lastSaw; @@ -118,6 +123,27 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) return 0; } +// We saw a node. +void StoreForwardPlugin::sawNodeReport() +{ + + /* + TODO: Move receivedRecord into the PSRAM + + TODO: Gracefully handle the case where we run out of records. + Maybe replace the oldest record that hasn't been seen in a while and assume they won't be back. + + TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). + */ + + DEBUG_MSG("Iterating through the seen nodes ...\n"); + for (int i = 0; i < 50; i++) { + if (receivedRecord[i][1]) { + DEBUG_MSG("... record-%u node-%u secAgo-%u\n", i, receivedRecord[i][0], (millis() - receivedRecord[i][1]) / 1000); + } + } +} + MeshPacket *StoreForwardPluginRadio::allocReply() { @@ -139,14 +165,51 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) { #ifndef NO_ESP32 if (radioConfig.preferences.store_forward_plugin_enabled) { - // auto &p = mp.decoded.data; + auto &p = mp; if (mp.from != nodeDB.getNodeNum()) { - DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n"); - printPacket("----- PACKET FROM RADIO", &mp); - // DEBUG_MSG("\n\nStore & Forward Plugin -- Print End ---------- ---------- ---------- ---------- ----------\n"); + // DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n"); + printPacket("----- PACKET FROM RADIO -----", &mp); uint32_t sawTime = storeForwardPlugin->sawNode(mp.from); - DEBUG_MSG("Last Saw this node %d, %d millis ago\n", mp.from, (millis() - sawTime)); + DEBUG_MSG("We last saw this node (%u), %u sec ago\n", mp.from, (millis() - sawTime) / 1000); + + if (mp.decoded.data.portnum == PortNum_UNKNOWN_APP) { + DEBUG_MSG("Packet came from - PortNum_UNKNOWN_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_TEXT_MESSAGE_APP) { + DEBUG_MSG("Packet came from - PortNum_TEXT_MESSAGE_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_REMOTE_HARDWARE_APP) { + DEBUG_MSG("Packet came from - PortNum_REMOTE_HARDWARE_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_POSITION_APP) { + DEBUG_MSG("Packet came from - PortNum_POSITION_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_NODEINFO_APP) { + DEBUG_MSG("Packet came from - PortNum_NODEINFO_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_REPLY_APP) { + DEBUG_MSG("Packet came from - PortNum_REPLY_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_IP_TUNNEL_APP) { + DEBUG_MSG("Packet came from - PortNum_IP_TUNNEL_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_SERIAL_APP) { + DEBUG_MSG("Packet came from - PortNum_SERIAL_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_STORE_FORWARD_APP) { + DEBUG_MSG("Packet came from - PortNum_STORE_FORWARD_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_RANGE_TEST_APP) { + DEBUG_MSG("Packet came from - PortNum_RANGE_TEST_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_PRIVATE_APP) { + DEBUG_MSG("Packet came from - PortNum_PRIVATE_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_RANGE_TEST_APP) { + DEBUG_MSG("Packet came from - PortNum_RANGE_TEST_APP\n"); + } else if (mp.decoded.data.portnum == PortNum_ATAK_FORWARDER) { + DEBUG_MSG("Packet came from - PortNum_ATAK_FORWARDER\n"); + } else { + DEBUG_MSG("Packet came from an unknown port %u\n", mp.decoded.data.portnum); + } + + static uint8_t bytes[MAX_RHPACKETLEN]; + size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), SubPacket_fields, &p.decoded); + assert(numbytes <= MAX_RHPACKETLEN); + + DEBUG_MSG("MP numbytes %u\n", numbytes); + + // Serialization is in Router.cpp line 180 } } else { diff --git a/src/plugins/StoreForwardPlugin.h b/src/plugins/StoreForwardPlugin.h index e44d53704..9380d2161 100644 --- a/src/plugins/StoreForwardPlugin.h +++ b/src/plugins/StoreForwardPlugin.h @@ -22,6 +22,7 @@ class StoreForwardPlugin : private concurrency::OSThread @return 0 if we have never seen that node before otherwise return the last time we saw the node. */ uint32_t sawNode(uint32_t); + void sawNodeReport(); private: // Nothing here From d5cb7ebf3bf0aec104cc78107dfbc8e89ded9d57 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 21 Feb 2021 20:15:31 -0800 Subject: [PATCH 3/8] check in partial work. --- src/plugins/StoreForwardPlugin.cpp | 63 +++++++++++++++++++++++------- src/plugins/StoreForwardPlugin.h | 9 ++++- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/plugins/StoreForwardPlugin.cpp b/src/plugins/StoreForwardPlugin.cpp index 1396afd0f..213189cd0 100644 --- a/src/plugins/StoreForwardPlugin.cpp +++ b/src/plugins/StoreForwardPlugin.cpp @@ -8,6 +8,8 @@ #include #include +#define STOREFORWARD_MAX_PACKETS 6000 + StoreForwardPlugin *storeForwardPlugin; StoreForwardPluginRadio *storeForwardPluginRadio; @@ -37,16 +39,37 @@ int32_t StoreForwardPlugin::runOnce() DEBUG_MSG("Initializing Store & Forward Plugin - Enabled\n"); // Router if (ESP.getPsramSize()) { - if (ESP.getFreePsram() >= 1024 * 1024) { + if (ESP.getFreePsram() >= 2048 * 1024) { // Do the startup here storeForwardPluginRadio = new StoreForwardPluginRadio(); firstTime = 0; + /* + For PSRAM usage, see: + https://learn.upesy.com/en/programmation/psram.html#psram-tab + */ + + DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); + DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); + DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); + DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram()); + + PacketHistoryStruct *packetHistory = + (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, sizeof(PacketHistoryStruct)); + + DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); + DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); + DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); + DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram()); + + DEBUG_MSG("packetHistory Size - %u", sizeof(packetHistory)); + + // packetHistory[0].bytes; return (10 * 1000); } else { - DEBUG_MSG("Device has less than 1M of PSRAM free. Aborting startup.\n"); + DEBUG_MSG("Device has less than 2M of PSRAM free. Aborting startup.\n"); DEBUG_MSG("Store & Forward Plugin - Aborting Startup.\n"); return (INT32_MAX); @@ -101,10 +124,10 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) DEBUG_MSG("looking for node - %u\n", node); for (int i = 0; i < 50; i++) { - //DEBUG_MSG("Iterating through the seen nodes - %u %u %u\n", i, receivedRecord[i][0], receivedRecord[i][1]); + // DEBUG_MSG("Iterating through the seen nodes - %u %u %u\n", i, receivedRecord[i][0], receivedRecord[i][1]); // First time seeing that node. if (receivedRecord[i][0] == 0) { - //DEBUG_MSG("New node! Woohoo! Win!\n"); + // DEBUG_MSG("New node! Woohoo! Win!\n"); receivedRecord[i][0] = node; receivedRecord[i][1] = millis(); @@ -113,7 +136,7 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) // We've seen this node before. if (receivedRecord[i][0] == node) { - //DEBUG_MSG("We've seen this node before\n"); + // DEBUG_MSG("We've seen this node before\n"); uint32_t lastSaw = receivedRecord[i][1]; receivedRecord[i][1] = millis(); return lastSaw; @@ -123,6 +146,24 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) return 0; } +void StoreForwardPlugin::addHistory(const MeshPacket &mp) +{ + auto &p = mp; + + static uint8_t bytes[MAX_RHPACKETLEN]; + size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), SubPacket_fields, &p.decoded); + assert(numbytes <= MAX_RHPACKETLEN); + + DEBUG_MSG("MP numbytes %u\n", numbytes); + + // destination, source, bytes + // memcpy(p->encrypted.bytes, bytes, numbytes); + + // pb_decode_from_bytes + + // Serialization is in Router.cpp line 180 +} + // We saw a node. void StoreForwardPlugin::sawNodeReport() { @@ -165,7 +206,6 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) { #ifndef NO_ESP32 if (radioConfig.preferences.store_forward_plugin_enabled) { - auto &p = mp; if (mp.from != nodeDB.getNodeNum()) { // DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n"); @@ -177,6 +217,9 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) DEBUG_MSG("Packet came from - PortNum_UNKNOWN_APP\n"); } else if (mp.decoded.data.portnum == PortNum_TEXT_MESSAGE_APP) { DEBUG_MSG("Packet came from - PortNum_TEXT_MESSAGE_APP\n"); + + storeForwardPlugin->addHistory(&mp); + } else if (mp.decoded.data.portnum == PortNum_REMOTE_HARDWARE_APP) { DEBUG_MSG("Packet came from - PortNum_REMOTE_HARDWARE_APP\n"); } else if (mp.decoded.data.portnum == PortNum_POSITION_APP) { @@ -202,14 +245,6 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) } else { DEBUG_MSG("Packet came from an unknown port %u\n", mp.decoded.data.portnum); } - - static uint8_t bytes[MAX_RHPACKETLEN]; - size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), SubPacket_fields, &p.decoded); - assert(numbytes <= MAX_RHPACKETLEN); - - DEBUG_MSG("MP numbytes %u\n", numbytes); - - // Serialization is in Router.cpp line 180 } } else { diff --git a/src/plugins/StoreForwardPlugin.h b/src/plugins/StoreForwardPlugin.h index 9380d2161..d7888333e 100644 --- a/src/plugins/StoreForwardPlugin.h +++ b/src/plugins/StoreForwardPlugin.h @@ -6,6 +6,12 @@ #include #include +struct PacketHistoryStruct { + uint32_t time; + uint32_t to; + uint8_t bytes[MAX_RHPACKETLEN]; +}; + class StoreForwardPlugin : private concurrency::OSThread { bool firstTime = 1; @@ -23,9 +29,10 @@ class StoreForwardPlugin : private concurrency::OSThread */ uint32_t sawNode(uint32_t); void sawNodeReport(); + void addHistory(const MeshPacket &mp) private: - // Nothing here + // Nothing here protected: virtual int32_t runOnce(); From 256ba8fa1bb76d8e74d09c011ea76d4fdf5cbd9f Mon Sep 17 00:00:00 2001 From: Jm Date: Mon, 22 Feb 2021 20:07:19 -0800 Subject: [PATCH 4/8] partial work, untested --- src/plugins/StoreForwardPlugin.cpp | 66 +++++++++++++++++------------- src/plugins/StoreForwardPlugin.h | 5 ++- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/plugins/StoreForwardPlugin.cpp b/src/plugins/StoreForwardPlugin.cpp index 213189cd0..ea24313b8 100644 --- a/src/plugins/StoreForwardPlugin.cpp +++ b/src/plugins/StoreForwardPlugin.cpp @@ -9,6 +9,7 @@ #include #define STOREFORWARD_MAX_PACKETS 6000 +#define STOREFORWARD_SEND_HISTORY_SHORT 600 StoreForwardPlugin *storeForwardPlugin; StoreForwardPluginRadio *storeForwardPluginRadio; @@ -45,25 +46,7 @@ int32_t StoreForwardPlugin::runOnce() firstTime = 0; - /* - For PSRAM usage, see: - https://learn.upesy.com/en/programmation/psram.html#psram-tab - */ - - DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); - DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); - DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); - DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram()); - - PacketHistoryStruct *packetHistory = - (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, sizeof(PacketHistoryStruct)); - - DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); - DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); - DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); - DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram()); - - DEBUG_MSG("packetHistory Size - %u", sizeof(packetHistory)); + this->populatePSRAM(); // packetHistory[0].bytes; return (10 * 1000); @@ -109,6 +92,30 @@ int32_t StoreForwardPlugin::runOnce() return (INT32_MAX); } +void StoreForwardPlugin::populatePSRAM() +{ + /* + For PSRAM usage, see: + https://learn.upesy.com/en/programmation/psram.html#psram-tab + */ + + DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); + DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); + DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); + DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram()); + + // PacketHistoryStruct *packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, + // sizeof(PacketHistoryStruct)); + this->packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, sizeof(PacketHistoryStruct)); + + DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); + DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); + DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); + DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram()); + + DEBUG_MSG("packetHistory Size - %u", sizeof(packetHistory)); +} + // We saw a node. uint32_t StoreForwardPlugin::sawNode(uint32_t node) { @@ -121,8 +128,9 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). */ - - DEBUG_MSG("looking for node - %u\n", node); + // DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d", prefix, p->id, p->from & 0xff, p->to & 0xff, + // p->want_ack, p->hop_limit); + DEBUG_MSG("looking for node - from-0x%08x\n", node); for (int i = 0; i < 50; i++) { // DEBUG_MSG("Iterating through the seen nodes - %u %u %u\n", i, receivedRecord[i][0], receivedRecord[i][1]); // First time seeing that node. @@ -146,19 +154,19 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) return 0; } -void StoreForwardPlugin::addHistory(const MeshPacket &mp) +void StoreForwardPlugin::addHistory(const MeshPacket *mp) { auto &p = mp; static uint8_t bytes[MAX_RHPACKETLEN]; - size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), SubPacket_fields, &p.decoded); + size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), SubPacket_fields, &p->decoded); assert(numbytes <= MAX_RHPACKETLEN); DEBUG_MSG("MP numbytes %u\n", numbytes); // destination, source, bytes // memcpy(p->encrypted.bytes, bytes, numbytes); - + memcpy(this->packetHistory[0].bytes, bytes, MAX_RHPACKETLEN); // pb_decode_from_bytes // Serialization is in Router.cpp line 180 @@ -177,10 +185,10 @@ void StoreForwardPlugin::sawNodeReport() TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). */ - DEBUG_MSG("Iterating through the seen nodes ...\n"); + DEBUG_MSG("Iterating through the seen nodes in receivedRecord\n"); for (int i = 0; i < 50; i++) { if (receivedRecord[i][1]) { - DEBUG_MSG("... record-%u node-%u secAgo-%u\n", i, receivedRecord[i][0], (millis() - receivedRecord[i][1]) / 1000); + DEBUG_MSG("... record-%u from-0x%08x secAgo-%u\n", i, receivedRecord[i][0], (millis() - receivedRecord[i][1]) / 1000); } } } @@ -209,9 +217,11 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) if (mp.from != nodeDB.getNodeNum()) { // DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n"); + // DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d", prefix, p->id, p->from & 0xff, p->to & 0xff, + // p->want_ack, p->hop_limit); printPacket("----- PACKET FROM RADIO -----", &mp); - uint32_t sawTime = storeForwardPlugin->sawNode(mp.from); - DEBUG_MSG("We last saw this node (%u), %u sec ago\n", mp.from, (millis() - sawTime) / 1000); + uint32_t sawTime = storeForwardPlugin->sawNode(mp.from & 0xffffffff); + DEBUG_MSG("We last saw this node (%u), %u sec ago\n", mp.from & 0xffffffff, (millis() - sawTime) / 1000); if (mp.decoded.data.portnum == PortNum_UNKNOWN_APP) { DEBUG_MSG("Packet came from - PortNum_UNKNOWN_APP\n"); diff --git a/src/plugins/StoreForwardPlugin.h b/src/plugins/StoreForwardPlugin.h index d7888333e..2b7da6fb9 100644 --- a/src/plugins/StoreForwardPlugin.h +++ b/src/plugins/StoreForwardPlugin.h @@ -20,6 +20,8 @@ class StoreForwardPlugin : private concurrency::OSThread // TODO: Allow configuration of the maximum number of records. uint32_t receivedRecord[50][2] = {{0}}; + PacketHistoryStruct *packetHistory; + public: StoreForwardPlugin(); @@ -29,7 +31,8 @@ class StoreForwardPlugin : private concurrency::OSThread */ uint32_t sawNode(uint32_t); void sawNodeReport(); - void addHistory(const MeshPacket &mp) + void addHistory(const MeshPacket *mp); + void populatePSRAM(); private: // Nothing here From fd6842cb5b0dc93771107ac058205b38a2c2e2c7 Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 24 Feb 2021 20:27:21 -0800 Subject: [PATCH 5/8] Partial Work, stable build. --- src/plugins/StoreForwardPlugin.cpp | 50 ++++++++++++++++++++++++------ src/plugins/StoreForwardPlugin.h | 9 ++++-- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/plugins/StoreForwardPlugin.cpp b/src/plugins/StoreForwardPlugin.cpp index ea24313b8..0550b7af0 100644 --- a/src/plugins/StoreForwardPlugin.cpp +++ b/src/plugins/StoreForwardPlugin.cpp @@ -8,7 +8,7 @@ #include #include -#define STOREFORWARD_MAX_PACKETS 6000 +#define STOREFORWARD_MAX_PACKETS 7500 #define STOREFORWARD_SEND_HISTORY_SHORT 600 StoreForwardPlugin *storeForwardPlugin; @@ -26,8 +26,8 @@ int32_t StoreForwardPlugin::runOnce() without having to configure it from the PythonAPI or WebUI. */ - radioConfig.preferences.store_forward_plugin_enabled = 1; - radioConfig.preferences.is_router = 1; + // radioConfig.preferences.store_forward_plugin_enabled = 1; + // radioConfig.preferences.is_router = 1; if (radioConfig.preferences.store_forward_plugin_enabled) { @@ -79,6 +79,7 @@ int32_t StoreForwardPlugin::runOnce() // Maybe some cleanup functions? this->sawNodeReport(); + this->historyReport(); return (10 * 1000); } @@ -99,6 +100,8 @@ void StoreForwardPlugin::populatePSRAM() https://learn.upesy.com/en/programmation/psram.html#psram-tab */ + DEBUG_MSG("Before PSRAM initilization\n"); + DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); @@ -107,6 +110,7 @@ void StoreForwardPlugin::populatePSRAM() // PacketHistoryStruct *packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, // sizeof(PacketHistoryStruct)); this->packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, sizeof(PacketHistoryStruct)); + DEBUG_MSG("After PSRAM initilization\n"); DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize()); DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); @@ -154,7 +158,28 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node) return 0; } -void StoreForwardPlugin::addHistory(const MeshPacket *mp) +void StoreForwardPlugin::historyReport() +{ + DEBUG_MSG("Iterating through the message history...\n"); + DEBUG_MSG("Message history contains %u records\n", this->packetHistoryCurrent); + uint32_t startTimer = millis(); + for (int i = 0; i < this->packetHistoryCurrent; i++) { + if (this->packetHistory[i].time) { + // DEBUG_MSG("... time-%u to-0x%08x\n", this->packetHistory[i].time, this->packetHistory[i].to & 0xffffffff); + } + } + DEBUG_MSG("StoreForwardPlugin::historyReport runtime - %u ms\n", millis() - startTimer); +} +void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to) +{ + for (int i = 0; i < this->packetHistoryCurrent; i++) { + if (this->packetHistory[i].time) { + // DEBUG_MSG("... time-%u to-0x%08x\n", this->packetHistory[i].time, this->packetHistory[i].to & 0xffffffff); + } + } +} + +void StoreForwardPlugin::historyAdd(const MeshPacket *mp) { auto &p = mp; @@ -166,10 +191,10 @@ void StoreForwardPlugin::addHistory(const MeshPacket *mp) // destination, source, bytes // memcpy(p->encrypted.bytes, bytes, numbytes); - memcpy(this->packetHistory[0].bytes, bytes, MAX_RHPACKETLEN); - // pb_decode_from_bytes - - // Serialization is in Router.cpp line 180 + memcpy(this->packetHistory[this->packetHistoryCurrent].bytes, bytes, MAX_RHPACKETLEN); + this->packetHistory[this->packetHistoryCurrent].time = millis(); + this->packetHistory[this->packetHistoryCurrent].to = mp->to; + this->packetHistoryCurrent++; } // We saw a node. @@ -185,7 +210,7 @@ void StoreForwardPlugin::sawNodeReport() TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). */ - DEBUG_MSG("Iterating through the seen nodes in receivedRecord\n"); + DEBUG_MSG("Iterating through the seen nodes in receivedRecord...\n"); for (int i = 0; i < 50; i++) { if (receivedRecord[i][1]) { DEBUG_MSG("... record-%u from-0x%08x secAgo-%u\n", i, receivedRecord[i][0], (millis() - receivedRecord[i][1]) / 1000); @@ -228,7 +253,7 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) } else if (mp.decoded.data.portnum == PortNum_TEXT_MESSAGE_APP) { DEBUG_MSG("Packet came from - PortNum_TEXT_MESSAGE_APP\n"); - storeForwardPlugin->addHistory(&mp); + storeForwardPlugin->historyAdd(&mp); } else if (mp.decoded.data.portnum == PortNum_REMOTE_HARDWARE_APP) { DEBUG_MSG("Packet came from - PortNum_REMOTE_HARDWARE_APP\n"); @@ -255,6 +280,11 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) } else { DEBUG_MSG("Packet came from an unknown port %u\n", mp.decoded.data.portnum); } + + if ((millis() - sawTime) > STOREFORWARD_SEND_HISTORY_SHORT) { + // Node has been away for a while. + storeForwardPlugin->historySend(sawTime, mp.from); + } } } else { diff --git a/src/plugins/StoreForwardPlugin.h b/src/plugins/StoreForwardPlugin.h index 2b7da6fb9..e49b38fe9 100644 --- a/src/plugins/StoreForwardPlugin.h +++ b/src/plugins/StoreForwardPlugin.h @@ -6,9 +6,11 @@ #include #include + struct PacketHistoryStruct { uint32_t time; uint32_t to; + bool ack; uint8_t bytes[MAX_RHPACKETLEN]; }; @@ -16,11 +18,10 @@ class StoreForwardPlugin : private concurrency::OSThread { bool firstTime = 1; - // TODO: Move this into the PSRAM - // TODO: Allow configuration of the maximum number of records. uint32_t receivedRecord[50][2] = {{0}}; PacketHistoryStruct *packetHistory; + uint32_t packetHistoryCurrent = 0; public: StoreForwardPlugin(); @@ -31,7 +32,9 @@ class StoreForwardPlugin : private concurrency::OSThread */ uint32_t sawNode(uint32_t); void sawNodeReport(); - void addHistory(const MeshPacket *mp); + void historyAdd(const MeshPacket *mp); + void historyReport(); + void historySend(uint32_t msAgo, uint32_t to); void populatePSRAM(); private: From 30d600040b265f97f907187a1fe12aa56c563e6f Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Thu, 25 Feb 2021 08:12:30 -0800 Subject: [PATCH 6/8] Rename src/plugins/StoreForwardPlugin.cpp to src/plugins/esp32/StoreForwardPlugin.cpp --- src/plugins/{ => esp32}/StoreForwardPlugin.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{ => esp32}/StoreForwardPlugin.cpp (100%) diff --git a/src/plugins/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp similarity index 100% rename from src/plugins/StoreForwardPlugin.cpp rename to src/plugins/esp32/StoreForwardPlugin.cpp From 14271be81684fc02e6f42871adee612870bd393b Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Thu, 25 Feb 2021 08:12:57 -0800 Subject: [PATCH 7/8] Rename src/plugins/StoreForwardPlugin.h to src/plugins/esp32/StoreForwardPlugin.h --- src/plugins/{ => esp32}/StoreForwardPlugin.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{ => esp32}/StoreForwardPlugin.h (100%) diff --git a/src/plugins/StoreForwardPlugin.h b/src/plugins/esp32/StoreForwardPlugin.h similarity index 100% rename from src/plugins/StoreForwardPlugin.h rename to src/plugins/esp32/StoreForwardPlugin.h From 5f041ea7e93686e39e683c5c135f8adcc0ac3c32 Mon Sep 17 00:00:00 2001 From: Jm Date: Thu, 25 Feb 2021 08:14:07 -0800 Subject: [PATCH 8/8] Update Plugins.cpp --- src/plugins/Plugins.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/Plugins.cpp b/src/plugins/Plugins.cpp index cfcc21d54..39073ac2d 100644 --- a/src/plugins/Plugins.cpp +++ b/src/plugins/Plugins.cpp @@ -6,10 +6,10 @@ #include "plugins/TextMessagePlugin.h" #ifndef NO_ESP32 +#include "plugins/SerialPlugin.h" #include "plugins/esp32/EnvironmentalMeasurementPlugin.h" #include "plugins/esp32/RangeTestPlugin.h" -#include "plugins/SerialPlugin.h" -#include "plugins/StoreForwardPlugin.h" +#include "plugins/esp32/StoreForwardPlugin.h" #endif /**