From 5d228d6a4414680c8851b45316fc7d4875de6ab2 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 13 Jan 2023 23:07:41 -0800 Subject: [PATCH] use the function --- selfdrive/car/fw_query_definitions.py | 2 +- selfdrive/car/fw_versions.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/selfdrive/car/fw_query_definitions.py b/selfdrive/car/fw_query_definitions.py index 1f35c17853..2b161b2f8d 100755 --- a/selfdrive/car/fw_query_definitions.py +++ b/selfdrive/car/fw_query_definitions.py @@ -68,4 +68,4 @@ class FwQueryConfig: # Ecus added for data collection, not to be fingerprinted on extra_ecus: List[Tuple[capnp.lib.capnp._EnumModule, int, Optional[int]]] = field(default_factory=list) # A function that each make can provide to fuzzy fingerprint reliably on that make - match_fw_to_car_fuzzy: Callable = None + match_fw_to_car_fuzzy: Optional[Callable] = None diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index f4d92ab960..7ac5f80f32 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -44,7 +44,11 @@ def get_brand_addrs(): return brand_addrs -def match_fw_to_car_fuzzy(fw_versions_dict, log=True, exclude=None): +def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None): + # If make specifies a fuzzy matching function, use that instead + if config is not None and config.match_fw_to_car_fuzzy is not None: + return config.match_fw_to_car_fuzzy(fw_versions_dict) + """Do a fuzzy FW match. This function will return a match, and the number of firmware version that were matched uniquely to that specific car. If multiple ECUs uniquely match to different cars the match is rejected.""" @@ -90,7 +94,7 @@ def match_fw_to_car_fuzzy(fw_versions_dict, log=True, exclude=None): return set() -def match_fw_to_car_exact(fw_versions_dict): +def match_fw_to_car_exact(fw_versions_dict, config): """Do an exact FW match. Returns all cars that match the given FW versions for a list of "essential" ECUs. If an ECU is not considered essential the FW version can be missing to get a fingerprint, but if it's present it @@ -100,7 +104,6 @@ def match_fw_to_car_exact(fw_versions_dict): for candidate, fws in candidates.items(): for ecu, expected_versions in fws.items(): - config = FW_QUERY_CONFIGS[MODEL_TO_BRAND[candidate]] ecu_type = ecu[0] addr = ecu[1:] @@ -138,7 +141,8 @@ def match_fw_to_car(fw_versions, allow_exact=True, allow_fuzzy=True): matches = set() for brand in VERSIONS.keys(): fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand) - matches |= match_func(fw_versions_dict) + config = FW_QUERY_CONFIGS[brand] + matches |= match_func(fw_versions_dict, config) if len(matches): return exact_match, matches