From 861b5652e0d42d08126e1c7f05fefa52d8401c88 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 23 Jan 2014 13:36:02 +0100 Subject: [PATCH] Add support for parsing gas changes. Parsing the gas switch events is somewhat complicated, because depending on the actual model, they can be stored in different ways. The table below lists the number of gas mixes (G), tanks (T) and alarm bytes (A) supported by each model. Note that only the representative model in each group is listed. Model | G | T | A ==============|===|===|=== Pro | 1 | 0 | 1 Com | 1 | 1 | 1 Tec | 3 | 3 | 1 Aladin Tec | 1 | 0 | 2 Aladin Tec 2G | 3 | 0 | 2 Galileo | 3 | 3 | 3 Models without support for multiple gasmixes only need to set the initial gas mix correctly. Models with support for one or more tank pressure sensors can link the gas switches to the tank switches. Models with at least two alarm bytes can store a gas switch event in the second alarm byte. As can be observed from the table, some models can use several different methods to store the gas switches. The current implementation supports all of them. In the case of a conflict, the last used method always takes precedence. That's simply due to the fact that each method just sets the gasmix index, and only the final value is used. If this approach turns out to produce wrong results, it can always be fixed later. The initial gasmix is always assumed to be the first configured gasmix. --- src/uwatec_smart_parser.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 104481e..dd4734e 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -483,12 +483,20 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } } + // Get all the gas mixes. + unsigned int oxygen[3] = {0}; + unsigned int ngasmix = (trimix ? 0 : parser->header->ngases); + for (unsigned int i = 0; i < ngasmix; ++i) { + oxygen[i] = data[parser->header->gasmix + i * 2]; + } + int complete = 0; int calibrated = 0; unsigned int time = 0; unsigned int rbt = 99; unsigned int tank = 0; + unsigned int gasmix = 0; double depth = 0, depth_calibration = 0; double temperature = 0; double pressure = 0; @@ -496,6 +504,9 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t unsigned int bearing = 0; unsigned char alarms[3] = {0, 0, 0}; + // Previous gas mix - initialize with impossible value + unsigned int gasmix_previous = 0xFFFFFFFF; + int have_depth = 0, have_temperature = 0, have_pressure = 0, have_rbt = 0, have_heartrate = 0, have_alarms = 0, have_bearing = 0; @@ -587,6 +598,7 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t pressure = value / 4.0; } have_pressure = 1; + gasmix = tank; } else { pressure += svalue / 4.0; } @@ -619,6 +631,13 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t case ALARMS: alarms[table[id].index] = value; have_alarms = 1; + if (table[id].index == 1) { + if (parser->model == ALADINTEC || parser->model == ALADINTEC2G) { + gasmix = (value & 0x18) >> 3; + } else { + gasmix = (value & 0x30) >> 4; + } + } break; case TIME: complete = value; @@ -646,6 +665,17 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (gasmix != gasmix_previous && !trimix) { + if (gasmix >= ngasmix) + return DC_STATUS_DATAFORMAT; + sample.event.type = SAMPLE_EVENT_GASCHANGE; + sample.event.time = 0; + sample.event.flags = 0; + sample.event.value = oxygen[gasmix]; + if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + gasmix_previous = gasmix; + } + if (have_temperature) { sample.temperature = temperature; if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata);