DF-3017 / serialwatch.py
#!/usr/bin/env python3 """Serial watcher: tee the 2cpu forensic serial socket to a file, flag DF3017-CHAIN-WON or panic lines. usage: serialwatch.py <outfile> [secs]""" import socket, sys, time, os out = open(sys.argv[1], "ab", 0) secs = int(sys.argv[2]) if len(sys.argv) > 2 else 600 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect("/tmp/opencode/df3017-f2-serial.sock") s.settimeout(1.0) t0 = time.time() win = False panic = False while time.time() - t0 < secs: try: d = s.recv(65536) except socket.timeout: if win or panic: break continue if not d: break out.write(d) try: txt = d.decode("utf-8", "replace") except Exception: continue if "DF3017-CHAIN-WON" in txt: win = True print("[watch] WIN MARKER SEEN") if "panic:" in txt or "Fatal trap" in txt: panic = True print("[watch] PANIC SEEN:", txt.strip().splitlines()[-1][:80]) break s.close() out.close() print("[watch] done win=%s panic=%s" % (win, panic)) sys.exit(0 if win else 3) |