-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebugUtils.h
115 lines (99 loc) · 2.7 KB
/
DebugUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef DEBUGUTILS_H
#define DEBUGUTILS_H
#include <Arduino.h>
#include <ArduinoSTL.h>
#define TRACE(type, str) \
Serial.print(millis()); \
Serial.print(F(" : ")); \
Serial.print(F(type)); \
Serial.print(F(" : ")); \
Serial.print(F(str)); \
Serial.print(F(" : ")); \
Serial.print(__PRETTY_FUNCTION__); \
Serial.print(F("\n")); \
Serial.flush();
#define TRACE_PARAM(type, str, param) \
Serial.print(millis()); \
Serial.print(F(" : ")); \
Serial.print(F(type)); \
Serial.print(F(" : ")); \
Serial.print(F(str)); \
Serial.print(F(" : ")); \
Serial.print(param); \
Serial.print(F(" : ")); \
Serial.print(__PRETTY_FUNCTION__); \
Serial.print(F("\n")); \
Serial.flush();
#ifdef TRACE_LEVEL_OFF
#ifdef TRACE_LEVEL_ALL
#undef TRACE_LEVEL_ALL
#endif
#ifdef TRACE_LEVEL_DEBUG
#undef TRACE_LEVEL_DEBUG
#endif
#ifdef TRACE_LEVEL_INFO
#undef TRACE_LEVEL_INFO
#endif
#ifdef TRACE_LEVEL_WARN
#undef TRACE_LEVEL_WARN
#endif
#ifdef TRACE_LEVEL_ERROR
#undef TRACE_LEVEL_ERROR
#endif
#ifdef TRACE_LEVEL_FATAL
#undef TRACE_LEVEL_FATAL
#endif
#endif
#ifdef TRACE_LEVEL_ALL
#ifndef TRACE_LEVEL_DEBUG
#define TRACE_LEVEL_DEBUG
#endif
#endif
#ifdef TRACE_LEVEL_DEBUG
#ifndef TRACE_LEVEL_INFO
#define TRACE_LEVEL_INFO
#endif
#define DEBUG_PRINT(str) TRACE("DEBUG", str)
#define DEBUG_PRINT_PARAM(str, param) TRACE_PARAM("DEBUG", str, param)
#else
#define DEBUG_PRINT(str)
#define DEBUG_PRINT_PARAM(str, param)
#endif
#ifdef TRACE_LEVEL_INFO
#ifndef TRACE_LEVEL_WARN
#define TRACE_LEVEL_WARN
#endif
#define INFO_PRINT(str) TRACE("INFO ", str)
#define INFO_PRINT_PARAM(str, param) TRACE_PARAM("INFO ", str, param)
#else
#define INFO_PRINT(str)
#define INFO_PRINT_PARAM(str, param)
#endif
#ifdef TRACE_LEVEL_WARN
#ifndef TRACE_LEVEL_ERROR
#define TRACE_LEVEL_ERROR
#endif
#define WARN_PRINT(str) TRACE("WARN", str)
#define WARN_PRINT_PARAM(str, param) TRACE_PARAM("WARN", str, param)
#else
#define WARN_PRINT(str)
#define WARN_PRINT_PARAM(str, param)
#endif
#ifdef TRACE_LEVEL_ERROR
#ifndef TRACE_LEVEL_FATAL
#define TRACE_LEVEL_FATAL
#endif
#define ERROR_PRINT(str) TRACE("ERROR", str)
#define ERROR_PRINT_PARAM(str, param) TRACE_PARAM("ERROR", str, param)
#else
#define ERROR_PRINT(str)
#define ERROR_PRINT_PARAM(str, param)
#endif
#ifdef TRACE_LEVEL_FATAL
#define FATAL_PRINT(str) TRACE("FATAL", str)
#define FATAL_PRINT_PARAM(str, param) TRACE_PARAM("FATAL", str, param)
#else
#define FATAL_PRINT(str)
#define FATAL_PRINT_PARAM(str, param)
#endif
#endif