diff --git a/selfdrive/car/toyota/tests/test_toyota.py b/selfdrive/car/toyota/tests/test_toyota.py index 72469f52d1..b5db081498 100755 --- a/selfdrive/car/toyota/tests/test_toyota.py +++ b/selfdrive/car/toyota/tests/test_toyota.py @@ -11,7 +11,7 @@ from selfdrive.car.fw_versions import build_fw_dict # EV_CAR, FW_QUERY_CONFIG, FW_VERSIONS, LEGACY_SAFETY_MODE_CAR, \ # PLATFORM_CODE_ECUS, get_platform_codes from selfdrive.car.toyota.values import TSS2_CAR, ANGLE_CONTROL_CAR, FW_VERSIONS, FW_QUERY_CONFIG, EV_HYBRID_CAR, \ - LONG_FW_PATTERN, FW_LEN_CODE, get_platform_codes # FW_PATTERN_V3 + LONG_FW_PATTERN, FW_LEN_CODE, get_platform_codes from openpilot.selfdrive.car.toyota.values import CAR, DBC, TSS2_CAR, ANGLE_CONTROL_CAR, RADAR_ACC_CAR, FW_VERSIONS Ecu = car.CarParams.Ecu @@ -60,11 +60,8 @@ class TestToyotaFingerprint(unittest.TestCase): # get_platform_codes(fws) def test_fw_pattern(self): - # return + """Asserts all ECUs can be parsed""" for car_model, ecus in FW_VERSIONS.items(): - # print() - # print(car_model) - for ecu, fws in ecus.items(): for fw in fws: @@ -72,74 +69,6 @@ class TestToyotaFingerprint(unittest.TestCase): ret = get_platform_codes([fw]) self.assertTrue(len(ret)) print('ret', ret) - continue - match = FW_PATTERN.search(fw) - length = FW_LEN_CODE.search(fw) - if ecu[0] in (Ecu.fwdRadar, Ecu.fwdCamera): - assert (length is None) == (car_model not in TSS2_CAR), (car_model, ecu, fw) - if ecu[0] in (Ecu.engine,): - assert length is not None - # assert match is not None, (ecu, fw, match) - # print(fw, match) - - # def test_fw_debugging(self): - # for car_model, ecus in FW_VERSIONS.items(): - # print() - # print(car_model) - # cam_len_code = False - # eng_len_code = False - # - # for ecu, fws in ecus.items(): - # if ecu[0] in (Ecu.fwdRadar, Ecu.fwdCamera): - # cam_len_code |= all(f[0] < 4 for f in fws) - # if ecu[0] in (Ecu.engine, Ecu.abs): - # eng_len_code |= all(1 < f[0] < 4 for f in fws) - # print(ecu, eng_len_code) - # - # if (car_model in TSS2_CAR) != cam_len_code: - # print(car_model, car_model in TSS2_CAR, cam_len_code) - # - # if (car_model in EV_HYBRID_CAR) != eng_len_code: - # print('MISMATCH', car_model, car_model in EV_HYBRID_CAR, eng_len_code) - - def test_shared_fw(self): - return - all_fw = defaultdict(set) - for car_model, ecus in FW_VERSIONS.items(): - # print() - # print(car_model) - - for ecu, fws in ecus.items(): - parts = set() - for fw in fws: - length, part = FW_PATTERN_V3.search(fw).groups() - parts.add(part) - - all_fw[(ecu[1], fw)].add(car_model) - if len(parts) > 1: - print('uoh' ,car_model, ecu, parts) - - # print(all_fw) - - # shared abs (or whatever is in the continue statement) - shared = defaultdict(set) - - for car_model, ecus in FW_VERSIONS.items(): - # print() - # print(car_model) - - for ecu, fws in ecus.items(): - if ecu[0] != Ecu.abs: - continue - for fw in fws: - if len(all_fw[ecu[1], fw]) > 1: - shared[car_model] |= all_fw[ecu[1], fw] - # print(car_model, all_fw[ecu[1], fw]) - # # all_fw[(ecu[1], fw)].add(car_model) - - print(shared) - print(len(shared)) - # Tests for platform codes, part numbers, and FW dates which Hyundai will use to fuzzy # fingerprint in the absence of full FW matches: @@ -245,6 +174,7 @@ class TestToyotaFingerprint(unittest.TestCase): platforms_with_shared_codes = set() for platform, fw_by_addr in FW_VERSIONS.items(): + print('platform', platform) car_fw = [] for ecu, fw_versions in fw_by_addr.items(): ecu_name, addr, sub_addr = ecu @@ -254,6 +184,7 @@ class TestToyotaFingerprint(unittest.TestCase): CP = car.CarParams.new_message(carFw=car_fw) matches = FW_QUERY_CONFIG.match_fw_to_car_fuzzy(build_fw_dict(CP.carFw)) + print('matches', matches) if len(matches) == 1: self.assertEqual(list(matches)[0], platform) else: diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index e9b4869861..ed33fe15bd 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -302,7 +302,7 @@ def match_fw_to_car_fuzzy(live_fw_versions) -> Set[str]: candidates = set() for candidate, fws in FW_VERSIONS.items(): - print('\n\ncandidate:', candidate) + # print('\n\ncandidate:', candidate) # Keep track of ECUs which pass all checks (platform codes, within date range) valid_found_ecus = set() valid_expected_ecus = {ecu[1:] for ecu in fws if ecu[0] in PLATFORM_CODE_ECUS} @@ -322,7 +322,7 @@ def match_fw_to_car_fuzzy(live_fw_versions) -> Set[str]: found_platform_codes = {code for code, _ in codes} # found_dates = {date for _, date in codes if date is not None} - print(ecu, expected_platform_codes, found_platform_codes) + # print(ecu, expected_platform_codes, found_platform_codes) # Check platform code + part number matches for any found versions if not any(found_platform_code in expected_platform_codes for found_platform_code in found_platform_codes): @@ -347,16 +347,14 @@ def match_fw_to_car_fuzzy(live_fw_versions) -> Set[str]: return candidates - fuzzy_platform_blacklist -# # Regex patterns for parsing platform code, FW date, and part number from FW versions +# Regex patterns for parsing platform code, FW date, and part number from FW versions SHORT_FW_PATTERN = re.compile(b'(?P[A-Z0-9]{2})(?P[A-Z0-9]{2})(?P[A-Z0-9]{4})') MEDIUM_FW_PATTERN = re.compile(b'(?P[A-Z0-9]{5})(?P[A-Z0-9]{2})(?P[A-Z0-9]{3})') LONG_FW_PATTERN = re.compile(b'(?P[A-Z0-9]{5})(?P[A-Z0-9]{2})(?P[A-Z0-9]{2})(?P[A-Z0-9]{3})') FW_LEN_CODE = re.compile(b'^[\x01-\x05]') # 5 chunks max. highest seen is 3 chunks, 16 bytes each -# List of ECUs expected to have platform codes, camera and radar should exist on all cars +# List of ECUs expected to have platform codes PLATFORM_CODE_ECUS = [Ecu.abs, Ecu.engine, Ecu.eps, Ecu.dsu, Ecu.fwdCamera, Ecu.fwdRadar] -# So far we've only seen dates in fwdCamera -# DATE_FW_ECUS = [Ecu.fwdCamera] # Some ECUs that use KWP2000 have their FW versions on non-standard data identifiers. # Toyota diagnostic software first gets the supported data ids, then queries them one by one. @@ -431,8 +429,6 @@ FW_QUERY_CONFIG = FwQueryConfig( ) # FW_PATTERN = re.compile(b'[0-9]{4}[0-9A-Z][0-9A-Z]') -# FW_PATTERN2 = re.compile(br'(?<=\\x[0-9]{2})[0-9A-Z]{5}|^[0-9A-Z]{5}') -# FW_PATTERN_V3 = re.compile(b'(?P^[\x00-\x0F])?(?P[0-9A-Z]{4})') FW_VERSIONS = { CAR.AVALON: {