From f5b5e4118113649ce74e55655813a8aa14f27c35 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 6 Dec 2012 20:08:22 +0100 Subject: [PATCH] Reduce the amount of gaschange events. Previously, gaschange events were emitted for every single sample. With this change, the event is only emitted when the gas mix has actually changed. --- src/shearwater_predator_parser.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 62d37aa..0cbf369 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -196,6 +196,9 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Get the unit system. unsigned int units = data[8]; + // Previous gas mix. + unsigned int o2_previous = 0, he_previous = 0; + unsigned int time = 0; unsigned int offset = SZ_BLOCK; while (offset + SZ_BLOCK < size) { @@ -229,11 +232,17 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); // Gaschange. - sample.event.type = SAMPLE_EVENT_GASCHANGE2; - sample.event.time = 0; - sample.event.flags = 0; - sample.event.value = data[offset + 7] | (data[offset + 8] << 16); - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + unsigned int o2 = data[offset + 7]; + unsigned int he = data[offset + 8]; + if (o2 != o2_previous || he != he_previous) { + sample.event.type = SAMPLE_EVENT_GASCHANGE2; + sample.event.time = 0; + sample.event.flags = 0; + sample.event.value = o2 | (he << 16); + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + o2_previous = o2; + he_previous = he; + } // Deco stop / NDL. unsigned int decostop = array_uint16_be (data + offset + 2);