Skip to content

Commit

Permalink
cache car brands
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jun 2, 2024
1 parent ce2a686 commit 42dc0af
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 42dc0af

Please sign in to comment.