From 859c925802a3ed8bc5871fa14d9e9f99c412b63c Mon Sep 17 00:00:00 2001 From: "Mr.one" Date: Tue, 4 Aug 2026 14:03:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91pandad.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selfdrive/pandad/pandad.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/selfdrive/pandad/pandad.py b/selfdrive/pandad/pandad.py index 2400f8cd6..87719de02 100755 --- a/selfdrive/pandad/pandad.py +++ b/selfdrive/pandad/pandad.py @@ -79,19 +79,32 @@ def main() -> None: while not do_exit: try: cloudlog.event("pandad.flash_and_connect", count=count) - if (count % 2) == 0: + if count == 0: HARDWARE.reset_internal_panda() - else: - HARDWARE.recover_internal_panda() count += 1 - # Flash all Pandas in DFU mode - for serial in PandaDFU.list(): - cloudlog.info(f"Panda in DFU mode found, flashing recovery {serial}") - PandaDFU(serial).recover() - time.sleep(1) + # The internal panda takes a few seconds to boot its app after a reset. + # Wait for it to come back in normal mode before deciding to flash. + panda_serials: list[str] = [] + for _ in range(16): + panda_serials = Panda.list() + if len(panda_serials) == 1: + try: + with Panda(panda_serials[0]) as p: + if not p.bootstub: + break + except Exception: + pass + time.sleep(0.5) + + if len(panda_serials) == 0: + # Flash all Pandas in DFU mode + for serial in PandaDFU.list(): + cloudlog.info(f"Panda in DFU mode found, flashing recovery {serial}") + PandaDFU(serial).recover() + time.sleep(1) + panda_serials = Panda.list() - panda_serials = Panda.list() if len(panda_serials): assert len(panda_serials) == 1 cloudlog.info(f"{len(panda_serials)} panda found, connecting - {panda_serials}")