From 2d9008aff703721ac71bbc00bbf3a9f57fd029ce Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 12 Nov 2023 21:01:57 +0100 Subject: [PATCH] Remove disabled gas mixes Returning disabled gas mixes to the application mainly results in lots of unnecessary information. Therefore, remove all disabled gas mixes, unless they are actively used. Many other dive computers do not even include disabled gas mixes in the data. Unlike previously assumed, the on/off state of each gas mix is actually available in the PNF data format (opening record 4). For the older Predator data format, this info isn't available and all gas mixes are manually marked as enabled. --- src/shearwater_predator_parser.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index fc06b66..167f585 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -107,6 +107,8 @@ typedef struct shearwater_predator_gasmix_t { unsigned int oxygen; unsigned int helium; unsigned int diluent; + unsigned int enabled; + unsigned int active; } shearwater_predator_gasmix_t; typedef struct shearwater_predator_tank_t { @@ -245,6 +247,8 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; parser->gasmix[i].diluent = 0; + parser->gasmix[i].enabled = 0; + parser->gasmix[i].active = 0; } parser->ntanks = 0; for (unsigned int i = 0; i < NTANKS; ++i) { @@ -395,6 +399,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) gasmix[i].oxygen = data[20 + i]; gasmix[i].helium = data[30 + i]; gasmix[i].diluent = i >= 5; + gasmix[i].enabled = 1; } } @@ -443,6 +448,8 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) ngasmixes = idx + 1; } + gasmix[idx].active = 1; + o2_previous = o2; he_previous = he; dil_previous = ccr; @@ -552,6 +559,13 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) } } } + + // Gas mix on/off state. + unsigned int state = array_uint16_be (data + offset + 17); + for (unsigned int i = 0; i < NFIXED; ++i) { + gasmix[i].enabled = (state & (1 << i)) != 0; + } + unsigned int gtrmode = data[offset + 29]; if (popcount(gtrmode) >= 2) { for (unsigned int i = 0; i < 4; ++i) { @@ -678,6 +692,8 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) for (unsigned int i = 0; i < ngasmixes; ++i) { if (gasmix[i].oxygen == 0 && gasmix[i].helium == 0) continue; + if (!gasmix[i].enabled && !gasmix[i].active) + continue; if (gasmix[i].diluent && !shearwater_predator_is_ccr (divemode)) continue; parser->gasmix[parser->ngasmixes] = gasmix[i];