this commit isn't complete yet

pull/32148/head
Shane Smiskol 1 year ago
parent b4b7dcd0db
commit ae77d5cd54
  1. 3
      selfdrive/car/car_helpers.py
  2. 20
      selfdrive/car/fw_versions.py

@ -139,7 +139,7 @@ def fingerprint(logcan, sendcan, num_pandas):
# VIN query only reliably works through OBDII # VIN query only reliably works through OBDII
vin_rx_addr, vin_rx_bus, vin = get_vin(logcan, sendcan, (0, 1)) vin_rx_addr, vin_rx_bus, vin = get_vin(logcan, sendcan, (0, 1))
ecu_rx_addrs = get_present_ecus(logcan, sendcan, num_pandas=num_pandas) ecu_rx_addrs = get_present_ecus(logcan, sendcan, num_pandas=num_pandas)
car_fw = get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs, num_pandas=num_pandas) car_fw = get_fw_versions_ordered(logcan, sendcan, vin, ecu_rx_addrs, num_pandas=num_pandas)
cached = False cached = False
exact_fw_match, fw_candidates = match_fw_to_car(car_fw) exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
@ -148,6 +148,7 @@ def fingerprint(logcan, sendcan, num_pandas):
exact_fw_match, fw_candidates, car_fw = True, set(), [] exact_fw_match, fw_candidates, car_fw = True, set(), []
cached = False cached = False
# TODO: move up?
if not is_valid_vin(vin): if not is_valid_vin(vin):
cloudlog.event("Malformed VIN", vin=vin, error=True) cloudlog.event("Malformed VIN", vin=vin, error=True)
vin = VIN_UNKNOWN vin = VIN_UNKNOWN

@ -144,8 +144,8 @@ def match_fw_to_car_exact(live_fw_versions: LiveFwVersions, match_brand: str = N
return set(candidates.keys()) - invalid return set(candidates.keys()) - invalid
def match_fw_to_car(fw_versions: list[capnp.lib.capnp._DynamicStructBuilder], allow_exact: bool = True, allow_fuzzy: bool = True, def match_fw_to_car(fw_versions: list[capnp.lib.capnp._DynamicStructBuilder], vin: str, allow_exact: bool = True,
log: bool = True) -> tuple[bool, set[str]]: allow_fuzzy: bool = True, log: bool = True) -> tuple[bool, set[str]]:
# Try exact matching first # Try exact matching first
exact_matches: list[tuple[bool, MatchFwToCar]] = [] exact_matches: list[tuple[bool, MatchFwToCar]] = []
if allow_exact: if allow_exact:
@ -158,12 +158,18 @@ def match_fw_to_car(fw_versions: list[capnp.lib.capnp._DynamicStructBuilder], al
matches: set[str] = set() matches: set[str] = set()
for brand in VERSIONS.keys(): for brand in VERSIONS.keys():
fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand) fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand)
matches |= match_func(fw_versions_dict, match_brand=brand, log=log) cur_matches = match_func(fw_versions_dict, match_brand=brand, log=log)
# If specified and no matches so far, fall back to brand's fuzzy fingerprinting function # If specified and no matches so far, fall back to brand's fuzzy fingerprinting function
config = FW_QUERY_CONFIGS[brand] config = FW_QUERY_CONFIGS[brand]
if not exact_match and not len(matches) and config.match_fw_to_car_fuzzy is not None: if not exact_match and not len(cur_matches) and config.match_fw_to_car_fuzzy is not None:
matches |= config.match_fw_to_car_fuzzy(fw_versions_dict, VERSIONS[brand]) cur_matches |= config.match_fw_to_car_fuzzy(fw_versions_dict, VERSIONS[brand])
# FIXME: this is super ugly
if len(cur_matches) != 1 and config.match_fw_to_car_custom is not None:
cur_matches = config.match_fw_to_car_custom(fw_versions_dict, vin, VERSIONS[brand])
matches |= cur_matches
if len(matches): if len(matches):
return exact_match, matches return exact_match, matches
@ -237,7 +243,7 @@ def set_obd_multiplexing(params: Params, obd_multiplexing: bool):
cloudlog.warning("OBD multiplexing set successfully") cloudlog.warning("OBD multiplexing set successfully")
def get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs: set[EcuAddrBusType], timeout: float = 0.1, num_pandas: int = 1, def get_fw_versions_ordered(logcan, sendcan, vin: str, ecu_rx_addrs: set[EcuAddrBusType], timeout: float = 0.1, num_pandas: int = 1,
debug: bool = False, progress: bool = False) -> list[capnp.lib.capnp._DynamicStructBuilder]: debug: bool = False, progress: bool = False) -> list[capnp.lib.capnp._DynamicStructBuilder]:
"""Queries for FW versions ordering brands by likelihood, breaks when exact match is found""" """Queries for FW versions ordering brands by likelihood, breaks when exact match is found"""
@ -253,7 +259,7 @@ def get_fw_versions_ordered(logcan, sendcan, ecu_rx_addrs: set[EcuAddrBusType],
all_car_fw.extend(car_fw) all_car_fw.extend(car_fw)
# If there is a match using this brand's FW alone, finish querying early # If there is a match using this brand's FW alone, finish querying early
_, matches = match_fw_to_car(car_fw, log=False) _, matches = match_fw_to_car(car_fw, vin, log=False)
if len(matches) == 1: if len(matches) == 1:
break break

Loading…
Cancel
Save