dbc_rs/signal/
mod.rs

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