Skip to content

Commit

Permalink
Shearwater: Fix Sensor Calibration for DiveCAN Controllers.
Browse files Browse the repository at this point in the history
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 <github@ike.ch>
  • Loading branch information
mikeller committed Apr 28, 2024
1 parent ca55a11 commit 52cdaa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
7 changes: 5 additions & 2 deletions src/shearwater_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 3 additions & 20 deletions src/shearwater_predator_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 52cdaa3

Please sign in to comment.