make plugin reply handling simpler

This commit is contained in:
Kevin Hester
2020-12-13 12:57:37 +08:00
parent ad8bcba5ef
commit ee8f4de5ab
5 changed files with 29 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
#include "configuration.h"
#include "ReplyPlugin.h"
#include "MeshService.h"
#include "configuration.h"
#include "main.h"
#include <assert.h>
@@ -8,8 +8,10 @@
// Create an a static instance of our plugin - this registers with the plugin system
ReplyPlugin replyPlugin;
bool ReplyPlugin::handleReceived(const MeshPacket &req)
MeshPacket *ReplyPlugin::allocReply()
{
assert(currentRequest); // should always be !NULL
auto req = *currentRequest;
auto &p = req.decoded.data;
// The incoming message is in p.payload
DEBUG_MSG("Received message from=0x%0x, id=%d, msg=%.*s\n", req.from, req.id, p.payload.size, p.payload.bytes);
@@ -17,11 +19,9 @@ bool ReplyPlugin::handleReceived(const MeshPacket &req)
screen->print("Sending reply\n");
const char *replyStr = "Message Received";
auto reply = allocDataPacket(); // Allocate a packet for sending
auto reply = allocDataPacket(); // Allocate a packet for sending
reply->decoded.data.payload.size = strlen(replyStr); // You must specify how many bytes are in the reply
memcpy(reply->decoded.data.payload.bytes, replyStr, reply->decoded.data.payload.size);
setReplyTo(reply, req); // Set packet params so that this packet is marked as a reply to a previous request
service.sendToMesh(reply); // Queue the reply for sending
return true; // We handled it
return reply;
}