From b81dfba8fe4b5ebefb061d5fda5139ddf4d6ad66 Mon Sep 17 00:00:00 2001 From: Igor Biletskyy Date: Tue, 30 Aug 2022 10:46:12 -0700 Subject: [PATCH] python lib: cleanup hw type check (#1050) cleanup --- python/__init__.py | 31 +++---------------------------- tests/gmlan_harness_test.py | 6 +++--- tests/gps_stability_test.py | 4 ++-- tests/pedal/test_pedal.py | 2 +- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index e06cf0ba..1382e9ea 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -181,6 +181,8 @@ class Panda: F4_DEVICES = (HW_TYPE_WHITE_PANDA, HW_TYPE_GREY_PANDA, HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS) H7_DEVICES = (HW_TYPE_RED_PANDA, ) + HAS_OBD = (HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS, HW_TYPE_RED_PANDA) + CLOCK_SOURCE_MODE_DISABLED = 0 CLOCK_SOURCE_MODE_FREE_RUNNING = 1 @@ -498,27 +500,6 @@ class Panda: else: return (0, 0) - def is_white(self): - return self.get_type() == Panda.HW_TYPE_WHITE_PANDA - - def is_grey(self): - return self.get_type() == Panda.HW_TYPE_GREY_PANDA - - def is_black(self): - return self.get_type() == Panda.HW_TYPE_BLACK_PANDA - - def is_pedal(self): - return self.get_type() == Panda.HW_TYPE_PEDAL - - def is_uno(self): - return self.get_type() == Panda.HW_TYPE_UNO - - def is_dos(self): - return self.get_type() == Panda.HW_TYPE_DOS - - def is_red(self): - return self.get_type() == Panda.HW_TYPE_RED_PANDA - def get_mcu_type(self): hw_type = self.get_type() if hw_type in Panda.F2_DEVICES: @@ -530,13 +511,7 @@ class Panda: return None def has_obd(self): - return (self.is_uno() or self.is_dos() or self.is_black() or self.is_red()) - - def has_canfd(self) -> bool: - return self.get_type() in Panda.H7_DEVICES - - def is_internal(self) -> bool: - return self.get_type() in (Panda.HW_TYPE_UNO, Panda.HW_TYPE_DOS) + return self.get_type() in Panda.HAS_OBD def get_serial(self): dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20) diff --git a/tests/gmlan_harness_test.py b/tests/gmlan_harness_test.py index 587d850f..f10f98fc 100755 --- a/tests/gmlan_harness_test.py +++ b/tests/gmlan_harness_test.py @@ -11,19 +11,19 @@ WHITE_GMLAN_BUS = 3 OTHER_GMLAN_BUS = 1 def set_gmlan(p): - if p.is_white(): + if p.get_type() == Panda.HW_TYPE_WHITE_PANDA: p.set_gmlan(2) else: p.set_obd(True) def set_speed_kbps(p, speed): - if p.is_white(): + if p.get_type() == Panda.HW_TYPE_WHITE_PANDA: p.set_can_speed_kbps(WHITE_GMLAN_BUS, speed) else: p.set_can_speed_kbps(OTHER_GMLAN_BUS, speed) def send(p, id_, msg): - if p.is_white(): + if p.get_type() == Panda.HW_TYPE_WHITE_PANDA: p.can_send(id_, msg, WHITE_GMLAN_BUS) else: p.can_send(id_, msg, OTHER_GMLAN_BUS) diff --git a/tests/gps_stability_test.py b/tests/gps_stability_test.py index d113f7e9..f8cb13ca 100755 --- a/tests/gps_stability_test.py +++ b/tests/gps_stability_test.py @@ -30,10 +30,10 @@ def connect(): gps_panda = None # find out which one is white (for spamming the CAN buses) - if pandas[0].is_white() and not pandas[1].is_white(): + if pandas[0].get_type() == Panda.HW_TYPE_WHITE_PANDA and pandas[1].get_type() != Panda.HW_TYPE_WHITE_PANDA: white_panda = pandas[0] gps_panda = pandas[1] - elif not pandas[0].is_white() and pandas[1].is_white(): + elif pandas[0].get_type() != Panda.HW_TYPE_WHITE_PANDA and pandas[1].get_type() == Panda.HW_TYPE_WHITE_PANDA: white_panda = pandas[1] gps_panda = pandas[0] else: diff --git a/tests/pedal/test_pedal.py b/tests/pedal/test_pedal.py index 00b7d4ba..16da1354 100755 --- a/tests/pedal/test_pedal.py +++ b/tests/pedal/test_pedal.py @@ -48,7 +48,7 @@ class TestPedal(unittest.TestCase): self._flash_over_can(PEDAL_BUS, f"{BASEDIR}board/obj/pedal_usb.bin.signed") time.sleep(2) p = Panda(PEDAL_SERIAL) - self.assertTrue(p.is_pedal()) + self.assertTrue(p.get_type() == Panda.HW_TYPE_PEDAL) p.close() self.assertTrue(self._listen_can_frames() > 40)