from msg_container import MsgContainer from msg_sink import MsgSink from ubx.ubx import frame_parse, frame_parse_hdr from ubx.msg import UbxMsg class UbxReceiver(MsgSink): def __init__(self, parser: UbxMsg, mclass: int|None = None, mid: int|None = None): MsgSink.__init__(self) self.parser = parser self.mclass = mclass self.mid = mid def on_recv(self, msg: MsgContainer): data, hdr = frame_parse(msg.data) msg_parsed = self.parser.from_bytes(data) print(f"{msg.name}:{hdr.mclass}:{hdr.mid}:data({len(data)}):{msg_parsed}") def is_msg(self, msg: MsgContainer): hdr = frame_parse_hdr(msg.data) if hdr is not None: if self.mclass is not None and self.mid is not None: return self.mclass == hdr.mclass and self.mid == hdr.mid else: return True return False