From 784844d8dda52b4bafc96a501007af4fd282ce89 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 8 Mar 2016 20:01:20 +0100 Subject: [PATCH] Add support for the new D4i and D6i data format. One of the newer D4i and D6i firmware versions (for example v1.5.9), introduces a new variant of the data format. The new dive header is 8 bytes larger. The correct variant can be detected by means of the logbook id tag at the start of the header. --- src/suunto_d9_parser.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 8d5c3c6..7ea09e1 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -47,6 +47,12 @@ #define D9tx 0x1B #define DX 0x1C +#define ID_D6I_V1_MIX2 0x1871C062 +#define ID_D6I_V1_MIX3 0x1871C063 +#define ID_D6I_V2 0x18724062 +#define ID_D4I_V1 ID_D6I_V1_MIX2 +#define ID_D4I_V2 ID_D6I_V2 + #define AIR 0 #define NITROX 1 #define GAUGE 2 @@ -120,6 +126,9 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser) return DC_STATUS_SUCCESS; } + // Get the logbook id tag. + unsigned int id = array_uint32_le (data + 1); + // Gasmix information. unsigned int gasmode_offset = 0x19; unsigned int gasmix_offset = 0x21; @@ -130,12 +139,18 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser) gasmix_count = 8; } else if (parser->model == D4i) { gasmode_offset = 0x1D; - gasmix_offset = 0x5F; + if (id == ID_D4I_V2) + gasmix_offset = 0x67; + else + gasmix_offset = 0x5F; gasmix_count = 1; } else if (parser->model == D6i) { gasmode_offset = 0x1D; - gasmix_offset = 0x5F; - if (data[1] == 0x63) + if (id == ID_D6I_V2) + gasmix_offset = 0x67; + else + gasmix_offset = 0x5F; + if (id == ID_D6I_V1_MIX3) gasmix_count = 3; else gasmix_count = 2; @@ -193,7 +208,11 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser) parser->gasmix = data[0x26]; } else if (parser->model == D4i || parser->model == D6i || parser->model == D9tx) { - parser->gasmix = data[0x28]; + if (id == ID_D4I_V2 || id == ID_D6I_V2) { + parser->gasmix = data[0x2D]; + } else { + parser->gasmix = data[0x28]; + } } } parser->config = config;