libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
server.hpp
1#pragma once
2
3#include "../topic.hpp"
4#include "queue.hpp"
5
6namespace LibXR
7{
27{
28 public:
33 enum class Status : uint8_t
34 {
40 };
41
48 Server(size_t buffer_length);
49
65 void Register(TopicHandle topic);
66
72 size_t ParseData(ConstRawData data);
73
80 size_t ParseDataFromCallback(ConstRawData data, bool in_isr);
81
82 private:
87 enum class ParseResult : uint8_t
88 {
89 NEED_MORE,
90 DROPPED,
92 };
93
102 size_t ParseDataRaw(ConstRawData data, bool from_callback, bool in_isr);
103
110 bool SyncToPacketStart();
111
118 bool ReadHeader();
119
128 ParseResult ReadPayload(bool from_callback, bool in_isr);
129
134 void ResetParser();
135
137 uint32_t data_len_ =
138 0;
145 nullptr;
148};
149} // namespace LibXR
只读原始数据视图 / Immutable raw data view
微秒时间戳 / Microsecond timestamp
提供固定大小循环缓冲区的字节 FIFO 队列。
红黑树的泛型数据节点,继承自 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:27
size_t ParseDataRaw(ConstRawData data, bool from_callback, bool in_isr)
ParseData*() 的共享实现 / Shared implementation behind ParseData*()
Definition server.cpp:45
RBTree< uint32_t > topic_map_
Definition server.hpp:139
void Register(TopicHandle topic)
注册一个可接收 packet 的 topic / Register one topic that may receive parsed packets
Definition server.cpp:22
void ResetParser()
清空当前包的解析上下文并回到找起点状态 / Clear the current packet parsing context and return to the start-search state
Definition server.cpp:196
size_t ParseData(ConstRawData data)
在普通上下文里喂入一批新字节 / Feed one new byte batch in normal context
Definition server.cpp:35
QueueBase queue_
输入字节 FIFO。Input byte FIFO.
Definition server.hpp:141
ParseResult
一次 payload 阶段处理结果 / Result of one payload-stage handling step
Definition server.hpp:88
@ DROPPED
当前包被丢弃。Current packet is dropped.
@ NEED_MORE
当前包还没收全。Current packet is still incomplete.
@ DELIVERED
当前包已发布。Current packet is delivered.
size_t ParseDataFromCallback(ConstRawData data, bool in_isr)
在回调/ISR 路径里喂入一批新字节 / Feed one new byte batch in callback/ISR path
Definition server.cpp:40
TopicHandle current_topic_
当前包命中的目标 topic。Target topic matched by the current packet.
Definition server.hpp:144
MicrosecondTimestamp current_timestamp_
Definition server.hpp:146
uint32_t data_len_
当前包头声明的 payload 长度。Payload length declared by the current header.
Definition server.hpp:137
bool ReadHeader()
在已对齐前缀后继续读取并校验完整头部 / Read and validate the full header after the prefix is aligned
Definition server.cpp:97
Status
parser 当前所在阶段 / Current stage of the parser
Definition server.hpp:34
@ WAIT_START
正在找下一包前缀。Searching for the next packet prefix.
bool SyncToPacketStart()
把输入流同步到下一条 packet 起点 / Synchronize the input stream to the next packet start
Definition server.cpp:79
Server(size_t buffer_length)
构造 parser 并分配内部暂存队列 / Construct the parser and allocate its internal staging queue
Definition server.cpp:12
Status status_
当前 parser 阶段。Current parser stage.
Definition server.hpp:136
ParseResult ReadPayload(bool from_callback, bool in_isr)
读取当前包的 payload 和尾 CRC,并在成功时发布 / Read the payload and trailing CRC of the current packet and publish i...
Definition server.cpp:146
LibXR 命名空间
Definition ch32_can.hpp:14