|
|
@ -99,6 +99,7 @@ class StatusResponse(Response): |
|
|
|
frequency = None |
|
|
|
powerfactor = None |
|
|
|
event_count = None |
|
|
|
unpack_error = False |
|
|
|
|
|
|
|
def unpack(self, fmt, base): |
|
|
|
""" |
|
|
@ -111,6 +112,7 @@ class StatusResponse(Response): |
|
|
|
""" |
|
|
|
size = struct.calcsize(fmt) |
|
|
|
if (len(self.response) < base+size): |
|
|
|
self.unpack_error = True |
|
|
|
logging.error(f'base: {base} size: {size} len: {len(self.response)} fmt: {fmt} rep: {self.response}') |
|
|
|
return [0] |
|
|
|
return struct.unpack(fmt, self.response[base:base+size]) |
|
|
@ -196,7 +198,8 @@ class StatusResponse(Response): |
|
|
|
data['event_count'] = self.event_count |
|
|
|
data['time'] = self.time_rx |
|
|
|
|
|
|
|
return data |
|
|
|
if not self.unpack_error: |
|
|
|
return data |
|
|
|
|
|
|
|
class UnknownResponse(Response): |
|
|
|
""" |
|
|
@ -334,12 +337,13 @@ class EventsResponse(UnknownResponse): |
|
|
|
|
|
|
|
logging.debug(' '.join([f'{byte:02x}' for byte in chunk]) + ': ') |
|
|
|
|
|
|
|
if (len(chunk[0:6]) == 6): |
|
|
|
opcode, a_code, a_count, uptime_sec = struct.unpack('>BBHH', chunk[0:6]) |
|
|
|
a_text = self.alarm_codes.get(a_code, 'N/A') |
|
|
|
logging.debug(f' uptime={timedelta(seconds=uptime_sec)} a_count={a_count} opcode={opcode} a_code={a_code} a_text={a_text}') |
|
|
|
else: |
|
|
|
if (len(chunk[0:6]) < 6): |
|
|
|
logging.error(f'length of chunk must be greater or equal 6 bytes: {chunk}') |
|
|
|
return |
|
|
|
|
|
|
|
opcode, a_code, a_count, uptime_sec = struct.unpack('>BBHH', chunk[0:6]) |
|
|
|
a_text = self.alarm_codes.get(a_code, 'N/A') |
|
|
|
logging.debug(f' uptime={timedelta(seconds=uptime_sec)} a_count={a_count} opcode={opcode} a_code={a_code} a_text={a_text}') |
|
|
|
|
|
|
|
dbg = '' |
|
|
|
for fmt in ['BBHHHHH']: |
|
|
@ -366,12 +370,15 @@ class HardwareInfoResponse(UnknownResponse): |
|
|
|
def __dict__(self): |
|
|
|
""" Base values, availabe in each __dict__ call """ |
|
|
|
|
|
|
|
data = super().__dict__() |
|
|
|
responce_info = self.response |
|
|
|
if (len(responce_info) >= 16): |
|
|
|
logging.info(f'HardwareInfoResponse: {struct.unpack(">HHHHHHHH", responce_info)}') |
|
|
|
else: |
|
|
|
logging.error(f'wrong length of HardwareInfoResponse: {responce_info}') |
|
|
|
|
|
|
|
if (len(self.response) != 16): |
|
|
|
logging.error(f'HardwareInfoResponse: data length should be 16 bytes - measured {len(self.response)} bytes') |
|
|
|
logging.error(f'HardwareInfoResponse: data: {self.response}') |
|
|
|
return data |
|
|
|
|
|
|
|
logging.info(f'HardwareInfoResponse: {struct.unpack(">HHHHHHHH", self.response[0:16])}') |
|
|
|
fw_version, fw_build_yyyy, fw_build_mmdd, fw_build_hhmm, hw_id = struct.unpack('>HHHHH', self.response[0:10]) |
|
|
|
|
|
|
|
fw_version_maj = int((fw_version / 10000)) |
|
|
@ -385,7 +392,6 @@ class HardwareInfoResponse(UnknownResponse): |
|
|
|
f'build at {fw_build_dd:>02}/{fw_build_mm:>02}/{fw_build_yyyy}T{fw_build_HH:>02}:{fw_build_MM:>02}, '\ |
|
|
|
f'HW revision {hw_id}') |
|
|
|
|
|
|
|
data = super().__dict__() |
|
|
|
data['FW_ver_maj'] = fw_version_maj |
|
|
|
data['FW_ver_min'] = fw_version_min |
|
|
|
data['FW_ver_pat'] = fw_version_pat |
|
|
|