From 1e601a988ab8c3868ee39c4f43fb80efd1a153d0 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 28 Feb 2020 19:58:41 +0100 Subject: [PATCH] BSB daemon: Temperature is signed --- bsb/daemon/burrow-bsbd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bsb/daemon/burrow-bsbd.c b/bsb/daemon/burrow-bsbd.c index a387079..98fec4c 100644 --- a/bsb/daemon/burrow-bsbd.c +++ b/bsb/daemon/burrow-bsbd.c @@ -174,6 +174,15 @@ static const char * const stat_names[] = { #undef P }; +static int get_s16_be(const byte *x) +{ + int val = get_u16_be(x); + if (val >= 0x8000) + return val - 0x10000; + else + return val; +} + static void process_stats(time_t t, byte *resp, uint len) { for (uint i=0; i < ARRAY_SIZE(stat_names) && 4*i + 3 < (uint) len; i++) { @@ -195,7 +204,7 @@ static void process_info(byte *p, uint len) switch (addr) { case 0x05000219: if (len >= 4) { - uint temp = get_u16_be(p); + int temp = get_s16_be(p); uint press = get_u16_be(p + 2); mqtt_publish("burrow/heating/outside-temp", "%.2f", temp / 64.); mqtt_publish("burrow/heating/water-pressure", "%.1f", press / 10.); @@ -204,7 +213,7 @@ static void process_info(byte *p, uint len) case 0x05000229: // AGU.2 status if (len >= 2) { - uint temp = get_u16_be(p); + int temp = get_s16_be(p); mqtt_publish("burrow/heating/circuit1/mix-temp", "%.2f", temp / 64.); } break; @@ -218,14 +227,14 @@ static void process_info(byte *p, uint len) case 0x3d2d0215: // Room 1 status if (len >= 2) { - uint temp = get_u16_be(p); + int temp = get_s16_be(p); mqtt_publish("burrow/heating/circuit1/room-temp", "%.2f", temp / 64.); } break; case 0x3e2e0215: // Room 2 status if (len >= 2) { - uint temp = get_u16_be(p); + int temp = get_s16_be(p); mqtt_publish("burrow/heating/circuit2/room-temp", "%.2f", temp / 64.); } break; -- 2.39.2