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

mavlink / MAVSDK / 20560735970

28 Dec 2025 10:59PM UTC coverage: 48.047% (-0.03%) from 48.078%
20560735970

Pull #2746

github

web-flow
Merge 855e4cc2b into 2460e1568
Pull Request #2746: Configuration and component cleanup

18 of 45 new or added lines in 4 files covered. (40.0%)

19 existing lines in 6 files now uncovered.

17741 of 36924 relevant lines covered (48.05%)

466.77 hits per line

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

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

3
#include "mavsdk_impl.h"
4

5
namespace mavsdk {
6

7
Mavsdk::Mavsdk(Configuration configuration)
138✔
8
{
9
    _impl = std::make_shared<MavsdkImpl>(configuration);
138✔
10
}
138✔
11

12
Mavsdk::~Mavsdk() = default;
138✔
13

14
std::string Mavsdk::version() const
1✔
15
{
16
    return _impl->version();
1✔
17
}
18

19
ConnectionResult
20
Mavsdk::add_any_connection(const std::string& connection_url, ForwardingOption forwarding_option)
132✔
21
{
22
    return _impl->add_any_connection(connection_url, forwarding_option).first;
132✔
23
}
24

25
std::pair<ConnectionResult, Mavsdk::ConnectionHandle> Mavsdk::add_any_connection_with_handle(
12✔
26
    const std::string& connection_url, ForwardingOption forwarding_option)
27
{
28
    return _impl->add_any_connection(connection_url, forwarding_option);
12✔
29
}
30

31
void Mavsdk::remove_connection(ConnectionHandle handle)
12✔
32
{
33
    _impl->remove_connection(handle);
12✔
34
}
12✔
35

36
std::vector<std::shared_ptr<System>> Mavsdk::systems() const
57✔
37
{
38
    return _impl->systems();
57✔
39
}
40

41
std::optional<std::shared_ptr<System>> Mavsdk::first_autopilot(double timeout_s) const
57✔
42
{
43
    return _impl->first_autopilot(timeout_s);
57✔
44
}
45

46
void Mavsdk::set_configuration(Configuration configuration)
×
47
{
48
    _impl->set_configuration(configuration);
×
49
}
×
50

51
void Mavsdk::set_timeout_s(double timeout_s)
64✔
52
{
53
    _impl->set_timeout_s(timeout_s);
64✔
54
}
64✔
55

56
void Mavsdk::set_heartbeat_timeout_s(double timeout_s)
×
57
{
58
    _impl->set_heartbeat_timeout_s(timeout_s);
×
59
}
×
60

61
double Mavsdk::get_heartbeat_timeout_s() const
×
62
{
63
    return _impl->heartbeat_timeout_s();
×
64
}
65

66
Mavsdk::NewSystemHandle Mavsdk::subscribe_on_new_system(const NewSystemCallback& callback)
10✔
67
{
68
    return _impl->subscribe_on_new_system(callback);
10✔
69
}
70

71
void Mavsdk::unsubscribe_on_new_system(NewSystemHandle handle)
9✔
72
{
73
    _impl->unsubscribe_on_new_system(handle);
9✔
74
}
9✔
75

76
std::shared_ptr<ServerComponent> Mavsdk::server_component(unsigned instance)
54✔
77
{
78
    return _impl->server_component(instance);
54✔
79
}
80

81
std::shared_ptr<ServerComponent>
82
Mavsdk::server_component_by_type(ComponentType server_component_type, unsigned instance)
×
83
{
84
    return _impl->server_component_by_type(server_component_type, instance);
×
85
}
86

87
std::shared_ptr<ServerComponent> Mavsdk::server_component_by_id(uint8_t component_id)
×
88
{
NEW
89
    return _impl->server_component_by_id(component_id, _impl->get_mav_type());
×
90
}
91

92
Mavsdk::Configuration::Configuration(
×
93
    uint8_t system_id, uint8_t component_id, bool always_send_heartbeats) :
×
94
    _system_id(system_id),
×
95
    _component_id(component_id),
×
96
    _always_send_heartbeats(always_send_heartbeats),
×
97
    _component_type(component_type_for_component_id(component_id)),
×
NEW
98
    _mav_type(static_cast<MAV_TYPE>(
×
NEW
99
        mav_type_for_component_type(component_type_for_component_id(component_id))))
×
UNCOV
100
{}
×
101

102
ComponentType Mavsdk::Configuration::component_type_for_component_id(uint8_t component_id)
×
103
{
104
    switch (component_id) {
×
105
        case Mavsdk::DEFAULT_COMPONENT_ID_AUTOPILOT:
×
106
            return ComponentType::Autopilot;
×
107
        case Mavsdk::DEFAULT_COMPONENT_ID_GCS:
×
108
            return ComponentType::GroundStation;
×
109
        case Mavsdk::DEFAULT_COMPONENT_ID_CC:
×
110
            return ComponentType::CompanionComputer;
×
111
        case Mavsdk::DEFAULT_COMPONENT_ID_CAMERA:
×
112
            return ComponentType::Camera;
×
113
        case Mavsdk::DEFAULT_COMPONENT_ID_GIMBAL:
×
114
            return ComponentType::Gimbal;
×
115
        case Mavsdk::DEFAULT_COMPONENT_ID_REMOTEID:
×
116
            return ComponentType::RemoteId;
×
117
        default:
×
118
            return ComponentType::Custom;
×
119
    }
120
}
121

122
uint8_t Mavsdk::Configuration::mav_type_for_component_type(ComponentType component_type)
331✔
123
{
124
    switch (component_type) {
331✔
125
        case ComponentType::Autopilot:
98✔
126
            return MAV_TYPE_GENERIC;
98✔
127
        case ComponentType::GroundStation:
207✔
128
            return MAV_TYPE_GCS;
207✔
129
        case ComponentType::CompanionComputer:
4✔
130
            return MAV_TYPE_ONBOARD_CONTROLLER;
4✔
131
        case ComponentType::Camera:
22✔
132
            return MAV_TYPE_CAMERA;
22✔
133
        case ComponentType::Gimbal:
×
134
            return MAV_TYPE_GIMBAL;
×
135
        case ComponentType::RemoteId:
×
136
            return MAV_TYPE_ODID;
×
137
        case ComponentType::Custom:
×
138
            return MAV_TYPE_GENERIC;
×
139
        default:
×
140
            return MAV_TYPE_GENERIC;
×
141
    }
142
}
143

144
Mavsdk::Configuration::Configuration(ComponentType component_type) :
277✔
145
    _system_id(Mavsdk::DEFAULT_SYSTEM_ID_GCS),
277✔
146
    _component_id(Mavsdk::DEFAULT_COMPONENT_ID_GCS),
277✔
147
    _always_send_heartbeats(false),
277✔
148
    _component_type(component_type),
277✔
149
    _mav_type(static_cast<MAV_TYPE>(mav_type_for_component_type(component_type)))
277✔
150
{
151
    switch (component_type) {
277✔
152
        case ComponentType::GroundStation:
207✔
153
            _system_id = Mavsdk::DEFAULT_SYSTEM_ID_GCS;
207✔
154
            _component_id = Mavsdk::DEFAULT_COMPONENT_ID_GCS;
207✔
155
            _always_send_heartbeats = false;
207✔
156
            break;
207✔
157
        case ComponentType::CompanionComputer:
3✔
158
            // TODO implement auto-detection of system ID - maybe from heartbeats?
159
            _system_id = Mavsdk::DEFAULT_SYSTEM_ID_CC;
3✔
160
            _component_id = Mavsdk::DEFAULT_COMPONENT_ID_CC;
3✔
161
            _always_send_heartbeats = true;
3✔
162
            break;
3✔
163
        case ComponentType::Autopilot:
58✔
164
            _system_id = Mavsdk::DEFAULT_SYSTEM_ID_AUTOPILOT;
58✔
165
            _component_id = Mavsdk::DEFAULT_COMPONENT_ID_AUTOPILOT;
58✔
166
            _always_send_heartbeats = true;
58✔
167
            break;
58✔
168
        case ComponentType::Camera:
9✔
169
            _system_id = Mavsdk::DEFAULT_SYSTEM_ID_CAMERA;
9✔
170
            _component_id = Mavsdk::DEFAULT_COMPONENT_ID_CAMERA;
9✔
171
            _always_send_heartbeats = true;
9✔
172
            break;
9✔
173
        case ComponentType::Gimbal:
×
174
            _system_id = Mavsdk::DEFAULT_SYSTEM_ID_GIMBAL;
×
175
            _component_id = Mavsdk::DEFAULT_COMPONENT_ID_GIMBAL;
×
176
            _always_send_heartbeats = true;
×
177
            break;
×
178
        case ComponentType::RemoteId:
×
179
            _system_id = Mavsdk::DEFAULT_SYSTEM_ID_REMOTEID;
×
180
            _component_id = Mavsdk::DEFAULT_COMPONENT_ID_REMOTEID;
×
181
            _always_send_heartbeats = true;
×
182
            break;
×
183
        default:
×
184
            break;
×
185
    }
186
}
277✔
187

188
uint8_t Mavsdk::Configuration::get_system_id() const
207✔
189
{
190
    return _system_id;
207✔
191
}
192

193
void Mavsdk::Configuration::set_system_id(uint8_t system_id)
×
194
{
195
    _system_id = system_id;
×
196
}
×
197

198
uint8_t Mavsdk::Configuration::get_component_id() const
414✔
199
{
200
    return _component_id;
414✔
201
}
202

203
void Mavsdk::Configuration::set_component_id(uint8_t component_id)
×
204
{
205
    _component_id = component_id;
×
206
}
×
207

208
bool Mavsdk::Configuration::get_always_send_heartbeats() const
553✔
209
{
210
    return _always_send_heartbeats;
553✔
211
}
212

213
void Mavsdk::Configuration::set_always_send_heartbeats(bool always_send_heartbeats)
69✔
214
{
215
    _always_send_heartbeats = always_send_heartbeats;
69✔
216
}
69✔
217

218
ComponentType Mavsdk::Configuration::get_component_type() const
4,998✔
219
{
220
    return _component_type;
4,998✔
221
}
222

223
void Mavsdk::Configuration::set_component_type(ComponentType component_type)
×
224
{
225
    _component_type = component_type;
×
226
}
×
227

228
uint8_t Mavsdk::Configuration::get_mav_type() const
209✔
229
{
230
    return _mav_type;
209✔
231
}
232

233
void Mavsdk::Configuration::set_mav_type(uint8_t mav_type)
1✔
234
{
235
    _mav_type = static_cast<MAV_TYPE>(mav_type);
1✔
236
}
1✔
237

238
void Mavsdk::intercept_incoming_messages_async(std::function<bool(mavlink_message_t&)> callback)
24✔
239
{
240
    _impl->intercept_incoming_messages_async(callback);
24✔
241
}
24✔
242

243
void Mavsdk::intercept_outgoing_messages_async(std::function<bool(mavlink_message_t&)> callback)
14✔
244
{
245
    _impl->intercept_outgoing_messages_async(callback);
14✔
246
}
14✔
247

248
void Mavsdk::pass_received_raw_bytes(const char* bytes, size_t length)
1✔
249
{
250
    _impl->pass_received_raw_bytes(bytes, length);
1✔
251
}
1✔
252

253
Mavsdk::RawBytesHandle Mavsdk::subscribe_raw_bytes_to_be_sent(RawBytesCallback callback)
1✔
254
{
255
    return _impl->subscribe_raw_bytes_to_be_sent(callback);
1✔
256
}
257

258
void Mavsdk::unsubscribe_raw_bytes_to_be_sent(RawBytesHandle handle)
1✔
259
{
260
    _impl->unsubscribe_raw_bytes_to_be_sent(handle);
1✔
261
}
1✔
262

263
Mavsdk::ConnectionErrorHandle
264
Mavsdk::subscribe_connection_errors(Mavsdk::ConnectionErrorCallback callback)
×
265
{
266
    return _impl->subscribe_connection_errors(callback);
×
267
}
268

269
void Mavsdk::unsubscribe_connection_errors(ConnectionErrorHandle handle)
×
270
{
271
    return _impl->unsubscribe_connection_errors(handle);
×
272
}
273

274
Mavsdk::InterceptJsonHandle
275
Mavsdk::subscribe_incoming_messages_json(const InterceptJsonCallback& callback)
1✔
276
{
277
    return _impl->subscribe_incoming_messages_json(callback);
1✔
278
}
279

280
void Mavsdk::unsubscribe_incoming_messages_json(InterceptJsonHandle handle)
1✔
281
{
282
    _impl->unsubscribe_incoming_messages_json(handle);
1✔
283
}
1✔
284

285
Mavsdk::InterceptJsonHandle
286
Mavsdk::subscribe_outgoing_messages_json(const InterceptJsonCallback& callback)
1✔
287
{
288
    return _impl->subscribe_outgoing_messages_json(callback);
1✔
289
}
290

291
void Mavsdk::unsubscribe_outgoing_messages_json(InterceptJsonHandle handle)
1✔
292
{
293
    _impl->unsubscribe_outgoing_messages_json(handle);
1✔
294
}
1✔
295

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