diff --git a/selfdrive/car/ford/tests/print_platform_codes.py b/selfdrive/car/ford/tests/print_platform_codes.py index 670199980a..20e7250825 100755 --- a/selfdrive/car/ford/tests/print_platform_codes.py +++ b/selfdrive/car/ford/tests/print_platform_codes.py @@ -1,30 +1,28 @@ #!/usr/bin/env python3 from collections import defaultdict -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.ford.values import get_platform_codes from openpilot.selfdrive.car.ford.fingerprints import FW_VERSIONS -Ecu = car.CarParams.Ecu -ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} - +Ecu = CarParams.Ecu if __name__ == "__main__": cars_for_code: defaultdict = defaultdict(lambda: defaultdict(set)) for car_model, ecus in FW_VERSIONS.items(): print(car_model) - for ecu in sorted(ecus, key=lambda x: int(x[0])): + for ecu in sorted(ecus): platform_codes = get_platform_codes(ecus[ecu]) for code in platform_codes: cars_for_code[ecu][code].add(car_model) - print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):') + print(f' (Ecu.{ecu[0]}, {hex(ecu[1])}, {ecu[2]}):') print(f' Codes: {sorted(platform_codes)}') print() print('\nCar models vs. platform codes:') for ecu, codes in cars_for_code.items(): - print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):') + print(f' (Ecu.{ecu[0]}, {hex(ecu[1])}, {ecu[2]}):') for code, cars in codes.items(): print(f' {code!r}: {sorted(map(str, cars))}') diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 9bb8e7ecf5..c3590ebb2e 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -1,5 +1,6 @@ from cereal import car from panda import Panda +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_CAR, CAMERA_SCC_CAR, CANFD_RADAR_SCC_CAR, \ CANFD_UNSUPPORTED_LONGITUDINAL_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, \ @@ -9,7 +10,7 @@ from openpilot.selfdrive.car import create_button_events, get_safety_config from openpilot.selfdrive.car.interfaces import CarInterfaceBase from openpilot.selfdrive.car.disable_ecu import disable_ecu -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu ButtonType = car.CarState.ButtonEvent.Type EventName = car.CarEvent.EventName ENABLE_BUTTONS = (Buttons.RES_ACCEL, Buttons.SET_DECEL, Buttons.CANCEL) diff --git a/selfdrive/car/hyundai/tests/print_platform_codes.py b/selfdrive/car/hyundai/tests/print_platform_codes.py index f641535678..80e9bfad89 100755 --- a/selfdrive/car/hyundai/tests/print_platform_codes.py +++ b/selfdrive/car/hyundai/tests/print_platform_codes.py @@ -1,22 +1,21 @@ #!/usr/bin/env python3 -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.hyundai.values import PLATFORM_CODE_ECUS, get_platform_codes from openpilot.selfdrive.car.hyundai.fingerprints import FW_VERSIONS -Ecu = car.CarParams.Ecu -ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} +Ecu = CarParams.Ecu if __name__ == "__main__": for car_model, ecus in FW_VERSIONS.items(): print() print(car_model) - for ecu in sorted(ecus, key=lambda x: int(x[0])): + for ecu in sorted(ecus): if ecu[0] not in PLATFORM_CODE_ECUS: continue platform_codes = get_platform_codes(ecus[ecu]) codes = {code for code, _ in platform_codes} dates = {date for _, date in platform_codes if date is not None} - print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):') + print(f' (Ecu.{ecu[0]}, {hex(ecu[1])}, {ecu[2]}):') print(f' Codes: {codes}') print(f' Dates: {dates}') diff --git a/selfdrive/car/hyundai/tests/test_hyundai.py b/selfdrive/car/hyundai/tests/test_hyundai.py index b3dca09d98..aa79e9f36c 100644 --- a/selfdrive/car/hyundai/tests/test_hyundai.py +++ b/selfdrive/car/hyundai/tests/test_hyundai.py @@ -2,12 +2,15 @@ from hypothesis import settings, given, strategies as st import pytest +from openpilot.selfdrive.car import gen_empty_fingerprint from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.fw_versions import build_fw_dict +from openpilot.selfdrive.car.hyundai.interface import CarInterface +from openpilot.selfdrive.car.hyundai.radar_interface import RADAR_START_ADDR from openpilot.selfdrive.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, \ UNSUPPORTED_LONGITUDINAL_CAR, PLATFORM_CODE_ECUS, HYUNDAI_VERSION_REQUEST_LONG, \ - get_platform_codes + HyundaiFlags, get_platform_codes from openpilot.selfdrive.car.hyundai.fingerprints import FW_VERSIONS Ecu = CarParams.Ecu @@ -39,6 +42,21 @@ CANFD_EXPECTED_ECUS = {Ecu.fwdCamera, Ecu.fwdRadar} 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 + + # 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) + assert CP.radarUnavailable != radar + def test_can_features(self): # Test no EV/HEV in any gear lists (should all use ELECT_GEAR) assert set.union(*CAN_GEARS.values()) & (HYBRID_CAR | EV_CAR) == set() diff --git a/selfdrive/car/subaru/tests/test_subaru.py b/selfdrive/car/subaru/tests/test_subaru.py index 33040442b6..f81c392679 100644 --- a/selfdrive/car/subaru/tests/test_subaru.py +++ b/selfdrive/car/subaru/tests/test_subaru.py @@ -1,10 +1,5 @@ -from cereal import car from openpilot.selfdrive.car.subaru.fingerprints import FW_VERSIONS -Ecu = car.CarParams.Ecu - -ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} - class TestSubaruFingerprint: def test_fw_version_format(self): @@ -13,4 +8,3 @@ class TestSubaruFingerprint: fw_size = len(fws[0]) for fw in fws: assert len(fw) == fw_size, f"{platform} {ecu}: {len(fw)} {fw_size}" - diff --git a/selfdrive/car/toyota/tests/print_platform_codes.py b/selfdrive/car/toyota/tests/print_platform_codes.py index 9ec7a14cd3..495a9f7242 100755 --- a/selfdrive/car/toyota/tests/print_platform_codes.py +++ b/selfdrive/car/toyota/tests/print_platform_codes.py @@ -1,19 +1,15 @@ #!/usr/bin/env python3 from collections import defaultdict -from cereal import car from openpilot.selfdrive.car.toyota.values import PLATFORM_CODE_ECUS, get_platform_codes from openpilot.selfdrive.car.toyota.fingerprints import FW_VERSIONS -Ecu = car.CarParams.Ecu -ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} - if __name__ == "__main__": parts_for_ecu: dict = defaultdict(set) cars_for_code: dict = defaultdict(lambda: defaultdict(set)) for car_model, ecus in FW_VERSIONS.items(): print() print(car_model) - for ecu in sorted(ecus, key=lambda x: int(x[0])): + for ecu in sorted(ecus): if ecu[0] not in PLATFORM_CODE_ECUS: continue @@ -21,15 +17,15 @@ if __name__ == "__main__": parts_for_ecu[ecu] |= {code.split(b'-')[0] for code in platform_codes if code.count(b'-') > 1} for code in platform_codes: cars_for_code[ecu][b'-'.join(code.split(b'-')[:2])] |= {car_model} - print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):') + print(f' (Ecu.{ecu[0]}, {hex(ecu[1])}, {ecu[2]}):') print(f' Codes: {platform_codes}') print('\nECU parts:') for ecu, parts in parts_for_ecu.items(): - print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}): {parts}') + print(f' (Ecu.{ecu[0]}, {hex(ecu[1])}, {ecu[2]}): {parts}') print('\nCar models vs. platform codes (no major versions):') for ecu, codes in cars_for_code.items(): - print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):') + print(f' (Ecu.{ecu[0]}, {hex(ecu[1])}, {ecu[2]}):') for code, cars in codes.items(): print(f' {code!r}: {sorted(cars)}')