From b0874ea4d9045142c8e8db4bcfc6556caf2c07a1 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 12 Aug 2014 22:15:58 +0200 Subject: [PATCH] Disable gas mixes and events in gauge mode. For a dive in gauge mode, the gas mixes defined in the header should be ignored, and no gas change event should be emitted. This is done by hardcoding the number of gas mixes to zero. --- src/mares_iconhd_parser.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index eae33a9..fc1530c 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -34,6 +34,10 @@ #define NGASMIXES 3 +#define AIR 0 +#define GAUGE 1 +#define NITROX 2 + typedef struct mares_iconhd_parser_t mares_iconhd_parser_t; struct mares_iconhd_parser_t { @@ -92,8 +96,10 @@ mares_iconhd_parser_cache (mares_iconhd_parser_t *parser) // Gas mixes unsigned int ngasmixes = 0; unsigned int oxygen[NGASMIXES] = {0}; - unsigned int air = (p[0] & 0x02) == 0; - if (air) { + unsigned int mode = p[0] & 0x03; + if (mode == GAUGE) { + ngasmixes = 0; + } else if (mode == AIR) { oxygen[0] = 21; ngasmixes = 1; } else { @@ -290,16 +296,18 @@ 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 (gasmix >= parser->ngasmixes) { - return DC_STATUS_DATAFORMAT; - } - if (gasmix != gasmix_previous) { - sample.event.type = SAMPLE_EVENT_GASCHANGE; - sample.event.time = 0; - sample.event.value = parser->oxygen[gasmix]; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); - gasmix_previous = gasmix; + if (parser->ngasmixes > 0) { + unsigned int gasmix = (data[offset + 3] & 0xF0) >> 4; + if (gasmix >= parser->ngasmixes) { + return DC_STATUS_DATAFORMAT; + } + if (gasmix != gasmix_previous) { + sample.event.type = SAMPLE_EVENT_GASCHANGE; + sample.event.time = 0; + sample.event.value = parser->oxygen[gasmix]; + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + gasmix_previous = gasmix; + } } offset += parser->samplesize;