-
Notifications
You must be signed in to change notification settings - Fork 16
/
Debug.h
77 lines (65 loc) · 3.05 KB
/
Debug.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
#ifndef _DEBUG_H
#define _DEBUG_H
/*
***************************************************************************
** Program : Debug.h, part of DSMRloggerAPI
**
** Copyright (c) 2023 Martijn Hendriks / based on DSMR Api Willem Aandewiel
** Met dank aan Erik
**
** TERMS OF USE: MIT License. See bottom of file.
***************************************************************************
*/
/*---- start macro's ------------------------------------------------------------------*/
#ifdef DEBUG
//DEBUG MODE
#define DebugBegin(...)({ USBSerial.begin(__VA_ARGS__);while (!USBSerial); })
#define Debug(...) ({ USBSerial.print(__VA_ARGS__);\
TelnetStream.print(__VA_ARGS__);\
})
#define Debugln(...) ({ USBSerial.println(__VA_ARGS__); \
TelnetStream.println(__VA_ARGS__); \
})
#define Debugf(...) ({ USBSerial.printf(__VA_ARGS__); \
TelnetStream.printf(__VA_ARGS__); \
})
#define DebugFlush() ({ USBSerial.flush(); \
TelnetStream.flush(); \
})
#define USBPrint(...) ({ Debug(__VA_ARGS__);})
#define USBPrintf(...) ({ Debugf(__VA_ARGS__);})
#define USBPrintln(...) ({ Debugln(__VA_ARGS__);})
#else
//NORMAL MODE
#define DebugBegin(...)({ USBSerial.begin(__VA_ARGS__); })
#define Debug(...) ({ TelnetStream.print(__VA_ARGS__); })
#define Debugln(...) ({ TelnetStream.println(__VA_ARGS__); })
#define Debugf(...) ({ TelnetStream.printf(__VA_ARGS__); })
#define DebugFlush() ({ TelnetStream.flush(); })
#define USBPrint(...) ({ if (USBSerial.isConnected() && USBSerial.isPlugged() ) USBSerial.print(__VA_ARGS__);})
#define USBPrintf(...) ({ if (USBSerial.isConnected() && USBSerial.isPlugged() ) USBSerial.printf(__VA_ARGS__);})
#define USBPrintln(...) ({ if (USBSerial.isConnected() && USBSerial.isPlugged() ) USBSerial.println(__VA_ARGS__);})
#endif
#define DebugT(...) ({ _debugBOL(__FUNCTION__, __LINE__); \
Debug(__VA_ARGS__); \
})
#define DebugTln(...) ({ _debugBOL(__FUNCTION__, __LINE__); \
Debugln(__VA_ARGS__); \
})
#define DebugTf(...) ({ _debugBOL(__FUNCTION__, __LINE__); \
Debugf(__VA_ARGS__); \
})
/*---- einde macro's ------------------------------------------------------------------*/
char _bol[128];
void _debugBOL(const char *fn, int line)
{
snprintf(_bol, sizeof(_bol), "%1d [%02d:%02d:%02d][%7u|%6u] %-12.12s(%4d): ", \
xPortGetCoreID(), hour(), minute(), second(), \
ESP.getFreeHeap(), ESP.getMaxAllocHeap(),\
fn, line);
#ifdef DEBUG
USBSerial.print (_bol);
#endif
TelnetStream.print (_bol);
}
#endif