• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 16485391475

24 Jul 2025 01:13AM UTC coverage: 46.33% (+1.2%) from 45.096%
16485391475

push

github

web-flow
Merge pull request #2610 from mavlink/pr-add-libmavlike

Integrate parts of libmav into MAVSDK and add MavlinkDirect plugin

764 of 987 new or added lines in 14 files covered. (77.41%)

10 existing lines in 1 file now uncovered.

16272 of 35122 relevant lines covered (46.33%)

359.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.31
/src/mavsdk/core/connection.cpp
1
#include "connection.h"
2

3
#include <memory>
4
#include <utility>
5
#include "mavsdk_impl.h"
6
#include "log.h"
7

8
namespace mavsdk {
9

10
std::atomic<unsigned> Connection::_forwarding_connections_count = 0;
11

12
Connection::Connection(
100✔
13
    ReceiverCallback receiver_callback,
14
    LibmavReceiverCallback libmav_receiver_callback,
15
    mav::MessageSet& message_set,
16
    ForwardingOption forwarding_option) :
100✔
17
    _receiver_callback(std::move(receiver_callback)),
100✔
18
    _libmav_receiver_callback(std::move(libmav_receiver_callback)),
100✔
19
    _message_set(message_set),
100✔
20
    _mavlink_receiver(),
100✔
21
    _libmav_receiver(),
100✔
22
    _forwarding_option(forwarding_option)
200✔
23
{
24
    // Insert system ID 0 in all connections for broadcast.
25
    _system_ids.insert(0);
100✔
26

27
    if (forwarding_option == ForwardingOption::ForwardingOn) {
100✔
28
        _forwarding_connections_count++;
×
29
    }
30

31
    if (const char* env_p = std::getenv("MAVSDK_MAVLINK_DIRECT_DEBUGGING")) {
100✔
NEW
32
        if (std::string(env_p) == "1") {
×
NEW
33
            _debugging = true;
×
34
        }
35
    }
36
}
100✔
37

38
Connection::~Connection()
100✔
39
{
40
    // Just in case a specific connection didn't call it already.
41
    stop_mavlink_receiver();
100✔
42
    stop_libmav_receiver();
100✔
43
    _receiver_callback = {};
100✔
44
    _libmav_receiver_callback = {};
100✔
45
}
100✔
46

47
bool Connection::start_mavlink_receiver()
100✔
48
{
49
    _mavlink_receiver = std::make_unique<MavlinkReceiver>();
100✔
50
    return true;
100✔
51
}
52

53
void Connection::stop_mavlink_receiver()
200✔
54
{
55
    if (_mavlink_receiver) {
200✔
56
        _mavlink_receiver.reset();
100✔
57
    }
58
}
200✔
59

60
bool Connection::start_libmav_receiver()
100✔
61
{
62
    _libmav_receiver = std::make_unique<LibmavReceiver>(_message_set);
100✔
63
    return true;
100✔
64
}
65

66
void Connection::stop_libmav_receiver()
100✔
67
{
68
    if (_libmav_receiver) {
100✔
69
        _libmav_receiver.reset();
100✔
70
    }
71
}
100✔
72

73
void Connection::receive_libmav_message(const LibmavMessage& message, Connection* connection)
2,126✔
74
{
75
    // Register system ID when receiving a message from a new system.
76
    if (_system_ids.find(message.system_id) == _system_ids.end()) {
2,126✔
NEW
77
        _system_ids.insert(message.system_id);
×
78
    }
79

80
    if (_debugging) {
2,126✔
NEW
81
        LogDebug() << "Connection::receive_libmav_message: " << message.message_name
×
NEW
82
                   << " from system " << message.system_id;
×
83
    }
84

85
    if (_libmav_receiver_callback) {
2,126✔
86
        if (_debugging) {
2,125✔
NEW
87
            LogDebug() << "Calling libmav receiver callback for: " << message.message_name;
×
88
        }
89
        _libmav_receiver_callback(message, connection);
2,125✔
90
    } else {
NEW
91
        LogWarn() << "No libmav receiver callback set!";
×
92
    }
93
}
2,125✔
94

95
void Connection::receive_message(mavlink_message_t& message, Connection* connection)
2,142✔
96
{
97
    // Register system ID when receiving a message from a new system.
98
    if (_system_ids.find(message.sysid) == _system_ids.end()) {
2,142✔
99
        _system_ids.insert(message.sysid);
100✔
100
    }
101
    _receiver_callback(message, connection);
2,138✔
102
}
2,142✔
103

104
bool Connection::should_forward_messages() const
×
105
{
106
    return _forwarding_option == ForwardingOption::ForwardingOn;
×
107
}
108

109
unsigned Connection::forwarding_connections_count()
×
110
{
111
    return _forwarding_connections_count;
×
112
}
113

114
bool Connection::has_system_id(uint8_t system_id)
1,726✔
115
{
116
    return _system_ids.find(system_id) != _system_ids.end();
1,726✔
117
}
118

119
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc