dbc_rs/signal/
mod.rs

1mod decode;
2mod impls;
3mod parse;
4#[cfg(feature = "std")]
5mod std;
6mod validate;
7
8#[cfg(feature = "std")]
9mod builder;
10
11use crate::{ByteOrder, Receivers, compat::Name};
12#[cfg(feature = "std")]
13pub use builder::SignalBuilder;
14
15/// Position info: (start_bit, length, byte_order, unsigned)
16type Position = (u16, u16, ByteOrder, bool);
17/// Scaling: (factor, offset)
18type Scaling = (f64, f64);
19/// Range: (min, max)
20type Range = (f64, f64);
21
22/// Represents a CAN signal within a message.
23///
24/// A `Signal` contains:
25/// - A name
26/// - Start bit position and length
27/// - Byte order (big-endian or little-endian)
28/// - Signed/unsigned flag
29/// - Factor and offset for physical value conversion
30/// - Min/max range
31/// - Optional unit string
32/// - Receivers (nodes that receive this signal)
33///
34/// # Examples
35///
36/// ```rust,no_run
37/// use dbc_rs::Dbc;
38///
39/// let dbc = Dbc::parse(r#"VERSION "1.0"
40///
41/// BU_: ECM
42///
43/// BO_ 256 Engine : 8 ECM
44///  SG_ RPM : 0|16@1+ (0.25,0) [0|8000] "rpm" *
45/// "#)?;
46///
47/// let message = dbc.messages().at(0).unwrap();
48/// let signal = message.signals().at(0).unwrap();
49/// println!("Signal: {} (bits: {}-{})", signal.name(), signal.start_bit(), signal.start_bit() + signal.length() - 1);
50/// # Ok::<(), dbc_rs::Error>(())
51/// ```
52#[derive(Debug, Clone)]
53pub struct Signal {
54    name: Name,
55    start_bit: u16,
56    length: u16,
57    byte_order: ByteOrder,
58    unsigned: bool,
59    factor: f64,
60    offset: f64,
61    min: f64,
62    max: f64,
63    unit: Option<Name>,
64    receivers: Receivers,
65    /// True if this is a multiplexer switch signal (marked with 'M')
66    is_multiplexer_switch: bool,
67    /// If this is a multiplexed signal (marked with 'm0', 'm1', etc.), this contains the switch value
68    /// None means this is a normal signal (not multiplexed)
69    multiplexer_switch_value: Option<u64>,
70}