From c9e3d0bf3c969fa99bef213ab3f7b7e161898b73 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 12 Jan 2023 22:26:54 -0800 Subject: [PATCH] kinda works --- hkg_fuzzy_fp.py | 54 +++++++++++++++++++++++++-- selfdrive/car/fw_query_definitions.py | 4 +- selfdrive/car/hyundai/values.py | 10 ++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/hkg_fuzzy_fp.py b/hkg_fuzzy_fp.py index 25ebf626be..396f091106 100644 --- a/hkg_fuzzy_fp.py +++ b/hkg_fuzzy_fp.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +import re + from cereal import car from selfdrive.car.hyundai.values import FW_VERSIONS @@ -14,9 +16,55 @@ platform_codes = set() # these ecus are available on all cars (even CAN FD with no OBD fingerprinting) fw_keys = [(Ecu.fwdCamera, 0x7c4, None), (Ecu.fwdRadar, 0x7d0, None)] -for car in FW_VERSIONS.keys(): - # print() - # print(car) +# RADAR_REGEX = br'[A-Z]+|\S+' +# RADAR_REGEX = br'(?=[A-Z][a-z]|_)' +RADAR_REGEX = br'([A-Z]+[A-Z0-9]*)' + + +def get_platform_code(car_fw): + codes = list() + for fw in car_fw[(Ecu.fwdRadar, 0x7d0, None)]: + start_idx = fw.index(b'\xf1\x00') + fw = fw[start_idx + 2:] + # fw = fw.decode('utf-8', 'ignore') + + # code, radar_code_variant = re.findall(RADAR_REGEX, fw) + code = re.match(RADAR_REGEX, fw).group(0) + radar_code_variant = fw[len(code):len(code) + 4 - len(code)].replace(b'_', b'') + # code, radar_code_variant = fw[:2], fw[2:4].replace(b"_", b"") + + print(f"{code=}, {radar_code_variant=}, {fw=}") + continue + + # code = '' + # radar_code_variant = '' + + end_of_platform = False + for idx, char in enumerate(fw): + if char.islower(): + end_of_platform = True + elif char in ['_']: # end of platform code + break + + if not end_of_platform: + code += char + else: + if char == ' ': + break + radar_code_variant += char + + print(f"{code=}, {radar_code_variant=}, {fw=}") + + +for car, car_fw in FW_VERSIONS.items(): + print() + print(car) + + # print(car, car_fw) + get_platform_code(car_fw) + + continue + for ecu, fws in FW_VERSIONS[car].items(): if ecu not in fw_keys: continue diff --git a/selfdrive/car/fw_query_definitions.py b/selfdrive/car/fw_query_definitions.py index a1695733fa..1f35c17853 100755 --- a/selfdrive/car/fw_query_definitions.py +++ b/selfdrive/car/fw_query_definitions.py @@ -2,7 +2,7 @@ import capnp from dataclasses import dataclass, field import struct -from typing import Dict, List, Optional, Tuple +from typing import Callable, Dict, List, Optional, Tuple import panda.python.uds as uds @@ -67,3 +67,5 @@ class FwQueryConfig: non_essential_ecus: Dict[capnp.lib.capnp._EnumModule, List[str]] = field(default_factory=dict) # Ecus added for data collection, not to be fingerprinted on extra_ecus: List[Tuple[capnp.lib.capnp._EnumModule, int, Optional[int]]] = field(default_factory=list) + # A function that each make can provide to fuzzy fingerprint reliably on that make + match_fw_to_car_fuzzy: Callable = None diff --git a/selfdrive/car/hyundai/values.py b/selfdrive/car/hyundai/values.py index c4fda42b63..c8c6554762 100644 --- a/selfdrive/car/hyundai/values.py +++ b/selfdrive/car/hyundai/values.py @@ -318,6 +318,11 @@ FINGERPRINTS = { }], } + +def hyundai_fuzzy_fingerprint(car_fw): + pass + + HYUNDAI_VERSION_REQUEST_LONG = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \ p16(0xf100) # Long description HYUNDAI_VERSION_REQUEST_MULTI = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \ @@ -358,8 +363,11 @@ FW_QUERY_CONFIG = FwQueryConfig( (Ecu.adas, 0x730, None), # ADAS Driving ECU on HDA2 platforms (Ecu.cornerRadar, 0x7b7, None), ], + match_fw_to_car_fuzzy=hyundai_fuzzy_fingerprint, ) + + FW_VERSIONS = { CAR.IONIQ: { (Ecu.fwdRadar, 0x7d0, None): [ @@ -1584,7 +1592,7 @@ HYBRID_CAR = {CAR.IONIQ_PHEV, CAR.ELANTRA_HEV_2021, CAR.KIA_NIRO_PHEV, CAR.KIA_N EV_CAR = {CAR.IONIQ_EV_2020, CAR.IONIQ_EV_LTD, CAR.KONA_EV, CAR.KIA_NIRO_EV, CAR.KONA_EV_2022, CAR.KIA_EV6, CAR.IONIQ_5, CAR.GENESIS_GV60_EV_1ST_GEN} # these cars require a special panda safety mode due to missing counters and checksums in the messages -LEGACY_SAFETY_MODE_CAR = {CAR.HYUNDAI_GENESIS, CAR.IONIQ_EV_2020, CAR.IONIQ_EV_LTD, CAR.IONIQ_PHEV, CAR.IONIQ, CAR.KONA_EV, CAR.KIA_SORENTO, CAR.SONATA_LF, CAR.KIA_OPTIMA_G4, CAR.KIA_OPTIMA_G4_FL, CAR.VELOSTER, CAR.KIA_STINGER, CAR.GENESIS_G70, CAR.GENESIS_G80, CAR.KIA_CEED, CAR.ELANTRA, CAR.IONIQ_HEV_2022} +LEGACY_SAFETY_MODE_CAR = {CAR.HYUNDAI_GENESIS, CAR.IONIQ_PHEV, CAR.IONIQ, CAR.KONA_EV, CAR.KIA_SORENTO, CAR.SONATA_LF, CAR.KIA_OPTIMA_G4, CAR.KIA_OPTIMA_G4_FL, CAR.VELOSTER, CAR.KIA_STINGER, CAR.GENESIS_G70, CAR.GENESIS_G80, CAR.KIA_CEED, CAR.ELANTRA, CAR.IONIQ_HEV_2022} # If 0x500 is present on bus 1 it probably has a Mando radar outputting radar points. # If no points are outputted by default it might be possible to turn it on using selfdrive/debug/hyundai_enable_radar_points.py