pub struct ExtendedMultiplexing { /* private fields */ }Expand description
Extended Multiplexing definition (SG_MUL_VAL_)
Represents extended multiplexing entries that define which multiplexer switch values
activate specific multiplexed signals. This is an extension to basic multiplexing
(m0, m1, etc.) that allows signals to be active for ranges of switch values.
§When to Use Extended Multiplexing
Extended multiplexing is useful when:
- A signal should be active for multiple switch values (e.g., 0-5 and 10-15)
- Multiple multiplexer switches control a single signal (AND logic)
- The activation pattern is more complex than a single value
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM
BO_ 500 MuxMessage : 8 ECM
SG_ Mux1 M : 0|8@1+ (1,0) [0|255] ""
SG_ Signal_A m0 : 16|16@1+ (0.1,0) [0|100] "unit" *
SG_MUL_VAL_ 500 Signal_A Mux1 5-10 ;
"#)?;
// Get extended multiplexing entries for message 500
let entries: Vec<_> = dbc.extended_multiplexing_for_message(500).collect();
assert_eq!(entries.len(), 1);
let entry = entries[0];
assert_eq!(entry.message_id(), 500);
assert_eq!(entry.signal_name(), "Signal_A");
assert_eq!(entry.multiplexer_switch(), "Mux1");
assert_eq!(entry.value_ranges(), &[(5, 10)]);
// Decode - Signal_A will only be decoded when Mux1 is 5-10
let payload = [0x07, 0x00, 0xE8, 0x03, 0x00, 0x00, 0x00, 0x00]; // Mux1=7
let decoded = dbc.decode(500, &payload, false)?;
assert!(decoded.iter().any(|s| s.name == "Signal_A"));§Multiple Ranges
A signal can be active for multiple non-contiguous ranges:
SG_MUL_VAL_ 500 Signal_A Mux1 0-5,10-15,20-25 ;§Multiple Switches (AND Logic)
When multiple SG_MUL_VAL_ entries exist for the same signal with different
switches, ALL switches must match their respective ranges for the signal to
be decoded (AND logic):
SG_MUL_VAL_ 500 Signal_A Mux1 5-10 ;
SG_MUL_VAL_ 500 Signal_A Mux2 20-25 ;Here, Signal_A is only decoded when Mux1 is 5-10 AND Mux2 is 20-25.
Implementations§
Source§impl ExtendedMultiplexing
impl ExtendedMultiplexing
Sourcepub fn message_id(&self) -> u32
pub fn message_id(&self) -> u32
Returns the CAN message ID this extended multiplexing entry applies to.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM
BO_ 500 MuxMessage : 8 ECM
SG_ Mux1 M : 0|8@1+ (1,0) [0|255] ""
SG_ Signal_A m0 : 16|16@1+ (0.1,0) [0|100] "unit" *
SG_MUL_VAL_ 500 Signal_A Mux1 5-10 ;
"#)?;
let entry = dbc.extended_multiplexing_for_message(500).next().unwrap();
assert_eq!(entry.message_id(), 500);Sourcepub fn signal_name(&self) -> &str
pub fn signal_name(&self) -> &str
Returns the name of the signal this extended multiplexing entry controls.
The signal will only be decoded when the multiplexer switch value falls within one of the defined value ranges.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM
BO_ 500 MuxMessage : 8 ECM
SG_ Mux1 M : 0|8@1+ (1,0) [0|255] ""
SG_ Signal_A m0 : 16|16@1+ (0.1,0) [0|100] "unit" *
SG_MUL_VAL_ 500 Signal_A Mux1 5-10 ;
"#)?;
let entry = dbc.extended_multiplexing_for_message(500).next().unwrap();
assert_eq!(entry.signal_name(), "Signal_A");Sourcepub fn multiplexer_switch(&self) -> &str
pub fn multiplexer_switch(&self) -> &str
Returns the name of the multiplexer switch signal that controls activation.
The multiplexer switch is a signal marked with M in the DBC file. When
decoding, the switch’s current value is compared against the value ranges
to determine if the controlled signal should be decoded.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM
BO_ 500 MuxMessage : 8 ECM
SG_ Mux1 M : 0|8@1+ (1,0) [0|255] ""
SG_ Signal_A m0 : 16|16@1+ (0.1,0) [0|100] "unit" *
SG_MUL_VAL_ 500 Signal_A Mux1 5-10 ;
"#)?;
let entry = dbc.extended_multiplexing_for_message(500).next().unwrap();
assert_eq!(entry.multiplexer_switch(), "Mux1");Sourcepub fn value_ranges(&self) -> &[(u64, u64)]
pub fn value_ranges(&self) -> &[(u64, u64)]
Returns the value ranges that activate the controlled signal.
Each tuple (min, max) defines an inclusive range. The signal is decoded
when the multiplexer switch value falls within any of these ranges.
For example, [(0, 5), (10, 15)] means the signal is active when the
switch value is 0-5 OR 10-15.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM
BO_ 500 MuxMessage : 8 ECM
SG_ Mux1 M : 0|8@1+ (1,0) [0|255] ""
SG_ Signal_A m0 : 16|16@1+ (0.1,0) [0|100] "unit" *
SG_MUL_VAL_ 500 Signal_A Mux1 0-5,10-15 ;
"#)?;
let entry = dbc.extended_multiplexing_for_message(500).next().unwrap();
let ranges = entry.value_ranges();
// Check if switch value 3 activates the signal
let switch_value = 3u64;
let is_active = ranges.iter().any(|(min, max)| switch_value >= *min && switch_value <= *max);
assert!(is_active);Trait Implementations§
Source§impl Clone for ExtendedMultiplexing
impl Clone for ExtendedMultiplexing
Source§fn clone(&self) -> ExtendedMultiplexing
fn clone(&self) -> ExtendedMultiplexing
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExtendedMultiplexing
impl Debug for ExtendedMultiplexing
Source§impl PartialEq for ExtendedMultiplexing
impl PartialEq for ExtendedMultiplexing
impl StructuralPartialEq for ExtendedMultiplexing
Auto Trait Implementations§
impl Freeze for ExtendedMultiplexing
impl RefUnwindSafe for ExtendedMultiplexing
impl Send for ExtendedMultiplexing
impl Sync for ExtendedMultiplexing
impl Unpin for ExtendedMultiplexing
impl UnwindSafe for ExtendedMultiplexing
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)