From caaee6b10334e97cee59c4242c5e8e3f8d07ead1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 17 May 2021 15:15:35 +0200 Subject: [PATCH] Add upload binary decode to logging --- tasmota/support.ino | 40 +++++++++++++++++-------------------- tasmota/support_command.ino | 2 +- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 5f8c123fd..a65392ca9 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -535,6 +535,24 @@ char* Trim(char* p) return p; } +String HexToString(uint8_t* data, uint32_t length) { + if (!data || !length) { return ""; } + + uint32_t len = (length < 16) ? length : 16; + char hex_data[32]; + ToHex_P((const unsigned char*)data, len, hex_data, sizeof(hex_data)); + String result = hex_data; + result += F(" ["); + for (uint32_t i = 0; i < len; i++) { + result += (isprint(data[i])) ? (char)data[i] : ' '; + } + result += F("]"); + if (length > len) { + result += F(" ..."); + } + return result; +} + String UrlEncode(const String& text) { const char hex[] = "0123456789ABCDEF"; @@ -567,25 +585,6 @@ String UrlEncode(const String& text) { return encoded; } -/* -char* RemoveAllSpaces(char* p) -{ - // remove any white space from the base64 - char *cursor = p; - uint32_t offset = 0; - while (1) { - *cursor = *(cursor + offset); - if ((' ' == *cursor) || ('\t' == *cursor) || ('\n' == *cursor)) { // if space found, remove this char until end of string - offset++; - } else { - if (0 == *cursor) { break; } - cursor++; - } - } - return p; -} -*/ - char* NoAlNumToUnderscore(char* dest, const char* source) { char* write = dest; @@ -2405,9 +2404,6 @@ void AddLogSpi(bool hardware, uint32_t clk, uint32_t mosi, uint32_t miso) { } } - - - /*********************************************************************************************\ * Uncompress static PROGMEM strings \*********************************************************************************************/ diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 971536ef6..c26c6fd3c 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -241,7 +241,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) } AddLog_P(LOG_LEVEL_DEBUG, PSTR("CMD: " D_GROUP " %d, " D_INDEX " %d, " D_COMMAND " \"%s\", " D_DATA " \"%s\""), - grpflg, index, type, (binary_data) ? PSTR("Binary") : dataBuf); + grpflg, index, type, (binary_data) ? HexToString((uint8_t*)dataBuf, data_len).c_str() : dataBuf); if (type != nullptr) { Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}"));