diff --git a/selfdrive/car/fw_query_definitions.py b/selfdrive/car/fw_query_definitions.py index c10fd2c138..11a4d10c2c 100755 --- a/selfdrive/car/fw_query_definitions.py +++ b/selfdrive/car/fw_query_definitions.py @@ -77,7 +77,7 @@ class FwQueryConfig: # Brand-specific fuzzy fingerprinting options: # The minimum number of version matches to fuzzy fingerprint - fuzzy_min_match_count: Optional[int] = None + fuzzy_min_match_count: int = 2 # A function to get uniquely identifiable codes for a version # TODO: take list of versions and return set of platform codes fuzzy_get_platform_codes: Optional[Callable] = None diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index cae07e6b77..6e284ed081 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -64,7 +64,7 @@ def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None): # Build lookup table from (addr, sub_addr, fw) to list of candidate cars all_fw_versions = defaultdict(set) - all_fw_versions_prefixes = defaultdict(set) + all_platform_codes = defaultdict(set) for candidate, fw_by_addr in FW_VERSIONS.items(): if MODEL_TO_BRAND[candidate] != 'hyundai': continue @@ -80,14 +80,16 @@ def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None): for f in fws: all_fw_versions[(addr[1], addr[2], f)].add(candidate) - platform_codes = get_platform_codes([f]) - assert len(platform_codes) < 2 - if len(platform_codes): - print(platform_codes, f) - platform_code = list(platform_codes)[0] - all_fw_versions_prefixes[(addr[1], addr[2], platform_code)].add(candidate) + # Add platform codes to lookup dict if config specifies a function + if config.fuzzy_get_platform_codes is not None: + platform_codes = get_platform_codes([f]) + assert len(platform_codes) < 2 # TODO: remove and test? + if len(platform_codes) == 1: + print(platform_codes, f) + platform_code = list(platform_codes)[0] + all_platform_codes[(addr[1], addr[2], platform_code)].add(candidate) - print(all_fw_versions_prefixes) + print(all_platform_codes) match_count = 0 candidate = None for addr, versions in fw_versions_dict.items(): @@ -105,7 +107,7 @@ def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None): platform_code = list(platform_codes)[0] key = (addr[0], addr[1], platform_code) print('key', key) - candidates = all_fw_versions_prefixes[key] + candidates = all_platform_codes[key] print('second candidates', candidates) print() @@ -118,7 +120,7 @@ def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None): return set() print('match_count', match_count) - if match_count >= 1: + if match_count >= config.fuzzy_min_match_count: if log: cloudlog.error(f"Fingerprinted {candidate} using fuzzy match. {match_count} matching ECUs") return {candidate} @@ -264,7 +266,7 @@ def get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs, timeout=0.1, num_pand car_fw = get_fw_versions(logcan, sendcan, query_brand=brand, timeout=timeout, num_pandas=num_pandas, debug=debug, progress=progress) all_car_fw.extend(car_fw) # Try to match using FW returned from this brand only - matches = match_fw_to_car_exact(build_fw_dict(car_fw)) + matches = match_fw_to_car_exact(build_fw_dict(car_fw), None) if len(matches) == 1: break diff --git a/selfdrive/car/hyundai/values.py b/selfdrive/car/hyundai/values.py index ed8e947ffe..bfbbacba68 100644 --- a/selfdrive/car/hyundai/values.py +++ b/selfdrive/car/hyundai/values.py @@ -448,6 +448,11 @@ FW_QUERY_CONFIG = FwQueryConfig( (Ecu.hvac, 0x7b3, None), # HVAC Control Assembly (Ecu.cornerRadar, 0x7b7, None), ], + # Just one platform code match from radar or camera is enough + fuzzy_min_match_count=1, + fuzzy_get_platform_codes=get_platform_codes, + + # TODO: old, remove match_fw_to_car_fuzzy=match_fw_to_hyundai_fuzzy, )