forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.h
More file actions
126 lines (103 loc) · 3.64 KB
/
Copy pathDebug.h
File metadata and controls
126 lines (103 loc) · 3.64 KB
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
116
117
118
119
120
121
122
123
124
125
126
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#ifndef MO_DEBUG_H
#define MO_DEBUG_H
#include <MicroOcpp/Platform.h>
#define MO_DL_NONE 0x00 //suppress all output to the console
#define MO_DL_ERROR 0x01 //report failures
#define MO_DL_WARN 0x02 //report observed or assumed inconsistent state
#define MO_DL_INFO 0x03 //inform about internal state changes
#define MO_DL_DEBUG 0x04 //relevant info for debugging
#define MO_DL_VERBOSE 0x05 //all output
#ifndef MO_DBG_LEVEL
#define MO_DBG_LEVEL MO_DL_INFO //default
#endif
#define MO_DF_MINIMAL 0x00 //don't reveal origin of a debug message
#define MO_DF_COMPACT 0x01 //print module by file name and line number
#define MO_DF_FILE_LINE 0x02 //print file and line number
#define MO_DF_FULL 0x03 //print path and file and line numbr
#ifndef MO_DBG_FORMAT
#define MO_DBG_FORMAT MO_DF_FILE_LINE //default
#endif
#if MO_DBG_FORMAT == MO_DF_MINIMAL
#define MO_DBG(level, X) \
do { \
MO_CONSOLE_PRINTF X; \
MO_CONSOLE_PRINTF("\n"); \
} while (0);
#elif MO_DBG_FORMAT == MO_DF_COMPACT
#define MO_DBG(level, X) \
do { \
const char *_mo_file = __FILE__; \
size_t _mo_l = sizeof(__FILE__); \
size_t _mo_r = _mo_l; \
while (_mo_l > 0 && _mo_file[_mo_l-1] != '/' && _mo_file[_mo_l-1] != '\\') { \
_mo_l--; \
if (_mo_file[_mo_l] == '.') _mo_r = _mo_l; \
} \
MO_CONSOLE_PRINTF("%.*s:%i ", (int) (_mo_r - _mo_l), _mo_file + _mo_l,__LINE__); \
MO_CONSOLE_PRINTF X; \
MO_CONSOLE_PRINTF("\n"); \
} while (0);
#elif MO_DBG_FORMAT == MO_DF_FILE_LINE
#define MO_DBG(level, X) \
do { \
const char *_mo_file = __FILE__; \
size_t _mo_l = sizeof(__FILE__); \
for (; _mo_l > 0 && _mo_file[_mo_l-1] != '/' && _mo_file[_mo_l-1] != '\\'; _mo_l--); \
MO_CONSOLE_PRINTF("[MO] %s (%s:%i): ",level, _mo_file + _mo_l,__LINE__); \
MO_CONSOLE_PRINTF X; \
MO_CONSOLE_PRINTF("\n"); \
} while (0);
#elif MO_DBG_FORMAT == MO_DF_FULL
#define MO_DBG(level, X) \
do { \
MO_CONSOLE_PRINTF("[MO] %s (%s:%i): ",level, __FILE__,__LINE__); \
MO_CONSOLE_PRINTF X; \
MO_CONSOLE_PRINTF("\n"); \
} while (0);
#else
#error invalid MO_DBG_FORMAT definition
#endif
#if MO_DBG_LEVEL >= MO_DL_ERROR
#define MO_DBG_ERR(...) MO_DBG("ERROR",(__VA_ARGS__))
#else
#define MO_DBG_ERR(...)
#endif
#if MO_DBG_LEVEL >= MO_DL_WARN
#define MO_DBG_WARN(...) MO_DBG("warning",(__VA_ARGS__))
#else
#define MO_DBG_WARN(...)
#endif
#if MO_DBG_LEVEL >= MO_DL_INFO
#define MO_DBG_INFO(...) MO_DBG("info",(__VA_ARGS__))
#else
#define MO_DBG_INFO(...)
#endif
#if MO_DBG_LEVEL >= MO_DL_DEBUG
#define MO_DBG_DEBUG(...) MO_DBG("debug",(__VA_ARGS__))
#else
#define MO_DBG_DEBUG(...)
#endif
#if MO_DBG_LEVEL >= MO_DL_VERBOSE
#define MO_DBG_VERBOSE(...) MO_DBG("verbose",(__VA_ARGS__))
#else
#define MO_DBG_VERBOSE(...)
#endif
#ifdef MO_TRAFFIC_OUT
#define MO_DBG_TRAFFIC_OUT(...) \
do { \
MO_CONSOLE_PRINTF("[MO] Send: %s",__VA_ARGS__); \
MO_CONSOLE_PRINTF("\n"); \
} while (0)
#define MO_DBG_TRAFFIC_IN(...) \
do { \
MO_CONSOLE_PRINTF("[MO] Recv: %.*s",__VA_ARGS__); \
MO_CONSOLE_PRINTF("\n"); \
} while (0)
#else
#define MO_DBG_TRAFFIC_OUT(...)
#define MO_DBG_TRAFFIC_IN(...)
#endif
#endif