Removal of global log_data providing re-entry

Removal of global log_data providing re-entry and freeing 700k RAM
This commit is contained in:
Theo Arends 2020-12-23 18:26:15 +01:00
parent 61c559e748
commit 593675eb7a
3 changed files with 36 additions and 40 deletions

View File

@ -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, ...) void AddLog_P(uint32_t loglevel, PGM_P formatP, ...)
{ {
char log_data[LOGSZ]; char log_data[LOGSZ];

View File

@ -170,7 +170,6 @@ struct {
char mqtt_client[99]; // Composed MQTT Clientname char mqtt_client[99]; // Composed MQTT Clientname
char mqtt_topic[TOPSZ]; // Composed MQTT topic char mqtt_topic[TOPSZ]; // Composed MQTT topic
char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer 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 char log_buffer[LOG_BUFFER_SIZE]; // Web log buffer
} TasmotaGlobal; } TasmotaGlobal;

View File

@ -222,7 +222,7 @@ void DebugFreeMem(void)
void DebugRtcDump(char* parms) void DebugRtcDump(char* parms)
{ {
#ifdef ESP8266 #ifdef ESP8266
#define CFG_COLS 16 uint32_t CFG_COLS = 16;
uint16_t idx; uint16_t idx;
uint16_t maxrow; uint16_t maxrow;
@ -258,24 +258,25 @@ void DebugRtcDump(char* parms)
maxrow = srow + mrow; maxrow = srow + mrow;
} }
char log_data[LOGSZ];
for (row = srow; row < maxrow; row++) { for (row = srow; row < maxrow; row++) {
idx = row * CFG_COLS; 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++) { for (col = 0; col < CFG_COLS; col++) {
if (!(col%4)) { 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++) { for (col = 0; col < CFG_COLS; col++) {
// if (!(col%4)) { // 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); snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
AddLog(LOG_LEVEL_INFO); AddLogData(LOG_LEVEL_INFO, log_data);
} }
#endif // ESP8266 #endif // ESP8266
} }
@ -309,34 +310,32 @@ void DebugDump(uint32_t start, uint32_t size) {
maxrow = srow + mrow; maxrow = srow + mrow;
} }
char log_data[LOGSZ];
for (row = srow; row < maxrow; row++) { for (row = srow; row < maxrow; row++) {
idx = row * CFG_COLS; 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++) { for (col = 0; col < CFG_COLS; col++) {
if (!(col%4)) { 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++) { for (col = 0; col < CFG_COLS; col++) {
// if (!(col%4)) { // 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); snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
AddLog(LOG_LEVEL_INFO); AddLogData(LOG_LEVEL_INFO, log_data);
delay(1); delay(1);
} }
} }
void DebugCfgDump(char* parms) void DebugCfgDump(char* parms)
{ {
#define CFG_COLS 16 uint32_t CFG_COLS = 16;
uint16_t idx; uint16_t idx;
uint16_t maxrow; uint16_t maxrow;
@ -362,24 +361,25 @@ void DebugCfgDump(char* parms)
maxrow = srow + mrow; maxrow = srow + mrow;
} }
char log_data[LOGSZ];
for (row = srow; row < maxrow; row++) { for (row = srow; row < maxrow; row++) {
idx = row * CFG_COLS; 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++) { for (col = 0; col < CFG_COLS; col++) {
if (!(col%4)) { 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++) { for (col = 0; col < CFG_COLS; col++) {
// if (!(col%4)) { // 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); snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
AddLog(LOG_LEVEL_INFO); AddLogData(LOG_LEVEL_INFO, log_data);
delay(1); delay(1);
} }
} }
@ -397,16 +397,17 @@ void DebugCfgPeek(char* parms)
uint16_t data16 = (buffer[address +1] << 8) + buffer[address]; uint16_t data16 = (buffer[address +1] << 8) + buffer[address];
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + data16; 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++) { 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++) { 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); 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);
AddLog(LOG_LEVEL_INFO); AddLogData(LOG_LEVEL_INFO, log_data);
} }
void DebugCfgPoke(char* parms) void DebugCfgPoke(char* parms)