Check the salinity byte for out of range values.

Apparently some older firmware versions don't support the salinity
setting. Because unused bytes are initialized with zero, the salinity
value will be reported as being zero.

To fix this unexpected value, the salinity factor is first checked for
valid values. If the value is out of range, a DC_STATUS_UNSUPPORTED
error is returned to indicate the absence of the value.
This commit is contained in:
Jef Driesen 2012-12-01 12:45:16 +01:00
parent d3de4bf9bd
commit 3502ad39a6

View File

@ -212,6 +212,7 @@ 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;
unsigned int salinity = data[43];
if (value) {
switch (type) {
@ -236,11 +237,14 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
break;
case DC_FIELD_SALINITY:
if (data[43] == 100)
if (salinity < 100 || salinity > 104)
return DC_STATUS_UNSUPPORTED;
if (salinity == 100)
water->type = DC_WATER_FRESH;
else
water->type = DC_WATER_SALT;
water->density = data[43] * 10.0;
water->density = salinity * 10.0;
break;
case DC_FIELD_ATMOSPHERIC:
*((double *) value) = array_uint16_le (data + 15) / 1000.0;