From 42dc0af6692016129c89f1b54c1c25b9118044d0 Mon Sep 17 00:00:00 2001 From: deanlee Date: Sun, 2 Jun 2024 11:39:04 +0800 Subject: [PATCH] cache car brands --- selfdrive/car/interfaces.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index a9ff1eedd57770..eede096fe7fb16 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -33,6 +33,8 @@ TORQUE_OVERRIDE_PATH = os.path.join(BASEDIR, 'selfdrive/car/torque_data/override.toml') TORQUE_SUBSTITUTE_PATH = os.path.join(BASEDIR, 'selfdrive/car/torque_data/substitute.toml') +CAR_BRANDS = sorted(entry.name for entry in os.scandir(BASEDIR + '/selfdrive/car') if entry.is_dir()) + class LatControlInputs(NamedTuple): lateral_acceleration: float @@ -477,15 +479,13 @@ def update(self, CC: car.CarControl.Actuators, CS: car.CarState, now_nanos: int) } # interface-specific helpers - def get_interface_attr(attr: str, combine_brands: bool = False, ignore_none: bool = False) -> dict[str | StrEnum, Any]: # read all the folders in selfdrive/car and return a dict where: # - keys are all the car models or brand names # - values are attr values from all car folders result = {} - for car_folder in sorted([x[0] for x in os.walk(BASEDIR + '/selfdrive/car')]): + for brand_name in CAR_BRANDS: try: - brand_name = car_folder.split('/')[-1] brand_values = __import__(f'openpilot.selfdrive.car.{brand_name}.{INTERFACE_ATTR_FILE.get(attr, "values")}', fromlist=[attr]) if hasattr(brand_values, attr) or not ignore_none: attr_data = getattr(brand_values, attr, None)