diff options
author | Anton Lundin <glance@acc.umu.se> | 2017-04-27 20:35:02 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-04 10:50:15 -0700 |
commit | 527763f306a34879d0a216f89da1befa9cbf8980 (patch) | |
tree | afb50afb5a8b04f30204aa6bfcb7f294f73c895a /core/configuredivecomputerthreads.cpp | |
parent | 4cbf64bf99c7b47a9368f9f03399164b397c2ec8 (diff) | |
download | subsurface-527763f306a34879d0a216f89da1befa9cbf8980.tar.gz |
Start to read/write and present some OSTC4 settings
This is mostly copy-paste from the ostc3 case, but there are some minor
differences. Some minor things have different meaning, and there's a
slightly different command set, but I couldn't figure out a sane way of
joining them.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Diffstat (limited to 'core/configuredivecomputerthreads.cpp')
-rw-r--r-- | core/configuredivecomputerthreads.cpp | 440 |
1 files changed, 438 insertions, 2 deletions
diff --git a/core/configuredivecomputerthreads.cpp b/core/configuredivecomputerthreads.cpp index cbd16611b..76890bbf7 100644 --- a/core/configuredivecomputerthreads.cpp +++ b/core/configuredivecomputerthreads.cpp @@ -363,23 +363,459 @@ static dc_status_t write_suunto_vyper_settings(dc_device_t *device, DeviceDetail static dc_status_t read_ostc4_settings(dc_device_t *device, DeviceDetails *m_deviceDetails, dc_event_callback_t progress_cb, void *userdata) { + // This code is really similar to the OSTC3 code, but there are minor + // differences in what the data means, and how to communicate with the + // device. If anyone can find a good way to harmonize the two, be my guest. dc_status_t rc = DC_STATUS_SUCCESS; dc_event_progress_t progress; progress.current = 0; - progress.maximum = 1; + progress.maximum = 19; unsigned char hardware[1]; EMIT_PROGRESS(); + //Read gas mixes + gas gas1; + gas gas2; + gas gas3; + gas gas4; + gas gas5; + unsigned char gasData[4] = { 0, 0, 0, 0 }; + + rc = hw_ostc3_device_config_read(device, OSTC3_GAS1, gasData, sizeof(gasData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + gas1.oxygen = gasData[0]; + gas1.helium = gasData[1]; + gas1.type = gasData[2]; + gas1.depth = gasData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_GAS2, gasData, sizeof(gasData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + gas2.oxygen = gasData[0]; + gas2.helium = gasData[1]; + gas2.type = gasData[2]; + gas2.depth = gasData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_GAS3, gasData, sizeof(gasData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + gas3.oxygen = gasData[0]; + gas3.helium = gasData[1]; + gas3.type = gasData[2]; + gas3.depth = gasData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_GAS4, gasData, sizeof(gasData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + gas4.oxygen = gasData[0]; + gas4.helium = gasData[1]; + gas4.type = gasData[2]; + gas4.depth = gasData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_GAS5, gasData, sizeof(gasData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + gas5.oxygen = gasData[0]; + gas5.helium = gasData[1]; + gas5.type = gasData[2]; + gas5.depth = gasData[3]; + EMIT_PROGRESS(); + + m_deviceDetails->gas1 = gas1; + m_deviceDetails->gas2 = gas2; + m_deviceDetails->gas3 = gas3; + m_deviceDetails->gas4 = gas4; + m_deviceDetails->gas5 = gas5; + EMIT_PROGRESS(); + + //Read Dil Values + gas dil1; + gas dil2; + gas dil3; + gas dil4; + gas dil5; + unsigned char dilData[4] = { 0, 0, 0, 0 }; + + rc = hw_ostc3_device_config_read(device, OSTC3_DIL1, dilData, sizeof(dilData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + dil1.oxygen = dilData[0]; + dil1.helium = dilData[1]; + dil1.type = dilData[2]; + dil1.depth = dilData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_DIL2, dilData, sizeof(dilData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + dil2.oxygen = dilData[0]; + dil2.helium = dilData[1]; + dil2.type = dilData[2]; + dil2.depth = dilData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_DIL3, dilData, sizeof(dilData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + dil3.oxygen = dilData[0]; + dil3.helium = dilData[1]; + dil3.type = dilData[2]; + dil3.depth = dilData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_DIL4, dilData, sizeof(dilData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + dil4.oxygen = dilData[0]; + dil4.helium = dilData[1]; + dil4.type = dilData[2]; + dil4.depth = dilData[3]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_DIL5, dilData, sizeof(dilData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + dil5.oxygen = dilData[0]; + dil5.helium = dilData[1]; + dil5.type = dilData[2]; + dil5.depth = dilData[3]; + EMIT_PROGRESS(); + + m_deviceDetails->dil1 = dil1; + m_deviceDetails->dil2 = dil2; + m_deviceDetails->dil3 = dil3; + m_deviceDetails->dil4 = dil4; + m_deviceDetails->dil5 = dil5; + + //Read setpoint Values + setpoint sp1; + setpoint sp2; + setpoint sp3; + setpoint sp4; + setpoint sp5; + unsigned char spData[4] = { 0, 0, 0, 0}; + + rc = hw_ostc3_device_config_read(device, OSTC3_SP1, spData, sizeof(spData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + sp1.sp = spData[0]; + sp1.depth = spData[1]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_SP2, spData, sizeof(spData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + sp2.sp = spData[0]; + sp2.depth = spData[1]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_SP3, spData, sizeof(spData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + sp3.sp = spData[0]; + sp3.depth = spData[1]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_SP4, spData, sizeof(spData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + sp4.sp = spData[0]; + sp4.depth = spData[1]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_SP5, spData, sizeof(spData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + sp5.sp = spData[0]; + sp5.depth = spData[1]; + EMIT_PROGRESS(); + + m_deviceDetails->sp1 = sp1; + m_deviceDetails->sp2 = sp2; + m_deviceDetails->sp3 = sp3; + m_deviceDetails->sp4 = sp4; + m_deviceDetails->sp5 = sp5; + + //Read other settings + unsigned char uData[4] = { 0 }; + +#define READ_SETTING(_OSTC4_SETTING, _DEVICE_DETAIL) \ + do { \ + rc = hw_ostc3_device_config_read(device, _OSTC4_SETTING, uData, sizeof(uData)); \ + if (rc != DC_STATUS_SUCCESS) \ + return rc; \ + m_deviceDetails->_DEVICE_DETAIL = uData[0]; \ + EMIT_PROGRESS(); \ + } while (0) + +#undef READ_SETTING + + rc = hw_ostc3_device_config_read(device, OSTC3_PRESSURE_SENSOR_OFFSET, uData, sizeof(uData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + // OSTC3 stores the pressureSensorOffset in two-complement + m_deviceDetails->pressureSensorOffset = (signed char)uData[0]; + EMIT_PROGRESS(); + + rc = hw_ostc3_device_config_read(device, OSTC3_TEMP_SENSOR_OFFSET, uData, sizeof(uData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + // OSTC3 stores the tempSensorOffset in two-complement + m_deviceDetails->tempSensorOffset = (signed char)uData[0]; + EMIT_PROGRESS(); + + //read firmware settings + unsigned char fData[64] = { 0 }; + rc = hw_ostc3_device_version(device, fData, sizeof(fData)); + if (rc != DC_STATUS_SUCCESS) + return rc; + int serial = fData[0] + (fData[1] << 8); + m_deviceDetails->serialNo = QString::number(serial); + unsigned char X, Y, Z, beta; + unsigned int firmwareOnDevice = (fData[3] << 8) + fData[2]; + X = (firmwareOnDevice & 0xF800) >> 11; + Y = (firmwareOnDevice & 0x07C0) >> 6; + Z = (firmwareOnDevice & 0x003E) >> 1; + beta = firmwareOnDevice & 0x0001; + m_deviceDetails->firmwareVersion = QString("%1.%2.%3%4").arg(X).arg(Y).arg(Z).arg(beta?" beta":""); + QByteArray ar((char *)fData + 4, 60); + m_deviceDetails->customText = ar.trimmed(); + EMIT_PROGRESS(); + return rc; } static dc_status_t write_ostc4_settings(dc_device_t *device, DeviceDetails *m_deviceDetails, dc_event_callback_t progress_cb, void *userdata) { + // This code is really similar to the OSTC3 code, but there are minor + // differences in what the data means, and how to communicate with the + // device. If anyone can find a good way to harmonize the two, be my guest. dc_status_t rc = DC_STATUS_SUCCESS; dc_event_progress_t progress; progress.current = 0; - progress.maximum = 1; + progress.maximum = 18; + + //write gas values + unsigned char gas1Data[4] = { + m_deviceDetails->gas1.oxygen, + m_deviceDetails->gas1.helium, + m_deviceDetails->gas1.type, + m_deviceDetails->gas1.depth + }; + + unsigned char gas2Data[4] = { + m_deviceDetails->gas2.oxygen, + m_deviceDetails->gas2.helium, + m_deviceDetails->gas2.type, + m_deviceDetails->gas2.depth + }; + + unsigned char gas3Data[4] = { + m_deviceDetails->gas3.oxygen, + m_deviceDetails->gas3.helium, + m_deviceDetails->gas3.type, + m_deviceDetails->gas3.depth + }; + + unsigned char gas4Data[4] = { + m_deviceDetails->gas4.oxygen, + m_deviceDetails->gas4.helium, + m_deviceDetails->gas4.type, + m_deviceDetails->gas4.depth + }; + + unsigned char gas5Data[4] = { + m_deviceDetails->gas5.oxygen, + m_deviceDetails->gas5.helium, + m_deviceDetails->gas5.type, + m_deviceDetails->gas5.depth + }; + //gas 1 + rc = hw_ostc3_device_config_write(device, OSTC3_GAS1, gas1Data, sizeof(gas1Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //gas 2 + rc = hw_ostc3_device_config_write(device, OSTC3_GAS2, gas2Data, sizeof(gas2Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //gas 3 + rc = hw_ostc3_device_config_write(device, OSTC3_GAS3, gas3Data, sizeof(gas3Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //gas 4 + rc = hw_ostc3_device_config_write(device, OSTC3_GAS4, gas4Data, sizeof(gas4Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //gas 5 + rc = hw_ostc3_device_config_write(device, OSTC3_GAS5, gas5Data, sizeof(gas5Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + + //write setpoint values + unsigned char sp1Data[4] = { + m_deviceDetails->sp1.sp, + m_deviceDetails->sp1.depth + }; + + unsigned char sp2Data[4] = { + m_deviceDetails->sp2.sp, + m_deviceDetails->sp2.depth + }; + + unsigned char sp3Data[4] = { + m_deviceDetails->sp3.sp, + m_deviceDetails->sp3.depth + }; + + unsigned char sp4Data[4] = { + m_deviceDetails->sp4.sp, + m_deviceDetails->sp4.depth + }; + + unsigned char sp5Data[4] = { + m_deviceDetails->sp5.sp, + m_deviceDetails->sp5.depth + }; + + //sp 1 + rc = hw_ostc3_device_config_write(device, OSTC3_SP1, sp1Data, sizeof(sp1Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //sp 2 + rc = hw_ostc3_device_config_write(device, OSTC3_SP2, sp2Data, sizeof(sp2Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //sp 3 + rc = hw_ostc3_device_config_write(device, OSTC3_SP3, sp3Data, sizeof(sp3Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //sp 4 + rc = hw_ostc3_device_config_write(device, OSTC3_SP4, sp4Data, sizeof(sp4Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //sp 5 + rc = hw_ostc3_device_config_write(device, OSTC3_SP5, sp5Data, sizeof(sp5Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + + //write dil values + unsigned char dil1Data[4] = { + m_deviceDetails->dil1.oxygen, + m_deviceDetails->dil1.helium, + m_deviceDetails->dil1.type, + m_deviceDetails->dil1.depth + }; + + unsigned char dil2Data[4] = { + m_deviceDetails->dil2.oxygen, + m_deviceDetails->dil2.helium, + m_deviceDetails->dil2.type, + m_deviceDetails->dil2.depth + }; + + unsigned char dil3Data[4] = { + m_deviceDetails->dil3.oxygen, + m_deviceDetails->dil3.helium, + m_deviceDetails->dil3.type, + m_deviceDetails->dil3.depth + }; + + unsigned char dil4Data[4] = { + m_deviceDetails->dil4.oxygen, + m_deviceDetails->dil4.helium, + m_deviceDetails->dil4.type, + m_deviceDetails->dil4.depth + }; + + unsigned char dil5Data[4] = { + m_deviceDetails->dil5.oxygen, + m_deviceDetails->dil5.helium, + m_deviceDetails->dil5.type, + m_deviceDetails->dil5.depth + }; + //dil 1 + rc = hw_ostc3_device_config_write(device, OSTC3_DIL1, dil1Data, sizeof(gas1Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //dil 2 + rc = hw_ostc3_device_config_write(device, OSTC3_DIL2, dil2Data, sizeof(dil2Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //dil 3 + rc = hw_ostc3_device_config_write(device, OSTC3_DIL3, dil3Data, sizeof(dil3Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //dil 4 + rc = hw_ostc3_device_config_write(device, OSTC3_DIL4, dil4Data, sizeof(dil4Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + //dil 5 + rc = hw_ostc3_device_config_write(device, OSTC3_DIL5, dil5Data, sizeof(dil5Data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + + //write general settings + //custom text + rc = hw_ostc3_device_customtext(device, m_deviceDetails->customText.toUtf8().data()); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + + unsigned char data[4] = { 0 }; +#define WRITE_SETTING(_OSTC4_SETTING, _DEVICE_DETAIL) \ + do { \ + data[0] = m_deviceDetails->_DEVICE_DETAIL; \ + rc = hw_ostc3_device_config_write(device, _OSTC4_SETTING, data, sizeof(data)); \ + if (rc != DC_STATUS_SUCCESS) \ + return rc; \ + EMIT_PROGRESS(); \ + } while (0) + +#undef WRITE_SETTING + + // OSTC3 stores the pressureSensorOffset in two-complement + data[0] = (unsigned char)m_deviceDetails->pressureSensorOffset; + rc = hw_ostc3_device_config_write(device, OSTC3_PRESSURE_SENSOR_OFFSET, data, sizeof(data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + + // OSTC3 stores the tempSensorOffset in two-complement + data[0] = (unsigned char)m_deviceDetails->tempSensorOffset; + rc = hw_ostc3_device_config_write(device, OSTC3_TEMP_SENSOR_OFFSET, data, sizeof(data)); + if (rc != DC_STATUS_SUCCESS) + return rc; + EMIT_PROGRESS(); + + + //sync date and time + if (m_deviceDetails->syncTime) { + dc_datetime_t now; + dc_datetime_localtime(&now, dc_datetime_now()); + + rc = hw_ostc3_device_clock(device, &now); + } EMIT_PROGRESS(); |