mirror of
https://github.com/meshtastic/firmware.git
synced 2026-09-22 06:15:25 -04:00
* Null-check packet allocations in allocForSending and its callers
Sibling of 0ae44d701.
* Null-check allocDataProtobuf, allocAckNak and allocErrorResponse callers
Second tier of the same nullable contract.
* Keep telemetry sleep scheduling on allocation failure
Allocation failure now marks the telemetry invalid instead of returning
early, so power-saving SENSOR nodes still arm deep sleep.
27 lines
861 B
C++
27 lines
861 B
C++
#include "ReplyModule.h"
|
|
#include "MeshService.h"
|
|
#include "configuration.h"
|
|
#include "main.h"
|
|
|
|
#include <assert.h>
|
|
|
|
meshtastic_MeshPacket *ReplyModule::allocReply()
|
|
{
|
|
assert(currentRequest); // should always be !NULL
|
|
#if defined(DEBUG_PORT) && !defined(DEBUG_MUTE)
|
|
auto req = *currentRequest;
|
|
auto &p = req.decoded;
|
|
// The incoming message is in p.payload
|
|
LOG_INFO("Received message from=0x%08x, id=0x%08x, msg=%.*s", req.from, req.id, p.payload.size, p.payload.bytes);
|
|
#endif
|
|
|
|
const char *replyStr = "Message Received";
|
|
auto reply = allocDataPacket(); // Allocate a packet for sending
|
|
if (!reply)
|
|
return nullptr;
|
|
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);
|
|
|
|
return reply;
|
|
}
|