sforkowany z mirror/meshtastic-firmware
move want_replies into new plugin system
rodzic
91b99bd584
commit
3e0dc44210
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "MeshPlugin.h"
|
||||
#include "NodeDB.h"
|
||||
#include <assert.h>
|
||||
|
||||
std::vector<MeshPlugin *> *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;
|
||||
|
|
|
@ -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) {}
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -18,12 +18,17 @@ class NodeInfoPlugin : public ProtobufPlugin<User>
|
|||
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;
|
|
@ -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);
|
||||
}
|
|
@ -24,6 +24,12 @@ class PositionPlugin : public ProtobufPlugin<Position>
|
|||
@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;
|
Ładowanie…
Reference in New Issue