libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
can.hpp
1#pragma once
2
3#include "libxr.hpp"
4#include "message.hpp"
5
6namespace LibXR
7{
8
13class CAN
14{
15 public:
19 enum class Type : uint8_t
20 {
21 STANDARD = 0,
22 EXTENDED = 1,
23 REMOTE_STANDARD = 2,
24 REMOTE_EXTENDED = 3,
25 TYPE_NUM
26 };
27
34 CAN() {}
35
39 typedef struct __attribute__((packed))
40 {
41 uint32_t id;
42 Type type;
43 uint8_t data[8];
44 } ClassicPack;
45
47
48 enum class FilterMode : uint8_t
49 {
50 ID_MASK = 0,
51 ID_RANGE = 1
52 };
53
54 typedef struct
55 {
56 FilterMode mode;
57 uint32_t start_id_mask;
58 uint32_t end_id_match;
59 Type type;
60 Callback cb;
61 } Filter;
62
72 void Register(Callback cb, Type type, FilterMode mode = FilterMode::ID_RANGE,
73 uint32_t start_id_mask = 0, uint32_t end_id_match = UINT32_MAX);
74
80 virtual ErrorCode AddMessage(const ClassicPack &pack) = 0;
81
82 protected:
83 void OnMessage(const ClassicPack &pack, bool in_isr);
84
85 private:
86 LockFreeList subscriber_list_[static_cast<uint8_t>(Type::TYPE_NUM)];
87};
88
94class FDCAN : public CAN
95{
96 public:
104 FDCAN() {}
105
109 typedef struct __attribute__((packed))
110 {
111 uint32_t id;
112 Type type;
113 uint8_t len;
114 uint8_t data[64];
115 } FDPack;
116
117 using CAN::AddMessage;
118 using CAN::FilterMode;
119 using CAN::OnMessage;
120
121 using CallbackFD = LibXR::Callback<const FDPack &>;
122
123 typedef struct
124 {
125 FilterMode mode;
126 uint32_t start_id_mask;
127 uint32_t end_id_mask;
128 Type type;
129 CallbackFD cb;
130 } Filter;
131
141 void Register(CallbackFD cb, Type type, FilterMode mode = FilterMode::ID_RANGE,
142 uint32_t start_id_mask = 0, uint32_t end_id_mask = UINT32_MAX);
143
149 virtual ErrorCode AddMessage(const FDPack &pack) = 0;
150
151 protected:
152 void OnMessage(const FDPack &pack, bool in_isr);
153
154 private:
155 LockFreeList subscriber_list_fd_[static_cast<uint8_t>(Type::TYPE_NUM)];
156};
157
158} // namespace LibXR
CAN通信接口,定义标准CAN通信结构,支持不同类型的消息 (CAN communication interface that defines a standard CAN structure supp...
Definition can.hpp:14
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
Definition can.cpp:8
Type
CAN 消息类型 (Enumeration of CAN message types).
Definition can.hpp:20
@ EXTENDED
扩展 CAN 消息 (Extended CAN message).
@ REMOTE_EXTENDED
远程扩展 CAN 消息 (Remote extended CAN message).
@ STANDARD
标准 CAN 消息 (Standard CAN message).
@ REMOTE_STANDARD
远程标准 CAN 消息 (Remote standard CAN message).
virtual ErrorCode AddMessage(const ClassicPack &pack)=0
添加 CAN 消息到系统 (Adds a CAN message to the system).
struct __attribute__((packed))
经典 CAN 消息结构 (Structure representing a classic CAN message).
Definition can.hpp:39
CAN()
构造 CAN 对象,可指定主题名称和通信域 (Constructs a CAN object with an optional topic name and domain).
Definition can.hpp:34
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
Definition libxr_cb.hpp:124
FDCAN 通信接口,扩展 CAN 功能,支持灵活数据速率(FD)CAN 消息 (FDCAN communication interface that extends CAN functionality...
Definition can.hpp:95
struct __attribute__((packed))
FD CAN 消息结构 (Structure representing an FD CAN message).
Definition can.hpp:109
FDCAN()
构造 FDCAN 对象,可指定主题名称和通信域 (Constructs an FDCAN object with optional topic names and domain).
Definition can.hpp:104
virtual ErrorCode AddMessage(const FDPack &pack)=0
添加 FD CAN 消息到系统 (Adds an FD CAN message to the system).
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
Definition can.cpp:44
链表实现,用于存储和管理数据节点。 A linked list implementation for storing and managing data nodes.
LibXR 命名空间
Definition ch32_gpio.hpp:9