Files
story/firmware/echoear-platform-agent/tools/observe-com6-controls.py
T

20 lines
1.3 KiB
Python
Raw Normal View History

"""Capture operational metadata only; no voice text, credentials, or network names."""
import pathlib,re,serial,sys,time,json
s=serial.Serial();s.port='COM6';s.baudrate=115200;s.timeout=.2;s.dtr=False;s.rts=False;s.open()
s.write(b'\ndiag-state\n')
duration=int(sys.argv[1]) if len(sys.argv)>1 else 40
end=time.monotonic()+duration
output=[];tags={}
allow=re.compile(r'(RTC diagnostic:|device_control:|device_ota:|Platform error code:|POST /api/v1/device/(control|mqtt|ota)|Direct chat ready;|Startup task finished|Guru Meditation|Backtrace:|assert failed:|CORRUPT HEAP|Stack canary|Rebooting|esp-tls:|esp_mqtt:|mqtt_client:|Transport failed|Failed to allocate|Failed to create|Cannot allocate|system_api:)')
while time.monotonic()<end:
line=s.readline().decode('utf-8','replace').strip()
tag=re.search(r'\) ([A-Za-z_0-9-]+):',line)
if tag:tags[tag[1]]=tags.get(tag[1],0)+1
if allow.search(line):
safe=line[:700];output.append(safe);print(safe,flush=True)
s.close()
summary={'seconds':duration,'log_tags':tags,'selected_lines':len(output)}
print(json.dumps(summary),flush=True)
path=pathlib.Path('E:/Codex/story/.local-evidence/com6-controls-20260922/serial-controls.log')
with path.open('a',encoding='utf-8') as f:f.write('\n'.join(output)+'\n'+json.dumps(summary)+'\n')