From cbf4cb3c4a013865f3a0ebb9b7b9eae9990ccd3e Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Tue, 1 Sep 2026 19:34:16 +0200 Subject: [PATCH] =?UTF-8?q?fix(radio):=20fallback=20v=20calcMaxPacketMilli?= =?UTF-8?q?s=20podt=C3=A9kal=20a=20uzel=20z=20toho=20ohluchl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Funkce je nová v 1.17 a krmí `_preambleMillis` / `_maxPayloadMillis` do stavového `isReceiving()` každého SX126x a LR11x0 wrapperu. Její fallback pro případ, kdy `getTimeOnAir()` ještě není použitelný, byl napsaný jako `4000 - preamble_us` -- mělo to znamenat "4 sekundy v nejhorším případě", jenže jednotka jsou MIKROsekundy, takže to byly 4 ms. Oba operandy jsou unsigned. Náš CZ preset (SF8 / BW62.5) má symbol ~4,1 ms a preambuli ~116 ms, takže odečtení přeteče na ~4,29e9 us a `_maxPayloadMillis` vyjde ~4,29 milionu sekund. `isReceiving()` pak zachycený header nikdy nevytimeoutuje, hlásí "právě přijímám" napořád, RX se už nikdy nepřezbrojí -- a uzel ohluchne, i když dál normálně vysílá. Žádné acky, žádné kanálové zprávy, žádné adverty, a přitom je ve vzduchu všechno vidět. Spustí se to jen na desce, kde `getTimeOnAir()` v okamžiku `setParams()` nevrátí použitelnou hodnotu, což u nás zatím nenastalo. Ale míří to přesně na náš preset a na všechna naše rádia (SX1262 i LR1110), tak ať tam ta past neleží. Převzato z ALLFATHER-BV/meshcomod d6a72f8 (MIT). Upstream to pořád má. Co-Authored-By: Claude Opus 5 (1M context) --- src/helpers/radiolib/RadioLibWrappers.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/helpers/radiolib/RadioLibWrappers.cpp b/src/helpers/radiolib/RadioLibWrappers.cpp index d655107b..5c89809c 100644 --- a/src/helpers/radiolib/RadioLibWrappers.cpp +++ b/src/helpers/radiolib/RadioLibWrappers.cpp @@ -347,8 +347,24 @@ PacketMillis RadioLibWrapper::calcMaxPacketMillis(uint8_t sf, float bw, uint8_t // airtime for max packet at current radio settings uint32_t total_us = _radio->getTimeOnAir(MAX_TRANS_UNIT); - // airtime for payload only (no preamble, header or SOF) - uint32_t payload_us = total_us > preamble_us ? total_us - preamble_us : 4000 - preamble_us; // fallback to 4 secs at worst case + // airtime for payload only (no preamble, header or SOF). + // + // CUSTOM (TeTeHacko): the fallback taken when getTimeOnAir() is not usable yet + // must not underflow. Upstream writes the intended "4 secs at worst case" as + // 4000 -- these are MICROseconds, so 4 ms -- and then subtracts an unsigned + // preamble from it. Our CZ preset (SF8 / BW62.5) has a ~4.1 ms symbol time and + // a ~116 ms preamble, so the subtraction wraps to ~4.29e9 us and + // _maxPayloadMillis becomes ~4.29 million seconds. isReceiving() can then never + // time out a header it has latched: the radio reports "busy receiving" forever, + // RX is never re-armed, and the node goes deaf while still transmitting + // normally -- no acks, no channel messages, no adverts. + // + // Every SX126x/LR11x0 wrapper feeds this into its stateful isReceiving(), so it + // reaches the T1000-E and the Wio L1 as much as the SenseCap boards. + // Fix taken from ALLFATHER-BV/meshcomod d6a72f8 (MIT). + const uint32_t fallback_total_us = 4000000; // 4 SECONDS, in microseconds + const uint32_t base_us = (total_us > preamble_us) ? total_us : fallback_total_us; + uint32_t payload_us = (base_us > preamble_us) ? (base_us - preamble_us) : (base_us / 2); // rescale payload_us for max possible CR if (cr >= 5 && cr < 8) { payload_us = (payload_us * 8) / cr; }