Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
hf_can_message_t Struct Reference

Platform-agnostic CAN / CAN FD message (BaseCan v2). More...

#include <BaseCan.h>

Public Member Functions

 hf_can_message_t () noexcept
 
constexpr hf_u8_t GetMaxDataLength () const noexcept
 Largest payload for the current frame kind (8 classic, 64 FD).
 
constexpr hf_u8_t GetLength () const noexcept
 Payload length in bytes.
 
constexpr bool IsValidLength (hf_u8_t len) const noexcept
 Is len a valid payload length for the current frame kind?
 
bool SetLength (hf_u8_t len) noexcept
 Set the payload length in bytes.
 
constexpr bool IsValidDLC (hf_u8_t len) const noexcept
 Same as IsValidLength(); kept for source compatibility.
 
constexpr hf_u8_t GetEffectiveDLC () const noexcept
 Same as GetLength(); kept for source compatibility.
 
bool SetDLC (hf_u8_t len) noexcept
 Same as SetLength(); kept for source compatibility.
 
constexpr hf_u8_t GetDlcCode () const noexcept
 4-bit DLC code for the current length (HF_CAN_DLC_INVALID if invalid).
 
bool SetDlcCode (hf_u8_t code) noexcept
 Set the length from a 4-bit DLC code (as read from a controller).
 
bool SetData (const hf_u8_t *src, hf_u8_t len) noexcept
 Copy len bytes into the payload and set the length.
 
void SetStandardFrame () noexcept
 Set standard frame format (11-bit ID).
 
void SetExtendedFrame () noexcept
 Set extended frame format (29-bit ID).
 
void SetDataFrame () noexcept
 Set data frame (not remote).
 
void SetRemoteFrame () noexcept
 Set remote frame.
 
void SetSingleShot () noexcept
 Set single shot transmission.
 
void SetSelfReception () noexcept
 Set self reception request.
 
void SetFdFrame (bool brs=false) noexcept
 Make this an FD frame.
 
bool SetClassicFrame () noexcept
 Make this a classic frame (clears BRS / ESI).
 
constexpr hf_u8_t GetFlags () const noexcept
 Flags packed as hf_can_flag bits.
 
bool SetFlags (hf_u8_t flags) noexcept
 Set the flags from hf_can_flag bits.
 
constexpr bool IsValidId () const noexcept
 Validate message ID for current frame format.
 
constexpr hf_can_frame_error_t Validate () const noexcept
 Structural check drivers apply before transmit and after receive.
 
constexpr bool IsValid () const noexcept
 Validate() == NONE.
 
template<typename Frame >
void ToFrame (Frame &out) const noexcept
 Copy into a frame with members id, len, flags, data[64], ts_us.
 

Static Public Member Functions

template<typename Frame >
static hf_can_message_t FromFrame (const Frame &in) noexcept
 Build a message from a frame with members id, len, flags, data[64], ts_us.
 

Public Attributes

hf_u32_t id
 Message ID (11 or 29-bit)
 
hf_u8_t dlc
 Payload length in BYTES (0..8 classic, 0..64 FD)
 
hf_u8_t data [HF_CAN_FD_MAX_LEN]
 Payload (64 bytes, FD-sized)
 
bool is_extended
 Extended ID flag (29-bit vs 11-bit)
 
bool is_rtr
 Remote transmission request flag.
 
bool is_ss
 Single shot flag (no retransmission)
 
bool is_self
 Self reception request flag.
 
bool dlc_non_comp
 Received classic DLC code was 9..15 (length is 8)
 
hf_u64_t timestamp_us
 RX timestamp in microseconds (driver clock)
 
hf_u32_t sequence_number
 Message sequence number.
 
hf_u8_t controller_id
 Originating controller ID.
 
hf_u8_t retry_count
 Number of transmission retries.
 
hf_u8_t error_count
 Associated error count.
 
bool is_canfd
 FD frame format (FDF)
 
