Frame

Trait Frame 

Source
pub trait Frame: Sized {
    // Required methods
    fn new(id: impl Into<Id>, data: &[u8]) -> Option<Self>;
    fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<Self>;
    fn is_extended(&self) -> bool;
    fn is_remote_frame(&self) -> bool;
    fn id(&self) -> Id;
    fn dlc(&self) -> usize;
    fn data(&self) -> &[u8] ;

    // Provided methods
    fn is_standard(&self) -> bool { ... }
    fn is_data_frame(&self) -> bool { ... }
}
Expand description

A CAN2.0 Frame

Required Methods§

Source

fn new(id: impl Into<Id>, data: &[u8]) -> Option<Self>

Creates a new frame.

This will return None if the data slice is too long.

Source

fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<Self>

Creates a new remote frame (RTR bit set).

This will return None if the data length code (DLC) is not valid.

Source

fn is_extended(&self) -> bool

Returns true if this frame is a extended frame.

Source

fn is_remote_frame(&self) -> bool

Returns true if this frame is a remote frame.

Source

fn id(&self) -> Id

Returns the frame identifier.

Source

fn dlc(&self) -> usize

Returns the data length code (DLC) which is in the range 0..8.

For data frames the DLC value always matches the length of the data. Remote frames do not carry any data, yet the DLC can be greater than 0.

Source

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

Returns the frame data (0..8 bytes in length).

Provided Methods§

Source

fn is_standard(&self) -> bool

Returns true if this frame is a standard frame.

Source

fn is_data_frame(&self) -> bool

Returns true if this frame is a data frame.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Frame for CanAnyFrame

Source§

fn new(id: impl Into<Id>, data: &[u8]) -> Option<CanAnyFrame>

Create a new CAN frame If the data

Source§

fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<CanAnyFrame>

Create a new remote transmission request frame.

Source§

fn is_extended(&self) -> bool

Check if frame uses 29-bit extended ID format.

Source§

fn is_remote_frame(&self) -> bool

Check if frame is a remote transmission request.

Source§

fn id(&self) -> Id

Return the frame identifier.

Source§

fn dlc(&self) -> usize

Data length

Source§

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

A slice into the actual data. Slice will always be <= 8 bytes in length

Source§

impl Frame for CanFrame

Source§

fn new(id: impl Into<Id>, data: &[u8]) -> Option<CanFrame>

Create a new CAN 2.0 data frame

Source§

fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<CanFrame>

Create a new remote transmission request frame.

Source§

fn is_extended(&self) -> bool

Check if frame uses 29-bit extended ID format.

Source§

fn is_remote_frame(&self) -> bool

Check if frame is a remote transmission request.

Source§

fn id(&self) -> Id

Return the frame identifier.

Source§

fn dlc(&self) -> usize

Data length

Source§

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

A slice into the actual data. Slice will always be <= 8 bytes in length

Source§

impl Frame for CanDataFrame

Source§

fn new(id: impl Into<Id>, data: &[u8]) -> Option<CanDataFrame>

Create a new CAN 2.0 data frame

Source§

fn new_remote(_id: impl Into<Id>, _dlc: usize) -> Option<CanDataFrame>

Create a new remote transmission request frame.

Source§

fn is_extended(&self) -> bool

Check if frame uses 29-bit extended ID format.

Source§

fn is_remote_frame(&self) -> bool

Check if frame is a remote transmission request.

Source§

fn id(&self) -> Id

Return the frame identifier.

Source§

fn dlc(&self) -> usize

Data length

Source§

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

A slice into the actual data. Slice will always be <= 8 bytes in length

Source§

impl Frame for CanErrorFrame

Source§

fn new(id: impl Into<Id>, data: &[u8]) -> Option<CanErrorFrame>

Create an error frame.

Note that an application would not normally ever create an error frame. This is included mainly to aid in implementing mocks and other tests for an application.

This will set the error bit in the CAN ID word.

Source§

fn new_remote(_id: impl Into<Id>, _dlc: usize) -> Option<CanErrorFrame>

The application should not create an error frame. This will always return None.

Source§

fn is_extended(&self) -> bool

Check if frame uses 29-bit extended ID format.

Source§

fn is_remote_frame(&self) -> bool

Check if frame is a remote transmission request.

Source§

fn is_data_frame(&self) -> bool

Check if frame is a data frame.

Source§

fn id(&self) -> Id

Return the frame identifier.

Source§

fn dlc(&self) -> usize

Data length code

Source§

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

A slice into the actual data. An error frame can always access the full 8-byte data payload.

Source§

impl Frame for CanFdFrame

Source§

fn new(id: impl Into<Id>, data: &[u8]) -> Option<CanFdFrame>

Create a new FD frame

Source§

fn new_remote(_id: impl Into<Id>, _dlc: usize) -> Option<CanFdFrame>

CAN FD frames don’t support remote

Source§

fn is_extended(&self) -> bool

Check if frame uses 29-bit extended ID format.

Source§

fn is_remote_frame(&self) -> bool

The FD frames don’t support remote request

Source§

fn id(&self) -> Id

Return the frame identifier.

Source§

fn dlc(&self) -> usize

Data length code

Source§

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

A slice into the actual data.

This should only be one of the valid CAN FD data lengths.

Source§

impl Frame for CanRemoteFrame

Source§

fn new(id: impl Into<Id>, data: &[u8]) -> Option<CanRemoteFrame>

Create a new CAN 2.0 remote frame

Source§

fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<CanRemoteFrame>

Create a new remote transmission request frame.

This will set the RTR flag in the CAN ID word.

Source§

fn is_extended(&self) -> bool

Check if frame uses 29-bit extended ID format.

Source§

fn is_remote_frame(&self) -> bool

Check if frame is a remote transmission request.

Source§

fn id(&self) -> Id

Return the frame identifier.

Source§

fn dlc(&self) -> usize

Data length code

Source§

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

A slice into the actual data. Slice will always be <= 8 bytes in length

Implementors§

Source§

impl Frame for host_can::frame::CanFrame