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
42 void sendWorker(bool commandInt, bool showError, const MavCmdAckHandlerInfo_t* ackHandlerInfo,
43 int compId, MAV_CMD command, MAV_FRAME frame,
44 float param1, float param2, float param3, float param4, double param5, double param6, float param7);
45
47 bool isPending(int targetCompId, MAV_CMD command) const;
48
50 int findEntryIndex(int targetCompId, MAV_CMD command) const;
51
53 void handleCommandAck(const mavlink_message_t& message, const mavlink_command_ack_t& ack);
54
57 void stop();
58
59 static QString failureCodeToString(MavCmdResultFailureCode_t failureCode);
60 static void showCommandAckError(const mavlink_command_ack_t& ack);
61
62 // Test tuning knobs.
63 static constexpr int kTestAckTimeoutMs = 500;
64 static constexpr int kMaxRetryCount = 3;
65 static constexpr int kTestMaxWaitMs = kTestAckTimeoutMs * kMaxRetryCount * 2;
66
67signals:
69 void commandResult(int vehicleId, int targetComponent, int command, int ackResult, int failureCode);
70
71private slots:
72 void _responseTimeoutCheck();
73
74private:
75 typedef struct MavCommandListEntry {
76 int targetCompId = 0;
77 bool useCommandInt = false;
78 MAV_CMD command;
79 MAV_FRAME frame;
80 float rgParam1 = 0;
81 float rgParam2 = 0;
82 float rgParam3 = 0;
83 float rgParam4 = 0;
84 double rgParam5 = 0;
85 double rgParam6 = 0;
86 float rgParam7 = 0;
87 bool showError = true;
88 MavCmdAckHandlerInfo_t ackHandlerInfo;
89 int maxTries = kMaxRetryCount;
90 int tryCount = 0;
91 QElapsedTimer elapsedTimer;
92 int ackTimeoutMSecs = 0;
93 } MavCommandListEntry_t;
94
95 void _sendFromList(int index);
96 static bool _shouldRetry(MAV_CMD command);
97 static bool _canBeDuplicated(MAV_CMD command);
98 static int _responseCheckIntervalMSecs();
99 static int _ackTimeoutMSecs();
100 static QString _formatCommand(MAV_CMD command, float param1);
101
102 Vehicle* _vehicle = nullptr;
103 QList<MavCommandListEntry_t> _list;
104 QTimer _responseCheckTimer;
105 bool _stopped = false; // set by stop(), gates all send paths
106
107 static constexpr int _ackTimeoutMSecsHighLatency = 120000;
108};
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 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.