From e71e17bed1480e13ee4fffe23c2ad2210ccc7d48 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 13 Aug 2020 17:50:27 +0200 Subject: [PATCH] telegram functions can't be static - #445 --- src/devices/boiler.cpp | 2 ++ src/devices/thermostat.cpp | 2 ++ src/emsdevice.cpp | 3 --- src/emsdevice.h | 11 +++++------ src/emsesp.cpp | 12 +++++++----- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index d5540c261..83cf7e096 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -26,6 +26,8 @@ uuid::log::Logger Boiler::logger_{F_(boiler), uuid::log::Facility::CONSOLE}; Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand) : EMSdevice(device_type, device_id, product_id, version, name, flags, brand) { + this->reserve_mem(20); // reserve some space for the telegram registries, to avoid memory fragmentation + LOG_DEBUG(F("Adding new Boiler with device ID 0x%02X"), device_id); // the telegram handlers... diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index edd7a2ffd..f2211bbac 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -26,6 +26,8 @@ uuid::log::Logger Thermostat::logger_{F_(thermostat), uuid::log::Facility::CONSO Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand) : EMSdevice(device_type, device_id, product_id, version, name, flags, brand) { + this->reserve_mem(25); // reserve some space for the telegram registries, to avoid memory fragmentation + // common telegram handlers register_telegram_type(EMS_TYPE_RCOutdoorTemp, F("RCOutdoorTemp"), false, [&](std::shared_ptr t) { process_RCOutdoorTemp(t); }); register_telegram_type(EMS_TYPE_RCTime, F("RCTime"), false, [&](std::shared_ptr t) { process_RCTime(t); }); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index d8e9f7c22..b223e33ba 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -24,8 +24,6 @@ namespace emsesp { uuid::log::Logger EMSdevice::logger_{F_(emsesp), uuid::log::Facility::CONSOLE}; -std::vector EMSdevice::telegram_functions_; - std::string EMSdevice::brand_to_string() const { switch (brand_) { case EMSdevice::Brand::BOSCH: @@ -248,7 +246,6 @@ void EMSdevice::register_mqtt_topic(const std::string & topic, mqtt_subfunction_ } void EMSdevice::register_mqtt_cmd(const __FlashStringHelper * cmd, mqtt_cmdfunction_p f) { - LOG_DEBUG(F("Registering MQTT cmd %s for device type %s"), uuid::read_flash_string(cmd).c_str(), this->device_type_name().c_str()); Mqtt::add_command(this->device_type_, this->device_id_, cmd, f); } diff --git a/src/emsdevice.h b/src/emsdevice.h index 4113b7c1d..6e5025d51 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -147,7 +147,7 @@ class EMSdevice { void fetch_values(); void toggle_fetch(uint16_t telegram_id, bool toggle); - static void reserve_mem(size_t n) { + void reserve_mem(size_t n) { telegram_functions_.reserve(n); } @@ -229,8 +229,7 @@ class EMSdevice { }; enum DeviceType : uint8_t { - UNKNOWN = 0, - SERVICEKEY, // us + SERVICEKEY = 0, // this is us BOILER, THERMOSTAT, MIXING, @@ -280,11 +279,11 @@ class EMSdevice { private: uint8_t unique_id_; - uint8_t device_type_ = DeviceType::UNKNOWN; + uint8_t device_type_ = DeviceType::SERVICEKEY; uint8_t device_id_ = 0; uint8_t product_id_ = 0; std::string version_; - std::string name_; // the long name of the EMS model + std::string name_; // the long name for the EMS model uint8_t flags_ = 0; uint8_t brand_ = Brand::NO_BRAND; @@ -304,7 +303,7 @@ class EMSdevice { , process_function_(process_function) { } }; - static std::vector telegram_functions_; // each EMS device has its own set of registered telegram types + std::vector telegram_functions_; // each EMS device has its own set of registered telegram types }; } // namespace emsesp diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 4d8396970..a96a1dab7 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -573,7 +573,7 @@ void EMSESP::show_devices(uuid::console::Shell & shell) { } shell.println(); emsdevice->show_telegram_handlers(shell); - emsdevice->show_mqtt_handlers(shell); + // emsdevice->show_mqtt_handlers(shell); shell.println(); } } @@ -793,19 +793,21 @@ void EMSESP::start() { esp8266React.begin(); // loads system settings (wifi, mqtt, etc) emsespSettingsService.begin(); // load EMS-ESP specific settings // system_.check_upgrade(); // see if we need to migrate from previous versions - mqtt_.start(); // mqtt init console_.start(); // telnet and serial console + mqtt_.start(); // mqtt init system_.start(); // starts syslog, uart, sets version, initializes LED. Requires pre-loaded settings. shower_.start(); // initialize shower timer and shower alert txservice_.start(); // sets bus ID, sends out request for EMS devices sensors_.start(); // dallas external sensors webServer.begin(); // start web server - // reserve some space for the telegram registries, to avoid memory fragmentation - EMSdevice::reserve_mem(EMSdevice::EMS_DEVICES_MAX_TELEGRAMS); // space for 20 telegram handlers - emsdevices.reserve(5); // reserve space for initially 5 devices + emsdevices.reserve(5); // reserve space for initially 5 devices to avoid mem LOG_INFO("EMS Device library loaded with %d records", device_library_.size()); + +#if defined(EMSESP_STANDALONE) + mqtt_.on_connect(); // simulate an MQTT connection +#endif } // main loop calling all services