firmware/src/modules/ReplyModule.cpp

27 lines
843 B
C++
Raw Normal View History

#include "ReplyModule.h"
2020-12-11 01:11:53 +00:00
#include "MeshService.h"
2023-01-21 13:34:29 +00:00
#include "configuration.h"
2020-12-11 01:11:53 +00:00
#include "main.h"
#include <assert.h>
meshtastic_MeshPacket *ReplyModule::allocReply()
2020-12-11 01:11:53 +00:00
{
2020-12-13 04:57:37 +00:00
assert(currentRequest); // should always be !NULL
#ifdef DEBUG_PORT
2020-12-13 04:57:37 +00:00
auto req = *currentRequest;
2021-02-17 05:06:23 +00:00
auto &p = req.decoded;
2020-12-11 01:11:53 +00:00
// The incoming message is in p.payload
LOG_INFO("Received message from=0x%0x, id=%d, msg=%.*s\n", req.from, req.id, p.payload.size, p.payload.bytes);
#endif
2020-12-11 01:11:53 +00:00
screen->print("Sending reply\n");
const char *replyStr = "Message Received";
2023-01-21 13:34:29 +00:00
auto reply = allocDataPacket(); // Allocate a packet for sending
2021-02-17 05:06:23 +00: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 01:11:53 +00:00
2020-12-13 04:57:37 +00:00
return reply;
2020-12-11 01:11:53 +00:00
}