pub struct DecodedSignal<'a> {
pub name: &'a str,
pub value: f64,
pub raw_value: i64,
pub min: f64,
pub max: f64,
pub unit: Option<&'a str>,
pub description: Option<&'a str>,
}Expand description
A decoded signal from a CAN message.
Contains the signal name, its decoded physical value, unit, and optional value description.
Fields§
§name: &'a strThe name of the signal as defined in the DBC file.
value: f64The decoded physical value after applying factor and offset.
raw_value: i64The raw integer value before applying factor and offset. Useful for debugging, re-encoding, or storing raw CAN data.
min: f64The minimum valid physical value as defined in the DBC file.
max: f64The maximum valid physical value as defined in the DBC file.
unit: Option<&'a str>The unit of the signal (e.g., “rpm”, “°C”), if defined.
description: Option<&'a str>The value description text if defined in the DBC file (e.g., “Park”, “Drive”). This maps the raw signal value to a human-readable description.
Implementations§
Source§impl<'a> DecodedSignal<'a>
impl<'a> DecodedSignal<'a>
Sourcepub fn new(
name: &'a str,
value: f64,
raw_value: i64,
min: f64,
max: f64,
unit: Option<&'a str>,
description: Option<&'a str>,
) -> Self
pub fn new( name: &'a str, value: f64, raw_value: i64, min: f64, max: f64, unit: Option<&'a str>, description: Option<&'a str>, ) -> Self
Creates a new DecodedSignal with the given parameters.
§Arguments
name- The signal namevalue- The decoded physical value (after applying factor and offset)raw_value- The raw integer value before scalingmin- The minimum valid physical valuemax- The maximum valid physical valueunit- The optional unit of measurement (e.g., “rpm”, “km/h”)description- The optional value description text (e.g., “Park”, “Drive”)
§Examples
use dbc_rs::DecodedSignal;
let signal = DecodedSignal::new("Gear", 3.0, 3, 0.0, 5.0, Some(""), Some("Drive"));
assert_eq!(signal.name, "Gear");
assert_eq!(signal.value, 3.0);
assert_eq!(signal.raw_value, 3);
assert!(signal.is_in_range());
assert_eq!(signal.description, Some("Drive"));Sourcepub fn is_in_range(&self) -> bool
pub fn is_in_range(&self) -> bool
Returns true if the decoded value is within the valid range [min, max].
§Examples
use dbc_rs::DecodedSignal;
let signal = DecodedSignal::new("RPM", 2000.0, 8000, 0.0, 8000.0, Some("rpm"), None);
assert!(signal.is_in_range());
let out_of_range = DecodedSignal::new("RPM", 9000.0, 36000, 0.0, 8000.0, Some("rpm"), None);
assert!(!out_of_range.is_in_range());Trait Implementations§
Source§impl<'a> Clone for DecodedSignal<'a>
impl<'a> Clone for DecodedSignal<'a>
Source§fn clone(&self) -> DecodedSignal<'a>
fn clone(&self) -> DecodedSignal<'a>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for DecodedSignal<'a>
impl<'a> Debug for DecodedSignal<'a>
Source§impl<'a> PartialEq for DecodedSignal<'a>
impl<'a> PartialEq for DecodedSignal<'a>
impl<'a> StructuralPartialEq for DecodedSignal<'a>
Auto Trait Implementations§
impl<'a> Freeze for DecodedSignal<'a>
impl<'a> RefUnwindSafe for DecodedSignal<'a>
impl<'a> Send for DecodedSignal<'a>
impl<'a> Sync for DecodedSignal<'a>
impl<'a> Unpin for DecodedSignal<'a>
impl<'a> UnwindSafe for DecodedSignal<'a>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)