From 3b829ab48b031431f042d61ac4685adf4cee287c Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:47:07 -0600 Subject: [PATCH] Preserve unclassified HDA1 camera fault indications --- .../opendbc/car/hyundai/canfd_lfa_status.py | 19 -- .../opendbc/car/hyundai/carcontroller.py | 6 - .../opendbc/car/hyundai/hyundaicanfd.py | 12 +- .../hyundai/tests/test_canfd_lfa_status.py | 162 +++--------------- prebuilt.json | 2 +- 5 files changed, 26 insertions(+), 175 deletions(-) diff --git a/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py b/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py index 2ab4157548..3c14fb68da 100644 --- a/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py +++ b/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py @@ -6,8 +6,6 @@ from opendbc.car.hyundai.values import CAR, HyundaiFlags MAX_AGE_NS = 50_000_000 -DISPLAY_FAULT_HOLD_NS = 2_100_000_000 -DISPLAY_RELEASE_NS = 150_000_000 def preserves_stock_lfa(cp): @@ -51,8 +49,6 @@ class CANFDLfaStatus: self.counter = None self.body = None self.observed_ns = 0 - self.display_fault_start_ns = 0 - self.display_last_active_ns = 0 def update(self, can_packets): boot_clock = getattr(time, 'CLOCK_BOOTTIME', None) @@ -83,21 +79,6 @@ class CANFDLfaStatus: return self.body return None - def owns_display_status(self, active, now_ns, *, healthy=True): - body = self.current(now_ns) if healthy else None - matches = (body is not None and ((body[4] >> 6) | ((body[5] & 1) << 2)) == 4 and - body[7] >> 4 == 15 and not body[6] & 0xC0) - if matches: - if active: - if not self.display_fault_start_ns: - self.display_fault_start_ns = now_ns - self.display_last_active_ns = now_ns - return True - if self.display_last_active_ns and now_ns <= max(self.display_fault_start_ns + DISPLAY_FAULT_HOLD_NS, - self.display_last_active_ns + DISPLAY_RELEASE_NS): - return True - self.display_fault_start_ns = self.display_last_active_ns = 0 - return False def last_fault(self): body = self.body diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index 3ba0a30474..12a1395ab1 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -537,16 +537,10 @@ class CarController(CarControllerBase): stock_source = getattr(CS, "stock_lfa_status", None) stock_lfa = stock_source.current(clock_boot_ns()) if stock_source is not None else None stock_faults = stock_source.last_fault() if stock_source is not None and stock_lfa is None else None - stock_owned_status = False - if stock_source is not None: - display_healthy = CS.out.canValid and not (CS.out.canTimeout or CS.out.steerFaultTemporary or - CS.out.steerFaultPermanent or CS.out.accFaulted) - stock_owned_status = stock_source.owns_display_status(apply_steer_req, clock_boot_ns(), healthy=display_healthy) damping_source = getattr(CS, "stock_lkas_damping", None) can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN, steering_status_active, apply_steer_req, apply_torque, stock_lfa=stock_lfa, stock_lfa_faults=stock_faults, - stock_lfa_owned_status=stock_owned_status, stock_lkas_damping=(damping_source.current_damping(clock_boot_ns()) if damping_source is not None else None))) if _projection is not None: diff --git a/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py b/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py index a88724f18e..56deed5f14 100644 --- a/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py @@ -44,8 +44,7 @@ LFA_CONTROL_MASK = bytes.fromhex("ffffff3fc0ff3f000000000000ff0000") LFA_FAULT_MASK = bytes.fromhex("00000000c001c0f00000000000000000") -def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, *, stock_lfa=None, stock_lfa_faults=None, - stock_lkas_damping=None, stock_lfa_owned_status=False): +def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, *, stock_lfa=None, stock_lfa_faults=None, stock_lkas_damping=None): values = { "LKA_OptUsmSta": 2, "LKA_SysIndReq": 2 if enabled else 1, @@ -79,20 +78,13 @@ def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, # Stale samples retain only faults; a fresh healthy camera sample clears them. mask = LFA_CONTROL_MASK if stock_lfa is not None else bytes(value ^ 0xFF for value in LFA_FAULT_MASK) stock_indication = (source[4] >> 6) | ((source[5] & 1) << 2) - active_owner_status = (stock_lfa is not None and (lat_active or stock_lfa_owned_status) and stock_indication == 4 and - source[7] >> 4 == 15 and not source[6] & 0xC0) - if active_owner_status: - mask = bytearray(mask) - mask[7] |= 0xF0 - elif stock_indication >= 4: + if stock_indication >= 4: mask = bytearray(mask) mask[4], mask[5] = mask[4] & 0x3F, mask[5] & 0xFE elif stock_lfa is None: mask = bytearray(mask) mask[4], mask[5] = mask[4] | 0xC0, mask[5] | 1 data = bytearray((old & ~owned) | (new & owned) for old, new, owned in zip(source, message[1], mask, strict=True)) - if active_owner_status and not lat_active: - data[4], data[5] = (data[4] & 0x3F) | 0x40, data[5] & 0xFE data[:2] = hkg_can_fd_checksum(0x12A, None, data).to_bytes(2, "little") message = (message[0], bytes(data), message[2]) ret.append(message) diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_canfd_lfa_status.py b/opendbc_repo/opendbc/car/hyundai/tests/test_canfd_lfa_status.py index 8dc0cbc32c..058a75aef0 100644 --- a/opendbc_repo/opendbc/car/hyundai/tests/test_canfd_lfa_status.py +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_canfd_lfa_status.py @@ -520,167 +520,51 @@ def test_actual_interface_preserves_camera_lane_safety_user_mode(car, alpha, mod assert decoder.vl['LFA']['StrTqReqVal'] == 0 -@pytest.mark.parametrize('car', (CAR.KIA_NIRO_EV_2ND_GEN, CAR.GENESIS_GV60_EV_1ST_GEN)) +@pytest.mark.parametrize('car', (CAR.KIA_EV6, CAR.KIA_NIRO_EV_2ND_GEN, CAR.GENESIS_GV60_EV_1ST_GEN)) @pytest.mark.parametrize('alpha', (False, True)) -def test_actual_active_owner_status_keeps_its_display_without_changing_camera_faults(car, alpha, clock): +@pytest.mark.parametrize('preexisting', (False, True)) +def test_unclassified_camera_system_fail_remains_visible_before_and_during_aol(car, alpha, preexisting, clock): cp = params(car, alpha=alpha) ci = CarInterface(cp) ci.update([]) packer = CANPacker(DBC[car][Bus.pt]) decoder = CANParser(DBC[car][Bus.pt], [('LFA', 0)], ci.CC.CAN.ECAN) - command = structs.CarControl.new_message(enabled=True, latActive=True) - command.actuators.torque = .2 - for tick in range(4): - clock[0] = 5_000_000_000 + tick * 10_000_000 - stock = template(packer, ci.CC.CAN.CAM, tick, warning=15, fault=0) + command = structs.CarControl.new_message(enabled=True) + for tick in range(6): + clock[0] = 9_000_000_000 + tick * 10_000_000 + command.latActive = tick >= 2 + warning = 15 if preexisting or tick >= 3 else 0 + stock = template(packer, ci.CC.CAN.CAM, tick, warning=warning, fault=0) assert ci.update([(clock[0], physical_frames(ci, packer, tick, stock))]).canValid _, packets = ci.apply(command.as_reader(), clock[0]) own = [p for p in packets if p[0] == 0x12A and p[2] == ci.CC.CAN.ECAN] - assert len(own) == 1 decoder.update([(clock[0], own)]) - assert decoder.vl['LFA']['LKA_SysIndReq'] == 2 - assert decoder.vl['LFA']['LKA_SysWrn'] == 0 + assert decoder.vl['LFA']['LKA_SysWrn'] == warning + if warning: + assert decoder.vl['LFA']['LKA_SysIndReq'] == 4 assert decoder.vl['LFA']['ToiFltSta'] == 0 - assert own[0][1][9] == stock[1][9] and own[0][1][14] == stock[1][14] - assert ci.CS.stock_lfa_status.body == stock[1] - assert (stock[1][4] >> 6) | ((stock[1][5] & 1) << 2) == 4 - assert stock[1][7] >> 4 == 15 + assert decoder.vl['LFA']['ActToiSta'] == int(command.latActive) @pytest.mark.parametrize('fresh', (False, True)) @pytest.mark.parametrize('active', (False, True)) @pytest.mark.parametrize('indication', (4, 5, 6, 7)) -@pytest.mark.parametrize('warning', (0, 4, 15)) -@pytest.mark.parametrize('fault', (0, 1, 2, 3)) -def test_active_owner_status_preserves_faults_and_inactive_or_stale_indications(fresh, active, indication, warning, fault): +@pytest.mark.parametrize('warning', range(16)) +@pytest.mark.parametrize('fault', range(4)) +def test_fault_indication_is_never_cleared_by_lateral_request(fresh, active, indication, warning, fault): from opendbc.car.hyundai.hyundaicanfd import create_steering_messages cp = params(CAR.GENESIS_GV60_EV_1ST_GEN) packer = CANPacker(DBC[cp.carFingerprint][Bus.pt]) _, body, _ = packer.make_can_msg('LFA', 2, {'LKA_SysIndReq': indication, 'LKA_SysWrn': warning, - 'ToiFltSta': fault, 'ActToiSta': 0, 'StrTqReqVal': -100}) + 'ToiFltSta': fault, 'ActToiSta': 0, 'StrTqReqVal': -123}) kwargs = {'stock_lfa' if fresh else 'stock_lfa_faults': body} own = create_steering_messages(packer, cp, CanBus(cp), active, active, 2 if active else 0, **kwargs) decoder = CANParser(DBC[cp.carFingerprint][Bus.pt], [('LFA', 0)], CanBus(cp).ECAN) decoder.update([(1_000_000_000, own)]) - status = decoder.vl['LFA'] - owns_status = fresh and active and indication == 4 and warning == 15 and fault == 0 - assert status['LKA_SysIndReq'] == (2 if owns_status else indication) - assert status['LKA_SysWrn'] == (0 if owns_status else warning) - assert status['ToiFltSta'] == fault - assert status['ActToiSta'] == int(active) - assert status['StrTqReqVal'] == (2 if active else 0) + values = decoder.vl['LFA'] + assert values['LKA_SysIndReq'] == indication + assert values['LKA_SysWrn'] == warning + assert values['ToiFltSta'] == fault + assert values['ActToiSta'] == int(active) + assert values['StrTqReqVal'] == (2 if active else 0) assert int.from_bytes(own[0][1][:2], 'little') == hkg_can_fd_checksum(0x12A, None, bytearray(own[0][1])) - - -@pytest.mark.parametrize('car', (CAR.KIA_EV6, CAR.KIA_NIRO_EV_2ND_GEN, CAR.GENESIS_GV60_EV_1ST_GEN)) -@pytest.mark.parametrize('alpha', (False, True)) -def test_actual_hda1_release_status_does_not_rebroadcast_the_owned_warning(car, alpha, clock): - cp = params(car, alpha=alpha) - ci = CarInterface(cp) - ci.update([]) - packer = CANPacker(DBC[car][Bus.pt]) - decoder = CANParser(DBC[car][Bus.pt], [('LFA', 0)], ci.CC.CAN.ECAN) - command = structs.CarControl.new_message(enabled=True) - command.actuators.torque = .2 - for tick in range(214): - clock[0] = 6_000_000_000 + tick * 10_000_000 - command.latActive = tick < 20 - stock = template(packer, ci.CC.CAN.CAM, tick % 256, warning=15, fault=0) - assert ci.update([(clock[0], physical_frames(ci, packer, tick, stock))]).canValid - _, packets = ci.apply(command.as_reader(), clock[0]) - own = [p for p in packets if p[0] == 0x12A and p[2] == ci.CC.CAN.ECAN] - assert len(own) == 1 - decoder.update([(clock[0], own)]) - status = decoder.vl['LFA'] - assert status['LKA_SysWrn'] == (0 if tick <= 210 else 15) - assert status['LKA_SysIndReq'] == (2 if tick < 20 else 1 if tick <= 210 else 4) - assert status['ToiFltSta'] == 0 - assert status['ActToiSta'] == int(command.latActive) - if not command.latActive: - assert status['StrTqReqVal'] == 0 - assert ci.CS.stock_lfa_status.body == stock[1] - - -@pytest.mark.parametrize('mutation', ('stale', 'healthy', 'fault1', 'fault2', 'fault3', 'grade5', 'grade6', 'grade7', 'backward')) -def test_display_handover_stops_immediately_for_faults_or_invalid_source(mutation, clock): - packer = CANPacker(DBC[CAR.KIA_EV6][Bus.pt]) - source = CANFDLfaStatus(2) - source.update([(clock[0], [template(packer, 2, 0, warning=15)])]) - assert source.owns_display_status(True, clock[0]) - clock[0] += 10_000_000 - values = {'COUNTER': 1, 'LKA_SysIndReq': 4, 'LKA_SysWrn': 15} - if mutation.startswith('fault'): - values['ToiFltSta'] = int(mutation[-1]) - elif mutation.startswith('grade'): - values['LKA_SysIndReq'] = int(mutation[-1]) - elif mutation == 'healthy': - values.update(LKA_SysIndReq=1, LKA_SysWrn=0) - if mutation == 'stale': - clock[0] += 40_000_001 - elif mutation == 'backward': - clock[0] -= 20_000_000 - else: - source.update([(clock[0], [packer.make_can_msg('LFA', 2, values)])]) - assert not source.owns_display_status(False, clock[0]) - clock[0] = 1_100_000_000 - counter = 1 if mutation in ('stale', 'backward') else 2 - source.update([(clock[0], [template(packer, 2, counter, warning=15)])]) - assert not source.owns_display_status(False, clock[0]) - - -@pytest.mark.parametrize('last_active_ns,deadline_ns', ((1_100_000_000, 3_100_000_000), (4_000_000_000, 4_150_000_000))) -def test_display_handover_deadline_is_bounded_and_cannot_rearm_while_inactive(last_active_ns, deadline_ns, clock): - packer = CANPacker(DBC[CAR.KIA_EV6][Bus.pt]) - source = CANFDLfaStatus(2) - for counter, (stamp, active) in enumerate(((1_000_000_000, True), (last_active_ns, True), - (deadline_ns, False), (deadline_ns + 1, False), (deadline_ns + 2, False))): - clock[0] = stamp - source.update([(stamp, [template(packer, 2, counter, warning=15)])]) - assert source.owns_display_status(active, stamp) == (counter < 3) - - -def test_inactive_camera_warning_never_acquires_display_ownership(clock): - source = CANFDLfaStatus(2) - packer = CANPacker(DBC[CAR.KIA_EV6][Bus.pt]) - source.update([(clock[0], [template(packer, 2, 0, warning=15)])]) - assert not source.owns_display_status(False, clock[0]) - assert source.last_fault() is not None - - -@pytest.mark.parametrize('active', (False, True)) -def test_vehicle_fault_cancels_display_handover_and_cannot_rearm_it(active, clock): - source = CANFDLfaStatus(2) - packer = CANPacker(DBC[CAR.KIA_EV6][Bus.pt]) - source.update([(clock[0], [template(packer, 2, 0, warning=15)])]) - assert source.owns_display_status(True, clock[0]) - clock[0] += 10_000_000 - source.update([(clock[0], [template(packer, 2, 1, warning=15)])]) - assert not source.owns_display_status(active, clock[0], healthy=False) - assert not source.owns_display_status(False, clock[0], healthy=True) - - -@pytest.mark.parametrize('car', (CAR.KIA_EV6, CAR.KIA_NIRO_EV_2ND_GEN, CAR.GENESIS_GV60_EV_1ST_GEN)) -@pytest.mark.parametrize('alpha', (False, True)) -def test_actual_eps_fault_preserves_camera_warning_during_release(car, alpha, clock): - cp = params(car, alpha=alpha) - ci = CarInterface(cp) - ci.update([]) - packer = CANPacker(DBC[car][Bus.pt]) - decoder = CANParser(DBC[car][Bus.pt], [('LFA', 0)], ci.CC.CAN.ECAN) - command = structs.CarControl.new_message(enabled=True) - for tick in range(5): - clock[0] = 8_000_000_000 + tick * 10_000_000 - command.latActive = tick < 2 - stock = template(packer, ci.CC.CAN.CAM, tick, warning=15) - frames = physical_frames(ci, packer, tick, stock) - frames = [p for p in frames if not (p[0] == 0xEA and p[2] == ci.CC.CAN.ECAN)] - frames.append(packer.make_can_msg('MDPS', ci.CC.CAN.ECAN, {'MDPS_LkaFailSta': int(tick == 2)})) - state = ci.update([(clock[0], frames)]) - assert state.canValid and state.steerFaultTemporary == (tick == 2) - _, packets = ci.apply(command.as_reader(), clock[0]) - own = [p for p in packets if p[0] == 0x12A and p[2] == ci.CC.CAN.ECAN] - decoder.update([(clock[0], own)]) - assert decoder.vl['LFA']['LKA_SysWrn'] == (0 if tick < 2 else 15) - assert decoder.vl['LFA']['LKA_SysIndReq'] == (2 if tick < 2 else 4) - assert decoder.vl['LFA']['ToiFltSta'] == 0 - assert decoder.vl['LFA']['ActToiSta'] == int(command.latActive) diff --git a/prebuilt.json b/prebuilt.json index 3996c51868..bb954bca27 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "1f151444c0129f4a5e8dce80874d1a195eaf60823ccf73d2a6eeedcd85796424", "schema_version": 1} +{"protected_inventory_sha256": "5b4bf7f926311d3fbc6c7165dcf68a0c3ecbfb447b2c7a742d5237c7fc5a1110", "schema_version": 1}