* T096, and Station G3: refactoring the 'FEM' prefs to variant-specific code

* CommonCLI: 'FEM' commands removed
* introduced static no-op attachDynamicPrefs() for all boards
This commit is contained in:
Scott Powell
2026-08-24 01:50:22 +10:00
parent e485d01dcb
commit 47b0b7b3b8
21 changed files with 243 additions and 101 deletions
+80 -8
View File
@@ -21,10 +21,6 @@ bool StationG3Board::setLoRaFemLnaEnabled(bool enable) {
return true;
}
bool StationG3Board::canControlLoRaFemLna() const {
return loRaFEMControl.canControlLNA();
}
bool StationG3Board::isLoRaFemLnaEnabled() const {
return loRaFEMControl.isLNAEnabled();
}
@@ -37,10 +33,86 @@ bool StationG3Board::setLoRaFemPaGainEnabled(bool enable) {
return true;
}
bool StationG3Board::canControlLoRaFemPaGain() const {
return loRaFEMControl.canControlPAGain();
}
bool StationG3Board::isLoRaFemPaGainEnabled() const {
return loRaFEMControl.isPAGainEnabled();
}
void StationG3Board::attachDynamicPrefs(KeyValueStore* prefs) {
_prefs = prefs;
char gain[8];
gain[0] = 0;
_prefs->getByKey("fem_rxgain", gain, 7); // get initial values
setLoRaFemLnaEnabled(strcmp(gain, "1") == 0);
gain[0] = 0;
_prefs->getByKey("fem_txgain", gain, 7); // get initial values
setLoRaFemPaGainEnabled(strcmp(gain, "1") == 0);
}
bool StationG3Board::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
if (strcmp(command, "get radio.fem.rxgain") == 0) {
if (!loRaFEMControl.canControlLNA()) {
strcpy(reply, "Error: unsupported");
} else {
sprintf(reply, "> %s", isLoRaFemLnaEnabled() ? "on" : "off");
}
return true;
}
if (memcmp(command, "set radio.fem.rxgain ", 21) == 0) {
if (!loRaFEMControl.canControlLNA()) {
strcpy(reply, "Error: unsupported");
} else if (memcmp(&command[21], "on", 2) == 0) {
if (setLoRaFemLnaEnabled(true)) {
_prefs->setByKey("fem_rxgain", "1");
strcpy(reply, "OK - LoRa FEM RX gain on");
} else {
strcpy(reply, "Error: failed to apply LoRa FEM RX gain");
}
} else if (memcmp(&command[21], "off", 3) == 0) {
if (setLoRaFemLnaEnabled(false)) {
_prefs->setByKey("fem_rxgain", "0");
strcpy(reply, "OK - LoRa FEM RX gain off");
} else {
strcpy(reply, "Error: failed to apply LoRa FEM RX gain");
}
} else {
strcpy(reply, "Error: state must be on or off");
}
return true;
}
if (strcmp(command, "get radio.fem.txgain") == 0) {
if (!loRaFEMControl.canControlPAGain()) {
strcpy(reply, "Error: unsupported");
} else {
sprintf(reply, "> %s", isLoRaFemPaGainEnabled() ? "on" : "off");
}
return true;
}
if (memcmp(command, "set radio.fem.txgain ", 21) == 0) {
if (!loRaFEMControl.canControlPAGain()) {
strcpy(reply, "Error: unsupported");
} else if (memcmp(&command[21], "on", 2) == 0) {
if (setLoRaFemPaGainEnabled(true)) {
_prefs->setByKey("fem_txgain", "1");
strcpy(reply, "OK - LoRa FEM TX gain on");
} else {
strcpy(reply, "Error: failed to apply LoRa FEM TX gain");
}
} else if (memcmp(&command[21], "off", 3) == 0) {
if (setLoRaFemPaGainEnabled(false)) {
_prefs->setByKey("fem_txgain", "0");
strcpy(reply, "OK - LoRa FEM TX gain off");
} else {
strcpy(reply, "Error: failed to apply LoRa FEM TX gain");
}
} else {
strcpy(reply, "Error: state must be on or off");
}
return true;
}
return false; // not handled
}
+10 -7
View File
@@ -6,6 +6,12 @@
#include "LoRaFEMControl.h"
class StationG3Board : public ESP32Board {
KeyValueStore* _prefs = NULL;
bool setLoRaFemLnaEnabled(bool enable);
bool isLoRaFemLnaEnabled() const;
bool setLoRaFemPaGainEnabled(bool enable);
bool isLoRaFemPaGainEnabled() const;
public:
LoRaFEMControl loRaFEMControl;
@@ -25,6 +31,10 @@ public:
}
}
void attachDynamicPrefs(KeyValueStore* prefs);
bool handleCommand(const char* command, uint32_t sender_timestamp, char* reply) override;
void setPrimaryLNAEnable(bool enabled) {
loRaFEMControl.setLNAEnable(enabled);
}
@@ -43,13 +53,6 @@ public:
loRaFEMControl.setRxModeEnable();
}
bool setLoRaFemLnaEnabled(bool enable) override;
bool canControlLoRaFemLna() const override;
bool isLoRaFemLnaEnabled() const override;
bool setLoRaFemPaGainEnabled(bool enable) override;
bool canControlLoRaFemPaGain() const override;
bool isLoRaFemPaGainEnabled() const override;
void powerOff() override;
uint16_t getBattMilliVolts() override {