Merge pull request #59 from mikeller/fix_shearwater_sensor_calibration
This commit is contained in:
commit
6bd1183c34
@ -58,8 +58,8 @@ shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *conte
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the timeout for receiving data (3000ms).
|
// Set the timeout for receiving data (12s).
|
||||||
status = dc_iostream_set_timeout (device->iostream, 3000);
|
status = dc_iostream_set_timeout (device->iostream, 12 * 1000);
|
||||||
if (status != DC_STATUS_SUCCESS) {
|
if (status != DC_STATUS_SUCCESS) {
|
||||||
ERROR (context, "Failed to set the timeout.");
|
ERROR (context, "Failed to set the timeout.");
|
||||||
return status;
|
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.
|
// Convert and map to the model number.
|
||||||
unsigned int hardware = array_uint16_be (rsp_hardware);
|
unsigned int hardware = array_uint16_be (rsp_hardware);
|
||||||
|
|
||||||
|
DEBUG(device->base.context, "Hardware type: 0x%04x", hardware);
|
||||||
|
|
||||||
switch (hardware) {
|
switch (hardware) {
|
||||||
case 0x0101:
|
case 0x0101:
|
||||||
case 0x0202:
|
case 0x0202:
|
||||||
|
|||||||
@ -418,7 +418,6 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
dc_parser_t *abstract = (dc_parser_t *) parser;
|
dc_parser_t *abstract = (dc_parser_t *) parser;
|
||||||
const unsigned char *data = parser->base.data;
|
const unsigned char *data = parser->base.data;
|
||||||
unsigned int size = parser->base.size;
|
unsigned int size = parser->base.size;
|
||||||
const char *ppo2_source = NULL;
|
|
||||||
|
|
||||||
if (parser->cached) {
|
if (parser->cached) {
|
||||||
return DC_STATUS_SUCCESS;
|
return DC_STATUS_SUCCESS;
|
||||||
@ -728,38 +727,30 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
dc_field_add_string_fmt(&parser->cache, "Logversion", "%d%s", logversion, pnf ? "(PNF)" : "");
|
dc_field_add_string_fmt(&parser->cache, "Logversion", "%d%s", logversion, pnf ? "(PNF)" : "");
|
||||||
|
|
||||||
// Cache sensor calibration for later use
|
// Cache sensor calibration for later use
|
||||||
unsigned int nsensors = 0, ndefaults = 0;
|
|
||||||
unsigned int base = parser->opening[3] + (pnf ? 6 : 86);
|
unsigned int base = parser->opening[3] + (pnf ? 6 : 86);
|
||||||
|
parser->calibrated = data[base];
|
||||||
|
|
||||||
for (size_t i = 0; i < 3; ++i) {
|
for (size_t i = 0; i < 3; ++i) {
|
||||||
unsigned int calibration = array_uint16_be(data + base + 1 + i * 2);
|
if (parser->calibrated & (1 << i)) {
|
||||||
parser->calibration[i] = calibration / 100000.0;
|
unsigned int calibration = array_uint16_be(data + base + 1 + i * 2);
|
||||||
if (parser->model == PREDATOR) {
|
parser->calibration[i] = calibration / 100000.0;
|
||||||
// The Predator expects the mV output of the cells to be
|
if (parser->model == PREDATOR) {
|
||||||
// within 30mV to 70mV in 100% O2 at 1 atmosphere. If the
|
// The Predator expects the mV output of the cells to be
|
||||||
// calibration value is scaled with a factor 2.2, then the
|
// within 30mV to 70mV in 100% O2 at 1 atmosphere. If the
|
||||||
// sensors lines up and matches the average.
|
// calibration value is scaled with a factor 2.2, then the
|
||||||
parser->calibration[i] *= 2.2;
|
// sensors lines up and matches the average.
|
||||||
}
|
parser->calibration[i] *= 2.2;
|
||||||
if (data[base] & (1 << i)) {
|
|
||||||
if (calibration == 2100) {
|
|
||||||
ndefaults++;
|
|
||||||
}
|
}
|
||||||
nsensors++;
|
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the dive mode from the header (if available).
|
// Get the dive mode from the header (if available).
|
||||||
if (logversion >= 8) {
|
if (logversion >= 8) {
|
||||||
@ -830,8 +821,6 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
case M_CC:
|
case M_CC:
|
||||||
case M_CC2:
|
case M_CC2:
|
||||||
DC_ASSIGN_FIELD(parser->cache, DIVEMODE, DC_DIVEMODE_CCR);
|
DC_ASSIGN_FIELD(parser->cache, DIVEMODE, DC_DIVEMODE_CCR);
|
||||||
if (ppo2_source)
|
|
||||||
dc_field_add_string(&parser->cache, "PPO2 source", ppo2_source);
|
|
||||||
break;
|
break;
|
||||||
case M_SC:
|
case M_SC:
|
||||||
DC_ASSIGN_FIELD(parser->cache, DIVEMODE, DC_DIVEMODE_SCR);
|
DC_ASSIGN_FIELD(parser->cache, DIVEMODE, DC_DIVEMODE_SCR);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user