summaryrefslogtreecommitdiffstats
path: root/configuredivecomputerthreads.cpp
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2014-10-13 17:14:12 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-14 20:26:32 +0200
commitd7cae093bef23e9757c67172b5b5e11f2d4948dc (patch)
tree338e83a65c88d7365d6b1ef30822e0af48700e21 /configuredivecomputerthreads.cpp
parentc8eb2dccc5acbd11388373bf70edb2f4e73d2323 (diff)
downloadsubsurface-d7cae093bef23e9757c67172b5b5e11f2d4948dc.tar.gz
Check that the model is a supported one
This code adds some crude checks to verify that the device is a supported one before we actually read/write from it. This is to white/black-list devices so we don't write or read memory that we don't know anything about. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'configuredivecomputerthreads.cpp')
-rw-r--r--configuredivecomputerthreads.cpp69
1 files changed, 46 insertions, 23 deletions
diff --git a/configuredivecomputerthreads.cpp b/configuredivecomputerthreads.cpp
index 6f0ff9a93..902f0c90f 100644
--- a/configuredivecomputerthreads.cpp
+++ b/configuredivecomputerthreads.cpp
@@ -78,27 +78,12 @@ void ReadSettingsThread::run()
DeviceDetails *m_deviceDetails = new DeviceDetails(0);
switch (dc_device_get_type(m_data->device)) {
case DC_FAMILY_SUUNTO_VYPER:
- supported = true;
unsigned char data[SUUNTO_VYPER_CUSTOM_TEXT_LENGHT + 1];
- rc = dc_device_read(m_data->device, SUUNTO_VYPER_MAXDEPTH, data, 2);
- if (rc == DC_STATUS_SUCCESS) {
- // in ft * 128.0
- int depth = feet_to_mm(data[0] << 8 ^ data[1]) / 128;
- m_deviceDetails->setMaxDepth(depth);
- }
- rc = dc_device_read(m_data->device, SUUNTO_VYPER_TOTAL_TIME, data, 2);
- if (rc == DC_STATUS_SUCCESS) {
- int total_time = data[0] << 8 ^ data[1];
- m_deviceDetails->setTotalTime(total_time);
- }
- rc = dc_device_read(m_data->device, SUUNTO_VYPER_NUMBEROFDIVES, data, 2);
- if (rc == DC_STATUS_SUCCESS) {
- int number_of_dives = data[0] << 8 ^ data[1];
- m_deviceDetails->setNumberOfDives(number_of_dives);
- }
rc = dc_device_read(m_data->device, SUUNTO_VYPER_COMPUTER_TYPE, data, 1);
if (rc == DC_STATUS_SUCCESS) {
const char *model;
+ // FIXME: grab this info from libdivecomputer descriptor
+ // instead of hard coded here
switch(data[0]) {
case 0x03:
model = "Stinger";
@@ -106,23 +91,54 @@ void ReadSettingsThread::run()
case 0x04:
model = "Mosquito";
break;
- case 0x0A:
- model = "new Vyper";
+ case 0x05:
+ model = "D3";
break;
- case 0x0C:
- model = "Vyper or Cobra";
+ case 0x0A:
+ model = "Vyper";
break;
case 0x0B:
model = "Vytec";
break;
+ case 0x0C:
+ model = "Cobra";
+ break;
case 0x0D:
model = "Gekko";
break;
+ case 0x16:
+ model = "Zoop";
+ break;
+ case 20:
+ case 30:
+ case 60:
+ // Suunto Spyder have there sample interval at this position
+ // Fallthrough
default:
- model = "UNKNOWN";
+ supported = false;
+ goto unsupported_dc_error;
}
+ // We found a supported device
+ // we can safely proceed with reading/writing to this device.
+ supported = true;
m_deviceDetails->setModel(model);
}
+ rc = dc_device_read(m_data->device, SUUNTO_VYPER_MAXDEPTH, data, 2);
+ if (rc == DC_STATUS_SUCCESS) {
+ // in ft * 128.0
+ int depth = feet_to_mm(data[0] << 8 ^ data[1]) / 128;
+ m_deviceDetails->setMaxDepth(depth);
+ }
+ rc = dc_device_read(m_data->device, SUUNTO_VYPER_TOTAL_TIME, data, 2);
+ if (rc == DC_STATUS_SUCCESS) {
+ int total_time = data[0] << 8 ^ data[1];
+ m_deviceDetails->setTotalTime(total_time);
+ }
+ rc = dc_device_read(m_data->device, SUUNTO_VYPER_NUMBEROFDIVES, data, 2);
+ if (rc == DC_STATUS_SUCCESS) {
+ int number_of_dives = data[0] << 8 ^ data[1];
+ m_deviceDetails->setNumberOfDives(number_of_dives);
+ }
rc = dc_device_read(m_data->device, SUUNTO_VYPER_FIRMWARE, data, 1);
if (rc == DC_STATUS_SUCCESS) {
m_deviceDetails->setFirmwareVersion(QString::number(data[0]) + ".0.0");
@@ -429,6 +445,7 @@ void ReadSettingsThread::run()
supported = false;
break;
}
+unsupported_dc_error:
dc_device_close(m_data->device);
if (!supported) {
@@ -460,9 +477,15 @@ void WriteSettingsThread::run()
if (rc == DC_STATUS_SUCCESS) {
switch (dc_device_get_type(m_data->device)) {
case DC_FAMILY_SUUNTO_VYPER:
- supported = true;
unsigned char data;
unsigned char data2[2];
+ // Maybee we should read the model from the device to sanity check it here too..
+ // For now we just check that we actually read a device before writing to one.
+ if (m_deviceDetails->model() == "")
+ break;
+ else
+ supported = true;
+
dc_device_write(m_data->device, SUUNTO_VYPER_CUSTOM_TEXT,
// Convert the customText to a 30 char wide padded with " "
(const unsigned char *) QString("%1").arg(m_deviceDetails->customText(), -30, QChar(' ')).toUtf8().data(),