Skip to content

Commit

Permalink
operational round bool, simulation enum support (#69)
Browse files Browse the repository at this point in the history
* operational round bool, simulation enum support

* bump embedded base

* format and update ci

* add a format check

* fix fmt

---------

Co-authored-by: tszwingli <[email protected]>
  • Loading branch information
jr1221 and tszwinglitw authored Nov 29, 2024
1 parent 5968634 commit 6c79ea5
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 231 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Python
run: sudo apt-get install python3
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Build
run: cargo build --verbose
- name: Test
run: cargo test --verbose
- name: Fmt
run: cargo fmt --check
- name: Clippy
run: cargo clippy --verbose -- -D warnings
run: cargo clippy --verbose --all -- -D warnings
- name: Audit
run: cargo audit
30 changes: 13 additions & 17 deletions libs/calypso-cangen/src/can_gen_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use quote::{format_ident, quote};

/**
* Trait to generate individual decode function for a CANMsg
* For NetField and CANPoint, generates parts of the function
* For NetField and CANPoint, generates parts of the function
*/
pub trait CANGenDecode {
fn gen_decoder_fn(&mut self) -> ProcMacro2TokenStream;
Expand Down Expand Up @@ -62,11 +62,11 @@ impl CANGenDecode for NetField {
let mut point_skips = ProcMacro2TokenStream::new();
for point in &self.points {
let size_literal = Literal::usize_unsuffixed(point.size);
let skip_line = quote! {
reader.skip(#size_literal).unwrap();
let skip_line = quote! {
reader.skip(#size_literal).unwrap();
};
point_skips.extend(skip_line);
}
}
quote! {
#point_skips
}
Expand Down Expand Up @@ -148,20 +148,16 @@ impl CANGenDecode for CANPoint {
_ => quote! { reader.read_in::<#size_literal, u32>().unwrap() },
};
let read_type = match self.signed {
Some(true) => {
match self.size {
0..=8 => quote! { i8 },
9..=16 => quote! { i16 },
_ => quote! { i32 }
}
Some(true) => match self.size {
0..=8 => quote! { i8 },
9..=16 => quote! { i16 },
_ => quote! { i32 },
},
_ => match self.size {
0..=8 => quote! { u8 },
9..=16 => quote! { u16 },
_ => quote! { u32 },
},
_ => {
match self.size {
0..=8 => quote! { u8 },
9..=16 => quote! { u16 },
_ => quote! { u32 }
}
}
};

// prefix to call potential format function
Expand Down
32 changes: 14 additions & 18 deletions libs/calypso-cangen/src/can_gen_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ impl CANGenEncode for CANMsg {
}
}
}
},
}
None => {
quote! { }
quote! {}
}
}
}
Expand Down Expand Up @@ -83,27 +83,23 @@ impl CANGenEncode for CANPoint {
fn gen_encoder_fn(&mut self) -> ProcMacro2TokenStream {
let size_literal = Literal::usize_unsuffixed(self.size);
let write_type = match self.signed {
Some(true) => {
match self.size {
0..=8 => quote! { i8 },
9..=16 => quote! { i16 },
_ => quote! { i32 }
}
Some(true) => match self.size {
0..=8 => quote! { i8 },
9..=16 => quote! { i16 },
_ => quote! { i32 },
},
_ => match self.size {
0..=8 => quote! { u8 },
9..=16 => quote! { u16 },
_ => quote! { u32 },
},
_ => {
match self.size {
0..=8 => quote! { u8 },
9..=16 => quote! { u16 },
_ => quote! { u32 }
}
}
};
let format_prefix = match &self.format {
Some(format) => {
let id = format_ident!("{}_e", format);
quote! { FormatData::#id }
}
_ => quote! { },
_ => quote! {},
};
let default_value: f32 = match self.default_value {
Some(default_value) => default_value,
Expand All @@ -119,7 +115,7 @@ impl CANGenEncode for CANPoint {
quote! {
writer.write_as_from::<LittleEndian, #write_type>(#float_final as #write_type).unwrap();
}
},
}
// Big endian (default)
_ => {
match self.signed {
Expand All @@ -128,7 +124,7 @@ impl CANGenEncode for CANPoint {
quote! {
writer.write_signed_out::<#size_literal, #write_type>(#float_final as #write_type).unwrap();
}
},
}
// Unsigned (default)
_ => {
quote! {
Expand Down
20 changes: 16 additions & 4 deletions libs/calypso-cangen/src/can_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ pub struct NetField {
pub points: Vec<CANPoint>,
pub send: Option<bool>,
pub topic_append: Option<bool>,
pub sim_min: Option<f32>,
pub sim_max: Option<f32>,
pub sim_inc_min: Option<f32>,
pub sim_inc_max: Option<f32>,
pub sim: Option<Sim>,
}

/**
Expand All @@ -42,3 +39,18 @@ pub struct CANPoint {
pub format: Option<String>,
pub default_value: Option<f32>,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum Sim {
SimSweep {
min: f32,
max: f32,
inc_min: f32,
inc_max: f32,
round: Option<bool>,
},
SimEnum {
options: Vec<[f32; 2]>,
},
}
2 changes: 1 addition & 1 deletion libs/calypso-cangen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod can_types;
pub mod can_gen_decode;
pub mod can_gen_encode;
pub mod can_types;
Loading

0 comments on commit 6c79ea5

Please sign in to comment.