Add MY_DEBUGDEVICE to redirect debug output (#1006)

* Add MY_DEBUGDEVICE to redirect debug output

MY_DEBUGDEVICE, if defined, will replace MY_SERIALDEVICE
for the purpose of printing debug messages. This only
applies to debugging.
This commit is contained in:
Lee Nelson
2017-12-03 19:34:58 +01:00
committed by Mikael Falkvidd
parent 8d9af98a55
commit bfcb125e72
8 changed files with 64 additions and 30 deletions
+8 -5
View File
@@ -313,17 +313,20 @@ uint16_t hwFreeMem()
void hwDebugPrint(const char *fmt, ... )
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(F(" "));
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(F(" "));
#endif
va_list args;
va_start (args, fmt );
@@ -334,8 +337,8 @@ void hwDebugPrint(const char *fmt, ... )
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end (args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_SERIALDEVICE.flush();
MY_DEBUGDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.flush();
#else
(void)fmt;
#endif
+8 -5
View File
@@ -149,17 +149,20 @@ uint16_t hwFreeMem()
void hwDebugPrint(const char *fmt, ... )
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(" ");
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(" ");
#endif
va_list args;
va_start (args, fmt );
@@ -170,8 +173,8 @@ void hwDebugPrint(const char *fmt, ... )
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end (args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_SERIALDEVICE.flush();
MY_DEBUGDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.flush();
#else
(void)fmt;
#endif
+8 -5
View File
@@ -507,17 +507,20 @@ uint16_t hwFreeMem()
void hwDebugPrint(const char *fmt, ...)
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(F(" "));
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(F(" "));
#endif
va_list args;
va_start (args, fmt );
@@ -528,8 +531,8 @@ void hwDebugPrint(const char *fmt, ...)
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end (args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_SERIALDEVICE.flush();
MY_DEBUGDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.flush();
#else
(void)fmt;
#endif
+8 -5
View File
@@ -181,18 +181,21 @@ uint16_t hwFreeMem()
void hwDebugPrint(const char *fmt, ... )
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
if (MY_SERIALDEVICE) {
if (MY_DEBUGDEVICE) {
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(" ");
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(" ");
#endif
va_list args;
va_start (args, fmt );
@@ -203,7 +206,7 @@ void hwDebugPrint(const char *fmt, ... )
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end (args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
// MY_SERIALDEVICE.flush();
}
#else
+8 -5
View File
@@ -170,17 +170,20 @@ uint16_t hwFreeMem()
void hwDebugPrint(const char *fmt, ...)
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(" ");
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(" ");
#endif
va_list args;
va_start(args, fmt);
@@ -191,10 +194,10 @@ void hwDebugPrint(const char *fmt, ...)
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end(args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
// Disable flush since current STM32duino implementation performs a reset
// instead of an actual flush
//MY_SERIALDEVICE.flush();
//MY_DEBUGDEVICE.flush();
#else
(void)fmt;
#endif
+7 -4
View File
@@ -167,17 +167,20 @@ void hwRandomNumberInit(void)
void hwDebugPrint(const char *fmt, ...)
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
// prepend timestamp
MY_SERIALDEVICE.print(hwMillis());
MY_SERIALDEVICE.print(F(" "));
MY_DEBUGDEVICE.print(hwMillis());
MY_DEBUGDEVICE.print(F(" "));
#endif
va_list args;
va_start(args, fmt);
@@ -188,7 +191,7 @@ void hwDebugPrint(const char *fmt, ...)
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
va_end(args);
MY_SERIALDEVICE.print(fmtBuffer);
MY_DEBUGDEVICE.print(fmtBuffer);
#else
(void)fmt;
#endif