From 37304e13251b7187b5be62d003e5bad4f25cc6c5 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 9 Aug 2024 16:15:29 -0700 Subject: [PATCH] remove cereal from car_helpers (TODO: caching) --- selfdrive/car/car_helpers.py | 8 ++++---- selfdrive/car/data_structures.py | 14 ++++++++++++-- selfdrive/car/interfaces.py | 6 +++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index d2345f1a05..7af2cac996 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -1,9 +1,9 @@ import os import time -from cereal import car from openpilot.selfdrive.car import carlog from openpilot.selfdrive.car.can_definitions import CanRecvCallable, CanSendCallable +from openpilot.selfdrive.car.data_structures import CarParams from openpilot.selfdrive.car.interfaces import get_interface_attr from openpilot.selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars from openpilot.selfdrive.car.vin import get_vin, is_valid_vin, VIN_UNKNOWN @@ -135,17 +135,17 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu car_fingerprint, finger = can_fingerprint(can_recv) exact_match = True - source = car.CarParams.FingerprintSource.can + source = CarParams.FingerprintSource.can # If FW query returns exactly 1 candidate, use it if len(fw_candidates) == 1: car_fingerprint = list(fw_candidates)[0] - source = car.CarParams.FingerprintSource.fw + source = CarParams.FingerprintSource.fw exact_match = exact_fw_match if fixed_fingerprint: car_fingerprint = fixed_fingerprint - source = car.CarParams.FingerprintSource.fixed + source = CarParams.FingerprintSource.fixed carlog.error({"event": "fingerprinted", "car_fingerprint": str(car_fingerprint), "source": source, "fuzzy": not exact_match, "cached": cached, "fw_count": len(car_fw), "ecu_responses": list(ecu_rx_addrs), "vin_rx_addr": vin_rx_addr, diff --git a/selfdrive/car/data_structures.py b/selfdrive/car/data_structures.py index ef93d6b2b1..58ac750c7d 100644 --- a/selfdrive/car/data_structures.py +++ b/selfdrive/car/data_structures.py @@ -170,8 +170,9 @@ class CarParams: carFw: list['CarParams.CarFw'] = auto_field() radarTimeStep: float = 0.05 # time delta between radar updates, 20Hz is very standard - # fingerprintSource: FingerprintSource = auto_field() - # networkLocation: NetworkLocation = auto_field() # Where Panda/C2 is integrated into the car's CAN network + fingerprintSource: 'CarParams.FingerprintSource' = field(default_factory=lambda: CarParams.FingerprintSource.can) + # Where Panda/C2 is integrated into the car's CAN network + networkLocation: 'CarParams.NetworkLocation' = field(default_factory=lambda: CarParams.NetworkLocation.fwdCamera) wheelSpeedFactor: float = auto_field() # Multiplier on wheels speeds to computer actual speeds @@ -274,3 +275,12 @@ class CarParams: programmedFuelInjection = auto() debug = auto() + + class FingerprintSource(StrEnum): + can = auto() + fw = auto() + fixed = auto() + + class NetworkLocation(StrEnum): + fwdCamera = auto() # Standard/default integration at LKAS camera + gateway = auto() # Integration at vehicle's CAN gateway diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 5db51d2d87..83a388d2a6 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -117,14 +117,14 @@ class CarInterfaceBase(ABC): return ACCEL_MIN, ACCEL_MAX @classmethod - def get_non_essential_params(cls, candidate: str): + def get_non_essential_params(cls, candidate: str) -> CarParams: """ Parameters essential to controlling the car may be incomplete or wrong without FW versions or fingerprints. """ return cls.get_params(candidate, gen_empty_fingerprint(), list(), False, False) @classmethod - def get_params(cls, candidate: str, fingerprint: dict[int, dict[int, int]], car_fw: list[CarParams.CarFw], experimental_long: bool, docs: bool): + def get_params(cls, candidate: str, fingerprint: dict[int, dict[int, int]], car_fw: list[CarParams.CarFw], experimental_long: bool, docs: bool) -> CarParams: ret = CarInterfaceBase.get_std_params(candidate) platform = PLATFORMS[candidate] @@ -152,7 +152,7 @@ class CarInterfaceBase(ABC): @staticmethod @abstractmethod def _get_params(ret: CarParams, candidate, fingerprint: dict[int, dict[int, int]], - car_fw: list[CarParams.CarFw], experimental_long: bool, docs: bool): + car_fw: list[CarParams.CarFw], experimental_long: bool, docs: bool) -> CarParams: raise NotImplementedError @staticmethod