From 459bb6d15a4a9cd524e26ec4d071c6ae1a50529f Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 25 Sep 2024 19:29:22 -0400 Subject: [PATCH 1/8] Hyundai CAN-FD: Add CAN fingerprint fallback checks for HDA2 detection --- opendbc/car/hyundai/interface.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/interface.py b/opendbc/car/hyundai/interface.py index 27df5b556d..18c8bfd1b0 100644 --- a/opendbc/car/hyundai/interface.py +++ b/opendbc/car/hyundai/interface.py @@ -25,7 +25,16 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime # FIXME: the Optima Hybrid 2017 uses a different SCC12 checksum ret.dashcamOnly = candidate in {CAR.KIA_OPTIMA_H, } - hda2 = Ecu.adas in [fw.ecu for fw in car_fw] + # Check if the ADAS Driving ECU is present in the firmware response. + # If not found, check the CAM CAN bus fingerprint for known HDA2 steering messages (0x50 or 0x110), + # that indicate an HDA2 car even without a direct ADAS Driving ECU response. + if Ecu.adas in [fw.ecu for fw in car_fw]: + hda2 = True + else: + # Some HDA2 cars do not respond ADAS Driving ECU if the known HDA2 steering messages are present + cam_can = CanBus(ret).CAM + hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] + CAN = CanBus(None, hda2, fingerprint) if candidate in CANFD_CAR: From 6ec9359904a70f808980affc5a767fc082855b83 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 25 Sep 2024 19:47:44 -0400 Subject: [PATCH 2/8] fix test --- opendbc/car/hyundai/interface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opendbc/car/hyundai/interface.py b/opendbc/car/hyundai/interface.py index 18c8bfd1b0..f25f4b7e27 100644 --- a/opendbc/car/hyundai/interface.py +++ b/opendbc/car/hyundai/interface.py @@ -31,8 +31,9 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime if Ecu.adas in [fw.ecu for fw in car_fw]: hda2 = True else: - # Some HDA2 cars do not respond ADAS Driving ECU if the known HDA2 steering messages are present - cam_can = CanBus(ret).CAM + # Some HDA2 cars do not respond ADAS Driving ECU if the known HDA2 steering messages are present. + # The hda2 flag to initialize CanBus is not critical here since we only care about CAM bus steering messages. + cam_can = CanBus(None, False, fingerprint).CAM hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] CAN = CanBus(None, hda2, fingerprint) From b657a96b8931936d661151a0d04f656fa2fe1803 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 26 Sep 2024 17:44:04 -0400 Subject: [PATCH 3/8] just 1 source --- opendbc/car/hyundai/interface.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/opendbc/car/hyundai/interface.py b/opendbc/car/hyundai/interface.py index 95b41cc550..2972cfc146 100644 --- a/opendbc/car/hyundai/interface.py +++ b/opendbc/car/hyundai/interface.py @@ -18,16 +18,10 @@ class CarInterface(CarInterfaceBase): def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams: ret.carName = "hyundai" - # Check if the ADAS Driving ECU is present in the firmware response. - # If not found, check the CAM CAN bus fingerprint for known HDA2 steering messages (0x50 or 0x110), - # that indicate an HDA2 car even without a direct ADAS Driving ECU response. - if Ecu.adas in [fw.ecu for fw in car_fw]: - hda2 = True - else: - # Some HDA2 cars do not respond ADAS Driving ECU if the known HDA2 steering messages are present. - # The hda2 flag to initialize CanBus is not critical here since we only care about CAM bus steering messages. - cam_can = CanBus(None, False, fingerprint).CAM - hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] + # Check the CAM bus fingerprint for known HDA2 steering messages (0x50 or 0x110), that indicate an HDA2 car + # The hda2 flag to initialize CanBus is not critical here since we only care about CAM bus steering messages. + cam_can = CanBus(None, False, fingerprint).CAM + hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] CAN = CanBus(None, hda2, fingerprint) From ed5ca8fcb55ef229815b6e8c7ac4b6d65b74eebe Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 26 Sep 2024 17:53:17 -0400 Subject: [PATCH 4/8] update unit test --- opendbc/car/hyundai/tests/test_hyundai.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc/car/hyundai/tests/test_hyundai.py index 9fc28827e1..d02668dcec 100644 --- a/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc/car/hyundai/tests/test_hyundai.py @@ -6,6 +6,7 @@ from opendbc.car.structs import CarParams from opendbc.car.fw_versions import build_fw_dict from opendbc.car.hyundai.interface import CarInterface +from opendbc.car.hyundai.hyundaicanfd import CanBus from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR from opendbc.car.hyundai.values import CAMERA_SCC_CAR, CANFD_CAR, CAN_GEARS, CAR, CHECKSUM, DATE_FW_ECUS, \ HYBRID_CAR, EV_CAR, FW_QUERY_CONFIG, LEGACY_SAFETY_MODE_CAR, CANFD_FUZZY_WHITELIST, \ @@ -44,17 +45,21 @@ class TestHyundaiFingerprint: def test_feature_detection(self): # HDA2 - for has_adas in (True, False): - car_fw = [CarParams.CarFw(ecu=Ecu.adas if has_adas else Ecu.fwdCamera)] - CP = CarInterface.get_params(CAR.KIA_EV6, gen_empty_fingerprint(), car_fw, False, False) - assert bool(CP.flags & HyundaiFlags.CANFD_HDA2) == has_adas + for hda2 in (True, False): + hda2_steering_messages = [0x50, 0x110] + fingerprint = gen_empty_fingerprint() + if hda2: + cam_can = CanBus(None, False, fingerprint).CAM + fingerprint[cam_can] = hda2_steering_messages + CP = CarInterface.get_params(CAR.KIA_EV6, fingerprint, [], False, False) + assert bool(CP.flags & HyundaiFlags.CANFD_HDA2) == hda2 # radar available for radar in (True, False): fingerprint = gen_empty_fingerprint() if radar: fingerprint[1][RADAR_START_ADDR] = 8 - CP = CarInterface.get_params(CAR.HYUNDAI_SONATA, fingerprint, car_fw, False, False) + CP = CarInterface.get_params(CAR.HYUNDAI_SONATA, fingerprint, [], False, False) assert CP.radarUnavailable != radar def test_can_features(self): From 331e415f618c6d68324c5576699a79de89dc5e81 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 26 Sep 2024 17:57:44 -0400 Subject: [PATCH 5/8] comment --- opendbc/car/hyundai/interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/interface.py b/opendbc/car/hyundai/interface.py index 2972cfc146..11a5f2e8b8 100644 --- a/opendbc/car/hyundai/interface.py +++ b/opendbc/car/hyundai/interface.py @@ -18,7 +18,7 @@ class CarInterface(CarInterfaceBase): def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams: ret.carName = "hyundai" - # Check the CAM bus fingerprint for known HDA2 steering messages (0x50 or 0x110), that indicate an HDA2 car + # Check the CAM bus fingerprint for known HDA2 steering messages (0x50 or 0x110) to determine if it is an HDA2 car. # The hda2 flag to initialize CanBus is not critical here since we only care about CAM bus steering messages. cam_can = CanBus(None, False, fingerprint).CAM hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] From db921e29069ee952471b62db633e99ee81ff6472 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 26 Sep 2024 17:59:48 -0400 Subject: [PATCH 6/8] simplify --- opendbc/car/hyundai/tests/test_hyundai.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc/car/hyundai/tests/test_hyundai.py index d02668dcec..e826868cc8 100644 --- a/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc/car/hyundai/tests/test_hyundai.py @@ -46,11 +46,10 @@ class TestHyundaiFingerprint: def test_feature_detection(self): # HDA2 for hda2 in (True, False): - hda2_steering_messages = [0x50, 0x110] fingerprint = gen_empty_fingerprint() if hda2: cam_can = CanBus(None, False, fingerprint).CAM - fingerprint[cam_can] = hda2_steering_messages + fingerprint[cam_can] = [0x50, 0x110] # HDA2 steering messages CP = CarInterface.get_params(CAR.KIA_EV6, fingerprint, [], False, False) assert bool(CP.flags & HyundaiFlags.CANFD_HDA2) == hda2 From 7b8f46c9ffe558ec7d05bb71a0e7e0b82c3d6b42 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 26 Sep 2024 22:45:17 -0400 Subject: [PATCH 7/8] move hda2 to the end of arg so it's cleaner --- opendbc/car/hyundai/hyundaicanfd.py | 5 ++--- opendbc/car/hyundai/interface.py | 5 ++--- opendbc/car/hyundai/tests/test_hyundai.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 82ed0828b7..d3488ff531 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -4,12 +4,11 @@ class CanBus(CanBusBase): - def __init__(self, CP, hda2=None, fingerprint=None) -> None: + def __init__(self, CP, fingerprint=None, hda2=None) -> None: super().__init__(CP, fingerprint) if hda2 is None: - assert CP is not None - hda2 = CP.flags & HyundaiFlags.CANFD_HDA2.value + hda2 = CP.flags & HyundaiFlags.CANFD_HDA2.value if CP is not None else False # On the CAN-FD platforms, the LKAS camera is on both A-CAN and E-CAN. HDA2 cars # have a different harness than the HDA1 and non-HDA variants in order to split diff --git a/opendbc/car/hyundai/interface.py b/opendbc/car/hyundai/interface.py index 11a5f2e8b8..facc7b0fb1 100644 --- a/opendbc/car/hyundai/interface.py +++ b/opendbc/car/hyundai/interface.py @@ -19,11 +19,10 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime ret.carName = "hyundai" # Check the CAM bus fingerprint for known HDA2 steering messages (0x50 or 0x110) to determine if it is an HDA2 car. - # The hda2 flag to initialize CanBus is not critical here since we only care about CAM bus steering messages. - cam_can = CanBus(None, False, fingerprint).CAM + cam_can = CanBus(None, fingerprint).CAM hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] - CAN = CanBus(None, hda2, fingerprint) + CAN = CanBus(None, fingerprint, hda2) if candidate in CANFD_CAR: # Shared configuration for CAN-FD cars diff --git a/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc/car/hyundai/tests/test_hyundai.py index e826868cc8..2ac608ef3d 100644 --- a/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc/car/hyundai/tests/test_hyundai.py @@ -48,7 +48,7 @@ def test_feature_detection(self): for hda2 in (True, False): fingerprint = gen_empty_fingerprint() if hda2: - cam_can = CanBus(None, False, fingerprint).CAM + cam_can = CanBus(None, fingerprint).CAM fingerprint[cam_can] = [0x50, 0x110] # HDA2 steering messages CP = CarInterface.get_params(CAR.KIA_EV6, fingerprint, [], False, False) assert bool(CP.flags & HyundaiFlags.CANFD_HDA2) == hda2 From f0a4a5001bd7a6ea8fe97c9e64c9117993789862 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 26 Sep 2024 22:50:35 -0400 Subject: [PATCH 8/8] Update opendbc/car/hyundai/interface.py Co-authored-by: Jason Young <46612682+jyoung8607@users.noreply.github.com> --- opendbc/car/hyundai/interface.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/opendbc/car/hyundai/interface.py b/opendbc/car/hyundai/interface.py index facc7b0fb1..5acc7a23cd 100644 --- a/opendbc/car/hyundai/interface.py +++ b/opendbc/car/hyundai/interface.py @@ -18,10 +18,8 @@ class CarInterface(CarInterfaceBase): def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams: ret.carName = "hyundai" - # Check the CAM bus fingerprint for known HDA2 steering messages (0x50 or 0x110) to determine if it is an HDA2 car. cam_can = CanBus(None, fingerprint).CAM hda2 = 0x50 in fingerprint[cam_can] or 0x110 in fingerprint[cam_can] - CAN = CanBus(None, fingerprint, hda2) if candidate in CANFD_CAR: