Skip to content

Commit

Permalink
Merge pull request #85 from Northeastern-Electric-Racing/feature/sani…
Browse files Browse the repository at this point in the history
…tize_json

Add a JSON spec check on build
  • Loading branch information
harrison-e authored Dec 21, 2024
2 parents 1d22ca9 + 2300677 commit e4e1199
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "Embedded-Base"]
path = Embedded-Base
url = ../Embedded-Base
url = https://github.com/Northeastern-Electric-Racing/Embedded-Base.git
branch = main
52 changes: 37 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ daedalus = { path = "./libs/daedalus" }

[build-dependencies]
protobuf-codegen = "3.5.1"
calypso-cangen = { path = "./libs/calypso-cangen" }

[profile.release]
lto = true
Expand Down
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use calypso_cangen::validate::*;
use std::process;

/* Prebuild script */
fn main() {
println!("cargo:rerun-if-changed=Embedded-Base");
Expand All @@ -12,4 +15,16 @@ fn main() {
// Specify output directory relative to Cargo output directory.
.out_dir("src")
.run_from_script();

// Validate CAN spec
match validate_all_spec() {
Ok(()) => {}
Err(errors) => {
for error in errors {
// The \x1b[...m is an ANSI escape sequence for colored terminal output
println!("\x1b[31;1mCAN spec error:\x1b[0m {}", error);
}
process::exit(1);
}
}
}
2 changes: 2 additions & 0 deletions libs/calypso-cangen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ edition = "2021"
proc-macro2.workspace = true
quote.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
thiserror = "2.0.6"
4 changes: 2 additions & 2 deletions libs/calypso-cangen/src/can_gen_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl CANGenEncode for CANPoint {
}
_ => quote! {},
};
let default_value: f32 = match self.default_value {
Some(default_value) => default_value,
let default_value: f32 = match self.default {
Some(default) => default,
_ => 0f32,
};
let float_final = quote! {
Expand Down
7 changes: 5 additions & 2 deletions libs/calypso-cangen/src/can_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::Deserialize;
* Class representing a CAN message
*/
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct CANMsg {
pub id: String,
pub desc: String,
Expand All @@ -23,6 +24,7 @@ pub struct CANMsg {
* Class representing a NetField of a CAN message
*/
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct NetField {
pub name: String,
pub unit: String,
Expand All @@ -36,17 +38,18 @@ pub struct NetField {
* Class representing a CAN point of a NetField
*/
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct CANPoint {
pub size: usize,
pub signed: Option<bool>,
pub endianness: Option<String>,
pub format: Option<String>,
pub default_value: Option<f32>,
pub default: Option<f32>,
pub ieee754_f32: Option<bool>,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
#[serde(untagged, deny_unknown_fields)]
pub enum Sim {
SimSweep {
min: f32,
Expand Down
7 changes: 7 additions & 0 deletions libs/calypso-cangen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pub mod can_gen_decode;
pub mod can_gen_encode;
pub mod can_types;
pub mod validate;
/**
* Path to CAN spec JSON files
* Used by all daedalus macros
* Filepath is relative to project root (i.e. /Calypso)
*/
pub const CANGEN_SPEC_PATH: &str = "./Embedded-Base/cangen/can-messages";
Loading

0 comments on commit e4e1199

Please sign in to comment.