Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyundai CAN-FD: Add CAN fingerprint fallback checks for HDA2 detection #1285

Merged
merged 9 commits into from
Sep 27, 2024
5 changes: 2 additions & 3 deletions opendbc/car/hyundai/hyundaicanfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions opendbc/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ class CarInterface(CarInterfaceBase):
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams:
ret.carName = "hyundai"

hda2 = Ecu.adas in [fw.ecu for fw in car_fw]
CAN = CanBus(None, hda2, fingerprint)
# 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:
# Shared configuration for CAN-FD cars
Expand Down
14 changes: 9 additions & 5 deletions opendbc/car/hyundai/tests/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -44,17 +45,20 @@
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):
fingerprint = gen_empty_fingerprint()
if hda2:
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

# 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):
Expand Down
Loading