You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.4 KiB
101 lines
2.4 KiB
4 years ago
|
#!/usr/bin/env python3
|
||
|
import os
|
||
|
import time
|
||
|
from multiprocessing import Process
|
||
|
from tqdm import tqdm
|
||
|
|
||
|
os.environ['FILEREADER_CACHE'] = '1'
|
||
|
|
||
4 years ago
|
from common.realtime import config_realtime_process, Ratekeeper, DT_CTRL
|
||
4 years ago
|
from selfdrive.boardd.boardd import can_capnp_to_can_list
|
||
|
from tools.lib.logreader import LogReader
|
||
|
from panda import Panda
|
||
|
try:
|
||
4 years ago
|
from panda_jungle import PandaJungle # pylint: disable=import-error
|
||
4 years ago
|
except Exception:
|
||
4 years ago
|
PandaJungle = None # type: ignore
|
||
4 years ago
|
|
||
|
ROUTE = "77611a1fac303767/2020-03-24--09-50-38"
|
||
4 years ago
|
NUM_SEGS = 2 # route has 82 segments available
|
||
4 years ago
|
|
||
|
print("Loading log...")
|
||
|
CAN_MSGS = []
|
||
4 years ago
|
for i in tqdm(list(range(1, NUM_SEGS+1))):
|
||
4 years ago
|
log_url = f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2"
|
||
|
lr = LogReader(log_url)
|
||
|
CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can']
|
||
|
|
||
4 years ago
|
# set both to cycle ignition
|
||
|
IGN_ON = int(os.getenv("ON", "0"))
|
||
|
IGN_OFF = int(os.getenv("OFF", "0"))
|
||
4 years ago
|
ENABLE_IGN = IGN_ON > 0 and IGN_OFF > 0
|
||
|
if ENABLE_IGN:
|
||
|
print(f"Cycling ignition: on for {IGN_ON}s, off for {IGN_OFF}s")
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
def send_thread(s):
|
||
|
if "Jungle" in str(type(s)):
|
||
|
if "FLASH" in os.environ:
|
||
|
s.flash()
|
||
4 years ago
|
|
||
4 years ago
|
for i in [0, 1, 2, 3, 0xFFFF]:
|
||
4 years ago
|
s.can_clear(i)
|
||
|
s.set_ignition(False)
|
||
4 years ago
|
time.sleep(5)
|
||
4 years ago
|
s.set_ignition(True)
|
||
|
s.set_panda_power(True)
|
||
4 years ago
|
else:
|
||
4 years ago
|
s.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
||
|
s.set_can_loopback(False)
|
||
4 years ago
|
|
||
4 years ago
|
|
||
4 years ago
|
idx = 0
|
||
|
ign = True
|
||
4 years ago
|
rk = Ratekeeper(1 / DT_CTRL, print_delay_threshold=None)
|
||
4 years ago
|
while True:
|
||
4 years ago
|
# handle ignition cycling
|
||
4 years ago
|
if ENABLE_IGN:
|
||
|
i = (rk.frame*DT_CTRL) % (IGN_ON + IGN_OFF) < IGN_ON
|
||
|
if i != ign:
|
||
|
ign = i
|
||
|
s.set_ignition(ign)
|
||
|
|
||
|
snd = CAN_MSGS[idx]
|
||
4 years ago
|
snd = list(filter(lambda x: x[-1] <= 2, snd))
|
||
4 years ago
|
s.can_send_many(snd)
|
||
|
idx = (idx + 1) % len(CAN_MSGS)
|
||
4 years ago
|
|
||
|
# Drain panda message buffer
|
||
4 years ago
|
s.can_recv()
|
||
4 years ago
|
rk.keep_time()
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
def connect():
|
||
4 years ago
|
config_realtime_process(3, 55)
|
||
|
|
||
4 years ago
|
serials = {}
|
||
|
while True:
|
||
|
# look for new devices
|
||
|
for p in [Panda, PandaJungle]:
|
||
|
if p is None:
|
||
|
continue
|
||
|
|
||
|
for s in p.list():
|
||
|
if s not in serials:
|
||
|
print("starting send thread for", s)
|
||
4 years ago
|
serials[s] = Process(target=send_thread, args=(p(s), ))
|
||
4 years ago
|
serials[s].start()
|
||
|
|
||
|
# try to join all send procs
|
||
|
cur_serials = serials.copy()
|
||
|
for s, p in cur_serials.items():
|
||
|
p.join(0.01)
|
||
|
if p.exitcode is not None:
|
||
|
del serials[s]
|
||
|
|
||
|
time.sleep(1)
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
if __name__ == "__main__":
|
||
|
connect()
|