Skip to content

Commit 33e8f58

Browse files
authored
Handle fingerprints refactor
1 parent bfd81e5 commit 33e8f58

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

generate.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ class CAR:
2424
HYUNDAI_GENESIS = "HYUNDAI GENESIS 2015-2016"
2525
IONIQ = "HYUNDAI IONIQ HYBRID 2017-2019"
2626
27+
Another format is to look in in fingerprints.py instead of values.py
28+
29+
Exerpt:
30+
31+
FW_VERSIONS = {
32+
CAR.TOYOTA_AVALON: {
33+
(Ecu.abs, 0x7b0, None): [
34+
b'F152607060\x00\x00\x00\x00\x00\x00',
35+
],
36+
... continued }
37+
2738
`cars` should be an array of strings like this:
2839
2940
[
@@ -34,20 +45,29 @@ class CAR:
3445
"HYUNDAI IONIQ HYBRID 2017-2019"
3546
...
3647
]
48+
49+
For the second one, it should be like this:
50+
51+
[
52+
"TOYOTA AVALON",
53+
...
54+
]
3755
"""
3856
# Checkout branch
3957
os.system(f"cd comma_openpilot && git checkout --force {branch}")
4058

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

44-
paths = []
62+
values_py_paths = []
63+
fingerprints_py_paths = []
64+
cars = []
65+
4566
for root, dirs, files in os.walk("comma_openpilot/selfdrive/car/"):
46-
paths += [os.path.join(root, f) for f in files if f == "values.py"]
67+
values_py_paths += [os.path.join(root, f) for f in files if f == "values.py"]
4768

48-
cars = []
4969

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

87+
for root, dirs, files in os.walk("comma_openpilot/selfdrive/car/"):
88+
fingerprints_py_paths += [os.path.join(root, f) for f in files if f == "fingerprints.py"]
89+
90+
for path in fingerprints_py_paths:
91+
logging.info("Parsing %s", path)
92+
with open(path, "r") as f:
93+
tree = ast.parse(f.read())
94+
for node in ast.walk(tree):
95+
if isinstance(node, ast.Assign) and isinstance(node.value, ast.Dict):
96+
for key in node.value.keys:
97+
if isinstance(key, ast.Attribute):
98+
cars.append(key.attr)
99+
66100
# Log the cars
67101
logging.info("Found %d cars in %s", len(cars), branch)
68102

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

0 commit comments

Comments
 (0)