wip
This commit is contained in:
0
selfdrive/debug/internal/__init__.py
Normal file
0
selfdrive/debug/internal/__init__.py
Normal file
52
selfdrive/debug/internal/fuzz_fw_fingerprint.py
Normal file
52
selfdrive/debug/internal/fuzz_fw_fingerprint.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
# type: ignore
|
||||
import random
|
||||
from collections import defaultdict
|
||||
|
||||
from tqdm import tqdm
|
||||
|
||||
from openpilot.selfdrive.car.fw_versions import match_fw_to_car_fuzzy
|
||||
from openpilot.selfdrive.car.toyota.values import FW_VERSIONS as TOYOTA_FW_VERSIONS
|
||||
from openpilot.selfdrive.car.honda.values import FW_VERSIONS as HONDA_FW_VERSIONS
|
||||
from openpilot.selfdrive.car.hyundai.values import FW_VERSIONS as HYUNDAI_FW_VERSIONS
|
||||
from openpilot.selfdrive.car.volkswagen.values import FW_VERSIONS as VW_FW_VERSIONS
|
||||
|
||||
|
||||
FWS = {}
|
||||
FWS.update(TOYOTA_FW_VERSIONS)
|
||||
FWS.update(HONDA_FW_VERSIONS)
|
||||
FWS.update(HYUNDAI_FW_VERSIONS)
|
||||
FWS.update(VW_FW_VERSIONS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
total = 0
|
||||
match = 0
|
||||
wrong_match = 0
|
||||
confusions = defaultdict(set)
|
||||
|
||||
for _ in tqdm(range(1000)):
|
||||
for candidate, fws in FWS.items():
|
||||
fw_dict = {}
|
||||
for (_, addr, subaddr), fw_list in fws.items():
|
||||
fw_dict[(addr, subaddr)] = [random.choice(fw_list)]
|
||||
|
||||
matches = match_fw_to_car_fuzzy(fw_dict, log=False, exclude=candidate)
|
||||
|
||||
total += 1
|
||||
if len(matches) == 1:
|
||||
if list(matches)[0] == candidate:
|
||||
match += 1
|
||||
else:
|
||||
confusions[candidate] |= matches
|
||||
wrong_match += 1
|
||||
|
||||
print()
|
||||
for candidate, wrong_matches in sorted(confusions.items()):
|
||||
print(candidate, wrong_matches)
|
||||
|
||||
print()
|
||||
print(f"Total fuzz cases: {total}")
|
||||
print(f"Correct matches: {match}")
|
||||
print(f"Wrong matches: {wrong_match}")
|
||||
|
||||
|
||||
33
selfdrive/debug/internal/measure_modeld_packet_drop.py
Normal file
33
selfdrive/debug/internal/measure_modeld_packet_drop.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
import cereal.messaging as messaging
|
||||
|
||||
if __name__ == "__main__":
|
||||
modeld_sock = messaging.sub_sock("modelV2")
|
||||
|
||||
last_frame_id = None
|
||||
start_t: int | None = None
|
||||
frame_cnt = 0
|
||||
dropped = 0
|
||||
|
||||
while True:
|
||||
m = messaging.recv_one(modeld_sock)
|
||||
if m is None:
|
||||
continue
|
||||
|
||||
frame_id = m.modelV2.frameId
|
||||
t = m.logMonoTime / 1e9
|
||||
frame_cnt += 1
|
||||
|
||||
if start_t is None:
|
||||
start_t = t
|
||||
last_frame_id = frame_id
|
||||
continue
|
||||
|
||||
d_frame = frame_id - last_frame_id
|
||||
dropped += d_frame - 1
|
||||
|
||||
expected_num_frames = int((t - start_t) * 20)
|
||||
frame_drop = 100 * (1 - (expected_num_frames / frame_cnt))
|
||||
print(f"Num dropped {dropped}, Drop compared to 20Hz: {frame_drop:.2f}%")
|
||||
|
||||
last_frame_id = frame_id
|
||||
59
selfdrive/debug/internal/measure_torque_time_to_max.py
Normal file
59
selfdrive/debug/internal/measure_torque_time_to_max.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
# type: ignore
|
||||
|
||||
import os
|
||||
import argparse
|
||||
import struct
|
||||
from collections import deque
|
||||
from statistics import mean
|
||||
|
||||
from cereal import log
|
||||
import cereal.messaging as messaging
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description='Sniff a communication socket')
|
||||
parser.add_argument('--addr', default='127.0.0.1')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.addr != "127.0.0.1":
|
||||
os.environ["ZMQ"] = "1"
|
||||
messaging.context = messaging.Context()
|
||||
|
||||
poller = messaging.Poller()
|
||||
messaging.sub_sock('can', poller, addr=args.addr)
|
||||
|
||||
active = 0
|
||||
start_t = 0
|
||||
start_v = 0
|
||||
max_v = 0
|
||||
max_t = 0
|
||||
window = deque(maxlen=10)
|
||||
avg = 0
|
||||
while 1:
|
||||
polld = poller.poll(1000)
|
||||
for sock in polld:
|
||||
msg = sock.receive()
|
||||
with log.Event.from_bytes(msg) as log_evt:
|
||||
evt = log_evt
|
||||
|
||||
for item in evt.can:
|
||||
if item.address == 0xe4 and item.src == 128:
|
||||
torque_req = struct.unpack('!h', item.dat[0:2])[0]
|
||||
# print(torque_req)
|
||||
active = abs(torque_req) > 0
|
||||
if abs(torque_req) < 100:
|
||||
if max_v > 5:
|
||||
print(f'{start_v} -> {max_v} = {round(max_v - start_v, 2)} over {round(max_t - start_t, 2)}s')
|
||||
start_t = evt.logMonoTime / 1e9
|
||||
start_v = avg
|
||||
max_t = 0
|
||||
max_v = 0
|
||||
if item.address == 0x1ab and item.src == 0:
|
||||
motor_torque = ((item.dat[0] & 0x3) << 8) + item.dat[1]
|
||||
window.append(motor_torque)
|
||||
avg = mean(window)
|
||||
#print(f'{evt.logMonoTime}: {avg}')
|
||||
if active and avg > max_v + 0.5:
|
||||
max_v = avg
|
||||
max_t = evt.logMonoTime / 1e9
|
||||
62
selfdrive/debug/internal/qlog_size.py
Normal file
62
selfdrive/debug/internal/qlog_size.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import bz2
|
||||
from collections import defaultdict
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from cereal.services import SERVICE_LIST
|
||||
from openpilot.tools.lib.logreader import LogReader
|
||||
from openpilot.tools.lib.route import Route
|
||||
|
||||
MIN_SIZE = 0.5 # Percent size of total to show as separate entry
|
||||
|
||||
|
||||
def make_pie(msgs, typ):
|
||||
compressed_length_by_type = {k: len(bz2.compress(b"".join(v))) for k, v in msgs.items()}
|
||||
|
||||
total = sum(compressed_length_by_type.values())
|
||||
|
||||
sizes = sorted(compressed_length_by_type.items(), key=lambda kv: kv[1])
|
||||
|
||||
print(f"{typ} - Total {total / 1024:.2f} kB")
|
||||
for (name, sz) in sizes:
|
||||
print(f"{name} - {sz / 1024:.2f} kB")
|
||||
print()
|
||||
|
||||
sizes_large = [(k, sz) for (k, sz) in sizes if sz >= total * MIN_SIZE / 100]
|
||||
sizes_large += [('other', sum(sz for (_, sz) in sizes if sz < total * MIN_SIZE / 100))]
|
||||
|
||||
labels, sizes = zip(*sizes_large, strict=True)
|
||||
|
||||
plt.figure()
|
||||
plt.title(f"{typ}")
|
||||
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Check qlog size based on a rlog')
|
||||
parser.add_argument('route', help='route to use')
|
||||
parser.add_argument('segment', type=int, help='segment number to use')
|
||||
args = parser.parse_args()
|
||||
|
||||
r = Route(args.route)
|
||||
rlog = r.log_paths()[args.segment]
|
||||
msgs = list(LogReader(rlog))
|
||||
|
||||
msgs_by_type = defaultdict(list)
|
||||
for m in msgs:
|
||||
msgs_by_type[m.which()].append(m.as_builder().to_bytes())
|
||||
|
||||
qlog_by_type = defaultdict(list)
|
||||
for name, service in SERVICE_LIST.items():
|
||||
if service.decimation is None:
|
||||
continue
|
||||
|
||||
for i, msg in enumerate(msgs_by_type[name]):
|
||||
if i % service.decimation == 0:
|
||||
qlog_by_type[name].append(msg)
|
||||
|
||||
make_pie(msgs_by_type, 'rlog')
|
||||
make_pie(qlog_by_type, 'qlog')
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user