Add upload binary decode to logging

This commit is contained in:
Theo Arends 2021-05-17 15:15:35 +02:00
parent e28006f2c7
commit caaee6b103
2 changed files with 19 additions and 23 deletions

View File

@ -535,6 +535,24 @@ char* Trim(char* p)
return 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) { String UrlEncode(const String& text) {
const char hex[] = "0123456789ABCDEF"; const char hex[] = "0123456789ABCDEF";
@ -567,25 +585,6 @@ String UrlEncode(const String& text) {
return encoded; 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* NoAlNumToUnderscore(char* dest, const char* source)
{ {
char* write = dest; char* write = dest;
@ -2405,9 +2404,6 @@ void AddLogSpi(bool hardware, uint32_t clk, uint32_t mosi, uint32_t miso) {
} }
} }
/*********************************************************************************************\ /*********************************************************************************************\
* Uncompress static PROGMEM strings * Uncompress static PROGMEM strings
\*********************************************************************************************/ \*********************************************************************************************/

View File

@ -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\""), 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) { if (type != nullptr) {
Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}")); Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}"));