SignalBuilder

Struct SignalBuilder 

Source
pub struct SignalBuilder { /* private fields */ }

Implementations§

Source§

impl SignalBuilder

Source

pub fn validate(self) -> Result<Self>

Source

pub fn build(self) -> Result<Signal>

Builds and validates the Signal.

Consumes the builder and returns a fully constructed and validated Signal.

§Errors

Returns an error if:

  • Any required field is missing (name, start_bit, length, byte_order, unsigned, factor, offset, min, max)
  • Name exceeds maximum length (32 characters)
  • Signal length is invalid (zero or exceeds 64 bits)
  • Min value exceeds max value
  • Receivers fail to build
§Examples
use dbc_rs::{SignalBuilder, ByteOrder, ReceiversBuilder};

let signal = SignalBuilder::new()
    .name("EngineSpeed")
    .start_bit(0)
    .length(16)
    .byte_order(ByteOrder::LittleEndian)
    .unsigned(true)
    .factor(0.25)
    .offset(0.0)
    .min(0.0)
    .max(8000.0)
    .unit("rpm")
    .receivers(ReceiversBuilder::new().add_node("TCM"))
    .build()?;

assert_eq!(signal.name(), "EngineSpeed");
assert_eq!(signal.factor(), 0.25);
Source§

impl SignalBuilder

Source

pub fn new() -> Self

Creates a new SignalBuilder with no fields set.

§Examples
use dbc_rs::SignalBuilder;

let builder = SignalBuilder::new();
// Must set name, start_bit, length, and byte_order before building
Source

pub fn name(self, name: impl AsRef<str>) -> Self

Sets the signal name.

Source

pub fn unit(self, unit: impl AsRef<str>) -> Self

Sets the unit of measurement for this signal (e.g., “km/h”, “rpm”, “°C”).

Source

pub fn start_bit(self, start_bit: u16) -> Self

Sets the start bit position of the signal in the CAN message payload.

Source

pub fn length(self, length: u16) -> Self

Sets the length of the signal in bits.

Source

pub fn byte_order(self, byte_order: ByteOrder) -> Self

Sets the byte order (endianness) of the signal.

Source

pub fn unsigned(self, unsigned: bool) -> Self

Sets whether the signal is unsigned (true) or signed (false).

Source

pub fn factor(self, factor: f64) -> Self

Sets the scaling factor for converting raw values to physical values (physical = raw * factor + offset).

Source

pub fn offset(self, offset: f64) -> Self

Sets the offset for converting raw values to physical values (physical = raw * factor + offset).

Source

pub fn min(self, min: f64) -> Self

Sets the minimum physical value for this signal.

Source

pub fn max(self, max: f64) -> Self

Sets the maximum physical value for this signal.

Source

pub fn receivers(self, receivers: ReceiversBuilder) -> Self

Sets the receivers (ECU nodes) that subscribe to this signal.

§Arguments
  • receivers - A ReceiversBuilder specifying which nodes receive this signal
§Examples
use dbc_rs::{SignalBuilder, ReceiversBuilder};

let receivers = ReceiversBuilder::new()
    .add_node("ECU1")
    .add_node("ECU2");

let builder = SignalBuilder::new()
    .receivers(receivers);

Trait Implementations§

Source§

impl Clone for SignalBuilder

Source§

fn clone(&self) -> SignalBuilder

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 SignalBuilder

Source§

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

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

impl Default for SignalBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.