From eb9b0df727a277863be8f6ee1a1209a687cf5a51 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 25 Jan 2024 22:17:19 +0100 Subject: [PATCH] Reset baudrate when connecting from Python (#1837) * Reset baudrate when connecting from Python * unused --- python/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 09220bb7..08a18c97 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -28,6 +28,7 @@ logging.basicConfig(level=LOGLEVEL, format='%(message)s') CANPACKET_HEAD_SIZE = 0x6 DLC_TO_LEN = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64] LEN_TO_DLC = {length: dlc for (dlc, length) in enumerate(DLC_TO_LEN)} +PANDA_BUS_CNT = 4 def calculate_checksum(data): @@ -234,20 +235,18 @@ class Panda: FLAG_FORD_LONG_CONTROL = 1 FLAG_FORD_CANFD = 2 - def __init__(self, serial: Optional[str] = None, claim: bool = True, disable_checks: bool = True): + def __init__(self, serial: Optional[str] = None, claim: bool = True, disable_checks: bool = True, can_speed_kbps: int = 500): self._connect_serial = serial self._disable_checks = disable_checks self._handle: BaseHandle self._handle_open = False self.can_rx_overflow_buffer = b'' + self._can_speed_kbps = can_speed_kbps # connect and set mcu type self.connect(claim) - # reset comms - self.can_reset_communications() - def __enter__(self): return self @@ -305,6 +304,13 @@ class Panda: self.set_heartbeat_disabled() self.set_power_save(0) + # reset comms + self.can_reset_communications() + + # set CAN speed + for bus in range(PANDA_BUS_CNT): + self.set_can_speed_kbps(bus, self._can_speed_kbps) + @classmethod def spi_connect(cls, serial, ignore_version=False): # get UID to confirm slave is present and up