Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions selfdrive/car/car_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _get_interface_names() -> Dict[str, List[str]]:
def fingerprint(logcan, sendcan):
fixed_fingerprint = os.environ.get('FINGERPRINT', "")
skip_fw_query = os.environ.get('SKIP_FW_QUERY', False)
ecu_responses = set()
ecu_rx_addrs = set()

if not fixed_fingerprint and not skip_fw_query:
# Vin query only reliably works thorugh OBDII
Expand All @@ -98,7 +98,7 @@ def fingerprint(logcan, sendcan):
else:
cloudlog.warning("Getting VIN & FW versions")
_, vin = get_vin(logcan, sendcan, bus)
ecu_responses = get_present_ecus(logcan, sendcan)
ecu_rx_addrs = get_present_ecus(logcan, sendcan)
car_fw = get_fw_versions(logcan, sendcan)

exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
Expand Down Expand Up @@ -166,7 +166,7 @@ def fingerprint(logcan, sendcan):
source = car.CarParams.FingerprintSource.fixed

cloudlog.event("fingerprinted", car_fingerprint=car_fingerprint, source=source, fuzzy=not exact_match,
fw_count=len(car_fw), ecu_responses=ecu_responses, error=True)
fw_count=len(car_fw), ecu_responses=list(ecu_rx_addrs), error=True)
return car_fingerprint, finger, vin, car_fw, source, exact_match


Expand Down
22 changes: 10 additions & 12 deletions selfdrive/car/fw_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,21 @@ def match_fw_to_car(fw_versions, allow_fuzzy=True):
versions = get_interface_attr('FW_VERSIONS', ignore_none=True)

# Try exact matching first
exact_matches = [True]
exact_matches = [(True, match_fw_to_car_exact)]
if allow_fuzzy:
exact_matches.append(False)
exact_matches.append((False, match_fw_to_car_fuzzy))

for exact_match in exact_matches:
for exact_match, match_func in exact_matches:
# For each brand, attempt to fingerprint using FW returned from its queries
matches = set()
for brand in versions.keys():
fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand)
matches |= match_func(fw_versions_dict)

if exact_match:
matches = match_fw_to_car_exact(fw_versions_dict)
else:
matches = match_fw_to_car_fuzzy(fw_versions_dict)
if len(matches):
return exact_match, matches

if len(matches) == 1:
return exact_match, matches

return True, []
return True, set()


def get_present_ecus(logcan, sendcan):
Expand Down Expand Up @@ -448,9 +445,10 @@ def get_fw_versions(logcan, sendcan, extra=None, timeout=0.1, debug=False, progr
print()
print("Found FW versions")
print("{")
padding = max([len(fw.brand) for fw in fw_vers])
for version in fw_vers:
subaddr = None if version.subAddress == 0 else hex(version.subAddress)
print(f" (Ecu.{version.ecu}, {hex(version.address)}, {subaddr}): [{version.fwVersion}]")
print(f" Brand: {version.brand:{padding}} - (Ecu.{version.ecu}, {hex(version.address)}, {subaddr}): [{version.fwVersion}]")
print("}")

print()
Expand Down