From d0c7562c410fe16144678bdc40b4bb8cbc611acb Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 31 May 2022 22:07:54 +0200 Subject: [PATCH] Ignore invalid gas mixes The Cressi Michelangelo appears to store inactive gas mixes as a zero oxygen percentage. Such invalid values shouldn't be reported. --- src/cressi_goa_parser.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cressi_goa_parser.c b/src/cressi_goa_parser.c index 256dbc3..53263b1 100644 --- a/src/cressi_goa_parser.c +++ b/src/cressi_goa_parser.c @@ -43,6 +43,8 @@ #define FREEDIVE 2 #define GAUGE 3 +#define NGASMIXES 2 + typedef struct cressi_goa_parser_t cressi_goa_parser_t; struct cressi_goa_parser_t { @@ -174,6 +176,15 @@ cressi_goa_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign parser->maxdepth = statistics.maxdepth; } + unsigned int ngasmixes = 0; + if (divemode == SCUBA || divemode == NITROX) { + for (unsigned int i = 0; i < NGASMIXES; ++i) { + if (data[0x20 + 2 * i] == 0) + break; + ngasmixes++; + } + } + dc_gasmix_t *gasmix = (dc_gasmix_t *) value; if (value) { @@ -185,7 +196,7 @@ cressi_goa_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign *((double *) value) = parser->maxdepth; break; case DC_FIELD_GASMIX_COUNT: - *((unsigned int *) value) = divemode == SCUBA || divemode == NITROX ? 2 : 0; + *((unsigned int *) value) = ngasmixes; break; case DC_FIELD_GASMIX: gasmix->helium = 0.0;