diff --git a/opendbc_repo/opendbc/car/car_helpers.py b/opendbc_repo/opendbc/car/car_helpers.py index 8941fb3af4..e42dfadd89 100644 --- a/opendbc_repo/opendbc/car/car_helpers.py +++ b/opendbc_repo/opendbc/car/car_helpers.py @@ -16,7 +16,7 @@ from opendbc.car.gm.values import CAR as GM from opendbc.car.ford.discovery import (normal_bus0_selection as ford_normal_bus0_selection, normal_bus0_queries as ford_normal_bus0_queries, normal_bus_query_brand) from opendbc.car.volvo.discovery import normal_bus_topology as volvo_normal_bus_topology, v60_bus_topology as volvo_v60_bus_topology -from opendbc.car.hyundai.discovery import normal_bus_topology +from opendbc.car.hyundai.discovery import kona_electric_se_candidate, normal_bus_topology from opendbc.car.honda.discovery import (eps_needs_obd as honda_eps_needs_obd, nidec_bus0_topology, normal_bus_topology as honda_normal_bus_topology) from opendbc.car.honda.values import CAR as HONDA, HondaFlags @@ -271,6 +271,8 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu # Refine after both automatic sources, before the explicit override below. if not fixed_fingerprint: car_fingerprint = automatic_bolt_candidate(car_fingerprint, finger, camera_cruise_messages, vin) + if car_fingerprint is None: + car_fingerprint = kona_electric_se_candidate(vin, finger, car_fw) if car_fingerprint == 'SUBARU_IMPREZA' and source == CarParams.FingerprintSource.fw and exact_match: # Subaru's early GT Crosstrek and Impreza share a firmware bucket. # NHTSA vPIC identifies JF2GT with model-year codes J and K as Crosstrek. diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index 166ca72c6b..8252814b3d 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -204,7 +204,7 @@ class CarController(CarControllerBase): if _projection is not None: _projection.begin(CC.actuators.torque, self.frame) actuators = CC.actuators - if self.CP.carFingerprint == CAR.KIA_EV6_2025 and self.CP.dashcamOnly: + if self.CP.carFingerprint in (CAR.KIA_EV6_2025, CAR.HYUNDAI_KONA_EV_2023_NON_SCC) and self.CP.dashcamOnly: return actuators.as_builder(), [] hud_control = CC.hudControl # Card finalizes the AOL safety marker after CarInterface constructs us. diff --git a/opendbc_repo/opendbc/car/hyundai/carstate.py b/opendbc_repo/opendbc/car/hyundai/carstate.py index b91ed321b8..66cf79bcfe 100644 --- a/opendbc_repo/opendbc/car/hyundai/carstate.py +++ b/opendbc_repo/opendbc/car/hyundai/carstate.py @@ -51,7 +51,7 @@ BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: Bu def get_non_scc_cruise_signals(flags: int, car=None) -> tuple[str, str, str, str, str, str]: - if car == CAR.KIA_RAY_EV: + if car in (CAR.KIA_RAY_EV, CAR.HYUNDAI_KONA_EV_2023_NON_SCC): return "LABEL11", "CC_React", "LABEL11", "CC_Engaged", "E_EMS11", "Cruise_Limit_Target" if flags & HyundaiFlags.EV: return "LABEL11", "CC_React", "EMS12", "ACC_ACT", "E_EMS11", "Cruise_Limit_Target" diff --git a/opendbc_repo/opendbc/car/hyundai/discovery.py b/opendbc_repo/opendbc/car/hyundai/discovery.py index 27db038bd5..b7b204b902 100644 --- a/opendbc_repo/opendbc/car/hyundai/discovery.py +++ b/opendbc_repo/opendbc/car/hyundai/discovery.py @@ -1,6 +1,10 @@ import time from itertools import product +from opendbc.car.hyundai.values import CAR +from opendbc.car.structs import CarParams +from opendbc.car.vin import is_valid_vin + NORMAL_BUS_LAYOUT = {(2, 0x110): 32, (2, 0x362): 32, (1, 0x35): 32, (1, 0xEA): 24, (1, 0xA0): 24, (1, 0x1A0): 32, @@ -32,6 +36,29 @@ QUIET_CAMERA_NORMAL_BUS_LAYOUT = {(0, 0xEA): 24, (0, 0xA0): 24, (0, 0x1A0): 32, **{(1, address): 32 for address in range(0x210, 0x220)}} +def kona_electric_se_candidate(vin, fingerprint, car_fw): + if not is_valid_vin(vin) or vin[:8] != 'KM8K23AG' or vin[9] != 'P': + return None + + layout = {(0, 0x251): 8, (0, 0x371): 8, (0, 0x386): 8, (0, 0x394): 8, (0, 0x4F1): 4, + (0, 0x592): 8, (1, 0x329): 8, (2, 0x340): 8} + if any(fingerprint.get(bus, {}).get(addr) != length for (bus, addr), length in layout.items()): + return None + if any(frames.keys() & {0x420, 0x421} for frames in fingerprint.values()): + return None + + ecu = CarParams.Ecu + if any(fw.ecu == ecu.fwdRadar or (fw.address == 0x7D0 and fw.brand == 'hyundai') for fw in car_fw): + return None + observed_fw = {(fw.ecu.raw, fw.address, bytes(fw.fwVersion)) for fw in car_fw + if fw.brand == 'hyundai' and fw.bus == 0 and not fw.subAddress and not fw.logging} + expected_fw = { + (ecu.eps, 0x7D4, b'\xf1\x00OSP MDPS C 1.00 1.02 56310K4261\x00 4OEPC102'), + (ecu.fwdCamera, 0x7C4, b'\xf1\x00OSP LKA AT USA LHD 1.00 1.04 99211-J9200 904'), + } + return CAR.HYUNDAI_KONA_EV_2023_NON_SCC if expected_fw <= observed_fw else None + + def _canfd_variant_layouts(): layouts = [] originals = (NORMAL_BUS_LAYOUT, HDA1_NORMAL_BUS_LAYOUT, HDA2_NORMAL_BUS_LAYOUT) diff --git a/opendbc_repo/opendbc/car/hyundai/interface.py b/opendbc_repo/opendbc/car/hyundai/interface.py index 8f9cd1c033..d4ca8720f7 100644 --- a/opendbc_repo/opendbc/car/hyundai/interface.py +++ b/opendbc_repo/opendbc/car/hyundai/interface.py @@ -125,6 +125,14 @@ class CarInterface(CarInterfaceBase): def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams: ret.brand = "hyundai" + if candidate == CAR.HYUNDAI_KONA_EV_2023_NON_SCC: + ret.dashcamOnly = True + ret.autoResumeSng = False + ret.radarUnavailable = True + ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.noOutput)] + CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning) + return ret + if is_blended(ret): cam_can = CanBus(None, fingerprint).CAM lka_steering = any(fw.ecu == Ecu.adas for fw in car_fw) or 0x50 in fingerprint[cam_can] diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_kona_electric_se.py b/opendbc_repo/opendbc/car/hyundai/tests/test_kona_electric_se.py new file mode 100644 index 0000000000..6f7f0941e7 --- /dev/null +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_kona_electric_se.py @@ -0,0 +1,72 @@ +from unittest import TestCase, mock + +from opendbc.car import CanData, gen_empty_fingerprint, structs +from opendbc.car.car_helpers import get_car +from opendbc.car.hyundai.discovery import kona_electric_se_candidate +from opendbc.car.hyundai.fingerprints import FW_VERSIONS +from opendbc.car.hyundai.values import CAR + +MODEL = CAR.HYUNDAI_KONA_EV_2023_NON_SCC +SE_VIN = 'KM8K23AG0PU000000' +SCC_VIN = 'KM8K53AG1PU000000' +SE_LAYOUT = ((0, 0x251, 8), (0, 0x371, 8), (0, 0x386, 8), (0, 0x394, 8), (0, 0x4F1, 4), + (0, 0x592, 8), (1, 0x329, 8), (2, 0x340, 8)) + + +def kona_electric_fw(include_radar=False): + ecu = structs.CarParams.Ecu + versions = FW_VERSIONS[CAR.HYUNDAI_KONA_EV_2022] + firmware = [ + structs.CarParams.CarFw(ecu=ecu.eps, address=0x7D4, brand='hyundai', + fwVersion=b'\xf1\x00OSP MDPS C 1.00 1.02 56310K4261\x00 4OEPC102'), + structs.CarParams.CarFw(ecu=ecu.fwdCamera, address=0x7C4, brand='hyundai', + fwVersion=b'\xf1\x00OSP LKA AT USA LHD 1.00 1.04 99211-J9200 904'), + ] + if include_radar: + firmware.append(structs.CarParams.CarFw(ecu=ecu.fwdRadar, address=0x7D0, brand='hyundai', + fwVersion=versions[(ecu.fwdRadar, 0x7D0, None)][0])) + return firmware + + +def interface(vin, layout=SE_LAYOUT, radar=False, forced_candidate=None): + packets = [CanData(addr, bytes(length), bus) for bus, addr, length in layout] + cached = structs.CarParams(brand='hyundai', carVin=vin, carFw=kona_electric_fw(radar), carFingerprint=forced_candidate or '') + with mock.patch.dict('os.environ', clear=True): + return get_car(lambda *args, **kwargs: [packets] if kwargs.get('wait_for_one') else [], mock.Mock(), mock.Mock(), + alpha_long_allowed=True, is_release=False, cached_params=cached, forced_candidate=forced_candidate) + + +class TestKonaElectricSE(TestCase): + def test_exact_auto_and_manual_identity_cannot_transmit(self): + for manual in (None, MODEL): + with self.subTest(manual=manual): + ci = interface(SE_VIN, forced_candidate=manual) + cp = ci.CP + self.assertEqual(cp.carFingerprint, MODEL) + self.assertTrue(cp.dashcamOnly) + self.assertFalse(cp.alphaLongitudinalAvailable) + self.assertFalse(cp.openpilotLongitudinalControl) + self.assertEqual([(s.safetyModel, s.safetyParam) for s in cp.safetyConfigs], [(structs.CarParams.SafetyModel.noOutput, 0)]) + cmd = structs.CarControl(enabled=True, latActive=True, longActive=True) + self.assertFalse(ci.apply(cmd.as_reader(), 0)[1]) + + def test_scc_firmware_still_owns_matching_sibling(self): + ci = interface(SCC_VIN, (*SE_LAYOUT, (2, 0x420, 8), (2, 0x421, 8)), radar=True) + self.assertEqual(ci.CP.carFingerprint, CAR.HYUNDAI_KONA_EV_2022) + self.assertFalse(ci.CP.dashcamOnly) + + def test_evidence_is_conjunctive(self): + fp = gen_empty_fingerprint() + for bus, addr, length in SE_LAYOUT: + fp[bus][addr] = length + firmware = kona_electric_fw() + self.assertEqual(kona_electric_se_candidate(SE_VIN, fp, firmware), MODEL) + for vin in ('', '00000000000000000', SCC_VIN, SE_VIN[:9] + 'N' + SE_VIN[10:]): + self.assertIsNone(kona_electric_se_candidate(vin, fp, firmware)) + self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, firmware[:1])) + self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, kona_electric_fw(include_radar=True))) + fp[2][0x421] = 8 + self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, firmware)) + del fp[2][0x421] + fp[1][0x329] = 7 + self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, firmware)) diff --git a/opendbc_repo/opendbc/car/hyundai/values.py b/opendbc_repo/opendbc/car/hyundai/values.py index 2d2b871a0a..5ee2c49a3a 100644 --- a/opendbc_repo/opendbc/car/hyundai/values.py +++ b/opendbc_repo/opendbc/car/hyundai/values.py @@ -950,6 +950,11 @@ class CAR(Platforms): HYUNDAI_KONA_EV.specs, flags=HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS, ) + HYUNDAI_KONA_EV_2023_NON_SCC = HyundaiNonSccPlatformConfig( + [HyundaiNonSccCarDocs("Hyundai Kona Electric SE 2023", package="Non-SCC, dashcam only", car_parts=CarParts.common([CarHarness.hyundai_o]))], + HYUNDAI_KONA_EV_2022.specs, + flags=HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS, + ) KIA_RAY_EV = HyundaiNonSccPlatformConfig( [HyundaiNonSccCarDocs("Kia Ray EV 2025", package="Non-SCC with comma pedal (6-byte sensor) and 8-byte LFA; other variants dashcam only", car_parts=CarParts.common([CarHarness.hyundai_h]))], diff --git a/opendbc_repo/opendbc/car/tests/routes.py b/opendbc_repo/opendbc/car/tests/routes.py index a82ab54cd4..93ab725402 100644 --- a/opendbc_repo/opendbc/car/tests/routes.py +++ b/opendbc_repo/opendbc/car/tests/routes.py @@ -99,6 +99,7 @@ non_tested_cars = [ HYUNDAI.HYUNDAI_ELANTRA_2022_NON_SCC, HYUNDAI.HYUNDAI_ELANTRA_HEV_2022_NON_SCC, HYUNDAI.HYUNDAI_KONA_EV_NON_SCC, + HYUNDAI.HYUNDAI_KONA_EV_2023_NON_SCC, HYUNDAI.HYUNDAI_KONA_NON_SCC, HYUNDAI.HYUNDAI_IONIQ_5_N, # Frozen exemptions only: these three angle hybrids have no validated route. diff --git a/opendbc_repo/opendbc/car/torque_data/substitute.toml b/opendbc_repo/opendbc/car/torque_data/substitute.toml index 85eca44ff1..e6d0e543e1 100644 --- a/opendbc_repo/opendbc/car/torque_data/substitute.toml +++ b/opendbc_repo/opendbc/car/torque_data/substitute.toml @@ -53,6 +53,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"] "HYUNDAI_ELANTRA_2022_NON_SCC" = "HYUNDAI_ELANTRA_2021" "HYUNDAI_ELANTRA_HEV_2022_NON_SCC" = "HYUNDAI_SONATA" "HYUNDAI_KONA_EV_NON_SCC" = "HYUNDAI_KONA_EV" +"HYUNDAI_KONA_EV_2023_NON_SCC" = "HYUNDAI_KONA_EV" "HYUNDAI_KONA_NON_SCC" = "HYUNDAI_KONA_EV" "KIA_CEED_PHEV_2022_NON_SCC" = "HYUNDAI_SONATA" "KIA_FORTE_2019_NON_SCC" = "HYUNDAI_SONATA" diff --git a/prebuilt.json b/prebuilt.json index 42cf942cf9..0596403832 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "ce33871fe77809fd591d89ad2379046ddc912680ef6cc242e9f7997ac539ead3", "schema_version": 1} +{"protected_inventory_sha256": "d7e4040d0eea396aa644f3e18da68be560b309575c874fe298173e9cc8f58fd3", "schema_version": 1}