From 10ae594b1ff094cbc7ee072d27b3468290a89cf1 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 29 Dec 2012 07:35:50 -0800 Subject: [PATCH] Add gas changes and violation events for Atomic Aquatics Cobalt These are based on the documentation we have and have been tested and verified against actual dive data (with the exception of the pO2 and ascent speed violations). Signed-off-by: Dirk Hohndel --- src/atomics_cobalt_parser.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 3dd6eb7..acc8d6a 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -224,6 +224,9 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback else atmospheric = array_uint16_le (data + 0x26) * BAR / 1000.0; + // Previous gas mix - initialize with impossible value + unsigned int gasmix_previous = 0xFFFFFFFF; + unsigned int time = 0; unsigned int offset = header; while (offset + SZ_SEGMENT <= size) { @@ -245,11 +248,46 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback sample.pressure.value = pressure * PSI / BAR; if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + // Current gas mix + unsigned int gasmix = data[offset + 4]; + if (gasmix >= ngasmixes) { + return DC_STATUS_DATAFORMAT; + } + if (gasmix != gasmix_previous) { + unsigned int o2 = data[SZ_HEADER + SZ_GASMIX * gasmix + 4]; + unsigned int he = data[SZ_HEADER + SZ_GASMIX * gasmix + 5]; + 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); + gasmix_previous = gasmix; + } + // Temperature (1 °F). unsigned int temperature = data[offset + 8]; sample.temperature = (temperature - 32.0) * (5.0 / 9.0); if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + // violation status + sample.event.type = 0; + sample.event.time = 0; + sample.event.value = 0; + sample.event.flags = 0; + unsigned int violation = data[offset + 11]; + if (violation & 0x01) { + sample.event.type = SAMPLE_EVENT_ASCENT; + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + } + if (violation & 0x04) { + sample.event.type = SAMPLE_EVENT_CEILING; + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + } + if (violation & 0x08) { + sample.event.type = SAMPLE_EVENT_PO2; + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + } + offset += SZ_SEGMENT; }