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
impl Frame
Sourcepub fn new(id: CanId, data: &[u8]) -> Result<Frame, CanError>
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.
Sourcepub fn fd(id: CanId, data: &[u8]) -> Result<Frame, CanError>
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.
Sourcepub fn signals(&self) -> Option<Signals>
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.
Sourcepub fn len(&self) -> usize
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.