From 3f420d31e844d7fff2af848951777700c4c96368 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 12 Aug 2022 23:36:50 -0700 Subject: [PATCH] Revert "FPv2: fingerprint on all FW combinations" (#25417) * Revert "FPv2: fingerprint on all FW combinations (#25204)" This reverts commit c7e0622fa5bbf3ed8b000c86666f54f2b0a8c63d. * Revert "Revert "FPv2: fingerprint on all FW combinations (#25204)"" This reverts commit bb68b7bc1c28ba8c67f3051b8f99fabc42e85771. * For breaking, match only with current brand's FW * Add comment for fuzzy matching * fingerprint (online) only using FW from that brand * test_fw_query_on_routes fingerprints like online * extend match_fw_to_car to work for test_fw_query_on_routes * Apply suggestions from code review old-commit-hash: 45cfcfa3bba6ae75c89114e58de445eaef4c5627 --- selfdrive/car/fw_versions.py | 19 +++++++++++-------- selfdrive/debug/test_fw_query_on_routes.py | 7 +++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index 0ed8cc5425..9d2fd11b45 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -337,17 +337,21 @@ def match_fw_to_car_exact(fw_versions_dict): return set(candidates.keys()) - set(invalid) -def match_fw_to_car(fw_versions, allow_fuzzy=True): +def match_fw_to_car(fw_versions, allow_exact=True, allow_fuzzy=True): # Try exact matching first - exact_matches = [(True, match_fw_to_car_exact)] + exact_matches = [] + if allow_exact: + exact_matches = [(True, match_fw_to_car_exact)] if allow_fuzzy: exact_matches.append((False, match_fw_to_car_fuzzy)) + brands = get_interface_attr('FW_VERSIONS', ignore_none=True).keys() for exact_match, match_func in exact_matches: - # TODO: For each brand, attempt to fingerprint using only FW returned from its queries + # For each brand, attempt to fingerprint using all FW returned from its queries matches = set() - fw_versions_dict = build_fw_dict(fw_versions, filter_brand=None) - matches |= match_func(fw_versions_dict) + for brand in brands: + fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand) + matches |= match_func(fw_versions_dict) if len(matches): return exact_match, matches @@ -416,9 +420,8 @@ def get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs, timeout=0.1, debug=Fa for brand in sorted(brand_matches, key=lambda b: len(brand_matches[b]), reverse=True): car_fw = get_fw_versions(logcan, sendcan, query_brand=brand, timeout=timeout, debug=debug, progress=progress) all_car_fw.extend(car_fw) - - # TODO: Until erroneous FW versions are removed, try to fingerprint on all possible combinations so far - _, matches = match_fw_to_car(all_car_fw, allow_fuzzy=False) + # Try to match using FW returned from this brand only + matches = match_fw_to_car_exact(build_fw_dict(car_fw)) if len(matches) == 1: break diff --git a/selfdrive/debug/test_fw_query_on_routes.py b/selfdrive/debug/test_fw_query_on_routes.py index 0cc674cfc8..868813b0fe 100755 --- a/selfdrive/debug/test_fw_query_on_routes.py +++ b/selfdrive/debug/test_fw_query_on_routes.py @@ -10,7 +10,7 @@ from tools.lib.logreader import LogReader from tools.lib.route import Route from selfdrive.car.interfaces import get_interface_attr from selfdrive.car.car_helpers import interface_names -from selfdrive.car.fw_versions import match_fw_to_car_exact, match_fw_to_car_fuzzy, build_fw_dict +from selfdrive.car.fw_versions import match_fw_to_car NO_API = "NO_API" in os.environ @@ -89,9 +89,8 @@ if __name__ == "__main__": print("not in supported cars") break - fw_versions_dict = build_fw_dict(car_fw) - exact_matches = match_fw_to_car_exact(fw_versions_dict) - fuzzy_matches = match_fw_to_car_fuzzy(fw_versions_dict) + _, exact_matches = match_fw_to_car(car_fw, allow_exact=True, allow_fuzzy=False) + _, fuzzy_matches = match_fw_to_car(car_fw, allow_exact=False, allow_fuzzy=True) if (len(exact_matches) == 1) and (list(exact_matches)[0] == live_fingerprint): good_exact += 1