From 307bc938b5e408350913b72ad77cd62c2f78e4ce Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Tue, 18 Aug 2026 09:29:12 +0700 Subject: [PATCH] Fixed RXPS for LR1110 --- src/helpers/radiolib/CustomLR1110.h | 23 +++-------- src/helpers/radiolib/CustomLR1110Wrapper.h | 4 +- src/helpers/radiolib/RXPowerSaving.h | 23 ----------- .../test_rx_power_saving.cpp | 38 ------------------- 4 files changed, 7 insertions(+), 81 deletions(-) diff --git a/src/helpers/radiolib/CustomLR1110.h b/src/helpers/radiolib/CustomLR1110.h index d4fc31d34..a49eee835 100644 --- a/src/helpers/radiolib/CustomLR1110.h +++ b/src/helpers/radiolib/CustomLR1110.h @@ -71,6 +71,8 @@ class CustomLR1110 : public LR1110 { int16_t state = standby(RADIOLIB_LR11X0_STANDBY_RC); RADIOLIB_ASSERT(state); // Semtech requires the RC standby/RTC setup before SetRxDutyCycle. + state = configLfClock(RADIOLIB_LR11X0_LF_CLK_RC | RADIOLIB_LR11X0_LF_BUSY_RELEASE_ENABLED); + RADIOLIB_ASSERT(state); RadioModeConfig_t cfg = { .receive = { .timeout = RADIOLIB_LR11X0_RX_TIMEOUT_INF, @@ -79,23 +81,10 @@ class CustomLR1110 : public LR1110 { .len = 0, } }; - return runRxPowerSavingArmTransaction( - [this]() { - return configLfClock( - RADIOLIB_LR11X0_LF_CLK_RC | RADIOLIB_LR11X0_LF_BUSY_RELEASE_ENABLED); - }, - [this, &cfg]() { - return this->stageMode(RADIOLIB_RADIO_MODE_RX, &cfg); - }, - [this, rxPeriodRaw, sleepPeriodRaw]() { - return this->setRxDutyCycle( - rxPeriodRaw, sleepPeriodRaw, RADIOLIB_LR11X0_RX_DUTY_CYCLE_MODE_RX); - }, - [this]() { - // Preserve the arm error even if this best-effort rollback fails. - // A failed ConfigLfClock response may still mean the command ran. - restoreLfClock(); - }); + + state = stageMode(RADIOLIB_RADIO_MODE_RX, &cfg); + RADIOLIB_ASSERT(state); + return setRxDutyCycle(rxPeriodRaw, sleepPeriodRaw, RADIOLIB_LR11X0_RX_DUTY_CYCLE_MODE_RX); } int16_t setRxBoostedGainMode(bool en) { diff --git a/src/helpers/radiolib/CustomLR1110Wrapper.h b/src/helpers/radiolib/CustomLR1110Wrapper.h index d93ccca9c..36faeae36 100644 --- a/src/helpers/radiolib/CustomLR1110Wrapper.h +++ b/src/helpers/radiolib/CustomLR1110Wrapper.h @@ -58,9 +58,7 @@ protected: } int16_t stopDutyCycleHardware() override { - int16_t standby_err = _radio->standby(); - int16_t lf_err = ((CustomLR1110 *)_radio)->restoreLfClock(); - return standby_err != RADIOLIB_ERR_NONE ? standby_err : lf_err; + return _radio->standby(); } public: diff --git a/src/helpers/radiolib/RXPowerSaving.h b/src/helpers/radiolib/RXPowerSaving.h index 473e5f29f..7768c189b 100644 --- a/src/helpers/radiolib/RXPowerSaving.h +++ b/src/helpers/radiolib/RXPowerSaving.h @@ -29,29 +29,6 @@ public: uint8_t consecutiveFailures() const { return _consecutive_failures; } }; -// Runs the part of a hardware arm sequence that starts by changing persistent -// radio configuration. Every failing step rolls that configuration back, while -// the original arm error remains the result returned to the caller. -template -int16_t runRxPowerSavingArmTransaction(Configure configure, Stage stage, - Arm arm, Rollback rollback) { - int16_t state = configure(); - if (state != 0) { - rollback(); - return state; - } - - state = stage(); - if (state != 0) { - rollback(); - return state; - } - - state = arm(); - if (state != 0) rollback(); - return state; -} - struct RxPowerSavingConfig { uint8_t enabled = 0; uint32_t rx_us = RX_POWERSAVING_DEFAULT_RX_US; diff --git a/test/test_rx_power_saving/test_rx_power_saving.cpp b/test/test_rx_power_saving/test_rx_power_saving.cpp index 3c769e0ac..f699e3bd9 100644 --- a/test/test_rx_power_saving/test_rx_power_saving.cpp +++ b/test/test_rx_power_saving/test_rx_power_saving.cpp @@ -89,44 +89,6 @@ TEST(RxPowerSaving, ClearingRetryStateGrantsThreeFreshAttempts) { EXPECT_EQ(retry.consecutiveFailures(), 0); } -TEST(RxPowerSaving, ArmTransactionRollsBackEveryFailureAndPreservesItsError) { - for (int failing_step = 0; failing_step < 3; failing_step++) { - int calls[3] = {0, 0, 0}; - int rollback_calls = 0; - auto step = [&](int index) -> int16_t { - calls[index]++; - return index == failing_step ? (int16_t)(-700 - index) : (int16_t)0; - }; - - int16_t result = runRxPowerSavingArmTransaction( - [&]() { return step(0); }, - [&]() { return step(1); }, - [&]() { return step(2); }, - [&]() { rollback_calls++; }); - - EXPECT_EQ(result, -700 - failing_step); - EXPECT_EQ(rollback_calls, 1); - for (int index = 0; index < 3; index++) { - EXPECT_EQ(calls[index], index <= failing_step ? 1 : 0); - } - } -} - -TEST(RxPowerSaving, ArmTransactionDoesNotRollBackSuccessfulArm) { - int step_calls = 0; - int rollback_calls = 0; - - int16_t result = runRxPowerSavingArmTransaction( - [&]() -> int16_t { step_calls++; return 0; }, - [&]() -> int16_t { step_calls++; return 0; }, - [&]() -> int16_t { step_calls++; return 0; }, - [&]() { rollback_calls++; }); - - EXPECT_EQ(result, 0); - EXPECT_EQ(step_calls, 3); - EXPECT_EQ(rollback_calls, 0); -} - TEST(RxPowerSaving, RejectsInvalidProfileInputs) { uint32_t rx_us = 0; uint32_t sleep_us = 0;