libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::FDCAN Class Referenceabstract

FDCAN 通信接口,扩展 CAN 功能,支持灵活数据速率(FD)CAN 消息 (FDCAN communication interface that extends CAN functionality by supporting Flexible Data-Rate (FD) CAN messages). More...

#include <can.hpp>

Inheritance diagram for LibXR::FDCAN:
[legend]
Collaboration diagram for LibXR::FDCAN:
[legend]

Data Structures

struct  Filter
 

Public Types

using CallbackFD = LibXR::Callback<const FDPack &>
 
enum class  FilterMode
 
- Public Types inherited from LibXR::CAN
enum class  Type : uint8_t {
  STANDARD = 0 , EXTENDED = 1 , REMOTE_STANDARD = 2 , REMOTE_EXTENDED = 3 ,
  TYPE_NUM
}
 CAN 消息类型 (Enumeration of CAN message types). More...
 
enum class  FilterMode : uint8_t { ID_MASK = 0 , ID_RANGE = 1 }
 
using Callback = LibXR::Callback<const ClassicPack &>
 

Public Member Functions

 FDCAN ()
 构造 FDCAN 对象,可指定主题名称和通信域 (Constructs an FDCAN object with optional topic names and domain).
 
struct __attribute__ ((packed))
 FD CAN 消息结构 (Structure representing an FD CAN message).
 
void Register (CallbackFD cb, Type type, FilterMode mode=FilterMode::ID_RANGE, uint32_t start_id_mask=0, uint32_t end_id_mask=UINT32_MAX)
 注册回调函数 Registers a callback function
 
virtual ErrorCode AddMessage (const FDPack &pack)=0
 添加 FD CAN 消息到系统 (Adds an FD CAN message to the system).
 
virtual ErrorCode AddMessage (const ClassicPack &pack)=0
 添加 CAN 消息到系统 (Adds a CAN message to the system).
 
void OnMessage (const ClassicPack &pack, bool in_isr)
 
void Register (Callback cb, Type type, FilterMode mode=FilterMode::ID_RANGE, uint32_t start_id_mask=0, uint32_t end_id_match=UINT32_MAX)
 注册回调函数 Registers a callback function
 
- Public Member Functions inherited from LibXR::CAN
 CAN ()
 构造 CAN 对象,可指定主题名称和通信域 (Constructs a CAN object with an optional topic name and domain).
 
struct __attribute__ ((packed))
 经典 CAN 消息结构 (Structure representing a classic CAN message).
 
void Register (Callback cb, Type type, FilterMode mode=FilterMode::ID_RANGE, uint32_t start_id_mask=0, uint32_t end_id_match=UINT32_MAX)
 注册回调函数 Registers a callback function
 

Data Fields

 FDPack
 
- Data Fields inherited from LibXR::CAN
 ClassicPack
 

Protected Member Functions

void OnMessage (const FDPack &pack, bool in_isr)
 
- Protected Member Functions inherited from LibXR::CAN
void OnMessage (const ClassicPack &pack, bool in_isr)
 

Private Attributes

LockFreeList subscriber_list_fd_ [static_cast< uint8_t >(Type::TYPE_NUM)]
 

Detailed Description

FDCAN 通信接口,扩展 CAN 功能,支持灵活数据速率(FD)CAN 消息 (FDCAN communication interface that extends CAN functionality by supporting Flexible Data-Rate (FD) CAN messages).

Definition at line 94 of file can.hpp.

Member Typedef Documentation

◆ CallbackFD

using LibXR::FDCAN::CallbackFD = LibXR::Callback<const FDPack &>

Definition at line 122 of file can.hpp.

Member Enumeration Documentation

◆ FilterMode

enum class LibXR::CAN::FilterMode : uint8_t
strong

Definition at line 48 of file can.hpp.

49 {
50 ID_MASK = 0,
51 ID_RANGE = 1
52 };

Constructor & Destructor Documentation

◆ FDCAN()

LibXR::FDCAN::FDCAN ( )
inline

构造 FDCAN 对象,可指定主题名称和通信域 (Constructs an FDCAN object with optional topic names and domain).

Parameters
name_tp经典 CAN 消息的主题名称 (Topic name for classic CAN messages).
name_fd_tpFD CAN 消息的主题名称 (Topic name for FD CAN messages).
domain可选的通信域 (Optional domain for message communication).

Definition at line 104 of file can.hpp.

104{}

Member Function Documentation

◆ __attribute__()

struct LibXR::FDCAN::__attribute__ ( (packed) )
inline

FD CAN 消息结构 (Structure representing an FD CAN message).

< 消息 ID (Message ID).

< 消息类型 (Message type).

< 数据长度,最大 64 字节 (Data length, up to 64 bytes).

< 数据载荷 (Data payload).

Definition at line 104 of file can.hpp.

110 {
111 uint32_t id;
112 Type type;
113 uint8_t len;
114 uint8_t data[64];
115 } FDPack;
Type
CAN 消息类型 (Enumeration of CAN message types).
Definition can.hpp:20

