Skip to content

Commit dfe1eea

Browse files
committed
fix: use max estimated airtime for duty cycle enforcement
Previously the max required airtime to enter the next transmit slot was computed to be half the estimated time. However, the transmit logic uses 1.5 times the estimated time as maximum TX duration. By that, the duty cycle could still be violated as the actual transmit logic might send for longer than what we ensured to stay within the cycle. We fix this by aligning both computations and always use 1.5 times the estimated airtime. Xref: #817
1 parent 7058790 commit dfe1eea

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/Dispatcher.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ namespace mesh {
1010

1111
#define MAX_RX_DELAY_MILLIS 32000 // 32 seconds
1212
#define MIN_TX_BUDGET_RESERVE_MS 100 // min budget (ms) required before allowing next TX
13-
#define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX
1413
/// add some time to get the max allowed airtime for the est. airtime
15-
#define MAX_TX_AIRTIME_FOR_EST(est_airtime) ((est_airtime * 3) / 2)
14+
#define MAX_TX_AIRTIME_FOR_EST(est_airtime) (((est_airtime) * 3) / 2)
1615

1716
#ifndef NOISE_FLOOR_CALIB_INTERVAL
1817
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
@@ -275,9 +274,9 @@ void Dispatcher::processRecvPacket(Packet* pkt) {
275274

276275
void Dispatcher::ensureTxDutyCycle(int tx_len) {
277276
uint32_t est_airtime = _radio->getEstAirtimeFor(tx_len);
278-
if (tx_budget_ms < est_airtime / MIN_TX_BUDGET_AIRTIME_DIV) {
277+
if (tx_budget_ms < MAX_TX_AIRTIME_FOR_EST(est_airtime)) {
279278
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
280-
unsigned long needed = est_airtime / MIN_TX_BUDGET_AIRTIME_DIV - tx_budget_ms;
279+
unsigned long needed = MAX_TX_AIRTIME_FOR_EST(est_airtime) - tx_budget_ms;
281280
next_tx_time = futureMillis((unsigned long)(needed / duty_cycle));
282281
}
283282
}

0 commit comments

Comments
 (0)