bool is_brs
 Bit Rate Switching (FD only)
 
bool is_esi
 Error State Indicator (FD only)
 

Detailed Description

Platform-agnostic CAN / CAN FD message (BaseCan v2).

The payload buffer is FD-sized (64 bytes) and the length is a byte count, never a DLC code:

Code that writes dlc directly must keep it valid for the frame kind; drivers check it with Validate() before touching data.

ToFrame() / FromFrame() convert to and from any frame struct with the members id, len, flags, data[64] and ts_us (the layout of vortex::contracts::CanFrame). A frame round trip (frame -> message -> frame) is lossless.

Constructor & Destructor Documentation

◆ hf_can_message_t()

hf_can_message_t::hf_can_message_t ( )
inlinenoexcept

Member Function Documentation

◆ FromFrame()

template<typename Frame >
static hf_can_message_t hf_can_message_t::FromFrame ( const Frame &  in)
inlinestaticnoexcept

Build a message from a frame with members id, len, flags, data[64], ts_us.

Copies the fields as they are; call Validate() to check the result. Flag bits outside hf_can_flag::ALL are ignored.

◆ GetDlcCode()

constexpr hf_u8_t hf_can_message_t::GetDlcCode ( ) const
inlineconstexprnoexcept

4-bit DLC code for the current length (HF_CAN_DLC_INVALID if invalid).

◆ GetEffectiveDLC()

constexpr hf_u8_t hf_can_message_t::GetEffectiveDLC ( ) const
inlineconstexprnoexcept

Same as GetLength(); kept for source compatibility.

◆ GetFlags()

constexpr hf_u8_t hf_can_message_t::GetFlags ( ) const
inlineconstexprnoexcept

Flags packed as hf_can_flag bits.

◆ GetLength()

constexpr hf_u8_t hf_can_message_t::GetLength ( ) const
inlineconstexprnoexcept

Payload length in bytes.

◆ GetMaxDataLength()

constexpr hf_u8_t hf_can_message_t::GetMaxDataLength ( ) const
inlineconstexprnoexcept

Largest payload for the current frame kind (8 classic, 64 FD).

◆ IsValid()

constexpr bool hf_can_message_t::IsValid ( ) const
inlineconstexprnoexcept

Validate() == NONE.

◆ IsValidDLC()

constexpr bool hf_can_message_t::IsValidDLC ( hf_u8_t  len) const
inlineconstexprnoexcept

Same as IsValidLength(); kept for source compatibility.

◆ IsValidId()

constexpr bool hf_can_message_t::IsValidId ( ) const
inlineconstexprnoexcept

Validate message ID for current frame format.

◆ IsValidLength()

constexpr bool hf_can_message_t::IsValidLength ( hf_u8_t  len) const
inlineconstexprnoexcept

Is len a valid payload length for the current frame kind?

Parameters
lenLength in bytes (not a DLC code)

◆ SetClassicFrame()

bool hf_can_message_t::SetClassicFrame ( )
inlinenoexcept

Make this a classic frame (clears BRS / ESI).

Returns
false (nothing changed) when the current length is above 8.

◆ SetData()

bool hf_can_message_t::SetData ( const hf_u8_t *  src,
hf_u8_t  len 
)
inlinenoexcept

Copy len bytes into the payload and set the length.

Returns
false (nothing changed) when len is invalid for the frame kind, or src is null with a non-zero length.

◆ SetDataFrame()

void hf_can_message_t::SetDataFrame ( )
inlinenoexcept

Set data frame (not remote).

◆ SetDLC()

bool hf_can_message_t::SetDLC ( hf_u8_t  len)
inlinenoexcept

Same as SetLength(); kept for source compatibility.

◆ SetDlcCode()

bool hf_can_message_t::SetDlcCode ( hf_u8_t  code)
inlinenoexcept

Set the length from a 4-bit DLC code (as read from a controller).

