diff --git a/src/plugins/Plugins.cpp b/src/plugins/Plugins.cpp index 46f85410..69e68ea4 100644 --- a/src/plugins/Plugins.cpp +++ b/src/plugins/Plugins.cpp @@ -33,9 +33,9 @@ void setupPlugins() new ExternalNotificationPlugin(); //rangeTestPlugin = new RangeTestPlugin(); - //storeForwardPlugin = new StoreForwardPlugin(); + storeForwardPlugin = new StoreForwardPlugin(); new RangeTestPlugin(); - new StoreForwardPlugin(); + //new StoreForwardPlugin(); #endif } \ No newline at end of file diff --git a/src/plugins/StoreForwardPlugin-old.cpp b/src/plugins/StoreForwardPlugin-old.cpp deleted file mode 100644 index 3df421af..00000000 --- a/src/plugins/StoreForwardPlugin-old.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#if 0 - -#include "StoreForwardPlugin.h" -#include "MeshService.h" -#include "NodeDB.h" -#include "RTC.h" -#include "Router.h" -#include "configuration.h" -#include - -StoreForwardPlugin *storeForwardPlugin; -StoreForwardPluginRadio *storeForwardPluginRadio; - -StoreForwardPlugin::StoreForwardPlugin() : concurrency::OSThread("StoreForwardPlugin") {} - -int32_t StoreForwardPlugin::runOnce() -{ -#if 0 - -#ifndef NO_ESP32 - - /* - Uncomment the preferences below if you want to use the plugin - without having to configure it from the PythonAPI or WebUI. - */ - - radioConfig.preferences.store_forward_plugin_enabled = 0; - - if (radioConfig.preferences.store_forward_plugin_enabled) { - - if (firstTime) { - - DEBUG_MSG("Initializing Store & Forward Plugin\n"); - /* - */ - - // Router - if (radioConfig.preferences.is_router) { - if (ESP.getPsramSize()) { - if (ESP.getFreePsram() <= 1024 * 1024) { - // Do the startup here - - } 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"); - - return (INT32_MAX); - } - - // Non-Router - } else { - } - // storeForwardPluginRadio = new StoreForwardPluginRadio(); - - firstTime = 0; - - } else { - // TBD - } - - return (1000); - } else { - DEBUG_MSG("Store & Forward Plugin - Disabled\n"); - - return (INT32_MAX); - } - -#endif -#endif - return (INT32_MAX); -} - -MeshPacket *StoreForwardPluginRadio::allocReply() -{ - - auto reply = allocDataPacket(); // Allocate a packet for sending - - return reply; -} - -void StoreForwardPluginRadio::sendPayload(NodeNum dest, bool wantReplies) -{ -#if 0 - MeshPacket *p = allocReply(); - p->to = dest; - p->decoded.want_response = wantReplies; - - service.sendToMesh(p); -#endif -} - -bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) -{ - -#if 0 -#ifndef NO_ESP32 - - if (radioConfig.preferences.store_forward_plugin_enabled) { - - // auto &p = mp.decoded.data; - - 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"); - } - -#endif -#endif - - return true; // Let others look at this message also if they want -} - -#endif \ No newline at end of file diff --git a/src/plugins/StoreForwardPlugin-old.h b/src/plugins/StoreForwardPlugin-old.h deleted file mode 100644 index 29d11ea7..00000000 --- a/src/plugins/StoreForwardPlugin-old.h +++ /dev/null @@ -1,55 +0,0 @@ -#if 0 - -#pragma once - -#include "SinglePortPlugin.h" -#include "concurrency/OSThread.h" -#include "configuration.h" -#include -#include - -class StoreForwardPlugin : private concurrency::OSThread -{ - bool firstTime = 1; - - public: - StoreForwardPlugin(); - - protected: - virtual int32_t runOnce(); -}; - -extern StoreForwardPlugin *storeForwardPlugin; - -/* - * Radio interface for StoreForwardPlugin - * - */ -class StoreForwardPluginRadio : public SinglePortPlugin -{ - //uint32_t lastRxID; - - public: - StoreForwardPluginRadio() : SinglePortPlugin("StoreForwardPluginRadio", PortNum_STORE_FORWARD_APP) {} - //StoreForwardPluginRadio() : SinglePortPlugin("StoreForwardPluginRadio", PortNum_TEXT_MESSAGE_APP) {} - - /** - * Send our payload into the mesh - */ - void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); - - protected: - virtual MeshPacket *allocReply(); - - //virtual bool wantPortnum(PortNum p){return true;}; - - /** Called to handle a particular incoming message - - @return true if you've guaranteed you've handled this message and no other handlers should be considered for it - */ - virtual bool handleReceived(const MeshPacket &mp); -}; - -extern StoreForwardPluginRadio *storeForwardPluginRadio; - -#endif \ No newline at end of file diff --git a/src/plugins/StoreForwardPlugin.cpp b/src/plugins/StoreForwardPlugin.cpp index 2db4d735..087b34c1 100644 --- a/src/plugins/StoreForwardPlugin.cpp +++ b/src/plugins/StoreForwardPlugin.cpp @@ -6,10 +6,6 @@ #include "configuration.h" #include -#include - - - StoreForwardPlugin *storeForwardPlugin; StoreForwardPluginRadio *storeForwardPluginRadio; @@ -17,6 +13,7 @@ StoreForwardPlugin::StoreForwardPlugin() : concurrency::OSThread("StoreForwardPl int32_t StoreForwardPlugin::runOnce() { + #ifndef NO_ESP32 /* @@ -24,27 +21,60 @@ int32_t StoreForwardPlugin::runOnce() without having to configure it from the PythonAPI or WebUI. */ - if (0) { + radioConfig.preferences.store_forward_plugin_enabled = 1; + radioConfig.preferences.is_router = 0; + + if (radioConfig.preferences.store_forward_plugin_enabled) { if (firstTime) { + /* + */ - storeForwardPluginRadio = new StoreForwardPluginRadio(); + 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(); - firstTime = 0; + firstTime = 0; + + } 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"); + + 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 } - return (10); + return (1000); } else { - DEBUG_MSG("StoreForwardPlugin Disabled\n"); + DEBUG_MSG("Store & Forward Plugin - Disabled\n"); return (INT32_MAX); } #endif + return (INT32_MAX); } MeshPacket *StoreForwardPluginRadio::allocReply() @@ -54,6 +84,7 @@ MeshPacket *StoreForwardPluginRadio::allocReply() return reply; } + void StoreForwardPluginRadio::sendPayload(NodeNum dest, bool wantReplies) { MeshPacket *p = allocReply(); @@ -66,7 +97,18 @@ void StoreForwardPluginRadio::sendPayload(NodeNum dest, bool wantReplies) bool StoreForwardPluginRadio::handleReceived(const MeshPacket &mp) { #ifndef NO_ESP32 + if (radioConfig.preferences.store_forward_plugin_enabled) { + // auto &p = mp.decoded.data; + 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"); + } #endif diff --git a/src/plugins/StoreForwardPlugin.h b/src/plugins/StoreForwardPlugin.h index 1a27222f..be963491 100644 --- a/src/plugins/StoreForwardPlugin.h +++ b/src/plugins/StoreForwardPlugin.h @@ -19,13 +19,17 @@ class StoreForwardPlugin : private concurrency::OSThread extern StoreForwardPlugin *storeForwardPlugin; +/* + * Radio interface for StoreForwardPlugin + * + */ class StoreForwardPluginRadio : public SinglePortPlugin { - uint32_t lastRxID; + //uint32_t lastRxID; public: - - StoreForwardPluginRadio() : SinglePortPlugin("StoreForwardPluginRadio", PortNum_TEXT_MESSAGE_APP) {} + StoreForwardPluginRadio() : SinglePortPlugin("StoreForwardPluginRadio", PortNum_STORE_FORWARD_APP) {} + //StoreForwardPluginRadio() : SinglePortPlugin("StoreForwardPluginRadio", PortNum_TEXT_MESSAGE_APP) {} /** * Send our payload into the mesh @@ -35,6 +39,8 @@ class StoreForwardPluginRadio : public SinglePortPlugin protected: virtual MeshPacket *allocReply(); + virtual bool wantPortnum(PortNum p){return true;}; + /** Called to handle a particular incoming message @return true if you've guaranteed you've handled this message and no other handlers should be considered for it @@ -42,4 +48,5 @@ class StoreForwardPluginRadio : public SinglePortPlugin virtual bool handleReceived(const MeshPacket &mp); }; -extern StoreForwardPluginRadio *storeForwardPluginRadio; \ No newline at end of file +extern StoreForwardPluginRadio *storeForwardPluginRadio; +