RX power saving using rx duty cycle

This commit is contained in:
Jarosław Domański committed 2026-08-14 16:11:21 +02:00
1 parent d929643524
commit 285cf10a7a
17 files changed
+1436 -40

No files matched your search

+29 -1
View File
@@ -1,5 +1,28 @@
#include "MyMesh.h"
#include <algorithm>
#include "helpers/radiolib/RXPowerSaving.h"
static RxPowerSavingControl* getRxPowerSavingControl() {
#ifdef WRAPPER_CLASS
return &radio_driver;
#else
return nullptr;
#endif
}
static void applyRxPowerSavingConfig(NodePrefs& prefs, uint8_t sf, float bw) {
normalizeRxPowerSavingConfig(&prefs.rxps, sf, bw);
RxPowerSavingControl* control = getRxPowerSavingControl();
bool ok = control != nullptr
? control->setRxPowerSaving(
prefs.rxps.enabled != 0, prefs.rxps.rx_us, prefs.rxps.sleep_us)
: prefs.rxps.enabled == 0;
MESH_DEBUG_PRINTLN("RX Power Saving: desired=%s, rx=%lu, sleep=%lu, %s",
prefs.rxps.enabled ? "on" : "off",
(unsigned long)prefs.rxps.rx_us,
(unsigned long)prefs.rxps.sleep_us,
ok ? "accepted" : "unsupported");
}
/* ------------------------------ Config -------------------------------- */
@@ -862,7 +885,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
mesh::RTCClock &rtc, mesh::MeshTables &tables)
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
region_map(key_store), temp_map(key_store),
_cli(board, rtc, sensors, region_map, acl, &_prefs, this),
_cli(board, rtc, sensors, region_map, acl, &_prefs, this, getRxPowerSavingControl()),
telemetry(MAX_PACKET_PAYLOAD - 4),
discover_limiter(4, 120), // max 4 every 2 minutes
anon_limiter(4, 180) // max 4 every 3 minutes
@@ -983,6 +1006,7 @@ void MyMesh::begin(FILESYSTEM *fs) {
radio_driver.getRxBoostedGainMode() ? "Enabled" : "Disabled");
board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain);
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
applyRxPowerSavingConfig(_prefs, _prefs.sf, _prefs.bw);
updateAdvertTimer();
updateFloodAdvertTimer();
@@ -1308,12 +1332,14 @@ void MyMesh::loop() {
if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params
set_radio_at = 0; // clear timer
radio_driver.setParams(pending_freq, pending_bw, pending_sf, pending_cr);
applyRxPowerSavingConfig(_prefs, pending_sf, pending_bw);
MESH_DEBUG_PRINTLN("Temp radio params");
}
if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig
revert_radio_at = 0; // clear timer
radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
applyRxPowerSavingConfig(_prefs, _prefs.sf, _prefs.bw);
MESH_DEBUG_PRINTLN("Radio params restored");
}
@@ -1334,5 +1360,7 @@ bool MyMesh::hasPendingWork() const {
#if defined(WITH_BRIDGE)
if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep
#endif
const RxPowerSavingControl* control = getRxPowerSavingControl();
if (control != nullptr && control->isRxPowerSavingCalibrationActive()) return true;
return _mgr->getOutboundTotal() > 0;
}