mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-26 08:39:09 +03:00
implement txenabled system command - #2850
This commit is contained in:
@@ -21,6 +21,12 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define EMS_TXMODE_OFF 0
|
||||
#define EMS_TXMODE_DEFAULT 1
|
||||
#define EMS_TXMODE_EMSPLUS 2
|
||||
#define EMS_TXMODE_HT3 3
|
||||
#define EMS_TXMODE_HW 4
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
#define EMS_TX_STATUS_ERR 0
|
||||
|
||||
@@ -1813,9 +1813,9 @@ void EMSESP::shell_prompt() {
|
||||
void EMSESP::loop() {
|
||||
uuid::loop(); // store system uptime
|
||||
|
||||
// does LED and checks system health, and syslog service
|
||||
// handles LED and checks system health, and syslog service
|
||||
if (system_.loop()) {
|
||||
return; // LED flashing is active
|
||||
return; // LED flashing is active, skip the rest of the loop
|
||||
}
|
||||
|
||||
esp32React.loop(); // web services
|
||||
|
||||
@@ -696,6 +696,7 @@ bool Helpers::value2string(const char * value, std::string & value_s) {
|
||||
|
||||
// checks to see if a string (usually a command or payload cmd) looks like a boolean
|
||||
// on, off, true, false, 1, 0
|
||||
// uses translated words for on/off
|
||||
bool Helpers::value2bool(const char * value, bool & value_b) {
|
||||
if ((value == nullptr) || (strlen(value) == 0)) {
|
||||
return false;
|
||||
|
||||
@@ -42,6 +42,7 @@ MAKE_WORD(system)
|
||||
MAKE_WORD(fetch)
|
||||
MAKE_WORD(restart)
|
||||
MAKE_WORD(format)
|
||||
MAKE_WORD(txenabled)
|
||||
MAKE_WORD(raw)
|
||||
MAKE_WORD(watch)
|
||||
MAKE_WORD(syslog)
|
||||
@@ -168,6 +169,7 @@ MAKE_WORD_CUSTOM(password_prompt, "Password: ")
|
||||
MAKE_WORD_CUSTOM(unset, "<unset>")
|
||||
MAKE_WORD_CUSTOM(enable_mandatory, "<enable | disable>")
|
||||
MAKE_WORD_CUSTOM(service_mandatory, "<ap | mqtt | ntp>")
|
||||
MAKE_WORD_CUSTOM(txenabled_cmd, "enable/disable TX")
|
||||
|
||||
// more common names that don't need translations
|
||||
MAKE_NOTRANSLATION(1x3min, "1x3min")
|
||||
|
||||
@@ -71,6 +71,7 @@ MAKE_WORD_TRANSLATION(changeloglevel_cmd, "change log level", "Ändere Protokoll
|
||||
MAKE_WORD_TRANSLATION(fetch_cmd, "refresh all EMS values", "Aktualisiere alle EMS-Werte", "Verversen alle EMS waardes", "uppdatera alla EMS-värden", "odśwież wszystkie wartości EMS", "oppfrisk alle EMS verdier", "", "Bütün EMS değerlerini yenile", "aggiornare tutti i valori EMS", "obnoviť všetky hodnoty EMS", "aktualizovat všechny EMS hodnoty") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(restart_cmd, "restart EMS-ESP", "Neustart", "opnieuw opstarten", "starta om EMS-ESP", "uruchom ponownie EMS-ESP", "restart EMS-ESP", "redémarrer EMS-ESP", "EMS-ESPyi yeniden başlat", "riavvia EMS-ESP", "reštart EMS-ESP", "restartovat EMS-ESP") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(format_cmd, "factory reset EMS-ESP", "EMS-ESP auf Werkseinstellungen zurücksetzen", "fabriksåterställ EMS-ESP", "", "", "", "", "", "", "továrenske nastavenie EMS-ESP", "tovární nastavení EMS-ESP") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(txenabled_cmd, "enable/disable TX", "TX aktivieren/deaktivieren", "TX inschakelen/uitschakelen", "aktivera/inaktivera TX", "włącz/wyłącz TX", "aktiver/deaktiver TX", "", "TX'i etkinleştir/devre dışı bırak", "abilita/disabilita TX", "povoliť/zakázať TX", "povolit/zakázat TX") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(watch_cmd, "watch incoming telegrams", "Beobachte eingehende Telegramme", "inkomende telegrammen bekijken", "visa inkommande telegram", "obserwuj przyczodzące telegramy", "se innkommende telegrammer", "", "Gelen telegramları", "guardare i telegrammi in arrivo", "sledovať prichádzajúce telegramy", "sledovat příchozí telegramy") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(publish_cmd, "publish all to MQTT", "Publiziere MQTT", "publiceer alles naar MQTT", "publicera allt till MQTT", "opublikuj wszystko na MQTT", "Publiser alt til MQTT", "", "Hepsini MQTTye gönder", "pubblica tutto su MQTT", "zverejniť všetko na MQTT", "publikovat vše do MQTT") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(system_info_cmd, "show system info", "Zeige Systeminformationen", "toon systeemstatus", "visa systeminformation", "pokaż status systemu", "vis system status", "", "Sistem Durumunu Göster", "visualizza stati di sistema", "zobraziť stav systému", "zobrazit informace o systému") // TODO translate
|
||||
|
||||
@@ -399,17 +399,23 @@ std::string commands(std::string & expr, bool quotes) {
|
||||
|
||||
// checks for logic value
|
||||
int to_logic(const std::string & s) {
|
||||
if (s.empty()) {
|
||||
return -1;
|
||||
bool value_b;
|
||||
if (!Helpers::value2bool(s.c_str(), value_b)) {
|
||||
return -1; // invalid
|
||||
}
|
||||
auto l = Helpers::toLower(s);
|
||||
if (s[0] == '1' || l == "on" || l == "true") {
|
||||
return 1;
|
||||
}
|
||||
if (s[0] == '0' || l == "off" || l == "false") {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
return value_b;
|
||||
|
||||
// if (s.empty()) {
|
||||
// return -1;
|
||||
// }
|
||||
// auto l = Helpers::toLower(s);
|
||||
// if (s[0] == '1' || l == "on" || l == "true") {
|
||||
// return 1;
|
||||
// }
|
||||
// if (s[0] == '0' || l == "off" || l == "false") {
|
||||
// return 0;
|
||||
// }
|
||||
// return -1;
|
||||
}
|
||||
|
||||
// number to string, remove trailing zeros
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -103,6 +103,7 @@ class System {
|
||||
static bool command_info(const char * value, const int8_t id, JsonObject output);
|
||||
static bool command_response(const char * value, const int8_t id, JsonObject output);
|
||||
static bool command_service(const char * cmd, const char * value);
|
||||
static bool command_txenabled(const char * value, const int8_t id);
|
||||
|
||||
static bool get_value_info(JsonObject root, const char * cmd);
|
||||
static void get_value_json(JsonObject output, const std::string & circuit, const std::string & name, JsonVariant val);
|
||||
|
||||
Reference in New Issue
Block a user