diff --git a/selfdrive/car/body/fingerprints.py b/selfdrive/car/body/fingerprints.py index ab7a5f8d7b..90db0b08f9 100644 --- a/selfdrive/car/body/fingerprints.py +++ b/selfdrive/car/body/fingerprints.py @@ -1,8 +1,8 @@ # ruff: noqa: E501 -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.body.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu # debug ecu fw version is the git hash of the firmware diff --git a/selfdrive/car/chrysler/fingerprints.py b/selfdrive/car/chrysler/fingerprints.py index 1f453d8f50..84d70741e4 100644 --- a/selfdrive/car/chrysler/fingerprints.py +++ b/selfdrive/car/chrysler/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.chrysler.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FW_VERSIONS = { CAR.CHRYSLER_PACIFICA_2018: { diff --git a/selfdrive/car/data_structures.py b/selfdrive/car/data_structures.py index 77ec98d055..1b1dc129bd 100644 --- a/selfdrive/car/data_structures.py +++ b/selfdrive/car/data_structures.py @@ -1,34 +1,54 @@ -from enum import StrEnum, auto - - -class Ecu(StrEnum): - eps = auto() - abs = auto() - fwdRadar = auto() - fwdCamera = auto() - engine = auto() - unknown = auto() - transmission = auto() # Transmission Control Module - hybrid = auto() # hybrid control unit, e.g. Chrysler's HCP, Honda's IMA Control Unit, Toyota's hybrid control computer - srs = auto() # airbag - gateway = auto() # can gateway - hud = auto() # heads up display - combinationMeter = auto() # instrument cluster - electricBrakeBooster = auto() - shiftByWire = auto() - adas = auto() - cornerRadar = auto() - hvac = auto() - parkingAdas = auto() # parking assist system ECU, e.g. Toyota's IPAS, Hyundai's RSPA, etc. - epb = auto() # electronic parking brake - telematics = auto() - body = auto() # body control module - - # Toyota only - dsu = auto() - - # Honda only - vsa = auto() # Vehicle Stability Assist - programmedFuelInjection = auto() - - debug = auto() +from dataclasses import dataclass +from enum import StrEnum as _StrEnum, auto + + +class StrEnum(_StrEnum): + @staticmethod + def _generate_next_value_(name, *args): + # auto() defaults to name.lower() + return name + + +@dataclass +class CarParams: + carName: str + carFingerprint: str + fuzzyFingerprint: bool + + notCar: bool # flag for non-car robotics platforms + + class SteerControlType(StrEnum): + torque = auto() + angle = auto() + + class Ecu(StrEnum): + eps = auto() + abs = auto() + fwdRadar = auto() + fwdCamera = auto() + engine = auto() + unknown = auto() + transmission = auto() # Transmission Control Module + hybrid = auto() # hybrid control unit, e.g. Chrysler's HCP, Honda's IMA Control Unit, Toyota's hybrid control computer + srs = auto() # airbag + gateway = auto() # can gateway + hud = auto() # heads up display + combinationMeter = auto() # instrument cluster + electricBrakeBooster = auto() + shiftByWire = auto() + adas = auto() + cornerRadar = auto() + hvac = auto() + parkingAdas = auto() # parking assist system ECU, e.g. Toyota's IPAS, Hyundai's RSPA, etc. + epb = auto() # electronic parking brake + telematics = auto() + body = auto() # body control module + + # Toyota only + dsu = auto() + + # Honda only + vsa = auto() # Vehicle Stability Assist + programmedFuelInjection = auto() + + debug = auto() diff --git a/selfdrive/car/ford/fingerprints.py b/selfdrive/car/ford/fingerprints.py index 2201072fa3..aae3075cb5 100644 --- a/selfdrive/car/ford/fingerprints.py +++ b/selfdrive/car/ford/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.ford.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FW_VERSIONS = { CAR.FORD_BRONCO_SPORT_MK1: { diff --git a/selfdrive/car/honda/fingerprints.py b/selfdrive/car/honda/fingerprints.py index 191fd8e44a..797a0c8581 100644 --- a/selfdrive/car/honda/fingerprints.py +++ b/selfdrive/car/honda/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.honda.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu # Modified FW can be identified by the second dash being replaced by a comma # For example: `b'39990-TVA,A150\x00\x00'` diff --git a/selfdrive/car/hyundai/fingerprints.py b/selfdrive/car/hyundai/fingerprints.py index 6c7480a15d..3bd6f7e0be 100644 --- a/selfdrive/car/hyundai/fingerprints.py +++ b/selfdrive/car/hyundai/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.hyundai.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu # The existence of SCC or RDR in the fwdRadar FW usually determines the radar's function, # i.e. if it sends the SCC messages or if another ECU like the camera or ADAS Driving ECU does diff --git a/selfdrive/car/mazda/fingerprints.py b/selfdrive/car/mazda/fingerprints.py index c7b331b1cb..47fb1061af 100644 --- a/selfdrive/car/mazda/fingerprints.py +++ b/selfdrive/car/mazda/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.mazda.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FW_VERSIONS = { CAR.MAZDA_CX5_2022: { diff --git a/selfdrive/car/nissan/fingerprints.py b/selfdrive/car/nissan/fingerprints.py index 743feeace9..19eca89eee 100644 --- a/selfdrive/car/nissan/fingerprints.py +++ b/selfdrive/car/nissan/fingerprints.py @@ -1,8 +1,8 @@ # ruff: noqa: E501 -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.nissan.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FINGERPRINTS = { CAR.NISSAN_XTRAIL: [{ diff --git a/selfdrive/car/subaru/fingerprints.py b/selfdrive/car/subaru/fingerprints.py index 7f3ae73163..9fcbb81d46 100644 --- a/selfdrive/car/subaru/fingerprints.py +++ b/selfdrive/car/subaru/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.subaru.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FW_VERSIONS = { CAR.SUBARU_ASCENT: { diff --git a/selfdrive/car/tesla/fingerprints.py b/selfdrive/car/tesla/fingerprints.py index 68c50a62ed..4ce1fd2653 100644 --- a/selfdrive/car/tesla/fingerprints.py +++ b/selfdrive/car/tesla/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.tesla.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FW_VERSIONS = { CAR.TESLA_AP2_MODELS: { diff --git a/selfdrive/car/toyota/fingerprints.py b/selfdrive/car/toyota/fingerprints.py index 292be96fc8..a6caba9ae5 100644 --- a/selfdrive/car/toyota/fingerprints.py +++ b/selfdrive/car/toyota/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.toyota.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu FW_VERSIONS = { CAR.TOYOTA_AVALON: { diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index 1cc99b41b5..2eb2fdab72 100644 --- a/selfdrive/car/toyota/toyotacan.py +++ b/selfdrive/car/toyota/toyotacan.py @@ -1,6 +1,6 @@ -from cereal import car +from selfdrive.car.data_structures import CarParams -SteerControlType = car.CarParams.SteerControlType +SteerControlType = CarParams.SteerControlType def create_steer_command(packer, steer, steer_req): diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index 74fbd69939..39532092bc 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -4,11 +4,12 @@ from dataclasses import dataclass, field from enum import Enum, IntFlag from openpilot.selfdrive.car import CarSpecs, PlatformConfig, Platforms, AngleRateLimit, dbc_dict -from openpilot.selfdrive.car.data_structures import Ecu +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.docs_definitions import CarFootnote, CarDocs, Column, CarParts, CarHarness from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries +Ecu = CarParams.Ecu MIN_ACC_SPEED = 19. * CV.MPH_TO_MS PEDAL_TRANSITION = 10. * CV.MPH_TO_MS diff --git a/selfdrive/car/volkswagen/fingerprints.py b/selfdrive/car/volkswagen/fingerprints.py index 71bdb2cfd4..646efd4e48 100644 --- a/selfdrive/car/volkswagen/fingerprints.py +++ b/selfdrive/car/volkswagen/fingerprints.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.volkswagen.values import CAR -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu # TODO: Sharan Mk2 EPS and DQ250 auto trans both require KWP2000 support for fingerprinting diff --git a/selfdrive/debug/format_fingerprints.py b/selfdrive/debug/format_fingerprints.py index 2a5e4e6080..2e7c0348a1 100755 --- a/selfdrive/debug/format_fingerprints.py +++ b/selfdrive/debug/format_fingerprints.py @@ -2,28 +2,24 @@ import jinja2 import os -from cereal import car from openpilot.common.basedir import BASEDIR from openpilot.selfdrive.car.interfaces import get_interface_attr -Ecu = car.CarParams.Ecu - CARS = get_interface_attr('CAR') FW_VERSIONS = get_interface_attr('FW_VERSIONS') FINGERPRINTS = get_interface_attr('FINGERPRINTS') -ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} FINGERPRINTS_PY_TEMPLATE = jinja2.Template(""" {%- if FINGERPRINTS[brand] %} # ruff: noqa: E501 {% endif %} {% if FW_VERSIONS[brand] %} -from cereal import car +from openpilot.selfdrive.car.data_structures import CarParams {% endif %} from openpilot.selfdrive.car.{{brand}}.values import CAR {% if FW_VERSIONS[brand] %} -Ecu = car.CarParams.Ecu +Ecu = CarParams.Ecu {% endif %} {% if comments +%} {{ comments | join() }} @@ -49,7 +45,7 @@ FW_VERSIONS{% if not FW_VERSIONS[brand] %}: dict[str, dict[tuple, list[bytes]]]{ {% for car, _ in FW_VERSIONS[brand].items() %} CAR.{{car.name}}: { {% for key, fw_versions in FW_VERSIONS[brand][car].items() %} - (Ecu.{{ECU_NAME[key[0]]}}, 0x{{"%0x" | format(key[1] | int)}}, \ + (Ecu.{{key[0]}}, 0x{{"%0x" | format(key[1] | int)}}, \ {% if key[2] %}0x{{"%0x" | format(key[2] | int)}}{% else %}{{key[2]}}{% endif %}): [ {% for fw_version in (fw_versions + extra_fw_versions.get(car, {}).get(key, [])) | unique | sort %} {{fw_version}}, @@ -71,9 +67,8 @@ def format_brand_fw_versions(brand, extra_fw_versions: None | dict[str, dict[tup comments = [line for line in f.readlines() if line.startswith("#") and "noqa" not in line] with open(fingerprints_file, "w") as f: - f.write(FINGERPRINTS_PY_TEMPLATE.render(brand=brand, comments=comments, ECU_NAME=ECU_NAME, - FINGERPRINTS=FINGERPRINTS, FW_VERSIONS=FW_VERSIONS, - extra_fw_versions=extra_fw_versions)) + f.write(FINGERPRINTS_PY_TEMPLATE.render(brand=brand, comments=comments, FINGERPRINTS=FINGERPRINTS, + FW_VERSIONS=FW_VERSIONS, extra_fw_versions=extra_fw_versions)) if __name__ == "__main__":