WIP on GPIO example

This commit is contained in:
Kevin Hester
2020-12-07 10:18:11 +08:00
parent 8f5a1f19d3
commit 90060e84c0
12 changed files with 140 additions and 60 deletions

View File

@@ -1,5 +1,6 @@
#include "MeshPlugin.h"
#include "NodeDB.h"
#include "MeshService.h"
#include <assert.h>
std::vector<MeshPlugin *> *MeshPlugin::plugins;
@@ -31,7 +32,7 @@ void MeshPlugin::callPlugins(const MeshPacket &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);
pi.sendResponse(mp);
DEBUG_MSG("Plugin %s handled=%d\n", pi.name, handled);
if (handled)
@@ -41,4 +42,28 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
DEBUG_MSG("Plugin %s not interested\n", pi.name);
}
}
}
/** 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 MeshPlugin::sendResponse(const MeshPacket &req) {
auto r = allocReply();
if(r) {
DEBUG_MSG("Sending response\n");
setReplyTo(r, req);
service.sendToMesh(r);
}
else {
DEBUG_MSG("WARNING: Client requested response but this plugin did not provide\n");
}
}
/** set the destination and packet parameters of packet p intended as a reply to a particular "to" packet
* This ensures that if the request packet was sent reliably, the reply is sent that way as well.
*/
void setReplyTo(MeshPacket *p, const MeshPacket &to) {
p->to = to.from;
p->want_ack = to.want_ack;
}