tools: byd_can_dump — skip 'boot' dir, robust rlog/qlog discovery, fix sys.path
The auto-detect picked /data/media/0/realdata/boot (boot logs, no rlog). Now scans newest-first for a dir that actually contains an rlog/qlog, skips 'boot', and inserts repo root into sys.path so it runs from any CWD.
This commit is contained in:
1 parent
b598ba5dcb
commit
5684dd9d0e
1 file changed
+31
-12
+31
-12
@@ -22,9 +22,12 @@ Key BYD addresses it highlights:
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
KEY_ADDRS = {
|
KEY_ADDRS = {
|
||||||
287: "STEER_MODULE",
|
287: "STEER_MODULE",
|
||||||
289: "ESC",
|
289: "ESC",
|
||||||
@@ -59,23 +62,39 @@ def print_table(stats, started_mono=None):
|
|||||||
print(f"{addr:>6} {length:>3} {count:>7} {rate:>7.1f} {name}{marker}")
|
print(f"{addr:>6} {length:>3} {count:>7} {rate:>7.1f} {name}{marker}")
|
||||||
|
|
||||||
|
|
||||||
|
LOG_NAMES = ("rlog", "rlog.bz2", "rlog.zst", "qlog", "qlog.bz2", "qlog.zst")
|
||||||
|
|
||||||
|
|
||||||
|
def find_log_file(route_dir):
|
||||||
|
for name in LOG_NAMES:
|
||||||
|
p = os.path.join(route_dir, name)
|
||||||
|
if os.path.exists(p):
|
||||||
|
return p
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def find_latest_log(base):
|
||||||
|
"""Newest dir (by name) that actually contains an rlog/qlog; skips 'boot'."""
|
||||||
|
for d in sorted(os.listdir(base), reverse=True):
|
||||||
|
p = os.path.join(base, d)
|
||||||
|
if not os.path.isdir(p) or d == "boot":
|
||||||
|
continue
|
||||||
|
lp = find_log_file(p)
|
||||||
|
if lp is not None:
|
||||||
|
return lp
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def dump_from_route(route_dir=None):
|
def dump_from_route(route_dir=None):
|
||||||
from openpilot.tools.lib.logreader import LogReader
|
from openpilot.tools.lib.logreader import LogReader
|
||||||
|
|
||||||
base = "/data/media/0/realdata"
|
base = "/data/media/0/realdata"
|
||||||
if route_dir is None:
|
if route_dir is None:
|
||||||
routes = sorted(d for d in os.listdir(base) if os.path.isdir(os.path.join(base, d)))
|
log_path = find_latest_log(base)
|
||||||
assert routes, f"no routes found in {base}"
|
assert log_path is not None, f"no routes with rlog/qlog found in {base}"
|
||||||
route_dir = os.path.join(base, routes[-1])
|
else:
|
||||||
print(f"using latest route: {route_dir}")
|
log_path = find_log_file(route_dir)
|
||||||
|
assert log_path is not None, f"no rlog/qlog found in {route_dir}"
|
||||||
log_path = None
|
|
||||||
for name in ("rlog", "rlog.bz2", "rlog.zst", "qlog", "qlog.bz2", "qlog.zst"):
|
|
||||||
p = os.path.join(route_dir, name)
|
|
||||||
if os.path.exists(p):
|
|
||||||
log_path = p
|
|
||||||
break
|
|
||||||
assert log_path, f"no rlog/qlog found in {route_dir}"
|
|
||||||
print(f"reading {log_path} ...")
|
print(f"reading {log_path} ...")
|
||||||
|
|
||||||
stats = {}
|
stats = {}
|
||||||
|
|||||||
Reference in new issue
Block a user