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

mavlink / MAVSDK / 16233609062

12 Jul 2025 02:58AM UTC coverage: 45.799% (+0.6%) from 45.212%
16233609062

Pull #2610

github

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

473 of 727 new or added lines in 14 files covered. (65.06%)

35 existing lines in 7 files now uncovered.

15955 of 34837 relevant lines covered (45.8%)

145116.67 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(
94✔
32
    ReceiverCallback receiver_callback,
33
    LibmavReceiverCallback libmav_receiver_callback,
34
    ForwardingOption forwarding_option) :
94✔
35
    _receiver_callback(std::move(receiver_callback)),
94✔
36
    _libmav_receiver_callback(std::move(libmav_receiver_callback)),
94✔
37
    _mavlink_receiver(),
94✔
38
    _libmav_receiver(),
94✔
39
    _forwarding_option(forwarding_option)
188✔
40
{
41
    // Insert system ID 0 in all connections for broadcast.
42
    _system_ids.insert(0);
94✔
43

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

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

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

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

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

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

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

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

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

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

112
void Connection::receive_message(mavlink_message_t& message, Connection* connection)
2,131✔
113
{
114
    // Register system ID when receiving a message from a new system.
115
    if (_system_ids.find(message.sysid) == _system_ids.end()) {
2,131✔
116
        _system_ids.insert(message.sysid);
94✔
117
    }
118
    _receiver_callback(message, connection);
2,126✔
119
}
2,131✔
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,725✔
132
{
133
    return _system_ids.find(system_id) != _system_ids.end();
1,725✔
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