mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
minor changes, make cppcheck happy
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -55,8 +55,8 @@ enum CommandRet : uint8_t {
|
||||
|
||||
};
|
||||
|
||||
using cmdfunction_p = std::function<bool(const char * data, const int8_t id)>;
|
||||
using cmdfunction_json_p = std::function<bool(const char * data, const int8_t id, JsonObject & json)>;
|
||||
using cmd_function_p = std::function<bool(const char * data, const int8_t id)>;
|
||||
using cmd_json_function_p = std::function<bool(const char * data, const int8_t id, JsonObject & json)>;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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(std::shared_ptr<const Telegram>)>;
|
||||
|
||||
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<const Telegram> 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)
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
|
||||
// helpers for callback functions
|
||||
#define MAKE_PF_CB(__f) [&](std::shared_ptr<const Telegram> 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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
16
src/mqtt.h
16
src/mqtt.h
@@ -46,8 +46,8 @@ using uuid::console::Shell;
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
using mqtt_subfunction_p = std::function<bool(const char * message)>;
|
||||
using cmdfunction_p = std::function<bool(const char * data, const int8_t id)>;
|
||||
using mqtt_sub_function_p = std::function<bool(const char * message)>;
|
||||
using cmdfunction_p = std::function<bool(const char * data, const int8_t id)>;
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user