From 330a302aa12e2b58c389c54a30b9e2bec74f4e65 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:46:54 -0600 Subject: [PATCH] Keep stock Prius CAN healthy when the gap button signal is absent --- opendbc_repo/opendbc/car/toyota/carstate.py | 13 ++++++ .../car/toyota/tests/test_prius_gap_button.py | 40 +++++++++++++++++++ prebuilt.json | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 opendbc_repo/opendbc/car/toyota/tests/test_prius_gap_button.py diff --git a/opendbc_repo/opendbc/car/toyota/carstate.py b/opendbc_repo/opendbc/car/toyota/carstate.py index 653f7c954c..f0f09764d3 100644 --- a/opendbc_repo/opendbc/car/toyota/carstate.py +++ b/opendbc_repo/opendbc/car/toyota/carstate.py @@ -31,6 +31,11 @@ TEMP_STEER_FAULTS = (0, 9, 11, 21, 25) PERM_STEER_FAULTS = (3, 17) +def has_optional_prius_gap_button(CP): + return (CP.carFingerprint == CAR.TOYOTA_PRIUS and not CP.openpilotLongitudinalControl and + not CP.flags & (ToyotaFlags.LONG_FILTER | ToyotaFlags.FILTER_BUTTONS)) + + class CarState(CarStateBase): def __init__(self, CP): super().__init__(CP) @@ -266,6 +271,10 @@ class CarState(CarStateBase): if self.CP.flags & ToyotaFlags.FILTER_BUTTONS or advert_filter.configured(self.CP) or prius_advert_filter.configured(self.CP): fresh = cp.advert_button_ns > 0 and 0 <= cp._last_update_nanos - cp.advert_button_ns <= 200_000_000 self.distance_button = cp.advert_distance_button if fresh else 0 + elif not bypass and has_optional_prius_gap_button(self.CP): + self.distance_button = cp_acc.vl["ACC_CONTROL"]["DISTANCE"] + # A live gesture needs its source until the physical release arrives. + cp_acc.message_states[0x343].ignore_alive = not self.distance_button else: self.distance_button = (cp.vl["SDSU"]["FD_BUTTON"] if self.CP.flags & ToyotaFlags.LONG_FILTER else cp_acc.vl["ACC_CONTROL"]["DISTANCE"]) @@ -361,6 +370,10 @@ class CarState(CarStateBase): ("BLINKERS_STATE", float('nan')), ] + if has_optional_prius_gap_button(CP): + # Factory cruise state and AEB are received on separate messages. + pt_messages.append(("ACC_CONTROL", math.nan)) + if CP.carFingerprint == CAR.TOYOTA_SIENNA_4TH_GEN: pt_messages.append(("PCM_CRUISE_4", 1)) from opendbc.car.toyota import camera_2aa_filter diff --git a/opendbc_repo/opendbc/car/toyota/tests/test_prius_gap_button.py b/opendbc_repo/opendbc/car/toyota/tests/test_prius_gap_button.py new file mode 100644 index 0000000000..95da8bb249 --- /dev/null +++ b/opendbc_repo/opendbc/car/toyota/tests/test_prius_gap_button.py @@ -0,0 +1,40 @@ +import pytest + +from opendbc.can import CANPacker +from opendbc.car import Bus, gen_empty_fingerprint, structs +from opendbc.car.toyota.carstate import CarState +from opendbc.car.toyota.interface import CarInterface +from opendbc.car.toyota.values import CAR, DBC + + +@pytest.mark.parametrize('stock_aol', (True, False)) +def test_prius_gap_button_requires_the_source_only_during_a_press(stock_aol): + fp = gen_empty_fingerprint() + if not stock_aol: + fp[2][0x343] = 8 + cp = CarInterface.get_params(CAR.TOYOTA_PRIUS, fp, [], False, False, False) + assert not cp.openpilotLongitudinalControl + assert cp.safetyConfigs[0].safetyParam == (0x6242 if stock_aol else 0x242) + state = CarState(cp) + parsers = state.get_can_parsers(cp) + packer = CANPacker(DBC[CAR.TOYOTA_PRIUS][Bus.pt]) + gap = structs.CarState.ButtonEvent.Type.gapAdjustCruise + + def edges(stamp, value=None): + frames = [] if value is None else [packer.make_can_msg('ACC_CONTROL', 0, {'DISTANCE': value})] + for parser in parsers.values(): + parser.update([(stamp, frames)]) + return [event.pressed for event in state.update(parsers).buttonEvents if event.type == gap] + + assert edges(1_000_000_000) == [] + assert parsers[Bus.pt].message_states[0x343].ignore_alive + assert not parsers[Bus.pt].message_states[0x1D3].ignore_alive + assert not parsers[Bus.pt].message_states[0x262].ignore_alive + assert edges(1_030_000_000, 1) == [True] + gap_message = parsers[Bus.pt].message_states[0x343] + assert not gap_message.ignore_alive + assert edges(12_000_000_000) == [] + assert not gap_message.valid(12_000_000_000, False) + assert edges(12_030_000_000, 0) == [False] + assert gap_message.ignore_alive + assert gap_message.valid(23_000_000_000, False) diff --git a/prebuilt.json b/prebuilt.json index 519e9d4b31..ad8b6f8f5f 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "09b729de9501ffc15793faf5303aa809658f1b7b4b380eaf201a40387823cf90", "schema_version": 1} +{"protected_inventory_sha256": "4e859e4ded50f18e1399226be9d8928b477c119b2d35607934a97495b690adb5", "schema_version": 1}