Skip to content

Commit

Permalink
Add OpenCan tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkoziej committed Mar 10, 2024
1 parent 69de01b commit ef26bd9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
1 change: 1 addition & 0 deletions SConstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'default',
'Component',
'EspIdf',
'OpenCan',
'Phony',
],
)
Expand Down
14 changes: 1 addition & 13 deletions can/SConscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@
Import('env')


dbc = env.File('network.dbc')
network = env.File('network.yml')

dbc_emmitter = env.Command(
'create-dbc.py',
network,
[
'opencan-cli compose $SOURCE --dump-python > $TARGET',
# what a crime
f'sed -i -e s%opencan\\.dbc%{dbc.path}%g $TARGET',
],
)

dbc = env.Command(dbc, dbc_emmitter, 'python $SOURCE')
dbc = env.OpenCanDbc(network)
env.Alias('dbc', dbc)


Expand Down
57 changes: 57 additions & 0 deletions site_scons/site_tools/OpenCan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os


OUTPUTS = [
f'opencan_{file}'
for file in [
'callbacks.h',
'rx.c',
'rx.h',
'templates.h',
'tx.c',
'tx.h',
]
]


def OpenCan(env, network, node, *, GEN_DIR=None):
if GEN_DIR is None:
GEN_DIR = env.Dir('opencan-codegen')

out = env.Command(
[f'{GEN_DIR.path}/{output}' for output in OUTPUTS],
network,
f'opencan-cli codegen {network.path} {GEN_DIR.path} {node}',
)

return out


def OpenCanDbc(env, network):
dbc = env.File(os.path.splitext(network.path)[0] + '.dbc')

dbc_emmitter = env.Command(
'dbc-emmitter.py',
network,
[
'opencan-cli compose $SOURCE --dump-python > $TARGET',
# what a crime
f'sed -i -e s%opencan\\.dbc%{dbc.path}%g $TARGET',
],
)

dbc = env.Command(dbc, dbc_emmitter, 'python $SOURCE')

return dbc


def generate(env):
if env.Detect('OpenCan') and env.Detect('OpenCanDbc'):
return

env.AddMethod(OpenCan, 'OpenCan')
env.AddMethod(OpenCanDbc, 'OpenCanDbc')


def exists(env):
return env.Detect('OpenCan') and env.Detect('OpenCanDbc')

0 comments on commit ef26bd9

Please sign in to comment.