diff --git a/Makefile b/Makefile index 39194eda2..5d4f38c98 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ CXX_STANDARD := -std=c++11 # Defined Symbols #---------------------------------------------------------------------- DEFINES += -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_PROGMEM=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0 -DEFINES += -DEMSESP_DEBUG -DEMSESP_STANDALONE +DEFINES += -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST DEFINES += $(ARGS) DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.5.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" diff --git a/pio_local.ini_example b/pio_local.ini_example index 3b4de6449..3fdc28bb4 100644 --- a/pio_local.ini_example +++ b/pio_local.ini_example @@ -2,7 +2,7 @@ [common] ; custom build flags -; options are: EMSESP_DEBUG, EMSESP_UART_DEBUG, EMSESP_DEBUG_SENSOR, EMSESP_WIFI_TWEAK, EMSESP_DEFAULT_BOARD_PROFILE +; options are: EMSESP_DEBUG, EMSESP_UART_DEBUG, EMSESP_DEBUG_SENSOR, EMSESP_WIFI_TWEAK, EMSESP_DEFAULT_BOARD_PROFILE, EMSESP_TEST ; my_build_flags = -DEMSESP_DEBUG -DEMSESP_DEFAULT_BOARD_PROFILE=\"NODEMCU\" ; my_build_flags = -DEMSESP_DEBUG_SENSOR ; my_build_flags = -DEMSESP_DEBUG -DCORE_DEBUG_LEVEL=5 ; 5=verbose, 4=debug, 3=info diff --git a/platformio.ini b/platformio.ini index 543a19fc1..d8c4e5c72 100644 --- a/platformio.ini +++ b/platformio.ini @@ -149,7 +149,7 @@ platform = native build_flags = -DARDUINO -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_PROGMEM=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0 - -DEMSESP_DEBUG -DEMSESP_STANDALONE + -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.5.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" -lpthread -std=gnu++17 -Og -ggdb diff --git a/src/console.cpp b/src/console.cpp index 6a90bb9e1..3be20ad0b 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -21,7 +21,7 @@ #include "emsesp.h" #include "version.h" -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) #include "test/test.h" #endif @@ -66,13 +66,9 @@ static std::vector log_level_autocomplete(Shell & shell, const std: } static void setup_commands(std::shared_ptr & commands) { - // add for all contexts // log, exit, help - for (unsigned int context = ShellContext::MAIN; context < ShellContext::END; context++) { - commands->add_command(context, CommandFlags::USER, {F_(exit)}, EMSESPShell::main_exit_function); - commands->add_command(context, CommandFlags::USER, {F_(help)}, EMSESPShell::main_help_function); - } - + commands->add_command(ShellContext::MAIN, CommandFlags::USER, {F_(exit)}, EMSESPShell::main_exit_function); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, {F_(help)}, EMSESPShell::main_help_function); commands->add_command(ShellContext::MAIN, CommandFlags::USER, {F_(log)}, {F_(log_level_optional)}, console_log_level, log_level_autocomplete); // @@ -125,7 +121,7 @@ static void setup_commands(std::shared_ptr & commands) { // System commands // -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) // create commands test commands->add_command(ShellContext::MAIN, CommandFlags::USER, @@ -238,7 +234,7 @@ static void setup_commands(std::shared_ptr & commands) { #endif */ -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) // only for debug commands->add_command( ShellContext::MAIN, diff --git a/src/locale_common.h b/src/locale_common.h index 1e44494a4..0aa1c2ecb 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -189,7 +189,7 @@ MAKE_NOTRANSLATION(tpl_date, "Format: < dd.mm.yyyy >") MAKE_NOTRANSLATION(tpl_input, "Format: []") MAKE_NOTRANSLATION(tpl_input4, "Format: []") -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) MAKE_NOTRANSLATION(test_cmd, "run a test") #endif diff --git a/src/system.cpp b/src/system.cpp index 525464baa..7de595569 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -25,7 +25,7 @@ #include -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) #include "test/test.h" #endif @@ -54,7 +54,7 @@ Adafruit_NeoPixel pixels(1, 7, NEO_GRB + NEO_KHZ800); namespace emsesp { // Languages supported. Note: the order is important and must match locale_translations.h -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) // in Debug mode use one language (en) to save flash memory needed for the tests const char * const languages[] = {EMSESP_LOCALE_EN}; #else @@ -260,7 +260,6 @@ void System::syslog_init() { syslog_.destination(syslog_host_.c_str(), syslog_port_); syslog_.hostname(hostname().c_str()); - // register the command // removed in 3.6.0 // Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY); @@ -356,9 +355,7 @@ void System::wifi_tweak() { bool s1 = WiFi.getSleep(); WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE bool s2 = WiFi.getSleep(); -#if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] Adjusting WiFi - Tx power %d->%d, Sleep %d->%d", p1, p2, s1, s2); -#endif + LOG_DEBUG("Adjusting WiFi - Tx power %d->%d, Sleep %d->%d", p1, p2, s1, s2); #endif } @@ -420,7 +417,7 @@ void System::start() { void System::button_OnClick(PButton & b) { LOG_DEBUG("Button pressed - single click"); -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) #ifndef EMSESP_STANDALONE Test::listDir(LittleFS, FS_CONFIG_DIRECTORY, 3); #endif @@ -749,7 +746,7 @@ void System::commands_init() { // restart and watch (and test) are also exposed as Console commands Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY); Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, FL_(watch_cmd)); -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, FL_(test_cmd)); #endif @@ -1045,9 +1042,7 @@ bool System::check_upgrade(bool factory_settings) { // see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022 missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5)); if (missing_version) { -#ifdef EMSESP_DEBUG LOG_DEBUG("No version information found (%s)", settingsVersion.c_str()); -#endif settingsVersion = "3.4.4"; // this was the last stable version } } @@ -1085,9 +1080,7 @@ bool System::check_upgrade(bool factory_settings) { // if we're coming from 3.4.4 or 3.5.0b14 then we need to apply new settings if (missing_version) { -#ifdef EMSESP_DEBUG LOG_DEBUG("Setting MQTT ID Entity to v3.4 format"); -#endif EMSESP::esp8266React.getMqttSettingsService()->update( [&](MqttSettings & mqttSettings) { mqttSettings.entity_format = 0; // use old Entity ID format from v3.4 @@ -1400,7 +1393,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp return true; } -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) // run a test, e.g. http://ems-esp/api?device=system&cmd=test&data=boiler bool System::command_test(const char * value, const int8_t id) { return Test::run_test(value, id); diff --git a/src/system.h b/src/system.h index 289a86d6e..dba4d6dde 100644 --- a/src/system.h +++ b/src/system.h @@ -55,14 +55,13 @@ class System { static bool command_publish(const char * value, const int8_t id); static bool command_fetch(const char * value, const int8_t id); static bool command_restart(const char * value, const int8_t id); -#if defined(EMSESP_DEBUG) - static bool command_test(const char * value, const int8_t id); -#endif static bool command_syslog_level(const char * value, const int8_t id); static bool command_watch(const char * value, const int8_t id); - static bool command_info(const char * value, const int8_t id, JsonObject & output); static bool command_commands(const char * value, const int8_t id, JsonObject & output); +#if defined(EMSESP_TEST) + static bool command_test(const char * value, const int8_t id); +#endif std::string reset_reason(uint8_t cpu) const; diff --git a/src/test/test.cpp b/src/test/test.cpp index d9b6da93b..f559ac9dd 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#if defined(EMSESP_DEBUG) || defined(EMSESP_STANDALONE) +#if defined(EMSESP_STANDALONE) || defined(EMSESP_TEST) #include "test.h" @@ -1785,7 +1785,7 @@ void Test::add_device(uint8_t device_id, uint8_t product_id) { uart_telegram({device_id, EMSESP_DEFAULT_EMS_BUS_ID, EMSdevice::EMS_TYPE_VERSION, 0, product_id, 1, 0}); } -#ifdef EMSESP_DEBUG +#ifdef EMSESP_TEST #ifndef EMSESP_STANDALONE void Test::listDir(fs::FS & fs, const char * dirname, uint8_t levels) { Serial.println(); diff --git a/src/test/test.h b/src/test/test.h index 6483c1057..2404bd95f 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#if defined(EMSESP_DEBUG) || defined(EMSESP_STANDALONE) +#if defined(EMSESP_STANDALONE) || defined(EMSESP_TEST) #ifndef EMSESP_TEST_H #define EMSESP_TEST_H