Skip to main content

CanFdFrame

Struct CanFdFrame 

Source
#[non_exhaustive]
pub struct CanFdFrame { pub channel: Option<usize>, pub arbitration_id: u32, pub data: [u8; 64], pub size: u8, pub brs: Toggle, pub fdcan_frame: Toggle, }
Expand description

A CAN-FD frame.

This structure represents a CAN-FD frame with only standard CAN fields: arbitration ID, payload data, and CAN-FD options. Moteus-specific routing (destination, source, can_prefix) is handled by the higher-level Command type in the moteus crate.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§channel: Option<usize>

Channel index identifying which transport device this frame was received from or should be sent to.

§arbitration_id: u32

CAN arbitration ID

§data: [u8; 64]

Frame payload data (up to 64 bytes for CAN-FD)

§size: u8

Actual size of data in the frame

§brs: Toggle

Bit rate switch (BRS) toggle

§fdcan_frame: Toggle

FD frame format toggle

Implementations§

Source§

impl CanFdFrame

Source

pub const fn new() -> Self

Creates a new empty CAN-FD frame.

Source

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

Returns the payload data as a slice.

Source

pub fn payload_mut(&mut self) -> &mut [u8]

Returns the payload data as a mutable slice.

Source

pub fn clear_data(&mut self)

Clears the frame data, keeping metadata.

Source

pub fn remaining_capacity(&self) -> usize

Returns the remaining capacity in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the frame is empty (no data).

Source

pub fn brs_enabled(&self) -> bool

Returns true if BRS (bit rate switching) should be enabled.

Source

pub fn fdcan_enabled(&self) -> bool

Returns true if FD CAN frame format should be used.

Source

pub fn set_brs(&mut self, enabled: bool)

Sets BRS toggle.

Source

pub fn set_fdcan(&mut self, enabled: bool)

Sets FD CAN frame format toggle.

Source

pub fn round_up_dlc(size: usize) -> usize

Rounds up a data length to the next valid CAN-FD DLC size.

Source

pub fn pad_to_dlc(&mut self)

Pads the frame data with 0x50 to the next valid CAN-FD DLC size.

Trait Implementations§

Source§

impl Clone for CanFdFrame

Source§

fn clone(&self) -> CanFdFrame

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 Debug for CanFdFrame

Source§

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

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

impl Default for CanFdFrame

Source§

fn default() -> Self

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

impl PartialEq for CanFdFrame

Source§

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

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.