From 6e65428fc83ddd29ce1bc8b6abea6b7c2a1042c5 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sun, 28 Apr 2024 21:24:28 +1200 Subject: [PATCH 1/2] Shearwater: Fix Sensor Calibration for DiveCAN Controllers. Remove the code that forces hiding of O2 sensor readings despite the sensors being reported as properly calibrated by the divecomputer. This fixes the problem of no sensor readings showing on DiveCAN controllers due to the fact that the sensor calibration values are returned as defaults on these devices. Also increase the timeout for data reads - this seems to improve the reliability when reading logs of long dives. Signed-off-by: Michael Keller --- src/shearwater_common.c | 7 +++++-- src/shearwater_predator_parser.c | 23 +++-------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index 211be4f9..1b06cefd 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -58,8 +58,8 @@ shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *conte return status; } - // Set the timeout for receiving data (3000ms). - status = dc_iostream_set_timeout (device->iostream, 3000); + // Set the timeout for receiving data (12s). + status = dc_iostream_set_timeout (device->iostream, 12 * 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); return status; @@ -696,6 +696,9 @@ dc_status_t shearwater_common_get_model(shearwater_common_device_t *device, unsi // Convert and map to the model number. unsigned int hardware = array_uint16_be (rsp_hardware); + + DEBUG(device->base.context, "Hardware type: 0x%04x", hardware); + switch (hardware) { case 0x0101: case 0x0202: diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 1b184a41..cce1a4fa 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -418,7 +418,6 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) dc_parser_t *abstract = (dc_parser_t *) parser; const unsigned char *data = parser->base.data; unsigned int size = parser->base.size; - const char *ppo2_source = NULL; if (parser->cached) { return DC_STATUS_SUCCESS; @@ -728,7 +727,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) dc_field_add_string_fmt(&parser->cache, "Logversion", "%d%s", logversion, pnf ? "(PNF)" : ""); // Cache sensor calibration for later use - unsigned int nsensors = 0, ndefaults = 0; + unsigned int nsensors = 0; unsigned int base = parser->opening[3] + (pnf ? 6 : 86); for (size_t i = 0; i < 3; ++i) { unsigned int calibration = array_uint16_be(data + base + 1 + i * 2); @@ -741,25 +740,11 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) parser->calibration[i] *= 2.2; } if (data[base] & (1 << i)) { - if (calibration == 2100) { - ndefaults++; - } nsensors++; } } - if (nsensors && nsensors == ndefaults) { - // If all (calibrated) sensors still have their factory default - // calibration values (2100), they are probably not calibrated - // properly. To avoid returning incorrect ppO2 values to the - // application, they are manually disabled (e.g. marked as - // uncalibrated). - WARNING (abstract->context, "Disabled all O2 sensors due to a default calibration value."); - parser->calibrated = 0; - ppo2_source = "voted/averaged"; - } else { - parser->calibrated = data[base]; - ppo2_source = "cells"; - } + + parser->calibrated = data[base]; // Get the dive mode from the header (if available). if (logversion >= 8) { @@ -830,8 +815,6 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) case M_CC: case M_CC2: DC_ASSIGN_FIELD(parser->cache, DIVEMODE, DC_DIVEMODE_CCR); - if (ppo2_source) - dc_field_add_string(&parser->cache, "PPO2 source", ppo2_source); break; case M_SC: DC_ASSIGN_FIELD(parser->cache, DIVEMODE, DC_DIVEMODE_SCR); From a7fb341fb027c33e5a19be7924b24d30d49e2f3e Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sat, 4 May 2024 02:02:19 +1200 Subject: [PATCH 2/2] Shearwater: Add Sensor Calibration Info. Add the calibration values for ppO2 sonsors in CCR mode as extra info fields. Signed-off-by: Michael Keller --- src/shearwater_predator_parser.c | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index cce1a4fa..79881d2d 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -727,25 +727,31 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) dc_field_add_string_fmt(&parser->cache, "Logversion", "%d%s", logversion, pnf ? "(PNF)" : ""); // Cache sensor calibration for later use - unsigned int nsensors = 0; unsigned int base = parser->opening[3] + (pnf ? 6 : 86); + parser->calibrated = data[base]; + for (size_t i = 0; i < 3; ++i) { - unsigned int calibration = array_uint16_be(data + base + 1 + i * 2); - parser->calibration[i] = calibration / 100000.0; - if (parser->model == PREDATOR) { - // The Predator expects the mV output of the cells to be - // within 30mV to 70mV in 100% O2 at 1 atmosphere. If the - // calibration value is scaled with a factor 2.2, then the - // sensors lines up and matches the average. - parser->calibration[i] *= 2.2; - } - if (data[base] & (1 << i)) { - nsensors++; + if (parser->calibrated & (1 << i)) { + unsigned int calibration = array_uint16_be(data + base + 1 + i * 2); + parser->calibration[i] = calibration / 100000.0; + if (parser->model == PREDATOR) { + // The Predator expects the mV output of the cells to be + // within 30mV to 70mV in 100% O2 at 1 atmosphere. If the + // calibration value is scaled with a factor 2.2, then the + // sensors lines up and matches the average. + parser->calibration[i] *= 2.2; + } + + static const char *name[] = { + "Sensor 1 calibration [bar / V]", + "Sensor 2 calibration [bar / V]", + "Sensor 3 calibration [bar / V]", + }; + dc_field_add_string_fmt(&parser->cache, name[i], "%.2f", parser->calibration[i] * 1000); + } } - parser->calibrated = data[base]; - // Get the dive mode from the header (if available). if (logversion >= 8) { divemode = data[parser->opening[4] + (pnf ? 1 : 112)];