mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-10-23 08:43:48 +00:00
Fixed RXPS for LR1110
This commit is contained in:
1 parent
a5a519ac31
commit
307bc938b5
4 files changed
+7
-81
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 <typename Configure, typename Stage, typename Arm, typename Rollback>
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user