From: Gerhard Sittig Date: Mon, 23 Dec 2019 16:00:13 +0000 (+0100) Subject: center-3xx: use common signed LE16 conversion for temperature value X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=56a1bf7b4b8ccb969140196e90f62178de10da19;p=libsigrok.git center-3xx: use common signed LE16 conversion for temperature value Prefer the common conversion helper for little endian 16bit signed data. The previous local implementation only worked for positive values, and yielded incorrect results for negative temperatures. This fixes bug #1463. --- diff --git a/src/hardware/center-3xx/protocol.c b/src/hardware/center-3xx/protocol.c index 81868b06..196e29de 100644 --- a/src/hardware/center-3xx/protocol.c +++ b/src/hardware/center-3xx/protocol.c @@ -64,7 +64,7 @@ static void log_packet(const uint8_t *buf, int idx) static int packet_parse(const uint8_t *buf, int idx, struct center_info *info) { int i; - uint16_t temp_u16; + int16_t temp_i16; log_packet(buf, idx); @@ -89,9 +89,8 @@ static int packet_parse(const uint8_t *buf, int idx, struct center_info *info) /* Byte 7+8/9+10/11+12/13+14: channel T1/T2/T3/T4 temperature. */ for (i = 0; i < NUM_CHANNELS; i++) { - temp_u16 = buf[8 + (i * 2)]; - temp_u16 |= ((uint16_t)buf[7 + (i * 2)] << 8); - info->temp[i] = (float)temp_u16; + temp_i16 = RL16S(&buf[7 + 2 * i]); + info->temp[i] = (float)temp_i16; } /* Byte 43: Specifies whether we need to divide the value(s) by 10. */