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;