libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
server.hpp
1#pragma once
2
3#include "../topic.hpp"
4#include "queue.hpp"
5
6namespace LibXR
7{
28{
29 public:
34 enum class Status : uint8_t
35 {
41 };
42
49 Server(size_t buffer_length);
50
66 void Register(TopicHandle topic);
67
73 size_t ParseData(ConstRawData data);
74
81 size_t ParseDataFromCallback(ConstRawData data, bool in_isr);
82
83 private:
88 enum class ParseResult : uint8_t
89 {
90 NEED_MORE,
91 DROPPED,
92 DELIVERED
93 };
94
103 size_t ParseDataRaw(ConstRawData data, bool from_callback, bool in_isr);
104
111 bool SyncToPacketStart();
112
119 bool ReadHeader();
120
129 ParseResult ReadPayload(bool from_callback, bool in_isr);
130
135 void ResetParser();
136
137 Status status_ = Status::WAIT_START;
138 uint32_t data_len_ = 0;
140 RBTree<uint32_t> topic_map_;
142 QueueBase queue_;
143 RawData parse_buff_;
145 TopicHandle current_topic_ =
146 nullptr;
147 MicrosecondTimestamp current_timestamp_;
149};
150} // namespace LibXR
只读原始数据视图 / Immutable raw data view
微秒时间戳 / Microsecond timestamp
提供固定大小循环缓冲区的字节 FIFO 队列。 Byte FIFO queue providing a fixed-size circular buffer.
红黑树的泛型数据节点,继承自 BaseNode Generic data node for Red-Black Tree, inheriting from BaseNode.
Definition rbt.hpp:63
红黑树实现,支持泛型键和值,并提供线程安全操作 Red-Black Tree implementation supporting generic keys and values with thread-...
Definition rbt.hpp:23
可写原始数据视图 / Mutable raw data view
将字节流解析成 packet 并发布到已注册 topic 的状态机 / State machine that parses byte streams into packets and publishes...
Definition server.hpp:28
void Register(TopicHandle topic)
注册一个可接收 packet 的 topic / Register one topic that may receive parsed packets
Definition server.cpp:22
size_t ParseData(ConstRawData data)
在普通上下文里喂入一批新字节 / Feed one new byte batch in normal context
Definition server.cpp:35
size_t ParseDataFromCallback(ConstRawData data, bool in_isr)
在回调/ISR 路径里喂入一批新字节 / Feed one new byte batch in callback/ISR path
Definition server.cpp:40
Status
parser 当前所在阶段 / Current stage of the parser
Definition server.hpp:35
@ WAIT_START
正在找下一包前缀 / Searching for the next packet prefix.
Server(size_t buffer_length)
构造 parser 并分配内部暂存队列 / Construct the parser and allocate its internal staging queue
Definition server.cpp:12
RBTree< uint32_t >::Node< Block > * TopicHandle
指向一个 topic 运行时状态块的句柄 / Handle pointing to one topic runtime state block
Definition topic.hpp:125
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14