Classic codes 9..15 give 8 bytes and set dlc_non_comp.

Returns
false when code is above 15.

◆ SetExtendedFrame()

void hf_can_message_t::SetExtendedFrame ( )
inlinenoexcept

Set extended frame format (29-bit ID).

◆ SetFdFrame()

void hf_can_message_t::SetFdFrame ( bool  brs = false)
inlinenoexcept

Make this an FD frame.

Parameters
brsBit-rate switch for the data phase

◆ SetFlags()

bool hf_can_message_t::SetFlags ( hf_u8_t  flags)
inlinenoexcept

Set the flags from hf_can_flag bits.

Returns
false (nothing changed) when flags has a bit outside hf_can_flag::ALL.

◆ SetLength()

bool hf_can_message_t::SetLength ( hf_u8_t  len)
inlinenoexcept

Set the payload length in bytes.

Returns
false (and nothing changed) when len is above 8 on a classic frame, above 64, or an FD length without a DLC code.

◆ SetRemoteFrame()

void hf_can_message_t::SetRemoteFrame ( )
inlinenoexcept

Set remote frame.

◆ SetSelfReception()

void hf_can_message_t::SetSelfReception ( )
inlinenoexcept

Set self reception request.

◆ SetSingleShot()

void hf_can_message_t::SetSingleShot ( )
inlinenoexcept

Set single shot transmission.

◆ SetStandardFrame()

void hf_can_message_t::SetStandardFrame ( )
inlinenoexcept

Set standard frame format (11-bit ID).

◆ ToFrame()

template<typename Frame >
void hf_can_message_t::ToFrame ( Frame &  out) const
inlinenoexcept

Copy into a frame with members id, len, flags, data[64], ts_us.

ts_us receives the low 32 bits of timestamp_us. The whole 64-byte buffer is copied. is_ss, is_self, sequence_number and the other metadata have no place in the frame and are dropped.

◆ Validate()

constexpr hf_can_frame_error_t hf_can_message_t::Validate ( ) const
inlineconstexprnoexcept

Structural check drivers apply before transmit and after receive.

Same rules, in the same order, as vortex::contracts::CheckFrame.

Member Data Documentation

◆ controller_id

hf_u8_t hf_can_message_t::controller_id

Originating controller ID.

◆ data

hf_u8_t hf_can_message_t::data[HF_CAN_FD_MAX_LEN]

Payload (64 bytes, FD-sized)

◆ dlc

hf_u8_t hf_can_message_t::dlc

Payload length in BYTES (0..8 classic, 0..64 FD)

◆ dlc_non_comp

bool hf_can_message_t::dlc_non_comp

Received classic DLC code was 9..15 (length is 8)

◆ error_count

hf_u8_t hf_can_message_t::error_count

Associated error count.

◆ id

hf_u32_t hf_can_message_t::id

Message ID (11 or 29-bit)

◆ is_brs

bool hf_can_message_t::is_brs

Bit Rate Switching (FD only)

◆ is_canfd

bool hf_can_message_t::is_canfd

FD frame format (FDF)

◆ is_esi

bool hf_can_message_t::is_esi

Error State Indicator (FD only)

◆ is_extended

bool hf_can_message_t::is_extended

Extended ID flag (29-bit vs 11-bit)

◆ is_rtr

bool hf_can_message_t::is_rtr

Remote transmission request flag.

◆ is_self

bool hf_can_message_t::is_self

Self reception request flag.

◆ is_ss

bool hf_can_message_t::is_ss

Single shot flag (no retransmission)

◆ retry_count

hf_u8_t hf_can_message_t::retry_count

Number of transmission retries.

◆ sequence_number

hf_u32_t hf_can_message_t::sequence_number

Message sequence number.

◆ timestamp_us

hf_u64_t hf_can_message_t::timestamp_us

RX timestamp in microseconds (driver clock)


The documentation for this struct was generated from the following file: