From 5b117db455cf03ec13353f5c196920c846b6bd2a Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 31 Oct 2014 10:51:37 -0700 Subject: [PATCH] Verify board is unplugged --- src/ui/px4_configuration/PX4FirmwareUpgrade.cc | 17 ++++++++++++----- src/ui/px4_configuration/PX4FirmwareUpgrade.h | 2 +- .../PX4FirmwareUpgradeThread.cc | 9 ++++++--- .../PX4FirmwareUpgradeThread.h | 8 +++++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/ui/px4_configuration/PX4FirmwareUpgrade.cc b/src/ui/px4_configuration/PX4FirmwareUpgrade.cc index 70c1e067c..47f001456 100644 --- a/src/ui/px4_configuration/PX4FirmwareUpgrade.cc +++ b/src/ui/px4_configuration/PX4FirmwareUpgrade.cc @@ -35,6 +35,7 @@ #include #include #include +#include /// @Brief Constructs a new PX4FirmwareUpgrade Widget. This widget is used within the PX4VehicleConfig set of screens. PX4FirmwareUpgrade::PX4FirmwareUpgrade(QWidget *parent) : @@ -287,12 +288,18 @@ void PX4FirmwareUpgrade::_findBoard(void) } /// @brief Called when board has been found by the findBoard process -void PX4FirmwareUpgrade::_foundBoard(const QString portName, QString portDescription) +void PX4FirmwareUpgrade::_foundBoard(bool firstTry, const QString portName, QString portDescription) { - _portName = portName; - _portDescription = portDescription; - _setupState(upgradeStateBootloaderSearch); - _findBootloader(); + if (firstTry) { + // Board is still plugged + QMessageBox::critical(this, tr("Firmware Upgrade"), tr("You must unplug you board before beginning the Firmware Upgrade process.")); + _cancel(); + } else { + _portName = portName; + _portDescription = portDescription; + _setupState(upgradeStateBootloaderSearch); + _findBootloader(); + } } /// @brief Begins the findBootloader process to connect to the bootloader diff --git a/src/ui/px4_configuration/PX4FirmwareUpgrade.h b/src/ui/px4_configuration/PX4FirmwareUpgrade.h index ad3e6afe2..0a7361dd4 100644 --- a/src/ui/px4_configuration/PX4FirmwareUpgrade.h +++ b/src/ui/px4_configuration/PX4FirmwareUpgrade.h @@ -61,7 +61,7 @@ private slots: void _downloadProgress(qint64 curr, qint64 total); void _downloadFinished(void); void _downloadError(QNetworkReply::NetworkError code); - void _foundBoard(const QString portname, QString portDescription); + void _foundBoard(bool firstTry, const QString portname, QString portDescription); void _foundBootloader(int bootloaderVersion, int boardID, int flashSize); void _error(const int command, const QString errorString); void _bootloaderSyncFailed(void); diff --git a/src/ui/px4_configuration/PX4FirmwareUpgradeThread.cc b/src/ui/px4_configuration/PX4FirmwareUpgradeThread.cc index 496fec388..2a9b7ff03 100644 --- a/src/ui/px4_configuration/PX4FirmwareUpgradeThread.cc +++ b/src/ui/px4_configuration/PX4FirmwareUpgradeThread.cc @@ -75,6 +75,7 @@ void PX4FirmwareUpgradeThreadWorker::init(void) void PX4FirmwareUpgradeThreadWorker::findBoard(int msecTimeout) { + _findBoardFirstAttempt = true; connect(_timerRetry, &QTimer::timeout, this, &PX4FirmwareUpgradeThreadWorker::_findBoardOnce); _timerTimeout->start(msecTimeout); _elapsed.start(); @@ -107,11 +108,13 @@ void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(void) #endif _closeFind(); - emit foundBoard(portName, portDescription); + emit foundBoard(_findBoardFirstAttempt, portName, portDescription); return; } } + _findBoardFirstAttempt = false; + emit updateProgress(_elapsed.elapsed(), _timerTimeout->interval()); _timerRetry->start(); } @@ -285,9 +288,9 @@ void PX4FirmwareUpgradeThreadController::findBootloader(const QString& portName, emit _findBootloaderOnThread(portName, msecTimeout); } -void PX4FirmwareUpgradeThreadController::_foundBoard(const QString portName, QString portDescription) +void PX4FirmwareUpgradeThreadController::_foundBoard(bool firstTry, const QString portName, QString portDescription) { - emit foundBoard(portName, portDescription); + emit foundBoard(firstTry, portName, portDescription); } void PX4FirmwareUpgradeThreadController::_foundBootloader(int bootloaderVersion, int boardID, int flashSize) diff --git a/src/ui/px4_configuration/PX4FirmwareUpgradeThread.h b/src/ui/px4_configuration/PX4FirmwareUpgradeThread.h index f51362b06..59a7f4a68 100644 --- a/src/ui/px4_configuration/PX4FirmwareUpgradeThread.h +++ b/src/ui/px4_configuration/PX4FirmwareUpgradeThread.h @@ -69,7 +69,7 @@ public slots: void erase(void); signals: - void foundBoard(const QString portname, QString portDescription); + void foundBoard(bool firstTry, const QString portname, QString portDescription); void foundBootloader(int bootloaderVersion, int boardID, int flashSize); void bootloaderSyncFailed(void); void error(const int command, const QString errorString); @@ -91,6 +91,7 @@ private: QTime _elapsed; QString _portName; static const int _retryTimeout = 1000; + bool _findBoardFirstAttempt; }; /// @brief Provides methods to interact with the bootloader. The commands themselves are signalled @@ -129,9 +130,10 @@ public: signals: /// @brief Emitted by the findBoard process when it finds the board. + /// @param firstTry true: board found on first attempt /// @param portName Port that board is on /// @param portDescription User friendly port description - void foundBoard(const QString portname, QString portDescription); + void foundBoard(bool firstTry, const QString portname, QString portDescription); /// @brief Emitted by the findBootloader process when has a connection to the bootloader void foundBootloader(int bootloaderVersion, int boardID, int flashSize); @@ -164,7 +166,7 @@ signals: void _cancelFindOnThread(void); private slots: - void _foundBoard(const QString portname, QString portDescription); + void _foundBoard(bool firstTry, const QString portname, QString portDescription); void _foundBootloader(int bootloaderVersion, int boardID, int flashSize); void _bootloaderSyncFailed(void); void _error(const int errorCommand, const QString errorString) { emit error(errorCommand, errorString); } -- 2.22.0