Technician tool v0.2

Imported from the Google Drive folder 004-technician_tool/v0.2.
This commit is contained in:
kkallas committed 2026-09-26 16:53:59 +02:00
1 parent e5a33a1c34
commit e8b72b743d
17 files changed
+2410 -283

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
"""Load saved logs for offline analysis.
Accepts both raw serial captures and this tool's session logs, whose lines
look like "[14:02:11.532] I (1234) TAG: msg" and whose host events look
like "[14:02:11.532] --- reset issued by tool ---".
"""
from __future__ import annotations
import re
from pathlib import Path
from .logline import LineKind, LogLine, parse_line, split_glued
_SESSION_PREFIX = re.compile(r"^\[(\d\d):(\d\d):(\d\d)\.(\d{3})\] ")
_HOST_EVENT = re.compile(r"^--- .* ---$")
def read_log_file(path: Path) -> list[LogLine]:
text = path.read_bytes().decode("utf-8", errors="replace")
out: list[LogLine] = []
for i, raw in enumerate(text.splitlines()):
host_time = i * 0.001 # raw capture: keep order, no wall clock
if m := _SESSION_PREFIX.match(raw):
h, mi, s, ms = (int(g) for g in m.groups())
host_time = h * 3600 + mi * 60 + s + ms / 1000
raw = raw[m.end():]
if _HOST_EVENT.match(raw):
out.append(LogLine(raw, LineKind.HOST, host_time))
continue
out.extend(parse_line(part, host_time) for part in split_glued(raw))
return out