Files
os/tools/siri-remote/notifs.py
2026-10-24 09:06:06 +02:00

34 lines
900 B
Python

#!/usr/bin/env python3
"""Extracts ATT notifications from `btmon -r capture.btsnoop` text output.
usage: btmon -r cap.btsnoop | notifs.py [handle ...]
Prints: time handle hexdata
"""
import re
import sys
want = set(sys.argv[1:])
ts = 0.0
lines = sys.stdin.read().split("\n")
i = 0
while i < len(lines):
l = lines[i]
m = re.search(r"LE-ACL:.*\]\s+(\d+\.\d+)\s*$", l)
if m:
ts = float(m.group(1))
if "Handle Value Notification" in l:
h = re.search(r"Handle: (0x[0-9a-f]+)", lines[i + 1]).group(1)
data = []
j = i + 3
while j < len(lines):
m2 = re.match(r"^\s{8}((?:[0-9a-f]{2} )+)", lines[j] + " ")
if not m2:
break
data += m2.group(1).split()
j += 1
if not want or h in want:
print(f"{ts:9.3f} {h} {' '.join(data)}")
i = j
continue
i += 1