Skip to content

Commit f143c5e

Browse files
committed
Add boolean test case
1 parent 02b77c7 commit f143c5e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

testing/can-messages/src/messages.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,13 @@ impl Bar {
180180
pub const MESSAGE_ID: u32 = 512;
181181

182182
/// Construct new Bar from values
183-
pub fn new(one: u8, two: f32, three: u8, four: u8) -> Result<Self, CanError> {
183+
pub fn new(one: u8, two: f32, three: u8, four: u8, five: bool) -> Result<Self, CanError> {
184184
let mut res = Self { raw: [0u8; 8] };
185185
res.set_one(one)?;
186186
res.set_two(two)?;
187187
res.set_three(three)?;
188188
res.set_four(four)?;
189+
res.set_five(five)?;
189190
Ok(res)
190191
}
191192

@@ -367,6 +368,42 @@ impl Bar {
367368
value.pack_be_bits(&mut self.raw, start_bit, bits);
368369
Ok(())
369370
}
371+
372+
/// Five
373+
///
374+
/// - Min: 0
375+
/// - Max: 1
376+
/// - Unit: "boolean"
377+
/// - Receivers: Dolor
378+
#[inline(always)]
379+
pub fn five(&self) -> bool {
380+
self.five_raw()
381+
}
382+
383+
/// Get raw value of Five
384+
///
385+
/// - Start bit: 30
386+
/// - Signal size: 1 bits
387+
/// - Factor: 1
388+
/// - Offset: 0
389+
/// - Byte order: BigEndian
390+
/// - Value type: Unsigned
391+
#[inline(always)]
392+
pub fn five_raw(&self) -> bool {
393+
let signal = u8::unpack_be_bits(&self.raw, (30 - (1 - 1)), 1);
394+
395+
signal == 1
396+
}
397+
398+
/// Set value of Five
399+
#[inline(always)]
400+
pub fn set_five(&mut self, value: bool) -> Result<(), CanError> {
401+
let value = value as u8;
402+
let start_bit = 30;
403+
let bits = 1;
404+
value.pack_be_bits(&mut self.raw, start_bit, bits);
405+
Ok(())
406+
}
370407
}
371408

372409
impl core::convert::TryFrom<&[u8]> for Bar {

testing/dbc-examples/example.dbc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BO_ 512 Bar: 8 Ipsum
1717
SG_ Two : 7|8@0+ (0.39,0) [0.00|100] "%" Dolor
1818
SG_ Three : 13|3@0+ (1,0) [0|7] "" Dolor
1919
SG_ Four : 10|2@0+ (1,0) [0|3] "" Dolor
20+
SG_ Five : 30|1@0+ (1,0) [0|1] "boolean" Dolor
2021

2122

2223

0 commit comments

Comments
 (0)