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

mavlink / MAVSDK / 11767930807

10 Nov 2024 07:33PM UTC coverage: 38.608% (+0.7%) from 37.921%
11767930807

push

github

web-flow
Merge pull request #2394 from mavlink/pr-consolidate-ci

Consolidate CI

12030 of 31159 relevant lines covered (38.61%)

243.33 hits per line

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

0.0
/src/mavsdk/plugins/winch/winch_impl.cpp
1
#include "winch_impl.h"
2
#include "system.h"
3
#include "callback_list.tpp"
4

5
namespace mavsdk {
6

7
template class CallbackList<Winch::Status>;
8

9
WinchImpl::WinchImpl(System& system) : PluginImplBase(system)
×
10
{
11
    _system_impl->register_plugin(this);
×
12
}
×
13

14
WinchImpl::WinchImpl(std::shared_ptr<System> system) : PluginImplBase(std::move(system))
×
15
{
16
    _system_impl->register_plugin(this);
×
17
}
×
18

19
WinchImpl::~WinchImpl()
×
20
{
21
    _system_impl->unregister_plugin(this);
×
22
}
×
23

24
void WinchImpl::init()
×
25
{
26
    _system_impl->register_mavlink_message_handler(
×
27
        MAVLINK_MSG_ID_WINCH_STATUS,
28
        [this](const mavlink_message_t& message) { process_status(message); },
×
29
        this);
30
}
×
31

32
Winch::StatusHandle WinchImpl::subscribe_status(const Winch::StatusCallback& callback)
×
33
{
34
    std::lock_guard<std::mutex> lock(_subscription_mutex);
×
35
    return _status_subscriptions.subscribe(callback);
×
36
}
×
37

38
void WinchImpl::unsubscribe_status(Winch::StatusHandle handle)
×
39
{
40
    std::lock_guard<std::mutex> lock(_subscription_mutex);
×
41
    _status_subscriptions.unsubscribe(handle);
×
42
}
×
43

44
void WinchImpl::set_status(Winch::Status status)
×
45
{
46
    std::lock_guard<std::mutex> lock(_status_mutex);
×
47
    _status = status;
×
48
}
×
49

50
Winch::Status WinchImpl::status() const
×
51
{
52
    std::lock_guard<std::mutex> lock(_status_mutex);
×
53
    return _status;
×
54
}
×
55

56
void WinchImpl::process_status(const mavlink_message_t& message)
×
57
{
58
    mavlink_winch_status_t mavlink_winch_status;
×
59
    mavlink_msg_winch_status_decode(&message, &mavlink_winch_status);
×
60

61
    Winch::StatusFlags status_flags;
×
62
    status_flags.healthy =
×
63
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_HEALTHY;
×
64
    status_flags.fully_retracted =
×
65
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_FULLY_RETRACTED;
×
66
    status_flags.moving =
×
67
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_MOVING;
×
68
    status_flags.clutch_engaged =
×
69
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_CLUTCH_ENGAGED;
×
70
    status_flags.locked =
×
71
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_LOCKED;
×
72
    status_flags.dropping =
×
73
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_DROPPING;
×
74
    status_flags.arresting =
×
75
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_ARRESTING;
×
76
    status_flags.ground_sense =
×
77
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_GROUND_SENSE;
×
78
    status_flags.retracting =
×
79
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_RETRACTING;
×
80
    status_flags.redeliver =
×
81
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_REDELIVER;
×
82
    status_flags.abandon_line =
×
83
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_ABANDON_LINE;
×
84
    status_flags.locking =
×
85
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_LOCKING;
×
86
    status_flags.load_line =
×
87
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_LOAD_LINE;
×
88
    status_flags.load_payload =
×
89
        mavlink_winch_status.status & MAV_WINCH_STATUS_FLAG::MAV_WINCH_STATUS_LOAD_PAYLOAD;
×
90

91
    Winch::Status new_status;
×
92
    new_status.time_usec = mavlink_winch_status.time_usec;
×
93
    new_status.line_length_m = mavlink_winch_status.line_length;
×
94
    new_status.speed_m_s = mavlink_winch_status.speed;
×
95
    new_status.tension_kg = mavlink_winch_status.tension;
×
96
    new_status.voltage_v = mavlink_winch_status.voltage;
×
97
    new_status.current_a = mavlink_winch_status.current;
×
98
    new_status.temperature_c = mavlink_winch_status.temperature;
×
99
    new_status.status_flags = status_flags;
×
100

101
    set_status(new_status);
×
102

103
    {
104
        std::lock_guard<std::mutex> lock(_subscription_mutex);
×
105
        _status_subscriptions.queue(
×
106
            status(), [this](const auto& func) { _system_impl->call_user_callback(func); });
×
107
    }
×
108
}
×
109

110
void WinchImpl::deinit() {}
×
111

112
void WinchImpl::enable() {}
×
113

114
void WinchImpl::disable() {}
×
115

116
void WinchImpl::relax_async(uint32_t instance, const Winch::ResultCallback callback)
×
117
{
118
    MavlinkCommandSender::CommandLong command{};
×
119

120
    command.command = MAV_CMD_DO_WINCH;
×
121
    command.params.maybe_param1 = static_cast<float>(instance);
×
122
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::Relaxed);
×
123

124
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
125

126
    _system_impl->send_command_async(
×
127
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
128
            command_result_callback(result, callback);
×
129
        });
