Files
firmware/src/modules/ReplyModule.cpp

25 lines
813 B
C++
Raw Normal View History

#include "configuration.h"
#include "ReplyModule.h"
2020-12-11 09:11:53 +08:00
#include "MeshService.h"
#include "main.h"
#include <assert.h>
2022-02-27 02:21:02 -08:00
MeshPacket *ReplyModule::allocReply()
2020-12-11 09:11:53 +08:00
{
2020-12-13 12:57:37 +08:00
assert(currentRequest); // should always be !NULL
auto req = *currentRequest;
2021-02-17 13:06:23 +08:00
auto &p = req.decoded;
2020-12-11 09:11:53 +08:00
// 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 12:57:37 +08:00
auto reply = allocDataPacket(); // Allocate a packet for sending
2021-02-17 13:06:23 +08:00
reply->decoded.payload.size = strlen(replyStr); // You must specify how many bytes are in the reply
memcpy(reply->decoded.payload.bytes, replyStr, reply->decoded.payload.size);
2020-12-11 09:11:53 +08:00
2020-12-13 12:57:37 +08:00
return reply;
2020-12-11 09:11:53 +08:00
}