diff --git a/selfdrive/car/toyota/tests/test_toyota.py b/selfdrive/car/toyota/tests/test_toyota.py index aa8e4029bb..94fd1b3602 100755 --- a/selfdrive/car/toyota/tests/test_toyota.py +++ b/selfdrive/car/toyota/tests/test_toyota.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import random from hypothesis import given, settings, strategies as st import unittest @@ -131,8 +132,18 @@ class TestToyotaFingerprint(unittest.TestCase): CAR.LEXUS_ES_TSS2, CAR.LEXUS_RX_TSS2, CAR.CHR, + CAR.CHRH, CAR.COROLLA_TSS2, + CAR.COROLLAH_TSS2, + CAR.RAV4_TSS2, + CAR.RAV4H_TSS2, + CAR.LEXUS_NX_TSS2, + CAR.LEXUS_NXH, + CAR.LEXUS_NXH_TSS2, + CAR.LEXUS_NX, + CAR.LEXUS_RXH_TSS2, } + # excluded_platforms = {_car for _car in FW_VERSIONS} platforms_with_shared_codes = set() for platform, fw_by_addr in FW_VERSIONS.items(): @@ -148,8 +159,10 @@ class TestToyotaFingerprint(unittest.TestCase): if len(matches) == 1: self.assertEqual(list(matches)[0], platform) else: + print('matches', platform, matches) platforms_with_shared_codes.add(platform) + print(len(platforms_with_shared_codes), len(excluded_platforms)) self.assertEqual(platforms_with_shared_codes, excluded_platforms, (len(platforms_with_shared_codes), len(FW_VERSIONS))) diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index 4379d9d622..a760a2549f 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -301,17 +301,27 @@ def match_fw_to_car_fuzzy(live_fw_versions) -> Set[str]: # Check part number + platform code + major version matches for any found versions # Then check that sub-version for the above is within range (splits model years) - for found_platform_code, found_sub_versions in found_platform_codes.items(): - if found_platform_code in expected_platform_codes: - expected_sub_versions = expected_platform_codes[found_platform_code] - # Check any sub-version within range in the database for this part-platform-version combo - if any(min(expected_sub_versions) <= found_sub_version <= max(expected_sub_versions) for - found_sub_version in found_sub_versions): - valid_found_ecus.add(addr) - break + # Sub-versions are incremented for minor recalls, do not need to be checked. + # Platform codes and major versions change for different physical parts. For example, + # engine's major version describes actual Toyota engine type. + + if not any(found_platform_code in expected_platform_codes for found_platform_code in found_platform_codes): + break + valid_found_ecus.add(addr) + + # for found_platform_code, found_sub_versions in found_platform_codes.items(): + # if found_platform_code in expected_platform_codes: + # expected_sub_versions = expected_platform_codes[found_platform_code] + # + # # Check any sub-version within range in the database for this part-platform-version combo + # if any(min(expected_sub_versions) <= found_sub_version <= max(expected_sub_versions) for + # found_sub_version in found_sub_versions): + # valid_found_ecus.add(addr) + # break # If all live ECUs pass all checks for candidate, add it as a match + # print(candidate, valid_expected_ecus, valid_found_ecus) if valid_expected_ecus.issubset(valid_found_ecus): candidates.add(candidate) @@ -333,9 +343,9 @@ LONG_FW_PATTERN = re.compile(b'(?P[A-Z0-9]{5})(?P[A-Z0-9]{2})(?P FW_LEN_CODE = re.compile(b'^[\x01-\x03]') # highest seen is 3 chunks, 16 bytes each FW_CHUNK_LEN = 16 -# List of ECUs expected to have platform codes -# Engine is not well understood at this time (lots of variability in major version) -PLATFORM_CODE_ECUS = [Ecu.abs, Ecu.eps, Ecu.dsu, Ecu.fwdCamera, Ecu.fwdRadar] +# List of ECUs that are most unique across openpilot platforms +# TODO: use hybrid ECU, splits similar ICE and hybrid variants +PLATFORM_CODE_ECUS = [Ecu.abs, Ecu.eps, Ecu.fwdCamera] # Some ECUs that use KWP2000 have their FW versions on non-standard data identifiers.