Skip to content

Commit 688bed7

Browse files
committed
fix: preserve topic timestamps when forwarding
1 parent cc1ed9d commit 688bed7

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ SharedTopicClient is a client module for multi-topic data sharing and transparen
1515
- uart_name: 串口设备名 / UART device name (e.g., "uart_cdc")
1616
- task_stack_depth: 任务堆栈大小 / Task stack depth (e.g., 512)
1717
- buffer_size: 发送缓冲区字节数 / TX buffer size (e.g., 256)
18-
- topic_names: 需要订阅并转发的 Topic 名称列表 / List of topic names to subscribe and forward (e.g., ["topic1", "topic2"])
18+
- topic_configs: 需要订阅并转发的 Topic 配置列表。每项可以只写 topic 名,也可以写
19+
`[topic, domain]`。/ Topic configs to subscribe and forward. Each item may be a
20+
topic name or `[topic, domain]`.
21+
22+
## Timestamp
23+
24+
`SharedTopicClient` 转发 Topic 时会保留 libxr message envelope timestamp:
25+
26+
1. 本地 Topic callback 收到 `(timestamp, payload)`
27+
2. `Topic::PackData(topic_crc, buffer, timestamp, payload)` 写入串口包。
28+
3. 对端 `SharedTopic` 解析后用同一个 timestamp 发布到对端 domain。
29+
30+
因此同步类 topic 不需要在 payload 里重复携带时间戳;payload 只保留业务字段即可。
1931

2032
## 依赖 / Depends
2133

SharedTopicClient.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ depends: []
1717
// clang-format on
1818

1919
#include "app_framework.hpp"
20+
#include "message.hpp"
2021
#include "uart.hpp"
2122

2223
class SharedTopicClient : public LibXR::Application {
@@ -47,7 +48,6 @@ class SharedTopicClient : public LibXR::Application {
4748
ASSERT(uart_ != nullptr);
4849

4950
topics_pack_buffer_ = new LibXR::RawData[topic_configs.size()];
50-
5151
uint32_t i = 0;
5252

5353
for (auto config : topic_configs) {
@@ -61,12 +61,13 @@ class SharedTopicClient : public LibXR::Application {
6161
new uint8_t[ans->data_.max_length + LibXR::Topic::PACK_BASE_SIZE],
6262
ans->data_.max_length + LibXR::Topic::PACK_BASE_SIZE);
6363

64-
void (*func)(bool, CallbackInfo, LibXR::RawData&) =
65-
[](bool in_isr, CallbackInfo info, LibXR::RawData& data) {
66-
LibXR::WriteOperation op;
64+
void (*func)(bool, CallbackInfo, LibXR::MicrosecondTimestamp,
65+
LibXR::ConstRawData&) =
66+
[](bool in_isr, CallbackInfo info,
67+
LibXR::MicrosecondTimestamp timestamp, LibXR::ConstRawData& data) {
6768
LibXR::Topic::PackData(info.topic_crc32,
6869
info.client->topics_pack_buffer_[info.index],
69-
data);
70+
timestamp, data);
7071
info.client->tx_queue_.PushBatch(
7172
static_cast<uint8_t*>(
7273
info.client->topics_pack_buffer_[info.index].addr_),
@@ -91,8 +92,6 @@ class SharedTopicClient : public LibXR::Application {
9192
}
9293

9394
static void TxThreadFun(SharedTopicClient* client) {
94-
LibXR::Semaphore write_op_sem;
95-
LibXR::WriteOperation op(write_op_sem);
9695
LibXR::WriteOperation op_none;
9796
while (true) {
9897
client->tx_sem_.Wait();

0 commit comments

Comments
 (0)