radio: RX duty cycle (RXPS) from EasySkyMesh PowerSaving v18, opt-in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-12 14:57:16 +01:00
1 parent 507842cea2
commit b06fd957b9
14 files changed
+1386 -1

No files matched your search

+66
View File
@@ -3,6 +3,9 @@
#include "Utils.h"
#include "target.h"
#include <ctype.h>
#ifdef WITH_RX_POWERSAVING
#include "radiolib/RXPowerSavingCLI.h"
#endif
namespace {
@@ -17,8 +20,35 @@ bool looksLikeANumber(const char* s) {
return isdigit((unsigned char)*s) || *s == '.';
}
#ifdef WITH_RX_POWERSAVING
RxPowerSavingControl* rxpsControl() {
#ifdef WRAPPER_CLASS
return &radio_driver;
#else
return nullptr;
#endif
}
#endif
} // namespace
#ifdef WITH_RX_POWERSAVING
bool CommonRadioPrefs::applyRxPowerSaving(uint8_t sf, float bw) {
_active_sf = sf;
_active_bw = bw;
RxPowerSavingConfig* config = getRxPowerSavingConfig();
if (!config) return false;
// temporary radio parameters must not overwrite the saved automatic periods
RxPowerSavingConfig active = *config;
return applyRxPowerSavingConfig(&active, sf, bw, rxpsControl());
}
bool CommonRadioPrefs::isRxPowerSavingCalibrationActive() const {
const auto* control = rxpsControl();
return control && control->isRxPowerSavingCalibrationActive();
}
#endif
bool CommonRadioPrefs::getByKey(const char* key, char* value, size_t max_len) {
if (strcmp(key, "fem_rxgain") == 0) {
snprintf(value, max_len, "%d", (uint32_t)getFEMRxGain());
@@ -45,6 +75,30 @@ bool CommonRadioPrefs::setByKey(const char* key, const char* value) {
}
bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
#ifdef WITH_RX_POWERSAVING
if (strncmp(command, "get radio.rxps", 14) == 0 && (command[14] == 0 || command[14] == ' ')) {
const char* suffix = command + 14;
while (*suffix == ' ') ++suffix;
if (*suffix) return false;
auto* config = getRxPowerSavingConfig();
if (!config) { strcpy(reply, "Error: unsupported"); return true; }
const uint8_t sf = _active_sf ? _active_sf : getSpreadFactor();
const float bw = _active_sf ? _active_bw : getBandwidth();
RxPowerSavingConfig active = *config;
normalizeRxPowerSavingConfig(&active, sf, bw,
rxPowerSavingCaptureCost(rxpsControl()), rxPowerSavingTransition(rxpsControl()));
RXPowerSavingCLI::get(&active, rxpsControl(), sf, bw, reply, 160);
return true;
}
if (strncmp(command, "set radio.rxps ", 15) == 0) {
auto* config = getRxPowerSavingConfig();
if (!config) { strcpy(reply, "Error: unsupported"); return true; }
if (RXPowerSavingCLI::set(command + 15,
_active_sf ? _active_sf : getSpreadFactor(), _active_sf ? _active_bw : getBandwidth(),
config, rxpsControl(), reply, 160)) markDirty();
return true;
}
#endif
if (strcmp(command, "get radio") == 0) {
char freq[16], bw[16];
strcpy(freq, StrHelper::ftoa(getFreq()));
@@ -66,7 +120,19 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
setCodingRate(cr);
setFreq(freq);
setBandwidth(bw);
#ifdef WITH_RX_POWERSAVING
// the RXPS timing is in symbols: a new SF/BW can make it invalid
auto* rxps = getRxPowerSavingConfig();
const bool timing_ok = !rxps || !rxps->enabled || normalizeRxPowerSavingConfig(
rxps, sf, bw, rxPowerSavingCaptureCost(rxpsControl()), rxPowerSavingTransition(rxpsControl()));
if (!timing_ok && rxpsControl()) {
rxpsControl()->setRxPowerSaving(false, rxps->rx_us, rxps->sleep_us);
rxpsControl()->setRxPowerSavingConfigError(true);
}
strcpy(reply, timing_ok ? "OK - reboot to apply" : "OK - reboot to apply; RXPS continuous: invalid timing");
#else
strcpy(reply, "OK - reboot to apply");
#endif
} else {
strcpy(reply, "Error, invalid radio params");
}