Skip to content

Commit eb9b0df

Browse files
authoredJan 25, 2024
Reset baudrate when connecting from Python (commaai#1837)
* Reset baudrate when connecting from Python * unused
1 parent d6b5dbb commit eb9b0df

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎python/__init__.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CANPACKET_HEAD_SIZE = 0x6
2929
DLC_TO_LEN = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64]
3030
LEN_TO_DLC = {length: dlc for (dlc, length) in enumerate(DLC_TO_LEN)}
31+
PANDA_BUS_CNT = 4
3132

3233

3334
def calculate_checksum(data):
@@ -234,20 +235,18 @@ class Panda:
234235
FLAG_FORD_LONG_CONTROL = 1
235236
FLAG_FORD_CANFD = 2
236237

237-
def __init__(self, serial: Optional[str] = None, claim: bool = True, disable_checks: bool = True):
238+
def __init__(self, serial: Optional[str] = None, claim: bool = True, disable_checks: bool = True, can_speed_kbps: int = 500):
238239
self._connect_serial = serial
239240
self._disable_checks = disable_checks
240241

241242
self._handle: BaseHandle
242243
self._handle_open = False
243244
self.can_rx_overflow_buffer = b''
245+
self._can_speed_kbps = can_speed_kbps
244246

245247
# connect and set mcu type
246248
self.connect(claim)
247249

248-
# reset comms
249-
self.can_reset_communications()
250-
251250
def __enter__(self):
252251
return self
253252

@@ -305,6 +304,13 @@ def connect(self, claim=True, wait=False):
305304
self.set_heartbeat_disabled()
306305
self.set_power_save(0)
307306

307+
# reset comms
308+
self.can_reset_communications()
309+
310+
# set CAN speed
311+
for bus in range(PANDA_BUS_CNT):
312+
self.set_can_speed_kbps(bus, self._can_speed_kbps)
313+
308314
@classmethod
309315
def spi_connect(cls, serial, ignore_version=False):
310316
# get UID to confirm slave is present and up

0 commit comments

Comments
 (0)
Please sign in to comment.