-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.cpp
More file actions
143 lines (114 loc) · 3.76 KB
/
Copy pathlogger.cpp
File metadata and controls
143 lines (114 loc) · 3.76 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "logger.h"
SerialLogger::SerialLogger(const char *control_sequence)
:_control_sequence(control_sequence), _control_sequence_len(strlen(control_sequence))
{
}
bool SerialLogger::begin(void *args) {
return Serial;
}
void SerialLogger::log_raw(uint8_t *data, size_t length) {
Serial.write(data, length);
Serial.write(_control_sequence, _control_sequence_len);
}
void SerialLogger::sync(size_t packet_size) {
for (int i = 0; i < packet_size; ++i) {
Serial.print(0);
}
Serial.write(_control_sequence, _control_sequence_len);
}
void SerialLogger::log_pretty(TraceEntry_t &data) {
TraceEntry_t *entry = (TraceEntry_t *)&data;
Serial.printf("[%" PRIu32 "] Core:%ld ID:%" PRIu32 "FN: %ld" " | ",
entry->timestamp,
(long)entry->core_id,
entry->trace_id,
entry->function_call_id
);
switch (entry->trace_type) {
case ENTER: {
const TraceFunctionEntry_t& fn = entry->function_entry;
Serial.printf("ENTER: %s(", fn.func_name);
// Loop through arguments
for (int i = 0; i < fn.arg_count; i++) {
// Note: We are printing raw hex because we don't know
// how to decode 'val_types' yet.
Serial.printf("0x%08" PRIx32, fn.func_arguments[i]);
if (i < fn.arg_count - 1) {
Serial.printf(", ");
}
}
Serial.printf(")\n");
break;
}
case EXIT: {
const TraceFunctionEntry_t& fn = entry->function_entry;
Serial.printf("EXIT : %s | Return: 0x%08" PRIx32,
fn.func_name,
fn.return_val);
#ifdef TRACER_TRACE_STACK
Serial.printf(" | Stack Left: %ld bytes", (long)fn.stack_space_left);
#endif
Serial.printf("\n");
break;
}
case PANIC: {
const TracePanicEntry_t& panic = entry->panic_entry;
Serial.printf("PANIC: PC:0x%08" PRIx32 " Reason: %s\n",
panic.faulting_pc,
panic.exception_reason);
break;
}
default:
Serial.printf("UNKNOWN EVENT TYPE\n");
break;
}
}
void SerialLogger::flush() { Serial.flush(); }
UDPLogger::UDPLogger(const String& ssid, const String& password, uint16_t port, const char* server_addr)
:_ssid(ssid), _password(password), _port(port), _server_addr(IPAddress(server_addr))
{}
bool UDPLogger::begin(void* args) {
WiFi.begin(_ssid, _password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");
}
Serial.println("wifi connected");
if (_udp.begin(_port)) {
Serial.print("UDP client initialized on port ");
Serial.println(_port);
} else {
return false;
}
return true;
}
void UDPLogger::sync(size_t packet_size) {
return;
}
void UDPLogger::log_raw(uint8_t *data, size_t length) {
_check_conn_and_reconnect();
_udp.beginPacket(_server_addr, _port);
_udp.write(data, length);
_udp.endPacket();
}
void UDPLogger::log_pretty(TraceEntry_t &data) {
// there is no way to print pretty over the network, so just send the same stuff
log_raw(reinterpret_cast<uint8_t *>(&data), sizeof(data));
}
void UDPLogger::flush() { return; }
void UDPLogger::_check_conn_and_reconnect() {
bool had_to_reconnect = false;
while (WiFi.status() != WL_CONNECTED) {
had_to_reconnect = true;
WiFi.disconnect();
delay(100);
WiFi.reconnect();
delay(100);
}
if (had_to_reconnect) {
while (!_udp.begin(_port)) {
delay(100);
Serial.println(",");
}
}
}