Reuse accessory checks and CAN validation

This commit is contained in:
firestar5683
2026-11-29 22:43:13 -06:00
parent 6dcd7aada2
commit dfaf5ea134
14 changed files with 137 additions and 93 deletions
+8 -7
View File
@@ -315,13 +315,14 @@ class CarState(CarStateBase):
pt_cp.ts_nanos["AcceleratorPedal2"]["AcceleratorPedal2"],
pt_cp.ts_nanos["ECMEngineStatus"]["CruiseMainOn"],
pt_cp.ts_nanos["EBCMRegenPaddle"]["RegenPaddle"])
control_word = gm_control_word(self.CP)
if is_volt_longitudinal(self.CP):
# Observe only actual resume/driver sources, using the finalized brake owner.
alternate = is_volt_gateway_alternate_brake(self.CP) or (
volt_camera_removed and bool(self.CP.flags & GMFlags.NO_ACCELERATOR_POS_MSG))
c9 = self.CP.networkLocation == NetworkLocation.fwdCamera and not (
gm_control_word(self.CP) & (GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM) and
not gm_control_word(self.CP) & GMSafetyFlags.BRAKE_C9)
control_word & (GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM) and
not control_word & GMSafetyFlags.BRAKE_C9)
brake = (("EBCMBrakePedalPosition", "BrakePedalPosition") if alternate else
("ECMEngineStatus", "BrakePressed") if c9 else ("ECMAcceleratorPos", "BrakePedalPos"))
names = (("AcceleratorPedal2", "CruiseState", 100_000_000),
@@ -342,8 +343,8 @@ class CarState(CarStateBase):
self.camera_pedal_profile is not None and self.camera_pedal_profile.volt and
self.camera_pedal_profile.brake_source == BrakeSource.F1)
c9 = self.CP.networkLocation == NetworkLocation.fwdCamera and (
not gm_control_word(self.CP) & (GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM) or
bool(gm_control_word(self.CP) & GMSafetyFlags.BRAKE_C9))
not control_word & (GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM) or
bool(control_word & GMSafetyFlags.BRAKE_C9))
brake_name, brake_signal = (("EBCMBrakePedalPosition", "BrakePedalPosition") if alternate else
("ECMEngineStatus", "BrakePressed") if c9 else ("ECMAcceleratorPos", "BrakePedalPos"))
names = (("ECMEngineStatus", "CruiseMainOn"), ("ECMPRDNL2", "PRNDL2"), (brake_name, brake_signal),
@@ -357,7 +358,7 @@ class CarState(CarStateBase):
if self.camera_pedal_profile is not None and self.camera_pedal_profile.volt:
self.gm_auto_hold_sources += ((pt_cp.ts_nanos["GAS_SENSOR"]["COUNTER_PEDAL"], 100_000_000),)
# C9 is pressed authority, never analog force; missing-BE profiles retain minimum hold.
absent_be = c9 and bool(gm_control_word(self.CP) & (GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM))
absent_be = c9 and bool(control_word & (GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM))
if alternate_force:
self.gm_auto_hold_brake = pt_cp.vl["EBCMBrakePedalPosition"]["BrakePedalPosition"] / 208.
if c9:
@@ -426,9 +427,9 @@ class CarState(CarStateBase):
else:
ret.gearShifter = self.parse_gear_shifter(self.shifter_values.get(gear["PRNDL2"], None))
source_be_brake = (gm_control_word(self.CP) &
source_be_brake = (control_word &
(GMSafetyFlags.ASCM_INTERCEPT | GMSafetyFlags.SDGM).value and
not gm_control_word(self.CP) & GMSafetyFlags.BRAKE_C9.value)
not control_word & GMSafetyFlags.BRAKE_C9.value)
if is_volt_cc_f1_profile(self.CP):
ret.brakePressed = (pt_cp.vl["EBCMBrakePedalPosition"]["BrakePedalPosition"] >= 6 or
pt_cp.vl["ECMEngineStatus"]["BrakePressed"] != 0)
@@ -7,6 +7,7 @@ from opendbc.car.gm.values import (GMFlags, camera_acc_pedal_profile, is_volt_as
EPS_STATUS_TIMEOUT_NS = 300_000_000
STEERING_COMMAND_TIMEOUT_NS = 100_000_000
ButtonType = structs.CarState.ButtonEvent.Type
STEERING_SOURCE_LENGTHS = {0xC9: 8, 0xBE: 6, 0xBD: 7, 0x1E1: 7}
@cached_config
@@ -42,24 +43,30 @@ class SteeringAuthority:
if not self.enabled:
return
self.source_ns.clear()
malformed = any(bus == 0 and address == 0x184 and (stamp <= 0 or len(data) != 8)
for stamp, packets in can_packets for address, data, bus in packets)
lengths = {0xC9: 8, 0xBE: 6, 0xBD: 7, 0x1E1: 7}
invalid = {address for stamp, packets in can_packets for address, data, bus in packets
if bus == 0 and address in lengths and (stamp <= 0 or len(data) != lengths[address])}
for address in invalid:
self.source_ns.pop(address, None)
malformed_status = False
previous_status_ns = self.status_ns
invalid_sources = set()
for stamp, packets in can_packets:
for address, data, bus in packets:
if bus != 0 or stamp <= 0:
if bus != 0:
continue
if address in lengths and address not in invalid:
self.source_ns[address] = max(stamp, self.source_ns.get(address, 0))
if address == 0x184 and stamp > self.status_ns:
if self.active_since_ns and stamp - max(self.status_ns, self.active_since_ns) > EPS_STATUS_TIMEOUT_NS:
self.latched = True
self.status_ns = stamp
self.status = -1 if malformed else (data[0] >> 3) & 7
if address == 0x184:
valid = stamp > 0 and len(data) == 8
malformed_status |= not valid
if stamp > self.status_ns and stamp > 0:
if self.active_since_ns and stamp - max(self.status_ns, self.active_since_ns) > EPS_STATUS_TIMEOUT_NS:
self.latched = True
self.status_ns = stamp
self.status = (data[0] >> 3) & 7 if valid else -1
elif (length := STEERING_SOURCE_LENGTHS.get(address)) is not None:
if stamp > 0 and len(data) == length:
self.source_ns[address] = max(stamp, self.source_ns.get(address, 0))
else:
invalid_sources.add(address)
for address in invalid_sources:
self.source_ns.pop(address, None)
if malformed_status and self.status_ns > previous_status_ns:
self.status = -1
def command(self, now_ns: int, active: bool):
if not self.enabled:
@@ -42,3 +42,19 @@ def test_sdgm_refusal_requires_physical_disable_neutral_and_fresh_rearm(monkeypa
# Reuse the full original parser/controller physical sequence for this exact factory CP.
monkeypatch.setattr(ascm_fixture, "params", lambda *args, **kwargs: sdgm_params(brake_c9=c9, radar=True))
ascm_fixture.TestAscmIntercept(methodName="runTest").test_volt_steering_loss_requires_driver_rearm()
@pytest.mark.parametrize('bad_first', [True, False])
def test_sdgm_mixed_valid_and_malformed_batch_withdraws_source_credit(bad_first):
authority = CarInterface(sdgm_params(alpha=True)).CS.steering_authority
first_ns, second_ns = 1_000_000_000, 1_010_000_000
valid = [(0x184, bytes((8,)) + bytes(7), 0), (0xC9, bytes(8), 0), (0xBE, bytes(6), 0)]
malformed = [(0x184, b'', 0), (0xC9, bytes(7), 0), (0xBE, b'', 128)]
first, second = (malformed, valid) if bad_first else (valid, malformed)
authority.observe([(first_ns, first), (second_ns, second)])
assert authority.status_ns == second_ns
assert authority.status == -1
assert authority.source_ns == {0xBE: second_ns if bad_first else first_ns}
authority.observe([(second_ns + 1, valid)])
assert authority.status == 1
assert authority.source_ns == {0xC9: second_ns + 1, 0xBE: second_ns + 1}
@@ -130,11 +130,15 @@ class AdvertFilterCANParser(CANParser):
self.advert_distance_button = 0
self.advert_button_ns = 0
def update(self, strings, sendcan=False):
def _update_filtered(self, strings, sendcan, accept_accessory=None, *, physical_only=False):
batches = []
for stamp, frames in strings:
accepted = []
for address, data, bus in frames:
if physical_only and bus >= 128:
continue
if accept_accessory is not None and address in (0x201, 0x2AA, 0x2FF) and not accept_accessory(address, data, bus):
continue
if bus == self.bus:
if address in (0x1D3, 0x262):
valid = len(data) == 8 and data[-1] == toyota_checksum(address, None, bytearray(data))
@@ -152,3 +156,6 @@ class AdvertFilterCANParser(CANParser):
accepted.append((address, data, bus))
batches.append((stamp, accepted))
return super().update(batches, sendcan)
def update(self, strings, sendcan=False):
return self._update_filtered(strings, sendcan)
@@ -93,24 +93,18 @@ class CameraTwoAACANParser(AdvertFilterCANParser):
super().__init__(*args)
self.hardware_ambiguous = False
def _accept_accessory(self, address, data, bus):
if address in (0x201, 0x2FF):
self.hardware_ambiguous = True
return False
if address == 0x2AA:
self.hardware_ambiguous |= bus not in (0, 2) or len(data) != 8
return False
return True
def update(self, strings, sendcan=False):
batches = []
for stamp, frames in strings:
accepted = []
for address, data, bus in frames:
# pandad marks TX confirmations/rejections with bus >= 128; they
# are not received hardware (see panda.h CAN_*_BUS_OFFSET).
if bus >= 128:
continue
if address in (0x201, 0x2FF):
self.hardware_ambiguous = True
continue
if address == 0x2AA:
self.hardware_ambiguous |= bus not in (0, 2) or len(data) != 8
continue
accepted.append((address, data, bus))
batches.append((stamp, accepted))
result = super().update(batches, sendcan)
# Buses >= 128 carry Panda TX receipts, not physical RX.
result = self._update_filtered(strings, sendcan, self._accept_accessory, physical_only=True)
if self.hardware_ambiguous:
self.main_valid = self.eps_valid = False
return result
@@ -152,7 +152,8 @@ class CarController(CarControllerBase):
def update(self, CC, CS, now_nanos):
from opendbc.car.toyota import dsu_bypass
bypass_long = dsu_bypass.enabled(self.CP)
bypass_owner = dsu_bypass.configured(self.CP)
bypass_long = bypass_owner and self.CP.openpilotLongitudinalControl
_projection = self.learning_projection_observer
if _projection is not None:
_projection.begin(CC.actuators.torque, self.frame)
@@ -190,10 +191,6 @@ class CarController(CarControllerBase):
CS.out.canValid and not CS.out.canTimeout and CS.out.cruiseState.available and not CS.out.accFaulted and
not CS.out.stockAeb and not CS.out.steerFaultTemporary and not CS.out.steerFaultPermanent and not CS.out.doorOpen and
not CS.out.seatbeltUnlatched and CS.out.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.sport))
if pedal_owner:
hold_source_ready = hold_source_ready and bool(self.pedal_input is not None and self.pedal_input.update(now_nanos) and CS.pedal_ready)
if bypass_long:
hold_source_ready = hold_source_ready and bool(self.bypass_input is not None and self.bypass_input.update(now_nanos))
composite_pedal = pedal_composite.configured(self.CP)
if composite_pedal:
filter_allowed = filter_allowed and bool(
@@ -202,11 +199,16 @@ class CarController(CarControllerBase):
(not CS.out.brakePressed or CS.out.standstill) and
CS.out.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.sport))
if pedal_owner:
filter_allowed = filter_allowed and bool(self.pedal_input is not None and self.pedal_input.update(now_nanos) and CS.pedal_ready)
pedal_ready = bool((hold_source_ready or filter_allowed) and self.pedal_input is not None and
self.pedal_input.update(now_nanos) and CS.pedal_ready)
hold_source_ready = hold_source_ready and pedal_ready
filter_allowed = filter_allowed and pedal_ready
if bypass_long:
preference = getattr(self, 'bypass_input', None)
filter_allowed = filter_allowed and bool(
preference is not None and preference.update(now_nanos) and CS.out.canValid and not CS.out.canTimeout and
bypass_ready = bool((hold_source_ready or filter_allowed) and preference is not None and preference.update(now_nanos))
hold_source_ready = hold_source_ready and bypass_ready
filter_allowed = filter_allowed and bypass_ready and bool(
CS.out.canValid and not CS.out.canTimeout and
CS.out.cruiseState.available and not CS.out.accFaulted and not CS.out.stockAeb and
not CS.out.steerFaultTemporary and not CS.out.steerFaultPermanent and not CS.out.doorOpen and
not CS.out.seatbeltUnlatched and (not CS.out.brakePressed or CS.out.standstill) and
@@ -223,7 +225,7 @@ class CarController(CarControllerBase):
if (bypass_long or rav4h_long or pedal_owner or advert_long or original_prius_long) and not filter_allowed and CS.out.cruiseState.enabled:
pcm_cancel_cmd = True
lat_active = CC.latActive and abs(CS.out.steeringTorque) < MAX_USER_TORQUE
if dsu_bypass.configured(self.CP):
if bypass_owner:
lat_active = lat_active and CS.out.canValid and not CS.out.canTimeout and CS.out.cruiseState.available and not (
CS.out.steerFaultTemporary or CS.out.steerFaultPermanent or CS.out.doorOpen)
if self.original_prius_filter:
@@ -376,7 +378,7 @@ class CarController(CarControllerBase):
if (bypass_long or rav4h_long or pedal_owner or advert_long or original_prius_long) and (not filter_allowed or not long_active and CS.out.standstill):
self.standstill_req = True
if pedal_owner and (self.CP.carFingerprint in pedal.RADAR_PEDAL_CARS or pedal_composite.configured(self.CP)) and not long_active:
if pedal_owner and (self.CP.carFingerprint in pedal.RADAR_PEDAL_CARS or composite_pedal) and not long_active:
# A radar-disable safety handoff starts with fresh native RX checks.
# Neutral output must not request release before LONG is admitted.
self.standstill_req = True
+11 -8
View File
@@ -87,6 +87,9 @@ class CarState(CarStateBase):
ret = structs.CarState()
bypass = dsu_bypass.configured(self.CP)
advert_owner = advert_filter.configured(self.CP)
pedal_owner = pedal.configured(self.CP)
composite_pedal = pedal_owner and pedal_composite.configured(self.CP)
cp_acc = cp_cam if bypass or (self.CP.flags & ToyotaFlags.TSS2) and not (self.CP.flags & ToyotaFlags.RADAR_ACC) else cp
if not self.CP.flags & ToyotaFlags.SECOC.value:
@@ -153,7 +156,7 @@ class CarState(CarStateBase):
ret.steerFaultTemporary = cp.vl["EPS_STATUS"]["LKA_STATE"] in TEMP_STEER_FAULTS
ret.steerFaultPermanent = cp.vl["EPS_STATUS"]["LKA_STATE"] in PERM_STEER_FAULTS
if advert_filter.configured(self.CP):
if advert_owner:
stamp, expiry = parser_expiry(cp, 'EPS_STATUS', 'LKA_STATE')
expiry = min(expiry, stamp + 400_000_000)
ret.steerFaultTemporary |= not (cp.eps_valid and stamp > 0 and stamp <= cp._last_update_nanos <= expiry)
@@ -180,7 +183,7 @@ class CarState(CarStateBase):
ret.accFaulted = cp.vl["PCM_CRUISE_2"]["ACC_FAULTED"] != 0
ret.carFaultedNonCritical = cp.vl["PCM_CRUISE_SM"]["TEMP_ACC_FAULTED"] != 0
ret.cruiseState.available = cp.vl["PCM_CRUISE_2"]["MAIN_ON"] != 0
if (pedal.configured(self.CP) and not pedal_composite.configured(self.CP)) or advert_filter.configured(self.CP):
if (pedal_owner and not composite_pedal) or advert_owner:
stamp = cp.ts_nanos["PCM_CRUISE_2"]["MAIN_ON"]
ret.cruiseState.available &= bool(cp.main_valid and stamp > 0 and 0 <= cp._last_update_nanos - stamp <= 303_031_000)
ret.cruiseState.speed = cp.vl["PCM_CRUISE_2"]["SET_SPEED"] * CV.KPH_TO_MS
@@ -266,7 +269,7 @@ class CarState(CarStateBase):
buttonEvents.extend(create_button_events(1, 0, {1: ButtonType.lkas}) +
create_button_events(0, 1, {1: ButtonType.lkas}))
if (self.CP.flags & ToyotaFlags.TSS2 and not advert_filter.configured(self.CP) and
if (self.CP.flags & ToyotaFlags.TSS2 and not advert_owner and
not (self.CP.flags & (ToyotaFlags.RADAR_ACC | ToyotaFlags.SECOC | ToyotaFlags.LONG_FILTER))):
# distance button is wired to the ACC module (camera or radar)
prev_distance_button = self.distance_button
@@ -275,9 +278,9 @@ class CarState(CarStateBase):
buttonEvents += create_button_events(self.distance_button, prev_distance_button, {1: ButtonType.gapAdjustCruise})
if (self.CP.carFingerprint in (CAR.TOYOTA_PRIUS, CAR.TOYOTA_PRIUS_RETROFIT) or
self.CP.flags & (ToyotaFlags.LONG_FILTER | ToyotaFlags.FILTER_BUTTONS) or advert_filter.configured(self.CP)):
self.CP.flags & (ToyotaFlags.LONG_FILTER | ToyotaFlags.FILTER_BUTTONS) or advert_owner):
prev_distance_button = self.distance_button
if self.CP.flags & ToyotaFlags.FILTER_BUTTONS or advert_filter.configured(self.CP) or prius_advert_filter.configured(self.CP):
if self.CP.flags & ToyotaFlags.FILTER_BUTTONS or advert_owner 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):
@@ -338,12 +341,12 @@ class CarState(CarStateBase):
ret.steerFaultTemporary |= not (cp.eps_valid and eps_stamp > 0 and
0 <= cp._last_update_nanos - eps_stamp <= 400_000_000)
if pedal.configured(self.CP):
cp_pedal = can_parsers[Bus.alt] if pedal_composite.configured(self.CP) else cp
if pedal_owner:
cp_pedal = can_parsers[Bus.alt] if composite_pedal else cp
stamp = cp_pedal.ts_nanos.get("GAS_SENSOR", {}).get("STATE", 0)
self.pedal_ready = bool(cp_pedal.pedal_valid and stamp > 0 and 0 <= cp_pedal._last_update_nanos - stamp <= 200_000_000)
pedal_gas = (cp_pedal.vl['GAS_SENSOR']['INTERCEPTOR_GAS'] + cp_pedal.vl['GAS_SENSOR']['INTERCEPTOR_GAS2']) / 2 > 805
ret.gasPressed = (ret.gasPressed or pedal_gas) if pedal_composite.configured(self.CP) else pedal_gas
ret.gasPressed = (ret.gasPressed or pedal_gas) if composite_pedal else pedal_gas
ret.accFaulted = ret.accFaulted or not self.pedal_ready
ret.buttonEvents = buttonEvents
timestamp, expiry = parser_expiry(cp_cam, "RSA1", "TSGN1")
@@ -83,16 +83,11 @@ class PriusAdvertCANParser(AdvertFilterCANParser):
super().__init__(*args)
self.hardware_ambiguous = False
def _accept_accessory(self, address, data, bus):
# Buses >= 128 carry Panda TX receipts, not physical RX.
if bus < 128 and (address in (0x201, 0x2AA) or address == 0x2FF and (bus not in (0, 2) or len(data) != 4)):
self.hardware_ambiguous = True
return True
def update(self, strings, sendcan=False):
batches = []
for stamp, frames in strings:
frames = list(frames)
for address, data, bus in frames:
# pandad marks TX confirmations/rejections with bus >= 128; they
# are not received hardware (see panda.h CAN_*_BUS_OFFSET).
if bus >= 128:
continue
if address in (0x201, 0x2AA) or address == 0x2FF and (bus not in (0, 2) or len(data) != 4):
self.hardware_ambiguous = True
batches.append((stamp, frames))
return super().update(batches, sendcan)
return self._update_filtered(strings, sendcan, self._accept_accessory)
@@ -1,7 +1,7 @@
"""Original EPS66 Prius smartDSU ownership; the EPS73 retrofit remains distinct."""
from opendbc.can import CANParser
from opendbc.car import structs
from opendbc.car.dashboard_speed_limit import parser_expiry
from opendbc.car.toyota.rav4h_filter import Rav4hCANParser
from opendbc.car.toyota.toyotacan import toyota_checksum
from opendbc.car.toyota.values import CAR, ToyotaFlags
@@ -75,7 +75,7 @@ def source_current(parser, message, signal):
return bound > 0 and stamp > 0 and stamp <= parser._last_update_nanos <= expiry
class PriusSDSUCANParser(Rav4hCANParser):
class PriusSDSUCANParser(CANParser):
"""Keep independent status, MAIN/EPS quality and receiver identity evidence."""
def __init__(self, *args):
super().__init__(*args)
@@ -93,6 +93,8 @@ class PriusSDSUCANParser(Rav4hCANParser):
continue
if address in (0x201, 0x2AA) or address == 0x2FF and (bus not in (0, 2) or len(data) == 4):
self.hardware_ambiguous = True
if bus == self.bus and address == 0x2FF and len(data) != 8:
continue
if bus == self.bus and address in (0x1D3, 0x262):
valid = len(data) == 8 and data[-1] == toyota_checksum(address, None, bytearray(data))
if address == 0x1D3:
+20 -8
View File
@@ -107,6 +107,9 @@ class SelfdriveD:
cloudlog.info("selfdrived got CarParams")
else:
self.CP = CP
# The Params reader owns its immutable bytes. Injected CarParams can change.
self._startup_cp = self.CP if CP is None else None
self._startup_cp_identity = cp_identity(self.CP) if self._startup_cp is not None else None
self.aol_replay = feature_enabled(self.params, self.CP, 'aol', os.environ)
self.ordinary_axis_ack_required = axis_policy_for(self.CP).ordinary_axis_ack_required
@@ -124,8 +127,11 @@ class SelfdriveD:
self.aol_transport_pause = TransportPause(self.CP, self.aol_session_id)
self.aol_fault_reason = 'none'
self.steering_authority_unavailable = False
from openpilot.starpilot.car.gm.aol import steering_raw_projection_owner
self._startup_steering_monitored = self.CP.brand == 'gm' and monitored_profile(self.CP)
self._startup_raw_projection = steering_raw_projection_owner(self.CP, monitored=self._startup_steering_monitored)
self.steering_companion = (SteeringCompanion(messaging.sub_sock('starpilotCarState', conflate=False))
if monitored_profile(self.CP) else None)
if self._startup_steering_monitored else None)
self.force_stop_hold_alert = HoldAlertState()
self.aol_car_state_log_ns = 0
self.aol_last_intent = None
@@ -293,7 +299,8 @@ class SelfdriveD:
return update_big_model_status(self)
def _update_steering_authority(self, CS):
if self.CP.brand != 'gm' or not monitored_profile(self.CP):
fixed_cp = self.CP is getattr(self, '_startup_cp', None)
if self.CP.brand != 'gm' or not (self._startup_steering_monitored if fixed_cp else monitored_profile(self.CP)):
self.steering_authority_unavailable = False
return
companion = getattr(self, 'steering_companion', None)
@@ -307,15 +314,17 @@ class SelfdriveD:
source_current = bool(getattr(self, 'conditional_car_state_valid', False) and CS.canValid and not CS.canTimeout and
0 < source_ns <= now_ns and now_ns - source_ns <= INTENT_MAX_AGE_NS)
from openpilot.starpilot.car.gm.aol import steering_raw_projection_owner, steering_source_gap_intent_only
raw_projection = drained and (self._startup_raw_projection if fixed_cp else
steering_raw_projection_owner(self.CP, monitored=True))
pair = companion.current(self.sm, source_ns=source_ns, now_ns=now_ns, drain=False,
allow_raw_projection=steering_raw_projection_owner(self.CP)) if drained else None
allow_raw_projection=raw_projection) if drained else None
if not source_current:
pair = None
previous_axes = self.aol_axis_decision
expected_active = self.active or previous_axes.lateral_active or previous_axes.longitudinal_active
if pair is not None:
self.steering_authority_unavailable = pair
elif expected_active and not (drained and steering_source_gap_intent_only(self, CS, companion, now_ns)):
elif expected_active and not (drained and steering_source_gap_intent_only(self, CS, companion, now_ns, raw_projection=raw_projection)):
self.steering_authority_unavailable = True
if getattr(self, 'steering_authority_unavailable', False):
self.events.add(EventName.controlsMismatch)
@@ -2327,15 +2336,18 @@ class SelfdriveD:
not self.events.contains(ET.OVERRIDE_LONGITUDINAL)))
if not hasattr(self, 'aol_transport_pause'):
self.aol_transport_pause = TransportPause(self.CP, self.aol_session_id)
current_cp_identity = (self._startup_cp_identity if self.CP is getattr(self, '_startup_cp', None) else cp_identity(self.CP))
model_ready = bool(self.sm.all_checks(['modelV2', 'extrinsicsCalibration']) and
self.sm['extrinsicsCalibration'].calStatus == log.ExtrinsicsCalibration.Status.calibrated)
pause, upgraded = self.aol_transport_pause.observe(
current_cp_identity=current_cp_identity,
cp=self.CP, session=self.aol_session_id, sm=self.sm, cs=CS, native=native, now_ns=now_ns,
companion=getattr(self, 'aol_intent_companion', None), previous_intent=previous_intent, intent=intent,
expired_healthy_source=getattr(self, 'aol_expired_healthy_source', False),
previously_active=previous.lateral_active, hard_fault=bool(
self.aol_selected_pair_future or self.aol_authority_lost or lost_active_aol or lost_permission or aol_immediate_disable or
any(event.softDisable and event.name not in LONGITUDINAL_ONLY_EVENTS for event in self.events.to_msg())),
model_ready=bool(self.sm.all_checks(['modelV2', 'extrinsicsCalibration']) and
self.sm['extrinsicsCalibration'].calStatus == log.ExtrinsicsCalibration.Status.calibrated),
model_ready=model_ready,
user_disable=self.events.contains(ET.USER_DISABLE))
if source_current:
self.observe_ordinary_source_metadata(CS, intent, self.aol_transport_pause.observed_native, now_ns)
@@ -2355,10 +2367,10 @@ class SelfdriveD:
source_expiry_events.add(EventName.commIssue)
availability_events += source_expiry_events.to_msg()
availability = self.aol_availability_pause.observe(
current_cp_identity=current_cp_identity,
cp=self.CP, session=self.aol_session_id, sm=self.sm, cs=CS, native=native, now_ns=now_ns,
companion=intent_companion, intent=intent if intent is not None else retained_intent, events=availability_events,
model_ready=bool(self.sm.all_checks(['modelV2', 'extrinsicsCalibration']) and
self.sm['extrinsicsCalibration'].calStatus == log.ExtrinsicsCalibration.Status.calibrated),
model_ready=model_ready,
source_current=source_current, source_expired=publication_expiry, prior_lateral_active=previous.lateral_active,
hard_fault=bool(self.aol_selected_pair_future or self.aol_authority_lost or lost_active_aol or
lost_companion and not publication_expiry or lost_permission or upgraded),
+4 -4
View File
@@ -737,7 +737,7 @@ class TransportPauseFeedback:
if reason not in ('none', 'availabilityPause') or reason == 'none' and not availability_only(events):
return False
if not (latched and current and continuity and not self.paused and not self.pending_event and
cp_identity(cp) == self.cp and intent_producer_session and
intent_producer_session and
getattr(axis, 'intentProducerSessionId', '') == intent_producer_session == self.availability_producer and
int(getattr(axis, 'intentIntegrityEpoch', 0)) == self.availability_epoch and
self.session and
@@ -1230,8 +1230,8 @@ class TransportPauseFeedback:
self.retention_pending = not self.retention_qualified
return False
from openpilot.starpilot.car.gm.aol import sdgm_alpha_lateral_owner
if (sdgm_alpha_lateral_owner(cp) and latched and current and continuity and self.signature is not None and
signature[14:16] != self.signature[14:16]):
if (latched and current and continuity and self.signature is not None and
signature[14:16] != self.signature[14:16] and sdgm_alpha_lateral_owner(cp)):
self.failed = True
return True
if ((self.cold_main_wait_ns or self.cold_park_waiting) and current and continuity and self.signature is not None and
@@ -1479,7 +1479,7 @@ class TransportPauseFeedback:
cs.cruiseState.available and not cs.doorOpen and not cs.vehicleSensorsInvalid and not cs.steeringDisengage and
not cs.regenBraking and
sm.seen['aolAxisState'] and sm.valid['aolAxisState'] and sm.alive['aolAxisState'] and
axis.qualified and str(axis.faultSessionId) == self.session and cp_identity(cp) == self.cp and
axis.qualified and str(axis.faultSessionId) == self.session and same_cp and
0 < stamp == axis.observedMonoTime < axis.validUntilMonoTime < now_ns)
brake_native = (self._honda_brake_lateral_current(sm, cp, cs, axis, now_ns,
latched=latched, brake_source_ns=brake_source_ns) if (current or honda_driver_pending) and continuity else None)
@@ -18,10 +18,12 @@ class TransportPause:
self.epoch = None
def observe(self, *, cp, session, sm, cs, native, now_ns, companion, previous_intent,
intent, expired_healthy_source, previously_active, hard_fault, model_ready, user_disable):
intent, expired_healthy_source, previously_active, hard_fault, model_ready, user_disable,
current_cp_identity=None):
from openpilot.starpilot.aol import transport_pause as transport
self.observed_native = None
context_current = bool(transport.cp_identity(cp) == self.cp and session == self.session and model_ready and companion is not None)
identity = transport.cp_identity(cp) if current_cp_identity is None else current_cp_identity
context_current = bool(identity == self.cp and session == self.session and model_ready and companion is not None)
if context_current:
self.observed_native = transport._healthy_transport_native(sm, cp, cs, session, now_ns, native)
if self.observed_native is None and cp.brand == 'ford':
@@ -73,11 +75,13 @@ class AvailabilityPause:
self.active = False
def observe(self, *, cp, session, sm, cs, native, now_ns, companion, intent,
events, model_ready, source_current, prior_lateral_active, hard_fault, healthy_native, source_expired=False):
events, model_ready, source_current, prior_lateral_active, hard_fault, healthy_native, source_expired=False,
current_cp_identity=None):
from openpilot.starpilot.aol import transport_pause as transport
try:
healthy = healthy_native
eligible = bool(transport.cp_identity(cp) == self.cp and
identity = transport.cp_identity(cp) if current_cp_identity is None else current_cp_identity
eligible = bool(identity == self.cp and
session == self.session and not hard_fault and model_ready and (source_current or source_expired) and companion is not None and
companion.last_drain_ok and intent is not None and intent.allowedLatch and intent.lateralArmed and
healthy is not None and healthy.requestedLateral and healthy.lateralAllowed and healthy.pandaInventory)
+5 -4
View File
@@ -48,19 +48,20 @@ def sdgm_alpha_lateral_owner(cp) -> bool:
return bool(qualified_gm(cp) and aol_enabled(cp) and is_volt_sdgm_accepted_envelope(cp))
def steering_raw_projection_owner(cp) -> bool:
def steering_raw_projection_owner(cp, *, monitored=None) -> bool:
"""Qualified non-pedal Volt owners consume their exact raw steering receipt."""
from opendbc.car.gm.steering_authority import monitored_profile
return bool(qualified_gm(cp) and monitored_profile(cp))
return bool((monitored_profile(cp) if monitored is None else monitored) and qualified_gm(cp))
def steering_source_gap_intent_only(owner, cs, companion, now_ns: int) -> bool:
def steering_source_gap_intent_only(owner, cs, companion, now_ns: int, *, raw_projection=None) -> bool:
"""Recognize lost Card publication; never supply a current steering receipt."""
from openpilot.starpilot.aol.runtime import INTENT_MAX_AGE_NS
service = 'starpilotCarState'
sdgm = sdgm_alpha_lateral_owner(owner.CP)
if (not (is_volt_ascm_longitudinal(owner.CP) or sdgm) or not steering_raw_projection_owner(owner.CP) or
if (not (is_volt_ascm_longitudinal(owner.CP) or sdgm) or
not (steering_raw_projection_owner(owner.CP) if raw_projection is None else raw_projection) or
getattr(owner, 'steering_authority_unavailable', False) or
getattr(owner, 'car_state_samples', ())):
return False
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "59181bb8baa78b9040e51336f33d7476a7c1ba712f46f45bb9db6cf42d066d83", "schema_version": 1}
{"protected_inventory_sha256": "dabac5661483031bceaaf1f05fdc2920445ec434647dd213c0eb318a21203e63", "schema_version": 1}