diff --git a/src/console.cpp b/src/console.cpp index 081d59c05..bfd20eabf 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -36,9 +36,7 @@ static std::shared_ptr shell; std::vector EMSESPStreamConsole::ptys_; #ifndef EMSESP_STANDALONE -uuid::telnet::TelnetService telnet_([](Stream & stream, const IPAddress & addr, uint16_t port) -> std::shared_ptr { - return std::make_shared(stream, addr, port); -}); +uuid::telnet::TelnetService telnet_([](Stream & stream, const IPAddress & addr, uint16_t port) -> std::shared_ptr { return std::make_shared(stream, addr, port); }); #endif EMSESPShell::EMSESPShell() @@ -110,42 +108,30 @@ void EMSESPShell::add_console_commands() { // commands->remove_context_commands(ShellContext::MAIN); commands->remove_all_commands(); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(show)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { - shell.printfln(F("%s%sEMS-ESP version %s%s"), COLOR_BRIGHT_GREEN, COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_RESET); - shell.println(); - EMSESP::show_device_values(shell); - EMSESP::show_sensor_values(shell); - }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + shell.printfln(F("%s%sEMS-ESP version %s%s"), COLOR_BRIGHT_GREEN, COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_RESET); + shell.println(); + EMSESP::show_device_values(shell); + EMSESP::show_sensor_values(shell); + }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(show), F_(devices)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { EMSESP::show_devices(shell); }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show), F_(devices)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + EMSESP::show_devices(shell); + }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(show), F_(ems)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { EMSESP::show_ems(shell); }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show), F_(ems)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { EMSESP::show_ems(shell); }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(show), F_(values)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { EMSESP::show_device_values(shell); }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show), F_(values)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + EMSESP::show_device_values(shell); + }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(show), F_(mqtt)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { Mqtt::show_mqtt(shell); }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show), F_(mqtt)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { Mqtt::show_mqtt(shell); }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(show), F_(commands)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { Command::show_all(shell); }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(show), F_(commands)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + Command::show_all(shell); + }); commands->add_command( ShellContext::MAIN, @@ -177,74 +163,61 @@ void EMSESPShell::add_console_commands() { }; }); - commands->add_command(ShellContext::MAIN, - CommandFlags::ADMIN, - flash_string_vector{F_(set), F_(tx_mode)}, - flash_string_vector{F_(n_mandatory)}, - [](Shell & shell, const std::vector & arguments) { - uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10); - // save the tx_mode - EMSESP::webSettingsService.update( - [&](WebSettings & settings) { - settings.tx_mode = tx_mode; - shell.printfln(F_(tx_mode_fmt), settings.tx_mode); - return StateUpdateResult::CHANGED; - }, - "local"); - }); + commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, flash_string_vector{F_(set), F_(tx_mode)}, flash_string_vector{F_(n_mandatory)}, [](Shell & shell, const std::vector & arguments) { + uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10); + // save the tx_mode + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { + settings.tx_mode = tx_mode; + shell.printfln(F_(tx_mode_fmt), settings.tx_mode); + return StateUpdateResult::CHANGED; + }, + "local"); + }); - commands->add_command(ShellContext::MAIN, - CommandFlags::ADMIN, - flash_string_vector{F_(scan), F_(devices)}, - flash_string_vector{F_(deep_optional)}, - [](Shell & shell, const std::vector & arguments) { - if (arguments.size() == 0) { - EMSESP::scan_devices(); - } else { - shell.printfln(F("Performing a deep scan...")); - EMSESP::clear_all_devices(); - std::vector Device_Ids; + commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, flash_string_vector{F_(scan), F_(devices)}, flash_string_vector{F_(deep_optional)}, [](Shell & shell, const std::vector & arguments) { + if (arguments.size() == 0) { + EMSESP::scan_devices(); + } else { + shell.printfln(F("Performing a deep scan...")); + EMSESP::clear_all_devices(); + std::vector Device_Ids; - Device_Ids.push_back(0x08); // Boilers - 0x08 - Device_Ids.push_back(0x38); // HeatPump - 0x38 - Device_Ids.push_back(0x30); // Solar Module - 0x30 - Device_Ids.push_back(0x09); // Controllers - 0x09 - Device_Ids.push_back(0x02); // Connect - 0x02 - Device_Ids.push_back(0x48); // Gateway - 0x48 - Device_Ids.push_back(0x20); // Mixer Devices - 0x20 - Device_Ids.push_back(0x21); // Mixer Devices - 0x21 - Device_Ids.push_back(0x22); // Mixer Devices - 0x22 - Device_Ids.push_back(0x23); // Mixer Devices - 0x23 - Device_Ids.push_back(0x28); // Mixer Devices WW- 0x28 - Device_Ids.push_back(0x29); // Mixer Devices WW- 0x29 - Device_Ids.push_back(0x10); // Thermostats - 0x10 - Device_Ids.push_back(0x17); // Thermostats - 0x17 - Device_Ids.push_back(0x18); // Thermostat remote - 0x18 - Device_Ids.push_back(0x19); // Thermostat remote - 0x19 - Device_Ids.push_back(0x1A); // Thermostat remote - 0x1A - Device_Ids.push_back(0x1B); // Thermostat remote - 0x1B - Device_Ids.push_back(0x11); // Switches - 0x11 + Device_Ids.push_back(0x08); // Boilers - 0x08 + Device_Ids.push_back(0x38); // HeatPump - 0x38 + Device_Ids.push_back(0x30); // Solar Module - 0x30 + Device_Ids.push_back(0x09); // Controllers - 0x09 + Device_Ids.push_back(0x02); // Connect - 0x02 + Device_Ids.push_back(0x48); // Gateway - 0x48 + Device_Ids.push_back(0x20); // Mixer Devices - 0x20 + Device_Ids.push_back(0x21); // Mixer Devices - 0x21 + Device_Ids.push_back(0x22); // Mixer Devices - 0x22 + Device_Ids.push_back(0x23); // Mixer Devices - 0x23 + Device_Ids.push_back(0x28); // Mixer Devices WW- 0x28 + Device_Ids.push_back(0x29); // Mixer Devices WW- 0x29 + Device_Ids.push_back(0x10); // Thermostats - 0x10 + Device_Ids.push_back(0x17); // Thermostats - 0x17 + Device_Ids.push_back(0x18); // Thermostat remote - 0x18 + Device_Ids.push_back(0x19); // Thermostat remote - 0x19 + Device_Ids.push_back(0x1A); // Thermostat remote - 0x1A + Device_Ids.push_back(0x1B); // Thermostat remote - 0x1B + Device_Ids.push_back(0x11); // Switches - 0x11 - // send the read command with Version command - for (const uint8_t device_id : Device_Ids) { - EMSESP::send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id); - } - } - }); + // send the read command with Version command + for (const uint8_t device_id : Device_Ids) { + EMSESP::send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id); + } + } + }); - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(set)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { - EMSESP::webSettingsService.read([&](WebSettings & settings) { - shell.printfln(F_(tx_mode_fmt), settings.tx_mode); - shell.printfln(F_(bus_id_fmt), settings.ems_bus_id); - char buffer[4]; - shell.printfln(F_(master_thermostat_fmt), - settings.master_thermostat == 0 ? uuid::read_flash_string(F_(auto)).c_str() - : Helpers::hextoa(buffer, settings.master_thermostat)); - }); - }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(set)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { + shell.printfln(F_(tx_mode_fmt), settings.tx_mode); + shell.printfln(F_(bus_id_fmt), settings.ems_bus_id); + char buffer[4]; + shell.printfln(F_(master_thermostat_fmt), settings.master_thermostat == 0 ? uuid::read_flash_string(F_(auto)).c_str() : Helpers::hextoa(buffer, settings.master_thermostat)); + }); + }); commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, @@ -273,23 +246,18 @@ void EMSESPShell::add_console_commands() { settings.master_thermostat = value; EMSESP::actual_master_thermostat(value); // set the internal value too char buffer[5]; - shell.printfln(F_(master_thermostat_fmt), - !value ? uuid::read_flash_string(F_(auto)).c_str() : Helpers::hextoa(buffer, value)); + shell.printfln(F_(master_thermostat_fmt), !value ? uuid::read_flash_string(F_(auto)).c_str() : Helpers::hextoa(buffer, value)); return StateUpdateResult::CHANGED; }, "local"); }); #ifndef EMSESP_STANDALONE - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(set), F_(timeout)}, - flash_string_vector{F_(n_mandatory)}, - [](Shell & shell, const std::vector & arguments) { - uint16_t value = Helpers::atoint(arguments.front().c_str()); - telnet_.initial_idle_timeout(value * 60); - shell.printfln(F("Telnet timout is %d minutes"), value); - }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(set), F_(timeout)}, flash_string_vector{F_(n_mandatory)}, [](Shell & shell, const std::vector & arguments) { + uint16_t value = Helpers::atoint(arguments.front().c_str()); + telnet_.initial_idle_timeout(value * 60); + shell.printfln(F("Telnet timeout set to %d minutes"), value); + }); #endif commands->add_command(ShellContext::MAIN, @@ -442,12 +410,9 @@ void EMSESPShell::add_console_commands() { }); // System context menu - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - flash_string_vector{F_(system)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { - System::console_commands(shell, ShellContext::SYSTEM); - }); + commands->add_command(ShellContext::MAIN, CommandFlags::USER, flash_string_vector{F_(system)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + System::console_commands(shell, ShellContext::SYSTEM); + }); Console::load_standard_commands(ShellContext::MAIN); @@ -483,19 +448,22 @@ void Console::enter_custom_context(Shell & shell, unsigned int context) { // each custom context has the common commands like log, help, exit, su etc void Console::load_standard_commands(unsigned int context) { #if defined(EMSESP_TEST) - EMSESPShell::commands->add_command(context, - CommandFlags::USER, - flash_string_vector{F_(test)}, - flash_string_vector{F_(name_optional)}, - [](Shell & shell, const std::vector & arguments) { - if (arguments.size() == 0) { - Test::run_test(shell, "default"); - } else { - Test::run_test(shell, arguments.front()); - } - }); - EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F("t")}, [](Shell & shell, const std::vector & arguments) { - Test::run_test(shell, "default"); + EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F_(test)}, flash_string_vector{F_(name_optional)}, [](Shell & shell, const std::vector & arguments) { + if (arguments.size() == 0) { + Test::run_test(shell, "default"); + } else { + Test::run_test(shell, arguments.front()); + } + }); +#endif + +#if defined(EMSESP_DEBUG) + EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F_(debug)}, flash_string_vector{F_(name_optional)}, [](Shell & shell, const std::vector & arguments) { + if (arguments.size() == 0) { + Test::debug(shell, "default"); + } else { + Test::debug(shell, arguments.front()); + } }); #endif @@ -525,56 +493,45 @@ void Console::load_standard_commands(unsigned int context) { } shell.printfln(F_(log_level_fmt), uuid::log::format_level_lowercase(shell.log_level())); }, - [](Shell & shell __attribute__((unused)), const std::vector & arguments __attribute__((unused))) -> std::vector { - return uuid::log::levels_lowercase(); - }); + [](Shell & shell __attribute__((unused)), const std::vector & arguments __attribute__((unused))) -> std::vector { return uuid::log::levels_lowercase(); }); - EMSESPShell::commands->add_command(context, - CommandFlags::USER, - flash_string_vector{F_(help)}, - [](Shell & shell, const std::vector & arguments __attribute__((unused))) { - shell.print_all_available_commands(); - }); + EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F_(help)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { + shell.print_all_available_commands(); + }); - EMSESPShell::commands->add_command(context, - CommandFlags::USER, - flash_string_vector{F_(exit)}, - [=](Shell & shell, const std::vector & arguments __attribute__((unused))) { - // delete MAIN console stuff first to save memory - EMSESPShell::commands->remove_context_commands(context); - shell.exit_context(); - }); + EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F_(exit)}, [=](Shell & shell, const std::vector & arguments __attribute__((unused))) { + // delete MAIN console stuff first to save memory + EMSESPShell::commands->remove_context_commands(context); + shell.exit_context(); + }); - EMSESPShell::commands->add_command(context, - CommandFlags::USER, - flash_string_vector{F_(su)}, - [=](Shell & shell, const std::vector & arguments __attribute__((unused))) { - auto become_admin = [](Shell & shell) { - shell.logger().log(LogLevel::NOTICE, LogFacility::AUTH, F("su session opened on console")); - shell.add_flags(CommandFlags::ADMIN); - }; + EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F_(su)}, [=](Shell & shell, const std::vector & arguments __attribute__((unused))) { + auto become_admin = [](Shell & shell) { + shell.logger().log(LogLevel::NOTICE, LogFacility::AUTH, F("su session opened on console")); + shell.add_flags(CommandFlags::ADMIN); + }; - if (shell.has_flags(CommandFlags::LOCAL)) { - become_admin(shell); - } else { - shell.enter_password(F_(password_prompt), [=](Shell & shell, bool completed, const std::string & password) { - if (completed) { - uint64_t now = uuid::get_uptime_ms(); + if (shell.has_flags(CommandFlags::LOCAL)) { + become_admin(shell); + } else { + shell.enter_password(F_(password_prompt), [=](Shell & shell, bool completed, const std::string & password) { + if (completed) { + uint64_t now = uuid::get_uptime_ms(); - EMSESP::esp8266React.getSecuritySettingsService()->read([&](SecuritySettings & securitySettings) { - if (securitySettings.jwtSecret.equals(password.c_str())) { - become_admin(shell); - } else { - shell.delay_until(now + INVALID_PASSWORD_DELAY_MS, [](Shell & shell) { - shell.logger().log(LogLevel::NOTICE, LogFacility::AUTH, F("Invalid su password on console")); - shell.println(F("su: incorrect password")); - }); - } - }); - } - }); - } - }); + EMSESP::esp8266React.getSecuritySettingsService()->read([&](SecuritySettings & securitySettings) { + if (securitySettings.jwtSecret.equals(password.c_str())) { + become_admin(shell); + } else { + shell.delay_until(now + INVALID_PASSWORD_DELAY_MS, [](Shell & shell) { + shell.logger().log(LogLevel::NOTICE, LogFacility::AUTH, F("Invalid su password on console")); + shell.println(F("su: incorrect password")); + }); + } + }); + } + }); + } + }); } // prompt, change per context @@ -657,26 +614,13 @@ std::string EMSESPStreamConsole::console_name() { // Start up telnet and logging // Log order is off, err, warning, notice, info, debug, trace, all void Console::start() { -// if we've detected a boot into safe mode on ESP8266, start the Serial console too -// Serial is always on with the ESP32 as it has 2 UARTs -#if defined(ESP32) || defined(EMSESP_STANDALONE) || defined(EMSESP_FORCE_SERIAL) - serial_console_.begin(SERIAL_CONSOLE_BAUD_RATE); - serial_console_.println(); - - shell = std::make_shared(serial_console_, true); + shell = std::make_shared(Serial, true); shell->maximum_log_messages(100); // default is 50 shell->start(); -#endif -#ifndef ESP8266 #if defined(EMSESP_DEBUG) shell->log_level(uuid::log::Level::DEBUG); #endif -#endif - -#if defined(EMSESP_FORCE_SERIAL) - shell->log_level(uuid::log::Level::DEBUG); -#endif #if defined(EMSESP_STANDALONE) // always start in su/admin mode when running tests diff --git a/src/console.h b/src/console.h index 64ab1cb93..69d624565 100644 --- a/src/console.h +++ b/src/console.h @@ -136,10 +136,6 @@ class Console { static void enter_custom_context(Shell & shell, unsigned int context); static void load_standard_commands(unsigned int context); - - private: - static constexpr unsigned long SERIAL_CONSOLE_BAUD_RATE = 115200; - static constexpr auto & serial_console_ = Serial; }; } // namespace emsesp diff --git a/src/locale_EN.h b/src/locale_EN.h index 9337cc424..de89d0062 100644 --- a/src/locale_EN.h +++ b/src/locale_EN.h @@ -19,6 +19,7 @@ #pragma once // common words +MAKE_PSTR_WORD(debug) MAKE_PSTR_WORD(exit) MAKE_PSTR_WORD(help) MAKE_PSTR_WORD(log) diff --git a/src/test/test.cpp b/src/test/test.cpp index 5eb7cf105..ec83a6284 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -39,8 +39,7 @@ bool Test::run_test(const char * command, int8_t id) { // add some data // Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25) - uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, - 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); + uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); // Boiler -> Thermostat, UBAParameterWW(0x33), telegram: 08 97 33 00 23 24 (#data=2) uart_telegram({0x08, 0x98, 0x33, 0x00, 0x23, 0x24}); @@ -49,8 +48,7 @@ bool Test::run_test(const char * command, int8_t id) { uart_telegram({0x08, 0x0B, 0x33, 0x00, 0x08, 0xFF, 0x34, 0xFB, 0x00, 0x28, 0x00, 0x00, 0x46, 0x00, 0xFF, 0xFF, 0x00}); // Thermostat RCPLUSStatusMessage_HC1(0x01A5) - uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, - 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); + uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); return true; } @@ -63,8 +61,7 @@ bool Test::run_test(const char * command, int8_t id) { // add some data // Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25) - uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, - 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); + uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); // Boiler -> Thermostat, UBAParameterWW(0x33), telegram: 08 97 33 00 23 24 (#data=2) uart_telegram({0x08, 0x90, 0x33, 0x00, 0x23, 0x24}); @@ -73,8 +70,7 @@ bool Test::run_test(const char * command, int8_t id) { uart_telegram({0x08, 0x0B, 0x33, 0x00, 0x08, 0xFF, 0x34, 0xFB, 0x00, 0x28, 0x00, 0x00, 0x46, 0x00, 0xFF, 0xFF, 0x00}); // Thermostat 0x2A5 for HC1 - uart_telegram({0x10, 00, 0xFF, 00, 01, 0xA5, 0x80, 00, 01, 0x30, 0x28, 00, 0x30, 0x28, 01, 0x54, - 03, 03, 01, 01, 0x54, 02, 0xA8, 00, 00, 0x11, 01, 03, 0xFF, 0xFF, 00}); + uart_telegram({0x10, 00, 0xFF, 00, 01, 0xA5, 0x80, 00, 01, 0x30, 0x28, 00, 0x30, 0x28, 01, 0x54, 03, 03, 01, 01, 0x54, 02, 0xA8, 00, 00, 0x11, 01, 03, 0xFF, 0xFF, 00}); return true; } @@ -129,8 +125,7 @@ bool Test::run_test(const char * command, int8_t id) { uart_telegram({0x08, 0x0B, 0x14, 00, 0x3C, 0x1F, 0xAC, 0x70}); // Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25) - uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, - 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); + uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); // Boiler -> Me, UBAParameterWW(0x33), telegram: 08 0B 33 00 08 FF 34 FB 00 28 00 00 46 00 FF FF 00 (#data=13) uart_telegram({0x08, 0x0B, 0x33, 0x00, 0x08, 0xFF, 0x34, 0xFB, 0x00, 0x28, 0x00, 0x00, 0x46, 0x00, 0xFF, 0xFF, 0x00}); @@ -156,11 +151,9 @@ bool Test::run_test(const char * command, int8_t id) { add_device(0x30, 163); // SM100 // SM100Monitor - type 0x0362 EMS+ - for SM100 and SM200 - uart_telegram({0xB0, 0x0B, 0xFF, 00, 0x02, 0x62, 00, 0x44, 0x02, 0x7A, 0x80, 00, 0x80, 0x00, 0x80, 00, - 0x80, 00, 0x80, 00, 0x80, 00, 00, 0x7C, 0x80, 00, 0x80, 00, 0x80, 00, 0x80}); + uart_telegram({0xB0, 0x0B, 0xFF, 00, 0x02, 0x62, 00, 0x44, 0x02, 0x7A, 0x80, 00, 0x80, 0x00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 00, 0x7C, 0x80, 00, 0x80, 00, 0x80, 00, 0x80}); - uart_telegram({0xB0, 0x0B, 0xFF, 0x00, 0x02, 0x62, 0x01, 0x44, 0x03, 0x30, 0x80, 00, 0x80, 00, 0x80, 00, - 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 0x33}); + uart_telegram({0xB0, 0x0B, 0xFF, 0x00, 0x02, 0x62, 0x01, 0x44, 0x03, 0x30, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 0x33}); uart_telegram({0xB0, 00, 0xFF, 0x18, 02, 0x62, 0x80, 00, 0xB8}); @@ -336,8 +329,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { // add some data // Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25) - uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, - 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); + uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); // Boiler -> Thermostat, UBAParameterWW(0x33), telegram: 08 97 33 00 23 24 (#data=2) uart_telegram({0x08, 0x98, 0x33, 0x00, 0x23, 0x24}); @@ -346,8 +338,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { uart_telegram({0x08, 0x0B, 0x33, 0x00, 0x08, 0xFF, 0x34, 0xFB, 0x00, 0x28, 0x00, 0x00, 0x46, 0x00, 0xFF, 0xFF, 0x00}); // Thermostat RCPLUSStatusMessage_HC1(0x01A5) - uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, - 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); + uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); // time uart_telegram({0x98, 0x00, 0x06, 0x00, 0x00, 0x03, 0x04, 0x0C, 0x02, 0x33, 0x06, 00, 00, 00, 00, 00, 00}); @@ -439,8 +430,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { add_device(0x18, 202); // Bosch TC100 - https://github.com/proddy/EMS-ESP/issues/474 // 0x0A - uart_telegram({0x98, 0x0B, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); + uart_telegram({0x98, 0x0B, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); } if (command == "solar") { @@ -470,11 +460,9 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { // SM100Monitor - type 0x0362 EMS+ - for SM100 and SM200 // B0 0B FF 00 02 62 00 44 02 7A 80 00 80 00 80 00 80 00 80 00 80 00 00 7C 80 00 80 00 80 00 80 - rx_telegram({0xB0, 0x0B, 0xFF, 00, 0x02, 0x62, 00, 0x44, 0x02, 0x7A, 0x80, 00, 0x80, 0x00, 0x80, 00, - 0x80, 00, 0x80, 00, 0x80, 00, 00, 0x7C, 0x80, 00, 0x80, 00, 0x80, 00, 0x80}); + rx_telegram({0xB0, 0x0B, 0xFF, 00, 0x02, 0x62, 00, 0x44, 0x02, 0x7A, 0x80, 00, 0x80, 0x00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 00, 0x7C, 0x80, 00, 0x80, 00, 0x80, 00, 0x80}); - rx_telegram({0xB0, 0x0B, 0xFF, 0x00, 0x02, 0x62, 0x01, 0x44, 0x03, 0x30, 0x80, 00, 0x80, 00, 0x80, 00, - 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 0x33}); + rx_telegram({0xB0, 0x0B, 0xFF, 0x00, 0x02, 0x62, 0x01, 0x44, 0x03, 0x30, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 00, 0x80, 0x33}); rx_telegram({0xB0, 00, 0xFF, 0x18, 02, 0x62, 0x80, 00, 0xB8}); @@ -553,8 +541,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { // RCPLUSStatusMessage_HC1(0x01A5) // 98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03 (no CRC) - uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, - 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); + uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); uart_telegram("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03"); // without CRC uart_telegram_withCRC("98 00 FF 00 01 A6 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03 6B"); // with CRC @@ -583,8 +570,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { // fake telegrams. length includes CRC // Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25) - uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, - 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); + uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A, 0x80, 0x00, 0x01, 0xE1, 0x01, 0x76, 0x0E, 0x3D, 0x48, 0x00, 0xC9, 0x44, 0x02, 0x00}); // Boiler -> Thermostat, UBAParameterWW(0x33), telegram: 08 97 33 00 23 24 (#data=2) uart_telegram({0x08, 0x97, 0x33, 0x00, 0x23, 0x24}); @@ -610,12 +596,10 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { // Thermostat -> all, telegram: 10 00 FF 00 01 A5 00 D7 21 00 00 00 00 30 01 84 01 01 03 01 84 01 F1 00 00 11 01 00 08 63 00 // 0x1A5 test ems+ - uart_telegram({0x10, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xD7, 0x21, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x84, - 0x01, 0x01, 0x03, 0x01, 0x84, 0x01, 0xF1, 0x00, 0x00, 0x11, 0x01, 0x00, 0x08, 0x63, 0x00}); + uart_telegram({0x10, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xD7, 0x21, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x84, 0x01, 0x01, 0x03, 0x01, 0x84, 0x01, 0xF1, 0x00, 0x00, 0x11, 0x01, 0x00, 0x08, 0x63, 0x00}); // setting temp from 21.5 to 19.9C - uart_telegram({0x10, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xC7, 0x21, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x84, - 0x01, 0x01, 0x03, 0x01, 0x84, 0x01, 0xF1, 0x00, 0x00, 0x11, 0x01, 0x00, 0x08, 0x63, 0x00}); + uart_telegram({0x10, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xC7, 0x21, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x84, 0x01, 0x01, 0x03, 0x01, 0x84, 0x01, 0xF1, 0x00, 0x00, 0x11, 0x01, 0x00, 0x08, 0x63, 0x00}); // Thermostat -> Boiler, UBAFlags(0x35), telegram: 17 08 35 00 11 00 (#data=2) uart_telegram({0x17, 0x08, 0x35, 0x00, 0x11, 0x00}); @@ -624,12 +608,10 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { uart_telegram({0x17, 0x08, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00}); // Thermostat -> Me, RC20Set(0xA8), telegram: 17 0B A8 00 01 00 FF F6 01 06 00 01 0D 01 00 FF FF 01 02 02 02 00 00 05 1F 05 1F 02 0E 00 FF (#data=27) - uart_telegram({0x17, 0x0B, 0xA8, 0x00, 0x01, 0x00, 0xFF, 0xF6, 0x01, 0x06, 0x00, 0x01, 0x0D, 0x01, 0x00, 0xFF, - 0xFF, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x05, 0x1F, 0x05, 0x1F, 0x02, 0x0E, 0x00, 0xFF}); + uart_telegram({0x17, 0x0B, 0xA8, 0x00, 0x01, 0x00, 0xFF, 0xF6, 0x01, 0x06, 0x00, 0x01, 0x0D, 0x01, 0x00, 0xFF, 0xFF, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x05, 0x1F, 0x05, 0x1F, 0x02, 0x0E, 0x00, 0xFF}); // Boiler(0x08) -> All(0x00), UBAMonitorWW(0x34), data: 36 01 A5 80 00 21 00 00 01 00 01 3E 8D 03 77 91 00 80 00 - uart_telegram( - {0x08, 0x00, 0x34, 0x00, 0x36, 0x01, 0xA5, 0x80, 0x00, 0x21, 0x00, 0x00, 0x01, 0x00, 0x01, 0x3E, 0x8D, 0x03, 0x77, 0x91, 0x00, 0x80, 0x00}); + uart_telegram({0x08, 0x00, 0x34, 0x00, 0x36, 0x01, 0xA5, 0x80, 0x00, 0x21, 0x00, 0x00, 0x01, 0x00, 0x01, 0x3E, 0x8D, 0x03, 0x77, 0x91, 0x00, 0x80, 0x00}); // test 0x2A - DHWStatus3 uart_telegram({0x88, 00, 0x2A, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0xD2, 00, 00, 0x80, 00, 00, 01, 0x9D, 0x80, 0x00, 0x02, 0x79, 00}); @@ -657,8 +639,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { EMSESP::send_write_request(0x91, 0x17, 0x00, t18, sizeof(t18), 0x00); // TX - send EMS+ - const uint8_t t13[] = {0x90, 0x0B, 0xFF, 00, 01, 0xBA, 00, 0x2E, 0x2A, 0x26, 0x1E, 0x03, - 00, 0xFF, 0xFF, 05, 0x2A, 01, 0xE1, 0x20, 0x01, 0x0F, 05, 0x2A}; + const uint8_t t13[] = {0x90, 0x0B, 0xFF, 00, 01, 0xBA, 00, 0x2E, 0x2A, 0x26, 0x1E, 0x03, 00, 0xFF, 0xFF, 05, 0x2A, 01, 0xE1, 0x20, 0x01, 0x0F, 05, 0x2A}; EMSESP::txservice_.add(Telegram::Operation::TX_RAW, t13, sizeof(t13)); // EMS+ Junkers read request @@ -740,8 +721,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { add_device(0x18, 157); // Bosch CR100 - https://github.com/proddy/EMS-ESP/issues/355 // RCPLUSStatusMessage_HC1(0x01A5) - HC1 - uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, - 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); + uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); uart_telegram("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03"); // without CRC uart_telegram_withCRC("98 00 FF 00 01 A5 00 CF 21 2E 00 00 2E 24 03 25 03 03 01 03 25 00 C8 00 00 11 01 03 13"); // with CRC @@ -808,8 +788,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { if (command == "rx2") { shell.printfln(F("Testing rx2...")); - uart_telegram({0x1B, 0x5B, 0xFD, 0x2D, 0x9E, 0x3A, 0xB6, 0xE5, 0x02, 0x20, 0x33, 0x30, 0x32, 0x3A, 0x20, 0x5B, - 0x73, 0xFF, 0xFF, 0xCB, 0xDF, 0xB7, 0xA7, 0xB5, 0x67, 0x77, 0x77, 0xE4, 0xFF, 0xFD, 0x77, 0xFF}); + uart_telegram({0x1B, 0x5B, 0xFD, 0x2D, 0x9E, 0x3A, 0xB6, 0xE5, 0x02, 0x20, 0x33, 0x30, 0x32, 0x3A, 0x20, 0x5B, 0x73, 0xFF, 0xFF, 0xCB, 0xDF, 0xB7, 0xA7, 0xB5, 0x67, 0x77, 0x77, 0xE4, 0xFF, 0xFD, 0x77, 0xFF}); } // https://github.com/proddy/EMS-ESP/issues/380#issuecomment-633663007 @@ -974,6 +953,52 @@ 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}); } +void Test::listDir(fs::FS & fs, const char * dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\r\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("- failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println(" - not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.name(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print("\tSIZE: "); + Serial.println(file.size()); + } + file = root.openNextFile(); + } +} + +void Test::debug(uuid::console::Shell & shell, const std::string & cmd) { + // shell.add_flags(CommandFlags::ADMIN); // switch to su + + std::string command(20, '\0'); + if ((cmd.empty()) || (cmd == "default")) { + command = "ls"; + } else { + command = cmd; + } + + if (command == "ls") { + listDir(LITTLEFS, "/", 3); + } +} + } // namespace emsesp #endif diff --git a/src/test/test.h b/src/test/test.h index 15a93336b..0e93118c9 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -42,6 +42,10 @@ class Test { static void uart_telegram(const char * rx_data); static void uart_telegram_withCRC(const char * rx_data); static void add_device(uint8_t device_id, uint8_t product_id); + static void debug(uuid::console::Shell & shell, const std::string & command); + + private: + static void listDir(fs::FS & fs, const char * dirname, uint8_t levels); }; } // namespace emsesp