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 @@
#include <QDir>
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
/// @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
......
......@@ -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);
......
......@@ -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)
......
......@@ -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); }
......
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