Merge branch 'PowerSaving-v17' of https://github.com/IoTThinks/MeshCore into keymindCascade

# Conflicts:
#	examples/companion_radio/MyMesh.cpp
#	examples/companion_radio/NodePrefs.h
#	examples/simple_repeater/MyMesh.cpp
#	examples/simple_room_server/MyMesh.cpp
#	examples/simple_sensor/SensorMesh.cpp
#	platformio.ini
#	src/MeshCore.h
#	src/helpers/CommonCLI.cpp
#	src/helpers/CommonCLI.h
#	src/helpers/radiolib/CustomSX1262Wrapper.h
#	src/helpers/radiolib/CustomSX1268Wrapper.h
#	src/helpers/radiolib/LR11x0Reset.h
#	src/helpers/radiolib/SX126xReset.h
This commit is contained in:
mikecarper committed 2026-08-11 13:28:43 -07:00
commit ea3843e0b4
33 files changed
+679 -204

No files matched your search

+5
View File
@@ -320,6 +320,9 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
if (file.available() >= (int)sizeof(_prefs.vibe_quiet)) {
file.read((uint8_t *)&_prefs.vibe_quiet, sizeof(_prefs.vibe_quiet)); // 124
}
if (file.available() >= (int)sizeof(_prefs.radio_fem_txgain)) {
file.read((uint8_t *)&_prefs.radio_fem_txgain, sizeof(_prefs.radio_fem_txgain)); // 125
}
file.close();
}
@@ -369,6 +372,8 @@ bool DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
sizeof(_prefs.radio_fem_rxgain_override)) == sizeof(_prefs.radio_fem_rxgain_override); // 123
success = success && file.write((uint8_t *)&_prefs.vibe_quiet,
sizeof(_prefs.vibe_quiet)) == sizeof(_prefs.vibe_quiet); // 124
success = success && file.write((uint8_t *)&_prefs.radio_fem_txgain,
sizeof(_prefs.radio_fem_txgain)) == sizeof(_prefs.radio_fem_txgain); // 125
#if defined(NRF52_PLATFORM)
success = file.commit(success);
+48
View File
@@ -1357,6 +1357,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
_prefs.gps_interval = 0; // No automatic GPS updates by default
_prefs.autoadd_config = DEFAULT_AUTOADD_CONFIG;
_prefs.path_hash_mode = DEFAULT_PATH_HASH_MODE;
_prefs.radio_fem_txgain = 0;
//_prefs.rx_delay_base = 10.0f; enable once new algo fixed
_prefs.setRepeatEn(false);
#if defined(USE_SX1262) || defined(USE_SX1268) || defined(USE_LR1110) \
@@ -1436,6 +1437,7 @@ void MyMesh::begin(bool has_display) {
_prefs.radio_fem_rxgain = DEFAULT_FEM_RX_GAIN;
}
_prefs.radio_fem_rxgain = constrain(_prefs.radio_fem_rxgain, 0, 1);
_prefs.radio_fem_txgain = constrain(_prefs.radio_fem_txgain, 0, 1);
#ifdef BLE_PIN_CODE // 123456 by default
if (_prefs.ble_pin == 0) {
@@ -1484,6 +1486,7 @@ void MyMesh::begin(bool has_display) {
if (board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain) && fem_gain_changed) {
_radio->recalibrateNoiseFloor();
}
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
MESH_DEBUG_PRINTLN("RX Boosted Gain Mode: %s",
radio_driver.getRxBoostedGainMode() ? "Enabled" : "Disabled");
@@ -2047,6 +2050,19 @@ void MyMesh::execCommand(char* cmd, char* reply) {
}
return;
}
if (strcmp(key, "radio.fem.txgain") == 0) {
bool enabled;
if (!wcParseBool(value, enabled)) {
strcpy(reply, "Error: must be on or off");
} else if (!board.canControlLoRaFemPaGain()) {
strcpy(reply, "Error: unsupported");
} else if (!applyAndSaveFemTxGain(enabled)) {
strcpy(reply, "Error: failed to apply FEM TX gain");
} else {
strcpy(reply, "OK");
}
return;
}
#ifdef WITH_MQTT_BRIDGE
bool changed = false;
@@ -3450,6 +3466,15 @@ bool MyMesh::applyAndSaveFemRxGain(bool enabled) {
return true;
}
bool MyMesh::applyAndSaveFemTxGain(bool enabled) {
if (!board.canControlLoRaFemPaGain()) return false;
if (!board.setLoRaFemPaGainEnabled(enabled)) return false;
_prefs.radio_fem_txgain = enabled ? 1 : 0;
savePrefs();
return true;
}
#ifdef ENABLE_USB_INTERFACE
void MyMesh::enterTerminalMode() {
_terminal_mode = true;
@@ -4236,6 +4261,13 @@ void MyMesh::handleTerminalCommand(char* command) {
Serial.printf(" FEM RX gain: %s\r\n",
board.isLoRaFemLnaEnabled() ? "on" : "off");
}
} else if (strcmp(command, "get radio.fem.txgain") == 0) {
if (!board.canControlLoRaFemPaGain()) {
Serial.print(" ERROR: FEM TX gain control is unsupported on this board\r\n");
} else {
Serial.printf(" FEM TX gain: %s\r\n",
board.isLoRaFemPaGainEnabled() ? "on" : "off");
}
} else if (strncmp(command, "set ", 4) == 0) {
const char* config = command + 4;
if (strncmp(config, "af ", 3) == 0) {
@@ -4276,6 +4308,20 @@ void MyMesh::handleTerminalCommand(char* command) {
} else {
Serial.printf(" OK - FEM RX gain %s\r\n", value);
}
} else if (strncmp(config, "radio.fem.txgain", 16) == 0
&& (config[16] == 0 || config[16] == ' '
|| config[16] == '\t')) {
const char* value = config + 16;
while (*value == ' ' || *value == '\t') value++;
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
Serial.print(" ERROR: use set radio.fem.txgain <on|off>\r\n");
} else if (!board.canControlLoRaFemPaGain()) {
Serial.print(" ERROR: FEM TX gain control is unsupported on this board\r\n");
} else if (!applyAndSaveFemTxGain(strcmp(value, "on") == 0)) {
Serial.print(" ERROR: failed to apply FEM TX gain\r\n");
} else {
Serial.printf(" OK - FEM TX gain %s\r\n", value);
}
} else {
Serial.printf(" ERROR: unknown setting: %s\r\n", config);
}
@@ -4287,6 +4333,8 @@ void MyMesh::handleTerminalCommand(char* command) {
Serial.print(" set {name|lat|lon|freq|tx|af} {value}\r\n");
Serial.print(" get radio.fem.rxgain\r\n");
Serial.print(" set radio.fem.rxgain <on|off>\r\n");
Serial.print(" get radio.fem.txgain\r\n");
Serial.print(" set radio.fem.txgain <on|off>\r\n");
Serial.print(" card\r\n");
Serial.print(" import <meshcore://card>\r\n");
Serial.print(" clock\r\n");
+1
View File
@@ -277,6 +277,7 @@ private:
void checkCLIRescueCmd();
void checkSerialInterface();
bool applyAndSaveFemRxGain(bool enabled);
bool applyAndSaveFemTxGain(bool enabled);
#ifdef ENABLE_USB_INTERFACE
ContactInfo* getTerminalRecipient();
void printTerminalPath(const ContactInfo& recipient);
+1
View File
@@ -37,6 +37,7 @@ struct NodePrefs { // persisted to file
uint8_t default_scope_key[16];
uint8_t radio_fem_rxgain_override; // 1 once the user overrides the build default
uint8_t vibe_quiet; // haptic quiet mode; appended for prefs compatibility
uint8_t radio_fem_txgain; // LoRa FEM TX gain; appended for prefs compatibility
// Keep the upstream repeat API while retaining the existing binary prefs
// layout used by this branch.
+2
View File
@@ -3030,6 +3030,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.rx_boosted_gain = mesh::radio::configuredRxBoostedGainDefault();
#endif
_prefs.radio_fem_rxgain = 1; // LoRa FEM RX gain on by default (FEM boards)
_prefs.radio_fem_txgain = 0;
pending_discover_tag = 0;
pending_discover_until = 0;
@@ -3200,6 +3201,7 @@ void MyMesh::begin(FILESYSTEM *fs) {
if (board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain) && fem_gain_changed) {
_radio->recalibrateNoiseFloor();
}
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
setRxPowerSaving(_prefs.rx_powersaving_enabled, _prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us);
updateAdvertTimer();
+2
View File
@@ -1164,6 +1164,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.rx_boosted_gain = mesh::radio::configuredRxBoostedGainDefault();
#endif
_prefs.radio_fem_rxgain = 1;
_prefs.radio_fem_txgain = 0;
// Observer defaults (alert.*, etc.) moved to applyMQTTDefaults() - they live
// in /mqtt_prefs now, not NodePrefs.
@@ -1241,6 +1242,7 @@ void MyMesh::begin(FILESYSTEM *fs) {
if (board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain) && fem_gain_changed) {
_radio->recalibrateNoiseFloor();
}
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
setRxPowerSaving(_prefs.rx_powersaving_enabled, _prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us);
updateAdvertTimer();
+2
View File
@@ -931,6 +931,7 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise
_prefs.gps_interval = 0;
_prefs.advert_loc_policy = ADVERT_LOC_PREFS;
_prefs.radio_fem_rxgain = 1;
_prefs.radio_fem_txgain = 0;
memset(default_scope.key, 0, sizeof(default_scope.key));
}
@@ -974,6 +975,7 @@ void SensorMesh::begin(FILESYSTEM* fs) {
if (board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain) && fem_gain_changed) {
_radio->recalibrateNoiseFloor();
}
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
setRxPowerSaving(_prefs.rx_powersaving_enabled, _prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us);
updateAdvertTimer();