convert cmd's to lowercase

This commit is contained in:
proddy
2020-11-27 20:52:33 +01:00
parent 388c959468
commit 45933d3c3b

View File

@@ -30,6 +30,11 @@ std::vector<Command::CmdFunction> Command::cmdfunctions_;
// id may be used to represent a heating circuit for example // id may be used to represent a heating circuit for example
// returns false if error or not found // returns false if error or not found
bool Command::call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id) { bool Command::call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id) {
auto cf = find_command(device_type, cmd);
if ((cf == nullptr) || (cf->cmdfunction_json_)) {
return false; // command not found, or requires a json
}
#ifdef EMSESP_DEBUG #ifdef EMSESP_DEBUG
std::string dname = EMSdevice::device_type_2_device_name(device_type); std::string dname = EMSdevice::device_type_2_device_name(device_type);
if (value == nullptr) { if (value == nullptr) {
@@ -41,11 +46,6 @@ bool Command::call(const uint8_t device_type, const char * cmd, const char * val
} }
#endif #endif
auto cf = find_command(device_type, cmd);
if ((cf == nullptr) || (cf->cmdfunction_json_)) {
return false; // command not found, or requires a json
}
return ((cf->cmdfunction_)(value, id)); return ((cf->cmdfunction_)(value, id));
} }
@@ -53,6 +53,11 @@ bool Command::call(const uint8_t device_type, const char * cmd, const char * val
// id may be used to represent a heating circuit for example // id may be used to represent a heating circuit for example
// returns false if error or not found // returns false if error or not found
bool Command::call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id, JsonObject & json) { bool Command::call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id, JsonObject & json) {
auto cf = find_command(device_type, cmd);
if (cf == nullptr) {
return false; // command not found or not json
}
#ifdef EMSESP_DEBUG #ifdef EMSESP_DEBUG
std::string dname = EMSdevice::device_type_2_device_name(device_type); std::string dname = EMSdevice::device_type_2_device_name(device_type);
if (value == nullptr) { if (value == nullptr) {
@@ -64,11 +69,6 @@ bool Command::call(const uint8_t device_type, const char * cmd, const char * val
} }
#endif #endif
auto cf = find_command(device_type, cmd);
if (cf == nullptr) {
return false; // command not found or not json
}
// check if json object is empty, if so quit // check if json object is empty, if so quit
if (json.isNull()) { if (json.isNull()) {
LOG_WARNING(F("Ignore call for command %s in %s because no json"), cmd, EMSdevice::device_type_2_device_name(device_type).c_str()); LOG_WARNING(F("Ignore call for command %s in %s because no json"), cmd, EMSdevice::device_type_2_device_name(device_type).c_str());
@@ -108,13 +108,20 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ch
return nullptr; return nullptr;
} }
// convert cmd to lowercase and compare
char lowerCmd[20];
strlcpy(lowerCmd, cmd, sizeof(lowerCmd));
for (char * p = lowerCmd; *p; p++) {
*p = tolower(*p);
}
for (auto & cf : cmdfunctions_) { for (auto & cf : cmdfunctions_) {
if (!strcmp_P(cmd, reinterpret_cast<PGM_P>(cf.cmd_)) && (cf.device_type_ == device_type)) { if (!strcmp_P(lowerCmd, reinterpret_cast<PGM_P>(cf.cmd_)) && (cf.device_type_ == device_type)) {
return &cf; return &cf;
} }
} }
return nullptr; // not found return nullptr; // command not found
} }
// output list of all commands to console for a specific DeviceType // output list of all commands to console for a specific DeviceType