×
130
}
×
131

132
Winch::Result WinchImpl::relax(uint32_t instance)
×
133
{
134
    auto prom = std::promise<Winch::Result>();
×
135
    auto fut = prom.get_future();
×
136

137
    relax_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
138

139
    return fut.get();
×
140
}
×
141

142
void WinchImpl::relative_length_control_async(
×
143
    uint32_t instance, float length, float rate, const Winch::ResultCallback callback)
144
{
145
    MavlinkCommandSender::CommandLong command{};
×
146

147
    command.command = MAV_CMD_DO_WINCH;
×
148
    command.params.maybe_param1 = static_cast<float>(instance);
×
149
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::RelativeLengthControl);
×
150
    command.params.maybe_param3 = length;
×
151
    command.params.maybe_param4 = rate;
×
152

153
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
154

155
    _system_impl->send_command_async(
×
156
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
157
            command_result_callback(result, callback);
×
158
        });
×
159
}
×
160

161
Winch::Result WinchImpl::relative_length_control(uint32_t instance, float length, float rate)
×
162
{
163
    auto prom = std::promise<Winch::Result>();
×
164
    auto fut = prom.get_future();
×
165

166
    relative_length_control_async(
×
167
        instance, length, rate, [&prom](Winch::Result result) { prom.set_value(result); });
×
168

169
    return fut.get();
×
170
}
×
171

172
void WinchImpl::rate_control_async(
×
173
    uint32_t instance, float rate, const Winch::ResultCallback callback)
174
{
175
    MavlinkCommandSender::CommandLong command{};
×
176

177
    command.command = MAV_CMD_DO_WINCH;
×
178
    command.params.maybe_param1 = static_cast<float>(instance);
×
179
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::RateControl);
×
180
    command.params.maybe_param4 = rate;
×
181

182
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
183

184
    _system_impl->send_command_async(
×
185
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
186
            command_result_callback(result, callback);
×
187
        });
×
188
}
×
189

190
Winch::Result WinchImpl::rate_control(uint32_t instance, float rate)
×
191
{
192
    auto prom = std::promise<Winch::Result>();
×
193
    auto fut = prom.get_future();
×
194

195
    rate_control_async(instance, rate, [&prom](Winch::Result result) { prom.set_value(result); });
×
196

197
    return fut.get();
×
198
}
×
199

200
void WinchImpl::lock_async(uint32_t instance, const Winch::ResultCallback callback)
×
201
{
202
    MavlinkCommandSender::CommandLong command{};
×
203

204
    command.command = MAV_CMD_DO_WINCH;
×
205
    command.params.maybe_param1 = static_cast<float>(instance);
×
206
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::Lock);
×
207

208
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
209

210
    _system_impl->send_command_async(
×
211
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
212
            command_result_callback(result, callback);
×
213
        });
×
214
}
×
215

216
Winch::Result WinchImpl::lock(uint32_t instance)
×
217
{
218
    auto prom = std::promise<Winch::Result>();
×
219
    auto fut = prom.get_future();
×
220

221
    lock_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
222

223
    return fut.get();
×
224
}
×
225

226
void WinchImpl::deliver_async(uint32_t instance, const Winch::ResultCallback callback)
×
227
{
228
    MavlinkCommandSender::CommandLong command{};
×
229

230
    command.command = MAV_CMD_DO_WINCH;
×
231
    command.params.maybe_param1 = static_cast<float>(instance);
×
232
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::Deliver);
×
233

234
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
235

236
    _system_impl->send_command_async(
×
237
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
238
            command_result_callback(result, callback);
×
239
        });
×
240
}
×
241

242
Winch::Result WinchImpl::deliver(uint32_t instance)
×
243
{
244
    auto prom = std::promise<Winch::Result>();
×
245
    auto fut = prom.get_future();
×
246

247
    deliver_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
248

249
    return fut.get();
×
250
}
×
251

252
void WinchImpl::hold_async(uint32_t instance, const Winch::ResultCallback callback)
×
253
{
254
    MavlinkCommandSender::CommandLong command{};
×
255

256
    command.command = MAV_CMD_DO_WINCH;
×
257
    command.params.maybe_param1 = static_cast<float>(instance);
×
258
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::Hold);
×
259

260
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
261

262
    _system_impl->send_command_async(
×
263
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
264
            command_result_callback(result, callback);
×
265
        });
×
266
}
×
267

268
Winch::Result WinchImpl::hold(uint32_t instance)
×
269
{
270
    auto prom = std::promise<Winch::Result>();
×
271
    auto fut = prom.get_future();
×
272

273
    hold_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
274

275
    return fut.get();
×
276
}
×
277

