Skip to content

Commit

Permalink
Handle fingerprints refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonjchen authored Apr 20, 2024
1 parent bfd81e5 commit 33e8f58
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ class CAR:
HYUNDAI_GENESIS = "HYUNDAI GENESIS 2015-2016"
IONIQ = "HYUNDAI IONIQ HYBRID 2017-2019"
Another format is to look in in fingerprints.py instead of values.py
Exerpt:
FW_VERSIONS = {
CAR.TOYOTA_AVALON: {
(Ecu.abs, 0x7b0, None): [
b'F152607060\x00\x00\x00\x00\x00\x00',
],
... continued }
`cars` should be an array of strings like this:
[
Expand All @@ -34,20 +45,29 @@ class CAR:
"HYUNDAI IONIQ HYBRID 2017-2019"
...
]
For the second one, it should be like this:
[
"TOYOTA AVALON",
...
]
"""
# Checkout branch
os.system(f"cd comma_openpilot && git checkout --force {branch}")

# Get a list of values.py underneath the folder
# "comma_openpilot/selfdrive/car/"

paths = []
values_py_paths = []
fingerprints_py_paths = []
cars = []

for root, dirs, files in os.walk("comma_openpilot/selfdrive/car/"):
paths += [os.path.join(root, f) for f in files if f == "values.py"]
values_py_paths += [os.path.join(root, f) for f in files if f == "values.py"]

cars = []

for path in paths:
for path in values_py_paths:
logging.info("Parsing %s", path)
with open(path, "r") as f:
tree = ast.parse(f.read())
Expand All @@ -60,9 +80,23 @@ class CAR:
# Sometimes it's an object initializer,
# If so, use the first argument
elif isinstance(c.value, ast.Call):
# Sometimes
if len(c.value.args) > 0 and isinstance(c.value.args[0], ast.Str):
cars.append(c.value.args[0].s)

for root, dirs, files in os.walk("comma_openpilot/selfdrive/car/"):
fingerprints_py_paths += [os.path.join(root, f) for f in files if f == "fingerprints.py"]

for path in fingerprints_py_paths:
logging.info("Parsing %s", path)
with open(path, "r") as f:
tree = ast.parse(f.read())
for node in ast.walk(tree):
if isinstance(node, ast.Assign) and isinstance(node.value, ast.Dict):
for key in node.value.keys:
if isinstance(key, ast.Attribute):
cars.append(key.attr)

# Log the cars
logging.info("Found %d cars in %s", len(cars), branch)

Expand Down Expand Up @@ -105,7 +139,7 @@ def generate_branch(base, car):
# & is AND because & may be too special
# Lowercase because there's no caps lock in the keyboard
# Remove () because they are special characters and may cause issues
branch_name = f"{base}-{car.replace(' ', '-').replace('&', 'AND').replace('(', '').replace(')','').lower()}"
branch_name = f"{base}-{car.replace(' ', '-').replace('&', 'AND').replace('(', '').replace(')','').replace('_', '-').lower()}"
logging.info("Generating branch %s", branch_name)
# Delete branch if it already exists
os.system(f"cd comma_openpilot && git branch -D {branch_name}")
Expand Down

0 comments on commit 33e8f58

Please sign in to comment.