QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RequestMetaDataTypeStateMachine.h
Go to the documentation of this file.
1#pragma once
2
3#include "QGCStateMachine.h"
4#include "MAVLinkEnums.h"
6#include "VehicleTypes.h"
7
8#include <QtCore/QElapsedTimer>
9class Vehicle;
11class CompInfo;
15class QGCState;
16
18{
19 Q_OBJECT
20
21public:
22 explicit RequestMetaDataTypeStateMachine(ComponentInformationManager* compMgr, QObject* parent = nullptr);
24
26 QString typeToString() const;
27 CompInfo* compInfo() const { return _compInfo; }
28 ComponentInformationManager* compMgr() const { return _compMgr; }
29
30signals:
32
33private:
34 void _createStates();
35 void _wireTransitions();
36 void _wireTimeoutHandling();
37
38 // State entry/action functions
39 void _requestCompInfo();
40 void _requestCompInfoDeprecated();
41 void _requestMetaDataJson();
42 void _requestMetaDataJsonFallback();
43 void _requestTranslationJson();
44 void _requestTranslate();
45 void _completeRequest();
46
47 // Skip predicates
48 bool _shouldSkipCompInfoRequest() const;
49 bool _shouldSkipDeprecatedRequest() const;
50 bool _shouldSkipFallback() const;
51 bool _shouldSkipTranslation() const;
52
53 // Download helpers
54 void _requestFile(const QString& cacheFileTag, bool crcValid, const QString& uri, QString& outputFileName, bool trackMetadataSource);
55 QString _downloadCompleteJsonWorker(const QString& jsonFileName);
56 static bool _uriIsMAVLinkFTP(const QString& uri);
57
58 enum class MetadataSource {
59 None,
60 Cache,
61 FTP,
62 HTTP,
63 };
64 static const char* _metadataSourceToString(MetadataSource source);
65
66 // Message result handlers
67 void _handleCompMetadataResult(MAV_RESULT result, const mavlink_message_t& message);
68 void _handleCompInfoResult(MAV_RESULT result, VehicleTypes::RequestMessageResultHandlerFailureCode_t failureCode, const mavlink_message_t& message);
69
70private slots:
71 void _ftpDownloadComplete(const QString& file, const QString& errorMsg);
72 void _ftpDownloadProgress(float progress);
73 void _httpDownloadComplete(bool success, const QString& localFile, const QString& errorMsg, bool fromCache);
74 void _downloadAndTranslationComplete(QString translatedJsonTempFile, QString errorMsg);
75
76private:
77 ComponentInformationManager* _compMgr = nullptr;
78 CompInfo* _compInfo = nullptr;
79
80 // Download state
81 QString _jsonMetadataFileName;
82 QString _jsonMetadataTranslatedFileName;
83 bool _jsonMetadataCrcValid = false;
84 QString _jsonTranslationFileName;
85
86 QString* _currentFileName = nullptr;
87 QString _currentCacheFileTag;
88 bool _currentFileValidCrc = false;
89
90 QElapsedTimer _downloadStartTime;
91 MetadataSource _metadataSource = MetadataSource::None;
92 QString _metadataUri;
93 bool _metadataIsFallback = false;
94
95 // State pointers
96 AsyncFunctionState* _stateRequestCompInfo = nullptr;
97 SkippableAsyncState* _stateRequestDeprecated = nullptr;
98 AsyncFunctionState* _stateRequestMetaDataJson = nullptr;
99 SkippableAsyncState* _stateRequestMetaDataJsonFallback = nullptr;
100 AsyncFunctionState* _stateRequestTranslationJson = nullptr;
101 SkippableAsyncState* _stateRequestTranslate = nullptr;
102 QGCState* _stateComplete = nullptr;
103 QGCFinalState* _stateFinal = nullptr;
104
105 // Track active download state for completion
106 AsyncFunctionState* _activeAsyncState = nullptr;
107 SkippableAsyncState* _activeSkippableState = nullptr;
108
109 // Timeout values (ms)
110 static constexpr int _timeoutCompInfoRequest = 5000;
111 static constexpr int _timeoutMetaDataDownload = 30000;
112 static constexpr int _timeoutTranslation = 15000;
113};
struct __mavlink_message mavlink_message_t
Calls a function when entered and waits for an external trigger to advance.
Base class for all CompInfo types.
Definition CompInfo.h:15
A state that evaluates a predicate on entry and either executes or skips.
Final state for a QGCStateMachine with logging support.
QGroundControl specific state machine with enhanced error handling.
float progress() const
Get the current overall progress (0.0 to 1.0)
Full-featured base class for QGroundControl state machine states.
Definition QGCState.h:23
ComponentInformationManager * compMgr() const
Combines skip condition checking with async operation setup in a single state.
RequestMessageResultHandlerFailureCode_t