首次提交完整的python工程代码
This commit is contained in:
35
protocol/a_frame.py
Normal file
35
protocol/a_frame.py
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
Reference in New Issue
Block a user