""" PGNs verarbeiten """ import struct import time from datetime import timedelta, date from . import lookup def parse_60928(buf, device): """ Sets data in device and returns the 64bit NAME of device """ device.lastseen = time.time() # 21 bits Unique-ID und 11 bits Manuf.-Code device.uniqueid = ((buf[0] << 16) + (buf[1] << 8) + buf[2]) >> 3 device.manufacturercode = (buf[3] * 256 + buf[2]) >> 5 device.instance = buf[4] device.instlower = buf[4] & 0x07 device.instupper = buf[4] >> 3 device.devicefunction = buf[5] device.deviceclass = (buf[6] & 0x7f) >> 1 device.industrygroup = (buf[7] >> 4) & 0x07 # 3bit device.sysinstance = buf[7] & 0x0f # 4bit return struct.unpack_from('>Q', buf, 0)[0] def parse_126992(buf, source): # System time print(f"PGN 126992 System time from {source}") sid = buf[0] src = buf[1] & 0x0f dval = date(1970,1,1) + timedelta(days=(buf[3] << 8) + buf[2]) secs = struct.unpack_from(' 2: device.instdesc1 = buf[2:txtlen].decode('ascii') p = txtlen else: device.instdesc1 = "" p = 2 # Installation Description 2 txtlen = buf[p] if txtlen > 2: device.instdesc2 = buf[p+2:p+txtlen].decode('ascii') p += txtlen else: device.instdesc2 = "" p += 2 # Manufacturer Info txtlen = buf[p] if txtlen > 2: device.manufinfo = buf[p+2:p+txtlen].decode('ascii') else: device.manufinfo = "" def parse_127257(buf, boatdata): # Attitude sid = buf[0] yaw = struct.unpack_from('> 2 ix += 1 def parse_127502(buf): # Switch control # 7 byte for switches every switch takes 2 bits # 0 = Off, 1=On, 2 and 3 unknown instance = buf[0] switch = [0] * 28 ix = 0 for b in range(1, 8): val = buf[b] for x in range(4): switch[ix] = val & 0x03 val = val >> 2 ix += 1 def parse_127505(buf, boatdata): # Fluid Level instance = buf[0] & 0x0f if instance in boatdata.tank: boatdata.tank[instance].fluidtype = buf[0] >> 4 boatdata.tank[instance].level = struct.unpack_from('> 6 # 0: true, 1: magnetic, 2: error cog = struct.unpack_from('> 4 navterm = buf[1] & 0x03 xte = struct.unpack_from('