firmware/src/plugins/ReplyPlugin.cpp

25 lines
833 B
C++
Raw Normal View History

2020-12-11 01:11:53 +00:00
#include "ReplyPlugin.h"
#include "MeshService.h"
2020-12-13 04:57:37 +00:00
#include "configuration.h"
2020-12-11 01:11:53 +00:00
#include "main.h"
#include <assert.h>
2020-12-13 04:57:37 +00:00
MeshPacket *ReplyPlugin::allocReply()
2020-12-11 01:11:53 +00:00
{
2020-12-13 04:57:37 +00:00
assert(currentRequest); // should always be !NULL
auto req = *currentRequest;
2020-12-11 01:11:53 +00:00
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);
screen->print("Sending reply\n");
const char *replyStr = "Message Received";
2020-12-13 04:57:37 +00:00
auto reply = allocDataPacket(); // Allocate a packet for sending
2020-12-11 01:11:53 +00:00
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);
2020-12-13 04:57:37 +00:00
return reply;
2020-12-11 01:11:53 +00:00
}