mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-22 04:54:47 +00:00
move want_replies into new plugin system
This commit is contained in:
parent
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 python api to talk to these new device loads
|
||||||
* DONE require a recent android app to talk to these new device loads
|
* DONE require a recent android app to talk to these new device loads
|
||||||
* DONE fix handleIncomingPosition
|
* 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 for received positions handle either old or new positions / user messages
|
||||||
* on android side send old or new positions as needed / user messages
|
* on android side send old or new positions as needed / user messages
|
||||||
* on python side handle new position/user messages
|
* on python side handle new position/user messages
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "MeshPlugin.h"
|
#include "MeshPlugin.h"
|
||||||
|
#include "NodeDB.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
std::vector<MeshPlugin *> *MeshPlugin::plugins;
|
std::vector<MeshPlugin *> *MeshPlugin::plugins;
|
||||||
@ -27,6 +28,11 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
|
|||||||
auto &pi = **i;
|
auto &pi = **i;
|
||||||
if (pi.wantPortnum(mp.decoded.data.portnum)) {
|
if (pi.wantPortnum(mp.decoded.data.portnum)) {
|
||||||
bool handled = pi.handleReceived(mp);
|
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);
|
DEBUG_MSG("Plugin %s handled=%d\n", pi.name, handled);
|
||||||
if (handled)
|
if (handled)
|
||||||
break;
|
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
|
@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; }
|
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);
|
MeshPacket *copied = packetPool.allocCopy(*mp);
|
||||||
assert(toPhoneQueue.enqueue(copied, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,3 +37,13 @@ void NodeInfoPlugin::sendOurNodeInfo(NodeNum dest, bool wantReplies)
|
|||||||
|
|
||||||
service.sendToMesh(p);
|
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);
|
void sendOurNodeInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** Called to handle a particular incoming message
|
/** 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
|
@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);
|
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;
|
extern NodeInfoPlugin nodeInfoPlugin;
|
@ -44,3 +44,12 @@ void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies)
|
|||||||
|
|
||||||
service.sendToMesh(p);
|
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
|
@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);
|
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;
|
extern PositionPlugin positionPlugin;
|
Loading…
Reference in New Issue
Block a user