2021-01-31 17:12:01 +00:00
|
|
|
#include "StoreForwardPlugin.h"
|
|
|
|
#include "MeshService.h"
|
|
|
|
#include "NodeDB.h"
|
|
|
|
#include "RTC.h"
|
|
|
|
#include "Router.h"
|
|
|
|
#include "configuration.h"
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
StoreForwardPlugin *storeForwardPlugin;
|
|
|
|
StoreForwardPluginRadio *storeForwardPluginRadio;
|
2021-02-14 16:44:49 +00:00
|
|
|
|
2021-02-14 21:31:11 +00:00
|
|
|
StoreForwardPlugin::StoreForwardPlugin() : concurrency::OSThread("StoreForwardPlugin") {}
|
2021-01-31 17:12:01 +00:00
|
|
|
|
|
|
|
int32_t StoreForwardPlugin::runOnce()
|
|
|
|
{
|
2021-02-15 04:13:52 +00:00
|
|
|
|
2021-01-31 17:12:01 +00:00
|
|
|
#ifndef NO_ESP32
|
|
|
|
|
2021-02-07 07:29:18 +00:00
|
|
|
/*
|
|
|
|
Uncomment the preferences below if you want to use the plugin
|
|
|
|
without having to configure it from the PythonAPI or WebUI.
|
|
|
|
*/
|
|
|
|
|
2021-02-15 05:45:26 +00:00
|
|
|
radioConfig.preferences.store_forward_plugin_enabled = 0;
|
2021-02-15 04:13:52 +00:00
|
|
|
radioConfig.preferences.is_router = 0;
|
|
|
|
|
|
|
|
if (radioConfig.preferences.store_forward_plugin_enabled) {
|
2021-01-31 17:12:01 +00:00
|
|
|
|
|
|
|
if (firstTime) {
|
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
/*
|
|
|
|
*/
|
2021-01-31 17:12:01 +00:00
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
if (radioConfig.preferences.is_router) {
|
|
|
|
DEBUG_MSG("Initializing Store & Forward Plugin - Enabled\n");
|
|
|
|
// Router
|
|
|
|
if (ESP.getPsramSize()) {
|
|
|
|
if (ESP.getFreePsram() >= 1024 * 1024) {
|
|
|
|
// Do the startup here
|
|
|
|
storeForwardPluginRadio = new StoreForwardPluginRadio();
|
2021-01-31 17:12:01 +00:00
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
firstTime = 0;
|
2021-01-31 17:12:01 +00:00
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
} else {
|
|
|
|
DEBUG_MSG("Device has less than 1M of PSRAM free. Aborting startup.\n");
|
|
|
|
DEBUG_MSG("Store & Forward Plugin - Aborting Startup.\n");
|
|
|
|
|
|
|
|
return (INT32_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DEBUG_MSG("Device doesn't have PSRAM.\n");
|
|
|
|
DEBUG_MSG("Store & Forward Plugin - Aborting Startup.\n");
|
2021-02-14 22:01:08 +00:00
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
return (INT32_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DEBUG_MSG("Initializing Store & Forward Plugin - Enabled but is_router is not turned on.\n");
|
|
|
|
DEBUG_MSG(
|
|
|
|
"Initializing Store & Forward Plugin - If you want to use this plugin, you must also turn on is_router.\n");
|
|
|
|
// Non-Router
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// TBD
|
2021-01-31 17:12:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
return (1000);
|
2021-01-31 17:12:01 +00:00
|
|
|
} else {
|
2021-02-15 04:13:52 +00:00
|
|
|
DEBUG_MSG("Store & Forward Plugin - Disabled\n");
|
2021-01-31 17:12:01 +00:00
|
|
|
|
|
|
|
return (INT32_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2021-02-15 04:13:52 +00:00
|
|
|
return (INT32_MAX);
|
2021-01-31 17:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MeshPacket *StoreForwardPluginRadio::allocReply()
|
|
|
|
{
|
|
|
|
|
|
|
|
auto reply = allocDataPacket(); // Allocate a packet for sending
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
2021-02-15 04:13:52 +00:00
|
|
|
|
2021-01-31 17:12:01 +00:00
|
|
|
void StoreForwardPluginRadio::sendPayload(NodeNum dest, bool wantReplies)
|
|
|
|
{
|
|
|
|
MeshPacket *p = allocReply();
|
|
|
|
p->to = dest;
|
|
|
|
p->decoded.want_response = wantReplies;
|
|
|
|
|
|
|
|
service.sendToMesh(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp)
|
|
|
|
{
|
|
|
|
#ifndef NO_ESP32
|
2021-02-15 04:13:52 +00:00
|
|
|
if (radioConfig.preferences.store_forward_plugin_enabled) {
|
|
|
|
// auto &p = mp.decoded.data;
|
2021-01-31 17:12:01 +00:00
|
|
|
|
2021-02-15 04:13:52 +00:00
|
|
|
if (mp.from != nodeDB.getNodeNum()) {
|
|
|
|
DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n");
|
|
|
|
printPacket("----- PACKET FROM RADIO", &mp);
|
|
|
|
DEBUG_MSG("Store & Forward Plugin -- Print End ---------- ---------- ---------- ---------- ----------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DEBUG_MSG("Store & Forward Plugin - Disabled\n");
|
|
|
|
}
|
2021-01-31 17:12:01 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true; // Let others look at this message also if they want
|
|
|
|
}
|