From 5ec972376c836f8f10aa3cbd1dce1ea3a71809ec Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 10 Oct 2020 17:00:37 +0200 Subject: [PATCH] Consolidate function RemoveSpace --- tasmota/support.ino | 15 ++++++++------- tasmota/xdrv_02_mqtt.ino | 2 +- tasmota/xdrv_23_zigbee_A_impl.ino | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 7eb6f5ea1..ecaf63e26 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -359,8 +359,8 @@ char* Unescape(char* buffer, uint32_t* size) return buffer; } -char* RemoveSpace(char* p) -{ +char* RemoveSpace(char* p) { + // Remove white-space character (' ','\t','\n','\v','\f','\r') char* write = p; char* read = p; char ch = '.'; @@ -371,12 +371,11 @@ char* RemoveSpace(char* p) *write++ = ch; } } -// *write = '\0'; // Removed 20190223 as it buffer overflows on no isspace found - no need either return p; } -char* RemoveControlCharacter(char* p) -{ +char* RemoveControlCharacter(char* p) { + // Remove control character (0x00 .. 0x1F and 0x7F) char* write = p; char* read = p; char ch = '.'; @@ -391,8 +390,8 @@ char* RemoveControlCharacter(char* p) return p; } -char* ReplaceCommaWithDot(char* p) -{ +char* ReplaceCommaWithDot(char* p) { + // Replace character ',' with '.' char* write = (char*)p; char* read = (char*)p; char ch = '.'; @@ -458,6 +457,7 @@ char* Trim(char* p) return p; } +/* char* RemoveAllSpaces(char* p) { // remove any white space from the base64 @@ -474,6 +474,7 @@ char* RemoveAllSpaces(char* p) } return p; } +*/ char* NoAlNumToUnderscore(char* dest, const char* source) { diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index c5bd6a404..bee6eb941 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -1174,7 +1174,7 @@ void CmndTlsKey(void) { memcpy_P(spi_buffer, tls_spi_start, tls_spi_len); // remove any white space from the base64 - RemoveAllSpaces(XdrvMailbox.data); + RemoveSpace(XdrvMailbox.data); // allocate buffer for decoded base64 uint32_t bin_len = decode_base64_length((unsigned char*)XdrvMailbox.data); diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index de8373ad6..7c6eb9917 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -413,7 +413,7 @@ void ZbSendSend(class JsonParserToken val_cmd, uint16_t device, uint16_t groupad x = value.getUInt(); // automatic conversion to 0/1 // if (value.is()) { // // x = value.as() ? 1 : 0; - // } else if + // } else if // } else if (value.is()) { // x = value.as(); } else { @@ -1263,13 +1263,13 @@ bool parseDeviceInnerData(class Z_Device & device, JsonParserObject root) { // Import generic attributes first Z_Data & data = device.data.getByType(data_type, endpoint); - + // scan through attributes for (auto attr : data_values) { JsonParserToken attr_value = attr.getValue(); uint8_t conv_zigbee_type; Z_Data_Type conv_data_type; - uint8_t conv_map_offset; + uint8_t conv_map_offset; if (zigbeeFindAttributeByName(attr.getStr(), nullptr, nullptr, nullptr, &conv_zigbee_type, &conv_data_type, &conv_map_offset) != nullptr) { // found an attribute matching the name, does is fit the type? if (conv_data_type == data_type) { @@ -1340,7 +1340,7 @@ bool parseDeviceInnerData(class Z_Device & device, JsonParserObject root) { // void CmndZbData(void) { if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; } - RemoveAllSpaces(XdrvMailbox.data); + RemoveSpace(XdrvMailbox.data); if (XdrvMailbox.data[0] == '{') { // JSON input, enter saved data into memory -- essentially for debugging JsonParser parser(XdrvMailbox.data); @@ -1448,7 +1448,7 @@ void CmndZbConfig(void) { int8_t zb_txradio_dbm = Settings.zb_txradio_dbm; // if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; } - RemoveAllSpaces(XdrvMailbox.data); + RemoveSpace(XdrvMailbox.data); if (strlen(XdrvMailbox.data) > 0) { JsonParser parser(XdrvMailbox.data); JsonParserObject root = parser.getRootObject();