Files
protocol_convert_software_BD3/protocol/a_frame.py

35 lines
865 B
Python

import struct
class AFrame:
def __init__(self, data: bytes):
self.valid = False
self.data_id = 0
self.payload = b""
self.values = []
if len(data) < 24 + 8 + 2:
return
try:
magic, dlen, dir_, data_id, ptype, sat = struct.unpack('>IIIIII', data[:24])
payload = data[24:-2]
tail = data[-2:]
if magic != 0xEB90EB90 or tail != b'\x4C\x3A':
return
self.valid = True
self.data_id = data_id
self.payload = payload
# 按8字节切分double
vs = []
buf = payload
while len(buf) >= 8:
v = struct.unpack('>d', buf[:8])[0]
vs.append(v)
buf = buf[8:]
self.values = vs
except:
pass