From 502be7732dd5d17b50a840d0f47bb27a065e31a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 20 Nov 2017 11:24:11 +0100 Subject: [PATCH] Dinamically assign debug messages size --- code/espurna/config/general.h | 3 +-- code/espurna/debug.ino | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 19d8cbf6..040d3480 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -63,10 +63,9 @@ //------------------------------------------------------------------------------ // General debug options and macros -#define DEBUG_MESSAGE_MAX_LENGTH 80 +#define DEBUG_FORMAT_MAX_LENGTH 80 #define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT - #if DEBUG_SUPPORT #define DEBUG_MSG(...) debugSend(__VA_ARGS__) #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__) diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 0bdea8bd..48e561f7 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -18,18 +18,16 @@ WiFiUDP udpDebug; void debugSend(const char * format, ...) { - char buffer[DEBUG_MESSAGE_MAX_LENGTH+1]; - va_list args; va_start(args, format); - int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args); + char test[1]; + int len = ets_vsnprintf(test, 1, format, args) + 1; + char * buffer = new char[len]; + ets_vsnprintf(buffer, len, format, args); va_end(args); #if DEBUG_SERIAL_SUPPORT DEBUG_PORT.printf(buffer); - if (len > DEBUG_MESSAGE_MAX_LENGTH) { - DEBUG_PORT.printf(" (...)\n"); - } #endif #if DEBUG_UDP_SUPPORT @@ -38,9 +36,6 @@ void debugSend(const char * format, ...) { #endif udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); udpDebug.write(buffer); - if (len > DEBUG_MESSAGE_MAX_LENGTH) { - udpDebug.write(" (...)\n"); - } udpDebug.endPacket(); delay(1); #if SYSTEM_CHECK_ENABLED @@ -56,21 +51,19 @@ void debugSend(const char * format, ...) { void debugSend_P(PGM_P format, ...) { - char f[DEBUG_MESSAGE_MAX_LENGTH+1]; - memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH); - - char buffer[DEBUG_MESSAGE_MAX_LENGTH+1]; + char f[DEBUG_FORMAT_MAX_LENGTH+1]; + memcpy_P(f, format, DEBUG_FORMAT_MAX_LENGTH); va_list args; va_start(args, format); - int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args); + char test[1]; + int len = ets_vsnprintf(test, 1, f, args) + 1; + char * buffer = new char[len]; + ets_vsnprintf(buffer, len, f, args); va_end(args); #if DEBUG_SERIAL_SUPPORT DEBUG_PORT.printf(buffer); - if (len > DEBUG_MESSAGE_MAX_LENGTH) { - DEBUG_PORT.printf(" (...)\n"); - } #endif #if DEBUG_UDP_SUPPORT @@ -79,9 +72,6 @@ void debugSend_P(PGM_P format, ...) { #endif udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); udpDebug.write(buffer); - if (len > DEBUG_MESSAGE_MAX_LENGTH) { - udpDebug.write(" (...)\n"); - } udpDebug.endPacket(); delay(1); #if SYSTEM_CHECK_ENABLED