From 4df5e490083fe235293d3c17903b48d56100775a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 20 Sep 2012 23:19:32 +0200 Subject: [PATCH] Take the gas model into account to parse the gas mixes. When the gas model setting is set to air, the individual gas mix definitions retain their previous (non-air) values. This is convenient to avoid having to adjust the gas mixes again on your next nitrox or mixed gas dive. But the consequence is that for air dives, the gas model should take precedence over the individual gas mix definitions, and a single mix with air is returned instead. --- src/suunto_d9_parser.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 020a7dc..67fa49a 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -42,6 +42,12 @@ #define D6i 0x1A #define D9tx 0x1B +#define AIR 0 +#define NITROX 1 +#define GAUGE 2 +#define FREEDIVE 3 +#define MIXED 4 + typedef struct suunto_d9_parser_t suunto_d9_parser_t; struct suunto_d9_parser_t { @@ -185,6 +191,14 @@ suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsign if (size < config) return PARSER_STATUS_ERROR; + // Gas model + unsigned int gasmodel_offset = 0x1D - SKIP; + if (parser->model == HELO2) + gasmodel_offset += 6; + if (parser->model == D4i || parser->model == D6i || parser->model == D9tx) + gasmodel_offset = 0x1D; + unsigned int gasmodel = data[gasmodel_offset]; + gasmix_t *gasmix = (gasmix_t *) value; if (value) { @@ -203,7 +217,9 @@ suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsign *((double *) value) = array_uint16_le (data + 0x0D - SKIP) / 100.0; break; case FIELD_TYPE_GASMIX_COUNT: - if (parser->model == HELO2) { + if (gasmodel == AIR) { + *((unsigned int *) value) = 1; + } else if (parser->model == HELO2) { *((unsigned int *) value) = 8; } else if (parser->model == D9tx) { *((unsigned int *) value) = 8; @@ -216,7 +232,10 @@ suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsign } break; case FIELD_TYPE_GASMIX: - if (parser->model == HELO2) { + if (gasmodel == AIR) { + gasmix->helium = 0.0; + gasmix->oxygen = 0.21; + } else if (parser->model == HELO2) { gasmix->helium = data[0x58 - SKIP + 6 * flags + 2] / 100.0; gasmix->oxygen = data[0x58 - SKIP + 6 * flags + 1] / 100.0; } else if (parser->model == D9tx) {