From bfd20e559e8f2821a8890d1df5b1c015442cf48e Mon Sep 17 00:00:00 2001 From: Proddy Date: Tue, 3 Aug 2021 13:23:33 +0200 Subject: [PATCH] minor changes, make cppcheck happy --- src/command.cpp | 9 ++++++--- src/command.h | 16 ++++++++-------- src/emsdevice.h | 12 ++++++------ src/emsesp.h | 2 +- src/mqtt.cpp | 4 ++-- src/mqtt.h | 16 ++++++++-------- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index cfd886304..c3ea653c0 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -167,14 +167,13 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, char * c // add a command to the list, which does not return json // these commands are not callable directly via MQTT subscriptions either -void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_p cb, const __FlashStringHelper * description, uint8_t flags) { +void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, const cmd_function_p cb, const __FlashStringHelper * description, uint8_t flags) { // if the command already exists for that device type don't add it if (find_command(device_type, uuid::read_flash_string(cmd).c_str()) != nullptr) { return; } // if the description is empty, it's hidden which means it will not show up in Web API or Console as an available command - // TODO check whether we still need this piece of code if (description == nullptr) { flags |= CommandFlag::HIDDEN; } @@ -189,7 +188,11 @@ void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, cm // add a command to the list, which does return a json object as output // flag is fixed to MqttSubFlag::FLAG_NOSUB -void Command::add_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb, const __FlashStringHelper * description, uint8_t flags) { +void Command::add_json(const uint8_t device_type, + const __FlashStringHelper * cmd, + const cmd_json_function_p cb, + const __FlashStringHelper * description, + uint8_t flags) { // if the command already exists for that device type don't add it if (find_command(device_type, uuid::read_flash_string(cmd).c_str()) != nullptr) { return; diff --git a/src/command.h b/src/command.h index bbc27a9fb..69d988ccb 100644 --- a/src/command.h +++ b/src/command.h @@ -55,8 +55,8 @@ enum CommandRet : uint8_t { }; -using cmdfunction_p = std::function; -using cmdfunction_json_p = std::function; +using cmd_function_p = std::function; +using cmd_json_function_p = std::function; class Command { public: @@ -64,15 +64,15 @@ class Command { uint8_t device_type_; // DeviceType:: uint8_t flags_; // mqtt flags for command subscriptions const __FlashStringHelper * cmd_; - cmdfunction_p cmdfunction_; - cmdfunction_json_p cmdfunction_json_; + const cmd_function_p cmdfunction_; + const cmd_json_function_p cmdfunction_json_; const __FlashStringHelper * description_; CmdFunction(const uint8_t device_type, const uint8_t flags, const __FlashStringHelper * cmd, - cmdfunction_p cmdfunction, - cmdfunction_json_p cmdfunction_json, + const cmd_function_p cmdfunction, + const cmd_json_function_p cmdfunction_json, const __FlashStringHelper * description) : device_type_(device_type) , flags_(flags) @@ -105,13 +105,13 @@ class Command { static void add(const uint8_t device_type, const __FlashStringHelper * cmd, - cmdfunction_p cb, + const cmd_function_p cb, const __FlashStringHelper * description, uint8_t flags = CommandFlag::MQTT_SUB_FLAG_NORMAL); static void add_json(const uint8_t device_type, const __FlashStringHelper * cmd, - cmdfunction_json_p cb, + const cmd_json_function_p cb, const __FlashStringHelper * description, uint8_t flags = CommandFlag::MQTT_SUB_FLAG_NORMAL); diff --git a/src/emsdevice.h b/src/emsdevice.h index 4a771f0c6..38cc4f25c 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -40,7 +40,7 @@ enum DeviceValueType : uint8_t { TIME, // same as ULONG (32 bits) ENUM, TEXT, - CMD + CMD // special for commands only }; @@ -239,7 +239,7 @@ class EMSdevice { using process_function_p = std::function)>; - void register_telegram_type(const uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, process_function_p cb); + void register_telegram_type(const uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, const process_function_p cb); bool handle_telegram(std::shared_ptr telegram); std::string get_value_uom(const char * key); @@ -263,7 +263,7 @@ class EMSdevice { const __FlashStringHelper * const * options, const __FlashStringHelper * const * name, uint8_t uom, - cmdfunction_p f, + const cmd_function_p f, int32_t min, uint32_t max); void register_device_value(uint8_t tag, @@ -272,7 +272,7 @@ class EMSdevice { const __FlashStringHelper * const * options, const __FlashStringHelper * const * name, uint8_t uom, - cmdfunction_p f); + const cmd_function_p f); void register_device_value(uint8_t tag, void * value_p, uint8_t type, @@ -286,7 +286,7 @@ class EMSdevice { void read_command(const uint16_t type_id, uint8_t offset = 0, uint8_t length = 0); - void register_mqtt_topic(const std::string & topic, mqtt_subfunction_p f); + void register_mqtt_topic(const std::string & topic, const mqtt_sub_function_p f); void publish_mqtt_ha_sensor(); @@ -402,7 +402,7 @@ class EMSdevice { bool fetch_; // if this type_id be queried automatically process_function_p process_function_; - TelegramFunction(uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, process_function_p process_function) + TelegramFunction(uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, const process_function_p process_function) : telegram_type_id_(telegram_type_id) , telegram_type_name_(telegram_type_name) , fetch_(fetch) diff --git a/src/emsesp.h b/src/emsesp.h index b8c336e0d..47ef4858f 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -66,7 +66,7 @@ // helpers for callback functions #define MAKE_PF_CB(__f) [&](std::shared_ptr t) { __f(t); } // for Process Function callbacks to EMSDevice::process_function_p -#define MAKE_CF_CB(__f) [&](const char * value, const int8_t id) { return __f(value, id); } // for Command Function callbacks Command::cmdfunction_p +#define MAKE_CF_CB(__f) [&](const char * value, const int8_t id) { return __f(value, id); } // for Command Function callbacks Command::cmd_function_p namespace emsesp { diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 0e3476a79..61aeb1969 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -54,7 +54,7 @@ uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON}; // subscribe to an MQTT topic, and store the associated callback function // only if it already hasn't been added -void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_subfunction_p cb) { +void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_sub_function_p cb) { // check if we already have the topic subscribed, if so don't add it again if (!mqtt_subfunctions_.empty()) { for (auto & mqtt_subfunction : mqtt_subfunctions_) { @@ -126,7 +126,7 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper // subscribe to an MQTT topic, and store the associated callback function // For generic functions not tied to a specific device -void Mqtt::subscribe(const std::string & topic, mqtt_subfunction_p cb) { +void Mqtt::subscribe(const std::string & topic, mqtt_sub_function_p cb) { subscribe(0, topic, cb); // no device_id needed if generic to EMS-ESP } diff --git a/src/mqtt.h b/src/mqtt.h index 51cc6ca8c..609e6d545 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -46,8 +46,8 @@ using uuid::console::Shell; namespace emsesp { -using mqtt_subfunction_p = std::function; -using cmdfunction_p = std::function; +using mqtt_sub_function_p = std::function; +using cmdfunction_p = std::function; struct MqttMessage { const uint8_t operation; @@ -100,8 +100,8 @@ class Mqtt { static void on_connect(); - static void subscribe(const uint8_t device_type, const std::string & topic, mqtt_subfunction_p cb); - static void subscribe(const std::string & topic, mqtt_subfunction_p cb); + static void subscribe(const uint8_t device_type, const std::string & topic, mqtt_sub_function_p cb); + static void subscribe(const std::string & topic, mqtt_sub_function_p cb); static void resubscribe(); static void publish(const std::string & topic, const std::string & payload); @@ -239,11 +239,11 @@ class Mqtt { // function handlers for MQTT subscriptions struct MQTTSubFunction { - uint8_t device_type_; // which device type, from DeviceType:: - const std::string topic_; // short topic name - mqtt_subfunction_p mqtt_subfunction_; // can be empty + uint8_t device_type_; // which device type, from DeviceType:: + const std::string topic_; // short topic name + mqtt_sub_function_p mqtt_subfunction_; // can be empty - MQTTSubFunction(uint8_t device_type, const std::string && topic, mqtt_subfunction_p mqtt_subfunction) + MQTTSubFunction(uint8_t device_type, const std::string && topic, mqtt_sub_function_p mqtt_subfunction) : device_type_(device_type) , topic_(topic) , mqtt_subfunction_(mqtt_subfunction) {