@ -337,17 +337,21 @@ def match_fw_to_car_exact(fw_versions_dict):
return set ( candidates . keys ( ) ) - set ( invalid )
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
# 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 :
if allow_fuzzy :
exact_matches . append ( ( False , match_fw_to_car_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 :
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 ( )
matches = set ( )
fw_versions_dict = build_fw_dict ( fw_versions , filter_brand = None )
for brand in brands :
matches | = match_func ( fw_versions_dict )
fw_versions_dict = build_fw_dict ( fw_versions , filter_brand = brand )
matches | = match_func ( fw_versions_dict )
if len ( matches ) :
if len ( matches ) :
return exact_match , 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 ) :
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 )
car_fw = get_fw_versions ( logcan , sendcan , query_brand = brand , timeout = timeout , debug = debug , progress = progress )
all_car_fw . extend ( car_fw )
all_car_fw . extend ( car_fw )
# Try to match using FW returned from this brand only
# TODO: Until erroneous FW versions are removed, try to fingerprint on all possible combinations so far
matches = match_fw_to_car_exact ( build_fw_dict ( car_fw ) )
_ , matches = match_fw_to_car ( all_car_fw , allow_fuzzy = False )
if len ( matches ) == 1 :
if len ( matches ) == 1 :
break
break