Skip to content

Commit

Permalink
pandad: only reset pandas on first run (commaai#23511)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm authored Jan 13, 2022
1 parent 6d16b0c commit 1538013
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions selfdrive/pandad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from selfdrive.swaglog import cloudlog


def get_expected_signature(panda : Panda) -> bytes:
def get_expected_signature(panda: Panda) -> bytes:
fn = DEFAULT_H7_FW_FN if (panda.get_mcu_type() == MCU_TYPE_H7) else DEFAULT_FW_FN

try:
Expand All @@ -23,7 +23,7 @@ def get_expected_signature(panda : Panda) -> bytes:
return b""


def flash_panda(panda_serial : str) -> Panda:
def flash_panda(panda_serial: str) -> Panda:
panda = Panda(panda_serial)

fw_signature = get_expected_signature(panda)
Expand Down Expand Up @@ -54,7 +54,8 @@ def flash_panda(panda_serial : str) -> Panda:

return panda

def panda_sort_cmp(a : Panda, b : Panda):

def panda_sort_cmp(a: Panda, b: Panda):
a_type = a.get_type()
b_type = b.get_type()

Expand All @@ -71,7 +72,10 @@ def panda_sort_cmp(a : Panda, b : Panda):
# last resort: sort by serial number
return a.get_usb_serial() < b.get_usb_serial()


def main() -> NoReturn:
first_run = True

while True:
try:
# Flash all Pandas in DFU mode
Expand All @@ -98,8 +102,9 @@ def main() -> NoReturn:
Params().put_bool("PandaHeartbeatLost", True)
cloudlog.event("heartbeat lost", deviceState=health, serial=panda.get_usb_serial())

cloudlog.info(f"Resetting panda {panda.get_usb_serial()}")
panda.reset()
if first_run:
cloudlog.info(f"Resetting panda {panda.get_usb_serial()}")
panda.reset()

# sort pandas to have deterministic order
pandas.sort(key=cmp_to_key(panda_sort_cmp))
Expand All @@ -113,6 +118,8 @@ def main() -> NoReturn:
cloudlog.exception("Panda USB exception while setting up")
continue

first_run = False

# run boardd with all connected serials as arguments
os.chdir(os.path.join(BASEDIR, "selfdrive/boardd"))
subprocess.run(["./boardd", *panda_serials], check=True)
Expand Down

0 comments on commit 1538013

Please sign in to comment.