From 708d231c9cd80aff0ba977ac5f8396494835d809 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 2 Jan 2021 14:59:02 +0100 Subject: [PATCH] Reduce generic log buffer to 128 chars --- tasmota/support.ino | 33 ++++++++++++++++++++++++++------- tasmota/xdrv_02_mqtt.ino | 8 +++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 4845e8115..78c7f93dc 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -147,7 +147,7 @@ class TasAutoMutex { TasAutoMutex::TasAutoMutex(void **mutex, const char *name, int maxWait, bool take) { if (mutex) { if (!(*mutex)){ - TasAutoMutex::init(mutex); + TasAutoMutex::init(mutex); } this->mutex = (SemaphoreHandle_t)*mutex; this->maxWait = maxWait; @@ -2172,12 +2172,22 @@ void AddLogData(uint32_t loglevel, const char* log_data) { void AddLog_P(uint32_t loglevel, PGM_P formatP, ...) { - char log_data[LOGSZ]; + char log_data[132]; va_list arg; va_start(arg, formatP); - vsnprintf_P(log_data, sizeof(log_data), formatP, arg); + uint32_t len = vsnprintf_P(log_data, 129, formatP, arg); va_end(arg); + if (len > 128) { strcat(log_data, "..."); } // Actual data is more + +#ifdef DEBUG_TASMOTA_CORE + // Profile max_len + static uint32_t max_len = 0; + if (len > max_len) { + max_len = len; + Serial.printf("PRF: AddLog_P %d\n", max_len); + } +#endif AddLogData(loglevel, log_data); } @@ -2188,9 +2198,18 @@ void AddLog_Debug(PGM_P formatP, ...) va_list arg; va_start(arg, formatP); - vsnprintf_P(log_data, sizeof(log_data), formatP, arg); + uint32_t len = vsnprintf_P(log_data, sizeof(log_data), formatP, arg); va_end(arg); +#ifdef DEBUG_TASMOTA_CORE + // Profile max_len + static uint32_t max_len = 0; + if (len > max_len) { + max_len = len; + Serial.printf("PRF: AddLog_Debug %d\n", max_len); + } +#endif + AddLogData(LOG_LEVEL_DEBUG, log_data); } @@ -2211,13 +2230,13 @@ void AddLogMissed(const char *sensor, uint32_t misses) } void AddLogBufferSize(uint32_t loglevel, uint8_t *buffer, uint32_t count, uint32_t size) { - char log_data[LOGSZ]; + char log_data[4 + (count * size * 3)]; snprintf_P(log_data, sizeof(log_data), PSTR("DMP:")); for (uint32_t i = 0; i < count; i++) { - if (1 == size) { // uint8_t + if (1 == size) { // uint8_t snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer)); - } else { // uint16_t + } else { // uint16_t snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X%02X"), log_data, *(buffer +1), *(buffer)); } buffer += size; diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index 81de886f4..471d55ff4 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -218,11 +218,13 @@ bool MqttPublishLib(const char* topic, bool retained) { return result; } +#ifdef DEBUG_TASMOTA_CORE void MqttDumpData(char* topic, char* data, uint32_t data_len) { char dump_data[data_len +1]; memcpy(dump_data, data, sizeof(dump_data)); // Make another copy for removing optional control characters - AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, RemoveControlCharacter(dump_data)); + DEBUG_CORE_LOG(PSTR(D_LOG_MQTT "Size %d, \"%s %s\""), data_len, topic, RemoveControlCharacter(dump_data)); } +#endif void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len) { #ifdef USE_DEBUG_DRIVER @@ -248,9 +250,9 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len char data[data_len +1]; memcpy(data, mqtt_data, sizeof(data)); -// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, data); -// if (LOG_LEVEL_DEBUG_MORE <= TasmotaGlobal.seriallog_level) { Serial.println(data); } +#ifdef DEBUG_TASMOTA_CORE MqttDumpData(topic, data, data_len); // Use a function to save stack space used by dump_data +#endif // MQTT pre-processing XdrvMailbox.index = strlen(topic);