]> mj.ucw.cz Git - home-hw.git/commitdiff
Aircon: Bug fixes
authorMartin Mares <mj@ucw.cz>
Tue, 16 Jul 2019 19:10:34 +0000 (21:10 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 16 Jul 2019 19:10:34 +0000 (21:10 +0200)
aircon/firmware/main.c

index 556ec89440533c052af0d7a8f239ec26e036fcc3..89307b48710cd0c3c7680df1386c6b0ccbb4a9d2 100644 (file)
@@ -240,7 +240,7 @@ enum aircon_input_registers {
        AIRCON_IREG_TEMP_MIXED,
        AIRCON_IREG_MAX,
        AIRCON_IREG_DS_ID_BASE = 0x1000,
-       AIRCON_IREG_DS_ID_MAX = AIRCON_IREG_DS_ID_BASE + 4*DS_NUM_SENSORS,
+       AIRCON_IREG_DS_ID_MAX = AIRCON_IREG_DS_ID_BASE + 3*DS_NUM_SENSORS,
 };
 
 enum aircon_holding_registers {
@@ -294,7 +294,7 @@ void modbus_set_coil(u16 addr, bool value)
 
 bool modbus_check_input_register(u16 addr)
 {
-       return (addr < AIRCON_IREG_MAX || addr >= AIRCON_IREG_DS_ID_MAX && addr < AIRCON_IREG_DS_ID_MAX);
+       return (addr < AIRCON_IREG_MAX || addr >= AIRCON_IREG_DS_ID_BASE && addr < AIRCON_IREG_DS_ID_MAX);
 }
 
 static const byte temp_sensor_addrs[][8] = {
@@ -309,7 +309,7 @@ u16 modbus_get_input_register(u16 addr)
 {
        if (addr <= AIRCON_IREG_TEMP_MIXED) {
                byte i = 0;
-               while (i < DS_NUM_SENSORS && memcmp(ds_sensors[i].address, temp_sensor_addrs[addr], 8))
+               while (i < DS_NUM_SENSORS && memcmp(ds_sensors[i].address + 1, temp_sensor_addrs[addr], 6))
                        i++;
                if (i >= DS_NUM_SENSORS)
                        return 0x8000;
@@ -317,9 +317,9 @@ u16 modbus_get_input_register(u16 addr)
                        return 0x8000;
                return ds_sensors[i].current_temp & 0xffff;
        } else if (addr >= AIRCON_IREG_DS_ID_BASE && addr < AIRCON_IREG_DS_ID_MAX) {
-               byte i = (addr - AIRCON_IREG_DS_ID_BASE) / 4;
-               byte j = (addr - AIRCON_IREG_DS_ID_BASE) % 4;
-               return get_u16_be(ds_sensors[i].address + 2*j);
+               byte i = (addr - AIRCON_IREG_DS_ID_BASE) / 3;
+               byte j = (addr - AIRCON_IREG_DS_ID_BASE) % 3;
+               return get_u16_be(ds_sensors[i].address + 2*j + 1);
        } else {
                return 0;
        }