refactored

This commit is contained in:
2026-03-16 10:00:06 +01:00
parent 4ef406ff9a
commit 50d70ccce0
5 changed files with 41 additions and 10 deletions
-9
View File
@@ -1,9 +0,0 @@
from msg_receiver import MsgReceiver
class Nmea(MsgReceiver):
def __init__(self, name: str, tid: str, msg_type: str):
if tid == "--":
MsgReceiver.__init__(self, name, filter=f"^\\$..{msg_type}.*")
else:
MsgReceiver.__init__(self, name, filter=f"^\\${tid}{msg_type}.*")
@@ -2,7 +2,7 @@ from msg_container import MsgContainer
from msg_sink import MsgSink
import re
class MsgReceiver(MsgSink):
class AsciiReceiver(MsgSink):
def __init__(self, name: str, filter: str):
super().__init__()
self.name = name
+9
View File
@@ -0,0 +1,9 @@
from receiver.ascii_receiver import AsciiReceiver
class NmeaReceiver(AsciiReceiver):
def __init__(self, name: str, tid: str, msg_type: str):
if tid == "--":
AsciiReceiver.__init__(self, name, filter=f"^\\$..{msg_type}.*")
else:
AsciiReceiver.__init__(self, name, filter=f"^\\${tid}{msg_type}.*")
+31
View File
@@ -0,0 +1,31 @@
from msg_container import MsgContainer
from msg_sink import MsgSink
from msg_source import MsgSource
from struct import pack
class Packetizer(MsgSink, MsgSource):
def __init__(self):
MsgSink.__init__(self)
MsgSource.__init__(self)
self.packet = b''
self.wait_sync = True
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:
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)
def is_msg(self, msg: MsgContainer):
return True