mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Lift code out to read_ostc_settings
This lifts the reading of settings out of the run() method and introduces better error handling when libdivecomputer returns a error. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3655a726c2
commit
89e197a16b
1 changed files with 314 additions and 301 deletions
|
@ -547,52 +547,17 @@ static dc_status_t read_ostc3_settings(dc_device_t *device, DeviceDetails *m_dev
|
|||
return rc;
|
||||
}
|
||||
|
||||
void ReadSettingsThread::run()
|
||||
static dc_status_t read_ostc_settings(dc_device_t *device, DeviceDetails *m_deviceDetails)
|
||||
{
|
||||
bool supported = false;
|
||||
dc_status_t rc;
|
||||
#ifdef DEBUG_OSTC
|
||||
if (strcmp(m_data->vendor, "Heinrichs Weikamp") == 0 && strcmp(m_data->product, "OSTC 2N") == 0)
|
||||
rc = DC_STATUS_SUCCESS;
|
||||
else
|
||||
#endif
|
||||
rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
DeviceDetails *m_deviceDetails = new DeviceDetails(0);
|
||||
switch (dc_device_get_type(m_data->device)) {
|
||||
case DC_FAMILY_SUUNTO_VYPER:
|
||||
rc = read_suunto_vyper_settings(m_data->device, m_deviceDetails);
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
supported = true;
|
||||
emit devicedetails(m_deviceDetails);
|
||||
} else if (rc == DC_STATUS_UNSUPPORTED) {
|
||||
supported = false;
|
||||
} else {
|
||||
emit error("Failed!");
|
||||
}
|
||||
break;
|
||||
#if DC_VERSION_CHECK(0, 5, 0)
|
||||
case DC_FAMILY_HW_OSTC3:
|
||||
supported = true;
|
||||
rc = read_ostc3_settings(m_data->device, m_deviceDetails);
|
||||
if (rc == DC_STATUS_SUCCESS)
|
||||
emit devicedetails(m_deviceDetails);
|
||||
else
|
||||
emit error("Failed!");
|
||||
break;
|
||||
#endif // divecomputer 0.5.0
|
||||
#ifdef DEBUG_OSTC
|
||||
case DC_FAMILY_NULL:
|
||||
#endif
|
||||
case DC_FAMILY_HW_OSTC: {
|
||||
supported = true;
|
||||
unsigned char data[256] = {};
|
||||
#ifdef DEBUG_OSTC_CF
|
||||
// FIXME: how should we report settings not supported back?
|
||||
unsigned char max_CF = 0;
|
||||
#endif
|
||||
rc = hw_ostc_device_eeprom_read(m_data->device, 0, data, sizeof(data));
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
rc = hw_ostc_device_eeprom_read(device, 0, data, sizeof(data));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
m_deviceDetails->setSerialNo(QString::number(data[1] << 8 ^ data[0]));
|
||||
m_deviceDetails->setNumberOfDives(data[3] << 8 ^ data[2]);
|
||||
//Byte5-6:
|
||||
|
@ -832,9 +797,10 @@ void ReadSettingsThread::run()
|
|||
for (int cf = 0; cf <= 31 && cf <= max_CF; cf++)
|
||||
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
||||
#endif
|
||||
}
|
||||
rc = hw_ostc_device_eeprom_read(m_data->device, 1, data, sizeof(data));
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
|
||||
rc = hw_ostc_device_eeprom_read(device, 1, data, sizeof(data));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
// Byte1:
|
||||
// Logbook version indicator (Not writable!)
|
||||
// Byte2-3:
|
||||
|
@ -856,13 +822,15 @@ void ReadSettingsThread::run()
|
|||
m_deviceDetails->setGfHigh(read_ostc_cf(data, 33));
|
||||
// CF58: Future time to surface setFutureTTS
|
||||
m_deviceDetails->setFutureTTS(read_ostc_cf(data, 58));
|
||||
|
||||
#ifdef DEBUG_OSTC_CF
|
||||
for (int cf = 32; cf <= 63 && cf <= max_CF; cf++)
|
||||
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
||||
#endif
|
||||
}
|
||||
rc = hw_ostc_device_eeprom_read(m_data->device, 2, data, sizeof(data));
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
|
||||
rc = hw_ostc_device_eeprom_read(device, 2, data, sizeof(data));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
// Byte1-4:
|
||||
// not used/reserved (Not writable!)
|
||||
// Byte5-128:
|
||||
|
@ -883,10 +851,55 @@ void ReadSettingsThread::run()
|
|||
for (int cf = 64; cf <= 95 && cf <= max_CF; cf++)
|
||||
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ReadSettingsThread::run()
|
||||
{
|
||||
bool supported = false;
|
||||
dc_status_t rc;
|
||||
#ifdef DEBUG_OSTC
|
||||
if (strcmp(m_data->vendor, "Heinrichs Weikamp") == 0 && strcmp(m_data->product, "OSTC 2N") == 0)
|
||||
rc = DC_STATUS_SUCCESS;
|
||||
else
|
||||
#endif
|
||||
rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
DeviceDetails *m_deviceDetails = new DeviceDetails(0);
|
||||
switch (dc_device_get_type(m_data->device)) {
|
||||
case DC_FAMILY_SUUNTO_VYPER:
|
||||
rc = read_suunto_vyper_settings(m_data->device, m_deviceDetails);
|
||||
if (rc == DC_STATUS_SUCCESS) {
|
||||
supported = true;
|
||||
emit devicedetails(m_deviceDetails);
|
||||
break;
|
||||
} else if (rc == DC_STATUS_UNSUPPORTED) {
|
||||
supported = false;
|
||||
} else {
|
||||
emit error("Failed!");
|
||||
}
|
||||
break;
|
||||
#if DC_VERSION_CHECK(0, 5, 0)
|
||||
case DC_FAMILY_HW_OSTC3:
|
||||
supported = true;
|
||||
rc = read_ostc3_settings(m_data->device, m_deviceDetails);
|
||||
if (rc == DC_STATUS_SUCCESS)
|
||||
emit devicedetails(m_deviceDetails);
|
||||
else
|
||||
emit error("Failed!");
|
||||
break;
|
||||
#endif // divecomputer 0.5.0
|
||||
#ifdef DEBUG_OSTC
|
||||
case DC_FAMILY_NULL:
|
||||
#endif
|
||||
case DC_FAMILY_HW_OSTC:
|
||||
supported = true;
|
||||
rc = read_ostc_settings(m_data->device, m_deviceDetails);
|
||||
if (rc == DC_STATUS_SUCCESS)
|
||||
emit devicedetails(m_deviceDetails);
|
||||
else
|
||||
emit error("Failed!");
|
||||
break;
|
||||
default:
|
||||
supported = false;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue