From 8853a1ccd422fb662aea674265abc7ccc6525872 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 10 Oct 2014 20:29:17 +0200 Subject: [PATCH] Associate the pressure samples with the primary tank. The primary tank, which is the tank connected to the hose and thus the tank pressure sensor, it not necessary the first tank. The correct tank index can be found by searching the array for a gas mix with a sensor id equal to one. --- src/atomics_cobalt_parser.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 8378028..bd41914 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -213,6 +213,19 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Previous gas mix - initialize with impossible value unsigned int gasmix_previous = 0xFFFFFFFF; + // Get the primary tank. + unsigned int tank = 0; + while (tank < ngasmixes) { + unsigned int sensor = array_uint16_le(data + SZ_HEADER + SZ_GASMIX * tank + 12); + if (sensor == 1) + break; + tank++; + } + if (tank >= ngasmixes) { + ERROR (abstract->context, "Invalid primary tank index."); + return DC_STATUS_DATAFORMAT; + } + unsigned int time = 0; unsigned int in_deco = 0; unsigned int offset = header; @@ -231,7 +244,7 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Pressure (1 psi). unsigned int pressure = array_uint16_le (data + offset + 2); - sample.pressure.tank = 0; + sample.pressure.tank = tank; sample.pressure.value = pressure * PSI / BAR; if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata);