From 593675eb7ab039081592bff7bde7f93480f064a8 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 23 Dec 2020 18:26:15 +0100 Subject: [PATCH] Removal of global log_data providing re-entry Removal of global log_data providing re-entry and freeing 700k RAM --- tasmota/support.ino | 4 --- tasmota/tasmota.ino | 1 - tasmota/xdrv_99_debug.ino | 71 ++++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 30aee6b68..2697e257a 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -2029,10 +2029,6 @@ void AddLogData(uint32_t loglevel, const char* log_data) { } } -void AddLog(uint32_t loglevel) { - AddLogData(loglevel, TasmotaGlobal.log_data); -} - void AddLog_P(uint32_t loglevel, PGM_P formatP, ...) { char log_data[LOGSZ]; diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 11c699f2d..b70bd4637 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -170,7 +170,6 @@ struct { char mqtt_client[99]; // Composed MQTT Clientname char mqtt_topic[TOPSZ]; // Composed MQTT topic char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer - char log_data[LOGSZ]; // Logging char log_buffer[LOG_BUFFER_SIZE]; // Web log buffer } TasmotaGlobal; diff --git a/tasmota/xdrv_99_debug.ino b/tasmota/xdrv_99_debug.ino index 06dccf8e5..e4f00cec2 100644 --- a/tasmota/xdrv_99_debug.ino +++ b/tasmota/xdrv_99_debug.ino @@ -222,7 +222,7 @@ void DebugFreeMem(void) void DebugRtcDump(char* parms) { #ifdef ESP8266 - #define CFG_COLS 16 + uint32_t CFG_COLS = 16; uint16_t idx; uint16_t maxrow; @@ -258,24 +258,25 @@ void DebugRtcDump(char* parms) maxrow = srow + mrow; } + char log_data[LOGSZ]; for (row = srow; row < maxrow; row++) { idx = row * CFG_COLS; - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), idx); + snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx); for (col = 0; col < CFG_COLS; col++) { if (!(col%4)) { - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[idx + col]); + snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data); for (col = 0; col < CFG_COLS; col++) { // if (!(col%4)) { -// snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data); +// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data); // } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' '); + snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' '); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s|"), TasmotaGlobal.log_data); - AddLog(LOG_LEVEL_INFO); + snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data); + AddLogData(LOG_LEVEL_INFO, log_data); } #endif // ESP8266 } @@ -309,34 +310,32 @@ void DebugDump(uint32_t start, uint32_t size) { maxrow = srow + mrow; } + char log_data[LOGSZ]; for (row = srow; row < maxrow; row++) { idx = row * CFG_COLS; - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), idx); + snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx); for (col = 0; col < CFG_COLS; col++) { if (!(col%4)) { - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[idx + col]); + snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data); for (col = 0; col < CFG_COLS; col++) { // if (!(col%4)) { -// snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data); +// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data); // } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' '); + snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' '); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s|"), TasmotaGlobal.log_data); - AddLog(LOG_LEVEL_INFO); + snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data); + AddLogData(LOG_LEVEL_INFO, log_data); delay(1); } } - - - void DebugCfgDump(char* parms) { - #define CFG_COLS 16 + uint32_t CFG_COLS = 16; uint16_t idx; uint16_t maxrow; @@ -362,24 +361,25 @@ void DebugCfgDump(char* parms) maxrow = srow + mrow; } + char log_data[LOGSZ]; for (row = srow; row < maxrow; row++) { idx = row * CFG_COLS; - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), idx); + snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx); for (col = 0; col < CFG_COLS; col++) { if (!(col%4)) { - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[idx + col]); + snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data); for (col = 0; col < CFG_COLS; col++) { // if (!(col%4)) { -// snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data); +// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data); // } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' '); + snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' '); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s|"), TasmotaGlobal.log_data); - AddLog(LOG_LEVEL_INFO); + snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data); + AddLogData(LOG_LEVEL_INFO, log_data); delay(1); } } @@ -397,16 +397,17 @@ void DebugCfgPeek(char* parms) uint16_t data16 = (buffer[address +1] << 8) + buffer[address]; uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + data16; - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), address); + char log_data[LOGSZ]; + snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), address); for (uint32_t i = 0; i < 4; i++) { - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[address +i]); + snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[address +i]); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data); + snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data); for (uint32_t i = 0; i < 4; i++) { - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' '); + snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' '); } - snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), TasmotaGlobal.log_data, data8, data8, data16, data16, data32, data32); - AddLog(LOG_LEVEL_INFO); + snprintf_P(log_data, sizeof(log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), log_data, data8, data8, data16, data16, data32, data32); + AddLogData(LOG_LEVEL_INFO, log_data); } void DebugCfgPoke(char* parms)