From 189ed79d464a96393d7302c6355982b9a3494e97 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Thu, 27 Feb 2025 04:05:50 +1100 Subject: [PATCH] * new Dispatcher::getCADFailRetryDelay() --- examples/simple_repeater/main.cpp | 2 +- examples/simple_room_server/main.cpp | 2 +- src/Dispatcher.cpp | 9 ++++++++- src/Dispatcher.h | 1 + src/Mesh.cpp | 4 ++++ src/Mesh.h | 2 ++ src/helpers/CustomLLCC68Wrapper.h | 7 +++++-- src/helpers/CustomLR1110Wrapper.h | 7 +++++-- src/helpers/CustomSX1262Wrapper.h | 7 +++++-- src/helpers/CustomSX1268Wrapper.h | 7 +++++-- src/helpers/CustomSX1276Wrapper.h | 7 +++++-- src/helpers/RadioLibWrappers.cpp | 14 ++++++++++++-- src/helpers/RadioLibWrappers.h | 1 + 13 files changed, 55 insertions(+), 15 deletions(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 5dcaaf8d..4f1bdde3 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -20,7 +20,7 @@ /* ------------------------------ Config -------------------------------- */ -#define FIRMWARE_VER_TEXT "v5 (build: 25 Feb 2025)" +#define FIRMWARE_VER_TEXT "v6 (build: 27 Feb 2025)" #ifndef LORA_FREQ #define LORA_FREQ 915.0 diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index df7dd65a..5978be7f 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -20,7 +20,7 @@ /* ------------------------------ Config -------------------------------- */ -#define FIRMWARE_VER_TEXT "v5 (build: 25 Feb 2025)" +#define FIRMWARE_VER_TEXT "v6 (build: 27 Feb 2025)" #ifndef LORA_FREQ #define LORA_FREQ 915.0 diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index b45aaed8..3c351eb7 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -26,6 +26,10 @@ int Dispatcher::calcRxDelay(float score, uint32_t air_time) const { return (int) ((pow(10, 0.85f - score) - 1.0) * air_time); } +uint32_t Dispatcher::getCADFailRetryDelay() const { + return 200; +} + void Dispatcher::loop() { if (outbound) { // waiting for outbound send to be completed if (_radio->isSendComplete()) { @@ -165,7 +169,10 @@ void Dispatcher::processRecvPacket(Packet* pkt) { void Dispatcher::checkSend() { if (_mgr->getOutboundCount() == 0) return; // nothing waiting to send if (!millisHasNowPassed(next_tx_time)) return; // still in 'radio silence' phase (from airtime budget setting) - if (_radio->isReceiving()) return; // LBT - check if radio is currently mid-receive, or if channel activity + if (_radio->isReceiving()) { // LBT - check if radio is currently mid-receive, or if channel activity + next_tx_time = futureMillis(getCADFailRetryDelay()); + return; + } outbound = _mgr->getNextOutbound(_ms->getMillis()); if (outbound) { diff --git a/src/Dispatcher.h b/src/Dispatcher.h index e2ba60cb..7d75c219 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -124,6 +124,7 @@ protected: virtual float getAirtimeBudgetFactor() const; virtual int calcRxDelay(float score, uint32_t air_time) const; + virtual uint32_t getCADFailRetryDelay() const; public: void begin(); diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 8c0759e8..95a1d6d7 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -23,6 +23,10 @@ uint32_t Mesh::getDirectRetransmitDelay(const Packet* packet) { return 0; // by default, no delay } +uint32_t Mesh::getCADFailRetryDelay() const { + return _rng->nextInt(1, 4)*120; +} + int Mesh::searchPeersByHash(const uint8_t* hash) { return 0; // not found } diff --git a/src/Mesh.h b/src/Mesh.h index 41f10863..4647464e 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -58,6 +58,8 @@ class Mesh : public Dispatcher { protected: DispatcherAction onRecvPacket(Packet* pkt) override; + virtual uint32_t getCADFailRetryDelay() const override; + /** * \brief Decide what to do with received packet, ie. discard, forward, or hold */ diff --git a/src/helpers/CustomLLCC68Wrapper.h b/src/helpers/CustomLLCC68Wrapper.h index 4777e8df..c7d95c41 100644 --- a/src/helpers/CustomLLCC68Wrapper.h +++ b/src/helpers/CustomLLCC68Wrapper.h @@ -12,8 +12,11 @@ public: idle(); // put sx126x into standby // do some basic CAD (blocks for ~12780 micros (on SF 10)!) bool activity = (((CustomLLCC68 *)_radio)->scanChannel() == RADIOLIB_LORA_DETECTED); - idle(); - + if (activity) { + startRecv(); + } else { + idle(); + } return activity; } float getLastRSSI() const override { return ((CustomLLCC68 *)_radio)->getRSSI(); } diff --git a/src/helpers/CustomLR1110Wrapper.h b/src/helpers/CustomLR1110Wrapper.h index a3edfcb8..fb3a4b91 100644 --- a/src/helpers/CustomLR1110Wrapper.h +++ b/src/helpers/CustomLR1110Wrapper.h @@ -12,8 +12,11 @@ public: idle(); // put sx126x into standby // do some basic CAD (blocks for ~12780 micros (on SF 10)!) bool activity = (((CustomLR1110 *)_radio)->scanChannel() == RADIOLIB_LORA_DETECTED); - idle(); - + if (activity) { + startRecv(); + } else { + idle(); + } return activity; } diff --git a/src/helpers/CustomSX1262Wrapper.h b/src/helpers/CustomSX1262Wrapper.h index 9bfb57cd..ea2da5fe 100644 --- a/src/helpers/CustomSX1262Wrapper.h +++ b/src/helpers/CustomSX1262Wrapper.h @@ -13,8 +13,11 @@ public: idle(); // put sx126x into standby // do some basic CAD (blocks for ~12780 micros (on SF 10)!) bool activity = (((CustomSX1262 *)_radio)->scanChannel() == RADIOLIB_LORA_DETECTED); - idle(); - + if (activity) { + startRecv(); + } else { + idle(); + } return activity; } float getLastRSSI() const override { return ((CustomSX1262 *)_radio)->getRSSI(); } diff --git a/src/helpers/CustomSX1268Wrapper.h b/src/helpers/CustomSX1268Wrapper.h index bd6ddfaf..f9eee447 100644 --- a/src/helpers/CustomSX1268Wrapper.h +++ b/src/helpers/CustomSX1268Wrapper.h @@ -12,8 +12,11 @@ public: idle(); // put sx126x into standby // do some basic CAD (blocks for ~12780 micros (on SF 10)!) bool activity = (((CustomSX1268 *)_radio)->scanChannel() == RADIOLIB_LORA_DETECTED); - idle(); - + if (activity) { + startRecv(); + } else { + idle(); + } return activity; } float getLastRSSI() const override { return ((CustomSX1268 *)_radio)->getRSSI(); } diff --git a/src/helpers/CustomSX1276Wrapper.h b/src/helpers/CustomSX1276Wrapper.h index 23e9b72e..f9900705 100644 --- a/src/helpers/CustomSX1276Wrapper.h +++ b/src/helpers/CustomSX1276Wrapper.h @@ -12,8 +12,11 @@ public: idle(); // put into standby // do some basic CAD (blocks for ~12780 micros (on SF 10)!) bool activity = (((CustomSX1276 *)_radio)->tryScanChannel() == RADIOLIB_PREAMBLE_DETECTED); - idle(); - + if (activity) { + startRecv(); + } else { + idle(); + } return activity; } float getLastRSSI() const override { return ((CustomSX1276 *)_radio)->getRSSI(); } diff --git a/src/helpers/RadioLibWrappers.cpp b/src/helpers/RadioLibWrappers.cpp index 41abb382..8d133ccd 100644 --- a/src/helpers/RadioLibWrappers.cpp +++ b/src/helpers/RadioLibWrappers.cpp @@ -35,6 +35,15 @@ void RadioLibWrapper::idle() { state = STATE_IDLE; // need another startReceive() } +void RadioLibWrapper::startRecv() { + int err = _radio->startReceive(); + if (err == RADIOLIB_ERR_NONE) { + state = STATE_RX; + } else { + MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startReceive(%d)", err); + } +} + int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { if (state & STATE_INT_READY) { int len = _radio->getPacketLength(); @@ -54,10 +63,11 @@ int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { if (state != STATE_RX) { int err = _radio->startReceive(); - if (err != RADIOLIB_ERR_NONE) { + if (err == RADIOLIB_ERR_NONE) { + state = STATE_RX; + } else { MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startReceive(%d)", err); } - state = STATE_RX; } return 0; } diff --git a/src/helpers/RadioLibWrappers.h b/src/helpers/RadioLibWrappers.h index a4ec52cf..c9621cf6 100644 --- a/src/helpers/RadioLibWrappers.h +++ b/src/helpers/RadioLibWrappers.h @@ -10,6 +10,7 @@ protected: uint32_t n_recv, n_sent; void idle(); + void startRecv(); float packetScoreInt(float snr, int sf, int packet_len); public: