From d30b5c65feeb5afcbd2bb6d0facd9ae26eb78d9e Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 15 Feb 2014 09:02:23 +0100 Subject: [PATCH 1/2] Ignore invalid gas mixes. Gas mixes that have been marked as disabled are stored as the value 0xF0. When interpreted as an oxygen percentage, this results in an out of range value. Therefore, these gas mixes should simply be ignored. --- src/cressi_edy_parser.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 3886c8e..7f9ad47 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -52,6 +52,21 @@ static const dc_parser_vtable_t cressi_edy_parser_vtable = { }; +static unsigned int +cressi_edy_parser_count_gasmixes (const unsigned char *data) +{ + // Count the number of active gas mixes. The active gas + // mixes are always first, so we stop counting as soon + // as the first gas marked as disabled is found. + unsigned int i = 0; + while (i < 3) { + if (data[0x17 - i] == 0xF0) + break; + i++; + } + return i; +} + dc_status_t cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) { @@ -139,7 +154,7 @@ cressi_edy_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign *((double *) value) = (bcd2dec (p[0x02] & 0x0F) * 100 + bcd2dec (p[0x03])) / 10.0; break; case DC_FIELD_GASMIX_COUNT: - *((unsigned int *) value) = 3; + *((unsigned int *) value) = cressi_edy_parser_count_gasmixes(p); break; case DC_FIELD_GASMIX: gasmix->helium = 0.0; From ba77b0ed24532627659c0d116649244999f12f03 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 15 Feb 2014 09:41:28 +0100 Subject: [PATCH 2/2] Add support for gas switches. --- src/cressi_edy_parser.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 7f9ad47..e6d12a8 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -185,6 +185,9 @@ cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c else interval = 30; + unsigned int ngasmixes = cressi_edy_parser_count_gasmixes(data); + unsigned int gasmix = 0xFFFFFFFF; + unsigned int offset = 32; while (offset + 2 <= size) { dc_sample_value_t sample = {0}; @@ -206,6 +209,21 @@ cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c sample.depth = depth / 10.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + // Current gasmix + if (ngasmixes) { + unsigned int idx = (data[offset + 0] & 0x60) >> 5; + if (idx >= ngasmixes) + return DC_STATUS_DATAFORMAT; + if (idx != gasmix) { + sample.event.type = SAMPLE_EVENT_GASCHANGE; + sample.event.time = 0; + sample.event.flags = 0; + sample.event.value = bcd2dec(data[0x17 - idx]); + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + gasmix = idx; + } + } + offset += 2 + extra; }