From 390b5fe5536e1bd339b1c8802a4bc8f53fd497b8 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 1 Nov 2016 20:14:16 +0100 Subject: [PATCH] Report the initial gas mix on the first sample For dives with multiple gas mixes, an application doesn't have enough info to figure out which one is the initial gas mix. Usually it's the first gas mix, but that's not guaranteed. Reporting the intial gas mix on the first sample avoids this problem. --- src/cochran_commander_parser.c | 3 +++ src/cressi_leonardo_parser.c | 10 ++++++++++ src/mares_darwin_parser.c | 14 ++++++++++++++ src/mares_nemo_parser.c | 14 ++++++++++++++ src/suunto_eon_parser.c | 4 ++++ src/suunto_solution_parser.c | 9 +++++++++ src/suunto_vyper_parser.c | 8 ++++++++ src/uwatec_memomouse_parser.c | 10 ++++++++++ 8 files changed, 72 insertions(+) diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index 7802ea1..1873a46 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -501,6 +501,9 @@ cochran_commander_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callb sample.temperature = (data[layout->start_temp] - 32.0) / 1.8; if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + sample.gasmix = 0; + if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + while (offset < size) { const unsigned char *s = samples + offset; diff --git a/src/cressi_leonardo_parser.c b/src/cressi_leonardo_parser.c index d9ed79c..656f487 100644 --- a/src/cressi_leonardo_parser.c +++ b/src/cressi_leonardo_parser.c @@ -149,6 +149,9 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac unsigned int time = 0; unsigned int interval = 20; + unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int gasmix = 0; + unsigned int offset = SZ_HEADER; while (offset + 2 <= size) { dc_sample_value_t sample = {0}; @@ -166,6 +169,13 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac sample.depth = depth / 10.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Gas change. + if (gasmix != gasmix_previous) { + sample.gasmix = gasmix; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + gasmix_previous = gasmix; + } + // Ascent rate if (ascent) { sample.event.type = SAMPLE_EVENT_ASCENT; diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index d4d13da..ac2c16f 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -217,8 +217,15 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t unsigned int time = 0; + unsigned int mode = abstract->data[0x0C] & 0x03; unsigned int pressure = array_uint16_be (abstract->data + 0x17); + unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int gasmix = gasmix_previous; + if (mode != GAUGE) { + gasmix = 0; + } + unsigned int offset = parser->headersize; while (offset + parser->samplesize <= abstract->size) { dc_sample_value_t sample = {0}; @@ -238,6 +245,13 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.depth = depth / 10.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Gas change. + if (gasmix != gasmix_previous) { + sample.gasmix = gasmix; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + gasmix_previous = gasmix; + } + // Ascent rate if (ascent) { sample.event.type = SAMPLE_EVENT_ASCENT; diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index 33e5916..29b51b1 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -358,6 +358,13 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c pressure = array_uint16_le(p + parser->header + 4); } + // Initial gas mix. + unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int gasmix = gasmix_previous; + if (parser->mode == AIR || parser->mode == NITROX) { + gasmix = 0; + } + unsigned int time = 0; for (unsigned int i = 0; i < parser->sample_count; ++i) { dc_sample_value_t sample = {0}; @@ -378,6 +385,13 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c sample.depth = depth / 10.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Gas change. + if (gasmix != gasmix_previous) { + sample.gasmix = gasmix; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + gasmix_previous = gasmix; + } + // Ascent rate if (ascent) { sample.event.type = SAMPLE_EVENT_ASCENT; diff --git a/src/suunto_eon_parser.c b/src/suunto_eon_parser.c index 70fa74f..714df34 100644 --- a/src/suunto_eon_parser.c +++ b/src/suunto_eon_parser.c @@ -275,6 +275,10 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c sample.depth = 0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Initial gas mix. + sample.gasmix = 0; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + unsigned int depth = 0; unsigned int time = 0; unsigned int interval = data[3]; diff --git a/src/suunto_solution_parser.c b/src/suunto_solution_parser.c index 8372457..e8e6986 100644 --- a/src/suunto_solution_parser.c +++ b/src/suunto_solution_parser.c @@ -170,6 +170,8 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac return DC_STATUS_DATAFORMAT; unsigned int time = 0, depth = 0; + unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int gasmix = 0; unsigned int offset = 3; while (offset < size && data[offset] != 0x80) { @@ -193,6 +195,13 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac } sample.depth = depth * FEET; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + + // Gas change. + if (gasmix != gasmix_previous) { + sample.gasmix = gasmix; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + gasmix_previous = gasmix; + } } else { // Event. sample.event.type = SAMPLE_EVENT_NONE; diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index 6bcd3ac..3b46539 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -319,6 +319,8 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (rc != DC_STATUS_SUCCESS) return rc; + unsigned int gauge = data[4] & 0x40; + // Time sample.time = 0; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); @@ -327,6 +329,12 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.depth = 0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Initial gas mix + if (!gauge) { + sample.gasmix = 0; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + } + unsigned int depth = 0; unsigned int time = 0; unsigned int interval = data[3]; diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index ce52200..d03d31b 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -216,6 +216,9 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba unsigned int time = 20; + unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int gasmix = 0; + unsigned int offset = header + 18; while (offset + 2 <= size) { dc_sample_value_t sample = {0}; @@ -233,6 +236,13 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.depth = depth * 10.0 / 64.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Gas change. + if (gasmix != gasmix_previous) { + sample.gasmix = gasmix; + if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + gasmix_previous = gasmix; + } + // Warnings for (unsigned int i = 0; i < 6; ++i) { if (warnings & (1 << i)) {