From 3e0dc44210f7f559c6d8853eda113e8690d70496 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 5 Dec 2020 11:15:06 +0800 Subject: [PATCH] move want_replies into new plugin system --- docs/software/TODO.md | 2 +- src/mesh/MeshPlugin.cpp | 6 ++++++ src/mesh/MeshPlugin.h | 6 ++++++ src/mesh/MeshService.cpp | 3 --- src/plugins/NodeInfoPlugin.cpp | 10 ++++++++++ src/plugins/NodeInfoPlugin.h | 7 ++++++- src/plugins/PositionPlugin.cpp | 9 +++++++++ src/plugins/PositionPlugin.h | 6 ++++++ 8 files changed, 44 insertions(+), 5 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 1cb6b17e0..fc1c27c83 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -8,7 +8,7 @@ For app cleanup: * DONE require a recent python api to talk to these new device loads * DONE require a recent android app to talk to these new device loads * DONE fix handleIncomingPosition -* move want_replies handling into plugins +* DONE move want_replies handling into plugins * on android for received positions handle either old or new positions / user messages * on android side send old or new positions as needed / user messages * on python side handle new position/user messages diff --git a/src/mesh/MeshPlugin.cpp b/src/mesh/MeshPlugin.cpp index 938a3bffa..77aa1b0a5 100644 --- a/src/mesh/MeshPlugin.cpp +++ b/src/mesh/MeshPlugin.cpp @@ -1,4 +1,5 @@ #include "MeshPlugin.h" +#include "NodeDB.h" #include std::vector *MeshPlugin::plugins; @@ -27,6 +28,11 @@ void MeshPlugin::callPlugins(const MeshPacket &mp) auto &pi = **i; if (pi.wantPortnum(mp.decoded.data.portnum)) { bool handled = pi.handleReceived(mp); + + // Possibly send replies (unless we are handling a locally generated message) + if (mp.decoded.want_response && mp.from != nodeDB.getNodeNum()) + pi.sendResponse(mp.from); + DEBUG_MSG("Plugin %s handled=%d\n", pi.name, handled); if (handled) break; diff --git a/src/mesh/MeshPlugin.h b/src/mesh/MeshPlugin.h index c2e372cca..926157af9 100644 --- a/src/mesh/MeshPlugin.h +++ b/src/mesh/MeshPlugin.h @@ -47,4 +47,10 @@ 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; } + + /** Messages can be received that have the want_response bit set. If set, this callback will be invoked + * so that subclasses can (optionally) send a response back to the original sender. Implementing this method + * is optional + */ + virtual void sendResponse(NodeNum to) {} }; \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 5566d2a30..059cd70d2 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -96,9 +96,6 @@ int MeshService::handleFromRadio(const MeshPacket *mp) MeshPacket *copied = packetPool.allocCopy(*mp); assert(toPhoneQueue.enqueue(copied, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages - if (mp->decoded.want_response) - sendNetworkPing(mp->from); - return 0; } diff --git a/src/plugins/NodeInfoPlugin.cpp b/src/plugins/NodeInfoPlugin.cpp index d02766340..c6d8e6a70 100644 --- a/src/plugins/NodeInfoPlugin.cpp +++ b/src/plugins/NodeInfoPlugin.cpp @@ -37,3 +37,13 @@ void NodeInfoPlugin::sendOurNodeInfo(NodeNum dest, bool wantReplies) service.sendToMesh(p); } + + +/** Messages can be received that have the want_response bit set. If set, this callback will be invoked + * so that subclasses can (optionally) send a response back to the original sender. Implementing this method + * is optional + */ +void NodeInfoPlugin::sendResponse(NodeNum to) { + DEBUG_MSG("Sending user reply\n"); + sendOurNodeInfo(to, false); +} \ No newline at end of file diff --git a/src/plugins/NodeInfoPlugin.h b/src/plugins/NodeInfoPlugin.h index 627ab83e9..98a620e25 100644 --- a/src/plugins/NodeInfoPlugin.h +++ b/src/plugins/NodeInfoPlugin.h @@ -18,12 +18,17 @@ class NodeInfoPlugin : public ProtobufPlugin void sendOurNodeInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); protected: - /** 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 handleReceivedProtobuf(const MeshPacket &mp, const User &p); + + /** Messages can be received that have the want_response bit set. If set, this callback will be invoked + * so that subclasses can (optionally) send a response back to the original sender. Implementing this method + * is optional + */ + virtual void sendResponse(NodeNum to); }; extern NodeInfoPlugin nodeInfoPlugin; \ No newline at end of file diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index 1562c0f62..c1f813a4b 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -44,3 +44,12 @@ void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies) service.sendToMesh(p); } + +/** Messages can be received that have the want_response bit set. If set, this callback will be invoked + * so that subclasses can (optionally) send a response back to the original sender. Implementing this method + * is optional + */ +void PositionPlugin::sendResponse(NodeNum to) { + DEBUG_MSG("Sending posistion reply\n"); + sendOurPosition(to, false); +} \ No newline at end of file diff --git a/src/plugins/PositionPlugin.h b/src/plugins/PositionPlugin.h index 6f967c57a..4ca146dd4 100644 --- a/src/plugins/PositionPlugin.h +++ b/src/plugins/PositionPlugin.h @@ -24,6 +24,12 @@ class PositionPlugin : public ProtobufPlugin @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ virtual bool handleReceivedProtobuf(const MeshPacket &mp, const Position &p); + + /** Messages can be received that have the want_response bit set. If set, this callback will be invoked + * so that subclasses can (optionally) send a response back to the original sender. Implementing this method + * is optional + */ + virtual void sendResponse(NodeNum to); }; extern PositionPlugin positionPlugin; \ No newline at end of file