-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.cpp
46 lines (38 loc) · 1.07 KB
/
connection.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
#include "connection.h"
#include "mavsdk_impl.h"
#include "mavlink_channels.h"
#include "global_include.h"
namespace mavsdk {
Connection::Connection(receiver_callback_t receiver_callback) :
_receiver_callback(receiver_callback),
_mavlink_receiver()
{}
Connection::~Connection()
{
// Just in case a specific connection didn't call it already.
stop_mavlink_receiver();
_receiver_callback = {};
}
bool Connection::start_mavlink_receiver()
{
uint8_t channel;
if (!MAVLinkChannels::Instance().checkout_free_channel(channel)) {
return false;
}
_mavlink_receiver.reset(new MAVLinkReceiver(channel));
return true;
}
void Connection::stop_mavlink_receiver()
{
if (_mavlink_receiver) {
uint8_t used_channel = _mavlink_receiver->get_channel();
// Destroy receiver before giving the channel back.
_mavlink_receiver.reset();
MAVLinkChannels::Instance().checkin_used_channel(used_channel);
}
}
void Connection::receive_message(mavlink_message_t& message)
{
_receiver_callback(message);
}
} // namespace mavsdk