Skip to main content

CanFrame

Struct CanFrame 

pub struct CanFrame {
    pub id: u32,
    pub flags: FrameFlags,
    pub len: u8,
    /* private fields */
}
Expand description

Unified CAN frame: covers both classical CAN (8-byte payload) and CAN-FD (up to 64-byte payload).

The inline [u8; 64] payload buffer is sized for CAN-FD’s maximum DLC; classical frames use only the first 8 bytes and pay ~56 bytes of latent memory in exchange for full upper-layer agnosticism between classical and FD. See openspec/changes/walking-skeleton-single-arm/design.md Decision 14.

Fields§

§id: u32

CAN identifier (11-bit base or 29-bit extended; see FrameFlags::EXTENDED_ID).

§flags: FrameFlags

Metadata bits (FD/BRS/ESI/EXTENDED/RTR).

§len: u8

Payload length in bytes. len <= 8 for classical, len <= 64 for FD.

Implementations§

§

impl CanFrame

pub fn classical(id: u32, payload: &[u8]) -> Result<CanFrame, FrameError>

Construct a classical CAN frame with an 11-bit base identifier.

pub fn classical_extended( id: u32, payload: &[u8], ) -> Result<CanFrame, FrameError>

Construct a classical CAN frame with a 29-bit extended identifier.

pub fn fd(id: u32, payload: &[u8]) -> Result<CanFrame, FrameError>

Construct a CAN-FD frame. Length must be a valid FD DLC; BRS is set by default.

pub fn fd_extended(id: u32, payload: &[u8]) -> Result<CanFrame, FrameError>

Construct a CAN-FD frame with a 29-bit extended identifier.

pub fn from_parts( id: u32, flags: FrameFlags, payload: &[u8], ) -> Result<CanFrame, FrameError>

Construct a frame from raw fields. Performs the flag-compatibility validation that CanFrame::classical / CanFrame::fd enforce automatically.

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

Return the active payload bytes (&self.data[..self.len]).

pub fn is_fd(&self) -> bool

True iff FrameFlags::FD_FORMAT is set.

pub fn is_extended(&self) -> bool

True iff FrameFlags::EXTENDED_ID is set.

Trait Implementations§

§

impl Clone for CanFrame

§

fn clone(&self) -> CanFrame

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
§

impl Debug for CanFrame

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for CanFrame

§

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

impl Copy for CanFrame

§

impl Eq for CanFrame

§

impl StructuralPartialEq for CanFrame

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
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.