diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 6913c07e..c1957336 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -64,6 +64,11 @@ #define SERIAL_BAUDRATE 115200 // Default baudrate #endif +#ifndef DEBUG_ADD_TIMESTAMP +#define DEBUG_ADD_TIMESTAMP 1 // Add timestamp to debug messages + // (in millis overflowing every 1000 seconds) +#endif + // Second serial port (used for RX) //#define SERIAL_RX_PORT Serial // This setting is usually defined diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 5039d51a..330ac3a3 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -21,18 +21,20 @@ extern "C" { WiFiUDP _udp_debug; #endif -void debugSend(const char * format, ...) { +void _debugSend(char * message) { - va_list args; - va_start(args, format); - 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_ADD_TIMESTAMP + static bool add_timestamp = true; + char timestamp[10] = {0}; + if (add_timestamp) snprintf_P(timestamp, sizeof(timestamp), PSTR("[%06lu] "), millis() % 1000000); + add_timestamp = (message[strlen(message)-1] == 10); + #endif #if DEBUG_SERIAL_SUPPORT - DEBUG_PORT.printf(buffer); + #if DEBUG_ADD_TIMESTAMP + DEBUG_PORT.printf(timestamp); + #endif + DEBUG_PORT.printf(message); #endif #if DEBUG_UDP_SUPPORT @@ -40,7 +42,10 @@ void debugSend(const char * format, ...) { if (systemCheck()) { #endif _udp_debug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); - _udp_debug.write(buffer); + #if DEBUG_ADD_TIMESTAMP + _udp_debug.write(timestamp); + #endif + _udp_debug.write(message); _udp_debug.endPacket(); #if SYSTEM_CHECK_ENABLED } @@ -48,9 +53,27 @@ void debugSend(const char * format, ...) { #endif #if DEBUG_TELNET_SUPPORT - _telnetWrite(buffer, strlen(buffer)); + #if DEBUG_ADD_TIMESTAMP + _telnetWrite(timestamp, strlen(timestamp)); + #endif + _telnetWrite(message, strlen(message)); #endif + +} + +void debugSend(const char * format, ...) { + + va_list args; + va_start(args, format); + 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); + + _debugSend(buffer); + delete[] buffer; } @@ -68,25 +91,7 @@ void debugSend_P(PGM_P format_P, ...) { ets_vsnprintf(buffer, len, format, args); va_end(args); - #if DEBUG_SERIAL_SUPPORT - DEBUG_PORT.printf(buffer); - #endif - - #if DEBUG_UDP_SUPPORT - #if SYSTEM_CHECK_ENABLED - if (systemCheck()) { - #endif - _udp_debug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); - _udp_debug.write(buffer); - _udp_debug.endPacket(); - #if SYSTEM_CHECK_ENABLED - } - #endif - #endif - - #if DEBUG_TELNET_SUPPORT - _telnetWrite(buffer, strlen(buffer)); - #endif + _debugSend(buffer); delete[] buffer; diff --git a/code/espurna/ota.ino b/code/espurna/ota.ino index 61886ebe..ebeb398e 100644 --- a/code/espurna/ota.ino +++ b/code/espurna/ota.ino @@ -45,7 +45,7 @@ void otaSetup() { }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { - DEBUG_MSG_P(PSTR("[OTA] Progress: %u%%%%\r"), (progress / (total / 100))); + DEBUG_MSG_P(PSTR("[OTA] Progress: %u%%%% \r"), (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) {