Cleanup auto_fingerprints.py (#32377)

* messyyy

* super clean car wash

* rm
This commit is contained in:
Shane Smiskol 2024-05-08 15:58:27 -07:00 committed by GitHub
parent fe4c7f1499
commit b895095031
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 45 deletions

View File

@ -4,67 +4,37 @@ import argparse
from collections import defaultdict
from openpilot.selfdrive.debug.format_fingerprints import format_brand_fw_versions
from openpilot.selfdrive.car.fw_versions import match_fw_to_car
from openpilot.selfdrive.car.interfaces import get_interface_attr
from openpilot.selfdrive.car.fingerprints import MIGRATION
from openpilot.selfdrive.car.fw_versions import MODEL_TO_BRAND, match_fw_to_car
from openpilot.tools.lib.logreader import LogReader, ReadMode
ALL_FW_VERSIONS = get_interface_attr("FW_VERSIONS")
ALL_CARS = get_interface_attr("CAR")
PLATFORM_TO_PYTHON_CAR_NAME = {brand: {car.value: car.name for car in ALL_CARS[brand]} for brand in ALL_CARS}
BRAND_TO_PLATFORMS = {brand: [car.value for car in ALL_CARS[brand]] for brand in ALL_CARS}
PLATFORM_TO_BRAND = dict(sum([[(platform, brand) for platform in BRAND_TO_PLATFORMS[brand]] for brand in BRAND_TO_PLATFORMS], []))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Auto fingerprint from a route")
parser.add_argument("route", help="The route name to use")
parser.add_argument("platform", help="The platform, or leave empty to auto-determine using fuzzy", default=None, nargs='?')
parser.add_argument("platform", help="The platform, or leave empty to auto-determine using fuzzy", default=None, nargs="?")
args = parser.parse_args()
lr = LogReader(args.route, ReadMode.QLOG)
carFw = None
carVin = None
carPlatform = None
platform: str | None = None
CP = lr.first("carParams")
assert CP is not None, "No carParams in route"
if CP is None:
raise Exception("No fw versions in the provided route...")
carPlatform = MIGRATION.get(CP.carFingerprint, CP.carFingerprint)
carFw = CP.carFw
carVin = CP.carVin
carPlatform = CP.carFingerprint
if args.platform is None: # attempt to auto-determine platform with other fuzzy fingerprints
_, possible_platforms = match_fw_to_car(carFw, carVin, log=False)
if len(possible_platforms) != 1:
print(f"Unable to auto-determine platform, possible platforms: {possible_platforms}")
if carPlatform != "MOCK":
print("Using platform from route")
platform = carPlatform
else:
platform = None
else:
platform = list(possible_platforms)[0]
else:
if args.platform is not None:
platform = args.platform
elif carPlatform != "MOCK":
platform = carPlatform
else:
_, matches = match_fw_to_car(CP.carFw, CP.carVin, log=False)
assert len(matches) == 1, f"Unable to auto-determine platform, matches: {matches}"
platform = list(matches)[0]
if platform is None:
raise Exception("unable to determine platform, try manually specifying the fingerprint.")
print("Attempting to add fw version for: ", platform)
print("Attempting to add fw version for:", platform)
fw_versions: dict[str, dict[tuple, list[bytes]]] = defaultdict(lambda: defaultdict(list))
brand = PLATFORM_TO_BRAND[platform]
brand = MODEL_TO_BRAND[platform]
for fw in carFw:
for fw in CP.carFw:
if fw.brand == brand and not fw.logging:
addr = fw.address
subAddr = None if fw.subAddress == 0 else fw.subAddress