diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index 2ef189efce..3e38de4273 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -387,6 +387,9 @@ class CarController(CarControllerBase): if self.CP.carFingerprint == CAR.KIA_RAY_EV: self._ray_lkas11_active = True + if self.CP.carFingerprint == CAR.HYUNDAI_I30_2026: + return can_sends if CC.enabled and CC.latActive and CS.out.cruiseState.enabled else [] + # Button messages if not self.CP.openpilotLongitudinalControl or self._ray_pedal: if self._ray_pedal and CC.enabled and CS.out.cruiseState.enabled: diff --git a/opendbc_repo/opendbc/car/hyundai/hyundaican.py b/opendbc_repo/opendbc/car/hyundai/hyundaican.py index ed5087f764..d358a8213a 100644 --- a/opendbc_repo/opendbc/car/hyundai/hyundaican.py +++ b/opendbc_repo/opendbc/car/hyundai/hyundaican.py @@ -37,6 +37,16 @@ def create_lkas11(packer, frame, CP, apply_torque, steer_req, torque_fault, lkas11, sys_warning, sys_state, enabled, left_lane, right_lane, left_lane_depart, right_lane_depart, ray_lka_icon=None, aol_lka_icon=None): + if CP.carFingerprint == CAR.HYUNDAI_I30_2026: + values = dict(lkas11) + values["CR_Lkas_StrToqReq"] = apply_torque + values["CF_Lkas_ActToi"] = steer_req + values["CF_Lkas_ToiFlt"] = torque_fault or lkas11["CF_Lkas_ToiFlt"] + values["CF_Lkas_MsgCount"] = frame % 16 + data = packer.make_can_msg("LKAS11", 0, values)[1] + values["CF_Lkas_Chksum"] = hyundai_checksum(data[:6] + data[7:]) + return packer.make_can_msg("LKAS11", 0, values) + values = {s: lkas11[s] for s in [ "CF_Lkas_LdwsActivemode", "CF_Lkas_LdwsSysState", diff --git a/opendbc_repo/opendbc/car/hyundai/interface.py b/opendbc_repo/opendbc/car/hyundai/interface.py index d083166a0d..bf8fbe84cb 100644 --- a/opendbc_repo/opendbc/car/hyundai/interface.py +++ b/opendbc_repo/opendbc/car/hyundai/interface.py @@ -4,6 +4,7 @@ from opendbc.car.pedal import supported_pedal_detected from opendbc.car.hyundai.classic_scc_aol import CLASSIC_SCC_IDS from opendbc.car import Bus, get_safety_config, structs, uds from opendbc.car.hyundai.discovery import kona_electric_se_candidate +from opendbc.car.hyundai.fingerprints import FW_VERSIONS from opendbc.car.hyundai.hyundaicanfd import CanBus from opendbc.car.hyundai.non_scc_aol import NON_SCC_IDS from opendbc.car.hyundai.values import (is_blended, is_blended_alpha, HyundaiFlags, CAR, DBC, HyundaiSafetyFlags, CANFD_ANGLE_MODEL_BITS, @@ -140,7 +141,18 @@ class CarInterface(CarInterfaceBase): def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams: ret.brand = "hyundai" - if candidate == CAR.HYUNDAI_I30_2026: + i30 = candidate == CAR.HYUNDAI_I30_2026 + if i30: + expected = FW_VERSIONS[candidate] + exact = {(fw.ecu.raw, fw.address, None): bytes(fw.fwVersion) for fw in car_fw + if fw.subAddress == 0 and bytes(fw.fwVersion).startswith(b"\xf1\x00")} + qualified = (not is_release and all(exact.get(key) in versions for key, versions in expected.items()) and + fingerprint[0].get(0x421) == 8 and fingerprint[2].get(0x340) == 8 and + fingerprint[2].get(0x485) == 8) + if qualified: + ret.flags |= HyundaiFlags.CHECKSUM_CRC8.value + + if i30 and not qualified: # Controls may construct a PID for this profile. Keep it inert with valid gains. ret.lateralTuning.pid.kpBP = ret.lateralTuning.pid.kiBP = [0.0] ret.lateralTuning.pid.kpV = ret.lateralTuning.pid.kiV = [0.0] @@ -336,7 +348,7 @@ class CarInterface(CarInterfaceBase): from opendbc.car.hyundai.legacy_long_aol import CARS as legacy_long_cars if candidate == CAR.KIA_CARNIVAL_2025 and any(fw.ecu == Ecu.fwdCamera and fw.fwVersion == CARNIVAL_2027_CAMERA_FW for fw in car_fw): ret.alphaLongitudinalAvailable = False - ret.openpilotLongitudinalControl = alpha_long and ret.alphaLongitudinalAvailable and candidate not in legacy_long_cars + ret.openpilotLongitudinalControl = not i30 and alpha_long and ret.alphaLongitudinalAvailable and candidate not in legacy_long_cars if (candidate in (CAR.KIA_CARNIVAL_2025, CAR.KIA_CARNIVAL_HEV_4TH_GEN) and ret.flags & HyundaiFlags.CANFD_ALT_BUTTONS and 0x1aa in fingerprint[CAN.ECAN] and not ret.openpilotLongitudinalControl): @@ -423,6 +435,16 @@ class CarInterface(CarInterfaceBase): from opendbc.car.hyundai.gv60_startup import select_profile as gv60_select_profile gv60_select_profile(ret, is_release=is_release) + if i30: + ret.alphaLongitudinalAvailable = False + ret.openpilotLongitudinalControl = False + ret.pcmCruise = True + ret.radarUnavailable = True + ret.autoResumeSng = False + ret.flags &= ~HyundaiFlags.SEND_LFA.value + ret.minSteerSpeed = 5.0 + ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.hyundai, 0x6200)] + return ret def update(self, can_packets): diff --git a/opendbc_repo/opendbc/car/hyundai/values.py b/opendbc_repo/opendbc/car/hyundai/values.py index cdb2c9c434..c23aa352a8 100644 --- a/opendbc_repo/opendbc/car/hyundai/values.py +++ b/opendbc_repo/opendbc/car/hyundai/values.py @@ -53,6 +53,11 @@ class CarControllerParams: self.STEER_DELTA_UP = 2 self.STEER_DELTA_DOWN = 3 + elif CP.carFingerprint == CAR.HYUNDAI_I30_2026: + self.STEER_MAX = 90 + self.STEER_DELTA_UP = 2 + self.STEER_DELTA_DOWN = 3 + elif CP.flags & HyundaiFlags.ALT_LIMITS_2: self.STEER_MAX = 170 self.STEER_DELTA_UP = 2 diff --git a/opendbc_repo/opendbc/car/toyota/carcontroller.py b/opendbc_repo/opendbc/car/toyota/carcontroller.py index e28173c971..196d5a3768 100644 --- a/opendbc_repo/opendbc/car/toyota/carcontroller.py +++ b/opendbc_repo/opendbc/car/toyota/carcontroller.py @@ -1,6 +1,7 @@ import math import numpy as np from opendbc.car import ACCEL_MAX_TAKEOFF +from opendbc.car.toyota import enhanced_bsm from opendbc.car import Bus, make_tester_present_msg, rate_limit, structs, ACCELERATION_DUE_TO_GRAVITY, DT_CTRL from opendbc.car.lateral import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance from opendbc.car.carlog import carlog @@ -117,6 +118,7 @@ class CarController(CarControllerBase): self.secoc_lta_message_counter = 0 self.secoc_acc_message_counter = 0 self.secoc_prev_reset_counter = 0 + self.bsm_poller = enhanced_bsm.BsmPoller() if enhanced_bsm.configured(CP) else None self.brake_hold_active = False self._brake_hold_counter = 0 @@ -529,6 +531,9 @@ class CarController(CarControllerBase): if self.frame % 20 == 0 and self.CP.flags & ToyotaFlags.DISABLE_RADAR.value: can_sends.append(make_tester_present_msg(0x750, 0, 0xF)) + if self.bsm_poller is not None: + can_sends.extend(self.bsm_poller.update(CS.out, self.frame, factory_bsm=CS.factory_bsm)) + door_command = self.door_locks.update(CS.out) if door_command is not None: from opendbc.car import CanData diff --git a/opendbc_repo/opendbc/car/toyota/carstate.py b/opendbc_repo/opendbc/car/toyota/carstate.py index f0f09764d3..9b18a7a0bf 100644 --- a/opendbc_repo/opendbc/car/toyota/carstate.py +++ b/opendbc_repo/opendbc/car/toyota/carstate.py @@ -6,6 +6,7 @@ from opendbc.car.toyota import ( stock_aol, prius_longitudinal, dsu_bypass, pedal_composite, pedal, legacy_sdsu, advert_filter, legacy_advert_filter, prius_sdsu, prius_advert_filter ) from opendbc.car.toyota.lexus_is import LexusIsCANParser +from opendbc.car.toyota import enhanced_bsm from opendbc.car import Bus, DT_CTRL, create_button_events, structs from opendbc.car.common.conversions import Conversions as CV from opendbc.car.common.filter_simple import FirstOrderFilter @@ -39,6 +40,7 @@ def has_optional_prius_gap_button(CP): class CarState(CarStateBase): def __init__(self, CP): super().__init__(CP) + self.factory_bsm = False can_define = CANDefine(DBC[CP.carFingerprint][Bus.pt]) original_prius = prius_sdsu.configured(CP) or prius_advert_filter.configured(CP) self.eps_torque_scale = ((CP.safetyConfigs[0].safetyParam & 0xFF) / 100. if prius_advert_filter.configured(CP) else @@ -229,9 +231,13 @@ class CarState(CarStateBase): ret.genericToggle = bool(cp.vl["LIGHT_STALK"]["AUTO_HIGH_BEAM"]) ret.espDisabled = cp.vl["ESP_CONTROL"]["TC_DISABLED"] != 0 - if self.CP.flags & ToyotaFlags.HAS_BSM: + self.factory_bsm = isinstance(cp, enhanced_bsm.BsmCANParser) and cp.factory_bsm + if self.CP.flags & ToyotaFlags.HAS_BSM or self.factory_bsm: ret.leftBlindspot = (cp.vl["BSM"]["L_ADJACENT"] == 1) or (cp.vl["BSM"]["L_APPROACHING"] == 1) ret.rightBlindspot = (cp.vl["BSM"]["R_ADJACENT"] == 1) or (cp.vl["BSM"]["R_APPROACHING"] == 1) + elif isinstance(cp, enhanced_bsm.BsmCANParser) and ret.vEgo > 6.0: + ret.leftBlindspot = cp.occupied(enhanced_bsm.SIDES[0]) + ret.rightBlindspot = cp.occupied(enhanced_bsm.SIDES[1]) if self.CP.carFingerprint != CAR.TOYOTA_PRIUS_V: self.lkas_hud = copy.copy(cp_cam.vl["LKAS_HUD"]) @@ -404,6 +410,9 @@ class CarState(CarStateBase): LexusIsCANParser if CP.carFingerprint == CAR.LEXUS_IS else pedal.PedalCANParser if pedal.configured(CP) else advert_filter.AdvertFilterCANParser if CP.flags & ToyotaFlags.FILTER_BUTTONS or advert_filter.configured(CP) else Rav4hCANParser if rav4h_filter_configured(CP) else CANParser) + if enhanced_bsm.configured(CP): + pt_parser = enhanced_bsm.BsmCANParser + pt_messages.append(("BSM", math.nan)) return { Bus.pt: pt_parser(DBC[CP.carFingerprint][Bus.pt], pt_messages, 0, **({"stock_word": CP.safetyConfigs[0].safetyParam} if stock else {"alternate_main": alternate_sdsu_main} if legacy_advert else {})), diff --git a/opendbc_repo/opendbc/car/toyota/enhanced_bsm.py b/opendbc_repo/opendbc/car/toyota/enhanced_bsm.py new file mode 100644 index 0000000000..71926073bf --- /dev/null +++ b/opendbc_repo/opendbc/car/toyota/enhanced_bsm.py @@ -0,0 +1,90 @@ +"""Toyota blind-spot diagnostic fallback, adapted from sunnypilot/opendbc #502. + +Copyright (c) 2021-, sunnypilot, and a number of other contributors. +Licensed under the MIT License. See the repository license for the terms. +""" + +from opendbc.can import CANParser +from opendbc.car import CanData, structs +from opendbc.car.toyota.values import CAR, ToyotaFlags +from opendbc.safety import ALTERNATIVE_EXPERIENCE + + +SIDES = (0x41, 0x42) +REPLY_MAX_AGE_NS = 500_000_000 + + +def supported(cp): + required = ToyotaFlags.TSS2 | ToyotaFlags.NO_DSU | ToyotaFlags.RAISED_ACCEL_LIMIT | ToyotaFlags.HYBRID + allowed = required | ToyotaFlags.AUTO_BRAKE_HOLD + return (cp.carFingerprint == CAR.TOYOTA_PRIUS_TSS2 and cp.brand == 'toyota' and + cp.pcmCruise and cp.openpilotLongitudinalControl and not (cp.passive or cp.dashcamOnly or cp.notCar or cp.secOcRequired) and + cp.steerControlType == structs.CarParams.SteerControlType.torque and cp.flags & required == required and + not cp.flags & ~int(allowed) and len(cp.safetyConfigs) == 1 and + cp.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.toyota and cp.safetyConfigs[0].safetyParam == 73) + + +def configured(cp): + return supported(cp) and bool(cp.alternativeExperience & ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM) + + +def prepare(cp, requested): + permission = ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM + cp.alternativeExperience &= ~permission + if requested and supported(cp): + cp.alternativeExperience |= permission + + +class BsmCANParser(CANParser): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.blindspots = {} + self.factory_bsm = False + self.bsm_stamp = 0 + self.fresh_batch = False + + def update(self, strings, sendcan=False): + if strings and not isinstance(strings[0], list | tuple): + strings = [strings] + self.fresh_batch = False + for timestamp, frames in strings: + self.fresh_batch = True + if timestamp < self.bsm_stamp: + self.blindspots.clear() + self.bsm_stamp = timestamp + for address, data, bus in frames: + if bus == self.bus and address == 0x3F6 and len(data) == 8: + self.factory_bsm = True + self.blindspots.clear() + if (not self.factory_bsm and bus == self.bus and address == 0x758 and len(data) == 8 and + data[0] in SIDES and data[1:4] == b'\x06\x61\x69'): + self.blindspots[data[0]] = (timestamp, max(data[5:7]) > 35) + return super().update(strings, sendcan) + + def occupied(self, side): + timestamp, present = self.blindspots.get(side, (0, False)) + return self.fresh_batch and present and 0 < timestamp <= self.bsm_stamp <= timestamp + REPLY_MAX_AGE_NS + + +class BsmPoller: + def __init__(self): + self.active = False + self.started = 0 + + def update(self, state, frame, *, factory_bsm=False): + ready = (not factory_bsm and frame > 200 and state.canValid and not state.canTimeout and + state.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.sport) and + state.vEgo > (6.0 if self.active else 7.0)) + if ready != self.active: + self.active = ready + self.started = frame + session = 0x60 if ready else 0x01 + return [CanData(0x750, bytes((side, 2, 0x10, session, 0, 0, 0, 0)), 0) for side in SIDES] + # Retry twice if Panda had not yet admitted the initial session request. + # Panda ignores the repeated entry command on a side with an open session. + if ready and frame - self.started in (100, 200): + return [CanData(0x750, bytes((side, 2, 0x10, 0x60, 0, 0, 0, 0)), 0) for side in SIDES] + if ready and frame % 10 == 5: + side = SIDES[(frame // 10) % 2] + return [CanData(0x750, bytes((side, 2, 0x21, 0x69, 0, 0, 0, 0)), 0)] + return [] diff --git a/opendbc_repo/opendbc/car/toyota/tests/test_enhanced_bsm.py b/opendbc_repo/opendbc/car/toyota/tests/test_enhanced_bsm.py new file mode 100644 index 0000000000..956cd00ab4 --- /dev/null +++ b/opendbc_repo/opendbc/car/toyota/tests/test_enhanced_bsm.py @@ -0,0 +1,140 @@ +import pytest + +from opendbc.car import Bus, gen_empty_fingerprint, structs +from opendbc.car.toyota import enhanced_bsm +from opendbc.car.toyota.interface import CarInterface +from opendbc.car.toyota.values import CAR, DBC +from opendbc.safety import ALTERNATIVE_EXPERIENCE as AE +from opendbc.can import CANPacker +from opendbc.safety.tests.libsafety import libsafety_py + + +def params(car=CAR.TOYOTA_PRIUS_TSS2, *, factory=False, requested=True): + fingerprint = gen_empty_fingerprint() + if factory: + fingerprint[0][0x3F6] = 8 + fw = [structs.CarParams.CarFw(ecu=structs.CarParams.Ecu.hybrid)] + cp = CarInterface.get_params(car, fingerprint, fw, False, False, False) + enhanced_bsm.prepare(cp, requested) + return cp + + +@pytest.mark.parametrize('car,factory,requested,configured', ( + (CAR.TOYOTA_PRIUS_TSS2, False, True, True), + (CAR.TOYOTA_PRIUS_TSS2, True, True, False), + (CAR.TOYOTA_PRIUS_TSS2, False, False, False), + (CAR.TOYOTA_COROLLA_TSS2, False, True, False), +)) +def test_fallback_admission(car, factory, requested, configured): + cp = params(car, factory=factory, requested=requested) + ci = CarInterface(cp) + assert isinstance(ci.can_parsers[Bus.pt], enhanced_bsm.BsmCANParser) == configured + if factory: + packer = CANPacker(DBC[car][Bus.pt]) + bsm = packer.make_can_msg('BSM', 0, {'L_APPROACHING': 1}) + ci.update([(990_000_000, [])]) # The factory parser registers BSM on first access. + assert ci.update([(1_000_000_000, [bsm])]).leftBlindspot + assert (ci.CC.bsm_poller is not None) == configured + + +def test_fresh_bsm_replies_are_independent_and_use_recorded_idle_format(): + cp = params() + parser = CarInterface(cp).can_parsers[Bus.pt] + left = (0x758, bytes.fromhex('4106616900320089'), 0) + right = (0x758, bytes.fromhex('4206616900000089'), 0) + parser.update([(1_000_000_000, [left, right])]) + assert parser.occupied(0x41) + assert not parser.occupied(0x42) + parser.update([(1_300_000_000, [(0x758, bytes.fromhex('4206616900310089'), 0)])]) + parser.update([(1_500_000_001, [(*left[:2], 2), (*left[:2], 128), (0x758, b'\x41\x06\x50\x69\x00\x39\x39\x89', 0)])]) + assert not parser.occupied(0x41) + assert parser.occupied(0x42) + parser.update([(1_450_000_000, [])]) + assert not parser.occupied(0x42) + + +def test_late_factory_broadcast_takes_priority(): + cp = params() + ci = CarInterface(cp) + packer = CANPacker(DBC[CAR.TOYOTA_PRIUS_TSS2][Bus.pt]) + factory = packer.make_can_msg('BSM', 0, {'L_APPROACHING': 1}) + right = (0x758, bytes.fromhex('4206616900390089'), 0) + state = ci.update([(1_000_000_000, [factory, right])]) + assert state.leftBlindspot and not state.rightBlindspot + assert ci.CS.factory_bsm + + +def test_poll_cadence_and_cleanup(): + poller = enhanced_bsm.BsmPoller() + cs = structs.CarState(vEgo=9, canValid=True, gearShifter=structs.CarState.GearShifter.drive) + assert not poller.update(cs, 200) + assert [m.dat[:4] for m in poller.update(cs, 201)] == [b'A\x02\x10\x60', b'B\x02\x10\x60'] + assert [m.dat[:4] for m in poller.update(cs, 205)] == [b'A\x02\x21\x69'] + assert [m.dat[:4] for m in poller.update(cs, 215)] == [b'B\x02\x21\x69'] + cs.canTimeout = True + assert [m.dat[:4] for m in poller.update(cs, 216)] == [b'A\x02\x10\x01', b'B\x02\x10\x01'] + assert not poller.update(cs, 217) + + +@pytest.mark.parametrize('release', (False, True)) +def test_native_diagnostics_are_scoped_and_require_a_paced_moving_session(tmp_path, release): + path = libsafety_py._build_libsafety(release=release, output_dir=tmp_path) + safety = libsafety_py.ffi.dlopen(path) + packer = CANPacker('toyota_nodsu_pt_generated') + + def rx(name, values): + a, data, b = packer.make_can_msg(name, 0, values) + assert safety.safety_rx_hook(libsafety_py.make_CANPacket(a, b, data)) + + def wheel(speed): + rx('WHEEL_SPEEDS', {f'WHEEL_SPEED_{wheel}': speed * 3.6 for wheel in ('FL', 'FR', 'RL', 'RR')}) + + def start(word, permission, speed=8.): + safety.init_tests() + safety.set_alternative_experience(permission) + assert safety.set_safety_hooks(2, word) == 0 + safety.set_timer(1_000_000) + wheel(speed) + rx('STEER_TORQUE_SENSOR', {}) + rx('BRAKE_MODULE', {}) + rx('PCM_CRUISE', {'GAS_RELEASED': True}) + + def tx(data, bus=0): + return safety.safety_tx_hook(libsafety_py.make_CANPacket(0x750, bus, data)) + + enable = bytes.fromhex('4102106000000000') + poll = bytes.fromhex('4102216900000000') + end = bytes.fromhex('4102100100000000') + radar = bytes.fromhex('0f023e0000000000') + for word, feature in ((73, 0), (585, AE.TOYOTA_ENHANCED_BSM), (0x1049, AE.TOYOTA_ENHANCED_BSM)): + start(word, feature) + assert not tx(enable) + assert not tx(poll) + assert not tx(end) + start(73, AE.TOYOTA_ENHANCED_BSM, 0.) + assert not tx(enable) + wheel(8.) + assert not tx(poll) + assert not tx(enable, 2) + assert not tx(enable[:-1]) + assert not tx(enable[:-1] + b'\x01') + assert tx(radar) + assert tx(enable) + assert not tx(enable) + assert not tx(poll) + safety.set_timer(1_040_000) + assert tx(poll) + assert not tx(poll) + safety.set_timer(1_101_000) + assert not tx(poll) + wheel(0.) + assert not tx(poll) + assert tx(end) + assert not tx(end) + wheel(8.) + assert tx(enable) + rx('BSM', {}) + assert not tx(poll) + assert tx(end) + assert not tx(enable) + assert not safety.get_controls_allowed() diff --git a/opendbc_repo/opendbc/safety/__init__.py b/opendbc_repo/opendbc/safety/__init__.py index d30b244551..73fd5e0e38 100644 --- a/opendbc_repo/opendbc/safety/__init__.py +++ b/opendbc_repo/opendbc/safety/__init__.py @@ -11,3 +11,4 @@ class ALTERNATIVE_EXPERIENCE: GM_REMAP_CANCEL_TO_DISTANCE = 64 TOYOTA_AUTO_HOLD = 128 TOYOTA_AEB_HOLD = 256 + TOYOTA_ENHANCED_BSM = 512 diff --git a/opendbc_repo/opendbc/safety/declarations.h b/opendbc_repo/opendbc/safety/declarations.h index c5ed6b0af4..a966fb33e6 100644 --- a/opendbc_repo/opendbc/safety/declarations.h +++ b/opendbc_repo/opendbc/safety/declarations.h @@ -358,6 +358,7 @@ extern CurvatureSteeringState curvature_state; #define ALT_EXP_ALLOW_AEB 16 #define ALT_EXP_TOYOTA_AUTO_HOLD 128 #define ALT_EXP_TOYOTA_AEB_HOLD 256 +#define ALT_EXP_TOYOTA_ENHANCED_BSM 512 extern int alternative_experience; diff --git a/opendbc_repo/opendbc/safety/modes/hyundai.h b/opendbc_repo/opendbc/safety/modes/hyundai.h index f2253aec21..4d66d66059 100644 --- a/opendbc_repo/opendbc/safety/modes/hyundai.h +++ b/opendbc_repo/opendbc/safety/modes/hyundai.h @@ -386,6 +386,70 @@ static void hyundai_rx_hook(const CANPacket_t *msg) { } } +static bool hyundai_i30_2026 = false; +static bool hyundai_i30_topology_conflict = false; +static bool hyundai_i30_camera_idle = false; +static bool hyundai_i30_host_steering = false; +static bool hyundai_i30_camera_seen = false; +static uint8_t hyundai_i30_camera_counter = 0U; +static uint32_t hyundai_i30_camera_ts = 0U; +static uint32_t hyundai_i30_host_ts = 0U; + +static bool hyundai_i30_lkas_checksum_valid(const CANPacket_t *msg) { + uint8_t crc = 0xFDU ^ 0xDFU; + for (unsigned int i = 0U; i < 6U; i++) { + crc = crc8_update(crc, msg->data[i], 0x1DU); + } + crc = crc8_update(crc, msg->data[7], 0x1DU); + return (GET_LEN(msg) == 8U) && ((crc ^ 0xDFU) == msg->data[6]); +} + +static bool hyundai_i30_camera_is_idle(const CANPacket_t *msg) { + return hyundai_i30_lkas_checksum_valid(msg) && ((msg->data[3] & 0x1FU) == 4U) && (msg->data[2] == 0U); +} + +static bool hyundai_i30_can_steer(uint32_t now) { + return !hyundai_i30_topology_conflict && hyundai_i30_camera_idle && + (safety_get_ts_elapsed(now, hyundai_i30_camera_ts) <= 30000U) && + controls_allowed && cruise_engaged_prev && vehicle_moving && !brake_pressed && + !relay_malfunction && !safety_rx_checks_invalid && aol_rx_healthy(); +} + +static bool hyundai_i30_fwd_packet(const CANPacket_t *msg) { + bool blocked; + if (hyundai_i30_2026 && (msg->bus == 2U) && (msg->addr == 0x340U)) { + const uint32_t now = microsecond_timer_get(); + blocked = hyundai_i30_camera_is_idle(msg) && hyundai_i30_host_steering && + (safety_get_ts_elapsed(now, hyundai_i30_host_ts) <= 30000U) && + hyundai_i30_can_steer(now); + } else { + blocked = hyundai_daw_fwd(msg); + } + return blocked; +} + +static bool hyundai_i30_steer_tx(const CANPacket_t *msg, int desired_torque, bool steer_req) { + bool tx = false; + const uint32_t now = microsecond_timer_get(); + const TorqueSteeringLimits i30_limits = HYUNDAI_LIMITS(90, 2, 3); + if (!hyundai_i30_can_steer(now) || !hyundai_i30_lkas_checksum_valid(msg)) { + desired_torque_last = 0; + rt_torque_last = 0; + valid_steer_req_count = 0; + invalid_steer_req_count = 0; + ts_torque_check_last = now; + ts_steer_req_mismatch_last = now; + hyundai_i30_host_steering = false; + } else { + tx = !steer_torque_cmd_checks(desired_torque, steer_req, i30_limits); + if (tx) { + hyundai_i30_host_steering = true; + hyundai_i30_host_ts = now; + } + } + return tx; +} + static bool hyundai_tx_hook(const CANPacket_t *msg) { static int hyundai_blended_mirror_torque = 0; static bool hyundai_blended_mirror_request = false; @@ -527,6 +591,8 @@ static bool hyundai_tx_hook(const CANPacket_t *msg) { hyundai_blended_mirror_pending = false; } + const bool i30_lkas = (msg->addr == 0x340U) && !hyundai_blended_hda2 && hyundai_i30_2026; + // LKA STEER: safety check if ((msg->addr == 0x340U) && !hyundai_blended_hda2) { int desired_torque = ((GET_BYTES_LE(msg, 0, 4) >> 16) & 0x7ffU) - 1024U; @@ -536,10 +602,14 @@ static bool hyundai_tx_hook(const CANPacket_t *msg) { hyundai_alt_limits_2 ? HYUNDAI_STEERING_LIMITS_ALT_2 : hyundai_alt_limits ? HYUNDAI_STEERING_LIMITS_ALT : HYUNDAI_STEERING_LIMITS; - if (steer_torque_cmd_checks(desired_torque, steer_req, limits) || - (hyundai_kona_ev_label_cruise && ((desired_torque != 0) || steer_req) && - (!hyundai_kona_ev_label_fresh() || !aol_rx_healthy()))) { - tx = false; + if (i30_lkas) { + tx = hyundai_i30_steer_tx(msg, desired_torque, steer_req); + } else { + if (steer_torque_cmd_checks(desired_torque, steer_req, limits) || + (hyundai_kona_ev_label_cruise && ((desired_torque != 0) || steer_req) && + (!hyundai_kona_ev_label_fresh() || !aol_rx_healthy()))) { + tx = false; + } } } @@ -585,15 +655,17 @@ static bool hyundai_tx_hook(const CANPacket_t *msg) { } } - tx &= blended_aol_integrity(msg); - if (hyundai_blended_alpha && hyundai_blended_hda2 && (msg->addr == 0x50U)) { - hyundai_blended_mirror_pending = tx && !relay_malfunction && !safety_rx_checks_invalid; - const uint32_t mirror_torque_raw = (((uint32_t)msg->data[6] & 0xFU) << 7U) | ((uint32_t)msg->data[5] >> 1U); - hyundai_blended_mirror_torque = (int)mirror_torque_raw - 1024; - hyundai_blended_mirror_request = GET_BIT(msg, 52U); - hyundai_blended_mirror_ts = microsecond_timer_get(); + if (!i30_lkas) { + tx &= blended_aol_integrity(msg); + if (hyundai_blended_alpha && hyundai_blended_hda2 && (msg->addr == 0x50U)) { + hyundai_blended_mirror_pending = tx && !relay_malfunction && !safety_rx_checks_invalid; + const uint32_t mirror_torque_raw = (((uint32_t)msg->data[6] & 0xFU) << 7U) | ((uint32_t)msg->data[5] >> 1U); + hyundai_blended_mirror_torque = (int)mirror_torque_raw - 1024; + hyundai_blended_mirror_request = GET_BIT(msg, 52U); + hyundai_blended_mirror_ts = microsecond_timer_get(); + } + blended_aol_tx(msg, tx); } - blended_aol_tx(msg, tx); return tx; } @@ -655,6 +727,15 @@ static const CanMsg HYUNDAI_LONG_TX_MSGS[] = { #endif static safety_config hyundai_init(uint16_t safety_param) { + static const uint16_t HYUNDAI_I30_2026_STOCK = 0x6200U; + hyundai_i30_2026 = safety_param == HYUNDAI_I30_2026_STOCK; + hyundai_i30_topology_conflict = false; + hyundai_i30_camera_idle = false; + hyundai_i30_host_steering = false; + hyundai_i30_camera_seen = false; + hyundai_i30_camera_counter = 0U; + hyundai_i30_camera_ts = 0U; + hyundai_i30_host_ts = 0U; hyundai_non_scc_software_cruise = hyundai_non_scc_software_cruise_param(safety_param) && ((alternative_experience == 0) || (alternative_experience == 32)); const uint16_t param = hyundai_non_scc_software_cruise ? (safety_param & ~0x0020U) : safety_param; @@ -968,10 +1049,19 @@ static safety_config hyundai_init(uint16_t safety_param) { const safety_config denied = {0}; ret = denied; } - return hyundai_daw_configure(ret, false, !hyundai_blended_stock && !hyundai_blended_alpha); + if (hyundai_i30_2026) { + static const CanMsg i30_tx[] = { + {0x340, 0, 8, .check_relay = true, .disable_static_blocking = true, .check_relay_immediately = true}, + }; + SET_TX_MSGS(i30_tx, ret); + } else { + ret = hyundai_daw_configure(ret, false, !hyundai_blended_stock && !hyundai_blended_alpha); + } + return ret; } static safety_config hyundai_legacy_init(uint16_t param) { + hyundai_i30_2026 = false; hyundai_non_scc_software_cruise = false; // older hyundai models have less checks due to missing counters and checksums static const RxCheck hyundai_legacy_rx_checks[] = { @@ -1024,6 +1114,25 @@ static safety_config hyundai_legacy_init(uint16_t param) { } static void hyundai_optional_rx_hook(const CANPacket_t *msg) { + if (hyundai_i30_2026 && (msg->bus == 2U)) { + if (msg->addr == 0x421U) { + hyundai_i30_topology_conflict = true; + } else if (msg->addr == 0x340U) { + const uint32_t now = microsecond_timer_get(); + const uint8_t counter = msg->data[4] >> 4U; + const bool valid = hyundai_i30_lkas_checksum_valid(msg); + hyundai_i30_camera_idle = valid && hyundai_i30_camera_seen && hyundai_i30_camera_is_idle(msg) && + (counter == ((hyundai_i30_camera_counter + 1U) & 0xFU)) && + (safety_get_ts_elapsed(now, hyundai_i30_camera_ts) <= 30000U); + hyundai_i30_camera_seen = valid; + hyundai_i30_camera_counter = counter; + hyundai_i30_camera_ts = now; + if (!hyundai_i30_camera_idle) { + hyundai_i30_host_steering = false; + } + } else { + } + } hyundai_daw_rx(msg); if ((msg->addr == 0x391U) || (msg->addr == 0x50CU)) { blended_aol_rx(msg); @@ -1037,7 +1146,7 @@ static void hyundai_optional_rx_hook(const CANPacket_t *msg) { } const safety_hooks hyundai_hooks = { - .fwd_packet = hyundai_daw_fwd, + .fwd_packet = hyundai_i30_fwd_packet, .fwd = blended_aol_fwd, .init = hyundai_init, .optional_rx = hyundai_optional_rx_hook, diff --git a/opendbc_repo/opendbc/safety/modes/toyota.h b/opendbc_repo/opendbc/safety/modes/toyota.h index a559eb1b58..1972930708 100644 --- a/opendbc_repo/opendbc/safety/modes/toyota.h +++ b/opendbc_repo/opendbc/safety/modes/toyota.h @@ -67,6 +67,10 @@ static bool toyota_alt_brake = false; static bool toyota_stock_longitudinal = false; static bool toyota_lta = false; static bool toyota_radar_diagnostics_allowed = false; +static bool toyota_enhanced_bsm = false; +static bool toyota_factory_bsm_seen = false; +static uint32_t toyota_bsm_tx_ts[2] = {0U, 0U}; +static bool toyota_bsm_session[2] = {false, false}; static int toyota_dbc_eps_torque_factor = 100; // conversion factor for STEER_TORQUE_EPS in %: see dbc file static bool toyota_hold_main_on = false; @@ -219,6 +223,9 @@ static void toyota_hold_observe(const CANPacket_t *msg) { } static void toyota_optional_rx_hook(const CANPacket_t *msg) { + if (toyota_enhanced_bsm && msg_matches(msg, 0x3F6U, 0U) && (GET_LEN(msg) == 8U)) { + toyota_factory_bsm_seen = true; + } // Only bus0 pedal RX belongs to the required catalog. A CRC-valid camera // copy must neither invalidate its parent nor refresh the primary lease. const bool camera_copy = toyota_pedal && msg_matches(msg, 0x201U, 2U) && (GET_LEN(msg) == 6U) && @@ -605,6 +612,25 @@ static bool toyota_tx_hook(const CANPacket_t *msg) { !vehicle_moving && !gas_pressed && !safety_rx_checks_invalid && !relay_malfunction && (safety_get_ts_elapsed(now, toyota_hold_speed_ts) <= 100000U) && (safety_get_ts_elapsed(now, toyota_hold_gas_ts) <= 100000U); + } else if (toyota_enhanced_bsm && ((msg->data[0] == 0x41U) || (msg->data[0] == 0x42U))) { + const unsigned int side = msg->data[0] - 0x41U; + const uint64_t request = payload & ~0xFFULL; + const bool stop_polling = request == 0x0000000001100200ULL; + const bool start = request == 0x0000000060100200ULL; + const bool poll = request == 0x0000000069210200ULL; + const uint32_t now = microsecond_timer_get(); + const bool wheel_speed_current = toyota_hold_speed_seen && + (safety_get_ts_elapsed(now, toyota_hold_speed_ts) <= 100000U); + const bool ready = toyota_rx_ready(now) && wheel_speed_current && !safety_rx_checks_invalid && !relay_malfunction; + const bool session = toyota_bsm_session[side]; + const bool paced = safety_get_ts_elapsed(now, toyota_bsm_tx_ts[side]) >= 40000U; + const bool enable = start && !session && (vehicle_speed.values[0] > (7 * VEHICLE_SPEED_FACTOR)); + const bool poll_allowed = poll && session && paced && (vehicle_speed.values[0] > (6 * VEHICLE_SPEED_FACTOR)); + tx &= (stop_polling && session) || (!toyota_factory_bsm_seen && ready && (enable || poll_allowed)); + if (tx) { + toyota_bsm_session[side] = !stop_polling; + toyota_bsm_tx_ts[side] = now; + } } else { // Preserve the original radar-only tester-present allowance and configuration scope. tx &= toyota_radar_diagnostics_allowed && (payload == 0x00000000003E020FULL); @@ -619,6 +645,12 @@ static bool toyota_tx_hook(const CANPacket_t *msg) { } static safety_config toyota_init(uint16_t param) { + toyota_factory_bsm_seen = false; + toyota_enhanced_bsm = (param == 73U) && ((alternative_experience & ALT_EXP_TOYOTA_ENHANCED_BSM) != 0); + for (unsigned int i = 0U; i < 2U; i++) { + toyota_bsm_tx_ts[i] = 0U; + toyota_bsm_session[i] = false; + } const uint16_t parent_param = toyota_pedal_parent_param(param); toyota_factory_stock = toyota_factory_stock_param(parent_param); toyota_factory_eps5 = toyota_factory_stock && (parent_param != 0x6242U) && (parent_param != 0x6249U); diff --git a/opendbc_repo/opendbc/safety/modes/toyota_aol.h b/opendbc_repo/opendbc/safety/modes/toyota_aol.h index 3f224b711c..e6b20e24be 100644 --- a/opendbc_repo/opendbc/safety/modes/toyota_aol.h +++ b/opendbc_repo/opendbc/safety/modes/toyota_aol.h @@ -233,7 +233,8 @@ static void toyota_aol_observe(const CANPacket_t *msg) { } static void toyota_aol_configure(uint16_t param) { - const bool aol_requested = (alternative_experience == 32) || (alternative_experience == 160) || (alternative_experience == 288); + const int aol_experience = ((param == 73U) && (current_safety_param == 73U)) ? (alternative_experience & ~ALT_EXP_TOYOTA_ENHANCED_BSM) : alternative_experience; + const bool aol_requested = (aol_experience == 32) || (aol_experience == 160) || (aol_experience == 288); toyota_aol_reset(); toyota_camera_2aa_ambiguous = false; toyota_prius_sdsu_ambiguous = false; diff --git a/opendbc_repo/opendbc/safety/tests/test_hyundai.py b/opendbc_repo/opendbc/safety/tests/test_hyundai.py index 833fc4c8de..47c64e4e55 100755 --- a/opendbc_repo/opendbc/safety/tests/test_hyundai.py +++ b/opendbc_repo/opendbc/safety/tests/test_hyundai.py @@ -2,6 +2,7 @@ import random import unittest +from opendbc.car.hyundai.hyundaican import hyundai_checksum from opendbc.car.hyundai.values import HyundaiSafetyFlags from opendbc.car.structs import CarParams from opendbc.safety.tests.common import CANPackerSafety @@ -568,5 +569,68 @@ class TestHyundaiSoftwareCruiseSafety(unittest.TestCase): self.assertFalse(safety.safety_tx_hook(button(2))) +class TestHyundaiI30StockCruiseSafety(unittest.TestCase): + def setUp(self): + self.safety = libsafety_py.libsafety + self.packer = CANPackerSafety("hyundai_can_generated") + self.safety.init_tests() + self.safety.set_alternative_experience(0) + self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hyundai, 0x6200), 0) + + def _lkas(self, bus, counter, torque=0, request=False, corrupt=False): + def add_crc(msg): + addr, data, source = msg + data = bytearray(data) + data[6] = hyundai_checksum(data[:6] + data[7:]) ^ int(corrupt) + return addr, data, source + + values = {"CF_Lkas_MsgCount": counter, "CR_Lkas_StrToqReq": torque, "CF_Lkas_ActToi": request} + return self.packer.make_can_msg_safety("LKAS11", bus, values, fix_checksum=add_crc) + + def _engage_stock_cruise(self): + frames = ( + ("CLU11", {"CF_Clu_CruiseSwState": 2}, None), + ("EMS16", {}, checksum), + ("WHL_SPD11", {"WHL_SPD_FL": 15, "WHL_SPD_RR": 15}, checksum), + ("TCS13", {}, checksum), + ("MDPS12", {"CR_Mdps_StrColTq": 0}, None), + ("SCC12", {"ACCMode": 1}, checksum), + ) + for name, values, fix_checksum in frames: + self.assertTrue(self.safety.safety_rx_hook(self.packer.make_can_msg_safety(name, 0, values, fix_checksum=fix_checksum))) + self.assertTrue(self.safety.get_controls_allowed()) + self.assertTrue(self.safety.safety_config_valid()) + + def test_steering_requires_fresh_camera_and_stock_cruise(self): + self.assertFalse(self.safety.safety_tx_hook(self._lkas(0, 0, torque=1, request=True))) + self._engage_stock_cruise() + for count in (0, 1): + self.assertTrue(self.safety.safety_rx_hook(self._lkas(2, count))) + self.assertFalse(self.safety.safety_tx_hook(self._lkas(0, 0, torque=1, request=True, corrupt=True))) + self.assertFalse(self.safety.safety_tx_hook(self._lkas(0, 0, torque=91, request=True))) + self.assertTrue(self.safety.safety_tx_hook(self._lkas(0, 0, torque=1, request=True))) + + self.safety.set_timer(30_001) + self.assertFalse(self.safety.safety_tx_hook(self._lkas(0, 1, torque=1, request=True))) + + def test_forwarding_releases_when_camera_or_topology_conflicts(self): + self._engage_stock_cruise() + for count in (0, 1): + self.assertTrue(self.safety.safety_rx_hook(self._lkas(2, count))) + self.assertTrue(self.safety.safety_tx_hook(self._lkas(0, 0, torque=1, request=True))) + self.assertEqual(self.safety.safety_fwd_packet_hook(self._lkas(2, 2)), -1) + self.assertEqual(self.safety.safety_fwd_packet_hook(self._lkas(2, 2, torque=1, request=True)), 0) + self.assertTrue(self.safety.safety_rx_hook(self._lkas(2, 3, corrupt=True))) + self.assertEqual(self.safety.safety_fwd_packet_hook(self._lkas(2, 4)), 0) + + for count in (4, 5): + self.assertTrue(self.safety.safety_rx_hook(self._lkas(2, count))) + self.assertTrue(self.safety.safety_tx_hook(self._lkas(0, 1, torque=1, request=True))) + self.assertTrue(self.safety.safety_rx_hook(common.make_msg(2, 0x421, 8))) + self.assertEqual(self.safety.safety_fwd_packet_hook(self._lkas(2, 6)), 0) + self.assertFalse(self.safety.safety_tx_hook(self._lkas(0, 2, torque=1, request=True))) + self.assertFalse(self.safety.safety_tx_hook(common.make_msg(0, 0x421, 8))) + + if __name__ == "__main__": unittest.main() diff --git a/opendbc_repo/opendbc/safety/tests/test_toyota.py b/opendbc_repo/opendbc/safety/tests/test_toyota.py index d8879bedb9..10a4cb620f 100644 --- a/opendbc_repo/opendbc/safety/tests/test_toyota.py +++ b/opendbc_repo/opendbc/safety/tests/test_toyota.py @@ -9,6 +9,7 @@ import sys from opendbc.car.toyota.values import ToyotaSafetyFlags from opendbc.car.structs import CarParams +from opendbc.safety import ALTERNATIVE_EXPERIENCE from opendbc.safety.tests.libsafety import libsafety_py import opendbc.safety.tests.common as common @@ -572,6 +573,42 @@ class TestToyotaHighlanderAol(unittest.TestCase): self.assertTrue(self.safety.safety_rx_hook(self.packer.make_can_msg_safety("EPS_STATUS", 0, {"LKA_STATE": eps}))) self.safety.aol_set_host_request(3) + def test_enhanced_bsm_diagnostics_require_scoped_fresh_and_paced_session(self): + left = 0x41 + right = 0x42 + + def send(side, command): + return self.safety.safety_tx_hook(common.make_msg(0, 0x750, dat=bytes((side, 2, *command, 0, 0, 0, 0)))) + + start = (0x10, 0x60) + poll = (0x21, 0x69) + stop = (0x10, 0x01) + + self.init(ae=32) + self.physical() + self.assertFalse(send(left, start)) + self.init(ae=32 | ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM) + self.assertFalse(send(left, start)) + self.physical() + self.assertEqual(self.safety.aol_get_permission_mask(), 1) + speed = {f"WHEEL_SPEED_{wheel}": 36 for wheel in ("FL", "FR", "RL", "RR")} + self.assertTrue(self.safety.safety_rx_hook(self.packer.make_can_msg_safety("WHEEL_SPEEDS", 0, speed))) + self.assertTrue(send(left, start)) + self.assertFalse(send(left, start)) + self.assertFalse(send(left, poll)) + self.assertFalse(send(right, poll)) + self.safety.set_timer(1_040_000) + self.assertTrue(send(left, poll)) + self.assertFalse(send(left, (0x22, 0x69))) + self.assertTrue(send(right, start)) + self.rx(0x3F6, bytes(8)) + self.safety.set_timer(1_080_000) + self.assertFalse(send(left, poll)) + self.assertTrue(send(left, stop)) + self.assertTrue(send(right, stop)) + self.assertFalse(send(left, start)) + self.assertFalse(send(left, stop)) + def test_radar_stock_lateral_never_grants_longitudinal(self): self.init(word=585) self.physical(cruise=True) diff --git a/openpilot/common/libcommon.a b/openpilot/common/libcommon.a index 86c797b128..6daac230b1 100644 Binary files a/openpilot/common/libcommon.a and b/openpilot/common/libcommon.a differ diff --git a/openpilot/common/libparams_c.so b/openpilot/common/libparams_c.so index 1f6d24f18d..4441a56c39 100755 Binary files a/openpilot/common/libparams_c.so and b/openpilot/common/libparams_c.so differ diff --git a/openpilot/common/params_keys.h b/openpilot/common/params_keys.h index 568c73d7e8..983aaf57a4 100644 --- a/openpilot/common/params_keys.h +++ b/openpilot/common/params_keys.h @@ -24,6 +24,7 @@ inline static std::unordered_map keys = { {"NostalgiaMode", {PERSISTENT, BOOL, "0"}}, {"SNGHack", {PERSISTENT, BOOL, "0"}}, {"ToyotaAutoHold", {PERSISTENT, BOOL, "0"}}, + {"ToyotaEnhancedBsm", {PERSISTENT, BOOL, "0"}}, {"JeepBrakeHold", {PERSISTENT, BOOL, "0"}}, {"ToyotaRadarMode", {PERSISTENT, INT, "0"}}, {"RemoteStartBootsComma", {PERSISTENT, BOOL, "0"}}, diff --git a/openpilot/selfdrive/pandad/libpanda.a b/openpilot/selfdrive/pandad/libpanda.a index deea941c53..2486897e24 100644 Binary files a/openpilot/selfdrive/pandad/libpanda.a and b/openpilot/selfdrive/pandad/libpanda.a differ diff --git a/openpilot/selfdrive/pandad/main.o b/openpilot/selfdrive/pandad/main.o index b4d14ffcf1..b7bbca420c 100644 Binary files a/openpilot/selfdrive/pandad/main.o and b/openpilot/selfdrive/pandad/main.o differ diff --git a/openpilot/selfdrive/pandad/panda.o b/openpilot/selfdrive/pandad/panda.o index 79598ed9d1..571ecacfa4 100644 Binary files a/openpilot/selfdrive/pandad/panda.o and b/openpilot/selfdrive/pandad/panda.o differ diff --git a/openpilot/selfdrive/pandad/panda_safety.o b/openpilot/selfdrive/pandad/panda_safety.o index 6cabe575ae..35c7846131 100644 Binary files a/openpilot/selfdrive/pandad/panda_safety.o and b/openpilot/selfdrive/pandad/panda_safety.o differ diff --git a/openpilot/selfdrive/pandad/panda_usb.o b/openpilot/selfdrive/pandad/panda_usb.o index 807e70896c..b2ca8e790e 100644 Binary files a/openpilot/selfdrive/pandad/panda_usb.o and b/openpilot/selfdrive/pandad/panda_usb.o differ diff --git a/openpilot/selfdrive/pandad/pandad b/openpilot/selfdrive/pandad/pandad index 18c4822bff..31eee547fb 100755 Binary files a/openpilot/selfdrive/pandad/pandad and b/openpilot/selfdrive/pandad/pandad differ diff --git a/openpilot/selfdrive/pandad/pandad.o b/openpilot/selfdrive/pandad/pandad.o index 44364254b4..9796e43525 100644 Binary files a/openpilot/selfdrive/pandad/pandad.o and b/openpilot/selfdrive/pandad/pandad.o differ diff --git a/openpilot/selfdrive/pandad/spi.o b/openpilot/selfdrive/pandad/spi.o index 52696da140..89ccd4c377 100644 Binary files a/openpilot/selfdrive/pandad/spi.o and b/openpilot/selfdrive/pandad/spi.o differ diff --git a/openpilot/starpilot/car/toyota/aol.py b/openpilot/starpilot/car/toyota/aol.py index 96fbff4658..26eeece016 100644 --- a/openpilot/starpilot/car/toyota/aol.py +++ b/openpilot/starpilot/car/toyota/aol.py @@ -164,7 +164,12 @@ def qualified(cp, *, marked_only=False): allowed_experience = (32 | hold_permission,) if hold else (32,) if not marked_only: allowed_experience += (0, hold_permission) if hold else (0,) - if (cp.alternativeExperience not in allowed_experience or + from opendbc.car.toyota import enhanced_bsm + from opendbc.safety import ALTERNATIVE_EXPERIENCE + experience = cp.alternativeExperience + if enhanced_bsm.configured(cp): + experience &= ~ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM + if (experience not in allowed_experience or hold and not toyota_auto_hold_supported(cp)): return False required_flags = ToyotaFlags.TSS2 | ToyotaFlags.NO_DSU | ToyotaFlags.RAISED_ACCEL_LIMIT diff --git a/openpilot/starpilot/galaxy/vehicle_configuration.py b/openpilot/starpilot/galaxy/vehicle_configuration.py index 89086f1c46..5f35710239 100644 --- a/openpilot/starpilot/galaxy/vehicle_configuration.py +++ b/openpilot/starpilot/galaxy/vehicle_configuration.py @@ -5,7 +5,7 @@ from openpilot.starpilot.vehicle_selection import read_selection STARTUP_KEYS = ('SubaruAvhStartup', 'SubaruStopStartOff', 'AlphaLongitudinalEnabled', 'IsReleaseBranch', 'OpenpilotEnabledToggle', 'SafeMode', - 'DisableOpenpilotLongitudinal', 'ToyotaAutoHold', 'JeepBrakeHold', + 'DisableOpenpilotLongitudinal', 'ToyotaAutoHold', 'ToyotaEnhancedBsm', 'JeepBrakeHold', 'VoltSNG', 'GMAutoHold', 'VoltOnePedalMode', 'TurnAssist', 'LongPitch', 'HondaBoschARadar', 'NAPPedalEnabled', 'NAPRadarEnabled', 'NAPRadarBehindNosecone') diff --git a/openpilot/starpilot/lateral/hkg_vehicle_policy.py b/openpilot/starpilot/lateral/hkg_vehicle_policy.py index 18cbd99b95..b8368dd546 100644 --- a/openpilot/starpilot/lateral/hkg_vehicle_policy.py +++ b/openpilot/starpilot/lateral/hkg_vehicle_policy.py @@ -129,6 +129,9 @@ class HKGVehicleTorquePolicy(HKGShapedTorquePolicy): highway = float(np.interp(speed, [27.0, 29.0], [0.0, 1.0])) arc = float(np.interp(abs(setpoint), [0.45, 0.65, 1.25, 1.6], [0.0, 1.0, 1.0, 0.0])) threshold += 0.18 * highway * arc + high_speed = float(np.interp(speed, (28., 30., 33., 36.), (0., 1., 1., 0.))) + shallow_arc = float(np.interp(abs(setpoint), (.35, .45, .70, .90), (0., 1., 1., 0.))) + threshold += .80 * high_speed * shallow_arc return threshold, 1 + ( shaping.get_ioniq_5_friction_scale(speed, setpoint, jerk) - 1 ) * shaping.get_ioniq_5_center_taper_scale(setpoint, speed) diff --git a/openpilot/starpilot/lateral/tests/test_hkg_torque_context.py b/openpilot/starpilot/lateral/tests/test_hkg_torque_context.py index ab7f33c147..4f596820ab 100644 --- a/openpilot/starpilot/lateral/tests/test_hkg_torque_context.py +++ b/openpilot/starpilot/lateral/tests/test_hkg_torque_context.py @@ -126,6 +126,13 @@ def test_actual_first_driver_release_tick_preserves_dom_override_bypass(monkeypa (True, 28.0, 0.9, False, False, 0.09), (True, 26.0, 0.9, False, False, 0.0), (True, 30.0, 0.3, False, False, 0.0), + (True, 30.0, 0.55, False, False, 0.89), + (True, 34.5, 0.55, False, False, 0.49), + (True, 36.0, 0.55, False, False, 0.09), + (True, 27.0, 0.55, False, False, 0.0), + (True, 30.0, 0.55, True, False, 0.0), + (True, 30.0, 0.55, False, True, 0.0), + (False, 30.0, 0.55, False, False, 0.0), (True, 30.0, 1.8, False, False, 0.0), (True, 30.0, 0.9, True, False, 0.0), (True, 30.0, 0.9, False, True, 0.0), diff --git a/openpilot/starpilot/ui/cruise_steps_feature.py b/openpilot/starpilot/ui/cruise_steps_feature.py new file mode 100644 index 0000000000..c23401e7c6 --- /dev/null +++ b/openpilot/starpilot/ui/cruise_steps_feature.py @@ -0,0 +1,93 @@ +from __future__ import annotations + +import math +from typing import TYPE_CHECKING + +from openpilot.starpilot.controllers.toyota_cruise import capability as toyota_cruise_capability +from openpilot.starpilot.saved_document import commit_exact +from openpilot.starpilot.saved_source import read_saved +from openpilot.starpilot.ui.feature_settings_state import FeatureRow, FeatureSettingsRequest + +if TYPE_CHECKING: + from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner + + +CRUISE_KEYS = frozenset(("CustomCruise", "CustomCruiseLong")) + + +def cruise_rows(owner: FeatureSettingsOwner, configurable: bool) -> list[FeatureRow]: + software_capability = owner._cruise_capability() + toyota_capability = toyota_cruise_capability(owner.vehicle_params()) + capability = software_capability or toyota_capability + group = "toyota_cruise" if toyota_capability is not None else "long" + allowed = configurable and capability is not None and owner.authority(group) + unit_value, unit_raw, unit_valid = owner._value("IsMetric") + unit_valid = unit_valid and unit_value in ("0", "1") and owner._readable("IsMetric") + unit = "km/h" if unit_value == "1" else "mph" + reason = "Requires StarPilot cruise speed control" if capability is None else "Requires a compatible cruise configuration" + rows = [] + if toyota_capability is not None: + value, raw, valid = owner._value("ReverseCruise") + rows.append(FeatureRow("ReverseCruise", "Swap Toyota Cruise Steps", "On" if value == "1" else "Off" if value == "0" else "Invalid saved value", + raw, ("Off", "On") if valid else (), available=allowed and valid, + reason="Short press changes set speed by 5; hold changes it by 1", + capability=toyota_capability, dependencies=())) + return rows + for key, label, default in (("CustomCruise", "Short press", 1.0), ("CustomCruiseLong", "Hold", 5.0)): + value, raw, valid = owner._value(key) + try: + number = float(value) + valid = valid and owner._readable(key) and math.isfinite(number) and 1.0 <= number <= 150.0 + except ValueError: + valid = False + number = default + rows.append(FeatureRow(key, label, f"{number:g}" if valid else "Invalid saved value", raw, + step=1.0 if valid else 0.0, minimum=1.0, maximum=150.0 if unit_value == "1" else 99.0, + unit=unit if unit_valid else "", available=allowed and valid and unit_valid, + reason="Invalid saved value or units" if not valid or not unit_valid else + "Used when StarPilot controls cruise speed" if allowed else reason, + capability=capability, dependencies=(("IsMetric", unit_raw),), + display_unit=unit if unit_valid else "", default_value=str(default))) + return rows + +def apply_cruise(owner: FeatureSettingsOwner, request: FeatureSettingsRequest) -> bool: + key = request.key + if key not in CRUISE_KEYS or not request.confirmation: + return False + def authorized() -> bool: + if (not request.vehicle_fingerprint or owner.vehicle_fingerprint() != request.vehicle_fingerprint or + request.capability is None or request.capability != (owner._cruise_capability() or toyota_cruise_capability(owner.vehicle_params())) or + not owner.authority("long")): + return False + raw, readable = read_saved(owner.params, key, 128) + if not readable or raw != request.expected: + return False + if owner._cruise_capability() is None: + return False + units, units_readable = read_saved(owner.params, "IsMetric", 8) + return (units_readable and units in (None, b"0", b"1") and + request.dependencies == (("IsMetric", units),) and + request.display_unit == ("km/h" if units == b"1" else "mph")) + if not authorized(): + return False + try: + number = float(request.value) + except ValueError: + return False + upper = 150.0 if request.display_unit == "km/h" else 99.0 + if not math.isfinite(number) or not 1.0 <= number <= upper: + return False + encoded = str(number).encode() + return commit_exact(owner.params, key=key, max_bytes=128, raw=encoded, expected=request.expected, + authorized=authorized, temp_prefix=".cruise-interval-").verified + +def apply_reverse_cruise(owner: FeatureSettingsOwner, request: FeatureSettingsRequest) -> bool: + if request.value not in ("On", "Off"): + return False + def authorized(): + cap = toyota_cruise_capability(owner.vehicle_params()) + return bool(cap is not None and request.capability == cap and owner.authority("toyota_cruise") and + request.vehicle_fingerprint == owner.vehicle_fingerprint() and request.dependencies == ()) + return commit_exact(owner.params, key="ReverseCruise", max_bytes=8, expected=request.expected, + raw=b"1" if request.value == "On" else b"0", authorized=authorized, + temp_prefix=".toyota-cruise-").verified diff --git a/openpilot/starpilot/ui/feature_defaults.py b/openpilot/starpilot/ui/feature_defaults.py index f0faf8a77c..9b02e1eacd 100644 --- a/openpilot/starpilot/ui/feature_defaults.py +++ b/openpilot/starpilot/ui/feature_defaults.py @@ -19,6 +19,7 @@ BOOL_DEFAULTS = { "DriveModeProfiles": False, "DriveModeAcceleration": True, "DriveModeDeceleration": True, "SubaruAvhStartup": False, "SubaruStopStartOff": False, + "ToyotaEnhancedBsm": False, "SubaruSNG": False, "SubaruRedneckCruise": False, "RedneckCruise": False, diff --git a/openpilot/starpilot/ui/feature_settings_owner.py b/openpilot/starpilot/ui/feature_settings_owner.py index b0bbe96bda..4862a18f7c 100644 --- a/openpilot/starpilot/ui/feature_settings_owner.py +++ b/openpilot/starpilot/ui/feature_settings_owner.py @@ -62,6 +62,7 @@ from openpilot.starpilot.longitudinal.profile_preferences import read_document_v from openpilot.starpilot.ui.long_profile_feature import (LongProfileFeature, is_long_confirm_action, VALUE_HELP, CATEGORY_HELP, preset_label, preset_value) from openpilot.starpilot.ui.traffic_feature import TrafficFeature, EDIT_KEYS as TRAFFIC_EDIT_KEYS +from openpilot.starpilot.ui.cruise_steps_feature import CRUISE_KEYS, apply_cruise, apply_reverse_cruise, cruise_rows from openpilot.starpilot.ui.lane_change_feature import LaneChangeFeature, KEYS as LANE_CHANGE_KEYS from openpilot.starpilot.ui.conditional_feature import BUTTON_PREFIX, ConditionalFeature from openpilot.starpilot.saved_source import read_saved @@ -114,7 +115,6 @@ LANE_LIVE_KEYS = frozenset(("LaneCentering", "LaneCenteringPauseOnSignal", "Lane "LaneCenteringE2EAuthority", "LaneCenteringStrength")) CURVE_KEYS = frozenset((CURVE_MASTER_KEY, CURVE_NO_LEAD_KEY)) CURVE_PAGE_KEYS = CURVE_KEYS | {"ShowCSCStatus"} -CRUISE_KEYS = frozenset(("CustomCruise", "CustomCruiseLong")) class FeatureSettingsOwner: @@ -459,6 +459,25 @@ class FeatureSettingsOwner: raw=b"1" if request.value == "On" else b"0", authorized=authorized, temp_prefix=".toyota-sng-").verified + def _enhanced_bsm_capability(self) -> tuple | None: + from opendbc.car.toyota.enhanced_bsm import supported + cp = self.vehicle_params() + if cp is None or not supported(cp): + return None + return (str(cp.carFingerprint), str(cp.carVin), int(cp.flags), int(cp.safetyConfigs[0].safetyParam)) + + def _apply_enhanced_bsm(self, request: FeatureSettingsRequest) -> bool: + if not request.confirmation or request.value not in ("Off", "On") or request.dependencies: + return False + + def authorized() -> bool: + return (bool(request.vehicle_fingerprint) and self.vehicle_fingerprint() == request.vehicle_fingerprint and + request.capability is not None and request.capability == self._enhanced_bsm_capability() and + self.authority("vehicle") and self.authority("parked_preferences") and request.expected in (None, b"0", b"1")) + + return commit_exact(self.params, key="ToyotaEnhancedBsm", max_bytes=8, raw=b"1" if request.value == "On" else b"0", + expected=request.expected, authorized=authorized, temp_prefix=".toyota-bsm-").verified + def _auto_hold_capability(self) -> tuple | None: from opendbc.car.toyota.interface import toyota_auto_hold_supported cp = self.vehicle_params() @@ -508,83 +527,6 @@ class FeatureSettingsOwner: authorized=authorized, temp_prefix=".global-preference-") return result.committed and result.verified - def _cruise_rows(self, configurable: bool) -> list[FeatureRow]: - software_capability = self._cruise_capability() - toyota_capability = toyota_cruise_capability(self.vehicle_params()) - capability = software_capability or toyota_capability - group = "toyota_cruise" if toyota_capability is not None else "long" - allowed = configurable and capability is not None and self.authority(group) - unit_value, unit_raw, unit_valid = self._value("IsMetric") - unit_valid = unit_valid and unit_value in ("0", "1") and self._readable("IsMetric") - unit = "km/h" if unit_value == "1" else "mph" - reason = "Requires StarPilot cruise speed control" if capability is None else "Requires a compatible cruise configuration" - rows = [] - if toyota_capability is not None: - value, raw, valid = self._value("ReverseCruise") - rows.append(FeatureRow("ReverseCruise", "Swap Toyota Cruise Steps", "On" if value == "1" else "Off" if value == "0" else "Invalid saved value", - raw, ("Off", "On") if valid else (), available=allowed and valid, - reason="Short press changes set speed by 5; hold changes it by 1", - capability=toyota_capability, dependencies=())) - return rows - for key, label, default in (("CustomCruise", "Short press", 1.0), ("CustomCruiseLong", "Hold", 5.0)): - value, raw, valid = self._value(key) - try: - number = float(value) - valid = valid and self._readable(key) and math.isfinite(number) and 1.0 <= number <= 150.0 - except ValueError: - valid = False - number = default - rows.append(FeatureRow(key, label, f"{number:g}" if valid else "Invalid saved value", raw, - step=1.0 if valid else 0.0, minimum=1.0, maximum=150.0 if unit_value == "1" else 99.0, - unit=unit if unit_valid else "", available=allowed and valid and unit_valid, - reason="Invalid saved value or units" if not valid or not unit_valid else - "Used when StarPilot controls cruise speed" if allowed else reason, - capability=capability, dependencies=(("IsMetric", unit_raw),), - display_unit=unit if unit_valid else "", default_value=str(default))) - return rows - - def _apply_cruise(self, request: FeatureSettingsRequest) -> bool: - key = request.key - if key not in CRUISE_KEYS or not request.confirmation: - return False - def authorized() -> bool: - if (not request.vehicle_fingerprint or self.vehicle_fingerprint() != request.vehicle_fingerprint or - request.capability is None or request.capability != (self._cruise_capability() or toyota_cruise_capability(self.vehicle_params())) or - not self.authority("long")): - return False - raw, readable = read_saved(self.params, key, 128) - if not readable or raw != request.expected: - return False - if self._cruise_capability() is None: - return False - units, units_readable = read_saved(self.params, "IsMetric", 8) - return (units_readable and units in (None, b"0", b"1") and - request.dependencies == (("IsMetric", units),) and - request.display_unit == ("km/h" if units == b"1" else "mph")) - if not authorized(): - return False - try: - number = float(request.value) - except ValueError: - return False - upper = 150.0 if request.display_unit == "km/h" else 99.0 - if not math.isfinite(number) or not 1.0 <= number <= upper: - return False - encoded = str(number).encode() - return commit_exact(self.params, key=key, max_bytes=128, raw=encoded, expected=request.expected, - authorized=authorized, temp_prefix=".cruise-interval-").verified - - def _apply_reverse_cruise(self, request): - if request.value not in ("On", "Off"): - return False - def authorized(): - cap = toyota_cruise_capability(self.vehicle_params()) - return bool(cap is not None and request.capability == cap and self.authority("toyota_cruise") and - request.vehicle_fingerprint == self.vehicle_fingerprint() and request.dependencies == ()) - return commit_exact(self.params, key="ReverseCruise", max_bytes=8, expected=request.expected, - raw=b"1" if request.value == "On" else b"0", authorized=authorized, - temp_prefix=".toyota-cruise-").verified - def _dependents(self, *keys: str) -> tuple[tuple[str, bytes | None], ...]: return tuple((key, self._raw(key)) for key in keys) @@ -894,7 +836,8 @@ class FeatureSettingsOwner: page=FeaturePage.DEVELOPER_LONGITUDINAL, available=True), FeatureRow("", "Wheel Controls", "Assign steering-wheel buttons and cruise behavior", page=FeaturePage.WHEEL, available=True)] if (self._long_pitch_capability() is not None or self._bolt_disable_capability() is not None or - self._auto_hold_capability() is not None or self._toyota_sng_capability() is not None or self._jeep_hold_capability() is not None or + self._auto_hold_capability() is not None or self._enhanced_bsm_capability() is not None or + self._toyota_sng_capability() is not None or self._jeep_hold_capability() is not None or self._mqb_cluster_takeover_capability() is not None or self._pedal_setup_capability() is not None or self.subaru_smoothing.capability() is not None or self._subaru_avh_capability() is not None or self._subaru_startup_capability() is not None or self._subaru_sng_capability() is not None or @@ -934,6 +877,12 @@ class FeatureSettingsOwner: "Hold the brake for over one second at a complete stop with cruise main on and cruise disengaged. " + "Holds until you press the gas; normal cruise stop-and-go is unchanged. Applies after the next startup.") rows.extend([replace(row, available=row.available and self._readable("ToyotaAutoHold"), capability=capability)] if capability is not None else []) + bsm_capability = self._enhanced_bsm_capability() + if bsm_capability is not None: + row = self._bool_row("ToyotaEnhancedBsm", "Enhanced Blind Spot Monitoring", + configurable and parked and self.authority("vehicle") and self.authority("parked_preferences"), + "Read compatible Prius blind-spot sensors while driving. Applies after the next startup.") + rows.append(replace(row, available=row.available and self._readable("ToyotaEnhancedBsm"), capability=bsm_capability)) sng_capability = self._toyota_sng_capability() if sng_capability is not None: row = self._bool_row("SNGHack", "Stop-and-Go Hack", @@ -1181,7 +1130,7 @@ class FeatureSettingsOwner: elif page == FeaturePage.WHEEL: title = "Wheel Controls" if self.show_cruise_intervals or toyota_cruise_capability(self.vehicle_params()) is not None: - rows.extend(self._cruise_rows(configurable)) + rows.extend(cruise_rows(self, configurable)) rows = self.wheel.page(rows) elif page == FeaturePage.SLC: cp = self.vehicle_params() @@ -1479,7 +1428,7 @@ class FeatureSettingsOwner: if key == OUTPUT_MAX_KEY: return False if key == "ReverseCruise": - return self._apply_reverse_cruise(request) + return apply_reverse_cruise(self, request) if key in LATERAL_PAUSE_KEYS: return self._apply_lateral_pause(request) if key == "FordRearFogIndicator": @@ -1547,6 +1496,8 @@ class FeatureSettingsOwner: return self._apply_alpha_long(request) if key == "SNGHack": return self._apply_toyota_sng(request) + if key == "ToyotaEnhancedBsm": + return self._apply_enhanced_bsm(request) if key == "ToyotaAutoHold": return self._apply_auto_hold(request) if key == PLANNER_SELECTION_KEY: @@ -1557,7 +1508,7 @@ class FeatureSettingsOwner: if key in GLOBAL_BOOL_PREFERENCES: return self._apply_global_bool_preference(request) if key in CRUISE_KEYS: - return self._apply_cruise(request) + return apply_cruise(self, request) if key.startswith("conditional:"): return self.conditional.apply(request) if key in CURVE_ACTION_KEYS: diff --git a/openpilot/starpilot/ui/tests/test_toyota_enhanced_bsm.py b/openpilot/starpilot/ui/tests/test_toyota_enhanced_bsm.py new file mode 100644 index 0000000000..5b601989e8 --- /dev/null +++ b/openpilot/starpilot/ui/tests/test_toyota_enhanced_bsm.py @@ -0,0 +1,53 @@ +from dataclasses import replace +from types import SimpleNamespace + +from opendbc.car import gen_empty_fingerprint, structs +from opendbc.car.toyota.enhanced_bsm import configured +from opendbc.car.toyota.interface import CarInterface +from opendbc.car.toyota.values import CAR +from openpilot.common.params import Params +from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner +from openpilot.starpilot.ui.feature_settings_state import FeaturePage, row_change +from openpilot.starpilot.ui.vehicle_bool import VEHICLE_BOOL_KEYS, confirmation_question +from openpilot.starpilot.vehicle_preferences import VehicleStartupPreferences + + +def test_vehicle_setting_and_startup_permission(tmp_path): + params = Params(str(tmp_path)) + fw = [structs.CarParams.CarFw(ecu=structs.CarParams.Ecu.hybrid)] + current = SimpleNamespace(cp=CarInterface.get_params(CAR.TOYOTA_PRIUS_TSS2, gen_empty_fingerprint(), fw, False, False, False), parked=True) + owner = FeatureSettingsOwner(params, lambda group: current.parked and group in ('vehicle', 'parked_preferences'), + vehicle_fingerprint=lambda: current.cp.carFingerprint, vehicle_params=lambda: current.cp) + + def rows(): + state = owner.snapshot(FeaturePage.VEHICLE, parked=current.parked, system_long=True, lateral_context=True, metric=False) + return [row for row in state.rows if row.key == 'ToyotaEnhancedBsm'] + + assert not configured(VehicleStartupPreferences.read(params, enabled=True).prepare(current.cp)) + row, = rows() + assert row.available and row.value == 'Off' + request = row_change(row) + assert request is not None + assert request.key in VEHICLE_BOOL_KEYS and 'next startup' in confirmation_question(request) + assert not owner.apply(request) + request = replace(request, confirmation=True) + current.parked = False + assert not owner.apply(request) + current.parked = True + assert owner.apply(request) + assert not owner.apply(request) + prefs = VehicleStartupPreferences.read(params, enabled=True) + cp = prefs.prepare(current.cp) + assert configured(cp) + cp.alternativeExperience = 0 # Card resets this before finalizing startup preferences. + prefs.finalize(cp) + assert configured(cp) + + params.put_bool('SafeMode', True, block=True) + VehicleStartupPreferences.read(params, enabled=True).finalize(cp) + assert not configured(cp) + fp = gen_empty_fingerprint() + fp[0][0x3F6] = 8 + current.cp = CarInterface.get_params(CAR.TOYOTA_PRIUS_TSS2, fp, fw, False, False, False) + assert not rows() + assert not configured(prefs.prepare(current.cp)) diff --git a/openpilot/starpilot/ui/vehicle_bool.py b/openpilot/starpilot/ui/vehicle_bool.py index 7a91053f6b..bbde7ad468 100644 --- a/openpilot/starpilot/ui/vehicle_bool.py +++ b/openpilot/starpilot/ui/vehicle_bool.py @@ -3,7 +3,7 @@ from openpilot.starpilot.car.volkswagen.preferences import MUTE_CLUSTER_TAKEOVER VEHICLE_BOOL_KEYS = frozenset((MUTE_CLUSTER_TAKEOVER, "AlphaLongitudinalEnabled", "SubaruAvhStartup", "SubaruStopStartOff", "SubaruSNG", - "SubaruRedneckCruise", "RedneckCruise", + "SubaruRedneckCruise", "RedneckCruise", "ToyotaEnhancedBsm", "GMPedalLongitudinal", "DisableOpenpilotLongitudinal", "LongPitch", "VoltSNG", "SNGHack", "GMAutoHold", "VoltOnePedalMode", "TeslaCoopSteering", "TeslaAOLDisengageOnBrake", "TeslaSpeedSync", "RemoteStartBootsComma", "HKGRemoteStartBootsComma", "IgnoreIgnitionLine", "TeslaWakeOnCAN")) @@ -38,6 +38,8 @@ def confirmation_question(request): return f"{verb} Redneck Cruise after the next startup? Factory cruise keeps control of the pedals." if request.key == "SubaruRedneckCruise": return f"{verb} software cruise after the next startup? Stock ACC keeps pedal control." + if request.key == "ToyotaEnhancedBsm": + return f"{verb} Enhanced Blind Spot Monitoring after the next startup?" if request.key == "SNGHack": return f"{verb} Toyota stop-and-go assistance after the next startup?" if request.key == "VoltSNG": diff --git a/openpilot/starpilot/vehicle_preferences.py b/openpilot/starpilot/vehicle_preferences.py index 9eaa8760c4..6cafb83c62 100644 --- a/openpilot/starpilot/vehicle_preferences.py +++ b/openpilot/starpilot/vehicle_preferences.py @@ -32,6 +32,7 @@ def toyota_disable_long_supported(cp) -> bool: class VehicleStartupPreferences: controller_selection: bytes | None = field(default=None, kw_only=True) toyota_auto_hold: bool = False + toyota_enhanced_bsm: bool = field(default=False, kw_only=True) toyota_sng: bool = field(default=False, kw_only=True) jeep_brake_hold: bool = field(default=False, kw_only=True) turn_assist: bool = False @@ -141,6 +142,8 @@ class VehicleStartupPreferences: read_saved(params, "SubaruRedneckCruise", 8) == (b"1", True)), ford_bluepilot=tuple(ford_bluepilot(params, enabled=enabled).items()), tesla_aol=tesla_aol, tesla_screen=screen, tesla_screen_brake=screen_brake, tesla_cooperative=cooperative, tesla_speed_sync=speed_sync, toyota_auto_hold=toyota, + toyota_enhanced_bsm=bool(enabled and readable and safe in (None, b"0") and + read_saved(params, "ToyotaEnhancedBsm", 8) == (b"1", True)), toyota_sng=bool(enabled and readable and safe in (None, b"0") and read_saved(params, "SNGHack", 8) == (b"1", True)), jeep_brake_hold=jeep_hold, gm_longitudinal_tune=selected_tune(params, enabled=enabled), @@ -255,6 +258,8 @@ class VehicleStartupPreferences: apply_toyota_auto_hold(cp, self.toyota_auto_hold) from opendbc.car.toyota.ars510_preferences import configure_radar configure_radar(cp) + from opendbc.car.toyota import enhanced_bsm + enhanced_bsm.prepare(cp, self.toyota_enhanced_bsm) from opendbc.bluepilot_lateral.hosts.starpilot.safety_param import init_ford_safety_param_starpilot init_ford_safety_param_starpilot(cp, dict(self.ford_bluepilot)) from openpilot.starpilot.lateral.controller_selection import prepare_controller @@ -305,6 +310,8 @@ class VehicleStartupPreferences: apply_toyota_auto_hold(cp, self.toyota_auto_hold and admitted) from opendbc.car.toyota.ars510_preferences import configure_radar configure_radar(cp) + from opendbc.car.toyota import enhanced_bsm + enhanced_bsm.prepare(cp, self.toyota_enhanced_bsm) prepare_smoothing(cp, self.subaru_smoothing) diff --git a/panda/board/obj/body_h7.bin.signed b/panda/board/obj/body_h7.bin.signed index 21f512542b..deb35889d9 100644 Binary files a/panda/board/obj/body_h7.bin.signed and b/panda/board/obj/body_h7.bin.signed differ diff --git a/panda/board/obj/bootstub.body_h7.bin b/panda/board/obj/bootstub.body_h7.bin index 3441c1aea9..e6a5b67db5 100644 Binary files a/panda/board/obj/bootstub.body_h7.bin and b/panda/board/obj/bootstub.body_h7.bin differ diff --git a/panda/board/obj/bootstub.panda.bin b/panda/board/obj/bootstub.panda.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda.bin and b/panda/board/obj/bootstub.panda.bin differ diff --git a/panda/board/obj/bootstub.panda_can_ignition_only.bin b/panda/board/obj/bootstub.panda_can_ignition_only.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7.bin b/panda/board/obj/bootstub.panda_h7.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7.bin and b/panda/board/obj/bootstub.panda_h7.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_hkg_remote.bin b/panda/board/obj/bootstub.panda_h7_hkg_remote.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_hkg_remote.bin and b/panda/board/obj/bootstub.panda_h7_hkg_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_remote.bin b/panda/board/obj/bootstub.panda_h7_remote.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_remote.bin and b/panda/board/obj/bootstub.panda_h7_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_tesla_wake.bin b/panda/board/obj/bootstub.panda_h7_tesla_wake.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_tesla_wake.bin and b/panda/board/obj/bootstub.panda_h7_tesla_wake.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin index 9631e703e5..cb4d408b52 100644 Binary files a/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_hkg_remote.bin b/panda/board/obj/bootstub.panda_hkg_remote.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_hkg_remote.bin and b/panda/board/obj/bootstub.panda_hkg_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_remote.bin b/panda/board/obj/bootstub.panda_remote.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_remote.bin and b/panda/board/obj/bootstub.panda_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_tesla_wake.bin b/panda/board/obj/bootstub.panda_tesla_wake.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_tesla_wake.bin and b/panda/board/obj/bootstub.panda_tesla_wake.bin differ diff --git a/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin b/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin index f50567cf4f..6f1098a1e5 100644 Binary files a/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin differ diff --git a/panda/board/obj/gitversion.h b/panda/board/obj/gitversion.h index 13de5dce49..f140660cea 100644 --- a/panda/board/obj/gitversion.h +++ b/panda/board/obj/gitversion.h @@ -1,4 +1,4 @@ #pragma once extern const uint8_t gitversion[29]; -const uint8_t gitversion[29] = "DEV-650530d8-Pf38f504f-DEBUG"; +const uint8_t gitversion[29] = "DEV-016dafc5-Pf38f504f-DEBUG"; diff --git a/panda/board/obj/panda.bin.signed b/panda/board/obj/panda.bin.signed index 6144cfaab2..0d355b49a3 100644 Binary files a/panda/board/obj/panda.bin.signed and b/panda/board/obj/panda.bin.signed differ diff --git a/panda/board/obj/panda_can_ignition_only.bin.signed b/panda/board/obj/panda_can_ignition_only.bin.signed index a6d6e6505a..1b3e4058f7 100644 Binary files a/panda/board/obj/panda_can_ignition_only.bin.signed and b/panda/board/obj/panda_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7.bin.signed b/panda/board/obj/panda_h7.bin.signed index ef99ba8702..b443036150 100644 Binary files a/panda/board/obj/panda_h7.bin.signed and b/panda/board/obj/panda_h7.bin.signed differ diff --git a/panda/board/obj/panda_h7_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_can_ignition_only.bin.signed index 1386a5b197..990fe10ac9 100644 Binary files a/panda/board/obj/panda_h7_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7_hkg_remote.bin.signed b/panda/board/obj/panda_h7_hkg_remote.bin.signed index a27d7f9424..fec3ea4fa7 100644 Binary files a/panda/board/obj/panda_h7_hkg_remote.bin.signed and b/panda/board/obj/panda_h7_hkg_remote.bin.signed differ diff --git a/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed index 4b9a71d964..7263d58488 100644 Binary files a/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7_remote.bin.signed b/panda/board/obj/panda_h7_remote.bin.signed index f47fd15b1a..457c10c9ab 100644 Binary files a/panda/board/obj/panda_h7_remote.bin.signed and b/panda/board/obj/panda_h7_remote.bin.signed differ diff --git a/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed index 3ef513c260..b190e1868d 100644 Binary files a/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7_tesla_wake.bin.signed b/panda/board/obj/panda_h7_tesla_wake.bin.signed index 252c02f002..aca2826215 100644 Binary files a/panda/board/obj/panda_h7_tesla_wake.bin.signed and b/panda/board/obj/panda_h7_tesla_wake.bin.signed differ diff --git a/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed index fd59616799..cd8cb2aa6b 100644 Binary files a/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_hkg_remote.bin.signed b/panda/board/obj/panda_hkg_remote.bin.signed index 2652a0bd89..10054ee80d 100644 Binary files a/panda/board/obj/panda_hkg_remote.bin.signed and b/panda/board/obj/panda_hkg_remote.bin.signed differ diff --git a/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed index 0be45f0490..845df6c58d 100644 Binary files a/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_remote.bin.signed b/panda/board/obj/panda_remote.bin.signed index ece7d506f2..6dceff6bb7 100644 Binary files a/panda/board/obj/panda_remote.bin.signed and b/panda/board/obj/panda_remote.bin.signed differ diff --git a/panda/board/obj/panda_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_remote_can_ignition_only.bin.signed index a94ca5e258..78524cac5d 100644 Binary files a/panda/board/obj/panda_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_tesla_wake.bin.signed b/panda/board/obj/panda_tesla_wake.bin.signed index de10b7519a..ede97cc46c 100644 Binary files a/panda/board/obj/panda_tesla_wake.bin.signed and b/panda/board/obj/panda_tesla_wake.bin.signed differ diff --git a/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed b/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed index 774e0f7ca9..d430ecbb57 100644 Binary files a/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed and b/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/version b/panda/board/obj/version index 305fac6f9f..468af598fd 100644 --- a/panda/board/obj/version +++ b/panda/board/obj/version @@ -1 +1 @@ -DEV-650530d8-Pf38f504f-DEBUG \ No newline at end of file +DEV-016dafc5-Pf38f504f-DEBUG \ No newline at end of file diff --git a/panda/tests/libpanda/libpanda.so b/panda/tests/libpanda/libpanda.so index 0607b58d73..41c364584c 100755 Binary files a/panda/tests/libpanda/libpanda.so and b/panda/tests/libpanda/libpanda.so differ diff --git a/prebuilt.json b/prebuilt.json index 3ac5c6ee4e..d128b06242 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "920d77cf37e6ad75d17808b4acb53095985438d50a62fd2d07ffb83bdb46bc03", "schema_version": 1} +{"protected_inventory_sha256": "7f4f22ee3423651e042b2406427edf0b75ba076744166eec287a1037b12758d1", "schema_version": 1}