>From 995ed21f525ec9156f1f41cb0612b7c1e428548e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 16 Oct 2014 15:06:21 +0200 Subject: [PATCH 2/5] Implement deco algorithm and parameter fields for OSTC2/3 Signed-off-by: Dirk Hohndel --- src/hw_ostc_parser.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 8fb8875e85fb..b279040b0f60 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -53,6 +53,9 @@ typedef struct hw_ostc_layout_t { unsigned int atmospheric; unsigned int salinity; unsigned int duration; + unsigned int deco_alg; + unsigned int gflow; + unsigned int gfhigh; } hw_ostc_layout_t; typedef struct hw_ostc_gasmix_t { @@ -82,6 +85,9 @@ static const hw_ostc_layout_t hw_ostc_layout_ostc = { 15, /* atmospheric */ 43, /* salinity */ 47, /* duration */ + 51, /* deco alg */ + 49, /* GF low */ + 50, /* GF high */ }; static const hw_ostc_layout_t hw_ostc_layout_frog = { @@ -91,6 +97,9 @@ static const hw_ostc_layout_t hw_ostc_layout_frog = { 21, /* atmospheric */ 43, /* salinity */ 47, /* duration */ + -1, /* deco alg */ + -1, /* GF low */ + -1, /* GF high */ }; static const hw_ostc_layout_t hw_ostc_layout_ostc3 = { @@ -100,6 +109,9 @@ static const hw_ostc_layout_t hw_ostc_layout_ostc3 = { 24, /* atmospheric */ 70, /* salinity */ 75, /* duration */ + 79, /* deco alg */ + 77, /* GF low */ + 78, /* GF high */ }; dc_status_t @@ -259,7 +271,10 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_salinity_t *water = (dc_salinity_t *) value; + dc_deco_alg_t *deco_alg = (dc_deco_alg_t *) value; + unsigned int *gf = (unsigned int *) value; unsigned int salinity = data[layout->salinity]; + unsigned char alg; if (version == 0x23) salinity += 100; @@ -306,6 +321,45 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned case DC_FIELD_ATMOSPHERIC: *((double *) value) = array_uint16_le (data + layout->atmospheric) / 1000.0; break; + case DC_FIELD_DECO_ALG: + if (layout->deco_alg == -1 || header ==47) + return DC_STATUS_UNSUPPORTED; + alg = data[layout->deco_alg]; + if (header == 57) { + if (alg == 0 || alg == 2) + *deco_alg = DC_DECO_ALG_BZH; + else if (alg == 4 || alg == 5) + *deco_alg = DC_DECO_ALG_BZHGF; + else if (alg == 1 || alg == 3) + *deco_alg = DC_DECO_ALG_UNKNOWN; + else + return DC_STATUS_DATAFORMAT; + } else if (header == 256) { // this is just the OSTC3 - Frog had deco_alg == -1 + if (alg == 0) + *deco_alg = DC_DECO_ALG_BZH; + else if (alg == 1) + *deco_alg = DC_DECO_ALG_BZHGF; + else + return DC_STATUS_DATAFORMAT; + } else { + return DC_STATUS_UNSUPPORTED; + } + break; + case DC_FIELD_DECO_GFLOW: + case DC_FIELD_DECO_GFHIGH: + if (layout->deco_alg == -1 || header ==47) + return DC_STATUS_UNSUPPORTED; + alg = data[layout->deco_alg]; + if ((header == 57 && (alg == 4 || alg == 5)) || + (header == 256 && alg == 1)) { + if (type == DC_FIELD_DECO_GFLOW) + *gf = data[layout->gflow]; + else + *gf = data[layout->gfhigh]; + } else { + return DC_STATUS_UNSUPPORTED; + } + break; default: return DC_STATUS_UNSUPPORTED; } -- 1.8.0.rc0.18.gf84667d