Skip to main content

Frame

Struct Frame 

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

A CAN frame: an identifier and its data.

Holds a classic CAN 2.0 frame (up to 8 bytes), a CAN-FD frame (up to 64 bytes at the discrete CAN-FD lengths), or a classic remote frame, which requests data and carries none. The data lives in a fixed buffer, so building a frame never allocates.

§Examples

use pamoja_can::{CanId, Frame};

let frame = Frame::new(CanId::standard(0x100), &[0x01, 0x02, 0x03]).unwrap();
assert_eq!(frame.data(), &[0x01, 0x02, 0x03]);
assert_eq!(frame.dlc(), 3);
assert!(!frame.is_fd());

Implementations§

Source§

impl Frame

Source

pub fn new(id: CanId, data: &[u8]) -> Result<Frame, CanError>

Builds a classic CAN 2.0 data frame.

§Arguments
  • id - the arbitration identifier.
  • data - the payload, at most 8 bytes.
§Returns

The frame.

§Errors

Returns CanError::DataTooLong if data is longer than 8 bytes.

Source

pub fn fd(id: CanId, data: &[u8]) -> Result<Frame, CanError>

Builds a CAN-FD data frame.

§Arguments
  • id - the arbitration identifier.
  • data - the payload, at one of the discrete CAN-FD lengths up to 64 bytes.
§Returns

The frame.

§Errors

Returns CanError::DataTooLong if data is longer than 64 bytes, or CanError::InvalidFdLength if its length is not one CAN-FD can carry.

Source

pub fn remote(id: CanId, len: usize) -> Frame

Builds a classic remote frame, which requests data of a given length and carries none.

§Arguments
  • id - the arbitration identifier.
  • len - the data length being requested, clamped to 8 bytes.
§Returns

The remote frame.

Source

pub fn id(&self) -> CanId

Returns the arbitration identifier.

§Returns

The identifier.

Source

pub fn data(&self) -> &[u8]

Returns the frame’s data.

§Returns

The payload bytes, or an empty slice for a remote frame.

Source

pub fn signals(&self) -> Option<Signals>

Reads the frame’s data as J1939 signals.

A J1939 message always carries exactly eight bytes, addressed by the offsets its parameter group publishes, so this hands back a view that reads them by offset rather than a slice a caller has to index.

§Returns

The eight data bytes as Signals, or None if this frame does not carry exactly eight, which a J1939 message always does.

Source

pub fn len(&self) -> usize

Returns the data length: the payload length, or the requested length for a remote frame.

§Returns

The length in bytes.

Source

pub fn is_empty(&self) -> bool

Reports whether the frame carries no data.

§Returns

true if the length is zero.

Source

pub fn dlc(&self) -> u8

Returns the data-length code for this frame’s length.

§Returns

The 4-bit data-length code.

Source

pub fn is_fd(&self) -> bool

Reports whether this is a CAN-FD frame.

§Returns

true for a CAN-FD frame.

Source

pub fn is_remote(&self) -> bool

Reports whether this is a remote frame.

§Returns

true for a remote frame.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Frame

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 Frame

Source§

impl Debug for Frame

Source§

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

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

impl Eq for Frame

Source§

impl PartialEq for Frame

Source§

fn eq(&self, other: &Frame) -> 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 Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

§

impl UnwindSafe for Frame

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.