-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug.cpp
61 lines (50 loc) · 1.28 KB
/
debug.cpp
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
// Copyright (c) 2021 - Schelte Bron
#include <ESP8266WiFi.h>
#include "otmon.h"
const int port = 45256;
WiFiServer debug(port);
WiFiClient debugClient;
void debuglog(const char *fmt, ...) {
char buffer[256];
int len;
va_list argptr;
if (debugClient) {
va_start(argptr, fmt);
len = vsnprintf_P(buffer, sizeof(buffer), fmt, argptr);
va_end(argptr);
if (debugClient.availableForWrite() >= len) {
debugClient.write(buffer, len);
}
}
}
void debugmsg(char dir, unsigned message) {
char buffer[256];
int len;
if (debugClient) {
len = otformat(buffer, dir, message);
len += sprintf(buffer + len, "\r\n");
if (debugClient.availableForWrite() >= len) {
debugClient.write(buffer, len);
}
}
}
void debugsetup() {
debug.begin();
debug.setNoDelay(true);
}
void debugevent() {
//check if there are any new clients
if (debug.hasClient()) {
if (debugClient) {
// Already connected
debug.available().println("busy");
} else {
// Accept the connection
debugClient = debug.available();
}
}
while (debugClient.available()) {
// Ignore any input
debugClient.read();
}
}