Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "FPv2: fingerprint on all FW combinations" #25417

Merged
merged 8 commits into from
Aug 13, 2022
19 changes: 11 additions & 8 deletions selfdrive/car/fw_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +348 to +354
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is responsible for going from matching using all FW, to filtering FW down to each brand's queries and fingerprinting solely on that.


if len(matches):
return exact_match, matches
Expand Down Expand Up @@ -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))
Comment on lines +423 to +424
Copy link
Contributor Author

@sshane sshane Aug 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goes from trying to match on all FW so far -> trying to match only on FW returned from this brand

if len(matches) == 1:
break

Expand Down
7 changes: 3 additions & 4 deletions selfdrive/debug/test_fw_query_on_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
Expand Down Expand Up @@ -89,9 +89,8 @@
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
Expand Down