-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDebugTools.h
52 lines (44 loc) · 1.28 KB
/
DebugTools.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
#ifndef DebugTools_h
#define DebugTools_h
byte debugOutputBuffer[INPUT_BUFFER_SIZE] = {0};
int debugOutputBufferPosition = 0;
byte debugInputBuffer[INPUT_BUFFER_SIZE] = {0};
int debugInputBufferPosition = 0;
void printHexBuffer(byte* buffer, int length) {
char tmp[2];
for (int i = 0; i < length; i++) {
sprintf(tmp, "%.2X", buffer[i]);
Serial.print(tmp);
}
}
void writeSerial1Debuggable(byte b) {
Serial1.write(b);
if (DEBUG) {
if (debugOutputBufferPosition < INPUT_BUFFER_SIZE) {
debugOutputBuffer[debugOutputBufferPosition++] = b;
}
}
}
void writeSerial1Debuggable(byte* buffer, int size) {
Serial1.write(buffer, size);
if (DEBUG) {
memcpy(&debugOutputBuffer[debugOutputBufferPosition], buffer, size);
debugOutputBufferPosition += size;
}
}
void writeSerial1Debuggable(const byte* buffer, int size) {
writeSerial1Debuggable((byte*)buffer, size);
}
void flushDebugOutputBuffer() {
if (DEBUG) {
Serial.print("Us->Body ");
if (debugInputBufferPosition != 0) {
printHexBuffer(debugOutputBuffer, debugOutputBufferPosition);
} else {
Serial.print("no message");
}
debugOutputBufferPosition = 0;
Serial.println();
}
}
#endif