diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-12-28 10:22:46 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-12-28 10:22:46 -0800 |
commit | 003f5d18b64d14d941a774086472918f203a063d (patch) | |
tree | 41d31bcfc4cdd6e1be789501d200688b4c05425f /qt-ui | |
parent | 0be0cdb046018a5ec633bfc6f0aacba20d5c35e2 (diff) | |
download | subsurface-003f5d18b64d14d941a774086472918f203a063d.tar.gz |
Automatic OSTC firmware update: download file and try to install
This successfully downloads the hex file.
The actuall update of the OSTC fails before it gets started with a crash
when the ConfigureDiveComputer object is created.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 80 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.h | 14 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 2 |
3 files changed, 73 insertions, 23 deletions
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index 46ac62386..48c96e594 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -1,17 +1,21 @@ #include "configuredivecomputerdialog.h" -#include "../divecomputer.h" -#include "../libdivecomputer.h" -#include "../helpers.h" -#include "../display.h" -#include "../divelist.h" +#include "divecomputer.h" +#include "libdivecomputer.h" +#include "helpers.h" +#include "display.h" +#include "divelist.h" #include "configuredivecomputer.h" +#include "mainwindow.h" #include <QFileDialog> #include <QMessageBox> #include <QSettings> #include <QWebElement> #include <QWebFrame> #include <QWebPage> +#include <QNetworkAccessManager> +#include <QNetworkRequest> +#include <QNetworkReply> #include <QDebug> struct product { @@ -193,29 +197,37 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : OstcFirmwareCheck::OstcFirmwareCheck(QString product) { QUrl url; - if (product == "OSTC 3") + if (product == "OSTC 3") { url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc3_changelog.txt"); - else if (product == "OSTC Sport") + latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc3_firmware.hex"); + } else if (product == "OSTC Sport") { url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_changelog.txt"); - else // not one of the known dive computers + latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_firmware.hex"); + } else { // not one of the known dive computers return; - hwVersionPage.mainFrame()->load(url); - connect(&hwVersionPage, SIGNAL(loadFinished(bool)), this, SLOT(parseOstcFwVersion())); + } + connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(parseOstcFwVersion(QNetworkReply *))); + QNetworkRequest download(url); + manager.get(download); } -void OstcFirmwareCheck::parseOstcFwVersion() +void OstcFirmwareCheck::parseOstcFwVersion(QNetworkReply *reply) { - QString parse = hwVersionPage.mainFrame()->toPlainText(); + QString parse = reply->readAll(); int firstOpenBracket = parse.indexOf('['); int firstCloseBracket = parse.indexOf(']'); latestFirmwareAvailable = parse.mid(firstOpenBracket + 1, firstCloseBracket - firstOpenBracket -1); qDebug() << "latest firmware available" << latestFirmwareAvailable; + disconnect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseOstcFwVersion(QNetworkReply*))); } -void OstcFirmwareCheck::checkLatest(QWidget *parent, uint32_t firmwareOnDevice) +void OstcFirmwareCheck::checkLatest(QWidget *_parent, device_data_t *data) { + devData = *data; + parent = _parent; // for now libdivecomputer gives us the firmware on device undecoded as integer // for the OSTC that means highbyte.lowbyte is the version number + int firmwareOnDevice = devData.libdc_firmware; QString firmware; firmware = QString("%1.%2").arg(firmwareOnDevice / 256). arg(firmwareOnDevice % 256); if (!latestFirmwareAvailable.isEmpty() && latestFirmwareAvailable != firmware) { @@ -229,14 +241,44 @@ void OstcFirmwareCheck::checkLatest(QWidget *parent, uint32_t firmwareOnDevice) response.setIcon(QMessageBox::Question); response.setWindowModality(Qt::WindowModal); int ret = response.exec(); - if (ret == QMessageBox::Accepted) { - qDebug() << "go to firmware upgrade"; - } else { - qDebug() << "no upgrade"; - } + if (ret == QMessageBox::Accepted) + upgradeFirmware(); } } +void OstcFirmwareCheck::upgradeFirmware() +{ + // start download of latestFirmwareHexFile + QString saveFileName = latestFirmwareHexFile; + saveFileName.replace("http://www.heinrichsweikamp.net/autofirmware/", ""); + saveFileName.replace("firmware", latestFirmwareAvailable); + QString filename = existing_filename ?: prefs.default_filename; + QFileInfo fi(filename); + filename = fi.absolutePath().append(QDir::separator()).append(saveFileName); + storeFirmware = QFileDialog::getSaveFileName(parent, tr("Save the downloaded firmware as"), + filename, tr("HEX files (*.hex)")); + if (storeFirmware.isEmpty()) + return; + + connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(saveOstcFirmware(QNetworkReply *))); + QNetworkRequest download(latestFirmwareHexFile); + manager.get(download); +} + +void OstcFirmwareCheck::saveOstcFirmware(QNetworkReply *reply) +{ + // firmware is downloaded + // call config->startFirmwareUpdate() with that file and the device data + + QByteArray firmwareData = reply->readAll(); + QFile file(storeFirmware); + file.open(QIODevice::WriteOnly); + file.write(firmwareData); + file.close(); + ConfigureDiveComputer *config = new ConfigureDiveComputer(MainWindow::instance()); + config->startFirmwareUpdate(storeFirmware, &devData); +} + ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog() { QSettings settings; @@ -1023,6 +1065,8 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked() } } + + void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow) { // Disable the buttons to do operations on this data diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index 3e3262df4..e36e88d1f 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -7,7 +7,7 @@ #include "../libdivecomputer.h" #include "configuredivecomputer.h" #include <QStyledItemDelegate> -#include <QWebPage> +#include <QNetworkAccessManager> class GasSpinBoxItemDelegate : public QStyledItemDelegate { @@ -107,13 +107,19 @@ class OstcFirmwareCheck : QObject Q_OBJECT public: explicit OstcFirmwareCheck(QString product); - void checkLatest(QWidget *parent, uint32_t firmwareOnDevice); + void checkLatest(QWidget *parent, device_data_t *data); public slots: - void parseOstcFwVersion(); + void parseOstcFwVersion(QNetworkReply *reply); + void saveOstcFirmware(QNetworkReply * reply); private: - QWebPage hwVersionPage; + void upgradeFirmware(); + device_data_t devData; QString latestFirmwareAvailable; + QString latestFirmwareHexFile; + QString storeFirmware; + QWidget *parent; + QNetworkAccessManager manager; }; #endif // CONFIGUREDIVECOMPUTERDIALOG_H diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 59a8139d6..95d8b79b7 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -404,7 +404,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished() MainWindow::instance()->dive_list()->selectDive(idx, true); QString dcName = data.devname; if (ostcFirmwareCheck) - ostcFirmwareCheck->checkLatest(this, data.libdc_firmware); + ostcFirmwareCheck->checkLatest(this, &data); } } else if (currentState == CANCELLING || currentState == CANCELLED) { if (import_thread_cancelled) { |