mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +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;
|
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;
|
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] = {};
|
unsigned char data[256] = {};
|
||||||
#ifdef DEBUG_OSTC_CF
|
#ifdef DEBUG_OSTC_CF
|
||||||
// FIXME: how should we report settings not supported back?
|
// FIXME: how should we report settings not supported back?
|
||||||
unsigned char max_CF = 0;
|
unsigned char max_CF = 0;
|
||||||
#endif
|
#endif
|
||||||
rc = hw_ostc_device_eeprom_read(m_data->device, 0, data, sizeof(data));
|
rc = hw_ostc_device_eeprom_read(device, 0, data, sizeof(data));
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
|
return rc;
|
||||||
m_deviceDetails->setSerialNo(QString::number(data[1] << 8 ^ data[0]));
|
m_deviceDetails->setSerialNo(QString::number(data[1] << 8 ^ data[0]));
|
||||||
m_deviceDetails->setNumberOfDives(data[3] << 8 ^ data[2]);
|
m_deviceDetails->setNumberOfDives(data[3] << 8 ^ data[2]);
|
||||||
//Byte5-6:
|
//Byte5-6:
|
||||||
|
@ -832,9 +797,10 @@ void ReadSettingsThread::run()
|
||||||
for (int cf = 0; cf <= 31 && cf <= max_CF; cf++)
|
for (int cf = 0; cf <= 31 && cf <= max_CF; cf++)
|
||||||
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
rc = hw_ostc_device_eeprom_read(m_data->device, 1, data, sizeof(data));
|
rc = hw_ostc_device_eeprom_read(device, 1, data, sizeof(data));
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
|
return rc;
|
||||||
// Byte1:
|
// Byte1:
|
||||||
// Logbook version indicator (Not writable!)
|
// Logbook version indicator (Not writable!)
|
||||||
// Byte2-3:
|
// Byte2-3:
|
||||||
|
@ -856,13 +822,15 @@ void ReadSettingsThread::run()
|
||||||
m_deviceDetails->setGfHigh(read_ostc_cf(data, 33));
|
m_deviceDetails->setGfHigh(read_ostc_cf(data, 33));
|
||||||
// CF58: Future time to surface setFutureTTS
|
// CF58: Future time to surface setFutureTTS
|
||||||
m_deviceDetails->setFutureTTS(read_ostc_cf(data, 58));
|
m_deviceDetails->setFutureTTS(read_ostc_cf(data, 58));
|
||||||
|
|
||||||
#ifdef DEBUG_OSTC_CF
|
#ifdef DEBUG_OSTC_CF
|
||||||
for (int cf = 32; cf <= 63 && cf <= max_CF; cf++)
|
for (int cf = 32; cf <= 63 && cf <= max_CF; cf++)
|
||||||
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
rc = hw_ostc_device_eeprom_read(m_data->device, 2, data, sizeof(data));
|
rc = hw_ostc_device_eeprom_read(device, 2, data, sizeof(data));
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
|
return rc;
|
||||||
// Byte1-4:
|
// Byte1-4:
|
||||||
// not used/reserved (Not writable!)
|
// not used/reserved (Not writable!)
|
||||||
// Byte5-128:
|
// Byte5-128:
|
||||||
|
@ -883,10 +851,55 @@ void ReadSettingsThread::run()
|
||||||
for (int cf = 64; cf <= 95 && cf <= max_CF; cf++)
|
for (int cf = 64; cf <= 95 && cf <= max_CF; cf++)
|
||||||
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
printf("CF %d: %d\n", cf, read_ostc_cf(data, cf));
|
||||||
#endif
|
#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);
|
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:
|
default:
|
||||||
supported = false;
|
supported = false;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue