[LoRaWAN] Use new stageMode and launchMode, reduce scanGuard

This commit is contained in:
StevenCellist 2025-02-02 00:13:02 +01:00
parent 43f58e1b1f
commit c43b89dc42
2 changed files with 14 additions and 6 deletions

View file

@ -1364,9 +1364,18 @@ int16_t LoRaWANNode::receiveCommon(uint8_t dir, const LoRaWANChannel_t* dlChanne
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// calculate the Rx timeout // calculate the Rx timeout
RadioLibTime_t timeoutHost = this->phyLayer->getTimeOnAir(0) + 2*this->scanGuard*1000; RadioLibTime_t timeoutHost = this->phyLayer->getTimeOnAir(0) + this->scanGuard*1000;
RadioLibTime_t timeoutMod = this->phyLayer->calculateRxTimeout(timeoutHost); RadioLibTime_t timeoutMod = this->phyLayer->calculateRxTimeout(timeoutHost);
// TODO remove default arguments
RadioModeConfig_t modeCfg;
modeCfg.receive.timeout = timeoutMod;
modeCfg.receive.irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS;
modeCfg.receive.irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK;
modeCfg.receive.len = 0;
state = this->phyLayer->stageMode(RADIOLIB_RADIO_MODE_RX, modeCfg);
RADIOLIB_ASSERT(state);
// wait for the start of the Rx window // wait for the start of the Rx window
RadioLibTime_t waitLen = tReference + dlDelays[window] - mod->hal->millis(); RadioLibTime_t waitLen = tReference + dlDelays[window] - mod->hal->millis();
// make sure that no underflow occured; if so, clip the delay (although this will likely miss any downlink) // make sure that no underflow occured; if so, clip the delay (although this will likely miss any downlink)
@ -1380,14 +1389,13 @@ int16_t LoRaWANNode::receiveCommon(uint8_t dir, const LoRaWANChannel_t* dlChanne
mod->hal->delay(waitLen); mod->hal->delay(waitLen);
// open Rx window by starting receive with specified timeout // open Rx window by starting receive with specified timeout
// TODO remove default arguments state = this->phyLayer->launchMode();
state = this->phyLayer->startReceive(timeoutMod, RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK, 0);
tOpen = mod->hal->millis(); tOpen = mod->hal->millis();
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Opening Rx%d window (%d ms timeout)... <-- Rx Delay end ", window, (int)(timeoutHost / 1000 + scanGuard / 2)); RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Opening Rx%d window (%d ms timeout)... <-- Rx Delay end ", window, (int)(timeoutHost / 1000 + 2));
// wait for the timeout to complete (and a small additional delay) // wait for the timeout to complete (and a small additional delay)
mod->hal->delay(timeoutHost / 1000 + this->scanGuard / 2); mod->hal->delay(timeoutHost / 1000 + 2);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Closing Rx%d window", window); RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Closing Rx%d window", window);
// if the IRQ bit for Rx Timeout is not set, something is received, so stop the windows // if the IRQ bit for Rx Timeout is not set, something is received, so stop the windows

View file

@ -850,7 +850,7 @@ class LoRaWANNode {
500 is the **maximum** value, but it is not a good idea to go anywhere near that. 500 is the **maximum** value, but it is not a good idea to go anywhere near that.
If you have to go above 50 you probably have a bug somewhere. Check your device timing. If you have to go above 50 you probably have a bug somewhere. Check your device timing.
*/ */
RadioLibTime_t scanGuard = 10; RadioLibTime_t scanGuard = 4;
#if !RADIOLIB_GODMODE #if !RADIOLIB_GODMODE
protected: protected: