Skip to content

Commit

Permalink
Release no-LoRa packet after sending to phone (#5254)
Browse files Browse the repository at this point in the history
  • Loading branch information
GUVWAF authored Nov 4, 2024
1 parent f3b6989 commit 7ba6d97
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,14 @@ void MeshService::sendToMesh(meshtastic_MeshPacket *p, RxSource src, bool ccToPh
LOG_DEBUG("Can't send status to phone");
}

if (res == ERRNO_OK && ccToPhone) { // Check if p is not released in case it couldn't be sent
if ((res == ERRNO_OK || res == ERRNO_SHOULD_RELEASE) && ccToPhone) { // Check if p is not released in case it couldn't be sent
sendToPhone(packetPool.allocCopy(*p));
}

// Router may ask us to release the packet if it wasn't sent
if (res == ERRNO_SHOULD_RELEASE) {
releaseToPool(p);
}
}

bool MeshService::trySendPosition(NodeNum dest, bool wantReplies)
Expand Down
1 change: 1 addition & 0 deletions src/mesh/MeshTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef uint32_t PacketId; // A packet sequence number
#define ERRNO_NO_INTERFACES 33
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
#define ERRNO_DISABLED 34 // the interface is disabled
#define ERRNO_SHOULD_RELEASE 35 // no error, but the packet should still be released
#define ID_COUNTER_MASK (UINT32_MAX >> 22) // mask to select the counter portion of the ID

/*
Expand Down
23 changes: 13 additions & 10 deletions src/mesh/RadioLibInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ ErrorCode RadioLibInterface::send(meshtastic_MeshPacket *p)

#endif

if (p->to == NODENUM_BROADCAST_NO_LORA) {
LOG_DEBUG("Drop no-LoRa pkt");
return ERRNO_SHOULD_RELEASE;
}

// Sometimes when testing it is useful to be able to never turn on the xmitter
#ifndef LORA_DISABLE_SENDING
printPacket("enqueuing for send", p);
Expand Down Expand Up @@ -276,10 +281,8 @@ void RadioLibInterface::onNotify(uint32_t notification)
// Send any outgoing packets we have ready
meshtastic_MeshPacket *txp = txQueue.dequeue();
assert(txp);
bool isLoraTx = txp->to != NODENUM_BROADCAST_NO_LORA;
startSend(txp);

if (isLoraTx) {
bool sent = startSend(txp);
if (sent) {
// Packet has been sent, count it toward our TX airtime utilization.
uint32_t xmitMsec = getPacketTime(txp);
airTime->logAirtime(TX_LOG, xmitMsec);
Expand Down Expand Up @@ -465,15 +468,13 @@ void RadioLibInterface::setStandby()
}

/** start an immediate transmit */
void RadioLibInterface::startSend(meshtastic_MeshPacket *txp)
bool RadioLibInterface::startSend(meshtastic_MeshPacket *txp)
{
printPacket("Start low level send", txp);
if (txp->to == NODENUM_BROADCAST_NO_LORA) {
LOG_DEBUG("Drop Tx packet because dest is broadcast no-lora");
packetPool.release(txp);
} else if (disabled || !config.lora.tx_enabled) {
if (disabled || !config.lora.tx_enabled) {
LOG_WARN("Drop Tx packet because LoRa Tx disabled");
packetPool.release(txp);
return false;
} else {
configHardwareForSend(); // must be after setStandby

Expand All @@ -493,5 +494,7 @@ void RadioLibInterface::startSend(meshtastic_MeshPacket *txp)
// Must be done AFTER, starting transmit, because startTransmit clears (possibly stale) interrupt pending register
// bits
enableInterrupt(isrTxLevel0);

return res == RADIOLIB_ERR_NONE;
}
}
}
3 changes: 2 additions & 1 deletion src/mesh/RadioLibInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified

/** start an immediate transmit
* This method is virtual so subclasses can hook as needed, subclasses should not call directly
* @return true if packet was sent
*/
virtual void startSend(meshtastic_MeshPacket *txp);
virtual bool startSend(meshtastic_MeshPacket *txp);

meshtastic_QueueStatus getQueueStatus();

Expand Down

0 comments on commit 7ba6d97

Please sign in to comment.