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.

83 lines
2.5 KiB

#!/usr/bin/env python3
2 years ago
import jinja2
import os
2 years ago
from cereal import car
from openpilot.common.basedir import BASEDIR
2 years ago
from openpilot.selfdrive.car.interfaces import get_interface_attr
Ecu = car.CarParams.Ecu
2 years ago
CARS = get_interface_attr('CAR')
FW_VERSIONS = get_interface_attr('FW_VERSIONS')
FINGERPRINTS = get_interface_attr('FINGERPRINTS')
2 years ago
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
2 years ago
FINGERPRINTS_PY_TEMPLATE = jinja2.Template("""
{%- if FINGERPRINTS[brand] %}
2 years ago
# ruff: noqa: E501
{% endif %}
2 years ago
{% if FW_VERSIONS[brand] %}
2 years ago
from cereal import car
{% endif %}
from openpilot.selfdrive.car.{{brand}}.values import CAR
2 years ago
{% if FW_VERSIONS[brand] %}
2 years ago
Ecu = car.CarParams.Ecu
{% endif %}
2 years ago
{% if FINGERPRINTS[brand] %}
2 years ago
{% if fingerprints_comments %}{{ fingerprints_comments | join() }}\n\n{% endif %}
2 years ago
FINGERPRINTS = {
{% for car, fingerprints in FINGERPRINTS[brand].items() %}
CAR.{{car.name}}: [
{% for fingerprint in fingerprints %}
{
{% for key, value in fingerprint.items() %}{{key}}: {{value}}{% if not loop.last %}, {% endif %}{% endfor %}
}{% if loop.last %}]{% endif %},
{% endfor %}
2 years ago
{% endfor %}
}
{% endif %}
2 years ago
{% if FW_VERSIONS[brand] %}
2 years ago
2 years ago
FW_VERSIONS = {
{% for car, _ in FW_VERSIONS[brand].items() %}
CAR.{{car.name}}: {
{% for key, fw_versions in FW_VERSIONS[brand][car].items() %}
2 years ago
(Ecu.{{ECU_NAME[key[0]]}}, 0x{{"%0x" | format(key[1] | int)}}, \
2 years ago
{% if key[2] %}0x{{"%0x" | format(key[2] | int)}}{% else %}{{key[2]}}{% endif %}): [
{% for fw_version in fw_versions %}
{{fw_version}},
2 years ago
{% endfor %}
],
{% endfor %}
2 years ago
},
{% endfor %}
}
{% endif %}
""", trim_blocks=True)
2 years ago
2 years ago
2 years ago
def format_brand_fw_versions(brand, extra_fw_versions: None | dict[str, dict[tuple, list[bytes]]] = None):
fw_versions = FW_VERSIONS.copy()
# TODO: this modifies FW_VERSIONS in place
if extra_fw_versions is not None:
for platform, ecus in extra_fw_versions.items():
for ecu, fws in ecus.items():
fw_versions[brand][platform][ecu] += fws
fingerprints_file = os.path.join(BASEDIR, f"selfdrive/car/{brand}/fingerprints.py")
with open(fingerprints_file, "r") as f:
fingerprints_comments = [line for line in f.readlines() if line.startswith("#") and "noqa" not in line]
with open(fingerprints_file, "w") as f:
f.write(FINGERPRINTS_PY_TEMPLATE.render(brand=brand, fingerprints_comments=fingerprints_comments, ECU_NAME=ECU_NAME,
2 years ago
FINGERPRINTS=FINGERPRINTS, FW_VERSIONS=fw_versions))
2 years ago
2 years ago
if __name__ == "__main__":
for brand in FW_VERSIONS.keys():
format_brand_fw_versions(brand)