Restore Kona Electric CCNC display support

This commit is contained in:
firestar5683
2026-11-19 11:53:33 -06:00
parent 1b1bcb6058
commit d4e19a6879
6 changed files with 184 additions and 7 deletions
@@ -27,6 +27,7 @@ from opendbc.car.hyundai.ray_pedal import create_ray_pedal_command, ray_pedal_ga
from opendbc.car.hyundai.ioniq6_longitudinal import Ioniq6LongitudinalPolicy
from opendbc.car.hyundai.ioniq6_bsm import BlindspotStatus
from opendbc.car.hyundai.canfd_dash_icons import CanFDDashIcons
from opendbc.car.hyundai.canfd_lfa_status import preserves_stock_lfa
from opendbc.car.hyundai.classic_scc_aol import qualified as qualified_classic_stock_aol
from opendbc.car.hyundai.classic_long_aol import AOL_EXPERIENCE, qualified as qualified_classic_long_aol
from opendbc.car.hyundai.canfd_stock_aol import qualified as qualified_canfd_stock_aol, qualified_long as qualified_canfd_long_aol
@@ -168,6 +169,7 @@ class CarController(CarControllerBase):
not CP.openpilotLongitudinalControl and CP.pcmCruise and
int(CP.safetyConfigs[-1].safetyParam) in (0x0811, 0x0891))
self.canfd_torque_aol_status = (qualified_canfd_stock_aol(CP) or qualified_canfd_long_aol(CP))
self.ccnc_fault_ownership_required = preserves_stock_lfa(CP)
self.canfd_dash_icons = CanFDDashIcons() if ioniq6_status or self.canfd_torque_aol_status else None
self.classic_dash_icons = CanFDDashIcons() if classic_aol_dash_enabled(CP) else None
self.classic_lfa_icon = None
@@ -590,7 +592,8 @@ class CarController(CarControllerBase):
can_sends.extend(hyundaicanfd.create_ccnc(self.packer, self.CAN, self.CP.openpilotLongitudinalControl,
CC.enabled, hud_control, CC.leftBlinker, CC.rightBlinker,
CS.ccnc_161.copy(), CS.ccnc_162.copy(), CS.ccnc_1b5 if support_current else None,
CS.is_metric, CS.out, CS.out.cruiseState.available, CC.latActive, owned_lfa_status=stock_ccnc_owned))
CS.is_metric, CS.out, CS.out.cruiseState.available, CC.latActive,
owned_lfa_status=(stock_ccnc_owned if self.ccnc_fault_ownership_required else None)))
self.last_ccnc_161_ts_ns = CS.ccnc_161_ts_ns
self.last_ccnc_162_ts_ns = CS.ccnc_162_ts_ns
else:
@@ -327,8 +327,8 @@ def create_ioniq6_blindspot_status(counter: int, status: BlindspotStatus, *, bus
# Source-derived CCNC camera display transform; the repository MIT notice applies.
def create_ccnc(packer, CAN, openpilot_longitudinal, enabled, hud, left_blinker, right_blinker, msg_161, msg_162, msg_1b5,
is_metric, out, main_cruise_enabled, lfa_icon, *, owned_lfa_status=False):
if lfa_icon or owned_lfa_status:
is_metric, out, main_cruise_enabled, lfa_icon, *, owned_lfa_status=None):
if owned_lfa_status or (owned_lfa_status is None and lfa_icon):
# The host owns lateral; keep unrelated faults and obstruction warnings.
for field in ("FAULT_LSS", "FAULT_HDA", "FAULT_DAS", "FAULT_LFA", "FAULT_DAW"):
if msg_162.get(field) == 1:
@@ -7,7 +7,7 @@ from opendbc.car import Bus, gen_empty_fingerprint, structs
from opendbc.car.hyundai.canfd_lfa_status import CANFDClusterStatus, CANFDLfaStatus, preserves_stock_lfa
from opendbc.car.hyundai.hyundaicanfd import CLUSTER_CONTROL_MASK, CanBus, create_lfahda_cluster, hkg_can_fd_checksum
from opendbc.car.hyundai.interface import CarInterface
from opendbc.car.hyundai.values import CAR, DBC
from opendbc.car.hyundai.values import CAR, DBC, HyundaiFlags
@pytest.fixture
@@ -389,6 +389,10 @@ def test_actual_interface_preserves_body_icons_cadence_and_identical_steering(ca
_, original = reference.apply(command.as_reader(), clock[0])
assert [p for p in own if p[0] == 0x12A] == [p for p in original if p[0] == 0x12A]
messages = [p for p in own if p[0] == 0x1E0]
if cp.flags & HyundaiFlags.CCNC:
assert not messages
assert not any(p[0] in (0x161, 0x162) for p in own)
continue
assert len(messages) == int(tick % 5 == 0)
if messages:
original_cluster = next(p for p in original if p[0] == 0x1E0)
@@ -864,7 +868,7 @@ def test_same_batch_ownership_requires_valid_ordered_healthy_predecessor(failure
assert not source.owns_display_status(False, clock[0] + 3_000_000_000, healthy=True)
@pytest.mark.parametrize('car', (CAR.HYUNDAI_KONA_2ND_GEN, CAR.HYUNDAI_KONA_HEV_2ND_GEN,
@pytest.mark.parametrize('car', (CAR.HYUNDAI_KONA_EV_2ND_GEN, CAR.HYUNDAI_KONA_2ND_GEN, CAR.HYUNDAI_KONA_HEV_2ND_GEN,
CAR.HYUNDAI_SANTA_CRUZ_2025, CAR.HYUNDAI_SONATA_2024,
CAR.HYUNDAI_SONATA_HEV_2024, CAR.HYUNDAI_TUCSON_2025,
CAR.HYUNDAI_TUCSON_HEV_2025, CAR.KIA_K5_2025))
@@ -0,0 +1,170 @@
import pytest
from opendbc.can import CANPacker, CANParser
from opendbc.car import Bus, gen_empty_fingerprint, structs
from opendbc.car.hyundai.canfd_stock_aol import qualified
from opendbc.car.hyundai.hyundaicanfd import CanBus
from opendbc.car.hyundai.interface import CarInterface
from opendbc.car.hyundai.tests.test_canfd_lfa_status import clock as clock
from opendbc.car.hyundai.tests.test_canfd_lfa_status import physical_frames, template
from opendbc.car.hyundai.values import CAR, DBC, HyundaiFlags
from opendbc.safety.tests.libsafety import libsafety_py
def kona_params(*, pair='both', alpha=False, alternate=False, offset=0, hda2=False):
fp = gen_empty_fingerprint()
ecan = offset + int(hda2)
fp[ecan][0x1AA if alternate else 0x1CF] = 16 if alternate else 8
fp[offset + 2][0x1A0] = 32
bus = ecan if pair == 'ecan' else offset + 2
if pair not in ('none', 'missing_161'):
fp[bus][0x161] = 16 if pair == 'short_161' else 32
if pair not in ('none', 'missing_162'):
fp[bus][0x162] = 16 if pair == 'short_162' else 32
if hda2:
fp[offset + 2][0x50] = 16
return CarInterface.get_params(CAR.HYUNDAI_KONA_EV_2ND_GEN, fp, [], alpha, False, False)
@pytest.mark.parametrize('pair', ('both', 'none', 'missing_161', 'missing_162', 'short_161', 'short_162', 'ecan'))
@pytest.mark.parametrize('alpha', (False, True))
@pytest.mark.parametrize('alternate', (False, True))
@pytest.mark.parametrize('offset', (0, 4))
def test_factory_restores_ccnc_profile_for_kona_ev(pair, alpha, alternate, offset):
cp = kona_params(pair=pair, alpha=alpha, alternate=alternate, offset=offset)
assert cp.flags & HyundaiFlags.CCNC
assert cp.pcmCruise and not cp.openpilotLongitudinalControl
assert not cp.alphaLongitudinalAvailable
expected = 0x409 | (0x20 if alternate else 0)
assert cp.safetyConfigs[-1].safetyParam & ~0x800 == expected
assert qualified(cp)
cp.safetyConfigs[-1].safetyParam |= 0x800
assert qualified(cp, marked_only=True)
assert CanBus(cp).ECAN == offset
@pytest.mark.parametrize('alpha', (False, True))
@pytest.mark.parametrize('alternate', (False, True))
def test_hda2_kona_profile_is_unchanged(alpha, alternate):
original = kona_params(pair='none', alpha=alpha, alternate=alternate, hda2=True)
observed = kona_params(alpha=alpha, alternate=alternate, hda2=True)
assert observed.flags & HyundaiFlags.CCNC
assert observed.flags == original.flags
assert [c.to_dict() for c in observed.safetyConfigs] == [c.to_dict() for c in original.safetyConfigs]
@pytest.mark.parametrize('alpha', (False, True))
@pytest.mark.parametrize('failure', ('none', 'eps_fault', 'host_fault', 'camera_fault', 'higher_grade', 'obstruction', 'missing_tracker'))
def test_actual_kona_ccnc_sender_uses_qualified_ownership_and_preserves_faults(alpha, failure, clock):
cp = kona_params(alpha=alpha)
cp.safetyConfigs[-1].safetyParam |= 0x800
ci = CarInterface(cp)
ci.update([])
packer = CANPacker(DBC[CAR.HYUNDAI_KONA_EV_2ND_GEN][Bus.pt])
bus = ci.CC.CAN
decoder = CANParser(DBC[CAR.HYUNDAI_KONA_EV_2ND_GEN][Bus.pt], [('CCNC_0x161', 0), ('CCNC_0x162', 0)], bus.ECAN)
command = structs.CarControl.new_message()
seen = 0
for tick in range(100):
clock[0] = 90_000_000_000 + tick * 10_000_000
command.latActive = 2 <= tick < 80
faulted = tick >= 40 and failure != 'none'
stock = template(packer, bus.CAM, tick, warning=15 if tick >= 14 else 0,
fault=int(faulted and failure == 'camera_fault'))
if faulted and failure == 'higher_grade':
stock = packer.make_can_msg('LFA', bus.CAM, {'COUNTER': tick, 'LKA_SysIndReq': 5, 'LKA_SysWrn': 15})
frames = [p for p in physical_frames(ci, packer, tick, stock) if not (p[0] == 0xEA and p[2] == bus.ECAN)]
frames.append(packer.make_can_msg('MDPS', bus.ECAN, {'COUNTER': tick, 'MDPS_LkaToiActvSta': int(4 <= tick < 82),
'MDPS_LkaFailSta': int(faulted and failure == 'eps_fault')}))
if tick % 5 == 0:
warning = (2 if faulted and failure == 'obstruction' else 1) if tick >= 15 else 0
frames.extend([packer.make_can_msg('CCNC_0x161', bus.CAM, {'COUNTER': tick // 5}),
packer.make_can_msg('CCNC_0x162', bus.CAM, {'COUNTER': tick // 5,
'FAULT_LSS': warning, 'FAULT_DAS': warning, 'FAULT_FCA': 2})])
assert ci.update([(clock[0], frames)]).canValid
if faulted and failure == 'host_fault':
ci.CS.out.accFaulted = True
if faulted and failure == 'missing_tracker':
ci.CS.stock_lfa_status = None
_, packets = ci.apply(command.as_reader(), clock[0])
display = [p for p in packets if p[0] in (0x161, 0x162)]
if not display:
continue
seen += 1
decoder.update([(clock[0], display)])
expected = (2 if failure == 'obstruction' else 1) if faulted else 0
assert decoder.vl['CCNC_0x162']['FAULT_LSS'] == expected
assert decoder.vl['CCNC_0x162']['FAULT_DAS'] == expected
assert decoder.vl['CCNC_0x162']['FAULT_FCA'] == 2
assert decoder.vl['CCNC_0x161']['LFA_ICON'] == (2 if command.latActive else 0)
assert seen == 19
@pytest.mark.parametrize('alternate', (False, True))
@pytest.mark.parametrize('aol', (False, True))
def test_selected_ccnc_native_profile_owns_only_supported_frames(alternate, aol):
cp = kona_params(alternate=alternate)
if aol:
cp.safetyConfigs[-1].safetyParam |= 0x800
word = cp.safetyConfigs[-1].safetyParam
assert word == (0x429 if alternate else 0x409) | (0x800 if aol else 0)
safety = libsafety_py.libsafety
safety.set_alternative_experience(0)
assert safety.set_safety_hooks(structs.CarParams.SafetyModel.hyundaiCanfd, word) == 0
safety.init_tests()
packer = CANPacker('hyundai_canfd_generated')
for name in ('CCNC_0x161', 'CCNC_0x162'):
address, body, bus = packer.make_can_msg(name, 0, {})
assert safety.safety_tx_hook(libsafety_py.make_CANPacket(address, bus, body))
assert safety.safety_fwd_hook(2, address) == -1
assert safety.safety_fwd_hook(2, 0x1A0) == 0
assert safety.safety_fwd_hook(0, 0xEA) == 2
address, body, bus = packer.make_can_msg('SCC_CONTROL', 0, {'ACCMode': 1, 'aReqValue': 1., 'aReqRaw': 1.})
assert not safety.safety_tx_hook(libsafety_py.make_CANPacket(address, bus, body))
@pytest.mark.parametrize('missing', (0x161, 0x162))
def test_kona_ccnc_missing_pair_does_not_emit_legacy_or_empty_display(missing, clock):
cp = kona_params()
ci = CarInterface(cp)
ci.update([])
packer = CANPacker(DBC[CAR.HYUNDAI_KONA_EV_2ND_GEN][Bus.pt])
command = structs.CarControl.new_message(latActive=True)
for tick in range(20):
clock[0] = 95_000_000_000 + tick * 10_000_000
frames = physical_frames(ci, packer, tick, template(packer, ci.CC.CAN.CAM, tick))
name = 'CCNC_0x162' if missing == 0x161 else 'CCNC_0x161'
frames.append(packer.make_can_msg(name, ci.CC.CAN.CAM, {'COUNTER': tick}))
assert ci.update([(clock[0], frames)]).canValid
_, packets = ci.apply(command.as_reader(), clock[0])
assert any(p[0] == 0x12A for p in packets)
assert not any(p[0] in (0x161, 0x162, 0x1E0) for p in packets)
@pytest.mark.parametrize('alpha', (False, True))
def test_ccnc_selection_keeps_all_steering_packets_identical(alpha, clock):
cp = kona_params(alpha=alpha)
cp.safetyConfigs[-1].safetyParam |= 0x800
legacy = cp.as_reader().as_builder()
legacy.flags = int(legacy.flags) & ~int(HyundaiFlags.CCNC)
legacy.safetyConfigs[-1].safetyParam &= ~0x400
current, previous = CarInterface(cp), CarInterface(legacy)
current.update([])
previous.update([])
packer = CANPacker(DBC[CAR.HYUNDAI_KONA_EV_2ND_GEN][Bus.pt])
command = structs.CarControl.new_message(latActive=True)
for tick in range(300):
clock[0] = 96_000_000_000 + tick * 10_000_000
command.actuators.torque = .2 if tick < 150 else -.2
stock = template(packer, current.CC.CAN.CAM, tick % 256, warning=15 if tick >= 14 else 0)
frames = [p for p in physical_frames(current, packer, tick, stock) if p[0] not in (0xEA, 0x125)]
frames.extend([packer.make_can_msg('MDPS', 0, {'COUNTER': tick % 256, 'MDPS_LkaToiActvSta': int(tick >= 4)}),
packer.make_can_msg('STEERING_SENSORS', 0, {'COUNTER': tick % 256, 'STEERING_ANGLE': 95. if tick < 245 else -95.})])
if tick % 5 == 0:
frames.extend([packer.make_can_msg('CCNC_0x161', 2, {'COUNTER': tick // 5}),
packer.make_can_msg('CCNC_0x162', 2, {'COUNTER': tick // 5, 'FAULT_DAS': int(tick >= 15)})])
assert current.update([(clock[0], frames)]).canValid
assert previous.update([(clock[0], frames)]).canValid
_, actual = current.apply(command.as_reader(), clock[0])
_, before = previous.apply(command.as_reader(), clock[0])
assert [p for p in actual if p[0] == 0x12A] == [p for p in before if p[0] == 0x12A]
+1 -1
View File
@@ -389,7 +389,7 @@ class CAR(Platforms):
[HyundaiCarDocs("Hyundai Kona Electric (with HDA II, Korea only) 2023", video="https://www.youtube.com/watch?v=U2fOCmcQ8hw",
car_parts=CarParts.common([CarHarness.hyundai_r]))],
CarSpecs(mass=1740, wheelbase=2.66, steerRatio=13.6, tireStiffnessFactor=0.385),
flags=HyundaiFlags.EV | HyundaiFlags.CANFD_NO_RADAR_DISABLE,
flags=HyundaiFlags.EV | HyundaiFlags.CANFD_NO_RADAR_DISABLE | HyundaiFlags.CCNC,
radar_dbc=HYUNDAI_MRR35_RADAR_DBC,
)
HYUNDAI_KONA_HEV = HyundaiPlatformConfig(
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "357d61a457af9c82576e4f76847e87e168a5fc3f3fd2c84075edb7a2d59d5cc2", "schema_version": 1}
{"protected_inventory_sha256": "21270f97e3996f408a38d311cbbc5c41502d44e35ae76c567b293cb25a4caf75", "schema_version": 1}