can replay: flashing lock

pull/21407/head
Comma Device 4 years ago
parent fd81a5556b
commit 6a5940c562
  1. 24
      tools/replay/can_replay.py

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import time import time
from multiprocessing import Process import threading
from tqdm import tqdm from tqdm import tqdm
os.environ['FILEREADER_CACHE'] = '1' os.environ['FILEREADER_CACHE'] = '1'
@ -15,16 +15,17 @@ try:
except Exception: except Exception:
PandaJungle = None # type: ignore PandaJungle = None # type: ignore
ROUTE = "77611a1fac303767/2020-03-24--09-50-38"
NUM_SEGS = 2 # route has 82 segments available
print("Loading log...") print("Loading log...")
ROUTE = "77611a1fac303767/2020-03-24--09-50-38"
NUM_SEGS = 2 # route has 82 segments available
CAN_MSGS = [] CAN_MSGS = []
for i in tqdm(list(range(1, NUM_SEGS+1))): for i in tqdm(list(range(1, NUM_SEGS+1))):
log_url = f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2" log_url = f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2"
lr = LogReader(log_url) lr = LogReader(log_url)
CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can'] CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can']
# set both to cycle ignition # set both to cycle ignition
IGN_ON = int(os.getenv("ON", "0")) IGN_ON = int(os.getenv("ON", "0"))
IGN_OFF = int(os.getenv("OFF", "0")) IGN_OFF = int(os.getenv("OFF", "0"))
@ -33,10 +34,11 @@ if ENABLE_IGN:
print(f"Cycling ignition: on for {IGN_ON}s, off for {IGN_OFF}s") print(f"Cycling ignition: on for {IGN_ON}s, off for {IGN_OFF}s")
def send_thread(s): def send_thread(s, flock):
if "Jungle" in str(type(s)): if "Jungle" in str(type(s)):
if "FLASH" in os.environ: if "FLASH" in os.environ:
s.flash() with flock:
s.flash()
for i in [0, 1, 2, 3, 0xFFFF]: for i in [0, 1, 2, 3, 0xFFFF]:
s.can_clear(i) s.can_clear(i)
@ -48,7 +50,6 @@ def send_thread(s):
s.set_safety_mode(Panda.SAFETY_ALLOUTPUT) s.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
s.set_can_loopback(False) s.set_can_loopback(False)
idx = 0 idx = 0
ign = True ign = True
rk = Ratekeeper(1 / DT_CTRL, print_delay_threshold=None) rk = Ratekeeper(1 / DT_CTRL, print_delay_threshold=None)
@ -74,6 +75,7 @@ def connect():
config_realtime_process(3, 55) config_realtime_process(3, 55)
serials = {} serials = {}
flashing_lock = threading.Lock()
while True: while True:
# look for new devices # look for new devices
for p in [Panda, PandaJungle]: for p in [Panda, PandaJungle]:
@ -83,14 +85,14 @@ def connect():
for s in p.list(): for s in p.list():
if s not in serials: if s not in serials:
print("starting send thread for", s) print("starting send thread for", s)
serials[s] = Process(target=send_thread, args=(p(s), )) serials[s] = threading.Thread(target=send_thread, args=(p(s), flashing_lock))
serials[s].start() serials[s].start()
# try to join all send procs # try to join all send threads
cur_serials = serials.copy() cur_serials = serials.copy()
for s, p in cur_serials.items(): for s, t in cur_serials.items():
p.join(0.01) t.join(0.01)
if p.exitcode is not None: if not t.is_alive():
del serials[s] del serials[s]
time.sleep(1) time.sleep(1)

Loading…
Cancel
Save