mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-20 07:53:56 +08:00
openpilot v0.9.7 release
date: 2024-06-11T01:36:39
master commit: f8cb04e4a8
This commit is contained in:
@@ -6,10 +6,8 @@ import usb1
|
||||
import struct
|
||||
import hashlib
|
||||
import binascii
|
||||
import datetime
|
||||
import logging
|
||||
from functools import wraps, partial
|
||||
from typing import Optional
|
||||
from itertools import accumulate
|
||||
|
||||
from .base import BaseHandle
|
||||
@@ -150,9 +148,6 @@ class Panda:
|
||||
SERIAL_LIN2 = 3
|
||||
SERIAL_SOM_DEBUG = 4
|
||||
|
||||
GMLAN_CAN2 = 1
|
||||
GMLAN_CAN3 = 2
|
||||
|
||||
USB_PIDS = (0xddee, 0xddcc)
|
||||
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
|
||||
REQUEST_OUT = usb1.ENDPOINT_OUT | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
|
||||
@@ -170,9 +165,9 @@ class Panda:
|
||||
HW_TYPE_CUATRO = b'\x0a'
|
||||
|
||||
CAN_PACKET_VERSION = 4
|
||||
HEALTH_PACKET_VERSION = 15
|
||||
HEALTH_PACKET_VERSION = 16
|
||||
CAN_HEALTH_PACKET_VERSION = 5
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIIBBBBBHBBBHfBBHBHHB")
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBHBBBHfBBHBHHB")
|
||||
CAN_HEALTH_STRUCT = struct.Struct("<BIBBBBBBBBIIIIIIIHHBBBIIII")
|
||||
|
||||
F4_DEVICES = [HW_TYPE_WHITE_PANDA, HW_TYPE_GREY_PANDA, HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS]
|
||||
@@ -196,13 +191,11 @@ class Panda:
|
||||
FLAG_TOYOTA_ALT_BRAKE = (1 << 8)
|
||||
FLAG_TOYOTA_STOCK_LONGITUDINAL = (2 << 8)
|
||||
FLAG_TOYOTA_LTA = (4 << 8)
|
||||
FLAG_TOYOTA_GAS_INTERCEPTOR = (8 << 8)
|
||||
|
||||
FLAG_HONDA_ALT_BRAKE = 1
|
||||
FLAG_HONDA_BOSCH_LONG = 2
|
||||
FLAG_HONDA_NIDEC_ALT = 4
|
||||
FLAG_HONDA_RADARLESS = 8
|
||||
FLAG_HONDA_GAS_INTERCEPTOR = 16
|
||||
|
||||
FLAG_HYUNDAI_EV_GAS = 1
|
||||
FLAG_HYUNDAI_HYBRID_GAS = 2
|
||||
@@ -215,6 +208,7 @@ class Panda:
|
||||
|
||||
FLAG_TESLA_POWERTRAIN = 1
|
||||
FLAG_TESLA_LONG_CONTROL = 2
|
||||
FLAG_TESLA_RAVEN = 4
|
||||
|
||||
FLAG_VOLKSWAGEN_LONG_CONTROL = 1
|
||||
|
||||
@@ -234,7 +228,7 @@ 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, can_speed_kbps: int = 500):
|
||||
def __init__(self, serial: str | None = None, claim: bool = True, disable_checks: bool = True, can_speed_kbps: int = 500):
|
||||
self._connect_serial = serial
|
||||
self._disable_checks = disable_checks
|
||||
|
||||
@@ -310,6 +304,10 @@ class Panda:
|
||||
for bus in range(PANDA_BUS_CNT):
|
||||
self.set_can_speed_kbps(bus, self._can_speed_kbps)
|
||||
|
||||
@property
|
||||
def spi(self) -> bool:
|
||||
return isinstance(self._handle, PandaSpiHandle)
|
||||
|
||||
@classmethod
|
||||
def spi_connect(cls, serial, ignore_version=False):
|
||||
# get UID to confirm slave is present and up
|
||||
@@ -363,6 +361,7 @@ class Panda:
|
||||
try:
|
||||
this_serial = device.getSerialNumber()
|
||||
except Exception:
|
||||
logging.exception("failed to get serial number of panda")
|
||||
continue
|
||||
|
||||
if serial is None or this_serial == serial:
|
||||
@@ -414,7 +413,7 @@ class Panda:
|
||||
else:
|
||||
logging.warning(f"found device with panda descriptors but invalid serial: {serial}", RuntimeWarning)
|
||||
except Exception:
|
||||
continue
|
||||
logging.exception("error connecting to panda")
|
||||
except Exception:
|
||||
logging.exception("exception while listing pandas")
|
||||
return ret
|
||||
@@ -439,6 +438,8 @@ class Panda:
|
||||
self._handle.controlWrite(Panda.REQUEST_IN, 0xd8, 0, 0, b'', timeout=timeout, expect_disconnect=True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.close()
|
||||
if not enter_bootloader and reconnect:
|
||||
self.reconnect()
|
||||
|
||||
@@ -530,7 +531,7 @@ class Panda:
|
||||
if reconnect:
|
||||
self.reconnect()
|
||||
|
||||
def recover(self, timeout: Optional[int] = 60, reset: bool = True) -> bool:
|
||||
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
|
||||
dfu_serial = self.get_dfu_serial()
|
||||
|
||||
if reset:
|
||||
@@ -549,7 +550,7 @@ class Panda:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def wait_for_dfu(dfu_serial: Optional[str], timeout: Optional[int] = None) -> bool:
|
||||
def wait_for_dfu(dfu_serial: str | None, timeout: int | None = None) -> bool:
|
||||
t_start = time.monotonic()
|
||||
dfu_list = PandaDFU.list()
|
||||
while (dfu_serial is None and len(dfu_list) == 0) or (dfu_serial is not None and dfu_serial not in dfu_list):
|
||||
@@ -561,7 +562,7 @@ class Panda:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def wait_for_panda(serial: Optional[str], timeout: int) -> bool:
|
||||
def wait_for_panda(serial: str | None, timeout: int) -> bool:
|
||||
t_start = time.monotonic()
|
||||
serials = Panda.list()
|
||||
while (serial is None and len(serials) == 0) or (serial is not None and serial not in serials):
|
||||
@@ -596,26 +597,25 @@ class Panda:
|
||||
"safety_rx_invalid": a[4],
|
||||
"tx_buffer_overflow": a[5],
|
||||
"rx_buffer_overflow": a[6],
|
||||
"gmlan_send_errs": a[7],
|
||||
"faults": a[8],
|
||||
"ignition_line": a[9],
|
||||
"ignition_can": a[10],
|
||||
"controls_allowed": a[11],
|
||||
"car_harness_status": a[12],
|
||||
"safety_mode": a[13],
|
||||
"safety_param": a[14],
|
||||
"fault_status": a[15],
|
||||
"power_save_enabled": a[16],
|
||||
"heartbeat_lost": a[17],
|
||||
"alternative_experience": a[18],
|
||||
"interrupt_load": a[19],
|
||||
"fan_power": a[20],
|
||||
"safety_rx_checks_invalid": a[21],
|
||||
"spi_checksum_error_count": a[22],
|
||||
"fan_stall_count": a[23],
|
||||
"sbu1_voltage_mV": a[24],
|
||||
"sbu2_voltage_mV": a[25],
|
||||
"som_reset_triggered": a[26],
|
||||
"faults": a[7],
|
||||
"ignition_line": a[8],
|
||||
"ignition_can": a[9],
|
||||
"controls_allowed": a[10],
|
||||
"car_harness_status": a[11],
|
||||
"safety_mode": a[12],
|
||||
"safety_param": a[13],
|
||||
"fault_status": a[14],
|
||||
"power_save_enabled": a[15],
|
||||
"heartbeat_lost": a[16],
|
||||
"alternative_experience": a[17],
|
||||
"interrupt_load": a[18],
|
||||
"fan_power": a[19],
|
||||
"safety_rx_checks_invalid": a[20],
|
||||
"spi_checksum_error_count": a[21],
|
||||
"fan_stall_count": a[22],
|
||||
"sbu1_voltage_mV": a[23],
|
||||
"sbu2_voltage_mV": a[24],
|
||||
"som_reset_triggered": a[25],
|
||||
}
|
||||
|
||||
@ensure_can_health_packet_version
|
||||
@@ -752,21 +752,10 @@ class Panda:
|
||||
def set_power_save(self, power_save_enabled=0):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xe7, int(power_save_enabled), 0, b'')
|
||||
|
||||
def enable_deepsleep(self):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xfb, 0, 0, b'')
|
||||
|
||||
def set_safety_mode(self, mode=SAFETY_SILENT, param=0):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdc, mode, param, b'')
|
||||
|
||||
def set_gmlan(self, bus=2):
|
||||
# TODO: check panda type
|
||||
if bus is None:
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 0, 0, b'')
|
||||
elif bus in (Panda.GMLAN_CAN2, Panda.GMLAN_CAN3):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 1, bus, b'')
|
||||
|
||||
def set_obd(self, obd):
|
||||
# TODO: check panda type
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, int(obd), 0, b'')
|
||||
|
||||
def set_can_loopback(self, enable):
|
||||
@@ -894,21 +883,6 @@ class Panda:
|
||||
def set_heartbeat_disabled(self):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf8, 0, 0, b'')
|
||||
|
||||
# ******************* RTC *******************
|
||||
def set_datetime(self, dt):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa1, int(dt.year), 0, b'')
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa2, int(dt.month), 0, b'')
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa3, int(dt.day), 0, b'')
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa4, int(dt.isoweekday()), 0, b'')
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa5, int(dt.hour), 0, b'')
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa6, int(dt.minute), 0, b'')
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xa7, int(dt.second), 0, b'')
|
||||
|
||||
def get_datetime(self):
|
||||
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xa0, 0, 0, 8)
|
||||
a = struct.unpack("HBBBBBB", dat)
|
||||
return datetime.datetime(a[0], a[1], a[2], a[4], a[5], a[6])
|
||||
|
||||
# ****************** Timer *****************
|
||||
def get_microsecond_timer(self):
|
||||
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xa8, 0, 0, 4)
|
||||
|
||||
Reference in New Issue
Block a user