|
|
@@ -61,14 +61,70 @@ class NbusSlave():
|
|
|
|
|
|
def cmd_sensor_type(self, index):
|
|
|
resp = self.serial_port.request(self.module, index, CMD_SENSOR_TYPE, [])
|
|
|
- return resp[3]
|
|
|
-
|
|
|
- def cmd_sensors_type(self, pocet):
|
|
|
- resp = self.serial_port.request(self.module, 0, CMD_SENSOR_TYPE, [])
|
|
|
- typy = [];
|
|
|
- for i in range(pocet):
|
|
|
- typy.append([resp[3 + 2 * i], resp[4 + 2 * i]])
|
|
|
- return typy
|
|
|
+ type_struct={}
|
|
|
+ n = (len(resp) - 4)//2 # pocet typov
|
|
|
+ for i in range(n):
|
|
|
+ type_struct[resp[i*2+3]] = resp[i*2+4]
|
|
|
+ return type_struct
|
|
|
+
|
|
|
+ def cmd_sensors_format(self):
|
|
|
+ resp = self.serial_port.request(self.module, 0, CMD_FORMAT, [])
|
|
|
+ type_struct={}
|
|
|
+ n = (len(resp) - 4)//4 # pocet typov
|
|
|
+ for i in range(n):
|
|
|
+ fmt={}
|
|
|
+ b1 = resp[3+i*4+1]
|
|
|
+ b2 = resp[3+i*4+2]
|
|
|
+ b3 = resp[3+i*4+3]
|
|
|
+ fmt["sign"] = (b1 & 0x80)>>7
|
|
|
+ fmt["multiplier"] = b1 & 0x7F
|
|
|
+ fmt["value_multiplier"] = b2
|
|
|
+ fmt["byte_length"] = b3>>4
|
|
|
+ fmt["samples"] = b2 & 0xF
|
|
|
+ type_struct[resp[i*4+3]] = fmt
|
|
|
+ return type_struct
|
|
|
+
|
|
|
+ def cmd_sensor_info(self):
|
|
|
+ resp = self.serial_port.request(self.module, 0, CMD_INFO, [])
|
|
|
+ info_struct={}
|
|
|
+ n = (len(resp))
|
|
|
+ print(n)
|
|
|
+ if n<34:
|
|
|
+ return {}
|
|
|
+ info_struct["name"] = ""
|
|
|
+ for i in range(8):
|
|
|
+ if resp[i+3]>=32:
|
|
|
+ info_struct["name"] += chr(resp[i+3])
|
|
|
+ info_struct["type"] = ""
|
|
|
+ for i in range(3):
|
|
|
+ info_struct["type"] += chr(resp[i+11])
|
|
|
+ info_struct["id"] = ""
|
|
|
+ idhw=0
|
|
|
+ for i in range(4):
|
|
|
+ idhw = idhw*256 + resp[i+14]
|
|
|
+ info_struct["id"] = hex(idhw)
|
|
|
+
|
|
|
+ info_struct["FW"] = ""
|
|
|
+ for i in range(3):
|
|
|
+ info_struct["FW"] += chr(resp[i+18])
|
|
|
+
|
|
|
+ info_struct["HW"] = ""
|
|
|
+ for i in range(3):
|
|
|
+ info_struct["HW"] += chr(resp[i+21])
|
|
|
+
|
|
|
+ info_struct["MEM"] = ""
|
|
|
+ idhw=0
|
|
|
+ for i in range(8):
|
|
|
+ idhw = idhw*256 + resp[i+24]
|
|
|
+ info_struct["MEM"] = hex(idhw)
|
|
|
+
|
|
|
+ info_struct["sensors"] = resp[32]
|
|
|
+ info_struct["actuators"] = resp[33]
|
|
|
+
|
|
|
+ return info_struct
|
|
|
+
|
|
|
+ def cmd_sensors_type(self):
|
|
|
+ return self.cmd_sensor_type(0)
|
|
|
|
|
|
def cmd_sensor_get_data(self, index):
|
|
|
resp = self.serial_port.request(self.module, index, CMD_DATA, [])
|