Skip to content

Commit

Permalink
Got Rust autogeneration working with Rust prebuild hook!
Browse files Browse the repository at this point in the history
  • Loading branch information
nwdepatie committed Feb 27, 2024
1 parent d54ed4b commit f9d10c4
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 971 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Embedded-Base"]
path = Embedded-Base
url = [email protected]:Northeastern-Electric-Racing/Embedded-Base.git
1 change: 1 addition & 0 deletions Embedded-Base
Submodule Embedded-Base added at 0c828d
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::process::Command;

/* Prebuild script */
fn main() {
println!("cargo:rerun-if-env-changed=ALWAYS_RUN");

// Create a new command that runs bash
let mut command = Command::new("python3");

// Pass the script name as an argument
command.arg("./calypsogen.py");

// Execute the command
// This will download a file called ncbi_dataset.zip in the current directory
command.output().expect("Failed to generate can messages!");
}
35 changes: 35 additions & 0 deletions calypsogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import importlib.util
import sys

# Full path to the directory containing the cangen module
EMBEDDED_BASE_PATH = "./Embedded-Base"
module_name = "cangen"

# Full path to the cangen module file
module_path = f"{EMBEDDED_BASE_PATH}/{module_name}/__init__.py"

# Add the cangen directory to the system's path
sys.path.append(EMBEDDED_BASE_PATH)

# Load the module
spec = importlib.util.spec_from_file_location(module_name, module_path)
cangen = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cangen)

decode_data = open("./src/decode_data.rs", "w")
master_mapping = open("./src/master_mapping.rs", "w")

bms_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/bms.yaml", "r"))
mpu_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/mpu.yaml", "r"))
wheel_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/wheel.yaml", "r"))

bms_messages.msgs.extend(mpu_messages.msgs)
bms_messages.msgs.extend(wheel_messages.msgs)

result = cangen.RustSynth().parse_messages(bms_messages.msgs)

decode_data.write(result.decode_data)
decode_data.close()

master_mapping.write(result.master_mapping)
master_mapping.close()
158 changes: 0 additions & 158 deletions oxy/RustSynth.py

This file was deleted.

26 changes: 0 additions & 26 deletions oxy/YAMLParser.py

This file was deleted.

Loading

0 comments on commit f9d10c4

Please sign in to comment.