mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 09:13:52 +08:00
@@ -52,7 +52,7 @@ class PandaJungle(Panda):
|
|||||||
|
|
||||||
def flash(self, fn=None, code=None, reconnect=True):
|
def flash(self, fn=None, code=None, reconnect=True):
|
||||||
if not fn:
|
if not fn:
|
||||||
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn.replace("panda", "panda_jungle"))
|
fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn.replace("panda", "panda_jungle"))
|
||||||
super().flash(fn=fn, code=code, reconnect=reconnect)
|
super().flash(fn=fn, code=code, reconnect=reconnect)
|
||||||
|
|
||||||
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
|
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
|
||||||
@@ -73,9 +73,15 @@ class PandaJungle(Panda):
|
|||||||
self.flash()
|
self.flash()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_mcu_type(self) -> McuType:
|
||||||
|
hw_type = self.get_type()
|
||||||
|
if hw_type in PandaJungle.H7_DEVICES:
|
||||||
|
return McuType.H7
|
||||||
|
raise ValueError(f"unknown HW type: {hw_type}")
|
||||||
|
|
||||||
def up_to_date(self, fn=None) -> bool:
|
def up_to_date(self, fn=None) -> bool:
|
||||||
if fn is None:
|
if fn is None:
|
||||||
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn.replace("panda", "panda_jungle"))
|
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn.replace("panda", "panda_jungle"))
|
||||||
return super().up_to_date(fn=fn)
|
return super().up_to_date(fn=fn)
|
||||||
|
|
||||||
# ******************* health *******************
|
# ******************* health *******************
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ class Panda:
|
|||||||
else:
|
else:
|
||||||
self._connect_serial = serial
|
self._connect_serial = serial
|
||||||
|
|
||||||
|
# connect and set mcu type
|
||||||
self.connect(claim)
|
self.connect(claim)
|
||||||
|
|
||||||
def _cli_select_panda(self):
|
def _cli_select_panda(self):
|
||||||
@@ -201,9 +202,13 @@ class Panda:
|
|||||||
self._serial = serial
|
self._serial = serial
|
||||||
self._connect_serial = serial
|
self._connect_serial = serial
|
||||||
self._handle_open = True
|
self._handle_open = True
|
||||||
|
self._mcu_type = self.get_mcu_type()
|
||||||
self.health_version, self.can_version, self.can_health_version = self.get_packets_versions()
|
self.health_version, self.can_version, self.can_health_version = self.get_packets_versions()
|
||||||
logger.debug("connected")
|
logger.debug("connected")
|
||||||
|
|
||||||
|
hw_type = self.get_type()
|
||||||
|
assert hw_type in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
|
||||||
|
|
||||||
# disable openpilot's heartbeat checks
|
# disable openpilot's heartbeat checks
|
||||||
if self._disable_checks:
|
if self._disable_checks:
|
||||||
self.set_heartbeat_disabled()
|
self.set_heartbeat_disabled()
|
||||||
@@ -330,9 +335,6 @@ class Panda:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def reset(self, enter_bootstub=False, enter_bootloader=False, reconnect=True):
|
def reset(self, enter_bootstub=False, enter_bootloader=False, reconnect=True):
|
||||||
if enter_bootstub or enter_bootloader:
|
|
||||||
assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
|
|
||||||
|
|
||||||
# no response is expected since it resets right away
|
# no response is expected since it resets right away
|
||||||
timeout = 5000 if isinstance(self._handle, PandaSpiHandle) else 15000
|
timeout = 5000 if isinstance(self._handle, PandaSpiHandle) else 15000
|
||||||
try:
|
try:
|
||||||
@@ -412,14 +414,16 @@ class Panda:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def flash(self, fn=None, code=None, reconnect=True):
|
def flash(self, fn=None, code=None, reconnect=True):
|
||||||
assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
|
|
||||||
|
|
||||||
if self.up_to_date(fn=fn):
|
if self.up_to_date(fn=fn):
|
||||||
logger.info("flash: already up to date")
|
logger.info("flash: already up to date")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
hw_type = self.get_type()
|
||||||
|
if hw_type not in self.SUPPORTED_DEVICES:
|
||||||
|
raise RuntimeError(f"HW type {hw_type.hex()} is deprecated and can no longer be flashed.")
|
||||||
|
|
||||||
if not fn:
|
if not fn:
|
||||||
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn)
|
fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn)
|
||||||
assert os.path.isfile(fn)
|
assert os.path.isfile(fn)
|
||||||
logger.debug("flash: main version is %s", self.get_version())
|
logger.debug("flash: main version is %s", self.get_version())
|
||||||
if not self.bootstub:
|
if not self.bootstub:
|
||||||
@@ -434,15 +438,13 @@ class Panda:
|
|||||||
logger.debug("flash: bootstub version is %s", self.get_version())
|
logger.debug("flash: bootstub version is %s", self.get_version())
|
||||||
|
|
||||||
# do flash
|
# do flash
|
||||||
Panda.flash_static(self._handle, code, mcu_type=McuType.H7)
|
Panda.flash_static(self._handle, code, mcu_type=self._mcu_type)
|
||||||
|
|
||||||
# reconnect
|
# reconnect
|
||||||
if reconnect:
|
if reconnect:
|
||||||
self.reconnect()
|
self.reconnect()
|
||||||
|
|
||||||
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
|
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
|
||||||
assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
|
|
||||||
|
|
||||||
dfu_serial = self.get_dfu_serial()
|
dfu_serial = self.get_dfu_serial()
|
||||||
|
|
||||||
if reset:
|
if reset:
|
||||||
@@ -487,7 +489,7 @@ class Panda:
|
|||||||
def up_to_date(self, fn=None) -> bool:
|
def up_to_date(self, fn=None) -> bool:
|
||||||
current = self.get_signature()
|
current = self.get_signature()
|
||||||
if fn is None:
|
if fn is None:
|
||||||
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn)
|
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn)
|
||||||
expected = Panda.get_signature_from_firmware(fn)
|
expected = Panda.get_signature_from_firmware(fn)
|
||||||
return (current == expected)
|
return (current == expected)
|
||||||
|
|
||||||
@@ -599,6 +601,12 @@ class Panda:
|
|||||||
else:
|
else:
|
||||||
return (0, 0, 0)
|
return (0, 0, 0)
|
||||||
|
|
||||||
|
def get_mcu_type(self) -> McuType:
|
||||||
|
hw_type = self.get_type()
|
||||||
|
if hw_type in Panda.H7_DEVICES:
|
||||||
|
return McuType.H7
|
||||||
|
raise ValueError(f"unknown HW type: {hw_type}")
|
||||||
|
|
||||||
def is_internal(self):
|
def is_internal(self):
|
||||||
return self.get_type() in Panda.INTERNAL_DEVICES
|
return self.get_type() in Panda.INTERNAL_DEVICES
|
||||||
|
|
||||||
@@ -619,7 +627,7 @@ class Panda:
|
|||||||
return self._serial
|
return self._serial
|
||||||
|
|
||||||
def get_dfu_serial(self):
|
def get_dfu_serial(self):
|
||||||
return PandaDFU.st_serial_to_dfu_serial(self._serial, McuType.H7)
|
return PandaDFU.st_serial_to_dfu_serial(self._serial, self._mcu_type)
|
||||||
|
|
||||||
def get_uid(self):
|
def get_uid(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ def check_signature(p):
|
|||||||
|
|
||||||
|
|
||||||
def test_dfu(p):
|
def test_dfu(p):
|
||||||
|
app_mcu_type = p.get_mcu_type()
|
||||||
dfu_serial = p.get_dfu_serial()
|
dfu_serial = p.get_dfu_serial()
|
||||||
|
|
||||||
p.reset(enter_bootstub=True)
|
p.reset(enter_bootstub=True)
|
||||||
@@ -18,7 +19,7 @@ def test_dfu(p):
|
|||||||
assert Panda.wait_for_dfu(dfu_serial, timeout=19), "failed to enter DFU"
|
assert Panda.wait_for_dfu(dfu_serial, timeout=19), "failed to enter DFU"
|
||||||
|
|
||||||
dfu = PandaDFU(dfu_serial)
|
dfu = PandaDFU(dfu_serial)
|
||||||
assert dfu.get_mcu_type() == McuType.H7
|
assert dfu.get_mcu_type() == app_mcu_type
|
||||||
|
|
||||||
assert dfu_serial in PandaDFU.list()
|
assert dfu_serial in PandaDFU.list()
|
||||||
|
|
||||||
@@ -37,9 +38,9 @@ def test_known_bootstub(p):
|
|||||||
McuType.H7: ["bootstub.panda_h7.bin"],
|
McuType.H7: ["bootstub.panda_h7.bin"],
|
||||||
}
|
}
|
||||||
|
|
||||||
for kb in known_bootstubs[McuType.H7]:
|
for kb in known_bootstubs[p.get_mcu_type()]:
|
||||||
app_serial = p.get_usb_serial()
|
app_ids = (p.get_mcu_type(), p.get_usb_serial())
|
||||||
assert app_serial is not None
|
assert None not in app_ids
|
||||||
|
|
||||||
p.reset(enter_bootstub=True)
|
p.reset(enter_bootstub=True)
|
||||||
p.reset(enter_bootloader=True)
|
p.reset(enter_bootloader=True)
|
||||||
@@ -56,9 +57,10 @@ def test_known_bootstub(p):
|
|||||||
|
|
||||||
p.connect(claim=False, wait=True)
|
p.connect(claim=False, wait=True)
|
||||||
|
|
||||||
# check for serial mismatch
|
# check for MCU or serial mismatch
|
||||||
with Panda(p._serial, claim=False) as np:
|
with Panda(p._serial, claim=False) as np:
|
||||||
assert np.get_usb_serial() == app_serial
|
bootstub_ids = (np.get_mcu_type(), np.get_usb_serial())
|
||||||
|
assert app_ids == bootstub_ids
|
||||||
|
|
||||||
# ensure we can flash app and it jumps to app
|
# ensure we can flash app and it jumps to app
|
||||||
p.flash()
|
p.flash()
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ def test_hw_type(p):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
hw_type = p.get_type()
|
hw_type = p.get_type()
|
||||||
|
mcu_type = p.get_mcu_type()
|
||||||
|
assert mcu_type is not None
|
||||||
|
|
||||||
app_uid = p.get_uid()
|
app_uid = p.get_uid()
|
||||||
usb_serial = p.get_usb_serial()
|
usb_serial = p.get_usb_serial()
|
||||||
@@ -28,6 +30,7 @@ def test_hw_type(p):
|
|||||||
with Panda(p.get_usb_serial()) as pp:
|
with Panda(p.get_usb_serial()) as pp:
|
||||||
assert pp.bootstub
|
assert pp.bootstub
|
||||||
assert pp.get_type() == hw_type, "Bootstub and app hw type mismatch"
|
assert pp.get_type() == hw_type, "Bootstub and app hw type mismatch"
|
||||||
|
assert pp.get_mcu_type() == mcu_type, "Bootstub and app MCU type mismatch"
|
||||||
assert pp.get_uid() == app_uid
|
assert pp.get_uid() == app_uid
|
||||||
|
|
||||||
def test_heartbeat(p, panda_jungle):
|
def test_heartbeat(p, panda_jungle):
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ def recover(s):
|
|||||||
def flash(s):
|
def flash(s):
|
||||||
with PandaJungle(s) as p:
|
with PandaJungle(s) as p:
|
||||||
p.flash()
|
p.flash()
|
||||||
|
return p.get_mcu_type()
|
||||||
|
|
||||||
# Reset + flash all CI hardware to get it into a consistent state
|
# Reset + flash all CI hardware to get it into a consistent state
|
||||||
# * port 1: jungles-under-test
|
# * port 1: jungles-under-test
|
||||||
@@ -41,4 +42,5 @@ if __name__ == "__main__":
|
|||||||
for s in SERIALS:
|
for s in SERIALS:
|
||||||
assert PandaJungle.wait_for_panda(s, timeout=10)
|
assert PandaJungle.wait_for_panda(s, timeout=10)
|
||||||
assert set(PandaJungle.list()) >= SERIALS
|
assert set(PandaJungle.list()) >= SERIALS
|
||||||
list(exc.map(flash, SERIALS, timeout=20))
|
mcu_types = list(exc.map(flash, SERIALS, timeout=20))
|
||||||
|
assert set(mcu_types) == {McuType.H7, }
|
||||||
|
|||||||
Reference in New Issue
Block a user