|
28 | 28 | CANPACKET_HEAD_SIZE = 0x6
|
29 | 29 | DLC_TO_LEN = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64]
|
30 | 30 | LEN_TO_DLC = {length: dlc for (dlc, length) in enumerate(DLC_TO_LEN)}
|
| 31 | +PANDA_BUS_CNT = 4 |
31 | 32 |
|
32 | 33 |
|
33 | 34 | def calculate_checksum(data):
|
@@ -234,20 +235,18 @@ class Panda:
|
234 | 235 | FLAG_FORD_LONG_CONTROL = 1
|
235 | 236 | FLAG_FORD_CANFD = 2
|
236 | 237 |
|
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): |
238 | 239 | self._connect_serial = serial
|
239 | 240 | self._disable_checks = disable_checks
|
240 | 241 |
|
241 | 242 | self._handle: BaseHandle
|
242 | 243 | self._handle_open = False
|
243 | 244 | self.can_rx_overflow_buffer = b''
|
| 245 | + self._can_speed_kbps = can_speed_kbps |
244 | 246 |
|
245 | 247 | # connect and set mcu type
|
246 | 248 | self.connect(claim)
|
247 | 249 |
|
248 |
| - # reset comms |
249 |
| - self.can_reset_communications() |
250 |
| - |
251 | 250 | def __enter__(self):
|
252 | 251 | return self
|
253 | 252 |
|
@@ -305,6 +304,13 @@ def connect(self, claim=True, wait=False):
|
305 | 304 | self.set_heartbeat_disabled()
|
306 | 305 | self.set_power_save(0)
|
307 | 306 |
|
| 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 | + |
308 | 314 | @classmethod
|
309 | 315 | def spi_connect(cls, serial, ignore_version=False):
|
310 | 316 | # get UID to confirm slave is present and up
|
|
0 commit comments