From 2f291ddbf5dd6d1f145a23a7bb18276ecd1cf825 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 7 Sep 2025 13:07:55 +0100 Subject: [PATCH] [SX126x] Simplify receive timeout duration (5x ToA instead of 100 symbols) --- src/modules/SX126x/SX126x.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 922e9389..50de53cc 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -256,24 +256,10 @@ int16_t SX126x::receive(uint8_t* data, size_t len, RadioLibTime_t timeout) { RadioLibTime_t timeoutInternal = timeout; if(!timeoutInternal) { - // get currently active modem - uint8_t modem = getPacketType(); - if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { - // calculate timeout (100 LoRa symbols, the default for SX127x series) - float symbolLength = (float)(uint32_t(1) << this->spreadingFactor) / (float)this->bandwidthKhz; - timeoutInternal = (RadioLibTime_t)(symbolLength * 100.0f); - - } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { - // calculate timeout (500 % of expected time-one-air) - size_t maxLen = len; - if(len == 0) { maxLen = 0xFF; } - float brBps = (RADIOLIB_SX126X_CRYSTAL_FREQ * 1000000.0f * 32.0f) / (float)this->bitRate; - timeoutInternal = (RadioLibTime_t)(((maxLen * 8.0f) / brBps) * 1000.0f * 5.0f); - - } else { - return(RADIOLIB_ERR_UNKNOWN); - - } + // calculate timeout (500 % of expected time-one-air) + size_t maxLen = len; + if(len == 0) { maxLen = RADIOLIB_SX126X_MAX_PACKET_LENGTH; } + timeoutInternal = (getTimeOnAir(maxLen) * 5) / 1000; } RADIOLIB_DEBUG_BASIC_PRINTLN("Timeout in %lu ms", timeoutInternal);