From c5d5220e287cf55ef8b043990c9c403c04315509 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 27 Mar 2017 19:17:29 +0200 Subject: [PATCH] Fix a bug in the tank pressure samples The number of tank pressure sensors is not necessary equal to the number of gas mixes. Take for example a dive with two gas mixes, but only a single tank pressure sensor attached to one of the two tanks. Because the tank index is shared with the gas mix index, it will refer to a non-existing sensor when switching to a tank without a pressure sensor attached. The invalid tank index should not be considered a fatal error. The tank pressure values should be ignored instead. The device appears to record zero values anyway, except for the first value immediately after the gas switch. I suspect that's caused by the fact that the pressure is only recorded every 4 samples, and therefore the last pressure value is reported with a small delay. --- src/mares_iconhd_parser.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 534d2ca..8e356be 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -603,15 +603,13 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Some extra data. if (parser->model == ICONHDNET && (nsamples % 4) == 0) { // Pressure (1/100 bar). - if (parser->ntanks > 0) { - unsigned int pressure = array_uint16_le(data + offset); - if (gasmix >= parser->ntanks) { - ERROR (abstract->context, "Invalid tank index."); - return DC_STATUS_DATAFORMAT; - } + unsigned int pressure = array_uint16_le(data + offset); + if (gasmix < parser->ntanks) { sample.pressure.tank = gasmix; sample.pressure.value = pressure / 100.0; if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + } else if (pressure != 0) { + WARNING (abstract->context, "Invalid tank with non-zero pressure."); } offset += 8;