this is promising

start on making existing fingerprinting functions use the config, instead of entirely replacing them
pull/28386/head
Shane Smiskol 2 years ago
parent ece74463dd
commit 3a721f1e2c
  1. 46
      selfdrive/car/fw_versions.py
  2. 11
      selfdrive/car/hyundai/values.py

@ -11,6 +11,7 @@ from selfdrive.car.interfaces import get_interface_attr
from selfdrive.car.fingerprints import FW_VERSIONS
from selfdrive.car.isotp_parallel_query import IsoTpParallelQuery
from system.swaglog import cloudlog
from selfdrive.car.hyundai.values import get_platform_codes
Ecu = car.CarParams.Ecu
ESSENTIAL_ECUS = [Ecu.engine, Ecu.eps, Ecu.abs, Ecu.fwdRadar, Ecu.fwdCamera, Ecu.vsa]
@ -48,8 +49,8 @@ def get_brand_addrs():
def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None):
# If make specifies a fuzzy matching function, use that instead
if config is not None and config.match_fw_to_car_fuzzy is not None:
return config.match_fw_to_car_fuzzy(fw_versions_dict)
# if config is not None and config.match_fw_to_car_fuzzy is not None:
# return config.match_fw_to_car_fuzzy(fw_versions_dict)
"""Do a fuzzy FW match. This function will return a match, and the number of firmware version
that were matched uniquely to that specific car. If multiple ECUs uniquely match to different cars
@ -59,35 +60,62 @@ def match_fw_to_car_fuzzy(fw_versions_dict, config, log=True, exclude=None):
# Getting this exactly right isn't crucial, but excluding camera and radar makes it almost
# impossible to get 3 matching versions, even if two models with shared parts are released at the same
# time and only one is in our database.
exclude_types = [Ecu.fwdCamera, Ecu.fwdRadar, Ecu.eps, Ecu.debug]
# exclude_types = [Ecu.fwdCamera, Ecu.fwdRadar, Ecu.eps, Ecu.debug]
# Build lookup table from (addr, sub_addr, fw) to list of candidate cars
all_fw_versions = defaultdict(list)
all_fw_versions = defaultdict(set)
all_fw_versions_prefixes = defaultdict(set)
for candidate, fw_by_addr in FW_VERSIONS.items():
if MODEL_TO_BRAND[candidate] != 'hyundai':
continue
if candidate == exclude:
continue
for addr, fws in fw_by_addr.items():
if addr[0] in exclude_types:
# if addr[0] in exclude_types:
# continue
# hyundai works best with camera and radar (which have mostly standardized platform codes)
if addr[0] not in [Ecu.fwdCamera, Ecu.fwdRadar]:
continue
for f in fws:
all_fw_versions[(addr[1], addr[2], f)].append(candidate)
all_fw_versions[(addr[1], addr[2], f)].add(candidate)
platform_codes = get_platform_codes([f])
assert len(platform_codes) < 2
if len(platform_codes):
print(platform_codes, f)
platform_code = list(platform_codes)[0]
all_fw_versions_prefixes[(addr[1], addr[2], platform_code)].add(candidate)
print(all_fw_versions_prefixes)
match_count = 0
candidate = None
for addr, versions in fw_versions_dict.items():
for version in versions:
# All cars that have this FW response on the specified address
candidates = all_fw_versions[(addr[0], addr[1], version)]
print(addr)
print('first candidates', candidates)
if len(candidates) != 1:
platform_codes = get_platform_codes([version])
assert len(platform_codes) < 2
if len(platform_codes):
print(platform_codes, version)
platform_code = list(platform_codes)[0]
candidates = all_fw_versions_prefixes[(addr[0], addr[1], platform_code)]
print('second candidates', candidates)
print()
if len(candidates) == 1:
match_count += 1
if candidate is None:
candidate = candidates[0]
candidate = list(candidates)[0]
# We uniquely matched two different cars. No fuzzy match possible
elif candidate != candidates[0]:
elif candidate != list(candidates)[0]:
return set()
print('match_count', match_count)
if match_count >= 2:
if log:
cloudlog.error(f"Fingerprinted {candidate} using fuzzy match. {match_count} matching ECUs")
@ -142,6 +170,8 @@ def match_fw_to_car(fw_versions, allow_exact=True, allow_fuzzy=True):
# For each brand, attempt to fingerprint using all FW returned from its queries
matches = set()
for brand in VERSIONS.keys():
if brand != 'hyundai':
continue
fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand)
config = FW_QUERY_CONFIGS[brand]
matches |= match_func(fw_versions_dict, config)

@ -343,10 +343,12 @@ FINGERPRINTS = {
}
def get_platform_codes(fw_versions):
def get_platform_codes(fw_versions: List[bytes]):
codes = set()
platform_code_prefix = HYUNDAI_VERSION_REQUEST_LONG[1:]
for fw in fw_versions:
if platform_code_prefix not in fw:
continue
start_idx = fw.index(platform_code_prefix) + len(platform_code_prefix)
code = fw[start_idx:start_idx + 4] # Hyundai platform code is max 4 bytes
codes.add(code.replace(b" ", b"").replace(b"_", b""))
@ -354,6 +356,7 @@ def get_platform_codes(fw_versions):
def match_fw_to_hyundai_fuzzy(fw_versions_dict):
print('HERERERERER')
platform_codes_radar = get_platform_codes(fw_versions_dict.get((0x7d0, None), {}))
platform_codes_camera = get_platform_codes(fw_versions_dict.get((0x7c4, None), {}))
if len(platform_codes_radar) != 1 or len(platform_codes_camera) != 1:
@ -826,11 +829,9 @@ FW_VERSIONS = {
},
CAR.SANTA_FE_2022: {
(Ecu.fwdRadar, 0x7d0, None): [
b'\xf1\x00TM__ SCC F-CUP 1.00 1.00 99110-S1500 ',
b'\xf1\x00TM__ SCC FHCUP 1.00 1.00 99110-S1500 ',
],
(Ecu.abs, 0x7d1, None): [
b'\xf1\x00TM ESC \x01 102!\x04\x03 58910-S2DA0',
b'\xf1\x00TM ESC \x02 101 \x08\x04 58910-S2GA0',
b'\xf1\x00TM ESC \x03 101 \x08\x02 58910-S2DA0',
b'\xf1\x8758910-S2DA0\xf1\x00TM ESC \x03 101 \x08\x02 58910-S2DA0',
@ -841,7 +842,6 @@ FW_VERSIONS = {
b'\xf1\x00TM ESC \x04 101 \x08\x04 58910-S2GA0',
],
(Ecu.engine, 0x7e0, None): [
b'\xf1\x870\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf1\x81HM6M1_0a0_L50',
b'\xf1\x81HM6M1_0a0_H00',
b'\xf1\x82TACVN5GMI3XXXH0A',
b'\xf1\x82TMBZN5TMD3XXXG2E',
@ -850,7 +850,6 @@ FW_VERSIONS = {
b'\xf1\x81HM6M1_0a0_G20',
b'\xf1\x870\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf1\x82TMDWN5TMD3TXXJ1A',
b'\xf1\x81HM6M2_0a0_G00',
b'\xf1\x870\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf1\x81HM6M1_0a0_J10',
],
(Ecu.eps, 0x7d4, None): [
b'\xf1\x00TM MDPS C 1.00 1.02 56370-S2AA0 0B19',
@ -860,10 +859,8 @@ FW_VERSIONS = {
b'\xf1\x00TMA MFC AT MEX LHD 1.00 1.01 99211-S2500 210205',
b'\xf1\x00TMA MFC AT USA LHD 1.00 1.00 99211-S2500 200720',
b'\xf1\x00TM MFC AT EUR LHD 1.00 1.03 99211-S1500 210224',
b'\xf1\x00TMA MFC AT USA LHD 1.00 1.01 99211-S2500 210205',
],
(Ecu.transmission, 0x7e1, None): [
b'\xf1\x00HT6WA280BLHT6WAD00A1STM2G25NH2\x00\x00\x00\x00\x00\x00\xf8\xc0\xc3\xaa',
b'\xf1\x00HT6WA280BLHT6WAD00A1STM4G25NH1\x00\x00\x00\x00\x00\x00\x9cl\x04\xbc',
b'\xf1\x00T02601BL T02900A1 VTMPT25XXX900NSA\xf3\xf4Uj',
b'\xf1\x87SDMXCA9087684GN1VfvgUUeVwwgwwwwwffffU?\xfb\xff\x97\x88\x7f\xff+\xa4\xf1\x89HT6WAD00A1\xf1\x82STM4G25NH1\x00\x00\x00\x00\x00\x00',

Loading…
Cancel
Save