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
6 changes: 5 additions & 1 deletion opendbc/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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]
# 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]

jyoung8607 marked this conversation as resolved.
Show resolved Hide resolved
CAN = CanBus(None, hda2, fingerprint)

if candidate in CANFD_CAR:
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, False, 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
jyoung8607 marked this conversation as resolved.
Show resolved Hide resolved

# 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)
jyoung8607 marked this conversation as resolved.
Show resolved Hide resolved
assert CP.radarUnavailable != radar

def test_can_features(self):
Expand Down
Loading