-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaders.cpp
78 lines (69 loc) · 1.81 KB
/
readers.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
#include <cstdint>
#include "readers.h"
#include "table.h"
extern "C"{
#include "table.h"
#include "mavlink/mavlink_types.h"
#include "mavlink/common/mavlink.h"
#include "mavlink_introspect_gen.h"
}
#include "c_introspect.h"
namespace UAVFormatReaders {
void dataFlashReader::parseByte(const uint8_t byte) {
this->hasData = this->parser.parseDataFlash(byte, this->msg);
this->numBytes++;
if (this->hasData) {
this->numPackets++;
cStruct s = this->parser.getIntrospectiveStruct(this->msg);
this->results.push(new introspect::Struct(&s));
}
}
void dataFlashReader::parseBuffer(const uint8_t * buf, uint64_t len) {
for (uint64_t i = 0; i < len; i++) {
this->parseByte(buf[i]);
}
}
introspect::Struct* dataFlashReader::getPacket() {
// Caller should delete
if (this->numAvailable() > 0) {
auto s = this->results.front();
this->results.pop();
return s;
}
else throw "Not ready to provide data!";
}
int mavLinkReader::channel = 1;
void mavLinkReader::parseByte(const uint8_t byte){
this->hasData = mavlink_parse_char(
this->mychannel,
byte,
&this->msg,
&this->status);
this->numBytes++;
if (this->hasData){
this->numPackets++;
int id = this->msg.msgid;
if (unboxers[id] != nullptr) {
cStruct * s = (unboxers[id])(&this->msg);
this->results.push(new introspect::Struct(s));
}
}
}
void mavLinkReader::parseBuffer(const uint8_t * buf, uint64_t len){
for (uint64_t i = 0; i < len; i++) {
this->parseByte(buf[i]);
}
}
introspect::Struct * mavLinkReader::getPacket() {
// Caller should delete
if (this->numAvailable() > 0) {
auto s = this->results.front();
this->results.pop();
return s;
}
else throw "Not ready to provide data!";
}
void deleteStruct(introspect::Struct * s) {
delete s;
}
}