From 1079bdc0b0dd29bb2ba24dc678741192925891e0 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 28 Dec 2012 21:44:29 -0800 Subject: [PATCH] Fix gas handling for OSTC Two issues: - the OSTC counts its gases 1-based, not 0-based - dives don't always start with the first gas. Simply create a gas change event right after the first time sample that informs the application what the first gas mix is Signed-off-by: Dirk Hohndel --- src/hw_ostc_parser.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index b86d7b2..6e4f700 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -334,6 +334,19 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + // Initial gas mix. + if (time == samplerate) { + unsigned int idx = data[31]; + if (idx < 1 || idx > 5) + return DC_STATUS_DATAFORMAT; + idx--; /* Convert to a zero based index. */ + sample.event.type = SAMPLE_EVENT_GASCHANGE2; + sample.event.time = 0; + sample.event.flags = 0; + sample.event.value = data[19 + 2 * idx] | (data[20 + 2 * idx] << 16); + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + } + // Depth (mbar). unsigned int depth = array_uint16_le (data + offset); sample.depth = (depth * BAR / 1000.0) / hydrostatic; @@ -400,9 +413,12 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Gas Change if (events & 0x20) { - if (offset + 1 > size || data[offset] >= 5) + if (offset + 1 > size) return DC_STATUS_DATAFORMAT; unsigned int idx = data[offset]; + if (idx < 1 || idx > 5) + return DC_STATUS_DATAFORMAT; + idx--; /* Convert to a zero based index. */ sample.event.type = SAMPLE_EVENT_GASCHANGE2; sample.event.time = 0; sample.event.flags = 0;