mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-21 22:12:05 +08:00
dragonpilot beta3
date: 2023-12-23T21:19:29 commit: 38612b14f1a8aa49d1c6ef61bd67f5a095abb3f9
This commit is contained in:
+21
-78
@@ -168,9 +168,9 @@ class Panda:
|
||||
HW_TYPE_TRES = b'\x09'
|
||||
|
||||
CAN_PACKET_VERSION = 4
|
||||
HEALTH_PACKET_VERSION = 14
|
||||
HEALTH_PACKET_VERSION = 15
|
||||
CAN_HEALTH_PACKET_VERSION = 5
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIIBBBBBBHBBBHfBBHBHH")
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIIBBBBBHBBBHfBBHBHHB")
|
||||
CAN_HEALTH_STRUCT = struct.Struct("<BIBBBBBBBBIIIIIIIHHBBBIIII")
|
||||
|
||||
F2_DEVICES = [HW_TYPE_PEDAL, ]
|
||||
@@ -194,11 +194,13 @@ 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
|
||||
@@ -220,6 +222,8 @@ class Panda:
|
||||
FLAG_SUBARU_GEN2 = 1
|
||||
FLAG_SUBARU_LONG = 2
|
||||
|
||||
FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE = 1
|
||||
|
||||
FLAG_NISSAN_ALT_EPS_BUS = 1
|
||||
|
||||
FLAG_GM_HW_CAM = 1
|
||||
@@ -590,21 +594,21 @@ class Panda:
|
||||
"ignition_line": a[9],
|
||||
"ignition_can": a[10],
|
||||
"controls_allowed": a[11],
|
||||
"gas_interceptor_detected": a[12],
|
||||
"car_harness_status": a[13],
|
||||
"safety_mode": a[14],
|
||||
"safety_param": a[15],
|
||||
"fault_status": a[16],
|
||||
"power_save_enabled": a[17],
|
||||
"heartbeat_lost": a[18],
|
||||
"alternative_experience": a[19],
|
||||
"interrupt_load": a[20],
|
||||
"fan_power": a[21],
|
||||
"safety_rx_checks_invalid": a[22],
|
||||
"spi_checksum_error_count": a[23],
|
||||
"fan_stall_count": a[24],
|
||||
"sbu1_voltage_mV": a[25],
|
||||
"sbu2_voltage_mV": a[26],
|
||||
"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],
|
||||
}
|
||||
|
||||
@ensure_can_health_packet_version
|
||||
@@ -877,63 +881,6 @@ class Panda:
|
||||
"""
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf2, port_number, 0, b'')
|
||||
|
||||
# ******************* kline *******************
|
||||
|
||||
# pulse low for wakeup
|
||||
def kline_wakeup(self, k=True, l=True):
|
||||
assert k or l, "must specify k-line, l-line, or both"
|
||||
logging.debug("kline wakeup...")
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf0, 2 if k and l else int(l), 0, b'')
|
||||
logging.debug("kline wakeup done")
|
||||
|
||||
def kline_5baud(self, addr, k=True, l=True):
|
||||
assert k or l, "must specify k-line, l-line, or both"
|
||||
logging.debug("kline 5 baud...")
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf4, 2 if k and l else int(l), addr, b'')
|
||||
logging.debug("kline 5 baud done")
|
||||
|
||||
def kline_drain(self, bus=2):
|
||||
# drain buffer
|
||||
bret = bytearray()
|
||||
while True:
|
||||
ret = self._handle.controlRead(Panda.REQUEST_IN, 0xe0, bus, 0, 0x40)
|
||||
if len(ret) == 0:
|
||||
break
|
||||
logging.debug(f"kline drain: 0x{ret.hex()}")
|
||||
bret += ret
|
||||
return bytes(bret)
|
||||
|
||||
def kline_ll_recv(self, cnt, bus=2):
|
||||
echo = bytearray()
|
||||
while len(echo) != cnt:
|
||||
ret = self._handle.controlRead(Panda.REQUEST_OUT, 0xe0, bus, 0, cnt - len(echo))
|
||||
if len(ret) > 0:
|
||||
logging.debug(f"kline recv: 0x{ret.hex()}")
|
||||
echo += ret
|
||||
return bytes(echo)
|
||||
|
||||
def kline_send(self, x, bus=2, checksum=True):
|
||||
self.kline_drain(bus=bus)
|
||||
if checksum:
|
||||
x += bytes([sum(x) % 0x100])
|
||||
for i in range(0, len(x), 0xf):
|
||||
ts = x[i:i + 0xf]
|
||||
logging.debug(f"kline send: 0x{ts.hex()}")
|
||||
self._handle.bulkWrite(2, bytes([bus]) + ts)
|
||||
echo = self.kline_ll_recv(len(ts), bus=bus)
|
||||
if echo != ts:
|
||||
logging.error(f"**** ECHO ERROR {i} ****")
|
||||
logging.error(f"0x{echo.hex()}")
|
||||
logging.error(f"0x{ts.hex()}")
|
||||
assert echo == ts
|
||||
|
||||
def kline_recv(self, bus=2, header_len=4):
|
||||
# read header (last byte is length)
|
||||
msg = self.kline_ll_recv(header_len, bus=bus)
|
||||
# read data (add one byte to length for checksum)
|
||||
msg += self.kline_ll_recv(msg[-1]+1, bus=bus)
|
||||
return msg
|
||||
|
||||
def send_heartbeat(self, engaged=True):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf3, engaged, 0, b'')
|
||||
|
||||
@@ -975,10 +922,6 @@ class Panda:
|
||||
a = struct.unpack("H", dat)
|
||||
return a[0]
|
||||
|
||||
# ****************** Phone *****************
|
||||
def set_phone_power(self, enabled):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xb3, int(enabled), 0, b'')
|
||||
|
||||
# ****************** Siren *****************
|
||||
def set_siren(self, enabled):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf6, int(enabled), 0, b'')
|
||||
|
||||
Reference in New Issue
Block a user