From 76f93d3fe53127157223574db7456f65b4bde418 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 7 Mar 2015 23:30:02 +0100 Subject: [PATCH] Ignore disabled gas mixes. Gas mixes are disabled by setting their oxygen percentage byte to 0x00. This is clearly an invalid gas mix, and it makes no sense to return it back to the application. It seems the device doesn't allow you to enable a gas mix if the previous gas mix has already been disabled. Therefore we can simply stop parsing the gas mixes once the first disabled gas mix has been found. --- src/uwatec_smart_parser.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index a4c002f..cf2b2c7 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -282,10 +282,16 @@ uwatec_smart_parser_cache (uwatec_smart_parser_t *parser) } // Get the gas mixes. + unsigned int ngasmixes = 0; unsigned int oxygen[NGASMIXES] = {0}; - unsigned int ngasmixes = (trimix ? 0 : parser->header->ngases); - for (unsigned int i = 0; i < ngasmixes; ++i) { - oxygen[i] = data[parser->header->gasmix + i * 2]; + if (!trimix) { + for (unsigned int i = 0; i < parser->header->ngases; ++i) { + unsigned int o2 = data[parser->header->gasmix + i * 2]; + if (o2 == 0) + break; // Skip disabled gas mixes. + oxygen[ngasmixes] = o2; + ngasmixes++; + } } // Cache the data for later use.