From d0d4c7b9948bb526aeaa5a7320b227252e4cd674 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 23 Oct 2017 20:55:19 +0200 Subject: [PATCH 1/3] Support for the Scubapro Aladin Sport Matrix. The protocol is identical to the G2 protocol, with the exception of a missing handshake. Signed-off-by: Berthold Stoeger --- src/descriptor.c | 3 ++- src/uwatec_smart_parser.c | 32 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/descriptor.c b/src/descriptor.c index a9c51eb..6a2d695 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -138,7 +138,8 @@ static const dc_descriptor_t g_descriptors[] = { {"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26}, /* Scubapro G2 */ #ifdef USBHID - {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32}, + {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17}, + {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32}, #endif /* Reefnet */ {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1}, diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 18a0dfe..e0726e4 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -35,19 +35,20 @@ #define NBITS 8 -#define SMARTPRO 0x10 -#define GALILEO 0x11 -#define ALADINTEC 0x12 -#define ALADINTEC2G 0x13 -#define SMARTCOM 0x14 -#define ALADIN2G 0x15 -#define SMARTTEC 0x18 -#define GALILEOTRIMIX 0x19 -#define SMARTZ 0x1C -#define MERIDIAN 0x20 -#define CHROMIS 0x24 -#define MANTIS2 0x26 -#define G2 0x32 +#define SMARTPRO 0x10 +#define GALILEO 0x11 +#define ALADINTEC 0x12 +#define ALADINTEC2G 0x13 +#define SMARTCOM 0x14 +#define ALADIN2G 0x15 +#define ALADINSPORTMATRIX 0x17 +#define SMARTTEC 0x18 +#define GALILEOTRIMIX 0x19 +#define SMARTZ 0x1C +#define MERIDIAN 0x20 +#define CHROMIS 0x24 +#define MANTIS2 0x26 +#define G2 0x32 #define UNSUPPORTED 0xFFFFFFFF @@ -521,7 +522,7 @@ uwatec_smart_parser_cache (uwatec_smart_parser_t *parser) if (parser->model == GALILEO || parser->model == GALILEOTRIMIX || parser->model == ALADIN2G || parser->model == MERIDIAN || parser->model == CHROMIS || parser->model == MANTIS2 || - parser->model == G2) { + parser->model == G2 || parser->model == ALADINSPORTMATRIX) { unsigned int offset = header->tankpressure + 2 * i; endpressure = array_uint16_le(data + offset); beginpressure = array_uint16_le(data + offset + 2 * header->ngases); @@ -611,6 +612,7 @@ uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i parser->nevents[2] = C_ARRAY_SIZE (uwatec_smart_galileo_events_2); break; case G2: + case ALADINSPORTMATRIX: parser->headersize = 84; parser->header = &uwatec_smart_trimix_header; parser->samples = uwatec_smart_galileo_samples; @@ -950,7 +952,7 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback if (parser->model == GALILEO || parser->model == GALILEOTRIMIX || parser->model == ALADIN2G || parser->model == MERIDIAN || parser->model == CHROMIS || parser->model == MANTIS2 || - parser->model == G2) { + parser->model == G2 || parser->model == ALADINSPORTMATRIX) { // Uwatec Galileo id = uwatec_galileo_identify (data[offset]); } else { From e786b0b0b649223b1c3eb248e700b9b3c3e5a6da Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 14 Nov 2017 12:57:00 +0100 Subject: [PATCH 2/3] Use an out-of-range value as undefined The main purpose of the magic value UNDEFINED, is to indicate that a value isn't present in the data. But since the value 0xFF can actually be stored in the data, we can't distinguish between those two cases. This ambiguity can be avoided by using a magic value that lies outside the valid range for 8 and 16 bit fields. Note that an initial gas mix value of 0xFF remains interpreted as UNDEFINED, but this is now made explicit. --- src/hw_ostc_parser.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index f1c656f..a1dc0c3 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -34,7 +34,7 @@ #define MAXCONFIG 7 #define NGASMIXES 15 -#define UNDEFINED 0xFF +#define UNDEFINED 0xFFFFFFFF #define ALL 0 #define FIXED 1 @@ -229,7 +229,9 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) hw_ostc_gasmix_t gasmix[NGASMIXES] = {{0}}; if (version == 0x22) { ngasmixes = 3; - initial = data[31]; + if (data[31] != 0xFF) { + initial = data[31]; + } for (unsigned int i = 0; i < ngasmixes; ++i) { gasmix[i].oxygen = data[25 + 2 * i]; gasmix[i].helium = 0; @@ -250,7 +252,9 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) } } else { ngasmixes = 5; - initial = data[31]; + if (data[31] != 0xFF) { + initial = data[31]; + } for (unsigned int i = 0; i < ngasmixes; ++i) { gasmix[i].oxygen = data[19 + 2 * i + 0]; gasmix[i].helium = data[19 + 2 * i + 1]; From 20d7d03a0d923591f012dfbfc97786074e133da7 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Mon, 13 Nov 2017 10:02:43 +0100 Subject: [PATCH 3/3] OSTC: initialize initial CNS from header As the OSTC does not report a CNS value on the first sample, we need to initialize it differently. This can be solved by using the initial CNS value form the dive header, and storing that value in the first sample. The resulting patch is very similar to 44f629f03a91a3b3. Signed-off-by: Jan Mulder --- src/hw_ostc_parser.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index a1dc0c3..d01f087 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -98,6 +98,7 @@ typedef struct hw_ostc_parser_t { unsigned int nfixed; unsigned int initial; unsigned int initial_setpoint; + unsigned int initial_cns; hw_ostc_gasmix_t gasmix[NGASMIXES]; } hw_ostc_parser_t; @@ -222,9 +223,11 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) } // Get all the gas mixes, the index of the inital mix, - // and the initial setpoint (used in the fixed setpoint mode). + // the initial setpoint (used in the fixed setpoint CCR mode), + // and the initial CNS from the header unsigned int initial = UNDEFINED; unsigned int initial_setpoint = UNDEFINED; + unsigned int initial_cns = UNDEFINED; unsigned int ngasmixes = 0; hw_ostc_gasmix_t gasmix[NGASMIXES] = {{0}}; if (version == 0x22) { @@ -250,6 +253,8 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) if (data[82] == OSTC3_CC) { initial_setpoint = data[60]; } + // Initial CNS + initial_cns = array_uint16_le (data + 53); } else { ngasmixes = 5; if (data[31] != 0xFF) { @@ -278,6 +283,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) parser->nfixed = ngasmixes; parser->initial = initial; parser->initial_setpoint = initial_setpoint; + parser->initial_cns = initial_cns; for (unsigned int i = 0; i < ngasmixes; ++i) { parser->gasmix[i] = gasmix[i]; } @@ -312,6 +318,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign parser->nfixed = 0; parser->initial = 0; parser->initial_setpoint = 0; + parser->initial_cns = 0; for (unsigned int i = 0; i < NGASMIXES; ++i) { parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; @@ -349,6 +356,7 @@ hw_ostc_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsig parser->nfixed = 0; parser->initial = 0; parser->initial_setpoint = 0; + parser->initial_cns = 0; for (unsigned int i = 0; i < NGASMIXES; ++i) { parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; @@ -663,6 +671,12 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); } + // Initial CNS (%). + if (time == samplerate && parser->initial_cns != UNDEFINED) { + sample.cns = parser->initial_cns / 100.0; + if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + } + // Depth (mbar). unsigned int depth = array_uint16_le (data + offset); sample.depth = (depth * BAR / 1000.0) / hydrostatic;