◆ AddMessage() [1/2]

virtual ErrorCode LibXR::CAN::AddMessage ( const ClassicPack & pack)
virtual

添加 CAN 消息到系统 (Adds a CAN message to the system).

Parameters
pack经典 CAN 消息包 (The classic CAN message packet).
Returns
操作结果 (ErrorCode indicating success or failure).

Implements LibXR::CAN.

Reimplemented in LibXR::STM32CANFD.

◆ AddMessage() [2/2]

virtual ErrorCode LibXR::FDCAN::AddMessage ( const FDPack & pack)
pure virtual

添加 FD CAN 消息到系统 (Adds an FD CAN message to the system).

Parameters
packFD CAN 消息包 (The FD CAN message packet).
Returns
操作结果 (ErrorCode indicating success or failure).

Implemented in LibXR::STM32CANFD.

◆ OnMessage() [1/2]

void CAN::OnMessage ( const ClassicPack & pack,
bool in_isr )

Definition at line 83 of file can.cpp.

19{
20 ASSERT(pack.type < Type::TYPE_NUM);
21 subscriber_list_[static_cast<uint8_t>(pack.type)].Foreach<Filter>(
22 [&](Filter &node)
23 {
24 switch (node.mode)
25 {
26 case FilterMode::ID_MASK:
27 if ((pack.id & node.start_id_mask) == node.end_id_match)
28 {
29 node.cb.Run(in_isr, pack);
30 }
31 break;
32 case FilterMode::ID_RANGE:
33 if (pack.id >= node.start_id_mask && pack.id <= node.end_id_match)
34 {
35 node.cb.Run(in_isr, pack);
36 }
37 break;
38 }
39
40 return ErrorCode::OK;
41 });
42}

◆ OnMessage() [2/2]

void FDCAN::OnMessage ( const FDPack & pack,
bool in_isr )
protected

Definition at line 54 of file can.cpp.

55{
56 ASSERT(pack.type < Type::TYPE_NUM);
57 subscriber_list_fd_[static_cast<uint8_t>(pack.type)].Foreach<Filter>(
58 [&](Filter &node)
59 {
60 switch (node.mode)
61 {
62 case FilterMode::ID_MASK:
63 if ((pack.id & node.start_id_mask) == node.end_id_mask)
64 {
65 node.cb.Run(in_isr, pack);
66 }
67 break;
68 case FilterMode::ID_RANGE:
69 if (pack.id >= node.start_id_mask && pack.id <= node.end_id_mask)
70 {
71 node.cb.Run(in_isr, pack);
72 }
73 break;
74 }
75
76 return ErrorCode::OK;
77 });
78}

◆ Register() [1/2]

void CAN::Register ( Callback cb,
Type type,
FilterMode mode = FilterMode::ID_RANGE,
uint32_t start_id_mask = 0,
uint32_t end_id_match = UINT32_MAX )

注册回调函数 Registers a callback function

Parameters
cb回调函数 Callback function
type帧类型 Frame type
mode过滤器模式 Filter mode
start_id_mask起始ID/掩码 Starting ID/mask
end_id_match结束ID/匹配 Ending ID/match

Definition at line 72 of file can.cpp.

10{
11 ASSERT(type < Type::TYPE_NUM);
12
13 auto node = new (std::align_val_t(LIBXR_CACHE_LINE_SIZE))
14 LockFreeList::Node<Filter>(Filter{mode, start_id_mask, end_id_match, type, cb});
15 subscriber_list_[static_cast<uint8_t>(type)].Add(*node);
16}
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...

◆ Register() [2/2]

void FDCAN::Register ( CallbackFD cb,
Type type,
FilterMode mode = FilterMode::ID_RANGE,
uint32_t start_id_mask = 0,
uint32_t end_id_mask = UINT32_MAX )

注册回调函数 Registers a callback function

Parameters
cb回调函数 Callback function
type帧类型 Frame type
mode过滤器模式 Filter mode
start_id_mask起始ID/掩码 Starting ID/mask
end_id_match结束ID/匹配 Ending ID/match

Definition at line 44 of file can.cpp.

46{
47 ASSERT(type < Type::REMOTE_STANDARD);
48
49 auto node = new (std::align_val_t(LIBXR_CACHE_LINE_SIZE))
50 LockFreeList::Node<Filter>(Filter{mode, start_id_mask, end_id_mask, type, cb});
51 subscriber_list_fd_[static_cast<uint8_t>(type)].Add(*node);
52}
@ REMOTE_STANDARD
远程标准 CAN 消息 (Remote standard CAN message).

Field Documentation

◆ FDPack

LibXR::FDCAN::FDPack

Definition at line 115 of file can.hpp.

◆ subscriber_list_fd_

LockFreeList LibXR::FDCAN::subscriber_list_fd_[static_cast< uint8_t >(Type::TYPE_NUM)]
private

Definition at line 156 of file can.hpp.


The documentation for this class was generated from the following files: