2020-01-18 03:23:21 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
import json
|
2021-03-02 05:03:44 +08:00
|
|
|
import codecs
|
2023-08-10 04:26:54 +08:00
|
|
|
import cereal.messaging as messaging
|
2020-01-18 03:23:21 +08:00
|
|
|
|
2023-08-10 04:26:54 +08:00
|
|
|
from hexdump import hexdump
|
2020-01-18 03:23:21 +08:00
|
|
|
from cereal import log
|
2023-09-22 09:25:15 +08:00
|
|
|
from cereal.services import SERVICE_LIST
|
2020-01-18 03:23:21 +08:00
|
|
|
|
2023-08-10 04:26:54 +08:00
|
|
|
codecs.register_error("strict", codecs.backslashreplace_errors)
|
|
|
|
|
2020-01-18 03:23:21 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2022-04-30 11:13:44 +08:00
|
|
|
parser = argparse.ArgumentParser(description='Dump communication sockets. See cereal/services.py for a complete list of available sockets.')
|
2020-01-18 03:23:21 +08:00
|
|
|
parser.add_argument('--pipe', action='store_true')
|
|
|
|
parser.add_argument('--raw', action='store_true')
|
|
|
|
parser.add_argument('--json', action='store_true')
|
|
|
|
parser.add_argument('--dump-json', action='store_true')
|
|
|
|
parser.add_argument('--no-print', action='store_true')
|
|
|
|
parser.add_argument('--addr', default='127.0.0.1')
|
|
|
|
parser.add_argument('--values', help='values to monitor (instead of entire event)')
|
2021-10-13 11:17:12 +08:00
|
|
|
parser.add_argument("socket", type=str, nargs='*', help="socket names to dump. defaults to all services defined in cereal")
|
2020-01-18 03:23:21 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.addr != "127.0.0.1":
|
|
|
|
os.environ["ZMQ"] = "1"
|
|
|
|
messaging.context = messaging.Context()
|
|
|
|
|
|
|
|
poller = messaging.Poller()
|
|
|
|
|
2023-09-22 09:25:15 +08:00
|
|
|
for m in args.socket if len(args.socket) > 0 else SERVICE_LIST:
|
2020-06-28 08:46:59 +08:00
|
|
|
messaging.sub_sock(m, poller, addr=args.addr)
|
2020-01-18 03:23:21 +08:00
|
|
|
|
|
|
|
values = None
|
|
|
|
if args.values:
|
|
|
|
values = [s.strip().split(".") for s in args.values.split(",")]
|
|
|
|
|
|
|
|
while 1:
|
2021-03-30 18:16:57 +08:00
|
|
|
polld = poller.poll(100)
|
2020-01-18 03:23:21 +08:00
|
|
|
for sock in polld:
|
|
|
|
msg = sock.receive()
|
2023-07-21 12:56:57 +08:00
|
|
|
with log.Event.from_bytes(msg) as log_evt:
|
|
|
|
evt = log_evt
|
2020-01-18 03:23:21 +08:00
|
|
|
|
|
|
|
if not args.no_print:
|
|
|
|
if args.pipe:
|
|
|
|
sys.stdout.write(msg)
|
|
|
|
sys.stdout.flush()
|
|
|
|
elif args.raw:
|
|
|
|
hexdump(msg)
|
|
|
|
elif args.json:
|
|
|
|
print(json.loads(msg))
|
|
|
|
elif args.dump_json:
|
|
|
|
print(json.dumps(evt.to_dict()))
|
|
|
|
elif values:
|
2021-12-16 21:58:17 +08:00
|
|
|
print(f"logMonotime = {evt.logMonoTime}")
|
2020-01-18 03:23:21 +08:00
|
|
|
for value in values:
|
|
|
|
if hasattr(evt, value[0]):
|
|
|
|
item = evt
|
|
|
|
for key in value:
|
|
|
|
item = getattr(item, key)
|
2021-12-16 21:58:17 +08:00
|
|
|
print(f"{'.'.join(value)} = {item}")
|
2020-01-18 03:23:21 +08:00
|
|
|
print("")
|
|
|
|
else:
|
2020-08-13 16:10:50 +08:00
|
|
|
try:
|
|
|
|
print(evt)
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
w = evt.which()
|
|
|
|
s = f"( logMonoTime {evt.logMonoTime} \n {w} = "
|
|
|
|
s += str(evt.__getattr__(w))
|
|
|
|
s += f"\n valid = {evt.valid} )"
|
|
|
|
print(s)
|