Struct CanFrame

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

A CAN frame as transmitted over a CAN socket.

Implementations§

Source§

impl CanFrame

Source

pub fn new(id: impl Into<CanId>, data: impl Into<CanData>) -> Self

Create a new data from with the given CAN ID and data payload.

To create a new data frame with a potentially invalid ID or data payload, use Self::try_new().

Source

pub fn try_new<Id, Data>( id: Id, data: Data, ) -> Result<Self, TryNewCanFrameError>
where Id: TryInto<CanId>, TryNewCanFrameError: From<Id::Error> + From<Data::Error>, Data: TryInto<CanData>,

Create a new data from with the given CAN ID and data payload.

Will report an error if the ID or data is invalid.

You should normally prefer Self::new() if you can guarantee that the ID and data are valid.

Source

pub fn new_rtr(id: impl Into<CanId>) -> Self

Create a new remote transmission request (RTR) frame with a data length code of 0.

To set a different data length code, you can call Self::set_data_length_code() or Self::with_data_length_code() after constructing the RTR frame.

Source

pub fn id(&self) -> CanId

Get the CAN ID of the frame.

Source

pub fn is_rtr(&self) -> bool

Check if this frame is a remote transmission request (an RTR frame).

RTR frames represent a request to transmit a value over the CAN bus. However, an application could decide to use RTR frames differently.

RTR frames have no associated data.

Source

pub fn data(&self) -> Option<CanData>

Get the data of the frame.

Returns None for RTR frames and Some(data) for data frames.

Source

pub fn set_data_length_code( &mut self, dlc: u8, ) -> Result<(), InvalidDataLengthCode>

Set the data length code of the frame.

If the data length code is higher than the current data length, the extra data bytes that become available will have a value of 0.

If the data length code is in the range 9 to 15 (inclusive), the actual data length of the frame will be set to 8. However, if the CAN controller supports it, it may preserve the given data length code in the frame header.

Source

pub fn with_data_length_code( self, dlc: u8, ) -> Result<Self, InvalidDataLengthCode>

Create a copy the frame with a modified data length code.

If the data length code is higher than the current data length, the extra data bytes that become available will have a value of 0.

If the data length code is in the range 9 to 15 (inclusive), the actual data length of the frame will be set to 8. However, if the CAN controller supports it, it may preserve the given data length code in the frame header.

Source

pub fn data_length_code(&self) -> u8

Get the data length code of the frame (it may be higher than the number of data bytes in the frame).

If this is an RTR frame, it is often used to indicate how much bytes are expected in the response data frame. However, the application is free to use the data length code for a different purpose.

The CAN controller may preserve data length codes with a value above 8 (but at most 15). The data length should normally be assumed to be 8 bytes, and application is free to interpret the additional values according to it’s own logic. Note that your CAN controller or driver may not preserve data length codes above 8.

Trait Implementations§

Source§

impl Clone for CanFrame

Source§

fn clone(&self) -> CanFrame

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CanFrame

Source§

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

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

impl Copy 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
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.