From 2c5e787b77ddb93ea97b7366ef291e0f1a8f6960 Mon Sep 17 00:00:00 2001 From: John Van Ostrand Date: Sun, 2 Jul 2017 10:07:45 -0400 Subject: [PATCH] Fixed duplicate gasmix event reports Newer cochran DCs record a gas change event at the begining of a dive. The code creates a gas change before processing samples so with newer DCs this resulted in duplicate events. --- src/cochran_commander_parser.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index 8208e07..5a0ad55 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -567,6 +567,7 @@ cochran_commander_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callb sample.gasmix = 0; if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + unsigned int last_gasmix = sample.gasmix; while (offset < size) { const unsigned char *s = samples + offset; @@ -630,12 +631,18 @@ cochran_commander_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callb break; case 0xCD: // Switched to deco blend case 0xEF: // Switched to gas blend 2 - sample.gasmix = 1; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (last_gasmix != 1) { + sample.gasmix = 1; + if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + last_gasmix = sample.gasmix; + } break; case 0xF3: // Switched to gas blend 1 - sample.gasmix = 0; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (last_gasmix != 0) { + sample.gasmix = 0; + if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + last_gasmix = sample.gasmix; + } break; }