From 192feeaf0ea29c0482c9a3257528c77f003e3146 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 19 Dec 2021 15:11:30 -0500 Subject: [PATCH 1/3] Update broadcast address to NODENUM_BROADCAST --- src/plugins/esp32/StoreForwardPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index 39ad5014..ff28fac2 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -144,10 +144,10 @@ uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) Copy the messages that were received by the router in the last msAgo to the packetHistoryTXQueue structure. - TODO: The condition (this->packetHistory[i].to & 0xffffffff) == to) is not tested since + TODO: The condition (this->packetHistory[i].to & NODENUM_BROADCAST) == to) is not tested since I don't have an easy way to target a specific user. Will need to do this soon. */ - if ((this->packetHistory[i].to & 0xffffffff) == 0xffffffff || ((this->packetHistory[i].to & 0xffffffff) == to)) { + if ((this->packetHistory[i].to & NODENUM_BROADCAST) == NODENUM_BROADCAST || ((this->packetHistory[i].to & NODENUM_BROADCAST) == to)) { this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from; From d09754fbcf4d913c980d48527de617c4da0f7ae3 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 21 Dec 2021 19:28:47 -0500 Subject: [PATCH 2/3] Add support for secondary channels that don't have their own PSK. --- src/plugins/esp32/StoreForwardPlugin.cpp | 4 ++++ src/plugins/esp32/StoreForwardPlugin.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index ff28fac2..3c23cbce 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -148,9 +148,11 @@ uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) I don't have an easy way to target a specific user. Will need to do this soon. */ if ((this->packetHistory[i].to & NODENUM_BROADCAST) == NODENUM_BROADCAST || ((this->packetHistory[i].to & NODENUM_BROADCAST) == to)) { + this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from; + this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].channel = this->packetHistory[i].channel; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload_size = this->packetHistory[i].payload_size; memcpy(this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload, this->packetHistory[i].payload, Constants_DATA_PAYLOAD_LEN); @@ -171,6 +173,7 @@ void StoreForwardPlugin::historyAdd(const MeshPacket &mp) this->packetHistory[this->packetHistoryCurrent].time = millis(); this->packetHistory[this->packetHistoryCurrent].to = mp.to; + this->packetHistory[this->packetHistoryCurrent].channel = mp.channel; this->packetHistory[this->packetHistoryCurrent].from = mp.from; this->packetHistory[this->packetHistoryCurrent].payload_size = p.payload.size; memcpy(this->packetHistory[this->packetHistoryCurrent].payload, p.payload.bytes, Constants_DATA_PAYLOAD_LEN); @@ -191,6 +194,7 @@ void StoreForwardPlugin::sendPayload(NodeNum dest, uint32_t packetHistory_index) p->to = dest; p->from = this->packetHistoryTXQueue[packetHistory_index].from; + p->channel = this->packetHistoryTXQueue[packetHistory_index].channel; // Let's assume that if the router received the S&F request that the client is in range. // TODO: Make this configurable. diff --git a/src/plugins/esp32/StoreForwardPlugin.h b/src/plugins/esp32/StoreForwardPlugin.h index 65b4f189..dd252dba 100644 --- a/src/plugins/esp32/StoreForwardPlugin.h +++ b/src/plugins/esp32/StoreForwardPlugin.h @@ -12,6 +12,7 @@ struct PacketHistoryStruct { uint32_t time; uint32_t to; uint32_t from; + uint8_t channel; bool ack; uint8_t payload[Constants_DATA_PAYLOAD_LEN]; pb_size_t payload_size; From efdd2ad49096d232b5f8805c8ad6c61689c6aee5 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 26 Dec 2021 15:51:27 -0800 Subject: [PATCH 3/3] Apply formatting to S&F --- src/plugins/esp32/StoreForwardPlugin.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index 3c23cbce..eb15c561 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -80,8 +80,7 @@ void StoreForwardPlugin::populatePSRAM() /* Use a maximum of 2/3 the available PSRAM unless otherwise specified. Note: This needs to be done after every thing that would use PSRAM */ - uint32_t numberOfPackets = - (this->records ? this->records : (((ESP.getFreePsram() / 3) * 2) / sizeof(PacketHistoryStruct))); + uint32_t numberOfPackets = (this->records ? this->records : (((ESP.getFreePsram() / 3) * 2) / sizeof(PacketHistoryStruct))); this->packetHistory = static_cast(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct))); @@ -107,7 +106,7 @@ void StoreForwardPlugin::historyReport() void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to) { - //uint32_t packetsSent = 0; + // uint32_t packetsSent = 0; uint32_t queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to); @@ -147,7 +146,8 @@ uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) TODO: The condition (this->packetHistory[i].to & NODENUM_BROADCAST) == to) is not tested since I don't have an easy way to target a specific user. Will need to do this soon. */ - if ((this->packetHistory[i].to & NODENUM_BROADCAST) == NODENUM_BROADCAST || ((this->packetHistory[i].to & NODENUM_BROADCAST) == to)) { + if ((this->packetHistory[i].to & NODENUM_BROADCAST) == NODENUM_BROADCAST || + ((this->packetHistory[i].to & NODENUM_BROADCAST) == to)) { this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to; @@ -355,7 +355,6 @@ ProcessMessage StoreForwardPlugin::handleReceivedProtobuf(const MeshPacket &mp, DEBUG_MSG("StoreAndForward_RequestResponse_ROUTER_PONG\n"); break; - default: assert(0); // unexpected state - FIXME, make an error code and reboot } @@ -411,9 +410,8 @@ StoreForwardPlugin::StoreForwardPlugin() // Popupate PSRAM with our data structures. this->populatePSRAM(); - - //this->packetTimeMax = 2000; - //DEBUG_MSG("SF Time to Transmit maxPacketSize (%d bytes) %d ms\n", maxPacketSize, this->packetTimeMax); + // this->packetTimeMax = 2000; + // DEBUG_MSG("SF Time to Transmit maxPacketSize (%d bytes) %d ms\n", maxPacketSize, this->packetTimeMax); } else { DEBUG_MSG("Device has less than 1M of PSRAM free. Aborting startup.\n");