From 44f629f03a91a3b3a94e561e85c2d951861d6f69 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Sat, 29 Apr 2017 08:15:35 +0200 Subject: [PATCH] OSTC3: set initial setpoint in profile data In CCR fixed setpoint mode of the OSTC3, the initial setpoint at the start of the dive was not set. This fix adds the initial setpoint based on the data in the fixed setpoint table (ie, the first fixed setpoint is the initial one). Signed-off-by: Jan Mulder --- 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 b9f947b..b23e6d3 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -97,6 +97,7 @@ typedef struct hw_ostc_parser_t { unsigned int ngasmixes; unsigned int nfixed; unsigned int initial; + unsigned int initial_setpoint; hw_ostc_gasmix_t gasmix[NGASMIXES]; } hw_ostc_parser_t; @@ -220,8 +221,10 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) return DC_STATUS_DATAFORMAT; } - // Get all the gas mixes, and the index of the inital mix. + // Get all the gas mixes, the index of the inital mix, + // and the initial setpoint (used in the fixed setpoint mode). unsigned int initial = UNDEFINED; + unsigned int initial_setpoint = UNDEFINED; unsigned int ngasmixes = 0; hw_ostc_gasmix_t gasmix[NGASMIXES] = {{0}}; if (version == 0x22) { @@ -241,6 +244,10 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) initial = i + 1; /* One based index! */ } } + // The first fixed setpoint is the initial setpoint in CCR mode. + if (data[82] == OSTC3_CC) { + initial_setpoint = data[60]; + } } else { ngasmixes = 5; initial = data[31]; @@ -266,6 +273,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) parser->ngasmixes = ngasmixes; parser->nfixed = ngasmixes; parser->initial = initial; + parser->initial_setpoint = initial_setpoint; for (unsigned int i = 0; i < ngasmixes; ++i) { parser->gasmix[i] = gasmix[i]; } @@ -299,6 +307,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign parser->ngasmixes = 0; parser->nfixed = 0; parser->initial = 0; + parser->initial_setpoint = 0; for (unsigned int i = 0; i < NGASMIXES; ++i) { parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; @@ -335,6 +344,7 @@ hw_ostc_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsig parser->ngasmixes = 0; parser->nfixed = 0; parser->initial = 0; + parser->initial_setpoint = 0; for (unsigned int i = 0; i < NGASMIXES; ++i) { parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; @@ -640,6 +650,12 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); } + // Initial setpoint (mbar). + if (time == samplerate && parser->initial_setpoint != UNDEFINED) { + sample.setpoint = parser->initial_setpoint / 100.0; + if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + } + // Depth (mbar). unsigned int depth = array_uint16_le (data + offset); sample.depth = (depth * BAR / 1000.0) / hydrostatic;