ExtendedMultiplexing

Struct ExtendedMultiplexing 

Source
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

Source

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);
Source

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");
Source

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");
Source

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

Source§

fn clone(&self) -> ExtendedMultiplexing

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExtendedMultiplexing

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ExtendedMultiplexing

Source§

fn eq(&self, other: &ExtendedMultiplexing) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ExtendedMultiplexing

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.