Browse Source

Add timestamp to debug output

pull/461/head
Xose Pérez 6 years ago
parent
commit
8488e7d552
3 changed files with 41 additions and 31 deletions
  1. +5
    -0
      code/espurna/config/general.h
  2. +35
    -30
      code/espurna/debug.ino
  3. +1
    -1
      code/espurna/ota.ino

+ 5
- 0
code/espurna/config/general.h View File

@ -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


+ 35
- 30
code/espurna/debug.ino View File

@ -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;


+ 1
- 1
code/espurna/ota.ino View File

@ -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) {


Loading…
Cancel
Save