QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FirmwareUpgradeController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtCore/QPointer>
5#include <QtCore/QTimer>
6#include <QtGui/QPixmap>
7#include <QtQmlIntegration/QtQmlIntegration>
8#include <QtQuick/QQuickItem>
9
10#include "QGCSerialPortInfo.h"
11
12class QGCFileDownload;
13
14class PX4FirmwareUpgradeThread;
16class FirmwareImage;
17class Fact;
18
20
21// Firmware Upgrade MVC Controller for FirmwareUpgrade.qml.
22class FirmwareUpgradeController : public QObject
23{
24 Q_OBJECT
25 QML_ELEMENT
26#ifdef QGC_UNITTEST_BUILD
27 friend class FirmwareUpgradeControllerTest; // Unit test
28#endif
29public:
36
43
52
56
58 {
59 public:
63 : autopilotStackType(stack), firmwareType(firmware), firmwareVehicleType(vehicle) {}
64
65 bool operator==(const FirmwareIdentifier& firmwareId) const
66 {
67 return (firmwareId.autopilotStackType == autopilotStackType &&
68 firmwareId.firmwareType == firmwareType &&
69 firmwareId.firmwareVehicleType == firmwareVehicleType);
70 }
71
72 // members
76 };
77
80
81 Q_PROPERTY(bool downloadingFirmwareList MEMBER _downloadingFirmwareList NOTIFY downloadingFirmwareListChanged)
82 Q_PROPERTY(QString boardPort READ boardPort NOTIFY boardFound)
83 Q_PROPERTY(QString boardDescription READ boardDescription NOTIFY boardFound)
84 Q_PROPERTY(QString boardType MEMBER _boardTypeName NOTIFY boardFound)
85 Q_PROPERTY(bool pixhawkBoard READ pixhawkBoard NOTIFY boardFound)
87 Q_PROPERTY(QStringList apmFirmwareNames MEMBER _apmFirmwareNames NOTIFY apmFirmwareNamesChanged)
88 Q_PROPERTY(int apmFirmwareNamesBestIndex MEMBER _apmFirmwareNamesBestIndex NOTIFY apmFirmwareNamesChanged)
89 Q_PROPERTY(QStringList apmFirmwareUrls MEMBER _apmFirmwareUrls NOTIFY apmFirmwareNamesChanged)
90 Q_PROPERTY(QString px4StableVersion READ px4StableVersion NOTIFY px4StableVersionChanged)
91 Q_PROPERTY(QString px4BetaVersion READ px4BetaVersion NOTIFY px4BetaVersionChanged)
92 Q_PROPERTY(QVariantList availablePorts MEMBER _availablePorts NOTIFY availablePortsChanged)
93
94
95 Q_PROPERTY(QQuickItem* statusLog READ statusLog WRITE setStatusLog)
96
97
98 Q_PROPERTY(QQuickItem* progressBar READ progressBar WRITE setProgressBar)
99
100
101 Q_INVOKABLE void startBoardSearch(void);
102
104 Q_INVOKABLE void flashPort(const QString& systemLocation);
105
107 Q_INVOKABLE void cancel(void);
108
110 Q_INVOKABLE void flash(AutoPilotStackType_t stackType,
111 FirmwareBuildType_t firmwareType = StableFirmware,
113
114 Q_INVOKABLE void flashFirmwareUrl(QString firmwareUrl);
115
117 Q_INVOKABLE void flashSingleFirmwareMode(FirmwareBuildType_t firmwareType);
118
120
121 // overload, not exposed to qml side
122 void flash(const FirmwareIdentifier& firmwareId);
123
124 // Property accessors
125
126 QQuickItem* progressBar(void) { return _progressBar; }
127 void setProgressBar(QQuickItem* progressBar) { _progressBar = progressBar; }
128
129 QQuickItem* statusLog(void) { return _statusLog; }
130 void setStatusLog(QQuickItem* statusLog) { _statusLog = statusLog; }
131
132 QString boardPort(void) { return _boardInfo.portName(); }
133 QString boardDescription(void) { return _boardInfo.description(); }
134
135 FirmwareBuildType_t selectedFirmwareBuildType(void) { return _selectedFirmwareBuildType; }
137 QString firmwareTypeAsString(FirmwareBuildType_t type) const;
138
139 QString px4StableVersion (void) { return _px4StableVersion; }
140 QString px4BetaVersion (void) { return _px4BetaVersion; }
141
142 bool pixhawkBoard(void) const { return _boardType == QGCSerialPortInfo::BoardTypePixhawk; }
143
149 Q_INVOKABLE QStringList availableBoardsName(void);
150
151signals:
152 void boardFound (void);
154 void noBoardFound (void);
155 void boardGone (void);
156 void flashComplete (void);
157 void flashCancelled (void);
158 void error (void);
159 void eraseStarted (void);
164 void downloadingFirmwareListChanged (bool downloadingFirmwareList);
166
167private slots:
168 void _firmwareDownloadProgress (qint64 curr, qint64 total);
169 void _firmwareDownloadComplete (bool success, const QString &localFile, const QString &errorMsg);
170 void _foundBoard (bool firstAttempt, const QSerialPortInfo& portInfo, int boardType, QString boardName);
171 void _noBoardFound (void);
172 void _boardGone (void);
173 void _foundBoardInfo (int bootloaderVersion, int boardID, int flashSize);
174 void _error (const QString& errorString);
175 void _status (const QString& statusString);
176 void _bootloaderSyncFailed (void);
177 void _flashComplete (void);
178 void _updateProgress (int curr, int total);
179 void _eraseStarted (void);
180 void _eraseComplete (void);
181 void _eraseProgressTick (void);
182 void _px4ReleasesGithubDownloadComplete (bool success, const QString &localFile, const QString &errorMsg);
183 void _ardupilotManifestDownloadComplete (bool success, const QString &localFile, const QString &errorMsg);
184 void _buildAPMFirmwareNames (void);
185 void _portsAvailable (const QVariantList& ports);
186
187private:
188 QHash<FirmwareIdentifier, QString>* _firmwareHashForBoardId(int boardId);
189 void _getFirmwareFile (FirmwareIdentifier firmwareId);
190 void _downloadFirmware (void);
191 void _appendStatusLog (const QString& text, bool critical = false);
192 void _errorCancel (const QString& msg);
193 void _determinePX4StableVersion (void);
194 void _downloadArduPilotManifest (void);
195
196 QString _singleFirmwareURL;
197 bool _singleFirmwareMode;
198 bool _downloadingFirmwareList;
199 QString _portName;
200 QString _portDescription;
201
202 // Firmware hashes
203 QHash<FirmwareIdentifier, QString> _rgSiKRadioFirmware;
204
205 // Hash map for ArduPilot ChibiOS lookup by board name
206 QHash<FirmwareIdentifier, QString> _rgAPMChibiosReplaceNamedBoardFirmware;
207 QHash<FirmwareIdentifier, QString> _rgFirmwareDynamic;
208
209 QMap<FirmwareBuildType_t, QMap<FirmwareVehicleType_t, QString> > _apmVersionMap;
210 QList<FirmwareVehicleType_t> _apmVehicleTypeFromCurrentVersionList;
211
213 bool _bootloaderFound;
214 uint32_t _bootloaderVersion;
215 uint32_t _bootloaderBoardID;
216 uint32_t _bootloaderBoardFlashSize;
217
218 bool _startFlashWhenBootloaderFound;
219 FirmwareIdentifier _startFlashWhenBootloaderFoundFirmwareIdentity;
220
221 QPixmap _boardIcon;
222
223 QString _firmwareFilename;
224
226 PX4FirmwareUpgradeThreadController* _threadController;
227
228 static const int _eraseTickMsec = 500;
229 static const int _eraseTotalMsec = 15000;
230 int _eraseTickCount;
231 QTimer _eraseTimer;
232
233 static const int _findBoardTimeoutMsec = 30000;
234 static const int _findBootloaderTimeoutMsec = 5000;
235
236 QQuickItem* _statusLog;
237 QQuickItem* _progressBar;
238
239 bool _searchingForBoard;
240
241 QSerialPortInfo _boardInfo;
243 QString _boardTypeName;
244
245 FirmwareBuildType_t _selectedFirmwareBuildType;
246
247 FirmwareImage* _image;
248
249 QString _px4StableVersion; // Version strange for latest PX4 stable
250 QString _px4BetaVersion; // Version strange for latest PX4 beta
251
252 const QString _apmBoardDescriptionReplaceText;
253
254 static constexpr const char* _manifestFirmwareJsonKey = "firmware";
255 static constexpr const char* _manifestBoardIdJsonKey = "board_id";
256 static constexpr const char* _manifestMavTypeJsonKey = "mav-type";
257 static constexpr const char* _manifestFormatJsonKey = "format";
258 static constexpr const char* _manifestUrlJsonKey = "url";
259 static constexpr const char* _manifestMavFirmwareVersionTypeJsonKey = "mav-firmware-version-type";
260 static constexpr const char* _manifestUSBIDJsonKey = "USBID";
261 static constexpr const char* _manifestMavFirmwareVersionJsonKey = "mav-firmware-version";
262 static constexpr const char* _manifestBootloaderStrJsonKey = "bootloader_str";
263 static constexpr const char* _manifestLatestKey = "latest";
264 static constexpr const char* _manifestPlatformKey = "platform";
265 static constexpr const char* _manifestBrandNameKey = "brand_name";
266
267 typedef struct {
268 uint32_t boardId;
269 FirmwareBuildType_t firmwareBuildType;
270 FirmwareVehicleType_t vehicleType;
271 QString url;
272 QString version;
273 QStringList rgBootloaderPortString;
274 QList<int> rgVID;
275 QList<int> rgPID;
276 QString friendlyName;
277 bool chibios;
278 bool fmuv2;
279 } ManifestFirmwareInfo_t;
280
281
282 QList<ManifestFirmwareInfo_t> _rgManifestFirmwareInfo;
283 QMap<QString, FirmwareBuildType_t> _manifestMavFirmwareVersionTypeToFirmwareBuildTypeMap;
284 QMap<QString, FirmwareVehicleType_t> _manifestMavTypeToFirmwareVehicleTypeMap;
285 QStringList _apmFirmwareNames;
286 int _apmFirmwareNamesBestIndex = 0;
287 QStringList _apmFirmwareUrls;
288 Fact* _apmChibiOSSetting;
289 Fact* _apmVehicleTypeSetting;
290 QVariantList _availablePorts;
291 QPointer<QGCFileDownload> _activeDownloader;
292 bool _flashCancelled = false;
293
294 FirmwareBuildType_t _manifestMavFirmwareVersionTypeToFirmwareBuildType (const QString& manifestMavFirmwareVersionType);
295 FirmwareVehicleType_t _manifestMavTypeToFirmwareVehicleType (const QString& manifestMavType);
296};
297
298// global hashing function
uint qHash(const FirmwareUpgradeController::FirmwareIdentifier &firmwareId)
QString errorString
A Fact is used to hold a single value within the system.
Definition Fact.h:17
Support for Intel Hex firmware file.
FirmwareIdentifier(AutoPilotStackType_t stack=AutoPilotStackPX4, FirmwareBuildType_t firmware=StableFirmware, FirmwareVehicleType_t vehicle=DefaultVehicleFirmware)
bool operator==(const FirmwareIdentifier &firmwareId) const
Supported firmware types. If you modify these you will need to update the qml file as well.
Q_INVOKABLE void startBoardSearch(void)
TextArea for log output.
Q_INVOKABLE void flash(AutoPilotStackType_t stackType, FirmwareBuildType_t firmwareType=StableFirmware, FirmwareVehicleType_t vehicleType=DefaultVehicleFirmware)
Called when the firmware type has been selected by the user to continue the flash process.
void apmFirmwareNamesChanged(void)
Q_INVOKABLE FirmwareVehicleType_t vehicleTypeFromFirmwareSelectionIndex(int index)
void px4BetaVersionChanged(const QString &px4BetaVersion)
void px4StableVersionChanged(const QString &px4StableVersion)
FirmwareUpgradeController(void)
@Brief Constructs a new FirmwareUpgradeController Widget. This widget is used within the PX4VehicleCo...
Q_INVOKABLE void cancel(void)
Cancels whatever state the upgrade worker thread is in.
void showFirmwareSelectDlg(void)
Q_INVOKABLE void flashSingleFirmwareMode(FirmwareBuildType_t firmwareType)
Called to flash when upgrade is running in singleFirmwareMode.
FirmwareBuildType_t selectedFirmwareBuildType(void)
Q_INVOKABLE void flashPort(const QString &systemLocation)
Selects which serial port to flash. The worker will wait for this port to be in bootloader mode and t...
Q_INVOKABLE QStringList availableBoardsName(void)
Return a human friendly string of available boards.
void selectedFirmwareBuildTypeChanged(FirmwareBuildType_t firmwareType)
QString firmwareTypeAsString(FirmwareBuildType_t type) const
returns firmware type as a string
void setSelectedFirmwareBuildType(FirmwareBuildType_t firmwareType)
void downloadingFirmwareListChanged(bool downloadingFirmwareList)
Q_INVOKABLE void flashFirmwareUrl(QString firmwareUrl)
void availablePortsChanged(void)
void setProgressBar(QQuickItem *progressBar)
void setStatusLog(QQuickItem *statusLog)
Provides methods to interact with the bootloader. The commands themselves are signalled across to PX4...
File download with progress, decompression, and hash verification.
Provides information about existing serial ports.
QString portName() const
Returns the name of the serial port.
QString description() const
Returns the description string of the serial port, if available; otherwise returns an empty string.