refactored

This commit is contained in:
2026-03-16 11:06:18 +01:00
parent 50d70ccce0
commit 34e56c6291
11 changed files with 131 additions and 78 deletions
+27 -12
View File
@@ -3,29 +3,44 @@ from msg_sink import MsgSink
from msg_source import MsgSource
from struct import pack
class Packetizer(MsgSink, MsgSource):
def __init__(self):
class UbxPacketizer(MsgSink, MsgSource):
def __init__(self, sync_bytes: bytes):
MsgSink.__init__(self)
MsgSource.__init__(self)
self.sync_bytes = sync_bytes
self.packet = b''
self.wait_sync = True
self.latency = None
def on_recv(self, msg: MsgContainer):
name = msg.name
data = msg.data
for n in range (len(data)):
d = data[n]
if d == 13 or d == 10:
w = len(self.sync_bytes)
self.latency = 0
for n in range (0, len(data)):
d = data[n:n+w]
if d == self.sync_bytes:
self.latency = w-1
print("UBX-sync")
timestamp = msg.timestamp
self.wait_sync = False
if len(self.packet) > 0:
self.call_sinks(MsgContainer(name, timestamp, self.packet))
self.wait_sync = True
self.packet = b''
elif not self.wait_sync:
self.packet += pack('B', d)
if self.latency == 0:
self.packet += d
else:
self.latency -= 1
def is_msg(self, msg: MsgContainer):
return True
return True
if __name__ == "__main__":
_sync = b'JA'
_data = b'31'
pkt = UbxPacketizer(sync_bytes=_sync)
frame1 = _sync + b'31' + _sync + b'31'
pkt.on_recv(MsgContainer('test', 31101970.0208, frame1))
frame2 = _sync + b'3' + _sync + b'10'
pkt.on_recv(MsgContainer('test', 31101970.0208, frame2))