-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.cpp
95 lines (73 loc) · 2.52 KB
/
parser.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
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
// main.c
// Proof of concept for using PPRZLink's generated C messages interface
// to read autopilot data.
#ifdef __cplusplus
extern "C" {
#endif
#include "parser.h"
uint8_t parsed_message_buffer[MESSAGE_BUFFER_LENGTH];
bool msg_available;
struct pprz_transport *reader = (pprz_transport*) malloc(sizeof(struct pprz_transport));
struct link_device serial_port_dev;
int initParser() {
serial_port_dev.char_available = (char_available_t) &uartBytesAvailable;
serial_port_dev.get_byte = (get_byte_t) &uartGetByte;
if (uartOpen()) {
return 1;
}
uartInit();
pprz_transport_init(reader);
return 0;
}
void runner(){
pprz_check_and_parse(&serial_port_dev, reader, parsed_message_buffer, &msg_available);
if (msg_available) {
dl_parse_msg();
msg_available = false;
}
}
void closeParser(){
free(reader);
}
#ifdef __cplusplus
}
#endif
#include "autopilot_cpp.h"
#include <chrono>
void dl_parse_msg() {
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
long int ms = std::chrono::duration_cast<std::chrono::milliseconds>(now_ms.time_since_epoch()).count();
WaldoMessage wm(ms);
GpsMessage gm(ms);
int msg_id = parsed_message_buffer[1];
switch (msg_id) {
case DL_WALDO_MSG:
wm.roll = DL_WALDO_MSG_roll(parsed_message_buffer);
wm.yaw = DL_WALDO_MSG_yaw(parsed_message_buffer);
wm.pitch = DL_WALDO_MSG_pitch(parsed_message_buffer);
wm.fix = DL_WALDO_MSG_fix(parsed_message_buffer);
wm.utm_east = DL_WALDO_MSG_utm_east(parsed_message_buffer);
wm.utm_north = DL_WALDO_MSG_utm_north(parsed_message_buffer);
wm.utm_zone = DL_WALDO_MSG_utm_zone(parsed_message_buffer);
wm.speed = DL_WALDO_MSG_speed(parsed_message_buffer);
wm.week = DL_WALDO_MSG_week(parsed_message_buffer);
wm.itow = DL_WALDO_MSG_itow(parsed_message_buffer);
wm.est_height= DL_WALDO_MSG_est_height(parsed_message_buffer);
wmBuffer.push(wm);
logFile << wm.getLogString().rdbuf();
break;
case DL_GPS:
gm.utm_east = DL_GPS_utm_east(parsed_message_buffer);
gm.utm_north = DL_GPS_utm_north(parsed_message_buffer);
gm.utm_zone = DL_GPS_utm_zone(parsed_message_buffer);
gm.speed = DL_GPS_speed(parsed_message_buffer);
gm.week = DL_GPS_week(parsed_message_buffer);
gm.itow = DL_GPS_itow(parsed_message_buffer);
gm.alt = DL_GPS_alt(parsed_message_buffer);
gmBuffer.push(gm);
logFile << gm.getLogString().rdbuf();
break;
default:
break;
}
}