From a7fb341fb027c33e5a19be7924b24d30d49e2f3e Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sat, 4 May 2024 02:02:19 +1200 Subject: [PATCH] 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 cce1a4f..79881d2 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)];