Added RXPSv2 for sensor firmware

This commit is contained in:
Kevin Le
2026-09-19 08:00:55 +07:00
parent 3c0089e8cb
commit aa1593340e
+30 -1
View File
@@ -1,4 +1,28 @@
#include "SensorMesh.h"
#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) {
RxPowerSavingControl* control = getRxPowerSavingControl();
normalizeRxPowerSavingConfig(&prefs.rxps, sf, bw, rxPowerSavingCaptureCost(control),
rxPowerSavingTransition(control));
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 -------------------------------- */
@@ -709,7 +733,7 @@ void SensorMesh::onAckRecv(mesh::Packet* packet, uint32_t ack_crc) {
SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
region_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)
{
next_local_advert = next_flood_advert = 0;
@@ -782,6 +806,7 @@ void SensorMesh::begin(FILESYSTEM* fs) {
radio_driver.setTxPower(_prefs.tx_power_dbm);
board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain);
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
applyRxPowerSavingConfig(_prefs, _prefs.sf, _prefs.bw);
updateAdvertTimer();
updateFloodAdvertTimer();
@@ -925,12 +950,14 @@ void SensorMesh::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");
}
@@ -991,5 +1018,7 @@ void SensorMesh::loop() {
// To check if there is pending work
bool SensorMesh::hasPendingWork() const {
const RxPowerSavingControl* control = getRxPowerSavingControl();
if (control != nullptr && control->isRxPowerSavingCalibrationActive()) return true;
return _mgr->getOutboundTotal() > 0;
}