From d2e150319b96049516e69ad3ba87cf4cd254e095 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 4 Feb 2016 08:31:44 +0100 Subject: [PATCH] Fix the decoding of negative temperatures. Due to a firmware bug, negative temperatures are stored incorrectly and a workaround is necessary to recover the correct value. --- src/shearwater_predator_parser.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index f1a5c31..71c09c7 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -389,7 +389,14 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); // Temperature (°C or °F). - unsigned int temperature = data[offset + 13]; + int temperature = (signed char) data[offset + 13]; + if (temperature < 0) { + // Fix negative temperatures. + temperature += 102; + if (temperature > 0) { + temperature = 0; + } + } if (units == IMPERIAL) sample.temperature = (temperature - 32.0) * (5.0 / 9.0); else