From e6d59eb777b56f2873daade45d83ed136d53449a Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 8 Jul 2022 13:20:20 -0700 Subject: [PATCH 1/5] Print brand along with ecu --- selfdrive/car/fw_versions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index 03dcece10c85c9..9afddeee4f8424 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -448,9 +448,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() From e3284033f82fb654ecd6f7d314e09ab43e765d3d Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 8 Jul 2022 13:20:54 -0700 Subject: [PATCH 2/5] fix json decoding --- selfdrive/car/car_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 7f83732153acc1..3913c154287303 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -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_responses), error=True) return car_fingerprint, finger, vin, car_fw, source, exact_match From bb336d1d69e2e5ff5ebc68232094d9565b1ec391 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 8 Jul 2022 13:24:56 -0700 Subject: [PATCH 3/5] fw_versions updates --- selfdrive/car/car_helpers.py | 6 +++--- selfdrive/car/fw_versions.py | 24 ++++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 3913c154287303..18b1172ce717d9 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -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 @@ -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) @@ -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=list(ecu_responses), error=True) + fw_count=len(car_fw), ecu_rx_addrs=list(ecu_rx_addrs), error=True) return car_fingerprint, finger, vin, car_fw, source, exact_match diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index 9afddeee4f8424..cf499960fbdb52 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -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): @@ -374,7 +371,7 @@ def get_fw_versions(logcan, sendcan, extra=None, timeout=0.1, debug=False, progr addrs.insert(0, parallel_addrs) fw_versions = {} - for i, addr in enumerate(tqdm(addrs, disable=not progress)): + for addr in tqdm(addrs, disable=not progress): for addr_chunk in chunks(addr): for r in REQUESTS: try: @@ -383,8 +380,7 @@ def get_fw_versions(logcan, sendcan, extra=None, timeout=0.1, debug=False, progr if addrs: query = IsoTpParallelQuery(sendcan, logcan, r.bus, addrs, r.request, r.response, r.rx_offset, debug=debug) - t = 2 * timeout if i == 0 else timeout - fw_versions.update({(r.brand, addr): (version, r) for addr, version in query.get_data(t).items()}) + fw_versions.update({(r.brand, addr): (version, r) for addr, version in query.get_data(timeout).items()}) except Exception: cloudlog.warning(f"FW query exception: {traceback.format_exc()}") From de422be349c5e180bc0312b15f1f2f5e81ea4bc8 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 8 Jul 2022 13:28:48 -0700 Subject: [PATCH 4/5] add timeout handling back --- selfdrive/car/fw_versions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index cf499960fbdb52..c51d120166f9be 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -371,7 +371,7 @@ def get_fw_versions(logcan, sendcan, extra=None, timeout=0.1, debug=False, progr addrs.insert(0, parallel_addrs) fw_versions = {} - for addr in tqdm(addrs, disable=not progress): + for i, addr in enumerate(tqdm(addrs, disable=not progress)): for addr_chunk in chunks(addr): for r in REQUESTS: try: @@ -380,7 +380,8 @@ def get_fw_versions(logcan, sendcan, extra=None, timeout=0.1, debug=False, progr if addrs: query = IsoTpParallelQuery(sendcan, logcan, r.bus, addrs, r.request, r.response, r.rx_offset, debug=debug) - fw_versions.update({(r.brand, addr): (version, r) for addr, version in query.get_data(timeout).items()}) + t = 2 * timeout if i == 0 else timeout + fw_versions.update({(r.brand, addr): (version, r) for addr, version in query.get_data(t).items()}) except Exception: cloudlog.warning(f"FW query exception: {traceback.format_exc()}") From 22794a6834d00927679ed207daf4e8bb893e3eaa Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 8 Jul 2022 13:31:09 -0700 Subject: [PATCH 5/5] keep logging the same --- selfdrive/car/car_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 18b1172ce717d9..690072cc4d9ec6 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -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_rx_addrs=list(ecu_rx_addrs), 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