Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrysler VIN fuzzy fingerprint #33000

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions selfdrive/car/chrysler/tests/test_chrysler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import random
import re

from cereal import car
from openpilot.selfdrive.car.chrysler.values import CAR, FW_QUERY_CONFIG
from openpilot.selfdrive.car.chrysler.fingerprints import FW_VERSIONS

Ecu = car.CarParams.Ecu

CHASSIS_CODE_PATTERN = re.compile('[A-Z0-9]{2}')


class TestChryslerPlatformConfigs:
def test_vin_parse_codes(self, subtests):
for platform in CAR:
with subtests.test(platform=platform.value):
assert len(platform.config.chassis_codes) > 0, "Chassis codes not set"
assert len(platform.config.engines) > 0, "engines not set"
assert len(platform.config.years) > 0, "years codes not set"
assert all(CHASSIS_CODE_PATTERN.match(cc) for cc in \
platform.config.chassis_codes), "Bad chassis codes"

# No two platforms should share chassis codes
for comp in CAR:
if platform == comp:
continue
assert set() == (platform.config.chassis_codes & comp.config.chassis_codes) \
or (platform.config.years != comp.config.years) \
or (platform.config.engines & comp.config.engines), \
f"Shared chassis codes: {comp}"

def test_custom_fuzzy_fingerprinting(self, subtests):
all_radar_fw = list({fw for ecus in FW_VERSIONS.values() for fw in ecus[Ecu.fwdRadar, 0x753, None]})

for platform in CAR:
with subtests.test(platform=platform.name):
for year in platform.config.years:
for engine in platform.config.engines:
for chassis_code in platform.config.chassis_codes | {"00"}:
vin = ["0"] * 17
vin[9] = year
vin[4:6] = chassis_code
vin[7] = engine
vin = "".join(vin)

# Check a few FW cases - expected, unexpected
for radar_fw in random.sample(all_radar_fw, 5) + [b'\xf1\x875Q0907572G \xf1\x890571', b'\xf1\x877H9907572AA\xf1\x890396']:
should_match = ((engine in platform.config.engines and chassis_code in platform.config.chassis_codes and \
platform.config.years[0] <= year <= platform.config.years[1]) and radar_fw in all_radar_fw)

live_fws = {(0x753, None): [radar_fw]}
matches = FW_QUERY_CONFIG.match_fw_to_car_fuzzy(live_fws, vin, FW_VERSIONS)

expected_matches = {platform} if should_match else set()
assert expected_matches == matches, "Bad match"
98 changes: 87 additions & 11 deletions selfdrive/car/chrysler/values.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import IntFlag
from enum import IntFlag, StrEnum
from dataclasses import dataclass, field
from collections import defaultdict

from cereal import car
from panda.python import uds
Expand All @@ -9,7 +10,6 @@

Ecu = car.CarParams.Ecu


class ChryslerFlags(IntFlag):
# Detected flags
HIGHER_MIN_STEERING_SPEED = 1
Expand All @@ -23,61 +23,92 @@ class ChryslerCarDocs(CarDocs):
@dataclass
class ChryslerPlatformConfig(PlatformConfig):
dbc_dict: DbcDict = field(default_factory=lambda: dbc_dict('chrysler_pacifica_2017_hybrid_generated', 'chrysler_pacifica_2017_hybrid_private_fusion'))
chassis_codes: set[str] = field(default_factory=set)
engines: set[str] = field(default_factory=set)
years: str = field(default_factory=str)


@dataclass(frozen=True)
class ChryslerCarSpecs(CarSpecs):
minSteerSpeed: float = 3.8 # m/s


