Updating range test and storeforward.

This commit is contained in:
Jm
2021-02-16 17:42:46 -08:00
parent 2e8867eda6
commit 937955b36d
3 changed files with 67 additions and 12 deletions

View File

@@ -5,6 +5,7 @@
#include "Router.h"
#include "configuration.h"
#include <Arduino.h>
#include <map>
StoreForwardPlugin *storeForwardPlugin;
StoreForwardPluginRadio *storeForwardPluginRadio;
@@ -21,8 +22,8 @@ int32_t StoreForwardPlugin::runOnce()
without having to configure it from the PythonAPI or WebUI.
*/
radioConfig.preferences.store_forward_plugin_enabled = 0;
radioConfig.preferences.is_router = 0;
// radioConfig.preferences.store_forward_plugin_enabled = 1;
// radioConfig.preferences.is_router = 1;
if (radioConfig.preferences.store_forward_plugin_enabled) {
@@ -60,13 +61,16 @@ int32_t StoreForwardPlugin::runOnce()
DEBUG_MSG(
"Initializing Store & Forward Plugin - If you want to use this plugin, you must also turn on is_router.\n");
// Non-Router
return (30 * 1000);
}
} else {
// TBD
// What do we do if it's not our first time?
// Maybe some cleanup functions?
}
return (1000);
} else {
DEBUG_MSG("Store & Forward Plugin - Disabled\n");
@@ -77,6 +81,43 @@ int32_t StoreForwardPlugin::runOnce()
return (INT32_MAX);
}
// We saw a node.
uint32_t StoreForwardPlugin::sawNode(uint32_t node)
{
/*
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("looking for node - %i\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]);
// First time seeing that node.
if (receivedRecord[i][0] == 0) {
DEBUG_MSG("New node! Woohoo! Win!\n");
receivedRecord[i][0] = node;
receivedRecord[i][1] = millis();
return receivedRecord[i][1];
}
// We've seen this node before.
if (receivedRecord[i][0] == node) {
DEBUG_MSG("We've seen this node before\n");
uint32_t lastSaw = receivedRecord[i][1];
receivedRecord[i][1] = millis();
return lastSaw;
}
}
return 0;
}
MeshPacket *StoreForwardPluginRadio::allocReply()
{
@@ -101,9 +142,11 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp)
// auto &p = mp.decoded.data;
if (mp.from != nodeDB.getNodeNum()) {
DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n");
DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n");
printPacket("----- PACKET FROM RADIO", &mp);
DEBUG_MSG("Store & Forward Plugin -- Print End ---------- ---------- ---------- ---------- ----------\n");
// DEBUG_MSG("\n\nStore & Forward Plugin -- Print End ---------- ---------- ---------- ---------- ----------\n");
uint32_t sawTime = storeForwardPlugin->sawNode(mp.from);
DEBUG_MSG("Last Saw this node %d, %d millis ago\n", mp.from, (millis() - sawTime));
}
} else {