-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMAVLinkReceiver.cpp
More file actions
53 lines (44 loc) · 1.86 KB
/
MAVLinkReceiver.cpp
File metadata and controls
53 lines (44 loc) · 1.86 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
#include "MAVLinkReceiver.h"
struct MAVLinkReceiver::Impl {
mavlink_status_t status{};
};
MAVLinkReceiver::MAVLinkReceiver(QObject* parent)
: QObject(parent), d_(std::make_unique<Impl>()) {}
MAVLinkReceiver::~MAVLinkReceiver() = default; // ← now Impl is complete
void MAVLinkReceiver::onBytes(const QByteArray& data, uint16_t senderPort) {
RxMavlinkMsg out = getMAVLinkFromBytes(data);
emit messageReceived(out);
}
// void MAVLinkReceiver::onBytes(const QByteArray& data) {
// RxMavlinkMsg out = getMAVLinkFromBytes(data);
// emit messageReceived(out);
// }
RxMavlinkMsg MAVLinkReceiver::getMAVLinkFromBytes(const QByteArray& data) {
mavlink_message_t msg;
const uint8_t* p = reinterpret_cast<const uint8_t*>(data.constData());
const int n = data.size();
for (int i = 0; i < n; ++i) {
if (mavlink_parse_char(MAVLINK_COMM_0, p[i], &msg, &d_->status)) {
RxMavlinkMsg out{ msg.sysid, msg.compid, msg.msgid,
QByteArray(reinterpret_cast<const char*>(_MAV_PAYLOAD(&msg)),
static_cast<int>(msg.len)) };
return out;
}
}
return RxMavlinkMsg{0, 0, 0, QByteArray()};
}
RxMavlinkMsg MAVLinkReceiver::getMAVLinkFromBytesWithFreshState(const QByteArray& data) {
mavlink_message_t msg;
mavlink_status_t fresh{};
const uint8_t* p = reinterpret_cast<const uint8_t*>(data.constData());
const int n = data.size();
for (int i = 0; i < n; ++i) {
if (mavlink_parse_char(MAVLINK_COMM_0, p[i], &msg, &fresh)) {
RxMavlinkMsg out{ msg.sysid, msg.compid, msg.msgid,
QByteArray(reinterpret_cast<const char*>(_MAV_PAYLOAD(&msg)),
static_cast<int>(msg.len)) };
return out;
}
}
return RxMavlinkMsg{0, 0, 0, QByteArray()};
}