class CAR(Platforms):
# https://vpic.nhtsa.dot.gov/mid/home/displayfile/b5f541b7-8157-415d-889c-7f63628e9e66 vin stuff 2024
# a platform is fully determined by [5:6]+[8]+[10] (chassis_code+engine+year)
# Chrysler
CHRYSLER_PACIFICA_2017_HYBRID = ChryslerPlatformConfig(
CHRYSLER_PACIFICA_2017_HYBRID = ChryslerPlatformConfig( # ru
[ChryslerCarDocs("Chrysler Pacifica Hybrid 2017")],
ChryslerCarSpecs(mass=2242., wheelbase=3.089, steerRatio=16.2),
chassis_codes={"C1"},
years="HH",
engines={"7"}
)
CHRYSLER_PACIFICA_2018_HYBRID = ChryslerPlatformConfig(
CHRYSLER_PACIFICA_2018_HYBRID = ChryslerPlatformConfig( # ru
[ChryslerCarDocs("Chrysler Pacifica Hybrid 2018")],
CHRYSLER_PACIFICA_2017_HYBRID.specs,
chassis_codes={"C1"},
years="JJ",
engines={"7"}
)
CHRYSLER_PACIFICA_2019_HYBRID = ChryslerPlatformConfig(
CHRYSLER_PACIFICA_2019_HYBRID = ChryslerPlatformConfig( # ru
[ChryslerCarDocs("Chrysler Pacifica Hybrid 2019-24")],
CHRYSLER_PACIFICA_2017_HYBRID.specs,
chassis_codes={"C1", "C3"},
years="KR",
engines={"7"}
)
CHRYSLER_PACIFICA_2018 = ChryslerPlatformConfig(
CHRYSLER_PACIFICA_2018 = ChryslerPlatformConfig( # ru
[ChryslerCarDocs("Chrysler Pacifica 2017-18")],
CHRYSLER_PACIFICA_2017_HYBRID.specs,
chassis_codes={"C1", "C3"},
years="HJ",
engines={"G"}
)
CHRYSLER_PACIFICA_2020 = ChryslerPlatformConfig(
CHRYSLER_PACIFICA_2020 = ChryslerPlatformConfig( # ru
[
ChryslerCarDocs("Chrysler Pacifica 2019-20"),
ChryslerCarDocs("Chrysler Pacifica 2021-23", package="All"),
],
CHRYSLER_PACIFICA_2017_HYBRID.specs,
years="KP",
chassis_codes={"C1", "C3"},
engines={"G"}
)

# Dodge
DODGE_DURANGO = ChryslerPlatformConfig(
DODGE_DURANGO = ChryslerPlatformConfig( # wd
[ChryslerCarDocs("Dodge Durango 2020-21")],
CHRYSLER_PACIFICA_2017_HYBRID.specs,
chassis_codes={"DH", "DJ"},
years="LM",
engines={"G", "T", "9", "J"}
)

# Jeep
JEEP_GRAND_CHEROKEE = ChryslerPlatformConfig( # includes 2017 Trailhawk
JEEP_GRAND_CHEROKEE = ChryslerPlatformConfig( # includes 2017 Trailhawk # wk
[ChryslerCarDocs("Jeep Grand Cherokee 2016-18", video_link="https://www.youtube.com/watch?v=eLR9o2JkuRk")],
ChryslerCarSpecs(mass=1778., wheelbase=2.71, steerRatio=16.7),
chassis_codes={"JE", "JF"},
years="GI",
engines={"6", "G"},
)

JEEP_GRAND_CHEROKEE_2019 = ChryslerPlatformConfig( # includes 2020 Trailhawk
JEEP_GRAND_CHEROKEE_2019 = ChryslerPlatformConfig( # includes 2020 Trailhawk # wk
[ChryslerCarDocs("Jeep Grand Cherokee 2019-21", video_link="https://www.youtube.com/watch?v=jBe4lWnRSu4")],
JEEP_GRAND_CHEROKEE.specs,
chassis_codes={"JG", "JH"},
years="JL",
engines={"6", "G"}
)

# Ram
RAM_1500_5TH_GEN = ChryslerPlatformConfig(
[ChryslerCarDocs("Ram 1500 2019-24", car_parts=CarParts.common([CarHarness.ram]))],
ChryslerCarSpecs(mass=2493., wheelbase=3.88, steerRatio=16.3, minSteerSpeed=14.5),
dbc_dict('chrysler_ram_dt_generated', None),
chassis_codes={"RE", "RF"},
years="KR",
engines={"G", "T", "9"}
)
RAM_HD_5TH_GEN = ChryslerPlatformConfig(
[
Expand All @@ -86,6 +117,9 @@ class CAR(Platforms):
],
ChryslerCarSpecs(mass=3405., wheelbase=3.785, steerRatio=15.61, minSteerSpeed=16.),
dbc_dict('chrysler_ram_hd_generated', None),
chassis_codes={"R4", "R5", "R2", "R3", "RP", "RR"},
years="KR",
engines={"J", "L"}
)


Expand All @@ -106,6 +140,47 @@ def __init__(self, CP):
self.STEER_DELTA_DOWN = 3
self.STEER_MAX = 261 # higher than this faults the EPS

def match_fw_to_car_fuzzy(live_fw_versions, vin, offline_fw_versions) -> set[str]:
candidates = set()

# Compile all FW versions for each ECU
all_ecu_versions: dict[EcuAddrSubAddr, set[str]] = defaultdict(set)
for ecus in offline_fw_versions.values():
for ecu, versions in ecus.items():
all_ecu_versions[ecu] |= set(versions)

# Check chassis code, engine and year to determine the platform
chassis_code = vin[4:6]
engine = vin[7]
year = vin[9]

Copy link
Contributor

@sshane sshane Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the engine denote the trim/or if hybrid? Recently we're erring on the side of allowing more variants to fingerprint, if we reasonably expect them to work fine. For example, on Toyota the Corolla and Corolla Hybrid are treated the same. If the engine code here is supposed to split those, perhaps we don't need it.

Copy link
Contributor Author

@ksfi ksfi Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it denotes hybrid

Ok so maybe we can rearrange the platforms into 2:
CHRYSLER_PACIFICA_2017 that contains 2017_HYBRID, 2018_HYBRID and 2018
CHRYSLER_PACIFICA_2020 that contains 2020 and 2019_HYBRID

CHRYSLER_PACIFICA_2020 needs to be different because handled differently in interface.py

for platform in CAR:
valid_ecus = set()
for ecu in offline_fw_versions[platform]:
if ecu[0] not in CHECK_FUZZY_ECUS:
continue

# Sanity check that live FW is in the superset of all FW, Volkswagen ECU part numbers are commonly shared
addr = ecu[1:]
found_versions = live_fw_versions.get(addr, [])
expected_versions = all_ecu_versions[ecu]
if not any(found_version in expected_versions for found_version in found_versions):
break

valid_ecus.add(ecu[0])

if valid_ecus != CHECK_FUZZY_ECUS:
continue

if chassis_code in platform.config.chassis_codes and engine in platform.config.engines \
and platform.config.years[0] <= year <= platform.config.years[1]:
candidates.add(platform)

return {str(c) for c in candidates}

CHECK_FUZZY_ECUS = {Ecu.fwdRadar}



STEER_THRESHOLD = 120

Expand Down Expand Up @@ -151,6 +226,7 @@ def __init__(self, CP):
extra_ecus=[
(Ecu.abs, 0x7e4, None), # alt address for abs on hybrids, NOTE: not on all hybrid platforms
],
match_fw_to_car_fuzzy=match_fw_to_car_fuzzy,
)

DBC = CAR.create_dbc_map()
Loading