]> mj.ucw.cz Git - home-hw.git/commitdiff
BSB daemon: Temperature is signed
authorMartin Mares <mj@ucw.cz>
Fri, 28 Feb 2020 18:58:41 +0000 (19:58 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 28 Feb 2020 18:58:41 +0000 (19:58 +0100)
bsb/daemon/burrow-bsbd.c

index a3870798eb70f4e88a562f40422e6053cdf7fdce..98fec4c0fed9bd86bccac8b7f2f4b227bd666b18 100644 (file)
@@ -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;