From 7737123d0f9d61e1d93bf62616beb90842164ba6 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 28 Nov 2020 13:51:51 +0800 Subject: [PATCH] begin moving position stuff into plugin --- docs/software/TODO.md | 4 +++- proto | 2 +- src/mesh/MeshPlugin.cpp | 2 +- src/mesh/MeshPlugin.h | 9 +++++---- src/mesh/MeshService.cpp | 1 - src/mesh/portnums.pb.h | 10 +++++----- src/plugins/PositionPlugin.cpp | 13 +++++++++++++ src/plugins/TextMessagePlugin.h | 2 +- 8 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 src/plugins/PositionPlugin.cpp diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 178583af0..6ba049427 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -4,7 +4,9 @@ You probably don't care about this section - skip to the next one. For app cleanup: -* add app handlers in device code (make new app framework) +* require a recent python api to talk to these new device loads +* on android for received positions handle either old or new positions +* on android side send old or new positions as needed * move positions into regular data packets (use new app framework) * move user info into regular data packets (use new app framework) * test that positions, text messages and user info still work diff --git a/proto b/proto index 7c1016b8a..9a7ffbecc 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 7c1016b8a01d4d019c4239fe46624dee7bde22c7 +Subproject commit 9a7ffbecc72a11904bd4e85d086956e4e77eed6d diff --git a/src/mesh/MeshPlugin.cpp b/src/mesh/MeshPlugin.cpp index 853124981..938a3bffa 100644 --- a/src/mesh/MeshPlugin.cpp +++ b/src/mesh/MeshPlugin.cpp @@ -22,7 +22,7 @@ MeshPlugin::~MeshPlugin() void MeshPlugin::callPlugins(const MeshPacket &mp) { - DEBUG_MSG("In call plugins\n"); + // DEBUG_MSG("In call plugins\n"); for (auto i = plugins->begin(); i != plugins->end(); ++i) { auto &pi = **i; if (pi.wantPortnum(mp.decoded.data.portnum)) { diff --git a/src/mesh/MeshPlugin.h b/src/mesh/MeshPlugin.h index 19189fb52..e795eb19c 100644 --- a/src/mesh/MeshPlugin.h +++ b/src/mesh/MeshPlugin.h @@ -26,6 +26,11 @@ class MeshPlugin virtual ~MeshPlugin(); + /** For use only by MeshService + */ + static void callPlugins(const MeshPacket &mp); + + protected: /** * Initialize your plugin. This setup function is called once after all hardware and mesh protocol layers have * been initialized @@ -42,8 +47,4 @@ class MeshPlugin @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) { return false; } - - /** For use only by MeshService - */ - static void callPlugins(const MeshPacket &mp); }; \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 2c339f72e..d99078f0c 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -297,7 +297,6 @@ void MeshService::sendOurPosition(NodeNum dest, bool wantReplies) int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused) { - // Update our local node info with our position (even if we don't decide to update anyone else) MeshPacket *p = router->allocForSending(); p->decoded.which_payload = SubPacket_position_tag; diff --git a/src/mesh/portnums.pb.h b/src/mesh/portnums.pb.h index c9a2a5f23..285910510 100644 --- a/src/mesh/portnums.pb.h +++ b/src/mesh/portnums.pb.h @@ -18,16 +18,16 @@ typedef enum _PortNum { PortNum_UNKNOWN_APP = 0, PortNum_TEXT_MESSAGE_APP = 1, PortNum_GPIO_APP = 2, - PortNum_GPS_POSITION_APP = 3, + PortNum_POSITION_APP = 3, PortNum_MESH_USERINFO_APP = 4, - PortNum_IP_TUNNEL_APP = 5, - PortNum_PRIVATE_APP = 256 + PortNum_PRIVATE_APP = 256, + PortNum_IP_TUNNEL_APP = 1024 } PortNum; /* Helper constants for enums */ #define _PortNum_MIN PortNum_UNKNOWN_APP -#define _PortNum_MAX PortNum_PRIVATE_APP -#define _PortNum_ARRAYSIZE ((PortNum)(PortNum_PRIVATE_APP+1)) +#define _PortNum_MAX PortNum_IP_TUNNEL_APP +#define _PortNum_ARRAYSIZE ((PortNum)(PortNum_IP_TUNNEL_APP+1)) #ifdef __cplusplus diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp new file mode 100644 index 000000000..4b2624baf --- /dev/null +++ b/src/plugins/PositionPlugin.cpp @@ -0,0 +1,13 @@ +#include "configuration.h" +#include "PositionPlugin.h" +#include "NodeDB.h" + +PositionPlugin positionPlugin; + +bool PositionPlugin::handleReceived(const MeshPacket &mp) +{ + auto &p = mp.decoded.data; + DEBUG_MSG("Received position from=0x%0x, id=%d, msg=%.*s\n", mp.from, mp.id, p.payload.size, p.payload.bytes); + + return false; // Let others look at this message also if they want +} diff --git a/src/plugins/TextMessagePlugin.h b/src/plugins/TextMessagePlugin.h index 1df13a990..6dacf9045 100644 --- a/src/plugins/TextMessagePlugin.h +++ b/src/plugins/TextMessagePlugin.h @@ -7,12 +7,12 @@ class TextMessagePlugin : public MeshPlugin, public Observable { public: - /** Constructor * name is for debugging output */ TextMessagePlugin() : MeshPlugin("text") {} + protected: /** * @return true if you want to receive the specified portnum */