mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-29 11:01:15 +00:00
check in partial work.
This commit is contained in:
parent
a4e5c7224f
commit
d5cb7ebf3b
@ -8,6 +8,8 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#define STOREFORWARD_MAX_PACKETS 6000
|
||||||
|
|
||||||
StoreForwardPlugin *storeForwardPlugin;
|
StoreForwardPlugin *storeForwardPlugin;
|
||||||
StoreForwardPluginRadio *storeForwardPluginRadio;
|
StoreForwardPluginRadio *storeForwardPluginRadio;
|
||||||
|
|
||||||
@ -37,16 +39,37 @@ int32_t StoreForwardPlugin::runOnce()
|
|||||||
DEBUG_MSG("Initializing Store & Forward Plugin - Enabled\n");
|
DEBUG_MSG("Initializing Store & Forward Plugin - Enabled\n");
|
||||||
// Router
|
// Router
|
||||||
if (ESP.getPsramSize()) {
|
if (ESP.getPsramSize()) {
|
||||||
if (ESP.getFreePsram() >= 1024 * 1024) {
|
if (ESP.getFreePsram() >= 2048 * 1024) {
|
||||||
// Do the startup here
|
// Do the startup here
|
||||||
storeForwardPluginRadio = new StoreForwardPluginRadio();
|
storeForwardPluginRadio = new StoreForwardPluginRadio();
|
||||||
|
|
||||||
firstTime = 0;
|
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);
|
return (10 * 1000);
|
||||||
|
|
||||||
} else {
|
} 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");
|
DEBUG_MSG("Store & Forward Plugin - Aborting Startup.\n");
|
||||||
|
|
||||||
return (INT32_MAX);
|
return (INT32_MAX);
|
||||||
@ -101,10 +124,10 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node)
|
|||||||
|
|
||||||
DEBUG_MSG("looking for node - %u\n", node);
|
DEBUG_MSG("looking for node - %u\n", node);
|
||||||
for (int i = 0; i < 50; i++) {
|
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.
|
// First time seeing that node.
|
||||||
if (receivedRecord[i][0] == 0) {
|
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][0] = node;
|
||||||
receivedRecord[i][1] = millis();
|
receivedRecord[i][1] = millis();
|
||||||
|
|
||||||
@ -113,7 +136,7 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node)
|
|||||||
|
|
||||||
// We've seen this node before.
|
// We've seen this node before.
|
||||||
if (receivedRecord[i][0] == node) {
|
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];
|
uint32_t lastSaw = receivedRecord[i][1];
|
||||||
receivedRecord[i][1] = millis();
|
receivedRecord[i][1] = millis();
|
||||||
return lastSaw;
|
return lastSaw;
|
||||||
@ -123,6 +146,24 @@ uint32_t StoreForwardPlugin::sawNode(uint32_t node)
|
|||||||
return 0;
|
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.
|
// We saw a node.
|
||||||
void StoreForwardPlugin::sawNodeReport()
|
void StoreForwardPlugin::sawNodeReport()
|
||||||
{
|
{
|
||||||
@ -165,7 +206,6 @@ bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp)
|
|||||||
{
|
{
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
if (radioConfig.preferences.store_forward_plugin_enabled) {
|
if (radioConfig.preferences.store_forward_plugin_enabled) {
|
||||||
auto &p = mp;
|
|
||||||
|
|
||||||
if (mp.from != nodeDB.getNodeNum()) {
|
if (mp.from != nodeDB.getNodeNum()) {
|
||||||
// DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n");
|
// 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");
|
DEBUG_MSG("Packet came from - PortNum_UNKNOWN_APP\n");
|
||||||
} 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);
|
||||||
|
|
||||||
} 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");
|
||||||
} else if (mp.decoded.data.portnum == PortNum_POSITION_APP) {
|
} else if (mp.decoded.data.portnum == PortNum_POSITION_APP) {
|
||||||
@ -202,14 +245,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
struct PacketHistoryStruct {
|
||||||
|
uint32_t time;
|
||||||
|
uint32_t to;
|
||||||
|
uint8_t bytes[MAX_RHPACKETLEN];
|
||||||
|
};
|
||||||
|
|
||||||
class StoreForwardPlugin : private concurrency::OSThread
|
class StoreForwardPlugin : private concurrency::OSThread
|
||||||
{
|
{
|
||||||
bool firstTime = 1;
|
bool firstTime = 1;
|
||||||
@ -23,6 +29,7 @@ class StoreForwardPlugin : private concurrency::OSThread
|
|||||||
*/
|
*/
|
||||||
uint32_t sawNode(uint32_t);
|
uint32_t sawNode(uint32_t);
|
||||||
void sawNodeReport();
|
void sawNodeReport();
|
||||||
|
void addHistory(const MeshPacket &mp)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Nothing here
|
// Nothing here
|
||||||
|
Loading…
Reference in New Issue
Block a user