From 9c3af57038b18f8bcfab74c8a3f09276330df338 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 1 Dec 2012 10:27:33 +0100 Subject: [PATCH] Fix a regression in the depth calculation. Apparently some older firmware versions don't support the salinity setting. Because unused bytes are initialized with zero, the salinity adjustment results in a division by zero, which converts all depth values to infinity. To fix this regression, the salinity factor is first checked for valid values. If the value is out of range, no salinity adjustment is done, and the previous behaviour is retained. --- src/hw_ostc_parser.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index f86fed3..7588146 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -277,6 +277,12 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Get the sample rate. unsigned int samplerate = data[36]; + // Get the salinity factor. + unsigned int salinity = data[43]; + if (salinity < 100 || salinity > 104) + salinity = 100; + double hydrostatic = GRAVITY * salinity * 10.0; + // Get the extended sample configuration. hw_ostc_sample_info_t info[NINFO]; for (unsigned int i = 0; i < NINFO; ++i) { @@ -308,7 +314,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Depth (mbar). unsigned int depth = array_uint16_le (data + offset); - sample.depth = (depth * BAR / 1000.0) / (GRAVITY * data[43] * 10.0); + sample.depth = (depth * BAR / 1000.0) / hydrostatic; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); offset += 2;