From ede94693167a9d179d8022bb1d5989a409f254b9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 17 Feb 2014 08:49:04 +0100 Subject: [PATCH] Report the initial gas mix. The Suunto dive computers record gas change events in the profile data. But because there is no gas change event stored on the first sample, the application doesn't know which gas mix is in use, until the very first gas change event occurs. For the Suunto HelO2, the index of the initial gas mix is stored in the dive header. This is most likely also the case for the other models, but I haven't found yet where exactly it is stored. As a temporary solution, we simply assume the initial gas mix is the first gas in the list with available gas mixes. This should be a reasonable assumption for most dives. Fixes ticket #2 --- src/suunto_d9_parser.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index f982902..e3b97f4 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -335,6 +335,16 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca if (rc != DC_STATUS_SUCCESS) return rc; + // Initial gasmix. + unsigned int gasmix = 0; + if (parser->model == HELO2) { + gasmix = data[0x26]; + } + if (gasmix >= parser->ngasmixes) { + ERROR (abstract->context, "Invalid initial gas mix."); + return DC_STATUS_DATAFORMAT; + } + // Number of parameters in the configuration data. unsigned int nparams = data[parser->config]; if (nparams == 0 || nparams > MAXPARAMS) @@ -433,6 +443,23 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca } } + // Initial gasmix. + if (time == 0) { + unsigned int he = 0; + unsigned int o2 = 0; + if (parser->mode == AIR) { + he = 0; + o2 = 21; + } else { + he = parser->helium[gasmix]; + o2 = parser->oxygen[gasmix]; + } + sample.event.type = SAMPLE_EVENT_GASCHANGE2; + sample.event.time = 0; + sample.event.value = o2 | (he << 16); + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + } + // Events if ((nsamples + 1) == marker) { while (offset < size) {