Partial Work, stable build.

pull/712/head
Jm 2021-02-24 20:27:21 -08:00
rodzic 256ba8fa1b
commit fd6842cb5b
2 zmienionych plików z 46 dodań i 13 usunięć

Wyświetl plik

@ -8,7 +8,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <map> #include <map>
#define STOREFORWARD_MAX_PACKETS 6000 #define STOREFORWARD_MAX_PACKETS 7500
#define STOREFORWARD_SEND_HISTORY_SHORT 600 #define STOREFORWARD_SEND_HISTORY_SHORT 600
StoreForwardPlugin *storeForwardPlugin; StoreForwardPlugin *storeForwardPlugin;
@ -26,8 +26,8 @@ int32_t StoreForwardPlugin::runOnce()
without having to configure it from the PythonAPI or WebUI. without having to configure it from the PythonAPI or WebUI.
*/ */
radioConfig.preferences.store_forward_plugin_enabled = 1; // radioConfig.preferences.store_forward_plugin_enabled = 1;
radioConfig.preferences.is_router = 1; // radioConfig.preferences.is_router = 1;
if (radioConfig.preferences.store_forward_plugin_enabled) { if (radioConfig.preferences.store_forward_plugin_enabled) {
@ -79,6 +79,7 @@ int32_t StoreForwardPlugin::runOnce()
// Maybe some cleanup functions? // Maybe some cleanup functions?
this->sawNodeReport(); this->sawNodeReport();
this->historyReport();
return (10 * 1000); return (10 * 1000);
} }
@ -99,6 +100,8 @@ void StoreForwardPlugin::populatePSRAM()
https://learn.upesy.com/en/programmation/psram.html#psram-tab 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("Total heap: %d\n", ESP.getHeapSize());
DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap());
DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize()); DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize());
@ -107,6 +110,7 @@ void StoreForwardPlugin::populatePSRAM()
// PacketHistoryStruct *packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, // PacketHistoryStruct *packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS,
// sizeof(PacketHistoryStruct)); // sizeof(PacketHistoryStruct));
this->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("Total heap: %d\n", ESP.getHeapSize());
DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap()); DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap());
@ -154,7 +158,28 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node)
return 0; 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; auto &p = mp;
@ -166,10 +191,10 @@ void StoreForwardPlugin::addHistory(const MeshPacket *mp)
// destination, source, bytes // destination, source, bytes
// memcpy(p->encrypted.bytes, bytes, numbytes); // memcpy(p->encrypted.bytes, bytes, numbytes);
memcpy(this->packetHistory[0].bytes, bytes, MAX_RHPACKETLEN); memcpy(this->packetHistory[this->packetHistoryCurrent].bytes, bytes, MAX_RHPACKETLEN);
// pb_decode_from_bytes this->packetHistory[this->packetHistoryCurrent].time = millis();
this->packetHistory[this->packetHistoryCurrent].to = mp->to;
// Serialization is in Router.cpp line 180 this->packetHistoryCurrent++;
} }
// We saw a node. // 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?). 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++) { for (int i = 0; i < 50; i++) {
if (receivedRecord[i][1]) { if (receivedRecord[i][1]) {
DEBUG_MSG("... record-%u from-0x%08x 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);
@ -228,7 +253,7 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp)
} else if (mp.decoded.data.portnum == PortNum_TEXT_MESSAGE_APP) { } else if (mp.decoded.data.portnum == PortNum_TEXT_MESSAGE_APP) {
DEBUG_MSG("Packet came from - PortNum_TEXT_MESSAGE_APP\n"); 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) { } else if (mp.decoded.data.portnum == PortNum_REMOTE_HARDWARE_APP) {
DEBUG_MSG("Packet came from - PortNum_REMOTE_HARDWARE_APP\n"); DEBUG_MSG("Packet came from - PortNum_REMOTE_HARDWARE_APP\n");
@ -255,6 +280,11 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp)
} else { } else {
DEBUG_MSG("Packet came from an unknown port %u\n", mp.decoded.data.portnum); 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 { } else {

Wyświetl plik

@ -6,9 +6,11 @@
#include <Arduino.h> #include <Arduino.h>
#include <functional> #include <functional>
struct PacketHistoryStruct { struct PacketHistoryStruct {
uint32_t time; uint32_t time;
uint32_t to; uint32_t to;
bool ack;
uint8_t bytes[MAX_RHPACKETLEN]; uint8_t bytes[MAX_RHPACKETLEN];
}; };
@ -16,11 +18,10 @@ class StoreForwardPlugin : private concurrency::OSThread
{ {
bool firstTime = 1; bool firstTime = 1;
// TODO: Move this into the PSRAM
// TODO: Allow configuration of the maximum number of records.
uint32_t receivedRecord[50][2] = {{0}}; uint32_t receivedRecord[50][2] = {{0}};
PacketHistoryStruct *packetHistory; PacketHistoryStruct *packetHistory;
uint32_t packetHistoryCurrent = 0;
public: public:
StoreForwardPlugin(); StoreForwardPlugin();
@ -31,7 +32,9 @@ class StoreForwardPlugin : private concurrency::OSThread
*/ */
uint32_t sawNode(uint32_t); uint32_t sawNode(uint32_t);
void sawNodeReport(); void sawNodeReport();
void addHistory(const MeshPacket *mp); void historyAdd(const MeshPacket *mp);
void historyReport();
void historySend(uint32_t msAgo, uint32_t to);
void populatePSRAM(); void populatePSRAM();
private: private: