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

mavlink / MAVSDK / 17565334070

08 Sep 2025 10:02PM UTC coverage: 47.262% (+0.02%) from 47.241%
17565334070

Pull #2649

github

web-flow
Merge 31bace7d2 into 57e1189fd
Pull Request #2649: CI: Tell sonar we use C++17

16788 of 35521 relevant lines covered (47.26%)

444.32 hits per line

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

87.93
/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(
118✔
13
    ReceiverCallback receiver_callback,
14
    LibmavReceiverCallback libmav_receiver_callback,
15
    MavsdkImpl& mavsdk_impl,
16
    ForwardingOption forwarding_option) :
118✔
17
    _receiver_callback(std::move(receiver_callback)),
118✔
18
    _libmav_receiver_callback(std::move(libmav_receiver_callback)),
118✔
19
    _mavsdk_impl(mavsdk_impl),
118✔
20
    _mavlink_receiver(),
118✔
21
    _libmav_receiver(),
118✔
22
    _forwarding_option(forwarding_option)
236✔
23
{
24
    // Insert system ID 0 in all connections for broadcast.
25
    _system_ids.insert(0);
118✔
26

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

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

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

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

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

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

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

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

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

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

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

105
bool Connection::should_forward_messages() const
39✔
106
{
107
    return _forwarding_option == ForwardingOption::ForwardingOn;
39✔
108
}
109

110
unsigned Connection::forwarding_connections_count()
104✔
111
{
112
    return _forwarding_connections_count;
104✔
113
}
114

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

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