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>
This commit is contained in:
Joseph W. Joshua 2014-06-23 18:16:27 +03:00 committed by Thiago Macieira
parent 8aa7fddb22
commit cc6c385f33
7 changed files with 94 additions and 14 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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

View file

@ -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);
}
}

View file

@ -33,6 +33,8 @@ private slots:
void on_tabWidget_currentChanged(int index);
void on_updateFirmwareButton_clicked();
private:
Ui::ConfigureDiveComputerDialog *ui;

View file

@ -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>