278
void WinchImpl::retract_async(uint32_t instance, const Winch::ResultCallback callback)
×
279
{
280
    MavlinkCommandSender::CommandLong command{};
×
281

282
    command.command = MAV_CMD_DO_WINCH;
×
283
    command.params.maybe_param1 = static_cast<float>(instance);
×
284
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::Retract);
×
285

286
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
287

288
    _system_impl->send_command_async(
×
289
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
290
            command_result_callback(result, callback);
×
291
        });
×
292
}
×
293

294
Winch::Result WinchImpl::retract(uint32_t instance)
×
295
{
296
    auto prom = std::promise<Winch::Result>();
×
297
    auto fut = prom.get_future();
×
298

299
    retract_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
300

301
    return fut.get();
×
302
}
×
303

304
void WinchImpl::load_line_async(uint32_t instance, const Winch::ResultCallback callback)
×
305
{
306
    MavlinkCommandSender::CommandLong command{};
×
307

308
    command.command = MAV_CMD_DO_WINCH;
×
309
    command.params.maybe_param1 = static_cast<float>(instance);
×
310
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::LoadLine);
×
311

312
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
313

314
    _system_impl->send_command_async(
×
315
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
316
            command_result_callback(result, callback);
×
317
        });
×
318
}
×
319

320
Winch::Result WinchImpl::load_line(uint32_t instance)
×
321
{
322
    auto prom = std::promise<Winch::Result>();
×
323
    auto fut = prom.get_future();
×
324

325
    load_line_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
326

327
    return fut.get();
×
328
}
×
329

330
void WinchImpl::abandon_line_async(uint32_t instance, const Winch::ResultCallback callback)
×
331
{
332
    MavlinkCommandSender::CommandLong command{};
×
333

334
    command.command = MAV_CMD_DO_WINCH;
×
335
    command.params.maybe_param1 = static_cast<float>(instance);
×
336
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::AbandonLine);
×
337

338
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
339

340
    _system_impl->send_command_async(
×
341
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
342
            command_result_callback(result, callback);
×
343
        });
×
344
}
×
345

346
Winch::Result WinchImpl::abandon_line(uint32_t instance)
×
347
{
348
    auto prom = std::promise<Winch::Result>();
×
349
    auto fut = prom.get_future();
×
350

351
    abandon_line_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
352

353
    return fut.get();
×
354
}
×
355

356
void WinchImpl::load_payload_async(uint32_t instance, const Winch::ResultCallback callback)
×
357
{
358
    MavlinkCommandSender::CommandLong command{};
×
359

360
    command.command = MAV_CMD_DO_WINCH;
×
361
    command.params.maybe_param1 = static_cast<float>(instance);
×
362
    command.params.maybe_param2 = static_cast<float>(Winch::WinchAction::LoadPayload);
×
363

364
    command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH;
×
365

366
    _system_impl->send_command_async(
×
367
        command, [this, callback](MavlinkCommandSender::Result result, float) {
×
368
            command_result_callback(result, callback);
×
369
        });
×
370
}
×
371

372
Winch::Result WinchImpl::load_payload(uint32_t instance)
×
373
{
374
    auto prom = std::promise<Winch::Result>();
×
375
    auto fut = prom.get_future();
×
376

377
    load_payload_async(instance, [&prom](Winch::Result result) { prom.set_value(result); });
×
378

379
    return fut.get();
×
380
}
×
381

382
Winch::Result WinchImpl::winch_result_from_command_result(MavlinkCommandSender::Result result)
×
383
{
384
    switch (result) {
×
385
        case MavlinkCommandSender::Result::Success:
×
386
            return Winch::Result::Success;
×
387
        case MavlinkCommandSender::Result::NoSystem:
×
388
            return Winch::Result::NoSystem;
×
389
        case MavlinkCommandSender::Result::ConnectionError:
×
390
            // Fallthrough
391
        case MavlinkCommandSender::Result::Timeout:
392
            return Winch::Result::Timeout;
×
393
        case MavlinkCommandSender::Result::Busy:
×
394
            return Winch::Result::Busy;
×
395
        case MavlinkCommandSender::Result::Denied:
×
396
            // Fallthrough
397
        case MavlinkCommandSender::Result::TemporarilyRejected:
398
            // Fallthrough
399
        case MavlinkCommandSender::Result::Failed:
400
            return Winch::Result::Failed;
×
401
        case MavlinkCommandSender::Result::Unsupported:
×
402
            return Winch::Result::Unsupported;
×
403
        default:
×
404
            return Winch::Result::Unknown;
×
405
    }
406
}
407

408
void WinchImpl::command_result_callback(
×
409
    MavlinkCommandSender::Result command_result, const Winch::ResultCallback& callback) const
410
{
411
    Winch::Result action_result = winch_result_from_command_result(command_result);
×
412

413
    if (callback) {
×
414
        auto temp_callback = callback;
×
415
        _system_impl->call_user_callback(
×
416
            [temp_callback, action_result]() { temp_callback(action_result); });
417
    }
×
418
}
×
419

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

© 2025 Coveralls, Inc