less nested

pull/30792/head
Shane Smiskol 2 years ago
parent 6e11002886
commit 56bb9d2598
  1. 8
      selfdrive/debug/format_fingerprints.py

@ -11,7 +11,7 @@ Ecu = car.CarParams.Ecu
CARS = get_interface_attr('CAR') CARS = get_interface_attr('CAR')
FW_VERSIONS = get_interface_attr('FW_VERSIONS') FW_VERSIONS = get_interface_attr('FW_VERSIONS')
FINGERPRINTS = get_interface_attr('FINGERPRINTS') FINGERPRINTS = get_interface_attr('FINGERPRINTS')
PLATFORM_TO_PYTHON_CAR_NAME = {brand: {car.value: car.name for car in CARS[brand]} for brand in CARS} PLATFORM_TO_ENUM_NAME = {car.value: car.name for brand in CARS for car in CARS[brand]}
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
FINGERPRINTS_PY_TEMPLATE = jinja2.Template(""" FINGERPRINTS_PY_TEMPLATE = jinja2.Template("""
@ -30,7 +30,7 @@ Ecu = car.CarParams.Ecu
{% if FINGERPRINTS[brand] %} {% if FINGERPRINTS[brand] %}
FINGERPRINTS = { FINGERPRINTS = {
{% for car, fingerprints in FINGERPRINTS[brand].items() %} {% for car, fingerprints in FINGERPRINTS[brand].items() %}
CAR.{{PLATFORM_TO_PYTHON_CAR_NAME[brand][car]}}: [ CAR.{{PLATFORM_TO_ENUM_NAME[car]}}: [
{% for fingerprint in fingerprints %} {% for fingerprint in fingerprints %}
{ {
{% for key, value in fingerprint.items() %}{{key}}: {{value}}{% if not loop.last %}, {% endif %}{% endfor %} {% for key, value in fingerprint.items() %}{{key}}: {{value}}{% if not loop.last %}, {% endif %}{% endfor %}
@ -44,7 +44,7 @@ FINGERPRINTS = {
{% if FW_VERSIONS[brand] %} {% if FW_VERSIONS[brand] %}
FW_VERSIONS = { FW_VERSIONS = {
{% for car, _ in FW_VERSIONS[brand].items() %} {% for car, _ in FW_VERSIONS[brand].items() %}
CAR.{{PLATFORM_TO_PYTHON_CAR_NAME[brand][car]}}: { CAR.{{PLATFORM_TO_ENUM_NAME[car]}}: {
{% for key, fw_versions in FW_VERSIONS[brand][car].items() %} {% for key, fw_versions in FW_VERSIONS[brand][car].items() %}
(Ecu.{{ECU_NAME[key[0]]}}, 0x{{"%0x" | format(key[1] | int)}}, \ (Ecu.{{ECU_NAME[key[0]]}}, 0x{{"%0x" | format(key[1] | int)}}, \
{% if key[2] %}0x{{"%0x" | format(key[2] | int)}}{% else %}{{key[2]}}{% endif %}): [ {% if key[2] %}0x{{"%0x" | format(key[2] | int)}}{% else %}{{key[2]}}{% endif %}): [
@ -62,7 +62,7 @@ FW_VERSIONS = {
def format_brand_fw_versions(brand): def format_brand_fw_versions(brand):
with open(os.path.join(BASEDIR, f"selfdrive/car/{brand}/fingerprints.py"), "w") as f: with open(os.path.join(BASEDIR, f"selfdrive/car/{brand}/fingerprints.py"), "w") as f:
f.write(FINGERPRINTS_PY_TEMPLATE.render(brand=brand, ECU_NAME=ECU_NAME, PLATFORM_TO_PYTHON_CAR_NAME=PLATFORM_TO_PYTHON_CAR_NAME, f.write(FINGERPRINTS_PY_TEMPLATE.render(brand=brand, ECU_NAME=ECU_NAME, PLATFORM_TO_ENUM_NAME=PLATFORM_TO_ENUM_NAME,
FINGERPRINTS=FINGERPRINTS, FW_VERSIONS=FW_VERSIONS)) FINGERPRINTS=FINGERPRINTS, FW_VERSIONS=FW_VERSIONS))

Loading…
Cancel
Save