openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.9 KiB

import jinja2
from cereal import car
Ecu = car.CarParams.Ecu
from openpilot.selfdrive.car.interfaces import get_interface_attr
CARS = get_interface_attr('CAR')
FW_VERSIONS = get_interface_attr('FW_VERSIONS')
FINGERPRINTS = get_interface_attr('FINGERPRINTS')
PLATFORM_TO_PYTHON_CAR_NAME = {brand: {car.value: car.name for car in CARS[brand]} for brand in CARS}
ECU_NUMBER_TO_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
FINGERPRINTS_PY_TEMPLATE = """{% if brand in FINGERPRINTS %}
# ruff: noqa: E501
{% endif %}
{% if brand in FW_VERSIONS %}
from cereal import car
{% endif %}
from openpilot.selfdrive.car.{{brand}}.values import CAR
{% if brand in FW_VERSIONS %}
Ecu = car.CarParams.Ecu
{% endif %}
{% if brand in FINGERPRINTS %}
FINGERPRINTS = {
{% for car, fingerprints in FINGERPRINTS[brand].items() %}
CAR.{{PLATFORM_TO_PYTHON_CAR_NAME[brand][car]}}: [
{% for fingerprint in fingerprints %} { {% for key, value in fingerprint.items() %}{{key}}: {{value}}, {% endfor %}},
{% endfor %}
],
{% endfor %}
}
{% endif %}
{% if brand in FW_VERSIONS %}
FW_VERSIONS = {
{% for car, _ in FW_VERSIONS[brand].items() %}
CAR.{{PLATFORM_TO_PYTHON_CAR_NAME[brand][car]}}: {
{% for key, fw_versions in FW_VERSIONS[brand][car].items() %}
(Ecu.{{ECU_NUMBER_TO_NAME[key[0]]}}, 0x{{"%0x" | format(key[1] | int)}}, {{key[2]}}): [
{% for fw_version in fw_versions %}
{{fw_version}},
{% endfor %}
],
{% endfor %}
},
{% endfor %}
}
{% endif %}
"""
for brand in FW_VERSIONS.keys():
with open(f"selfdrive/car/{brand}/fingerprints.py", "w") as f:
template = jinja2.Template(FINGERPRINTS_PY_TEMPLATE, trim_blocks=True, lstrip_blocks=True)
f.write(template.render(brand=brand, ECU_NUMBER_TO_NAME=ECU_NUMBER_TO_NAME, PLATFORM_TO_PYTHON_CAR_NAME=PLATFORM_TO_PYTHON_CAR_NAME,
FINGERPRINTS=FINGERPRINTS, FW_VERSIONS=FW_VERSIONS))