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

mavlink / MAVSDK / 16246048748

13 Jul 2025 06:04AM UTC coverage: 46.215% (+1.0%) from 45.212%
16246048748

Pull #2610

github

web-flow
Merge bbba396a5 into 6c112e71f
Pull Request #2610: Integrate parts of libmav into MAVSDK and add MavlinkDirect plugin

727 of 980 new or added lines in 15 files covered. (74.18%)

26 existing lines in 5 files now uncovered.

16215 of 35086 relevant lines covered (46.22%)

141597.23 hits per line

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

66.18
/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

UNCOV
12
Connection::Connection(ReceiverCallback receiver_callback, ForwardingOption forwarding_option) :
×
UNCOV
13
    _receiver_callback(std::move(receiver_callback)),
×
UNCOV
14
    _mavlink_receiver(),
×
UNCOV
15
    _forwarding_option(forwarding_option)
×
16
{
17
    // Insert system ID 0 in all connections for broadcast.
UNCOV
18
    _system_ids.insert(0);
×
19

UNCOV
20
    if (forwarding_option == ForwardingOption::ForwardingOn) {
×
21
        _forwarding_connections_count++;
×
22
    }
23

NEW
24
    if (const char* env_p = std::getenv("MAVSDK_MAVLINK_DIRECT_DEBUGGING")) {
×
NEW
25
        if (std::string(env_p) == "1") {
×
NEW
26
            _debugging = true;
×
27
        }
28
    }
NEW
29
}
×
30

31
Connection::Connection(
98✔
32
    ReceiverCallback receiver_callback,
33
    LibmavReceiverCallback libmav_receiver_callback,
34
    ForwardingOption forwarding_option) :
98✔
35
    _receiver_callback(std::move(receiver_callback)),
98✔
36
    _libmav_receiver_callback(std::move(libmav_receiver_callback)),
98✔
37
    _mavlink_receiver(),
98✔
38
    _libmav_receiver(),
98✔
39
    _forwarding_option(forwarding_option)
196✔
40
{
41
    // Insert system ID 0 in all connections for broadcast.
42
    _system_ids.insert(0);
98✔
43

44
    if (forwarding_option == ForwardingOption::ForwardingOn) {
98✔
NEW
45
        _forwarding_connections_count++;
×
46
    }
47

48
    if (const char* env_p = std::getenv("MAVSDK_MAVLINK_DIRECT_DEBUGGING")) {
98✔
NEW
49
        if (std::string(env_p) == "1") {
×
NEW
50
            _debugging = true;
×
51
        }
52
    }
53
}
98✔
54

55
Connection::~Connection()
98✔
56
{
57
    // Just in case a specific connection didn't call it already.
58
    stop_mavlink_receiver();
98✔
59
    stop_libmav_receiver();
98✔
60
    _receiver_callback = {};
98✔
61
    _libmav_receiver_callback = {};
98✔
62
}
98✔
63

64
bool Connection::start_mavlink_receiver()
98✔
65
{
66
    _mavlink_receiver = std::make_unique<MavlinkReceiver>();
98✔
67
    return true;
98✔
68
}
69

70
void Connection::stop_mavlink_receiver()
196✔
71
{
72
    if (_mavlink_receiver) {
196✔
73
        _mavlink_receiver.reset();
98✔
74
    }
75
}
196✔
76

77
bool Connection::start_libmav_receiver()
96✔
78
{
79
    _libmav_receiver = std::make_unique<LibmavReceiver>();
96✔
80
    return true;
96✔
81
}
82

83
void Connection::stop_libmav_receiver()
98✔
84
{
85
    if (_libmav_receiver) {
98✔
86
        _libmav_receiver.reset();
96✔
87
    }
88
}
98✔
89

90
void Connection::receive_libmav_message(const LibmavMessage& message, Connection* connection)
2,129✔
91
{
92
    // Register system ID when receiving a message from a new system.
93
    if (_system_ids.find(message.system_id) == _system_ids.end()) {
2,129✔
NEW
94
        _system_ids.insert(message.system_id);
×
95
    }
96

97
    if (_debugging) {
2,129✔
NEW
98
        LogDebug() << "Connection::receive_libmav_message: " << message.message_name
×
NEW
99
                   << " from system " << message.system_id;
×
100
    }
101

102
    if (_libmav_receiver_callback) {
2,129✔
103
        if (_debugging) {
2,127✔
NEW
104
            LogDebug() << "Calling libmav receiver callback for: " << message.message_name;
×
105
        }
106
        _libmav_receiver_callback(message, connection);
2,127✔
107
    } else {
NEW
108
        LogWarn() << "No libmav receiver callback set!";
×
109
    }
110
}
2,128✔
111

112
void Connection::receive_message(mavlink_message_t& message, Connection* connection)
2,147✔
113
{
114
    // Register system ID when receiving a message from a new system.
115
    if (_system_ids.find(message.sysid) == _system_ids.end()) {
2,147✔
116
        _system_ids.insert(message.sysid);
98✔
117
    }
118
    _receiver_callback(message, connection);
2,145✔
119
}
2,147✔
120

121
bool Connection::should_forward_messages() const
×
122
{
123
    return _forwarding_option == ForwardingOption::ForwardingOn;
×
124
}
125

126
unsigned Connection::forwarding_connections_count()
×
127
{
128
    return _forwarding_connections_count;
×
129
}
130

131
bool Connection::has_system_id(uint8_t system_id)
1,730✔
132
{
133
    return _system_ids.find(system_id) != _system_ids.end();
1,730✔
134
}
135

136
} // 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