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

CAN通信接口,定义标准CAN通信结构,支持不同类型的消息 (CAN communication interface that defines a standard CAN structure supporting different message types). More...

#include <can.hpp>

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

Data Structures

struct  Filter
 

Public Types

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

 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
 
virtual ErrorCode AddMessage (const ClassicPack &pack)=0
 添加 CAN 消息到系统 (Adds a CAN message to the system).
 

Data Fields

 ClassicPack
 

Protected Member Functions

void OnMessage (const ClassicPack &pack, bool in_isr)
 

Private Attributes

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

Detailed Description

CAN通信接口,定义标准CAN通信结构,支持不同类型的消息 (CAN communication interface that defines a standard CAN structure supporting different message types).

Definition at line 13 of file can.hpp.

Member Typedef Documentation

◆ Callback

using LibXR::CAN::Callback = LibXR::Callback<const ClassicPack &>

Definition at line 46 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 };

◆ Type

enum class LibXR::CAN::Type : uint8_t
strong

CAN 消息类型 (Enumeration of CAN message types).

Enumerator
STANDARD 

标准 CAN 消息 (Standard CAN message).

EXTENDED 

扩展 CAN 消息 (Extended CAN message).

REMOTE_STANDARD 

远程标准 CAN 消息 (Remote standard CAN message).

REMOTE_EXTENDED 

远程扩展 CAN 消息 (Remote extended CAN message).

Definition at line 19 of file can.hpp.

20 {
21 STANDARD = 0,
22 EXTENDED = 1,
23 REMOTE_STANDARD = 2,
24 REMOTE_EXTENDED = 3,
25 TYPE_NUM
26 };
@ EXTENDED
扩展 CAN 消息 (Extended CAN message).
@ REMOTE_EXTENDED
远程扩展 CAN 消息 (Remote extended CAN message).
@ STANDARD
标准 CAN 消息 (Standard CAN message).
@ REMOTE_STANDARD
远程标准 CAN 消息 (Remote standard CAN message).

Constructor & Destructor Documentation

◆ CAN()

LibXR::CAN::CAN ( )
inline

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

Parameters
name_tpCAN 消息的主题名称 (Topic name for CAN messages).
domain可选的通信域 (Optional domain for message communication).

Definition at line 34 of file can.hpp.

34{}

Member Function Documentation

◆ __attribute__()

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

经典 CAN 消息结构 (Structure representing a classic CAN message).

< 消息 ID (Message ID).

< 消息类型 (Message type).

< 数据载荷,最大 8 字节 (Data payload, max 8 bytes).

Definition at line 34 of file can.hpp.

40 {
41 uint32_t id;
42 Type type;
43 uint8_t data[8];
44 } ClassicPack;
Type
CAN 消息类型 (Enumeration of CAN message types).
Definition can.hpp:20

◆ AddMessage()

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

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

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

Implemented in LibXR::FDCAN, LibXR::STM32CAN, and LibXR::STM32CANFD.

◆ OnMessage()

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

Definition at line 90 of file can.hpp.

91 {
92 ASSERT(pack.type < Type::TYPE_NUM);
93 subscriber_list_[static_cast<uint8_t>(pack.type)].Foreach<Filter>(
94 [&](Filter &node)
95 {
96 switch (node.mode)
97 {
98 case FilterMode::ID_MASK:
99 if ((pack.id & node.start_id_mask) == node.end_id_match)
100 {
101 node.cb.Run(in_isr, pack);
102 }
103 break;
104 case FilterMode::ID_RANGE:
105 if (pack.id >= node.start_id_mask && pack.id <= node.end_id_match)
106 {
107 node.cb.Run(in_isr, pack);
108 }
109 break;
110 }
111
112 return ErrorCode::OK;
113 });
114 }

◆ Register()

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

注册回调函数 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.hpp.

74 {
75 ASSERT(type < Type::TYPE_NUM);
76
77 auto node = new (std::align_val_t(LIBXR_CACHE_LINE_SIZE))
78 LockFreeList::Node<Filter>({mode, start_id_mask, end_id_match, type, cb});
79 subscriber_list_[static_cast<uint8_t>(type)].Add(*node);
80 }

Field Documentation

◆ ClassicPack

LibXR::CAN::ClassicPack

Definition at line 44 of file can.hpp.

◆ subscriber_list_

LockFreeList LibXR::CAN::subscriber_list_[static_cast< uint8_t >(Type::TYPE_NUM)]
private

Definition at line 117 of file can.hpp.


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