QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MavCommandQueue.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5#include <QtCore/QElapsedTimer>
6#include <QtCore/QList>
7#include <QtCore/QObject>
8#include <QtCore/QTimer>
9
10#include "VehicleTypes.h"
11
12class Vehicle;
13
21class MavCommandQueue : public QObject, public VehicleTypes
22{
23 Q_OBJECT
24
25public:
26 explicit MavCommandQueue(Vehicle* vehicle);
28
29 // Public send API — mirrors Vehicle's historical sendMavCommand* surface.
30 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);
31 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);
32 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);
33
34 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);
35 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);
36
37 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);
38 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);
39
43 void sendWorker(bool commandInt, bool showError, const MavCmdAckHandlerInfo_t* ackHandlerInfo,
44 int compId, MAV_CMD command, MAV_FRAME frame,
45 float param1, float param2, float param3, float param4, double param5, double param6, float param7);
46
48 bool isPending(int targetCompId, MAV_CMD command) const;
49
51 int findEntryIndex(int targetCompId, MAV_CMD command) const;
52
54 void handleCommandAck(const mavlink_message_t& message, const mavlink_command_ack_t& ack);
55
58 void stop();
59
60 static QString failureCodeToString(MavCmdResultFailureCode_t failureCode);
61 static void showCommandAckError(const mavlink_command_ack_t& ack);
62
63 // Test tuning knobs.
64 static constexpr int kTestAckTimeoutMs = 500;
65 static constexpr int kMaxRetryCount = 3;
66 static constexpr int kTestMaxWaitMs = kTestAckTimeoutMs * kMaxRetryCount * 2;
67
68signals:
70 void commandResult(int vehicleId, int targetComponent, int command, int ackResult, int failureCode);
71
72private slots:
73 void _responseTimeoutCheck();
74
75private:
76 typedef struct MavCommandListEntry {
77 int targetCompId = 0;
78 bool useCommandInt = false;
79 MAV_CMD command;
80 MAV_FRAME frame;
81 float rgParam1 = 0;
82 float rgParam2 = 0;
83 float rgParam3 = 0;
84 float rgParam4 = 0;
85 double rgParam5 = 0;
86 double rgParam6 = 0;
87 float rgParam7 = 0;
88 bool showError = true;
89 MavCmdAckHandlerInfo_t ackHandlerInfo;
90 int maxTries = kMaxRetryCount;
91 int tryCount = 0;
92 QElapsedTimer elapsedTimer;
93 int ackTimeoutMSecs = 0;
94 } MavCommandListEntry_t;
95
96 void 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);
97
98 void _sendFromList(int index);
99 static bool _shouldRetry(MAV_CMD command);
100 static bool _canBeDuplicated(MAV_CMD command);
101 static int _responseCheckIntervalMSecs();
102 static int _ackTimeoutMSecs();
103 static QString _formatCommand(MAV_CMD command, float param1);
104
105 Vehicle* _vehicle = nullptr;
106 QList<MavCommandListEntry_t> _list;
107 QTimer _responseCheckTimer;
108 bool _stopped = false; // set by stop(), gates all send paths
109
110 static constexpr int _ackTimeoutMSecsHighLatency = 120000;
111};
struct __mavlink_message mavlink_message_t
struct __mavlink_command_ack_t mavlink_command_ack_t
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)
static constexpr int kTestAckTimeoutMs
void commandResult(int vehicleId, int targetComponent, int command, int ackResult, int failureCode)
Emitted for every terminal ack that has no user-provided resultHandler.
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 constexpr int kTestMaxWaitMs
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
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)
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)
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)
Callback info bundle for sendMavCommandWithHandler.