From decfa24f92d14810c86aaa962f782aeed530b27b Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 19 Aug 2016 08:23:47 +0200 Subject: [PATCH] Fix the gas mix parsing for the Aladin Tec 2G. Unlike the other models, the Aladin Tec 2G uses only a single byte to store the oxygen percentage, and there is no need to manually re-map the deco mix. Normally, the oxygen percentage is stored using two bytes (little endian byte order). Thus for a device supporting two gas mixes, four bytes will be used, and the corresponding gas mix id for each byte is as follows: ID: 0 0 1 1 After re-mapping the id of the deco mix, this becomes: ID: 0 0 2 2 Since oxygen percentages are limited to the range 0-100%, the highest byte (marked with an X) should always be zero and can thus be ignored: ID: 0 X 2 X Now, because an oxygen percentage of zero indicates a disabled gas mix, this is equivalent to a device supporting three (or even four) gas mixes, each stored using only a single byte: ID: 0 1 2 3 We can take advantage of this knowledge to avoid having to re-map the deco mix id. --- src/uwatec_smart_parser.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index feb4844..5b0453f 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -211,7 +211,7 @@ static const uwatec_smart_header_info_t uwatec_smart_aladin_tec2g_header = { 22, 26, - 34, 2, + 34, 3, 30, /* temp_minimum */ 28, /* temp_maximum */ 32, /* temp_surface */ @@ -483,17 +483,17 @@ uwatec_smart_parser_cache (uwatec_smart_parser_t *parser) uwatec_smart_gasmix_t gasmix[NGASMIXES] = {{0}}; if (!trimix) { for (unsigned int i = 0; i < header->ngases; ++i) { - unsigned int id = i; - if (id > 0 && header->ngases == 2) { - id++; // Remap the id of the deco mix. + unsigned int idx = DC_GASMIX_UNKNOWN; + unsigned int o2 = 0; + if (parser->model == ALADINTEC2G) { + o2 = data[header->gasmix + i]; + } else { + o2 = array_uint16_le (data + header->gasmix + i * 2); } - unsigned int idx = DC_GASMIX_UNKNOWN; - - unsigned int o2 = data[header->gasmix + i * 2]; if (o2 != 0) { idx = ngasmixes; - gasmix[ngasmixes].id = id; + gasmix[ngasmixes].id = i; gasmix[ngasmixes].oxygen = o2; gasmix[ngasmixes].helium = 0; ngasmixes++; @@ -517,7 +517,7 @@ uwatec_smart_parser_cache (uwatec_smart_parser_t *parser) } if ((beginpressure != 0 || endpressure != 0) && (beginpressure != 0xFFFF) && (endpressure != 0xFFFF)) { - tank[ntanks].id = id; + tank[ntanks].id = i; tank[ntanks].beginpressure = beginpressure; tank[ntanks].endpressure = endpressure; tank[ntanks].gasmix = idx;