pub struct SignalBuilder { /* private fields */ }Expand description
Builder for creating CAN signals programmatically.
Use this builder to construct Signal instances with validated
properties. Required fields (name, start_bit, length) must be set before calling
build().
§Examples
use dbc_rs::{SignalBuilder, ByteOrder};
let signal = SignalBuilder::new()
.name("EngineRPM")
.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")
.build()?;Implementations§
Source§impl SignalBuilder
impl SignalBuilder
pub fn validate(self) -> Result<Self>
Sourcepub fn build(self) -> Result<Signal>
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
impl SignalBuilder
Sourcepub fn new() -> Self
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 buildingSourcepub fn unit(self, unit: impl AsRef<str>) -> Self
pub fn unit(self, unit: impl AsRef<str>) -> Self
Sets the unit of measurement for this signal (e.g., “km/h”, “rpm”, “°C”).
Sourcepub fn comment(self, comment: impl AsRef<str>) -> Self
pub fn comment(self, comment: impl AsRef<str>) -> Self
Sets the comment text for this signal (from CM_ SG_ entry).
Sourcepub fn start_bit(self, start_bit: u16) -> Self
pub fn start_bit(self, start_bit: u16) -> Self
Sets the start bit position of the signal in the CAN message payload.
Sourcepub fn byte_order(self, byte_order: ByteOrder) -> Self
pub fn byte_order(self, byte_order: ByteOrder) -> Self
Sets the byte order (endianness) of the signal.
Sourcepub fn unsigned(self, unsigned: bool) -> Self
pub fn unsigned(self, unsigned: bool) -> Self
Sets whether the signal is unsigned (true) or signed (false).
Sourcepub fn factor(self, factor: f64) -> Self
pub fn factor(self, factor: f64) -> Self
Sets the scaling factor for converting raw values to physical values (physical = raw * factor + offset).
Sourcepub fn offset(self, offset: f64) -> Self
pub fn offset(self, offset: f64) -> Self
Sets the offset for converting raw values to physical values (physical = raw * factor + offset).
Sourcepub fn receivers(self, receivers: ReceiversBuilder) -> Self
pub fn receivers(self, receivers: ReceiversBuilder) -> Self
Sets the receivers (ECU nodes) that subscribe to this signal.
§Arguments
receivers- AReceiversBuilderspecifying 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
impl Clone for SignalBuilder
Source§fn clone(&self) -> SignalBuilder
fn clone(&self) -> SignalBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more