Commit 445c8527 authored by Don Gagne's avatar Don Gagne

Merge pull request #2426 from DonLakeFlyer/APMVersionInfo

Show Apm version info when flashing
parents 137ce9d7 8c7ec0ae
......@@ -262,6 +262,7 @@ HEADERS += \
src/QGCComboBox.h \
src/QGCConfig.h \
src/QGCDockWidget.h \
src/QGCFileDownload.h \
src/QGCGeo.h \
src/QGCLoggingCategory.h \
src/QGCMapPalette.h \
......@@ -382,6 +383,7 @@ SOURCES += \
src/QGCApplication.cc \
src/QGCComboBox.cc \
src/QGCDockWidget.cc \
src/QGCFileDownload.cc \
src/QGCLoggingCategory.cc \
src/QGCMapPalette.cc \
src/QGCPalette.cc \
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#include "QGCFileDownload.h"
#include <QFileInfo>
#include <QStandardPaths>
QGCFileDownload::QGCFileDownload(QObject* parent)
: QNetworkAccessManager(parent)
{
}
bool QGCFileDownload::download(const QString& remoteFile)
{
if (remoteFile.isEmpty()) {
qWarning() << "downloadFile empty";
return false;
}
// Split out filename from path
QString remoteFileName = QFileInfo(remoteFile).fileName();
if (remoteFileName.isEmpty()) {
qWarning() << "Unabled to parse filename from downloadFile" << remoteFile;
return false;
}
// Determine location to download file to
QString localFile = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
if (localFile.isEmpty()) {
localFile = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
if (localFile.isEmpty()) {
qDebug() << "Unabled to find writable download location. Tried downloads and temp directory.";
return false;
}
}
localFile += "/" + remoteFileName;
QUrl remoteUrl;
if (remoteFile.startsWith("http:")) {
remoteUrl.setUrl(remoteFile);
} else {
remoteUrl = QUrl::fromLocalFile(remoteFile);
}
if (!remoteUrl.isValid()) {
qWarning() << "Remote URL is invalid" << remoteFile;
return false;
}
QNetworkRequest networkRequest(remoteUrl);
// Store local file location in user attribute so we can retrieve when the download finishes
networkRequest.setAttribute(QNetworkRequest::User, localFile);
QNetworkReply* networkReply = get(networkRequest);
if (!networkReply) {
qWarning() << "QNetworkAccessManager::get failed";
return false;
}
connect(networkReply, &QNetworkReply::downloadProgress, this, &QGCFileDownload::downloadProgress);
connect(networkReply, &QNetworkReply::finished, this, &QGCFileDownload::_downloadFinished);
connect(networkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(_downloadError(QNetworkReply::NetworkError)));
return true;
}
void QGCFileDownload::_downloadFinished(void)
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
// When an error occurs or the user cancels the download, we still end up here. So bail out in
// those cases.
if (reply->error() != QNetworkReply::NoError) {
return;
}
// Download file location is in user attribute
QString downloadFilename = reply->request().attribute(QNetworkRequest::User).toString();
Q_ASSERT(!downloadFilename.isEmpty());
// Store downloaded file in download location
QFile file(downloadFilename);
if (!file.open(QIODevice::WriteOnly)) {
emit error(QString("Could not save downloaded file to %1. Error: %2").arg(downloadFilename).arg(file.errorString()));
return;
}
file.write(reply->readAll());
file.close();
emit downloadFinished(reply->url().toString(), downloadFilename);
}
/// @brief Called when an error occurs during download
void QGCFileDownload::_downloadError(QNetworkReply::NetworkError code)
{
QString errorMsg;
if (code == QNetworkReply::OperationCanceledError) {
errorMsg = "Download cancelled";
} else {
errorMsg = QString("Error during download. Error: %1").arg(code);
}
emit error(errorMsg);
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef QGCFileDownload_H
#define QGCFileDownload_H
#include <QNetworkReply>
class QGCFileDownload : public QNetworkAccessManager
{
Q_OBJECT
public:
QGCFileDownload(QObject* parent = NULL);
/// Download the specified remote file.
/// @param remoteFile File to download. Can be http address or file system path.
/// @return true: Asynchronous download has started, false: Download initialization failed
bool download(const QString& remoteFile);
signals:
void downloadProgress(qint64 curr, qint64 total);
void downloadFinished(QString remoteFile, QString localFile);
void error(QString errorMsg);
private slots:
void _downloadFinished(void);
void _downloadError(QNetworkReply::NetworkError code);
};
#endif
......@@ -164,7 +164,7 @@ QGCView {
var firmwareType = firmwareVersionCombo.model.get(firmwareVersionCombo.currentIndex).firmwareType
var vehicleType = FirmwareUpgradeController.DefaultVehicleFirmware
if (apmFlightStack.checked) {
vehicleType = vehicleTypeSelectionCombo.model.get(vehicleTypeSelectionCombo.currentIndex).vehicleType
vehicleType = controller.vehicleTypeFromVersionIndex(vehicleTypeSelectionCombo.currentIndex)
}
controller.flash(stack, firmwareType, vehicleType)
}
......@@ -199,47 +199,6 @@ QGCView {
}
}
ListModel {
id: vehicleTypeList
ListElement {
text: "Quad"
vehicleType: FirmwareUpgradeController.QuadFirmware
}
ListElement {
text: "X8"
vehicleType: FirmwareUpgradeController.X8Firmware
}
ListElement {
text: "Hexa"
vehicleType: FirmwareUpgradeController.HexaFirmware
}
ListElement {
text: "Octo"
vehicleType: FirmwareUpgradeController.OctoFirmware
}
ListElement {
text: "Y"
vehicleType: FirmwareUpgradeController.YFirmware
}
ListElement {
text: "Y6"
vehicleType: FirmwareUpgradeController.Y6Firmware
}
ListElement {
text: "Heli"
vehicleType: FirmwareUpgradeController.HeliFirmware
}
ListElement {
text: "Plane"
vehicleType: FirmwareUpgradeController.PlaneFirmware
}
ListElement {
text: "Rover"
vehicleType: FirmwareUpgradeController.RoverFirmware
}
}
ListModel {
id: px4FlowTypeList
......@@ -274,17 +233,6 @@ QGCView {
firmwareVersionCombo.currentIndex = 0
}
function vehicleTypeChanged(model) {
vehicleTypeSelectionCombo.model = null
// All of this bizarre, setting model to null and index to 1 and then to 0 is to work around
// strangeness in the combo box implementation. This sequence of steps correctly changes the combo model
// without generating any warnings and correctly updates the combo text with the new selection.
vehicleTypeSelectionCombo.model = null
vehicleTypeSelectionCombo.model = model
vehicleTypeSelectionCombo.currentIndex = 1
vehicleTypeSelectionCombo.currentIndex = 0
}
QGCRadioButton {
id: px4FlightStack
checked: true
......@@ -301,10 +249,7 @@ QGCView {
text: "APM Flight Stack"
visible: !px4Flow
onClicked: {
parent.firmwareVersionChanged(firmwareTypeList)
parent.vehicleTypeChanged(vehicleTypeList)
}
onClicked: parent.firmwareVersionChanged(firmwareTypeList)
}
QGCLabel {
......@@ -317,19 +262,21 @@ QGCView {
Row {
spacing: 10
QGCComboBox {
id: firmwareVersionCombo
width: 200
visible: showFirmwareTypeSelection
model: px4Flow ? px4FlowTypeList : firmwareTypeList
id: firmwareVersionCombo
width: 200
visible: showFirmwareTypeSelection
model: px4Flow ? px4FlowTypeList : firmwareTypeList
currentIndex: controller.selectedFirmwareType
onActivated: {
if (model.get(index).firmwareType == FirmwareUpgradeController.PX4BetaFirmware || FirmwareUpgradeController.APMBetaFirmware ) {
controller.selectedFirmwareType = index
if (model.get(index).firmwareType == FirmwareUpgradeController.BetaFirmware) {
firmwareVersionWarningLabel.visible = true
firmwareVersionWarningLabel.text = "WARNING: BETA FIRMWARE. " +
"This firmware version is ONLY intended for beta testers. " +
"Although it has received FLIGHT TESTING, it represents actively changed code. " +
"Do NOT use for normal operation."
} else if (model.get(index).firmwareType == FirmwareUpgradeController.PX4DeveloperFirmware || FirmwareUpgradeController.APMDeveloperFirmware) {
} else if (model.get(index).firmwareType == FirmwareUpgradeController.DeveloperFirmware) {
firmwareVersionWarningLabel.visible = true
firmwareVersionWarningLabel.text = "WARNING: CONTINUOUS BUILD FIRMWARE. " +
"This firmware has NOT BEEN FLIGHT TESTED. " +
......@@ -347,7 +294,7 @@ QGCView {
id: vehicleTypeSelectionCombo
width: 200
visible: apmFlightStack.checked
model: vehicleTypeList
model: controller.apmAvailableVersions
}
}
......
......@@ -106,10 +106,12 @@ public:
FirmwareUpgradeController(void);
~FirmwareUpgradeController();
Q_PROPERTY(QString boardPort READ boardPort NOTIFY boardFound)
Q_PROPERTY(QString boardDescription READ boardDescription NOTIFY boardFound)
Q_PROPERTY(QString boardType MEMBER _foundBoardType NOTIFY boardFound)
Q_PROPERTY(QString boardPort READ boardPort NOTIFY boardFound)
Q_PROPERTY(QString boardDescription READ boardDescription NOTIFY boardFound)
Q_PROPERTY(QString boardType MEMBER _foundBoardTypeName NOTIFY boardFound)
Q_PROPERTY(FirmwareType_t selectedFirmwareType READ selectedFirmwareType WRITE setSelectedFirmwareType NOTIFY selectedFirmwareTypeChanged)
Q_PROPERTY(QStringList apmAvailableVersions READ apmAvailableVersions NOTIFY apmAvailableVersionsChanged)
/// TextArea for log output
Q_PROPERTY(QQuickItem* statusLog READ statusLog WRITE setStatusLog)
......@@ -126,6 +128,8 @@ public:
Q_INVOKABLE void flash(AutoPilotStackType_t stackType,
FirmwareType_t firmwareType = StableFirmware,
FirmwareVehicleType_t vehicleType = DefaultVehicleFirmware );
Q_INVOKABLE FirmwareVehicleType_t vehicleTypeFromVersionIndex(int index);
// overload, not exposed to qml side
void flash(const FirmwareIdentifier& firmwareId);
......@@ -140,6 +144,11 @@ public:
QString boardPort(void) { return _foundBoardInfo.portName(); }
QString boardDescription(void) { return _foundBoardInfo.description(); }
FirmwareType_t selectedFirmwareType(void) { return _selectedFirmwareType; }
void setSelectedFirmwareType(FirmwareType_t firmwareType);
QStringList apmAvailableVersions(void);
signals:
void boardFound(void);
......@@ -148,12 +157,14 @@ signals:
void flashComplete(void);
void flashCancelled(void);
void error(void);
void selectedFirmwareTypeChanged(FirmwareType_t firmwareType);
void apmAvailableVersionsChanged(void);
private slots:
void _downloadProgress(qint64 curr, qint64 total);
void _downloadFinished(void);
void _downloadError(QNetworkReply::NetworkError code);
void _foundBoard(bool firstAttempt, const QSerialPortInfo& portInfo, int type);
void _foundBoard(bool firstAttempt, const QSerialPortInfo& portInfo, int boardType);
void _noBoardFound(void);
void _boardGone();
void _foundBootloader(int bootloaderVersion, int boardID, int flashSize);
......@@ -165,6 +176,7 @@ private slots:
void _eraseStarted(void);
void _eraseComplete(void);
void _eraseProgressTick(void);
void _apmVersionDownloadFinished(QString remoteFile, QString localFile);
private:
void _getFirmwareFile(FirmwareIdentifier firmwareId);
......@@ -172,7 +184,10 @@ private:
void _downloadFirmware(void);
void _appendStatusLog(const QString& text, bool critical = false);
void _errorCancel(const QString& msg);
void _loadAPMVersions(QGCSerialPortInfo::BoardType_t boardType);
QHash<FirmwareIdentifier, QString>* _firmwareHashForBoardId(int boardId);
QHash<FirmwareIdentifier, QString>* _firmwareHashForBoardType(QGCSerialPortInfo::BoardType_t boardType);
QString _portName;
QString _portDescription;
......@@ -184,6 +199,9 @@ private:
QHash<FirmwareIdentifier, QString> _rgPX4FLowFirmware;
QHash<FirmwareIdentifier, QString> _rg3DRRadioFirmware;
QMap<FirmwareType_t, QMap<FirmwareVehicleType_t, QString> > _apmVersionMap;
QList<FirmwareVehicleType_t> _apmVehicleTypeFromCurrentVersionList;
/// Information which comes back from the bootloader
bool _bootloaderFound; ///< true: we have received the foundBootloader signals
uint32_t _bootloaderVersion; ///< Bootloader version
......@@ -216,9 +234,12 @@ private:
bool _searchingForBoard; ///< true: searching for board, false: search for bootloader
QSerialPortInfo _foundBoardInfo;
QString _foundBoardType;
QSerialPortInfo _foundBoardInfo;
QGCSerialPortInfo::BoardType_t _foundBoardType;
QString _foundBoardTypeName;
FirmwareType_t _selectedFirmwareType;
FirmwareImage* _image;
};
......
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