Null-check packet allocations in allocForSending and its callers (#11086)
* 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.
This commit is contained in:
@@ -2614,6 +2614,8 @@ uint16_t InkHUD::MenuApplet::getSystemInfoPanelHeight()
|
|||||||
void InkHUD::MenuApplet::sendText(NodeNum dest, ChannelIndex channel, const char *message)
|
void InkHUD::MenuApplet::sendText(NodeNum dest, ChannelIndex channel, const char *message)
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = router->allocForSending();
|
meshtastic_MeshPacket *p = router->allocForSending();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
|
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->channel = channel;
|
p->channel = channel;
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ meshtastic_MeshPacket *MeshModule::allocAckNak(meshtastic_Routing_Error err, Nod
|
|||||||
// So we manually call pb_encode_to_bytes and specify routing port number
|
// So we manually call pb_encode_to_bytes and specify routing port number
|
||||||
// auto p = allocDataProtobuf(c);
|
// auto p = allocDataProtobuf(c);
|
||||||
meshtastic_MeshPacket *p = router->allocForSending();
|
meshtastic_MeshPacket *p = router->allocForSending();
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
p->decoded.portnum = meshtastic_PortNum_ROUTING_APP;
|
p->decoded.portnum = meshtastic_PortNum_ROUTING_APP;
|
||||||
p->decoded.payload.size =
|
p->decoded.payload.size =
|
||||||
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Routing_msg, &c);
|
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Routing_msg, &c);
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ template <class T> class ProtobufModule : protected SinglePortModule
|
|||||||
{
|
{
|
||||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
p->decoded.payload.size =
|
p->decoded.payload.size =
|
||||||
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), fields, &payload);
|
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), fields, &payload);
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ PacketId generatePacketId()
|
|||||||
meshtastic_MeshPacket *Router::allocForSending()
|
meshtastic_MeshPacket *Router::allocForSending()
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = packetPool.allocZeroed();
|
meshtastic_MeshPacket *p = packetPool.allocZeroed();
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Assume payload is decoded at start.
|
p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Assume payload is decoded at start.
|
||||||
p->from = nodeDB->getNodeNum();
|
p->from = nodeDB->getNodeNum();
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ class SinglePortModule : public MeshModule
|
|||||||
{
|
{
|
||||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||||
meshtastic_MeshPacket *p = router->allocForSending();
|
meshtastic_MeshPacket *p = router->allocForSending();
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
p->decoded.portnum = ourPortNum;
|
p->decoded.portnum = ourPortNum;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
@@ -1417,6 +1417,9 @@ void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req)
|
|||||||
res.which_payload_variant = meshtastic_AdminMessage_get_owner_response_tag;
|
res.which_payload_variant = meshtastic_AdminMessage_get_owner_response_tag;
|
||||||
setPassKey(&res);
|
setPassKey(&res);
|
||||||
myReply = allocDataProtobuf(res);
|
myReply = allocDataProtobuf(res);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1500,6 +1503,9 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32
|
|||||||
res.which_payload_variant = meshtastic_AdminMessage_get_config_response_tag;
|
res.which_payload_variant = meshtastic_AdminMessage_get_config_response_tag;
|
||||||
setPassKey(&res);
|
setPassKey(&res);
|
||||||
myReply = allocDataProtobuf(res);
|
myReply = allocDataProtobuf(res);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1609,6 +1615,9 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
|
|||||||
res.which_payload_variant = meshtastic_AdminMessage_get_module_config_response_tag;
|
res.which_payload_variant = meshtastic_AdminMessage_get_module_config_response_tag;
|
||||||
setPassKey(&res);
|
setPassKey(&res);
|
||||||
myReply = allocDataProtobuf(res);
|
myReply = allocDataProtobuf(res);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1636,6 +1645,9 @@ void AdminModule::handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &r
|
|||||||
}
|
}
|
||||||
setPassKey(&r);
|
setPassKey(&r);
|
||||||
myReply = allocDataProtobuf(r);
|
myReply = allocDataProtobuf(r);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1655,6 +1667,9 @@ void AdminModule::handleGetDeviceMetadata(const meshtastic_MeshPacket &req)
|
|||||||
r.which_payload_variant = meshtastic_AdminMessage_get_device_metadata_response_tag;
|
r.which_payload_variant = meshtastic_AdminMessage_get_device_metadata_response_tag;
|
||||||
setPassKey(&r);
|
setPassKey(&r);
|
||||||
myReply = allocDataProtobuf(r);
|
myReply = allocDataProtobuf(r);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1730,6 +1745,9 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r
|
|||||||
r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag;
|
r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag;
|
||||||
setPassKey(&r);
|
setPassKey(&r);
|
||||||
myReply = allocDataProtobuf(r);
|
myReply = allocDataProtobuf(r);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1744,6 +1762,9 @@ void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t ch
|
|||||||
r.which_payload_variant = meshtastic_AdminMessage_get_channel_response_tag;
|
r.which_payload_variant = meshtastic_AdminMessage_get_channel_response_tag;
|
||||||
setPassKey(&r);
|
setPassKey(&r);
|
||||||
myReply = allocDataProtobuf(r);
|
myReply = allocDataProtobuf(r);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
@@ -1756,6 +1777,9 @@ void AdminModule::handleGetDeviceUIConfig(const meshtastic_MeshPacket &req)
|
|||||||
r.which_payload_variant = meshtastic_AdminMessage_get_ui_config_response_tag;
|
r.which_payload_variant = meshtastic_AdminMessage_get_ui_config_response_tag;
|
||||||
r.get_ui_config_response = uiconfig;
|
r.get_ui_config_response = uiconfig;
|
||||||
myReply = allocDataProtobuf(r);
|
myReply = allocDataProtobuf(r);
|
||||||
|
if (!myReply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (req.pki_encrypted) {
|
if (req.pki_encrypted) {
|
||||||
myReply->pki_encrypted = true;
|
myReply->pki_encrypted = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1022,6 +1022,8 @@ void CannedMessageModule::sendText(NodeNum dest, ChannelIndex channel, const cha
|
|||||||
lastDestSet = true;
|
lastDestSet = true;
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->channel = channel;
|
p->channel = channel;
|
||||||
p->want_ack = true;
|
p->want_ack = true;
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ void DetectionSensorModule::sendDetectionMessage()
|
|||||||
char *message = new char[40];
|
char *message = new char[40];
|
||||||
sprintf(message, "%s detected", moduleConfig.detection_sensor.name);
|
sprintf(message, "%s detected", moduleConfig.detection_sensor.name);
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p) {
|
||||||
|
delete[] message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
p->want_ack = false;
|
p->want_ack = false;
|
||||||
p->decoded.payload.size = strlen(message);
|
p->decoded.payload.size = strlen(message);
|
||||||
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
||||||
@@ -153,6 +157,10 @@ void DetectionSensorModule::sendCurrentStateMessage(bool state)
|
|||||||
char *message = new char[40];
|
char *message = new char[40];
|
||||||
sprintf(message, "%s state: %i", moduleConfig.detection_sensor.name, state);
|
sprintf(message, "%s state: %i", moduleConfig.detection_sensor.name, state);
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p) {
|
||||||
|
delete[] message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
p->want_ack = false;
|
p->want_ack = false;
|
||||||
p->decoded.payload.size = strlen(message);
|
p->decoded.payload.size = strlen(message);
|
||||||
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ meshtastic_MeshPacket *DropzoneModule::sendConditions()
|
|||||||
// the dropzone is open
|
// the dropzone is open
|
||||||
auto dropzoneStatus = analogRead(A1) < 100 ? "OPEN" : "CLOSED";
|
auto dropzoneStatus = analogRead(A1) < 100 ? "OPEN" : "CLOSED";
|
||||||
auto reply = allocDataPacket();
|
auto reply = allocDataPacket();
|
||||||
|
if (!reply)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
auto node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
auto node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
||||||
if (sensor.hasSensor()) {
|
if (sensor.hasSensor()) {
|
||||||
|
|||||||
@@ -169,6 +169,8 @@ bool KeyVerificationModule::sendInitialRequest(NodeNum remoteNode)
|
|||||||
KeyVerification.hash1.size = 32;
|
KeyVerification.hash1.size = 32;
|
||||||
memcpy(KeyVerification.hash1.bytes, owner.public_key.bytes, 32);
|
memcpy(KeyVerification.hash1.bytes, owner.public_key.bytes, 32);
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(KeyVerification);
|
meshtastic_MeshPacket *p = allocDataProtobuf(KeyVerification);
|
||||||
|
if (!p)
|
||||||
|
return false;
|
||||||
p->to = remoteNode;
|
p->to = remoteNode;
|
||||||
p->channel = 0;
|
p->channel = 0;
|
||||||
// Only request PKI when we already hold the destination's key. Otherwise this first message goes out
|
// Only request PKI when we already hold the destination's key. Otherwise this first message goes out
|
||||||
@@ -325,6 +327,8 @@ void KeyVerificationModule::processSecurityNumber(uint32_t incomingNumber)
|
|||||||
KeyVerification.hash1.size = 32;
|
KeyVerification.hash1.size = 32;
|
||||||
memcpy(KeyVerification.hash1.bytes, hash1, 32);
|
memcpy(KeyVerification.hash1.bytes, hash1, 32);
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(KeyVerification);
|
meshtastic_MeshPacket *p = allocDataProtobuf(KeyVerification);
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = currentRemoteNode;
|
p->to = currentRemoteNode;
|
||||||
p->channel = 0;
|
p->channel = 0;
|
||||||
p->pki_encrypted = true;
|
p->pki_encrypted = true;
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies)
|
|||||||
// only send neighbours if we have some to send
|
// only send neighbours if we have some to send
|
||||||
if (neighborInfo.neighbors_count > 0) {
|
if (neighborInfo.neighbors_count > 0) {
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(neighborInfo);
|
meshtastic_MeshPacket *p = allocDataProtobuf(neighborInfo);
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = wantReplies;
|
p->decoded.want_response = wantReplies;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
|||||||
@@ -292,6 +292,8 @@ meshtastic_MeshPacket *PositionModule::allocAtakPli()
|
|||||||
{
|
{
|
||||||
LOG_INFO("Send TAK V2 PLI packet");
|
LOG_INFO("Send TAK V2 PLI packet");
|
||||||
meshtastic_MeshPacket *mp = allocDataPacket();
|
meshtastic_MeshPacket *mp = allocDataPacket();
|
||||||
|
if (!mp)
|
||||||
|
return nullptr;
|
||||||
mp->decoded.portnum = meshtastic_PortNum_ATAK_PLUGIN_V2;
|
mp->decoded.portnum = meshtastic_PortNum_ATAK_PLUGIN_V2;
|
||||||
|
|
||||||
meshtastic_TAKPacketV2 takPacket = meshtastic_TAKPacketV2_init_zero;
|
meshtastic_TAKPacketV2 takPacket = meshtastic_TAKPacketV2_init_zero;
|
||||||
@@ -572,6 +574,8 @@ int32_t PositionModule::runOnce()
|
|||||||
void PositionModule::sendLostAndFoundText()
|
void PositionModule::sendLostAndFoundText()
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = NODENUM_BROADCAST;
|
p->to = NODENUM_BROADCAST;
|
||||||
char message[128];
|
char message[128];
|
||||||
int written = snprintf(message, sizeof(message), "🚨I'm lost! Lat / Lon: %f, %f\a", (lastGpsLatitude * 1e-7),
|
int written = snprintf(message, sizeof(message), "🚨I'm lost! Lat / Lon: %f, %f\a", (lastGpsLatitude * 1e-7),
|
||||||
|
|||||||
@@ -114,6 +114,8 @@ int32_t RangeTestModule::runOnce()
|
|||||||
void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies)
|
void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies)
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = wantReplies;
|
p->decoded.want_response = wantReplies;
|
||||||
p->hop_limit = 0;
|
p->hop_limit = 0;
|
||||||
|
|||||||
@@ -168,6 +168,8 @@ void ReplyBotModule::sendDm(const meshtastic_MeshPacket &rx, const char *text)
|
|||||||
if (!text)
|
if (!text)
|
||||||
return;
|
return;
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = rx.from;
|
p->to = rx.from;
|
||||||
p->channel = rx.channel;
|
p->channel = rx.channel;
|
||||||
p->want_ack = false;
|
p->want_ack = false;
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ meshtastic_MeshPacket *ReplyModule::allocReply()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *replyStr = "Message Received";
|
const char *replyStr = "Message Received";
|
||||||
auto reply = allocDataPacket(); // Allocate a packet for sending
|
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
|
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);
|
memcpy(reply->decoded.payload.bytes, replyStr, reply->decoded.payload.size);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ void RoutingModule::sendAckNak(meshtastic_Routing_Error err, NodeNum to, PacketI
|
|||||||
bool ackWantsAck)
|
bool ackWantsAck)
|
||||||
{
|
{
|
||||||
auto p = allocAckNak(err, to, idFrom, chIndex, hopLimit);
|
auto p = allocAckNak(err, to, idFrom, chIndex, hopLimit);
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
|
|
||||||
// Allow the caller to set want_ack on this ACK packet if it's important that the ACK be delivered reliably
|
// Allow the caller to set want_ack on this ACK packet if it's important that the ACK be delivered reliably
|
||||||
p->want_ack = ackWantsAck;
|
p->want_ack = ackWantsAck;
|
||||||
|
|||||||
@@ -314,6 +314,8 @@ int32_t SerialModule::runOnce()
|
|||||||
void SerialModule::sendTelemetry(meshtastic_Telemetry m)
|
void SerialModule::sendTelemetry(meshtastic_Telemetry m)
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = router->allocForSending();
|
meshtastic_MeshPacket *p = router->allocForSending();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->decoded.portnum = meshtastic_PortNum_TELEMETRY_APP;
|
p->decoded.portnum = meshtastic_PortNum_TELEMETRY_APP;
|
||||||
p->decoded.payload.size =
|
p->decoded.payload.size =
|
||||||
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Telemetry_msg, &m);
|
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Telemetry_msg, &m);
|
||||||
@@ -350,6 +352,8 @@ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies)
|
|||||||
{
|
{
|
||||||
const meshtastic_Channel *ch = (boundChannel != NULL) ? &channels.getByName(boundChannel) : NULL;
|
const meshtastic_Channel *ch = (boundChannel != NULL) ? &channels.getByName(boundChannel) : NULL;
|
||||||
meshtastic_MeshPacket *p = allocReply();
|
meshtastic_MeshPacket *p = allocReply();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
if (ch != NULL) {
|
if (ch != NULL) {
|
||||||
p->channel = ch->index;
|
p->channel = ch->index;
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ class SerialModuleRadio : public MeshModule
|
|||||||
{
|
{
|
||||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||||
meshtastic_MeshPacket *p = router->allocForSending();
|
meshtastic_MeshPacket *p = router->allocForSending();
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
p->decoded.portnum = ourPortNum;
|
p->decoded.portnum = ourPortNum;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ int32_t StatusMessageModule::runOnce()
|
|||||||
strncpy(ourStatus.status, moduleConfig.statusmessage.node_status, sizeof(ourStatus.status));
|
strncpy(ourStatus.status, moduleConfig.statusmessage.node_status, sizeof(ourStatus.status));
|
||||||
ourStatus.status[sizeof(ourStatus.status) - 1] = '\0'; // ensure null termination
|
ourStatus.status[sizeof(ourStatus.status) - 1] = '\0'; // ensure null termination
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return 1000 * 12 * 60 * 60;
|
||||||
p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes),
|
p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes),
|
||||||
meshtastic_StatusMessage_fields, &ourStatus);
|
meshtastic_StatusMessage_fields, &ourStatus);
|
||||||
p->to = NODENUM_BROADCAST;
|
p->to = NODENUM_BROADCAST;
|
||||||
|
|||||||
@@ -248,6 +248,8 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t
|
|||||||
(this->packetHistory[i].to == NODENUM_BROADCAST || this->packetHistory[i].to == dest)) {
|
(this->packetHistory[i].to == NODENUM_BROADCAST || this->packetHistory[i].to == dest)) {
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
p->to = local ? this->packetHistory[i].to : dest; // PhoneAPI can handle original `to`
|
p->to = local ? this->packetHistory[i].to : dest; // PhoneAPI can handle original `to`
|
||||||
p->from = this->packetHistory[i].from;
|
p->from = this->packetHistory[i].from;
|
||||||
@@ -304,6 +306,8 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t
|
|||||||
void StoreForwardModule::sendMessage(NodeNum dest, const meshtastic_StoreAndForward &payload)
|
void StoreForwardModule::sendMessage(NodeNum dest, const meshtastic_StoreAndForward &payload)
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(payload);
|
meshtastic_MeshPacket *p = allocDataProtobuf(payload);
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
|
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
|
|
||||||
@@ -340,6 +344,8 @@ void StoreForwardModule::sendMessage(NodeNum dest, meshtastic_StoreAndForward_Re
|
|||||||
void StoreForwardModule::sendErrorTextMessage(NodeNum dest, bool want_response)
|
void StoreForwardModule::sendErrorTextMessage(NodeNum dest, bool want_response)
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *pr = allocDataPacket();
|
meshtastic_MeshPacket *pr = allocDataPacket();
|
||||||
|
if (!pr)
|
||||||
|
return;
|
||||||
pr->to = dest;
|
pr->to = dest;
|
||||||
pr->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
pr->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
pr->want_ack = false;
|
pr->want_ack = false;
|
||||||
|
|||||||
@@ -464,35 +464,39 @@ bool AirQualityTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
}
|
}
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
||||||
p->to = dest;
|
if (!p) {
|
||||||
p->decoded.want_response = false;
|
validTelemetry = false;
|
||||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
|
||||||
else
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
|
||||||
|
|
||||||
// release previous packet before occupying a new spot
|
|
||||||
if (lastMeasurementPacket != nullptr)
|
|
||||||
packetPool.release(lastMeasurementPacket);
|
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(*p);
|
|
||||||
if (phoneOnly) {
|
|
||||||
LOG_INFO("Sending packet to phone");
|
|
||||||
service->sendToPhone(p);
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Sending packet to mesh");
|
p->to = dest;
|
||||||
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
p->decoded.want_response = false;
|
||||||
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
||||||
|
else
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
|
||||||
if (isPowerSavingSensor()) {
|
// release previous packet before occupying a new spot
|
||||||
meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed();
|
if (lastMeasurementPacket != nullptr)
|
||||||
if (notification) {
|
packetPool.release(lastMeasurementPacket);
|
||||||
notification->level = meshtastic_LogRecord_Level_INFO;
|
|
||||||
notification->time = getValidTime(RTCQualityFromNet);
|
lastMeasurementPacket = packetPool.allocCopy(*p);
|
||||||
sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment",
|
if (phoneOnly) {
|
||||||
Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.air_quality_interval,
|
LOG_INFO("Sending packet to phone");
|
||||||
default_telemetry_broadcast_interval_secs) /
|
service->sendToPhone(p);
|
||||||
1000U);
|
} else {
|
||||||
service->sendClientNotification(notification);
|
LOG_INFO("Sending packet to mesh");
|
||||||
|
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
|
|
||||||
|
if (isPowerSavingSensor()) {
|
||||||
|
meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed();
|
||||||
|
if (notification) {
|
||||||
|
notification->level = meshtastic_LogRecord_Level_INFO;
|
||||||
|
notification->time = getValidTime(RTCQualityFromNet);
|
||||||
|
sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment",
|
||||||
|
Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.air_quality_interval,
|
||||||
|
default_telemetry_broadcast_interval_secs) /
|
||||||
|
1000U);
|
||||||
|
service->sendClientNotification(notification);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,8 @@ meshtastic_Telemetry DeviceTelemetryModule::getLocalStatsTelemetry()
|
|||||||
void DeviceTelemetryModule::sendLocalStatsToPhone()
|
void DeviceTelemetryModule::sendLocalStatsToPhone()
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(getLocalStatsTelemetry());
|
meshtastic_MeshPacket *p = allocDataProtobuf(getLocalStatsTelemetry());
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = NODENUM_BROADCAST;
|
p->to = NODENUM_BROADCAST;
|
||||||
p->decoded.want_response = false;
|
p->decoded.want_response = false;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
@@ -191,6 +193,8 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
|
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
|
||||||
DEBUG_HEAP_AFTER("DeviceTelemetryModule::sendTelemetry", p);
|
DEBUG_HEAP_AFTER("DeviceTelemetryModule::sendTelemetry", p);
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
return false;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = false;
|
p->decoded.want_response = false;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
|||||||
@@ -661,34 +661,38 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
m.variant.environment_metrics.soil_moisture);
|
m.variant.environment_metrics.soil_moisture);
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
||||||
p->to = dest;
|
if (!p) {
|
||||||
p->decoded.want_response = false;
|
validTelemetry = false;
|
||||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
|
||||||
else
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
|
||||||
// release previous packet before occupying a new spot
|
|
||||||
if (lastMeasurementPacket != nullptr)
|
|
||||||
packetPool.release(lastMeasurementPacket);
|
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(*p);
|
|
||||||
if (phoneOnly) {
|
|
||||||
LOG_INFO("Send packet to phone");
|
|
||||||
service->sendToPhone(p);
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Send packet to mesh");
|
p->to = dest;
|
||||||
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
p->decoded.want_response = false;
|
||||||
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
||||||
|
else
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
// release previous packet before occupying a new spot
|
||||||
|
if (lastMeasurementPacket != nullptr)
|
||||||
|
packetPool.release(lastMeasurementPacket);
|
||||||
|
|
||||||
if (isPowerSavingSensor()) {
|
lastMeasurementPacket = packetPool.allocCopy(*p);
|
||||||
meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed();
|
if (phoneOnly) {
|
||||||
if (notification) {
|
LOG_INFO("Send packet to phone");
|
||||||
notification->level = meshtastic_LogRecord_Level_INFO;
|
service->sendToPhone(p);
|
||||||
notification->time = getValidTime(RTCQualityFromNet);
|
} else {
|
||||||
sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment",
|
LOG_INFO("Send packet to mesh");
|
||||||
Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval,
|
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
default_telemetry_broadcast_interval_secs) /
|
|
||||||
1000U);
|
if (isPowerSavingSensor()) {
|
||||||
service->sendClientNotification(notification);
|
meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed();
|
||||||
|
if (notification) {
|
||||||
|
notification->level = meshtastic_LogRecord_Level_INFO;
|
||||||
|
notification->time = getValidTime(RTCQualityFromNet);
|
||||||
|
sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment",
|
||||||
|
Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval,
|
||||||
|
default_telemetry_broadcast_interval_secs) /
|
||||||
|
1000U);
|
||||||
|
service->sendClientNotification(notification);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,23 +248,27 @@ bool HealthTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
sensor_read_error_count = 0;
|
sensor_read_error_count = 0;
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
||||||
p->to = dest;
|
if (!p) {
|
||||||
p->decoded.want_response = false;
|
validTelemetry = false;
|
||||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
|
||||||
else
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
|
||||||
// release previous packet before occupying a new spot
|
|
||||||
if (lastMeasurementPacket != nullptr)
|
|
||||||
packetPool.release(lastMeasurementPacket);
|
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(*p);
|
|
||||||
if (phoneOnly) {
|
|
||||||
LOG_INFO("Send packet to phone");
|
|
||||||
service->sendToPhone(p);
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Send packet to mesh");
|
p->to = dest;
|
||||||
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
p->decoded.want_response = false;
|
||||||
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
||||||
|
else
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
// release previous packet before occupying a new spot
|
||||||
|
if (lastMeasurementPacket != nullptr)
|
||||||
|
packetPool.release(lastMeasurementPacket);
|
||||||
|
|
||||||
|
lastMeasurementPacket = packetPool.allocCopy(*p);
|
||||||
|
if (phoneOnly) {
|
||||||
|
LOG_INFO("Send packet to phone");
|
||||||
|
service->sendToPhone(p);
|
||||||
|
} else {
|
||||||
|
LOG_INFO("Send packet to mesh");
|
||||||
|
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ bool HostMetricsModule::sendMetrics()
|
|||||||
// telemetry.variant.host_metrics.has_user_string ? telemetry.variant.host_metrics.user_string : "");
|
// telemetry.variant.host_metrics.has_user_string ? telemetry.variant.host_metrics.user_string : "");
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
|
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
|
||||||
|
if (!p)
|
||||||
|
return false;
|
||||||
p->to = NODENUM_BROADCAST;
|
p->to = NODENUM_BROADCAST;
|
||||||
p->decoded.want_response = false;
|
p->decoded.want_response = false;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
|||||||
@@ -275,23 +275,27 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
sensor_read_error_count = 0;
|
sensor_read_error_count = 0;
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
meshtastic_MeshPacket *p = allocDataProtobuf(m);
|
||||||
p->to = dest;
|
if (!p) {
|
||||||
p->decoded.want_response = false;
|
validTelemetry = false;
|
||||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
|
||||||
else
|
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
|
||||||
// release previous packet before occupying a new spot
|
|
||||||
if (lastMeasurementPacket != nullptr)
|
|
||||||
packetPool.release(lastMeasurementPacket);
|
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(*p);
|
|
||||||
if (phoneOnly) {
|
|
||||||
LOG_INFO("Send packet to phone");
|
|
||||||
service->sendToPhone(p);
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Send packet to mesh");
|
p->to = dest;
|
||||||
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
p->decoded.want_response = false;
|
||||||
|
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR)
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
||||||
|
else
|
||||||
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
// release previous packet before occupying a new spot
|
||||||
|
if (lastMeasurementPacket != nullptr)
|
||||||
|
packetPool.release(lastMeasurementPacket);
|
||||||
|
|
||||||
|
lastMeasurementPacket = packetPool.allocCopy(*p);
|
||||||
|
if (phoneOnly) {
|
||||||
|
LOG_INFO("Send packet to phone");
|
||||||
|
service->sendToPhone(p);
|
||||||
|
} else {
|
||||||
|
LOG_INFO("Send packet to mesh");
|
||||||
|
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -258,6 +258,8 @@ bool AudioModule::shouldDraw()
|
|||||||
void AudioModule::sendPayload(NodeNum dest, bool wantReplies)
|
void AudioModule::sendPayload(NodeNum dest, bool wantReplies)
|
||||||
{
|
{
|
||||||
meshtastic_MeshPacket *p = allocReply();
|
meshtastic_MeshPacket *p = allocReply();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = wantReplies;
|
p->decoded.want_response = wantReplies;
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ bool PaxcounterModule::sendInfo(NodeNum dest)
|
|||||||
pl.uptime = millis() / 1000;
|
pl.uptime = millis() / 1000;
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataProtobuf(pl);
|
meshtastic_MeshPacket *p = allocDataProtobuf(pl);
|
||||||
|
if (!p)
|
||||||
|
return false;
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = false;
|
p->decoded.want_response = false;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ void GamesModule::announceHighScore(const char *initials, uint32_t score)
|
|||||||
if (!initials || initials[0] == '\0')
|
if (!initials || initials[0] == '\0')
|
||||||
return;
|
return;
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
p->to = NODENUM_BROADCAST;
|
p->to = NODENUM_BROADCAST;
|
||||||
p->channel = 0; // primary channel
|
p->channel = 0; // primary channel
|
||||||
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
|
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ inline void onReceiveProto(char *topic, byte *payload, size_t length)
|
|||||||
// receives it when we get our own packet back. Then we'll stop our retransmissions.
|
// receives it when we get our own packet back. Then we'll stop our retransmissions.
|
||||||
if (isFromUs(e.packet)) {
|
if (isFromUs(e.packet)) {
|
||||||
auto pAck = routingModule->allocAckNak(meshtastic_Routing_Error_NONE, getFrom(e.packet), e.packet->id, ch.index);
|
auto pAck = routingModule->allocAckNak(meshtastic_Routing_Error_NONE, getFrom(e.packet), e.packet->id, ch.index);
|
||||||
|
if (!pAck)
|
||||||
|
return;
|
||||||
pAck->transport_mechanism = meshtastic_MeshPacket_TransportMechanism_TRANSPORT_MQTT;
|
pAck->transport_mechanism = meshtastic_MeshPacket_TransportMechanism_TRANSPORT_MQTT;
|
||||||
if (router->sendLocal(pAck) == ERRNO_SHOULD_RELEASE)
|
if (router->sendLocal(pAck) == ERRNO_SHOULD_RELEASE)
|
||||||
packetPool.release(pAck);
|
packetPool.release(pAck);
|
||||||
|
|||||||
Reference in New Issue
Block a user