From 7c1dfd9a95ef157323a1c4c7355c4e19f9aefe43 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sat, 28 Mar 2026 12:25:31 +0100 Subject: [PATCH] refactor: move tx duty cycle check to function As a preparation to make the tx duty cycle check more precise, we move it into a function. --- src/Dispatcher.cpp | 18 ++++++++++-------- src/Dispatcher.h | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 9d7a1113..50ddbe5a 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -271,19 +271,21 @@ void Dispatcher::processRecvPacket(Packet* pkt) { } } -void Dispatcher::checkSend() { - if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return; - - updateTxBudget(); - - uint32_t est_airtime = _radio->getEstAirtimeFor(MAX_TRANS_UNIT); +void Dispatcher::ensureTxDutyCycle(int tx_len) { + uint32_t est_airtime = _radio->getEstAirtimeFor(tx_len); if (tx_budget_ms < est_airtime / MIN_TX_BUDGET_AIRTIME_DIV) { float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor()); unsigned long needed = est_airtime / MIN_TX_BUDGET_AIRTIME_DIV - tx_budget_ms; next_tx_time = futureMillis((unsigned long)(needed / duty_cycle)); - return; } - +} + +void Dispatcher::checkSend() { + if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return; + + updateTxBudget(); + ensureTxDutyCycle(MAX_TRANS_UNIT); + if (!millisHasNowPassed(next_tx_time)) return; if (_radio->isReceiving()) { if (cad_busy_start == 0) { diff --git a/src/Dispatcher.h b/src/Dispatcher.h index 2a99d068..c488400f 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -195,6 +195,13 @@ public: private: bool tryParsePacket(Packet* pkt, const uint8_t* raw, int len); + /** + * \brief ensure the next tx time obeys the duty cycle + * + * Internally this updates the next_tx_time so that the Tx + * is executed by earliest the next allowed time slot. + */ + void ensureTxDutyCycle(int tx_len); void checkRecv(); void checkSend(); };