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