Skip to content

Commit a76a14e

Browse files
committed
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.
1 parent 31007d9 commit a76a14e

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/Dispatcher.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,21 @@ void Dispatcher::processRecvPacket(Packet* pkt) {
271271
}
272272
}
273273

274-
void Dispatcher::checkSend() {
275-
if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return;
276-
277-
updateTxBudget();
278-
279-
uint32_t est_airtime = _radio->getEstAirtimeFor(MAX_TRANS_UNIT);
274+
void Dispatcher::ensureTxDutyCycle(int tx_len) {
275+
uint32_t est_airtime = _radio->getEstAirtimeFor(tx_len);
280276
if (tx_budget_ms < est_airtime / MIN_TX_BUDGET_AIRTIME_DIV) {
281277
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
282278
unsigned long needed = est_airtime / MIN_TX_BUDGET_AIRTIME_DIV - tx_budget_ms;
283279
next_tx_time = futureMillis((unsigned long)(needed / duty_cycle));
284-
return;
285280
}
286-
281+
}
282+
283+
void Dispatcher::checkSend() {
284+
if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return;
285+
286+
updateTxBudget();
287+
ensureTxDutyCycle(MAX_TRANS_UNIT);
288+
287289
if (!millisHasNowPassed(next_tx_time)) return;
288290
if (_radio->isReceiving()) {
289291
if (cad_busy_start == 0) {

src/Dispatcher.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ class Dispatcher {
195195

196196
private:
197197
bool tryParsePacket(Packet* pkt, const uint8_t* raw, int len);
198+
/**
199+
* \brief ensure the next tx time obeys the duty cycle
200+
*
201+
* Internally this updates the next_tx_time so that the Tx
202+
* is executed by earliest the next allowed time slot.
203+
*/
204+
void ensureTxDutyCycle(int tx_len);
198205
void checkRecv();
199206
void checkSend();
200207
};

0 commit comments

Comments
 (0)