Commit 84de973d authored by Don Gagne's avatar Don Gagne

Merge pull request #934 from DonLakeFlyer/UnplugFirst

Verify board is unplugged before starting Firmware Upgrade
parents 66f20d1a 5b117db4
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
#include <QDebug> #include <QDebug>
#include <QMessageBox>
/// @Brief Constructs a new PX4FirmwareUpgrade Widget. This widget is used within the PX4VehicleConfig set of screens. /// @Brief Constructs a new PX4FirmwareUpgrade Widget. This widget is used within the PX4VehicleConfig set of screens.
PX4FirmwareUpgrade::PX4FirmwareUpgrade(QWidget *parent) : PX4FirmwareUpgrade::PX4FirmwareUpgrade(QWidget *parent) :
...@@ -287,12 +288,18 @@ void PX4FirmwareUpgrade::_findBoard(void) ...@@ -287,12 +288,18 @@ void PX4FirmwareUpgrade::_findBoard(void)
} }
/// @brief Called when board has been found by the findBoard process /// @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; if (firstTry) {
_portDescription = portDescription; // Board is still plugged
_setupState(upgradeStateBootloaderSearch); QMessageBox::critical(this, tr("Firmware Upgrade"), tr("You must unplug you board before beginning the Firmware Upgrade process."));
_findBootloader(); _cancel();
} else {
_portName = portName;
_portDescription = portDescription;
_setupState(upgradeStateBootloaderSearch);
_findBootloader();
}
} }
/// @brief Begins the findBootloader process to connect to the bootloader /// @brief Begins the findBootloader process to connect to the bootloader
......
...@@ -61,7 +61,7 @@ private slots: ...@@ -61,7 +61,7 @@ private slots:
void _downloadProgress(qint64 curr, qint64 total); void _downloadProgress(qint64 curr, qint64 total);
void _downloadFinished(void); void _downloadFinished(void);
void _downloadError(QNetworkReply::NetworkError code); 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 _foundBootloader(int bootloaderVersion, int boardID, int flashSize);
void _error(const int command, const QString errorString); void _error(const int command, const QString errorString);
void _bootloaderSyncFailed(void); void _bootloaderSyncFailed(void);
......
...@@ -75,6 +75,7 @@ void PX4FirmwareUpgradeThreadWorker::init(void) ...@@ -75,6 +75,7 @@ void PX4FirmwareUpgradeThreadWorker::init(void)
void PX4FirmwareUpgradeThreadWorker::findBoard(int msecTimeout) void PX4FirmwareUpgradeThreadWorker::findBoard(int msecTimeout)
{ {
_findBoardFirstAttempt = true;
connect(_timerRetry, &QTimer::timeout, this, &PX4FirmwareUpgradeThreadWorker::_findBoardOnce); connect(_timerRetry, &QTimer::timeout, this, &PX4FirmwareUpgradeThreadWorker::_findBoardOnce);
_timerTimeout->start(msecTimeout); _timerTimeout->start(msecTimeout);
_elapsed.start(); _elapsed.start();
...@@ -107,11 +108,13 @@ void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(void) ...@@ -107,11 +108,13 @@ void PX4FirmwareUpgradeThreadWorker::_findBoardOnce(void)
#endif #endif
_closeFind(); _closeFind();
emit foundBoard(portName, portDescription); emit foundBoard(_findBoardFirstAttempt, portName, portDescription);
return; return;
} }
} }
_findBoardFirstAttempt = false;
emit updateProgress(_elapsed.elapsed(), _timerTimeout->interval()); emit updateProgress(_elapsed.elapsed(), _timerTimeout->interval());
_timerRetry->start(); _timerRetry->start();
} }
...@@ -285,9 +288,9 @@ void PX4FirmwareUpgradeThreadController::findBootloader(const QString& portName, ...@@ -285,9 +288,9 @@ void PX4FirmwareUpgradeThreadController::findBootloader(const QString& portName,
emit _findBootloaderOnThread(portName, msecTimeout); 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) void PX4FirmwareUpgradeThreadController::_foundBootloader(int bootloaderVersion, int boardID, int flashSize)
......
...@@ -69,7 +69,7 @@ public slots: ...@@ -69,7 +69,7 @@ public slots:
void erase(void); void erase(void);
signals: 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 foundBootloader(int bootloaderVersion, int boardID, int flashSize);
void bootloaderSyncFailed(void); void bootloaderSyncFailed(void);
void error(const int command, const QString errorString); void error(const int command, const QString errorString);
...@@ -91,6 +91,7 @@ private: ...@@ -91,6 +91,7 @@ private:
QTime _elapsed; QTime _elapsed;
QString _portName; QString _portName;
static const int _retryTimeout = 1000; static const int _retryTimeout = 1000;
bool _findBoardFirstAttempt;
}; };
/// @brief Provides methods to interact with the bootloader. The commands themselves are signalled /// @brief Provides methods to interact with the bootloader. The commands themselves are signalled
...@@ -129,9 +130,10 @@ public: ...@@ -129,9 +130,10 @@ public:
signals: signals:
/// @brief Emitted by the findBoard process when it finds the board. /// @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 portName Port that board is on
/// @param portDescription User friendly port description /// @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 /// @brief Emitted by the findBootloader process when has a connection to the bootloader
void foundBootloader(int bootloaderVersion, int boardID, int flashSize); void foundBootloader(int bootloaderVersion, int boardID, int flashSize);
...@@ -164,7 +166,7 @@ signals: ...@@ -164,7 +166,7 @@ signals:
void _cancelFindOnThread(void); void _cancelFindOnThread(void);
private slots: 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 _foundBootloader(int bootloaderVersion, int boardID, int flashSize);
void _bootloaderSyncFailed(void); void _bootloaderSyncFailed(void);
void _error(const int errorCommand, const QString errorString) { emit error(errorCommand, errorString); } void _error(const int errorCommand, const QString errorString) { emit error(errorCommand, errorString); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment