Files
MeshCore/variants/station_g3_esp32/StationG3Board.cpp
agessaman 720f0f1528 kiss_modem: reach FEM gain through the board's radio.fem CLI commands
Boards own their FEM control through handleCommand() ("get/set
radio.fem.rxgain|txgain"). Use that instead of a parallel set of FEM
virtuals on MainBoard, so any board that implements the commands works
in KISS with no extra code.

- Remove the six FEM virtuals from MainBoard and the board overrides.
- KissModem talks to the board in one adapter. A gain counts as
  controllable only if "get" replies exactly "> on" or "> off". "set"
  is checked by reading the state back, never by its reply wording.
- SetFemState always replies with the read-back state once the
  requested bits pass the capability check.
- Guard the boards' prefs writes against a NULL store. KISS attaches
  no prefs, so "set radio.fem.*" would dereference NULL.
- Wio Tracker L1 1W TX gain is exposed again, matching its CLI.
2026-09-23 17:31:20 -07:00

119 lines
3.4 KiB
C++

#include "StationG3Board.h"
void StationG3Board::powerOff() {
loRaFEMControl.setSleepModeEnable();
#ifdef P_PA1_EN
rtc_gpio_hold_en((gpio_num_t)P_PA1_EN);
#endif
#ifdef P_PRIMARY_LNA_EN
rtc_gpio_hold_en((gpio_num_t)P_PRIMARY_LNA_EN);
#endif
ESP32Board::powerOff();
}
bool StationG3Board::setLoRaFemLnaEnabled(bool enable) {
if (!loRaFEMControl.canControlLNA()) {
return false;
}
loRaFEMControl.setLNAEnable(enable);
return true;
}
bool StationG3Board::isLoRaFemLnaEnabled() const {
return loRaFEMControl.isLNAEnabled();
}
bool StationG3Board::setLoRaFemPaGainEnabled(bool enable) {
if (!loRaFEMControl.canControlPAGain()) {
return false;
}
loRaFEMControl.setPAGainEnable(enable);
return true;
}
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)) {
if (_prefs) _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)) {
if (_prefs) _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)) {
if (_prefs) _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)) {
if (_prefs) _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
}