From c8b166dadbf961e17a9bd1cc28db3d92832ddf72 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 22 Mar 2016 21:15:03 +0100 Subject: [PATCH] Get the gas mixes from the sample data. The Shearwater devices support adding, removing or editing gas mixes during the dive. The pre-defined gas mixes available in the opening and closing block are only a snapshot of the configuration at the start and at the end of the dive. Thus by editing the gas mixes during the dive it's possible to switch to a gas mix that is not present in the opening (or even the closing block). The parser doesn't support that. To avoid this problem, we now collect the available gas mixes from the sample data. As a side effect we only return those gas mixes that are effectively used during the dive. --- src/shearwater_predator_parser.c | 38 +++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index d7c1cf3..f46b6af 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -234,16 +234,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) unsigned int ngasmixes = 0; unsigned int oxygen[NGASMIXES] = {0}; unsigned int helium[NGASMIXES] = {0}; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - unsigned int o2 = data[20 + i]; - unsigned int he = data[30 + i]; - if (o2 == 0 && he == 0) - continue; - oxygen[ngasmixes] = o2; - helium[ngasmixes] = he; - ngasmixes++; - } - + unsigned int o2_previous = 0, he_previous = 0; unsigned int offset = headersize; unsigned int length = size - footersize; @@ -260,6 +251,33 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) mode = DC_DIVEMODE_CC; } + // Gaschange. + unsigned int o2 = data[offset + 7]; + unsigned int he = data[offset + 8]; + if (o2 != o2_previous || he != he_previous) { + // Find the gasmix in the list. + unsigned int idx = 0; + while (idx < ngasmixes) { + if (o2 == oxygen[idx] && he == helium[idx]) + break; + idx++; + } + + // Add it to list if not found. + if (idx >= ngasmixes) { + if (idx >= NGASMIXES) { + ERROR (abstract->context, "Maximum number of gas mixes reached."); + return DC_STATUS_NOMEMORY; + } + oxygen[idx] = o2; + helium[idx] = he; + ngasmixes = idx + 1; + } + + o2_previous = o2; + he_previous = he; + } + offset += parser->samplesize; }