QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MavCommandQueue.cc
Go to the documentation of this file.
1#include "MavCommandQueue.h"
2
3#include <QtCore/QTimer>
4
5#include "AppMessages.h"
6#include "FirmwarePlugin.h"
7#include "MAVLinkLib.h"
9#include "MAVLinkProtocol.h"
10#include "MissionCommandTree.h"
11#include "QGCLoggingCategory.h"
12#include "Vehicle.h"
13#include "VehicleLinkManager.h"
14
15#ifdef QT_DEBUG
16#include "MockLink.h"
17#endif
18
19QGC_LOGGING_CATEGORY(MavCommandQueueLog, "Vehicle.MavCommandQueue")
20
21std::optional<int> MavCommandQueue::_testAckTimeoutOverride;
22
24 : QObject(vehicle)
25 , _vehicle(vehicle)
26{
27 _responseCheckTimer.setSingleShot(false);
28 _responseCheckTimer.setInterval(_responseCheckIntervalMSecs());
29 _responseCheckTimer.start();
30 connect(&_responseCheckTimer, &QTimer::timeout, this, &MavCommandQueue::_responseTimeoutCheck);
31}
32
34{
35 _responseCheckTimer.stop();
36 _responseCheckTimer.disconnect();
37}
38
40{
41 qCDebug(MavCommandQueueLog) << "stop - clearing pending commands and halting response timer";
42 _stopped = true;
43 _responseCheckTimer.stop();
44 _responseCheckTimer.disconnect();
45 _list.clear();
46}
47
48void MavCommandQueue::sendCommand(int compId, MAV_CMD command, bool showError, float param1, float param2, float param3, float param4, float param5, float param6, float param7)
49{
50 sendWorker(false, // commandInt
51 showError,
52 nullptr, // no handlers
53 compId,
54 command,
55 MAV_FRAME_GLOBAL,
56 param1, param2, param3, param4, param5, param6, param7);
57}
58
59void MavCommandQueue::sendCommandDelayed(int compId, MAV_CMD command, bool showError, int milliseconds, float param1, float param2, float param3, float param4, float param5, float param6, float param7)
60{
61 QTimer::singleShot(milliseconds, this, [=, this] {
62 sendCommand(compId, command, showError, param1, param2, param3, param4, param5, param6, param7);
63 });
64}
65
66void MavCommandQueue::sendCommandInt(int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
67{
68 sendWorker(true, // commandInt
69 showError,
70 nullptr, // no handlers
71 compId,
72 command,
73 frame,
74 param1, param2, param3, param4, param5, param6, param7);
75}
76
77void MavCommandQueue::sendCommandWithHandler(const MavCmdAckHandlerInfo_t* ackHandlerInfo, int compId, MAV_CMD command, float param1, float param2, float param3, float param4, float param5, float param6, float param7)
78{
79 sendWorker(false, // commandInt
80 false, // showError
81 ackHandlerInfo,
82 compId,
83 command,
84 MAV_FRAME_GLOBAL,
85 param1, param2, param3, param4, param5, param6, param7);
86}
87
88void MavCommandQueue::sendCommandIntWithHandler(const MavCmdAckHandlerInfo_t* ackHandlerInfo, int compId, MAV_CMD command, MAV_FRAME frame, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
89{
90 sendWorker(true, // commandInt
91 false, // showError
92 ackHandlerInfo,
93 compId,
94 command,
95 frame,
96 param1, param2, param3, param4, param5, param6, param7);
97}
98
99namespace {
100
101struct LambdaFallbackHandlerData {
102 Vehicle* vehicle;
103 bool showError;
104 std::function<void()> unsupportedLambda;
105};
106
107void lambdaFallbackResultHandler(void* resultHandlerData, int /*compId*/, const mavlink_command_ack_t& ack, VehicleTypes::MavCmdResultFailureCode_t /*failureCode*/)
108{
109 auto* data = static_cast<LambdaFallbackHandlerData*>(resultHandlerData);
110 auto* instanceData = data->vehicle->firmwarePluginInstanceData();
111
112 switch (ack.result) {
113 case MAV_RESULT_ACCEPTED:
114 if (instanceData) {
115 instanceData->setCommandSupported(MAV_CMD(ack.command),
117 }
118 break;
119 case MAV_RESULT_UNSUPPORTED:
120 if (instanceData) {
121 instanceData->setCommandSupported(MAV_CMD(ack.command),
123 }
124 data->unsupportedLambda();
125 break;
126 default:
127 if (data->showError) {
129 }
130 break;
131 }
132
133 delete data;
134}
135
139int32_t commandIntXY(double param, MAV_FRAME frame)
140{
141 if (qIsNaN(param)) {
142 return INT32_MAX;
143 }
144 return static_cast<int32_t>(frame == MAV_FRAME_MISSION ? param : param * 1e7);
145}
146
147} // namespace
148
149void MavCommandQueue::sendCommandWithLambdaFallbackWorker(std::function<void()> lambda, bool commandInt, int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
150{
151 auto* instanceData = _vehicle->firmwarePluginInstanceData();
152 const auto supported = instanceData ? instanceData->getCommandSupported(command)
154
155 switch (supported) {
157 lambda();
158 break;
160 if (commandInt) {
161 sendCommandInt(compId, command, frame, showError, param1, param2, param3, param4, param5, param6,
162 param7);
163 } else {
164 sendCommand(compId, command, showError, param1, param2, param3, param4, param5, param6, param7);
165 }
166 break;
168 auto* data = new LambdaFallbackHandlerData{_vehicle, showError, std::move(lambda)};
169 const MavCmdAckHandlerInfo_t handlerInfo{
170 /* .resultHandler = */ &lambdaFallbackResultHandler,
171 /* .resultHandlerData = */ data,
172 /* .progressHandler = */ nullptr,
173 /* .progressHandlerData = */ nullptr,
174 };
175 if (commandInt) {
176 sendCommandIntWithHandler(&handlerInfo, compId, command, frame, param1, param2, param3, param4, param5,
177 param6, param7);
178 } else {
179 sendCommandWithHandler(&handlerInfo, compId, command, param1, param2, param3, param4, param5, param6,
180 param7);
181 }
182 break;
183 }
184 }
185}
186
187void MavCommandQueue::sendCommandWithLambdaFallback(std::function<void()> lambda, int compId, MAV_CMD command, bool showError, float param1, float param2, float param3, float param4, float param5, float param6, float param7)
188{
189 sendCommandWithLambdaFallbackWorker(std::move(lambda), false /* commandInt */, compId, command, MAV_FRAME_GLOBAL, showError, param1, param2, param3, param4, param5, param6, param7);
190}
191
192void MavCommandQueue::sendCommandIntWithLambdaFallback(std::function<void()> lambda, int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
193{
194 sendCommandWithLambdaFallbackWorker(std::move(lambda), true /* commandInt */, compId, command, frame, showError, param1, param2, param3, param4, param5, param6, param7);
195}
196
197bool MavCommandQueue::isPending(int targetCompId, MAV_CMD command) const
198{
199 return findEntryIndex(targetCompId, command) != -1;
200}
201
202int MavCommandQueue::findEntryIndex(int targetCompId, MAV_CMD command) const
203{
204 for (int i = 0; i < _list.count(); i++) {
205 const MavCommandListEntry_t& entry = _list[i];
206 if (entry.targetCompId == targetCompId && entry.command == command) {
207 return i;
208 }
209 }
210 return -1;
211}
212
213int MavCommandQueue::_responseCheckIntervalMSecs()
214{
215 // Use shorter check interval during unit tests for faster test execution
216 return QGC::runningUnitTests() ? 50 : 500;
217}
218
219int MavCommandQueue::_ackTimeoutMSecs()
220{
221 return _testAckTimeoutOverride.value_or(_ackTimeoutMSecsDefault);
222}
223
224void MavCommandQueue::setTestAckTimeoutOverride(std::optional<int> msecs)
225{
226 if (!QGC::runningUnitTests()) {
227 qCWarning(MavCommandQueueLog) << "setTestAckTimeoutOverride called outside unit tests, ignoring";
228 return;
229 }
230 if (msecs.has_value() && *msecs <= 0) {
231 qCWarning(MavCommandQueueLog) << "setTestAckTimeoutOverride rejecting non-positive timeout:" << *msecs;
232 return;
233 }
234 _testAckTimeoutOverride = msecs;
235}
236
238{
239 return _testAckTimeoutOverride;
240}
241
242bool MavCommandQueue::_shouldRetry(MAV_CMD command)
243{
244 switch (command) {
245#ifdef QT_DEBUG
246 // These MockLink commands should be retried so we can create unit tests to test retry code
252 return true;
253#endif
254
255 // In general we should not retry any commands. This is for safety reasons. For example you don't want an ARM command
256 // to timeout with no response over a noisy link twice and then suddenly have the third try work 6 seconds later. At that
257 // point the user could have walked up to the vehicle to see what is going wrong.
258 //
259 // We do retry commands which are part of the initial vehicle connect sequence. This makes this process work better over noisy
260 // links where commands could be lost. Also these commands tend to just be requesting status so if they end up being delayed
261 // there are no safety concerns that could occur.
262 case MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES:
263 case MAV_CMD_REQUEST_MESSAGE:
264 case MAV_CMD_PREFLIGHT_STORAGE:
265 case MAV_CMD_RUN_PREARM_CHECKS:
266 return true;
267
268 default:
269 return false;
270 }
271}
272
273bool MavCommandQueue::_canBeDuplicated(MAV_CMD command)
274{
275 // For some commands we don't care about response as much as we care about sending them regularly.
276 // This test avoids commands not being sent due to an ACK not being received yet.
277 // MOTOR_TEST in ardusub is a case where we need a constant stream of commands so it doesn't time out.
278 switch (command) {
279 case MAV_CMD_DO_MOTOR_TEST:
280 case MAV_CMD_SET_MESSAGE_INTERVAL:
281 return true;
282 default:
283 return false;
284 }
285}
286
287QString MavCommandQueue::_formatCommand(MAV_CMD command, float param1)
288{
289 QString rawName = MissionCommandTree::instance()->rawName(command);
290 QString friendlyName = MissionCommandTree::instance()->friendlyName(command);
291 QString commandStr = friendlyName.isEmpty() ? rawName : QStringLiteral("%1 (%2)").arg(friendlyName, rawName);
292
293 if (command == MAV_CMD_REQUEST_MESSAGE || command == MAV_CMD_SET_MESSAGE_INTERVAL) {
294 const mavlink_message_info_t* info = MAVLinkMessageInfo::byId(static_cast<int>(param1));
295 if (info) {
296 commandStr += QStringLiteral(" [%1]").arg(info->name);
297 }
298 }
299
300 return commandStr;
301}
302
303void MavCommandQueue::sendWorker(bool commandInt, bool showError,
304 const MavCmdAckHandlerInfo_t* ackHandlerInfo,
305 int targetCompId, MAV_CMD command, MAV_FRAME frame,
306 float param1, float param2, float param3, float param4, double param5, double param6, float param7)
307{
308 if (_stopped) {
309 return;
310 }
311
312 // We can't send commands to compIdAll using this method. The reason being that we would get responses back possibly from multiple components
313 // which this code can't handle.
314 // We also can't send the majority of commands again if we are already waiting for a response from that same command. If we did that we would not be able to discern
315 // which ack was associated with which command.
316 if ((targetCompId == MAV_COMP_ID_ALL) || (isPending(targetCompId, command) && !_canBeDuplicated(command))) {
317 bool compIdAll = targetCompId == MAV_COMP_ID_ALL;
318 QString rawCommandName = MissionCommandTree::instance()->rawName(command);
319
320 qCDebug(MavCommandQueueLog) << QStringLiteral("sendWorker failing %1").arg(compIdAll ? "MAV_COMP_ID_ALL not supported" : "duplicate command") << rawCommandName << param1 << param2 << param3 << param4 << param5 << param6 << param7;
321
323 if (ackHandlerInfo && ackHandlerInfo->resultHandler) {
324 mavlink_command_ack_t ack = {};
325 ack.result = MAV_RESULT_FAILED;
326 (*ackHandlerInfo->resultHandler)(ackHandlerInfo->resultHandlerData, targetCompId, ack, failureCode);
327 } else {
328 emit commandResult(_vehicle->id(), targetCompId, command, MAV_RESULT_FAILED, failureCode);
329 }
330 if (showError) {
331 QGC::showAppMessage(tr("Unable to send command: %1.").arg(compIdAll ? tr("Internal error - MAV_COMP_ID_ALL not supported") : tr("Waiting on previous response to same command.")));
332 }
333 return;
334 }
335
336 SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
337 if (!sharedLink) {
338 qCDebug(MavCommandQueueLog) << "sendWorker: primary link gone!";
339
341 if (ackHandlerInfo && ackHandlerInfo->resultHandler) {
342 mavlink_command_ack_t ack = {};
343 ack.command = command;
344 ack.result = MAV_RESULT_FAILED;
345 (*ackHandlerInfo->resultHandler)(ackHandlerInfo->resultHandlerData, targetCompId, ack, failureCode);
346 } else {
347 emit commandResult(_vehicle->id(), targetCompId, command, MAV_RESULT_FAILED, failureCode);
348 }
349
350 if (showError) {
351 QGC::showAppMessage(tr("Unable to send command: Vehicle is not connected."));
352 }
353 return;
354 }
355
356 MavCommandListEntry_t entry;
357 entry.useCommandInt = commandInt;
358 entry.targetCompId = targetCompId;
359 entry.command = command;
360 entry.frame = frame;
361 entry.showError = showError;
362 entry.ackHandlerInfo = {};
363 if (ackHandlerInfo) {
364 entry.ackHandlerInfo = *ackHandlerInfo;
365 }
366 entry.rgParam1 = param1;
367 entry.rgParam2 = param2;
368 entry.rgParam3 = param3;
369 entry.rgParam4 = param4;
370 entry.rgParam5 = param5;
371 entry.rgParam6 = param6;
372 entry.rgParam7 = param7;
373 entry.maxTries = _shouldRetry(command) ? kMaxRetryCount : 1;
374 entry.ackTimeoutMSecs = sharedLink->linkConfiguration()->isHighLatency() ? _ackTimeoutMSecsHighLatency : _ackTimeoutMSecs();
375 entry.elapsedTimer.start();
376
377 qCDebug(MavCommandQueueLog) << "Sending" << _formatCommand(command, param1) << "param1-7:" << command << param1 << param2 << param3 << param4 << param5 << param6 << param7;
378
379 _list.append(entry);
380 _sendFromList(_list.count() - 1);
381}
382
383void MavCommandQueue::_sendFromList(int index)
384{
385 MavCommandListEntry_t commandEntry = _list[index];
386
387 QString rawCommandName = MissionCommandTree::instance()->rawName(commandEntry.command);
388 QString friendlyName = MissionCommandTree::instance()->friendlyName(commandEntry.command);
389
390 if (++_list[index].tryCount > commandEntry.maxTries) {
391 QString logMsg = QStringLiteral("Giving up sending command after max retries: %1").arg(rawCommandName);
392
393 // These commands identify their target message in param1.
394 if (commandEntry.command == MAV_CMD_REQUEST_MESSAGE || commandEntry.command == MAV_CMD_SET_MESSAGE_INTERVAL) {
395 int requestedMsgId = static_cast<int>(commandEntry.rgParam1);
396 const mavlink_message_info_t* info = MAVLinkMessageInfo::byId(requestedMsgId);
397 logMsg += QStringLiteral(" message: %1").arg(info ? info->name : QString::number(requestedMsgId));
398 }
399
400 qCWarning(MavCommandQueueLog) << logMsg;
401
402 _list.removeAt(index);
403 if (commandEntry.ackHandlerInfo.resultHandler) {
404 mavlink_command_ack_t ack = {};
405 ack.result = MAV_RESULT_FAILED;
406 (*commandEntry.ackHandlerInfo.resultHandler)(commandEntry.ackHandlerInfo.resultHandlerData, commandEntry.targetCompId, ack, MavCmdResultFailureNoResponseToCommand);
407 } else {
408 emit commandResult(_vehicle->id(), commandEntry.targetCompId, commandEntry.command, MAV_RESULT_FAILED, MavCmdResultFailureNoResponseToCommand);
409 }
410 if (commandEntry.showError) {
411 QGC::showAppMessage(tr("Vehicle did not respond to command: %1").arg(friendlyName));
412 }
413 return;
414 }
415
416 if (commandEntry.tryCount > 1 && !_vehicle->px4Firmware() && commandEntry.command == MAV_CMD_START_RX_PAIR) {
417 // The implementation of this command comes from the IO layer and is shared across stacks. So for other firmwares
418 // we aren't really sure whether they are correct or not.
419 return;
420 }
421
422 qCDebug(MavCommandQueueLog) << "Sending" << _formatCommand(commandEntry.command, commandEntry.rgParam1)
423 << "tryCount:param1-7" << commandEntry.tryCount << commandEntry.rgParam1 << commandEntry.rgParam2 << commandEntry.rgParam3 << commandEntry.rgParam4 << commandEntry.rgParam5 << commandEntry.rgParam6 << commandEntry.rgParam7;
424
425 SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
426 if (!sharedLink) {
427 qCDebug(MavCommandQueueLog) << "_sendFromList: primary link gone!";
428 return;
429 }
430
431 mavlink_message_t msg{};
432
433 if (commandEntry.useCommandInt) {
434 mavlink_command_int_t cmd;
435 memset(&cmd, 0, sizeof(cmd));
436 cmd.target_component = commandEntry.targetCompId;
437 cmd.command = commandEntry.command;
438 cmd.frame = commandEntry.frame;
439 cmd.param1 = commandEntry.rgParam1;
440 cmd.param2 = commandEntry.rgParam2;
441 cmd.param3 = commandEntry.rgParam3;
442 cmd.param4 = commandEntry.rgParam4;
443 cmd.x = commandIntXY(commandEntry.rgParam5, commandEntry.frame);
444 cmd.y = commandIntXY(commandEntry.rgParam6, commandEntry.frame);
445 cmd.z = commandEntry.rgParam7;
446 mavlink_msg_command_int_pack_chan(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::getComponentId(),
447 sharedLink->mavlinkChannel(), &msg, _vehicle->id(), cmd.target_component,
448 cmd.frame, cmd.command, cmd.current, cmd.autocontinue, cmd.param1, cmd.param2,
449 cmd.param3, cmd.param4, cmd.x, cmd.y, cmd.z);
450 } else {
452 memset(&cmd, 0, sizeof(cmd));
453 cmd.target_component = commandEntry.targetCompId;
454 cmd.command = commandEntry.command;
455 // MAVLink spec: confirmation increments on each resend.
456 cmd.confirmation = static_cast<uint8_t>(qMin(commandEntry.tryCount - 1, 255));
457 cmd.param1 = commandEntry.rgParam1;
458 cmd.param2 = commandEntry.rgParam2;
459 cmd.param3 = commandEntry.rgParam3;
460 cmd.param4 = commandEntry.rgParam4;
461 cmd.param5 = static_cast<float>(commandEntry.rgParam5);
462 cmd.param6 = static_cast<float>(commandEntry.rgParam6);
463 cmd.param7 = commandEntry.rgParam7;
464 mavlink_msg_command_long_pack_chan(
465 MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::getComponentId(), sharedLink->mavlinkChannel(),
466 &msg, _vehicle->id(), cmd.target_component, cmd.command, cmd.confirmation, cmd.param1, cmd.param2,
467 cmd.param3, cmd.param4, cmd.param5, cmd.param6, cmd.param7);
468 }
469
470 _vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), msg);
471}
472
473void MavCommandQueue::_responseTimeoutCheck()
474{
475 if (_list.isEmpty()) {
476 return;
477 }
478
479 // Walk the list backwards since _sendFromList can remove entries. Give-up result
480 // handlers invoked from _sendFromList can also re-enter the queue and remove or
481 // clear entries (e.g. closing the vehicle from within the callback), so re-validate
482 // the stop flag and index on every iteration.
483 for (int i = _list.count() - 1; i >= 0; i--) {
484 if (_stopped) {
485 return;
486 }
487 if (i >= _list.count()) {
488 i = _list.count(); // Handler removed entries below us, clamp (loop decrement follows)
489 continue;
490 }
491 MavCommandListEntry_t& commandEntry = _list[i];
492 if (commandEntry.elapsedTimer.elapsed() > commandEntry.ackTimeoutMSecs) {
493 // Try sending command again
494 _sendFromList(i);
495 }
496 }
497}
498
500{
501 QString rawName = MissionCommandTree::instance()->rawName(static_cast<MAV_CMD>(ack.command));
502 QString friendlyName = MissionCommandTree::instance()->friendlyName(static_cast<MAV_CMD>(ack.command));
503 QString commandStr = friendlyName.isEmpty() ? rawName : QStringLiteral("%1 (%2)").arg(friendlyName, rawName);
504
505 switch (ack.result) {
506 case MAV_RESULT_TEMPORARILY_REJECTED:
507 QGC::showAppMessage(tr("%1 command temporarily rejected").arg(commandStr));
508 break;
509 case MAV_RESULT_DENIED:
510 QGC::showAppMessage(tr("%1 command denied").arg(commandStr));
511 break;
512 case MAV_RESULT_UNSUPPORTED:
513 QGC::showAppMessage(tr("%1 command not supported").arg(commandStr));
514 break;
515 case MAV_RESULT_FAILED:
516 QGC::showAppMessage(tr("%1 command failed").arg(commandStr));
517 break;
518 default:
519 // Do nothing
520 break;
521 }
522}
523
525{
526 int entryIndex = findEntryIndex(message.compid, static_cast<MAV_CMD>(ack.command));
527 if (entryIndex == -1) {
528 QString rawCommandName = MissionCommandTree::instance()->rawName(static_cast<MAV_CMD>(ack.command));
529 qCDebug(MavCommandQueueLog) << "handleCommandAck Ack not in list" << rawCommandName;
530 return;
531 }
532
533 if (ack.result == MAV_RESULT_IN_PROGRESS) {
534 MavCommandListEntry_t commandEntry;
535 if (_vehicle->px4Firmware() && ack.command == MAV_CMD_DO_AUTOTUNE_ENABLE) {
536 // Hack to support PX4 autotune which does not send final result ack and just sends in progress
537 commandEntry = _list.takeAt(entryIndex);
538 } else {
539 // Command has not completed yet, don't remove
540 MavCommandListEntry_t& commandEntryRef = _list[entryIndex];
541 commandEntryRef.maxTries = 1; // Vehicle responded to command so don't retry
542 commandEntryRef.elapsedTimer.start(); // We've heard from vehicle, restart elapsed timer for no ack received timeout
543 commandEntry = commandEntryRef;
544 }
545
546 if (commandEntry.ackHandlerInfo.progressHandler) {
547 (*commandEntry.ackHandlerInfo.progressHandler)(commandEntry.ackHandlerInfo.progressHandlerData, message.compid, ack);
548 }
549 return;
550 }
551
552 MavCommandListEntry_t commandEntry = _list.takeAt(entryIndex);
553 if (commandEntry.ackHandlerInfo.resultHandler) {
554 (*commandEntry.ackHandlerInfo.resultHandler)(commandEntry.ackHandlerInfo.resultHandlerData, message.compid, ack, MavCmdResultCommandResultOnly);
555 } else {
556 if (commandEntry.showError) {
558 }
559 emit commandResult(_vehicle->id(), message.compid, ack.command, ack.result, MavCmdResultCommandResultOnly);
560 }
561}
562
564{
565 switch (failureCode) {
567 return QStringLiteral("Command Result Only");
569 return QStringLiteral("No Response To Command");
571 return QStringLiteral("Duplicate Command");
572 default:
573 return QStringLiteral("Unknown (%1)").arg(failureCode);
574 }
575}
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
struct __mavlink_message mavlink_message_t
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_command_ack_t mavlink_command_ack_t
struct __mavlink_command_long_t mavlink_command_long_t
CommandSupportedResult getCommandSupported(MAV_CMD cmd) const
static int getComponentId()
static MAVLinkProtocol * instance()
Owns the COMMAND_LONG / COMMAND_INT send/retry/ack pipeline for a single Vehicle.
void sendCommandInt(int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
static QString failureCodeToString(MavCmdResultFailureCode_t failureCode)
void sendCommandIntWithHandler(const MavCmdAckHandlerInfo_t *ackHandlerInfo, int compId, MAV_CMD command, MAV_FRAME frame, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, double param5=0.0, double param6=0.0, float param7=0.0f)
static std::optional< int > testAckTimeoutOverride()
void sendCommandWithHandler(const MavCmdAckHandlerInfo_t *ackHandlerInfo, int compId, MAV_CMD command, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
static constexpr int kMaxRetryCount
static void setTestAckTimeoutOverride(std::optional< int > msecs)
void sendWorker(bool commandInt, bool showError, const MavCmdAckHandlerInfo_t *ackHandlerInfo, int compId, MAV_CMD command, MAV_FRAME frame, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
void handleCommandAck(const mavlink_message_t &message, const mavlink_command_ack_t &ack)
Process a COMMAND_ACK — match it to a pending entry and fire callbacks.
void sendCommandDelayed(int compId, MAV_CMD command, bool showError, int milliseconds, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
void commandResult(quint32 vehicleId, int targetComponent, int command, int ackResult, int failureCode)
Emitted for every terminal ack that has no user-provided resultHandler.
bool isPending(int targetCompId, MAV_CMD command) const
True if a matching (targetCompId, command) is already queued or awaiting ack.
static void showCommandAckError(const mavlink_command_ack_t &ack)
MavCommandQueue(Vehicle *vehicle)
void sendCommand(int compId, MAV_CMD command, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
int findEntryIndex(int targetCompId, MAV_CMD command) const
Index of a matching entry in the pending queue, or -1. Exposed for test use.
void sendCommandIntWithLambdaFallback(std::function< void()> lambda, int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, double param5=0.0, double param6=0.0, float param7=0.0f)
void sendCommandWithLambdaFallback(std::function< void()> lambda, int compId, MAV_CMD command, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
static MissionCommandTree * instance()
QString rawName(MAV_CMD command) const
Returns the raw name for the specified command.
QString friendlyName(MAV_CMD command) const
Returns the friendly name for the specified command.
class FirmwarePluginInstanceData * firmwarePluginInstanceData()
Definition Vehicle.h:720
const mavlink_message_info_t * byId(uint32_t msgId)
Returns nullptr if the dialect has no message with this id.
std::optional< Frame > frame(std::string_view text)
bool runningUnitTests()
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9
void * progressHandlerData
nullptr for no handler
MavCmdProgressHandler progressHandler
MavCmdResultHandler resultHandler
nullptr for no handler
struct VehicleTypes::MavCmdAckHandlerInfo_s MavCmdAckHandlerInfo_t
Callback info bundle for sendMavCommandWithHandler.
@ MavCmdResultFailureDuplicateCommand
Unable to send command since duplicate is already being waited on for response.
@ MavCmdResultCommandResultOnly
commandResult specifies full success/fail info
@ MavCmdResultFailureNoResponseToCommand
No response from vehicle to command.