From e8c6fccd633f801045a417054115025a4be1fb0d Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 31 Jan 2021 09:12:36 -0800 Subject: [PATCH] #671 Range Test Plugin Initial work for Range Test Plugin --- src/plugins/Plugins.cpp | 11 +++- src/plugins/RangeTestPlugin.cpp | 103 ++++++++++++++++++++++++++++++++ src/plugins/RangeTestPlugin.h | 49 +++++++++++++++ 3 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 src/plugins/RangeTestPlugin.cpp create mode 100644 src/plugins/RangeTestPlugin.h diff --git a/src/plugins/Plugins.cpp b/src/plugins/Plugins.cpp index 90a1b554..93487ac7 100644 --- a/src/plugins/Plugins.cpp +++ b/src/plugins/Plugins.cpp @@ -1,9 +1,11 @@ #include "plugins/ExternalNotificationPlugin.h" #include "plugins/NodeInfoPlugin.h" #include "plugins/PositionPlugin.h" +#include "plugins/RangeTestPlugin.h" #include "plugins/RemoteHardwarePlugin.h" #include "plugins/ReplyPlugin.h" #include "plugins/SerialPlugin.h" +#include "plugins/StoreForwardPlugin.h" #include "plugins/TextMessagePlugin.h" /** @@ -24,7 +26,12 @@ void setupPlugins() #ifndef NO_ESP32 // Only run on an esp32 based device. - new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org - new ExternalNotificationPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org + /* + Maintained by MC Hamster (Jm Casler) jm@casler.org + */ + new SerialPlugin(); + new ExternalNotificationPlugin(); + new StoreForwardPlugin(); + new RangeTestPlugin(); #endif } \ No newline at end of file diff --git a/src/plugins/RangeTestPlugin.cpp b/src/plugins/RangeTestPlugin.cpp new file mode 100644 index 00000000..1b8f80f3 --- /dev/null +++ b/src/plugins/RangeTestPlugin.cpp @@ -0,0 +1,103 @@ +#include "RangeTestPlugin.h" +#include "MeshService.h" +#include "NodeDB.h" +#include "RTC.h" +#include "Router.h" +#include "configuration.h" +#include + +#include + +#define RANGETESTPLUGIN_ENABLED 1 +#define RANGETESTPLUGIN_SENDER 0 + +RangeTestPlugin *rangeTestPlugin; +RangeTestPluginRadio *rangeTestPluginRadio; + +RangeTestPlugin::RangeTestPlugin() : concurrency::OSThread("RangeTestPlugin") {} + +// char serialStringChar[Constants_DATA_PAYLOAD_LEN]; + +int32_t RangeTestPlugin::runOnce() +{ +#ifndef NO_ESP32 + + if (RANGETESTPLUGIN_ENABLED) { + + if (firstTime) { + + // Interface with the serial peripheral from in here. + DEBUG_MSG("Initializing Range Test Plugin\n"); + + rangeTestPluginRadio = new RangeTestPluginRadio(); + + firstTime = 0; + + } else { + // TBD + } + + return (10); + } else { + DEBUG_MSG("Range Test Plugin - Disabled\n"); + + return (INT32_MAX); + } + +#endif +} + +MeshPacket *RangeTestPluginRadio::allocReply() +{ + + auto reply = allocDataPacket(); // Allocate a packet for sending + + return reply; +} + +void RangeTestPluginRadio::sendPayload(NodeNum dest, bool wantReplies) +{ + MeshPacket *p = allocReply(); + p->to = dest; + p->decoded.want_response = wantReplies; + + service.sendToMesh(p); +} + +bool RangeTestPluginRadio::handleReceived(const MeshPacket &mp) +{ +#ifndef NO_ESP32 + + if (RANGETESTPLUGIN_ENABLED) { + + auto &p = mp.decoded.data; + // DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", + // nodeDB.getNodeNum(), mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); + + if (mp.from != nodeDB.getNodeNum()) { + + // DEBUG_MSG("* * Message came from the mesh\n"); + // Serial2.println("* * Message came from the mesh"); + Serial2.printf("%s", p.payload.bytes); + p.payload.size; + gpsStatus->getLatitude(); + gpsStatus->getLongitude(); + gpsStatus->getHasLock(); + gpsStatus->getDOP(); + mp.rx_snr; + mp.hop_limit; + mp.decoded.position.latitude_i; + mp.decoded.position.longitude_i; + + + + } + + } else { + DEBUG_MSG("Range Test Plugin Disabled\n"); + } + +#endif + + return true; // Let others look at this message also if they want +} diff --git a/src/plugins/RangeTestPlugin.h b/src/plugins/RangeTestPlugin.h new file mode 100644 index 00000000..f66744db --- /dev/null +++ b/src/plugins/RangeTestPlugin.h @@ -0,0 +1,49 @@ +#pragma once + +#include "SinglePortPlugin.h" +#include "concurrency/OSThread.h" +#include "configuration.h" +#include +#include + +class RangeTestPlugin : private concurrency::OSThread +{ + bool firstTime = 1; + + public: + RangeTestPlugin(); + + protected: + virtual int32_t runOnce(); +}; + +extern RangeTestPlugin *rangeTestPlugin; + +/* + * Radio interface for RangeTestPlugin + * + */ +class RangeTestPluginRadio : public SinglePortPlugin +{ + uint32_t lastRxID; + + public: + + RangeTestPluginRadio() : SinglePortPlugin("RangeTestPluginRadio", PortNum_TEXT_MESSAGE_APP) {} + + /** + * Send our payload into the mesh + */ + void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); + + protected: + virtual MeshPacket *allocReply(); + + /** 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 RangeTestPluginRadio *rangeTestPluginRadio; \ No newline at end of file