Reset baudrate when connecting from Python (#1837)

* Reset baudrate when connecting from Python

* unused
This commit is contained in:
Willem Melching
2024-01-25 22:17:19 +01:00
committed by GitHub
parent d6b5dbb3dc
commit eb9b0df727

View File

@@ -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