From 4ccfa51faf8c01ed1ca9d096fba5f49f030f3e43 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 7 Nov 2017 22:47:21 +0100 Subject: [PATCH] Fix the decoding of the ndl/deco information With the new APOS4 firmware, both the tts and the duration of the first deco stop are recorded while in deco. But compared with the older firmware, the tts field has moved to a slightly different offset. And contrary to the new documentation, it seems that the value for invalid or infinite has also changed from 0xFFFF to 0x7FFF, Note that for dives recorded with an older firmware version, the duration of the first deco stop isn't available, and libdivecomputer reports the tts instead. This is the same behaviour as before. Reported-by: Janice McLaughlin --- src/divesystem_idive_parser.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index f876891..24f7e53 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -370,17 +370,31 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba } // Deco stop / NDL. - unsigned int deco = array_uint16_le (data + offset + 21); - unsigned int tts = array_uint16_le (data + offset + 23); - if (tts != 0xFFFF) { - if (deco) { + unsigned int decostop = 0, decotime = 0, tts = 0; + if (apos4) { + decostop = array_uint16_le (data + offset + 21); + decotime = array_uint16_le (data + offset + 23); + tts = array_uint16_le (data + offset + 25); + if (tts == 0x7FFF) { + tts = INVALID; + } + } else { + decostop = array_uint16_le (data + offset + 21); + tts = array_uint16_le (data + offset + 23); + if (tts == 0xFFFF) { + tts = INVALID; + } + } + if (tts != INVALID) { + if (decostop) { sample.deco.type = DC_DECO_DECOSTOP; - sample.deco.depth = deco / 10.0; + sample.deco.depth = decostop / 10.0; + sample.deco.time = apos4 ? decotime : tts; } else { sample.deco.type = DC_DECO_NDL; sample.deco.depth = 0.0; + sample.deco.time = tts; } - sample.deco.time = tts; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); }