Files
dragonpilot/generator/generator.py
Vehicle Researcher 4f4a90117b Squashed 'opendbc/' changes from 684e28a7a..f3b573559
f3b573559 move generator to python3
9efff4086 2019+ New Prius Steer Angle (#189)
f3461d143 add units and a couple new signals for toyota (#188)
16033b3ff Remove non ascii characters
de162d8c2 Toyota no dsu: fix steer angle factor, it's 1% of a rad
2fb524554 Lexus CT200H seems to have the safetyParam 1 instead of 0.73
b2fde8b11 toyota time signal (#187)
6cfe0c432 Fixed brake signal unit in Bosch Honda

git-subtree-dir: opendbc
git-subtree-split: f3b573559f1619346f082554a72cebcc43da5275
2019-10-09 18:31:57 +00:00

50 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import re
cur_path = os.path.dirname(os.path.realpath(__file__))
generator_path = os.path.join(cur_path, '../')
include_pattern = re.compile(r'CM_ "IMPORT (.*?)"')
def read_dbc(dir_name, filename):
with open(os.path.join(dir_name, filename)) as file_in:
return file_in.read()
def create_dbc(dir_name, filename):
dbc_file_in = read_dbc(dir_name, filename)
includes = include_pattern.findall(dbc_file_in)
output_filename = filename.replace('.dbc', '_generated.dbc')
output_file_location = os.path.join(generator_path, output_filename)
with open(output_file_location, 'w') as dbc_file_out:
dbc_file_out.write('CM_ "AUTOGENERATED FILE, DO NOT EDIT"\n')
for include_filename in reversed(includes):
include_file_header = '\n\nCM_ "Imported file %s starts here"\n' % include_filename
dbc_file_out.write(include_file_header)
include_file = read_dbc(dir_name, include_filename)
dbc_file_out.write(include_file)
dbc_file_out.write('\nCM_ "%s starts here"\n' % filename)
core_dbc = include_pattern.sub('', dbc_file_in)
dbc_file_out.write(core_dbc)
for dir_name, _, filenames in os.walk(cur_path):
if dir_name == cur_path:
continue
print(dir_name)
for filename in filenames:
if filename.startswith('_'):
continue
print(filename)
create_dbc(dir_name, filename)