Skip to content

Commit bfcb125

Browse files
nelsonovmfalkvidd
authored andcommitted
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.
1 parent 8d9af98 commit bfcb125

File tree

8 files changed

+64
-30
lines changed

8 files changed

+64
-30
lines changed

MyConfig.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,21 @@
4646
* the flag in your sketch.
4747
*/
4848
//#define MY_DEBUG
49-
49+
/**
50+
* @def MY_DEBUGDEVICE
51+
* @brief Define MY_DEBUGDEVICE to redirect debug prints.
52+
*
53+
* If defined, MY_DEBUGDEVICE replaces MY_SERIALDEVICE for the purpose
54+
* of printing debug messages. This only applies to debugging.
55+
*
56+
* The intent is to provide the ability to send debugging messages
57+
* out a different serial port than what is being used for
58+
* communication between nodes or from gateway to controller when
59+
* this communication uses a serial interface. This assumes that
60+
* the MY_DEBUGDEVICE serial interface already exists. It can be a
61+
* hardware serial device or a software serial device.
62+
*/
63+
//#define MY_DEBUGDEVICE
5064
/**
5165
* @def MY_DEBUG_OTA
5266
* @brief Define MY_DEBUG_OTA to redirect debug prints to given node ID
@@ -1861,6 +1875,7 @@
18611875

18621876
// debug
18631877
#define MY_DEBUG
1878+
#define MY_DEBUGDEVICE
18641879
#define MY_DEBUG_OTA
18651880
#define MY_DEBUG_OTA_DISABLE_ACK
18661881
#define MY_SPECIAL_DEBUG

hal/architecture/AVR/MyHwAVR.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,20 @@ uint16_t hwFreeMem()
313313

314314
void hwDebugPrint(const char *fmt, ... )
315315
{
316+
#ifndef MY_DEBUGDEVICE
317+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
318+
#endif
316319
#ifndef MY_DISABLED_SERIAL
317320
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
318321
#ifdef MY_GATEWAY_SERIAL
319322
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
320323
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
321324
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
322-
MY_SERIALDEVICE.print(fmtBuffer);
325+
MY_DEBUGDEVICE.print(fmtBuffer);
323326
#else
324327
// prepend timestamp
325-
MY_SERIALDEVICE.print(hwMillis());
326-
MY_SERIALDEVICE.print(F(" "));
328+
MY_DEBUGDEVICE.print(hwMillis());
329+
MY_DEBUGDEVICE.print(F(" "));
327330
#endif
328331
va_list args;
329332
va_start (args, fmt );
@@ -334,8 +337,8 @@ void hwDebugPrint(const char *fmt, ... )
334337
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
335338
#endif
336339
va_end (args);
337-
MY_SERIALDEVICE.print(fmtBuffer);
338-
MY_SERIALDEVICE.flush();
340+
MY_DEBUGDEVICE.print(fmtBuffer);
341+
MY_DEBUGDEVICE.flush();
339342
#else
340343
(void)fmt;
341344
#endif

hal/architecture/ESP8266/MyHwESP8266.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,20 @@ uint16_t hwFreeMem()
149149

150150
void hwDebugPrint(const char *fmt, ... )
151151
{
152+
#ifndef MY_DEBUGDEVICE
153+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
154+
#endif
152155
#ifndef MY_DISABLED_SERIAL
153156
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
154157
#ifdef MY_GATEWAY_SERIAL
155158
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
156159
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
157160
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
158-
MY_SERIALDEVICE.print(fmtBuffer);
161+
MY_DEBUGDEVICE.print(fmtBuffer);
159162
#else
160163
// prepend timestamp
161-
MY_SERIALDEVICE.print(hwMillis());
162-
MY_SERIALDEVICE.print(" ");
164+
MY_DEBUGDEVICE.print(hwMillis());
165+
MY_DEBUGDEVICE.print(" ");
163166
#endif
164167
va_list args;
165168
va_start (args, fmt );
@@ -170,8 +173,8 @@ void hwDebugPrint(const char *fmt, ... )
170173
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
171174
#endif
172175
va_end (args);
173-
MY_SERIALDEVICE.print(fmtBuffer);
174-
MY_SERIALDEVICE.flush();
176+
MY_DEBUGDEVICE.print(fmtBuffer);
177+
MY_DEBUGDEVICE.flush();
175178
#else
176179
(void)fmt;
177180
#endif

hal/architecture/NRF5/MyHwNRF5.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,20 @@ uint16_t hwFreeMem()
507507

508508
void hwDebugPrint(const char *fmt, ...)
509509
{
510+
#ifndef MY_DEBUGDEVICE
511+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
512+
#endif
510513
#ifndef MY_DISABLED_SERIAL
511514
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
512515
#ifdef MY_GATEWAY_SERIAL
513516
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
514517
snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
515518
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
516-
MY_SERIALDEVICE.print(fmtBuffer);
519+
MY_DEBUGDEVICE.print(fmtBuffer);
517520
#else
518521
// prepend timestamp
519-
MY_SERIALDEVICE.print(hwMillis());
520-
MY_SERIALDEVICE.print(F(" "));
522+
MY_DEBUGDEVICE.print(hwMillis());
523+
MY_DEBUGDEVICE.print(F(" "));
521524
#endif
522525
va_list args;
523526
va_start (args, fmt );
@@ -528,8 +531,8 @@ void hwDebugPrint(const char *fmt, ...)
528531
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
529532
#endif
530533
va_end (args);
531-
MY_SERIALDEVICE.print(fmtBuffer);
532-
MY_SERIALDEVICE.flush();
534+
MY_DEBUGDEVICE.print(fmtBuffer);
535+
MY_DEBUGDEVICE.flush();
533536
#else
534537
(void)fmt;
535538
#endif

hal/architecture/SAMD/MyHwSAMD.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,21 @@ uint16_t hwFreeMem()
181181

182182
void hwDebugPrint(const char *fmt, ... )
183183
{
184+
#ifndef MY_DEBUGDEVICE
185+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
186+
#endif
184187
#ifndef MY_DISABLED_SERIAL
185-
if (MY_SERIALDEVICE) {
188+
if (MY_DEBUGDEVICE) {
186189
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
187190
#ifdef MY_GATEWAY_SERIAL
188191
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
189192
snprintf(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
190193
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
191-
MY_SERIALDEVICE.print(fmtBuffer);
194+
MY_DEBUGDEVICE.print(fmtBuffer);
192195
#else
193196
// prepend timestamp
194-
MY_SERIALDEVICE.print(hwMillis());
195-
MY_SERIALDEVICE.print(" ");
197+
MY_DEBUGDEVICE.print(hwMillis());
198+
MY_DEBUGDEVICE.print(" ");
196199
#endif
197200
va_list args;
198201
va_start (args, fmt );
@@ -203,7 +206,7 @@ void hwDebugPrint(const char *fmt, ... )
203206
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
204207
#endif
205208
va_end (args);
206-
MY_SERIALDEVICE.print(fmtBuffer);
209+
MY_DEBUGDEVICE.print(fmtBuffer);
207210
// MY_SERIALDEVICE.flush();
208211
}
209212
#else

hal/architecture/STM32F1/MyHwSTM32F1.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,20 @@ uint16_t hwFreeMem()
170170

171171
void hwDebugPrint(const char *fmt, ...)
172172
{
173+
#ifndef MY_DEBUGDEVICE
174+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
175+
#endif
173176
#ifndef MY_DISABLED_SERIAL
174177
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
175178
#ifdef MY_GATEWAY_SERIAL
176179
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
177180
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
178181
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
179-
MY_SERIALDEVICE.print(fmtBuffer);
182+
MY_DEBUGDEVICE.print(fmtBuffer);
180183
#else
181184
// prepend timestamp
182-
MY_SERIALDEVICE.print(hwMillis());
183-
MY_SERIALDEVICE.print(" ");
185+
MY_DEBUGDEVICE.print(hwMillis());
186+
MY_DEBUGDEVICE.print(" ");
184187
#endif
185188
va_list args;
186189
va_start(args, fmt);
@@ -191,10 +194,10 @@ void hwDebugPrint(const char *fmt, ...)
191194
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
192195
#endif
193196
va_end(args);
194-
MY_SERIALDEVICE.print(fmtBuffer);
197+
MY_DEBUGDEVICE.print(fmtBuffer);
195198
// Disable flush since current STM32duino implementation performs a reset
196199
// instead of an actual flush
197-
//MY_SERIALDEVICE.flush();
200+
//MY_DEBUGDEVICE.flush();
198201
#else
199202
(void)fmt;
200203
#endif

hal/architecture/Teensy3/MyHwTeensy3.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,20 @@ void hwRandomNumberInit(void)
167167

168168
void hwDebugPrint(const char *fmt, ...)
169169
{
170+
#ifndef MY_DEBUGDEVICE
171+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
172+
#endif
170173
#ifndef MY_DISABLED_SERIAL
171174
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
172175
#ifdef MY_GATEWAY_SERIAL
173176
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
174177
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
175178
C_INTERNAL, I_LOG_MESSAGE, hwMillis());
176-
MY_SERIALDEVICE.print(fmtBuffer);
179+
MY_DEBUGDEVICE.print(fmtBuffer);
177180
#else
178181
// prepend timestamp
179-
MY_SERIALDEVICE.print(hwMillis());
180-
MY_SERIALDEVICE.print(F(" "));
182+
MY_DEBUGDEVICE.print(hwMillis());
183+
MY_DEBUGDEVICE.print(F(" "));
181184
#endif
182185
va_list args;
183186
va_start(args, fmt);
@@ -188,7 +191,7 @@ void hwDebugPrint(const char *fmt, ...)
188191
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
189192
#endif
190193
va_end(args);
191-
MY_SERIALDEVICE.print(fmtBuffer);
194+
MY_DEBUGDEVICE.print(fmtBuffer);
192195
#else
193196
(void)fmt;
194197
#endif

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ MY_PASSIVE_NODE LITERAL1
5656

5757
# debug
5858
MY_DEBUG LITERAL1
59+
MY_DEBUGDEVICE LITERAL1
5960
MY_DEBUG_OTA LITERAL1
6061
MY_DEBUG_OTA_DISABLE_ACK LITERAL1
6162
MY_SPECIAL_DEBUG LITERAL1

0 commit comments

Comments
 (0)