Keep stock Prius CAN healthy when the gap button signal is absent

This commit is contained in:
firestar5683
2026-11-23 21:46:54 -06:00
parent 6e879b55da
commit 330a302aa1
3 changed files with 54 additions and 1 deletions
@@ -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
@@ -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)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "09b729de9501ffc15793faf5303aa809658f1b7b4b380eaf201a40387823cf90", "schema_version": 1}
{"protected_inventory_sha256": "4e859e4ded50f18e1399226be9d8928b477c119b2d35607934a97495b690adb5", "schema_version": 1}