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,
25 };
26
33 CAN(const char *name_tp = "can", Topic::Domain *domain = nullptr)
34 : classic_tp_(name_tp, sizeof(ClassicPack), domain, false, true)
35 {
36 }
37
41 typedef struct __attribute__((packed))
42 {
43 uint32_t id;
44 Type type;
45 uint8_t data[8];
46 } ClassicPack;
47
49
55 virtual ErrorCode AddMessage(const ClassicPack &pack) = 0;
56};
57
63class FDCAN : public CAN
64{
65 public:
73 FDCAN(const char *name_tp = "can", const char *name_fd_tp = "fdcan",
74 Topic::Domain *domain = nullptr)
76 {
77 }
78
82 typedef struct __attribute__((packed))
83 {
84 uint32_t id;
85 Type type;
86 uint8_t len;
87 uint8_t data[64];
88 } FDPack;
89
90 using CAN::AddMessage;
91
97 virtual ErrorCode AddMessage(const FDPack &pack) = 0;
98
100};
101
102} // namespace LibXR
CAN通信接口,定义标准CAN通信结构,支持不同类型的消息 (CAN communication interface that defines a standard CAN structure supp...
Definition can.hpp:14
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:41
Topic classic_tp_
经典 CAN 消息的主题 (Topic for classic CAN messages).
Definition can.hpp:48
FDCAN 通信接口,扩展 CAN 功能,支持灵活数据速率(FD)CAN 消息 (FDCAN communication interface that extends CAN functionality...
Definition can.hpp:64
struct __attribute__((packed))
FD CAN 消息结构 (Structure representing an FD CAN message).
Definition can.hpp:82
Topic fd_tp_
FD CAN 消息的主题 (Topic for FD CAN messages).
Definition can.hpp:99
virtual ErrorCode AddMessage(const FDPack &pack)=0
添加 FD CAN 消息到系统 (Adds an FD CAN message to the system).
主题域(Domain)管理器,用于组织多个主题。Domain manager for organizing multiple topics.
Definition message.hpp:133
主题(Topic)管理类 / Topic management class
Definition message.hpp:29
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值