Browse Source

Dinamically assign debug messages size

fastled
Xose Pérez 7 years ago
parent
commit
502be7732d
2 changed files with 11 additions and 22 deletions
  1. +1
    -2
      code/espurna/config/general.h
  2. +10
    -20
      code/espurna/debug.ino

+ 1
- 2
code/espurna/config/general.h View File

@ -63,10 +63,9 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// General debug options and macros // 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 #define DEBUG_SUPPORT DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT || DEBUG_TELNET_SUPPORT
#if DEBUG_SUPPORT #if DEBUG_SUPPORT
#define DEBUG_MSG(...) debugSend(__VA_ARGS__) #define DEBUG_MSG(...) debugSend(__VA_ARGS__)
#define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__) #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__)


+ 10
- 20
code/espurna/debug.ino View File

@ -18,18 +18,16 @@ WiFiUDP udpDebug;
void debugSend(const char * format, ...) { void debugSend(const char * format, ...) {
char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
va_list args; va_list args;
va_start(args, format); 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); va_end(args);
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.printf(buffer); DEBUG_PORT.printf(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
DEBUG_PORT.printf(" (...)\n");
}
#endif #endif
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
@ -38,9 +36,6 @@ void debugSend(const char * format, ...) {
#endif #endif
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer); udpDebug.write(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
udpDebug.write(" (...)\n");
}
udpDebug.endPacket(); udpDebug.endPacket();
delay(1); delay(1);
#if SYSTEM_CHECK_ENABLED #if SYSTEM_CHECK_ENABLED
@ -56,21 +51,19 @@ void debugSend(const char * format, ...) {
void debugSend_P(PGM_P 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_list args;
va_start(args, format); 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); va_end(args);
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.printf(buffer); DEBUG_PORT.printf(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
DEBUG_PORT.printf(" (...)\n");
}
#endif #endif
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
@ -79,9 +72,6 @@ void debugSend_P(PGM_P format, ...) {
#endif #endif
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer); udpDebug.write(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) {
udpDebug.write(" (...)\n");
}
udpDebug.endPacket(); udpDebug.endPacket();
delay(1); delay(1);
#if SYSTEM_CHECK_ENABLED #if SYSTEM_CHECK_ENABLED


Loading…
Cancel
Save