Skip to content

Commit d4b6f15

Browse files
committed
refactor: move max airtime computation to macro
By that we make it reusable and also ensure the integer division is executed correctly (it was correct before, but just because the mult and div operator are left associating).
1 parent a76a14e commit d4b6f15

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/Dispatcher.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace mesh {
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
1313
#define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX
14+
/// 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)
1416

1517
#ifndef NOISE_FLOOR_CALIB_INTERVAL
1618
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
@@ -325,7 +327,7 @@ void Dispatcher::checkSend() {
325327
} else {
326328
memcpy(&raw[len], outbound->payload, outbound->payload_len); len += outbound->payload_len;
327329

328-
uint32_t max_airtime = _radio->getEstAirtimeFor(len)*3/2;
330+
uint32_t max_airtime = MAX_TX_AIRTIME_FOR_EST(_radio->getEstAirtimeFor(len));
329331
outbound_start = _ms->getMillis();
330332
bool success = _radio->startSendRaw(raw, len);
331333
if (!success) {

0 commit comments

Comments
 (0)