scons sort of working
parent
0ef1e35d97
commit
eb78f6aa1b
|
@ -0,0 +1,24 @@
|
|||
Import('env')
|
||||
|
||||
import os
|
||||
from opendbc.can.process_dbc import process
|
||||
|
||||
for x in os.listdir('../'):
|
||||
if x.endswith(".dbc"):
|
||||
def build(target, source, env):
|
||||
process(source[0].path, target[0].path)
|
||||
in_fn = os.path.join('../', x)
|
||||
out_fn = os.path.join('dbc_out', x.replace(".dbc", ".cc"))
|
||||
env.Command(out_fn, in_fn, build)
|
||||
|
||||
"""
|
||||
dbcs = []
|
||||
for x in os.listdir('../'):
|
||||
if x.endswith(".dbc"):
|
||||
dbcs.append(env.Command(
|
||||
[os.path.join('dbc_out', x.replace(".dbc", ".cc"))],
|
||||
[os.path.join('../', x)],
|
||||
"python3 opendbc/can/process_dbc.py ../ $SOURCE"))
|
||||
print(dbcs)
|
||||
"""
|
||||
|
|
@ -8,22 +8,16 @@ import jinja2
|
|||
from collections import Counter
|
||||
from opendbc.can.dbc import dbc
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("usage: %s dbc_directory output_filename" % (sys.argv[0],))
|
||||
sys.exit(0)
|
||||
|
||||
dbc_dir = sys.argv[1]
|
||||
out_fn = sys.argv[2]
|
||||
|
||||
def process(in_fn, out_fn):
|
||||
dbc_name = os.path.split(out_fn)[-1].replace('.cc', '')
|
||||
#print("processing %s: %s -> %s" % (dbc_name, in_fn, out_fn))
|
||||
|
||||
template_fn = os.path.join(os.path.dirname(__file__), "dbc_template.cc")
|
||||
|
||||
with open(template_fn, "r") as template_f:
|
||||
template = jinja2.Template(template_f.read(), trim_blocks=True, lstrip_blocks=True)
|
||||
|
||||
can_dbc = dbc(os.path.join(dbc_dir, dbc_name + '.dbc'))
|
||||
can_dbc = dbc(in_fn)
|
||||
|
||||
msgs = [(address, msg_name, msg_size, sorted(msg_sigs, key=lambda s: s.name not in ("COUNTER", "CHECKSUM"))) # process counter and checksums first
|
||||
for address, ((msg_name, msg_size), msg_sigs) in sorted(can_dbc.msgs.items()) if msg_sigs]
|
||||
|
@ -97,9 +91,22 @@ def main():
|
|||
|
||||
parser_code = template.render(dbc=can_dbc, checksum_type=checksum_type, msgs=msgs, def_vals=def_vals, len=len)
|
||||
|
||||
|
||||
with open(out_fn, "w") as out_f:
|
||||
out_f.write(parser_code)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("usage: %s dbc_directory output_filename" % (sys.argv[0],))
|
||||
sys.exit(0)
|
||||
|
||||
dbc_dir = sys.argv[1]
|
||||
out_fn = sys.argv[2]
|
||||
|
||||
dbc_name = os.path.split(out_fn)[-1].replace('.cc', '')
|
||||
in_fn = os.path.join(dbc_dir, dbc_name + '.dbc')
|
||||
|
||||
process(in_fn, out_fn)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
Loading…
Reference in New Issue