Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
018676e
add test from hyundai
sshane Jun 20, 2023
78f812b
found tss2
sshane Jun 20, 2023
f5ddcca
abs and engine are very rarely shared (avalonh tss2 and camryh tss2 i…
sshane Jun 20, 2023
f51c7ac
some bad regex
sshane Jun 24, 2023
ae2ecf6
some pattern work
sshane Jun 25, 2023
347b62e
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 1, 2023
4e10034
some work
sshane Sep 1, 2023
902fe70
.
sshane Sep 1, 2023
050062d
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 8, 2023
cb84caa
some conceptual clean up
sshane Sep 8, 2023
afec5d7
fix short fw pattern
sshane Sep 8, 2023
ee881f3
hyundai test
sshane Sep 8, 2023
6179302
clean up values.py a bit
sshane Sep 8, 2023
881d3f3
print platform codes
sshane Sep 8, 2023
fc3ba3a
hyundai fuzzy
sshane Sep 8, 2023
f0450c3
pass test
sshane Sep 8, 2023
1d70d7f
move around constants
sshane Sep 8, 2023
b22c76f
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 8, 2023
e05679b
clean up
sshane Sep 8, 2023
025bb6d
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 8, 2023
03c14e5
clean up hyundai
sshane Sep 8, 2023
24bb20d
fix print
sshane Sep 8, 2023
648623a
more clean up, fix med pattern
sshane Sep 8, 2023
d194947
add documentation
sshane Sep 8, 2023
780a66f
use major version
sshane Sep 8, 2023
796b4bf
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 11, 2023
36e519d
some clean up from merge
sshane Sep 11, 2023
94e7272
some clean up from merge 2
sshane Sep 11, 2023
02f3e2f
spot check
sshane Sep 11, 2023
0b9f672
clean up imports
sshane Sep 11, 2023
4900e22
missing FW_QUERY_CONFIG
sshane Sep 11, 2023
21e4d22
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 18, 2023
fd884c8
short version: always prefixed with 3, get real platform code
sshane Sep 18, 2023
0a1c00f
limit to max chunks seen (3)
sshane Sep 18, 2023
a462a91
rm engine
sshane Sep 18, 2023
0dd9655
fix that
sshane Sep 18, 2023
90ed882
get_platform_codes returns dict
sshane Sep 18, 2023
c1e60c9
tests
sshane Sep 18, 2023
391eb22
comments
sshane Sep 18, 2023
e700568
fix test
sshane Sep 18, 2023
7fb9dc4
enable a test
sshane Sep 18, 2023
36c43b8
fix script
sshane Sep 18, 2023
99da735
print ecu parts
sshane Sep 18, 2023
16aef10
enable old test
sshane Sep 18, 2023
6e5cb8c
clean up some tests
sshane Sep 18, 2023
a88eb28
clean up
sshane Sep 18, 2023
393bfe2
more clean up
sshane Sep 18, 2023
cde385a
static
sshane Sep 18, 2023
93e8f79
this is all it took?
sshane Sep 18, 2023
3a59e99
add note
sshane Sep 18, 2023
d1e3d18
...
sshane Sep 18, 2023
16cb6dd
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 18, 2023
a20bc16
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 18, 2023
a1145f1
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 19, 2023
024f15d
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 20, 2023
c34024a
use less ECUs
sshane Sep 20, 2023
3468378
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 21, 2023
0e629e3
bump
sshane Sep 21, 2023
516f644
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 22, 2023
e74b9d5
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 22, 2023
58e4dab
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 23, 2023
368b2c4
todo
sshane Sep 23, 2023
7faf048
clean up fuzzy fp function
sshane Sep 23, 2023
a45836f
make deterministic in a feat of engineering
sshane Sep 23, 2023
2214f0a
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 24, 2023
2b520a6
add temp exclude_fw argument for testing
sshane Sep 24, 2023
2d9a4ad
fix logic
sshane Sep 24, 2023
81c1076
add blacklist
sshane Sep 24, 2023
4e4555e
add platform and its matches
sshane Sep 24, 2023
27aac16
fix for nb
sshane Sep 24, 2023
4bb11fc
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 25, 2023
1b0fd44
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 26, 2023
692e8bb
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 26, 2023
5025e49
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 28, 2023
0e3b47c
remove fw exclusion
sshane Sep 28, 2023
42c55f0
Revert "remove fw exclusion"
sshane Sep 28, 2023
3aeea90
clean up
sshane Sep 28, 2023
0f87423
Revert "Revert "remove fw exclusion""
sshane Sep 28, 2023
93bb762
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Sep 29, 2023
6538b27
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Oct 5, 2023
8d604dd
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Oct 6, 2023
8a1e91a
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Oct 7, 2023
b9e3cf0
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Oct 7, 2023
3490034
these two have similar chassis according to wikipedia (but mass is re…
sshane Oct 7, 2023
2411967
Revert "Revert "Revert "remove fw exclusion"""
sshane Oct 7, 2023
775c097
Revert "Revert "Revert "Revert "remove fw exclusion""""
sshane Oct 7, 2023
d9ebf5d
oof
sshane Oct 7, 2023
63b9e53
shadows global variable
sshane Oct 7, 2023
80c0917
Merge remote-tracking branch 'upstream/master' into toyota-fuzzy-v2
sshane Oct 8, 2023
2f87fb8
rm comment
sshane Oct 8, 2023
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
2 changes: 1 addition & 1 deletion selfdrive/car/hyundai/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def match_fw_to_car_fuzzy(live_fw_versions) -> Set[str]:
# to distinguish between hybrid and ICE. All EVs so far are either exclusively
# electric or specify electric in the platform code.
# TODO: whitelist platforms that we've seen hybrid and ICE versions of that have these specifiers
fuzzy_platform_blacklist = {str(car) for car in set(CANFD_CAR - EV_CAR)}
fuzzy_platform_blacklist = {str(c) for c in set(CANFD_CAR - EV_CAR)}
candidates: Set[str] = set()

for candidate, fws in FW_VERSIONS.items():
Expand Down
25 changes: 24 additions & 1 deletion selfdrive/car/toyota/tests/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import unittest

from cereal import car
from openpilot.selfdrive.car.fw_versions import build_fw_dict
from openpilot.selfdrive.car.toyota.values import CAR, DBC, TSS2_CAR, ANGLE_CONTROL_CAR, RADAR_ACC_CAR, FW_VERSIONS, \
PLATFORM_CODE_ECUS, get_platform_codes
FW_QUERY_CONFIG, PLATFORM_CODE_ECUS, FUZZY_EXCLUDED_PLATFORMS, \
get_platform_codes

Ecu = car.CarParams.Ecu
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
Expand Down Expand Up @@ -120,6 +122,27 @@ def test_platform_codes_spot_check(self):
])
self.assertEqual(results, {b"F1526-07-1": {b"10", b"40"}, b"8646F-41-04": {b"100"}, b"58-79": {b"000"}})

def test_fuzzy_excluded_platforms(self):
# Asserts a list of platforms that will not fuzzy fingerprint with platform codes due to them being shared.
platforms_with_shared_codes = set()
for platform, fw_by_addr in FW_VERSIONS.items():
car_fw = []
for ecu, fw_versions in fw_by_addr.items():
ecu_name, addr, sub_addr = ecu
for fw in fw_versions:
car_fw.append({"ecu": ecu_name, "fwVersion": fw, "address": addr,
"subAddress": 0 if sub_addr is None else sub_addr})

CP = car.CarParams.new_message(carFw=car_fw)
matches = FW_QUERY_CONFIG.match_fw_to_car_fuzzy(build_fw_dict(CP.carFw))
if len(matches) == 1:
self.assertEqual(list(matches)[0], platform)
else:
# If a platform has multiple matches, add it and its matches
platforms_with_shared_codes |= {platform, *matches}

self.assertEqual(platforms_with_shared_codes, FUZZY_EXCLUDED_PLATFORMS, (len(platforms_with_shared_codes), len(FW_VERSIONS)))


if __name__ == "__main__":
unittest.main()
37 changes: 37 additions & 0 deletions selfdrive/car/toyota/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,40 @@ def get_platform_codes(fw_versions: List[bytes]) -> Dict[bytes, Set[bytes]]:
return dict(codes)


def match_fw_to_car_fuzzy(live_fw_versions) -> Set[str]:
candidates = set()

for candidate, fws in FW_VERSIONS.items():
# Keep track of ECUs which pass all checks (platform codes, within sub-version range)
valid_found_ecus = set()
valid_expected_ecus = {ecu[1:] for ecu in fws if ecu[0] in PLATFORM_CODE_ECUS}
for ecu, expected_versions in fws.items():
addr = ecu[1:]
# Only check ECUs expected to have platform codes
if ecu[0] not in PLATFORM_CODE_ECUS:
continue

# Expected platform codes & versions
expected_platform_codes = get_platform_codes(expected_versions)

# Found platform codes & versions
found_platform_codes = get_platform_codes(live_fw_versions.get(addr, set()))

# Check part number + platform code + major version matches for any found versions
# Platform codes and major versions change for different physical parts, generation, API, etc.
# Sub-versions are incremented for minor recalls, do not need to be checked.
if not any(found_platform_code in expected_platform_codes for found_platform_code in found_platform_codes):
break

valid_found_ecus.add(addr)

# If all live ECUs pass all checks for candidate, add it as a match
if valid_expected_ecus.issubset(valid_found_ecus):
candidates.add(candidate)

return {str(c) for c in (candidates - FUZZY_EXCLUDED_PLATFORMS)}


# Regex patterns for parsing more general platform-specific identifiers from FW versions.
# - Part number: Toyota part number (usually last character needs to be ignored to find a match).
# Each ECU address has just one part number.
Expand Down Expand Up @@ -311,6 +345,8 @@ def get_platform_codes(fw_versions: List[bytes]) -> Dict[bytes, Set[bytes]]:
# - eps: describes lateral API changes for the EPS, such as using LTA for lane keeping and rejecting LKA messages
PLATFORM_CODE_ECUS = [Ecu.fwdCamera, Ecu.abs, Ecu.eps]

# These platforms have at least one platform code for all ECUs shared with another platform.
FUZZY_EXCLUDED_PLATFORMS = {CAR.LEXUS_ES_TSS2, CAR.LEXUS_RX_TSS2}

# Some ECUs that use KWP2000 have their FW versions on non-standard data identifiers.
# Toyota diagnostic software first gets the supported data ids, then queries them one by one.
Expand Down Expand Up @@ -382,6 +418,7 @@ def get_platform_codes(fw_versions: List[bytes]) -> Dict[bytes, Set[bytes]]:
(Ecu.combinationMeter, 0x7c0, None),
(Ecu.hvac, 0x7c4, None),
],
match_fw_to_car_fuzzy=match_fw_to_car_fuzzy,
)

FW_VERSIONS = {
Expand Down