6#include <QtCore/QThread>
7#include <QtCore/QVariantMap>
11#include <QtCore/QTimer>
14 : _controller(controller)
29void PX4FirmwareUpgradeThreadWorker::_init(
void)
33 _findBoardTimer =
new QTimer(
this);
34 _findBoardTimer->setSingleShot(
true);
35 _findBoardTimer->setInterval(500);
36 connect(_findBoardTimer, &QTimer::timeout,
this, &PX4FirmwareUpgradeThreadWorker::_findBoardOnce);
39void PX4FirmwareUpgradeThreadWorker::_cancel(
void)
41 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"_cancel";
42 _targetSystemLocation.clear();
43 _targetSerialNumber.clear();
44 _targetSeenAtLeastOnce =
false;
45 _ignoredPorts.clear();
50 _bootloader->deleteLater();
51 _bootloader =
nullptr;
53 if (_findBoardTimer && !_findBoardTimer->isActive()) {
54 _findBoardTimer->start();
58void PX4FirmwareUpgradeThreadWorker::_startFindBoardLoop(
void)
61 _findBoardFirstAttempt =
true;
62 _targetSystemLocation.clear();
63 _targetSerialNumber.clear();
64 _targetSeenAtLeastOnce =
false;
65 _ignoredPorts.clear();
69void PX4FirmwareUpgradeThreadWorker::_resumeDiscovery(
void)
71 _targetSystemLocation.clear();
72 _targetSerialNumber.clear();
73 _targetSeenAtLeastOnce =
false;
74 _ignoredPorts.clear();
76 if (_findBoardTimer && !_findBoardTimer->isActive()) {
77 _findBoardTimer->start();
81void PX4FirmwareUpgradeThreadWorker::_setTargetPort(
const QString& systemLocation)
83 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"_setTargetPort" << systemLocation;
84 _targetSystemLocation = systemLocation;
85 _targetSerialNumber.clear();
86 _targetSeenAtLeastOnce =
false;
88 _ignoredPorts.clear();
90 bool currentlyVisible =
false;
91 bool currentlyInBootloader =
false;
93 if (info.systemLocation() == systemLocation) {
94 currentlyVisible =
true;
97 _targetSerialNumber = info.serialNumber();
100 currentlyInBootloader = info.description().contains(QStringLiteral(
"BL"))
101 || info.description().contains(QStringLiteral(
"Bootloader"), Qt::CaseInsensitive);
105 _ignoredPorts.insert(info.systemLocation());
108 _findBoardFirstAttempt = currentlyVisible && !currentlyInBootloader;
111QVariantList PX4FirmwareUpgradeThreadWorker::_buildPortDescriptors()
const
118 const bool recognized = info.getBoardInfo(boardType, boardName);
121 entry[
"systemLocation"] = info.systemLocation();
122 entry[
"portName"] = info.portName();
123 entry[
"description"] = info.description();
124 entry[
"manufacturer"] = info.manufacturer();
126 entry[
"boardName"] = recognized ? boardName : QString();
127 entry[
"recognized"] = recognized;
129 QString display = info.portName();
130 if (!info.description().isEmpty()) {
131 display += QStringLiteral(
" — ") + info.description();
133 if (recognized && !boardName.isEmpty()) {
134 display += QStringLiteral(
" [") + boardName + QStringLiteral(
"]");
136 entry[
"displayName"] = display;
144void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(
void)
146 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"_findBoardOnce";
150 if (_targetSystemLocation.isEmpty()) {
151 _findBoardTimer->start();
158 bool foundTarget =
false;
161 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"Serial Port --------------";
162 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"\tport name:" << info.
portName();
163 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"\tdescription:" << info.description();
164 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"\tsystem location:" << info.systemLocation();
165 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"\tvendor ID:" << info.vendorIdentifier();
166 qCDebug(PX4FirmwareUpgradeThreadVerboseLog) <<
"\tproduct ID:" << info.productIdentifier();
168 bool match = (info.systemLocation() == _targetSystemLocation);
169 if (!match && !_targetSerialNumber.isEmpty() && !info.serialNumber().isEmpty()) {
170 match = (info.serialNumber() == _targetSerialNumber);
177 if (!match && _targetSeenAtLeastOnce && !_foundBoard
179 && !_ignoredPorts.contains(info.systemLocation())) {
194 _targetSeenAtLeastOnce =
true;
195 _foundBoardPortInfo = targetPort;
196 if (_targetSerialNumber.isEmpty() && !targetPort.
serialNumber().isEmpty()) {
199 emit
foundBoard(_findBoardFirstAttempt, targetPort, boardType, boardName);
200 if (!_findBoardFirstAttempt) {
206 uint32_t bootloaderVersion;
209 if (_bootloader->
getBoardInfo(bootloaderVersion, boardId, flashSize)) {
223 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Target port gone";
228 _findBoardFirstAttempt =
false;
229 _findBoardTimer->start();
232void PX4FirmwareUpgradeThreadWorker::_reboot(
void)
237void PX4FirmwareUpgradeThreadWorker::_flash(
void)
239 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"PX4FirmwareUpgradeThreadWorker::_flash";
243 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"_flash: bootloader gone, aborting";
255 emit
status(tr(
"Programming new version..."));
258 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Program complete";
260 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Program failed:" << _bootloader->
errorString();
264 emit
status(tr(
"Verifying program..."));
267 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Verify complete";
269 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Verify failed:" << _bootloader->
errorString();
274 emit
status(tr(
"Rebooting board"));
277 _bootloader->
close();
278 _bootloader->deleteLater();
279 _bootloader =
nullptr;
289 _bootloader->
close();
290 _bootloader->deleteLater();
291 _bootloader =
nullptr;
295bool PX4FirmwareUpgradeThreadWorker::_erase(
void)
297 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"PX4FirmwareUpgradeThreadWorker::_erase";
300 emit
status(tr(
"Erasing previous program..."));
302 if (_bootloader->
erase()) {
303 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Erase complete";
304 emit
status(tr(
"Erase complete"));
308 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"Erase failed:" << _bootloader->
errorString();
318 _workerThread =
new QThread(
this);
319 _worker->moveToThread(_workerThread);
333 _workerThread->start();
340 _workerThread->quit();
341 _workerThread->wait();
343 delete _workerThread;
348 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"PX4FirmwareUpgradeThreadController::findBoard";
354 qCDebug(PX4FirmwareUpgradeThreadLog) <<
"PX4FirmwareUpgradeThreadController::cancel";
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Bootloader Utility routines. Works with PX4 and 3DR Radio bootloaders.
bool program(const FirmwareImage *image)
void updateProgress(int curr, int total)
Signals progress indicator for long running bootloader utility routines.
QString errorString(void)
bool initFlashSequence(void)
bool open(const QString portName)
bool verify(const FirmwareImage *image)
bool getBoardInfo(uint32_t &bootloaderVersion, uint32_t &boardID, uint32_t &flashSize)
Support for Intel Hex firmware file.
Provides methods to interact with the bootloader. The commands themselves are signalled across to PX4...
void _setTargetPortOnThread(const QString &systemLocation)
~PX4FirmwareUpgradeThreadController(void)
void _rebootOnThread(void)
void _flashOnThread(void)
void _startFindBoardLoopOnThread(void)
void _initThreadWorker(void)
PX4FirmwareUpgradeThreadController(QObject *parent=nullptr)
void startFindBoardLoop(void)
Begins the process of searching for a supported board connected to any serial port....
void flash(const FirmwareImage *image)
const FirmwareImage * image(void)
Used to run bootloader commands on a separate thread. These routines are mainly meant to to be called...
void foundBoard(bool firstAttempt, const QGCSerialPortInfo &portInfo, int type, QString boardName)
void portsAvailable(const QVariantList &ports)
void error(const QString &errorString)
void foundBoardInfo(int bootloaderVersion, int boardID, int flashSize)
~PX4FirmwareUpgradeThreadWorker()
void status(const QString &statusText)
PX4FirmwareUpgradeThreadWorker(PX4FirmwareUpgradeThreadController *controller)
void updateProgress(int curr, int total)
QGC's version of Qt QSerialPortInfo. It provides additional information about board types that QGC ca...
bool getBoardInfo(BoardType_t &boardType, QString &name) const
QString portName() const
Returns the name of the serial port.
QString serialNumber() const
Error
Error codes for decompression operations.