Add methods to get signal min and max values
andresv opened this issue · comments
For example here we have steering angle that goes from -500
to 500
.
BO_ 37 STEER_ANGLE_SENSOR: 8 XXX
SG_ STEER_ANGLE : 3|12@0- (1.5,0) [-500|500] "deg" XXX
SG_ STEER_FRACTION : 39|4@0- (0.1,0) [-0.7|0.7] "deg" XXX
SG_ STEER_RATE : 35|12@0- (1,0) [-2000|2000] "deg/s" XXX
It would be useful to access those values also from Rust. Currently they are actually hardcoded in range check.
/// Set value of STEER_ANGLE
#[inline(always)]
pub fn set_steer_angle(&mut self, value: f32) -> Result<(), CanError> {
#[cfg(feature = "range_checked")]
if value < -500_f32 || 500_f32 < value {
return Err(CanError::ParameterOutOfRange { message_id: 37 });
}
let factor = 1.5_f32;
let offset = 0_f32;
let value = ((value - offset) / factor) as i16;
let value = u16::from_ne_bytes(value.to_ne_bytes());
self.raw.view_bits_mut::<Msb0>()[4..16].store_be(value);
Ok(())
}
I think that's a great idea, probably add them as associated constants? Then also use those in the range check code.
pub const STEER_ANGLE_MIN: f32 = -500;
pub const STEER_ANGLE_MAX: f32 = 500;
Yes, that is better than adding separate methods.