-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69de01b
commit ef26bd9
Showing
3 changed files
with
59 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
'default', | ||
'Component', | ||
'EspIdf', | ||
'OpenCan', | ||
'Phony', | ||
], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |