From cb0584adc1126ed5edcd3f89834e2269fd8d4729 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 c059c89..cf6d56a 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -250,16 +250,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; @@ -276,6 +267,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; }