implement txenabled system command - #2850

This commit is contained in:
proddy
2025-12-26 10:10:27 +01:00
parent fb698fd029
commit 05baec85b7
8 changed files with 52 additions and 22 deletions

View File

@@ -1019,6 +1019,7 @@ void System::commands_init() {
Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(format), System::command_format, FL_(format_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(txenabled), System::command_txenabled, FL_(txenabled_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, FL_(watch_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, F_(message), System::command_message, FL_(message_cmd));
#if defined(EMSESP_TEST)
@@ -1588,16 +1589,6 @@ bool System::command_service(const char * cmd, const char * value) {
});
EMSESP::system_.analog_enabled(b);
ok = true;
} else if (!strcmp(cmd, "settings/txmode")) { // TODO check
LOG_INFO("Setting TX mode to OFF"); // TODO remove this
EMSESP::webSettingsService.update([&](WebSettings & settings) {
// settings.tx_mode = EMS_TXMODE_OFF;
settings.tx_mode = 0; // TODO remove this
return StateUpdateResult::CHANGED;
});
EMSbus::tx_mode(EMS_TXMODE_OFF);
ok = true;
} else if (!strcmp(cmd, "mqtt/enabled")) {
EMSESP::esp32React.getMqttSettingsService()->update([&](MqttSettings & Settings) {
Settings.enabled = b;
@@ -2419,6 +2410,28 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
return true;
}
// txenabled command - temporarily pause the TX, setting Txmode to 0
bool System::command_txenabled(const char * value, const int8_t id) {
bool arg;
if (!Helpers::value2bool(value, arg)) {
return false; // argument not recognized
}
if (arg) {
// if the TX mode is already off, revert back to the saved setting
if (EMSbus::tx_mode() == EMS_TXMODE_OFF) {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
EMSbus::tx_mode(settings.tx_mode);
LOG_INFO("TX mode restored");
});
} else {
// otherwise set it to off
EMSbus::tx_mode(EMS_TXMODE_OFF);
LOG_INFO("TX mode set to OFF");
}
}
return true;
}
// format command - factory reset, removing all config files
bool System::command_format(const char * value, const int8_t id) {
#if !defined(EMSESP_STANDALONE) && !defined(EMSESP_DEBUG)