From 4f4224b4aac320ca8b4143581592a7a27ff98265 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Sun, 17 Nov 2024 17:51:01 +0100 Subject: [PATCH] Move some actions to after `startTransmit()` (#5383) To minimize the time between channel scan and actual transmit --- src/mesh/RadioInterface.cpp | 2 -- src/mesh/RadioLibInterface.cpp | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index f0d137e2cd..53b66ff0ae 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -601,8 +601,6 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p) // LOG_DEBUG("Send queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)", rf95.txGood(), rf95.rxGood(), rf95.rxBad()); assert(p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag); // It should have already been encoded by now - lastTxStart = millis(); - radioBuffer.header.from = p->from; radioBuffer.header.to = p->to; radioBuffer.header.id = p->id; diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 23ef3d6f12..5f82a41ced 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -278,7 +278,8 @@ void RadioLibInterface::onNotify(uint32_t notification) startReceive(); // try receiving this packet, afterwards we'll be trying to transmit again setTransmitDelay(); } else { - // Send any outgoing packets we have ready + // Send any outgoing packets we have ready as fast as possible to keep the time between channel scan and + // actual transmission as short as possible meshtastic_MeshPacket *txp = txQueue.dequeue(); assert(txp); bool sent = startSend(txp); @@ -470,7 +471,8 @@ void RadioLibInterface::setStandby() /** start an immediate transmit */ bool RadioLibInterface::startSend(meshtastic_MeshPacket *txp) { - printPacket("Start low level send", txp); + /* NOTE: Minimize the actions before startTransmit() to keep the time between + channel scan and actual transmit as low as possible to avoid collisions. */ if (disabled || !config.lora.tx_enabled) { LOG_WARN("Drop Tx packet because LoRa Tx disabled"); packetPool.release(txp); @@ -489,6 +491,9 @@ bool RadioLibInterface::startSend(meshtastic_MeshPacket *txp) completeSending(); powerMon->clearState(meshtastic_PowerMon_State_Lora_TXOn); // Transmitter off now startReceive(); // Restart receive mode (because startTransmit failed to put us in xmit mode) + } else { + lastTxStart = millis(); + printPacket("Started Tx", txp); } // Must be done AFTER, starting transmit, because startTransmit clears (possibly stale) interrupt pending register