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.
This commit is contained in:
Jef Driesen 2012-12-01 10:27:33 +01:00
parent 3803e3c52d
commit 9c3af57038

View File

@ -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;