-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turned cangen into a module, and refactored cangen (#233)
* packaged can_generator into python package * Added object for config and busses, fixed cangen * refactored module and restructured some code * used pop to parse config.yaml * updated readme to be more clear * changed name of config * added pop to consume config.yaml * made readme more clear * fixed can_generator errors * Update cmake to use CANgen and change install docs * Adds note about editable install * Reincorporates Clean Cangen --------- Co-authored-by: BlakeFreer <[email protected]>
- Loading branch information
1 parent
cd60958
commit 6e6610d
Showing
19 changed files
with
786 additions
and
201 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
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
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 |
---|---|---|
|
@@ -2,5 +2,4 @@ canGen: | |
ourNode: lvc | ||
busses: | ||
- busName: veh | ||
dbcFiles: | ||
- "../veh.dbc" | ||
dbcFile: "../veh.dbc" |
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 |
---|---|---|
|
@@ -2,5 +2,4 @@ canGen: | |
ourNode: tms | ||
busses: | ||
- busName: veh | ||
dbcFiles: | ||
- "../veh.dbc" | ||
dbcFile: "../veh.dbc" |
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 |
---|---|---|
|
@@ -2,5 +2,4 @@ canGen: | |
ourNode: FC | ||
busses: | ||
- busName: io | ||
dbcFiles: | ||
- "io.dbc" | ||
dbcFile: "io.dbc" |
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 |
---|---|---|
|
@@ -2,5 +2,4 @@ canGen: | |
ourNode: FRONTCONTROLLER | ||
busses: | ||
- busName: vehicle | ||
dbcFiles: | ||
- "pedal.dbc" | ||
dbcFile: "pedal.dbc" |
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,43 @@ | ||
# Cangen | ||
|
||
Generates C++ files from a corresponding dbc file. Ensures repeatable generation between all projects. | ||
|
||
## Installation | ||
|
||
From the `racecar/` directory, run | ||
|
||
```bash | ||
pip install scripts/cangen | ||
``` | ||
|
||
## Usage | ||
|
||
To generate CAN code for a project, execute `cangen` and pass the project folder. The project folder is the one which contains `config.yaml`. | ||
|
||
## Example | ||
|
||
If you are in the `racecar/firmware/` directory, you could generate `EV5/FrontController` code with | ||
|
||
```bash | ||
cangen projects/EV5/FrontController | ||
``` | ||
|
||
This command will generate code in a `generated/can/` subfolder of the project. | ||
|
||
``` | ||
FrontController | ||
├─ fc_docs | ||
├─ generated/can | ||
│ ├─ .gitignore | ||
│ ├─ pt_can_messages.h | ||
│ ├─ pt_msg_registry.h | ||
│ ├─ veh_can_messages.h | ||
│ └─ veh_msg_registry.h | ||
├─ inc | ||
├─ platforms | ||
├─ vehicle_control_system | ||
├─ CMakeLists.txt | ||
├─ config.yaml | ||
├─ main.cc | ||
└─ README.md | ||
``` |
Empty file.
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,34 @@ | ||
from __future__ import annotations | ||
import yaml | ||
|
||
DEFAULT_OUTPUT_DIR = "generated/can" | ||
|
||
|
||
class Bus: | ||
def __init__(self, bus: dict): | ||
self.dbc_file_path: str = bus.pop("dbcFile") | ||
self.bus_name: str = bus.pop("busName").capitalize() | ||
|
||
if bus: | ||
raise ValueError( | ||
f"{bus.keys()} field/s not expected in configuration file for bus {self.bus_name}." | ||
) | ||
|
||
|
||
class Config: | ||
@staticmethod | ||
def from_yaml(config_file_name: str) -> Config: | ||
with open(config_file_name, "r") as file: | ||
config = yaml.safe_load(file) | ||
return Config(config.pop("canGen")) | ||
|
||
def __init__(self, config: dict): | ||
self.node = config.pop("ourNode") | ||
self.output_dir = config.pop("outputPath", DEFAULT_OUTPUT_DIR) | ||
|
||
self.busses = [Bus(bus) for bus in config.pop("busses")] | ||
|
||
if config: | ||
raise ValueError( | ||
f"{config.keys()} field/s not expected in configuration file from node." | ||
) |
Oops, something went wrong.