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:
committed by
Mikael Falkvidd
parent
8d9af98a55
commit
bfcb125e72
+16
-1
@@ -46,7 +46,21 @@
|
|||||||
* the flag in your sketch.
|
* the flag in your sketch.
|
||||||
*/
|
*/
|
||||||
//#define MY_DEBUG
|
//#define MY_DEBUG
|
||||||
|
/**
|
||||||
|
* @def MY_DEBUGDEVICE
|
||||||
|
* @brief Define MY_DEBUGDEVICE to redirect debug prints.
|
||||||
|
*
|
||||||
|
* If defined, MY_DEBUGDEVICE replaces MY_SERIALDEVICE for the purpose
|
||||||
|
* of printing debug messages. This only applies to debugging.
|
||||||
|
*
|
||||||
|
* The intent is to provide the ability to send debugging messages
|
||||||
|
* out a different serial port than what is being used for
|
||||||
|
* communication between nodes or from gateway to controller when
|
||||||
|
* this communication uses a serial interface. This assumes that
|
||||||
|
* the MY_DEBUGDEVICE serial interface already exists. It can be a
|
||||||
|
* hardware serial device or a software serial device.
|
||||||
|
*/
|
||||||
|
//#define MY_DEBUGDEVICE
|
||||||
/**
|
/**
|
||||||
* @def MY_DEBUG_OTA
|
* @def MY_DEBUG_OTA
|
||||||
* @brief Define MY_DEBUG_OTA to redirect debug prints to given node ID
|
* @brief Define MY_DEBUG_OTA to redirect debug prints to given node ID
|
||||||
@@ -1861,6 +1875,7 @@
|
|||||||
|
|
||||||
// debug
|
// debug
|
||||||
#define MY_DEBUG
|
#define MY_DEBUG
|
||||||
|
#define MY_DEBUGDEVICE
|
||||||
#define MY_DEBUG_OTA
|
#define MY_DEBUG_OTA
|
||||||
#define MY_DEBUG_OTA_DISABLE_ACK
|
#define MY_DEBUG_OTA_DISABLE_ACK
|
||||||
#define MY_SPECIAL_DEBUG
|
#define MY_SPECIAL_DEBUG
|
||||||
|
|||||||
@@ -313,17 +313,20 @@ uint16_t hwFreeMem()
|
|||||||
|
|
||||||
void hwDebugPrint(const char *fmt, ... )
|
void hwDebugPrint(const char *fmt, ... )
|
||||||
{
|
{
|
||||||
|
#ifndef MY_DEBUGDEVICE
|
||||||
|
#define MY_DEBUGDEVICE MY_SERIALDEVICE
|
||||||
|
#endif
|
||||||
#ifndef MY_DISABLED_SERIAL
|
#ifndef MY_DISABLED_SERIAL
|
||||||
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
||||||
#ifdef MY_GATEWAY_SERIAL
|
#ifdef MY_GATEWAY_SERIAL
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// 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 " "),
|
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
|
||||||
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
// prepend timestamp
|
// prepend timestamp
|
||||||
MY_SERIALDEVICE.print(hwMillis());
|
MY_DEBUGDEVICE.print(hwMillis());
|
||||||
MY_SERIALDEVICE.print(F(" "));
|
MY_DEBUGDEVICE.print(F(" "));
|
||||||
#endif
|
#endif
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt );
|
va_start (args, fmt );
|
||||||
@@ -334,8 +337,8 @@ void hwDebugPrint(const char *fmt, ... )
|
|||||||
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
va_end (args);
|
va_end (args);
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
MY_SERIALDEVICE.flush();
|
MY_DEBUGDEVICE.flush();
|
||||||
#else
|
#else
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -149,17 +149,20 @@ uint16_t hwFreeMem()
|
|||||||
|
|
||||||
void hwDebugPrint(const char *fmt, ... )
|
void hwDebugPrint(const char *fmt, ... )
|
||||||
{
|
{
|
||||||
|
#ifndef MY_DEBUGDEVICE
|
||||||
|
#define MY_DEBUGDEVICE MY_SERIALDEVICE
|
||||||
|
#endif
|
||||||
#ifndef MY_DISABLED_SERIAL
|
#ifndef MY_DISABLED_SERIAL
|
||||||
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
||||||
#ifdef MY_GATEWAY_SERIAL
|
#ifdef MY_GATEWAY_SERIAL
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// 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 " "),
|
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
|
||||||
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
// prepend timestamp
|
// prepend timestamp
|
||||||
MY_SERIALDEVICE.print(hwMillis());
|
MY_DEBUGDEVICE.print(hwMillis());
|
||||||
MY_SERIALDEVICE.print(" ");
|
MY_DEBUGDEVICE.print(" ");
|
||||||
#endif
|
#endif
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt );
|
va_start (args, fmt );
|
||||||
@@ -170,8 +173,8 @@ void hwDebugPrint(const char *fmt, ... )
|
|||||||
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
va_end (args);
|
va_end (args);
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
MY_SERIALDEVICE.flush();
|
MY_DEBUGDEVICE.flush();
|
||||||
#else
|
#else
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -507,17 +507,20 @@ uint16_t hwFreeMem()
|
|||||||
|
|
||||||
void hwDebugPrint(const char *fmt, ...)
|
void hwDebugPrint(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
#ifndef MY_DEBUGDEVICE
|
||||||
|
#define MY_DEBUGDEVICE MY_SERIALDEVICE
|
||||||
|
#endif
|
||||||
#ifndef MY_DISABLED_SERIAL
|
#ifndef MY_DISABLED_SERIAL
|
||||||
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
||||||
#ifdef MY_GATEWAY_SERIAL
|
#ifdef MY_GATEWAY_SERIAL
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// 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 " "),
|
snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
|
||||||
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
// prepend timestamp
|
// prepend timestamp
|
||||||
MY_SERIALDEVICE.print(hwMillis());
|
MY_DEBUGDEVICE.print(hwMillis());
|
||||||
MY_SERIALDEVICE.print(F(" "));
|
MY_DEBUGDEVICE.print(F(" "));
|
||||||
#endif
|
#endif
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt );
|
va_start (args, fmt );
|
||||||
@@ -528,8 +531,8 @@ void hwDebugPrint(const char *fmt, ...)
|
|||||||
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
va_end (args);
|
va_end (args);
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
MY_SERIALDEVICE.flush();
|
MY_DEBUGDEVICE.flush();
|
||||||
#else
|
#else
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -181,18 +181,21 @@ uint16_t hwFreeMem()
|
|||||||
|
|
||||||
void hwDebugPrint(const char *fmt, ... )
|
void hwDebugPrint(const char *fmt, ... )
|
||||||
{
|
{
|
||||||
|
#ifndef MY_DEBUGDEVICE
|
||||||
|
#define MY_DEBUGDEVICE MY_SERIALDEVICE
|
||||||
|
#endif
|
||||||
#ifndef MY_DISABLED_SERIAL
|
#ifndef MY_DISABLED_SERIAL
|
||||||
if (MY_SERIALDEVICE) {
|
if (MY_DEBUGDEVICE) {
|
||||||
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
||||||
#ifdef MY_GATEWAY_SERIAL
|
#ifdef MY_GATEWAY_SERIAL
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// 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 " "),
|
snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
|
||||||
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
// prepend timestamp
|
// prepend timestamp
|
||||||
MY_SERIALDEVICE.print(hwMillis());
|
MY_DEBUGDEVICE.print(hwMillis());
|
||||||
MY_SERIALDEVICE.print(" ");
|
MY_DEBUGDEVICE.print(" ");
|
||||||
#endif
|
#endif
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt );
|
va_start (args, fmt );
|
||||||
@@ -203,7 +206,7 @@ void hwDebugPrint(const char *fmt, ... )
|
|||||||
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
va_end (args);
|
va_end (args);
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
// MY_SERIALDEVICE.flush();
|
// MY_SERIALDEVICE.flush();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -170,17 +170,20 @@ uint16_t hwFreeMem()
|
|||||||
|
|
||||||
void hwDebugPrint(const char *fmt, ...)
|
void hwDebugPrint(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
#ifndef MY_DEBUGDEVICE
|
||||||
|
#define MY_DEBUGDEVICE MY_SERIALDEVICE
|
||||||
|
#endif
|
||||||
#ifndef MY_DISABLED_SERIAL
|
#ifndef MY_DISABLED_SERIAL
|
||||||
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
||||||
#ifdef MY_GATEWAY_SERIAL
|
#ifdef MY_GATEWAY_SERIAL
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// 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 " "),
|
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
|
||||||
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
// prepend timestamp
|
// prepend timestamp
|
||||||
MY_SERIALDEVICE.print(hwMillis());
|
MY_DEBUGDEVICE.print(hwMillis());
|
||||||
MY_SERIALDEVICE.print(" ");
|
MY_DEBUGDEVICE.print(" ");
|
||||||
#endif
|
#endif
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -191,10 +194,10 @@ void hwDebugPrint(const char *fmt, ...)
|
|||||||
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
va_end(args);
|
va_end(args);
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
// Disable flush since current STM32duino implementation performs a reset
|
// Disable flush since current STM32duino implementation performs a reset
|
||||||
// instead of an actual flush
|
// instead of an actual flush
|
||||||
//MY_SERIALDEVICE.flush();
|
//MY_DEBUGDEVICE.flush();
|
||||||
#else
|
#else
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -167,17 +167,20 @@ void hwRandomNumberInit(void)
|
|||||||
|
|
||||||
void hwDebugPrint(const char *fmt, ...)
|
void hwDebugPrint(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
#ifndef MY_DEBUGDEVICE
|
||||||
|
#define MY_DEBUGDEVICE MY_SERIALDEVICE
|
||||||
|
#endif
|
||||||
#ifndef MY_DISABLED_SERIAL
|
#ifndef MY_DISABLED_SERIAL
|
||||||
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
|
||||||
#ifdef MY_GATEWAY_SERIAL
|
#ifdef MY_GATEWAY_SERIAL
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// 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 " "),
|
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
|
||||||
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
// prepend timestamp
|
// prepend timestamp
|
||||||
MY_SERIALDEVICE.print(hwMillis());
|
MY_DEBUGDEVICE.print(hwMillis());
|
||||||
MY_SERIALDEVICE.print(F(" "));
|
MY_DEBUGDEVICE.print(F(" "));
|
||||||
#endif
|
#endif
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -188,7 +191,7 @@ void hwDebugPrint(const char *fmt, ...)
|
|||||||
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
va_end(args);
|
va_end(args);
|
||||||
MY_SERIALDEVICE.print(fmtBuffer);
|
MY_DEBUGDEVICE.print(fmtBuffer);
|
||||||
#else
|
#else
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ MY_PASSIVE_NODE LITERAL1
|
|||||||
|
|
||||||
# debug
|
# debug
|
||||||
MY_DEBUG LITERAL1
|
MY_DEBUG LITERAL1
|
||||||
|
MY_DEBUGDEVICE LITERAL1
|
||||||
MY_DEBUG_OTA LITERAL1
|
MY_DEBUG_OTA LITERAL1
|
||||||
MY_DEBUG_OTA_DISABLE_ACK LITERAL1
|
MY_DEBUG_OTA_DISABLE_ACK LITERAL1
|
||||||
MY_SPECIAL_DEBUG LITERAL1
|
MY_SPECIAL_DEBUG LITERAL1
|
||||||
|
|||||||
Reference in New Issue
Block a user