Skip to main content

Signals

Struct Signals 

Source
pub struct Signals { /* private fields */ }
Expand description

The eight data bytes of a J1939 frame.

§Examples

use pamoja_can::Signals;

// Engine speed sits in bytes 4 and 5 of EEC1, at 0.125 rpm per bit.
let mut payload = Signals::new();
payload.set_u16(3, (1000.0 / 0.125) as u16);

assert_eq!(payload.u16(3), Some(8000));
assert_eq!(payload.u8(0), Some(pamoja_can::NOT_AVAILABLE));

Implementations§

Source§

impl Signals

Source

pub fn new() -> Signals

Builds a payload with every signal marked not available.

§Returns

Eight bytes of NOT_AVAILABLE, ready for a sender to write only what it has.

Source

pub fn from_bytes(bytes: [u8; 8]) -> Signals

Reads a payload received off the bus.

§Arguments
  • bytes - the eight data bytes of a received frame.
§Returns

The payload, ready for its signals to be read out.

Source

pub fn as_bytes(&self) -> &[u8; 8]

Returns the eight data bytes, ready to put in a frame.

§Returns

The payload in wire order.

Source

pub fn set_u8(&mut self, at: usize, value: u8) -> &mut Signals

Writes a one-byte signal.

§Arguments
  • at - the byte offset the parameter group places the signal at, 0..=7.
  • value - the raw value, already scaled as the group defines.
§Returns

The payload, so writes chain.

Source

pub fn set_u16(&mut self, at: usize, value: u16) -> &mut Signals

Writes a two-byte little-endian signal.

§Arguments
  • at - the offset of the signal’s first byte, 0..=6.
  • value - the raw value, already scaled as the group defines.
§Returns

The payload, so writes chain.

Source

pub fn u8(&self, at: usize) -> Option<u8>

Reads a one-byte signal.

§Arguments
  • at - the byte offset the parameter group places the signal at.
§Returns

The raw value, or None if at is past the payload.

Source

pub fn u16(&self, at: usize) -> Option<u16>

Reads a two-byte little-endian signal.

§Arguments
  • at - the offset of the signal’s first byte.
§Returns

The raw value, or None if the signal would run past the payload.

Trait Implementations§

Source§

impl Clone for Signals

Source§

fn clone(&self) -> Signals

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Signals

Source§

impl Debug for Signals

Source§

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

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

impl Default for Signals

Source§

fn default() -> Self

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

impl Eq for Signals

Source§

impl PartialEq for Signals

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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 Signals

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.