diff --git a/mesht_device.py b/mesht_device.py index 5328dd4..31c6cdb 100644 --- a/mesht_device.py +++ b/mesht_device.py @@ -12,6 +12,8 @@ from protobufs_extra.queuestatus_proto import * from protobufs_extra.device_metadata_proto import * from protobufs_extra.file_info_proto import * +from protobuf_decoder.protobuf_decoder import Parser + DATA_SCHEMA = [ ("varint", "portnum", 1), ("bytes", "payload", 2), @@ -214,6 +216,13 @@ PORTNUMS = { } NAMES_TO_PORTNUMS = {v: k for k, v in PORTNUMS.items()} +def parseBytesToProtobuf(byte_s): + try: + to_parse = ' '.join(f'{byte:02x}' for byte in byte_s) + res = Parser().parse(to_parse) + print("TESTED CLIENT SEND PROTO: ", res.to_dict()) + except: + pass class Channel: def __init__(self, index, name, role): @@ -223,7 +232,7 @@ class Channel: class MeshtDevice: - def __init__(self, transport, device_uuid, skip_init = False): + def __init__(self, transport, device_uuid, skip_init = False, test_client = False): self.transport = transport self.channels = [] self.lora_config = None @@ -233,6 +242,7 @@ class MeshtDevice: self.nid = None self.device_uuid = device_uuid self.skip_init = skip_init + self.test_client = test_client async def start(self): await self.transport.start() @@ -270,6 +280,11 @@ class MeshtDevice: async def recv(self): data = await self.transport.recv() + + if self.test_client: + parseBytesToProtobuf(data) + return {}, b"" + fr = pb.decode(data, FROMRADIO_SCHEMA) fr["device_uuid"] = self.device_uuid logger.debug(f"FromRadio: {fr}") diff --git a/packet_test.py b/packet_test.py index bc58dcf..ddadd58 100644 --- a/packet_test.py +++ b/packet_test.py @@ -3,7 +3,25 @@ import base64 import pb from mesht_device import FROMRADIO_SCHEMA, NODEINFO_SCHEMA, USER_SCHEMA, MESHPACKET_SCHEMA +from protobuf_decoder.protobuf_decoder import Parser ## -packet = "Em414jjW0ApSDdApp7IV/////yIiCEMSHA2+0JFpEhUIZRWTGIxAHcovCkElgprlPCj+9ChIADX3/LZnPczQkWlFAAAcwUgDYJv//////////wF4B5gBIKgBARIITG9uZ0Zhc3QaCSE5ZTc3MzhkOA==ClIN0CmnshX/////IiIIQxIcDb7QkWkSFQhlFZMYjEAdyi8KQSWCmuU8KP70KEgANff8tmc9zNCRaUUAABzBSANgm///////////AXgHmAEgqAEBEghMb25nRmFzdBoJITllNzczOGQ4" +packet = "nP712mDRlbdujxpSd4bUMBiNR/WQj5t4qXfxKA==" data = base64.b64decode(packet) -print(pb.decode(data, FROMRADIO_SCHEMA)) \ No newline at end of file +res = Parser().parse(data.hex()) + +print(res.to_dict()) +print(pb.decode(data, USER_SCHEMA)) + +### +#print(base64.b64decode('BtJrAGXS0BJzm9890X0uD1VawYhZ+woD5O6UI3oXUjmB')) +#from bson.binary import Binary as BinData +#enc = BinData('CgkhMDZmOTM5MDASEERyTzIgfCBDRU4gfCA4NjgaBERyTzIiBpAVBvk5ACgDOAxCIAvwvaWvYapqWHtbnIVK+Iil93nOk2DHMf0qMDg+Kf5XSAA='.encode("ascii"), 0) +#print(enc.hex) +#enc. +#from protobuf_decoder.protobuf_decoder import Parser +#packet = "BtJrAGXS0BJzm9890X0uD1VawYhZ+woD5O6UI3oXUjmB" +#data = base64.b64decode(packet) +#to_parse = ' '.join(f'{byte:02x}' for byte in data) +#res = Parser().parse(enc.hex()) +#print(res.to_dict()) +#print(pb.decode(data, FROMRADIO_SCHEMA)) \ No newline at end of file diff --git a/service.py b/service.py index 434decb..46056b9 100644 --- a/service.py +++ b/service.py @@ -89,7 +89,7 @@ class MeshMultiListener(MeshArgsParse): logger.info("Found ws transport") from transport_ws import WSTransport transport = WSTransport(device_config["port"], device_config["uuid"]) - self.devices.append(MeshtDevice(transport, device_config['uuid'], True)) + self.devices.append(MeshtDevice(transport, device_config['uuid'], True, True)) #set default mesh self.defaultDeviceUUID = self.json_config[0]["uuid"] @@ -112,7 +112,9 @@ class MeshMultiListener(MeshArgsParse): device.state = AVAILABLE while True: from_radio, _ = await device.recv() - await queue.put(from_radio) + if not device.test_client: + await queue.put(from_radio) + device.last_packet_catch = time() except asyncio.exceptions.CancelledError: logger.info(str(device), " kill device")