From 7c7c62dab25203dc876500540b73821503cd6913 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 12 Dec 2016 19:30:50 +0100 Subject: [PATCH] Ignore tank pressure if no sensor is attached If no tank pressure sensor is attached, the extra 8 bytes with the tank info are still present, but the recorded tank pressure value is always zero. --- src/mares_iconhd_parser.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index b174fe5..534d2ca 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -584,8 +584,8 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); // Current gas mix + unsigned int gasmix = (data[offset + 3] & 0xF0) >> 4; if (parser->ngasmixes > 0) { - unsigned int gasmix = (data[offset + 3] & 0xF0) >> 4; if (gasmix >= parser->ngasmixes) { ERROR (abstract->context, "Invalid gas mix index."); return DC_STATUS_DATAFORMAT; @@ -603,10 +603,16 @@ 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). - unsigned int pressure = array_uint16_le(data + offset); - sample.pressure.tank = 0; - sample.pressure.value = pressure / 100.0; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + 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; + } + sample.pressure.tank = gasmix; + sample.pressure.value = pressure / 100.0; + if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + } offset += 8; }