aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joseph W. Joshua <joejoshw@gmail.com>2014-06-23 18:16:27 +0300
committerGravatar Thiago Macieira <thiago@macieira.org>2014-08-13 10:48:15 -0700
commitcc6c385f3309417727f61b55550d6d47bef004dd (patch)
tree2b86c64b388ad7005cbf952bc3c93ef9abcbb1d3
parent8aa7fddb22cd6ab4d533082598be04649bb1ff21 (diff)
downloadsubsurface-cc6c385f3309417727f61b55550d6d47bef004dd.tar.gz
Start Work on Firmware Update
This patch implements the first step towards OSTC 3 firmware update. Its not much, just file selection, but I will build up on it from there. Implements a thread to initiate firmware updates. Currently, this is for the OSTC 3. Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Thiago Macieira <thiago@macieira.org>
-rw-r--r--configuredivecomputer.cpp15
-rw-r--r--configuredivecomputer.h1
-rw-r--r--configuredivecomputerthreads.cpp32
-rw-r--r--configuredivecomputerthreads.h22
-rw-r--r--qt-ui/configuredivecomputerdialog.cpp25
-rw-r--r--qt-ui/configuredivecomputerdialog.h2
-rw-r--r--qt-ui/configuredivecomputerdialog.ui11
7 files changed, 94 insertions, 14 deletions
diff --git a/configuredivecomputer.cpp b/configuredivecomputer.cpp
index 657f6fd10..c7b0ccbe9 100644
--- a/configuredivecomputer.cpp
+++ b/configuredivecomputer.cpp
@@ -24,10 +24,10 @@ void ConfigureDiveComputer::readSettings(device_data_t *data)
readThread->deleteLater();
readThread = new ReadSettingsThread(this, data);
- connect (readThread, SIGNAL(finished()),
+ connect(readThread, SIGNAL(finished()),
this, SLOT(readThreadFinished()), Qt::QueuedConnection);
- connect (readThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
- connect (readThread, SIGNAL(devicedetails(DeviceDetails*)), this,
+ connect(readThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
+ connect(readThread, SIGNAL(devicedetails(DeviceDetails*)), this,
SIGNAL(deviceDetailsChanged(DeviceDetails*)));
readThread->start();
@@ -41,9 +41,9 @@ void ConfigureDiveComputer::saveDeviceDetails(DeviceDetails *details, device_dat
writeThread->deleteLater();
writeThread = new WriteSettingsThread(this, data);
- connect (writeThread, SIGNAL(finished()),
+ connect(writeThread, SIGNAL(finished()),
this, SLOT(writeThreadFinished()), Qt::QueuedConnection);
- connect (writeThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
+ connect(writeThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
writeThread->setDeviceDetails(details);
writeThread->start();
@@ -417,6 +417,11 @@ bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *de
return true;
}
+void ConfigureDiveComputer::startFirmwareUpdate(QString fileName, device_data_t *data, QString errorText)
+{
+
+}
+
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
{
currentState = newState;
diff --git a/configuredivecomputer.h b/configuredivecomputer.h
index 31c0cb756..f64c9c95d 100644
--- a/configuredivecomputer.h
+++ b/configuredivecomputer.h
@@ -34,6 +34,7 @@ public:
void fetchDeviceDetails();
bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText);
bool restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText);
+ void startFirmwareUpdate(QString fileName, device_data_t *data, QString errorText);
signals:
void message(QString msg);
void error(QString err);
diff --git a/configuredivecomputerthreads.cpp b/configuredivecomputerthreads.cpp
index 66506affd..52f946179 100644
--- a/configuredivecomputerthreads.cpp
+++ b/configuredivecomputerthreads.cpp
@@ -467,3 +467,35 @@ void WriteSettingsThread::run()
emit error(lastError);
}
}
+
+
+FirmwareUpdateThread::FirmwareUpdateThread(QObject *parent, device_data_t *data, QString fileName)
+: QThread(parent), m_data(data), m_fileName(fileName)
+{
+
+}
+
+void FirmwareUpdateThread::run()
+{
+ bool supported = false;
+ dc_status_t rc;
+ rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
+ if (rc == DC_STATUS_SUCCESS) {
+ switch (dc_device_get_type(m_data->device)) {
+ case DC_FAMILY_HW_OSTC3:
+ supported = true;
+ //hw_ostc3_device_fwupdate(m_data->device, m_fileName.toUtf8().data());
+ break;
+ }
+ dc_device_close(m_data->device);
+
+ if (!supported) {
+ lastError = tr("This feature is not yet available for the selected dive computer.");
+ emit error(lastError);
+ }
+ }
+ else {
+ lastError = tr("Could not a establish connection to the dive computer.");
+ emit error(lastError);
+ }
+}
diff --git a/configuredivecomputerthreads.h b/configuredivecomputerthreads.h
index db54db460..66df7a93b 100644
--- a/configuredivecomputerthreads.h
+++ b/configuredivecomputerthreads.h
@@ -8,7 +8,8 @@
#include <QDateTime>
#include "devicedetails.h"
-class ReadSettingsThread : public QThread {
+class ReadSettingsThread : public QThread
+{
Q_OBJECT
public:
ReadSettingsThread(QObject *parent, device_data_t *data);
@@ -22,7 +23,8 @@ private:
device_data_t *m_data;
};
-class WriteSettingsThread : public QThread {
+class WriteSettingsThread : public QThread
+{
Q_OBJECT
public:
WriteSettingsThread(QObject *parent, device_data_t *data);
@@ -37,4 +39,20 @@ private:
DeviceDetails *m_deviceDetails;
};
+class FirmwareUpdateThread : public QThread
+{
+ Q_OBJECT
+public:
+ FirmwareUpdateThread(QObject *parent, device_data_t *data, QString fileName);
+ virtual void run();
+ QString lastError;
+signals:
+ void progress(int percent);
+ void message(QString msg);
+ void error(QString err);
+private:
+ device_data_t *m_data;
+ QString m_fileName;
+};
+
#endif // CONFIGUREDIVECOMPUTERTHREADS_H
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp
index 81d8f0326..733d64a4f 100644
--- a/qt-ui/configuredivecomputerdialog.cpp
+++ b/qt-ui/configuredivecomputerdialog.cpp
@@ -38,12 +38,12 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
deviceDetails = new DeviceDetails(this);
config = new ConfigureDiveComputer(this);
- connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
- connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
- connect (config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished()));
- connect (config, SIGNAL(deviceDetailsChanged(DeviceDetails*)),
+ connect(config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
+ connect(config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
+ connect(config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished()));
+ connect(config, SIGNAL(deviceDetailsChanged(DeviceDetails*)),
this, SLOT(deviceDetailsReceived(DeviceDetails*)));
- connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
+ connect(ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
memset(&device_data, 0, sizeof(device_data));
fill_computer_list();
@@ -451,3 +451,18 @@ void ConfigureDiveComputerDialog::on_tabWidget_currentChanged(int index)
dcType = DC_TYPE_UEMIS;
fill_device_list(dcType);
}
+
+void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
+{
+ QString filename = existing_filename ?: prefs.default_filename;
+ QFileInfo fi(filename);
+ filename = fi.absolutePath();
+ QString firmwarePath = QFileDialog::getOpenFileName(this, tr("Select firmware file"),
+ filename, tr("All files (*.*)")
+ );
+ if (!firmwarePath.isEmpty()) {
+ getDeviceData();
+ QString errText;
+ config->startFirmwareUpdate(firmwarePath, &device_data, errText);
+ }
+}
diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h
index de068c609..71266c471 100644
--- a/qt-ui/configuredivecomputerdialog.h
+++ b/qt-ui/configuredivecomputerdialog.h
@@ -33,6 +33,8 @@ private slots:
void on_tabWidget_currentChanged(int index);
+ void on_updateFirmwareButton_clicked();
+
private:
Ui::ConfigureDiveComputerDialog *ui;
diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui
index 4274a3abe..d0dd91155 100644
--- a/qt-ui/configuredivecomputerdialog.ui
+++ b/qt-ui/configuredivecomputerdialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>787</width>
- <height>672</height>
+ <width>785</width>
+ <height>670</height>
</rect>
</property>
<property name="windowTitle">
@@ -89,6 +89,13 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QPushButton" name="updateFirmwareButton">
+ <property name="text">
+ <string>Update Firmware</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>