From cbe1d55c42cdbd28ea1e814afaac1d495beba9fc Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 9 Jun 2023 16:42:05 -0700 Subject: [PATCH] revert back to what we did before --- selfdrive/car/fw_versions.py | 74 ++++++++------------- selfdrive/car/hyundai/tests/test_hyundai.py | 2 +- 2 files changed, 29 insertions(+), 47 deletions(-) diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index b4bafed366..008295e458 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -81,52 +81,34 @@ def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None): for platform_code in config.fuzzy_get_platform_codes(fws): all_platform_codes[(addr[1], addr[2], platform_code)].append(candidate) - # TODO: we really want to support both ways of fuzzy FP, but we don't want to partially match with both. - # meaning we get one radar platform code match, no camera platform code match, and a random exact FW ECU match. - # when matching with platform codes, it should be all ECUs specified in the config - # and if we don't match all ECUs with platform codes, we should fall back on normal full FW fuzzy matching, not mixing both - # UPDATE: i'm reframing this such that fuzzy FP adds matches, not replaces any logic or matches or minimum count. - # makes it easier to understand/less complex and doesn't try to fix general issues with fuzzy FP by masking over it - # by splitting up fuzzy FP into exact matching vs. platform code matching. that should be handled explicitly. - # there may be issues with this approach, but they weren't already there, and this PR is trying to do a lot already - def fuzzy_match(use_config): - matched_ecus = set() - candidate = None - for addr, versions in fw_versions_dict.items(): - ecu_key = (addr[0], addr[1]) - for version in versions: - candidates = set() - if use_config: - # Returns one or none, all cars that have this platform code - for platform_code in config.fuzzy_get_platform_codes([version]): - candidates = all_platform_codes[(*ecu_key, platform_code)] - else: - # All cars that have this FW response on the specified address - candidates = all_fw_versions[(*ecu_key, version)] - - if len(candidates) == 1: - matched_ecus.add(ecu_key) - if candidate is None: - candidate = candidates[0] - # We uniquely matched two different cars. No fuzzy match possible - elif candidate != candidates[0]: - return None, matched_ecus - - return candidate, matched_ecus - - # Try to fuzzy fingerprint both with and without platform codes independently - for use_config in {config.fuzzy_get_platform_codes is not None}: - candidate, matched_ecus = fuzzy_match(use_config) - - if candidate is None: - continue - - # Note that it is possible to match to a candidate without all its ECUs being present - # if there are enough matches. FIXME: parameterize this or require all ECUs to exist like exact matching - if len(matched_ecus) >= config.fuzzy_min_match_count: - if log: - cloudlog.error(f"Fingerprinted {candidate} using fuzzy match. {len(matched_ecus)} matching ECUs") - return {candidate} + matched_ecus = set() + candidate = None + for addr, versions in fw_versions_dict.items(): + ecu_key = (addr[0], addr[1]) + for version in versions: + # All cars that have this FW response on the specified address + candidates = all_fw_versions[(*ecu_key, version)] + + # If not one candidate for this ECU and version, try platform codes + dates + if len(candidates) != 1 and config.fuzzy_get_platform_codes is not None: + # Returns one or none, all cars that have this platform code + for platform_code in config.fuzzy_get_platform_codes([version]): + candidates = all_platform_codes[(*ecu_key, platform_code)] + + if len(candidates) == 1: + matched_ecus.add(ecu_key) + if candidate is None: + candidate = candidates[0] + # We uniquely matched two different cars. No fuzzy match possible + elif candidate != candidates[0]: + return set() + + # Note that it is possible to match to a candidate without all its ECUs being present + # if there are enough matches. FIXME: parameterize this or require all ECUs to exist like exact matching + if len(matched_ecus) >= config.fuzzy_min_match_count: + if log: + cloudlog.error(f"Fingerprinted {candidate} using fuzzy match. {len(matched_ecus)} matching ECUs") + return {candidate} return set() diff --git a/selfdrive/car/hyundai/tests/test_hyundai.py b/selfdrive/car/hyundai/tests/test_hyundai.py index b9d3a1f527..6254a5878f 100755 --- a/selfdrive/car/hyundai/tests/test_hyundai.py +++ b/selfdrive/car/hyundai/tests/test_hyundai.py @@ -86,7 +86,7 @@ class TestHyundaiFingerprint(TestFwFingerprintBase): b'ON-1904', b'ON-1905', b'ON-1906', b'ON-1907'}) def test_excluded_platforms_new(self): - # Asserts a list of platforms that will not fuzzy fingerprint due to shared platform codes + # Asserts a list of platforms that will not fuzzy fingerprint with platform codes due to them being shared. # This list can be shrunk as we combine platforms and detect features excluded_platforms = { CAR.GENESIS_G70,