Files
xserial/README.md
2026-06-10 13:41:56 +08:00

3.8 KiB
Raw Blame History

xserial

xserial 是一个基于 Rust workspace 的串口 / TCP / UDP 数据观测工具,支持可配置分帧、协议解码、会话管理,以及以文本、十六进制和绘图为核心的桌面 GUI。

工作区结构

仓库当前包含 4 个 crate

  • xserial-core 负责传输层、分帧器、协议解码器和 pipeline 基础能力。
  • xserial-client 负责会话生命周期、配置、事件分发、历史缓冲和 Lua 相关接口。
  • xserial-gui 当前主要使用入口,基于 egui / eframe
  • xserial-tui 终端 UI crate目前还只是占位实现。

当前功能

  • 在一个 GUI 中管理多个 session。
  • 支持 SerialTCPUDP 三种传输方式。
  • 支持以下 framer LineFixedLengthCobsMixedTextPlot
  • 支持以下 decoder TextHexPlotMixedTextPlot
  • 每个 session 可在 TextHexPlot 三种视图之间切换。
  • 支持单连接 mixed text + plot 数据流。
  • 支持 InterleavedBlockXY 三种 plot 格式。
  • 可在 sidebar 中直接编辑 session 配置。
  • plot 视图支持嵌入主界面,也支持在 GUI 内部弹出为浮动窗口。

构建

cargo check --workspace

运行

启动 GUI

cargo run -p xserial-gui

当前 xserial-tui 还不是完整实现:

cargo run -p xserial-tui

测试

运行整个 workspace 的测试:

cargo test --workspace

常用本地检查命令:

cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings

GUI 快速开始

  1. 启动 xserial-gui
  2. 在 sidebar 中创建一个 session。
  3. 选择传输方式:SerialTCPUDP
  4. 添加一个或多个 pipeline并选择匹配的 framer / decoder。
  5. 连接 session。
  6. TextHexPlot 视图之间切换。

补充说明:

  • session 配置入口在 sidebar 的齿轮按钮。
  • 连接控制是单个切换按钮,不再区分独立的 Connect / Disconnect
  • plot 视图支持内嵌和浮动窗口两种显示方式。

Plot 测试服务器

仓库自带一个本地波形测试工具:

python tools/test_plot.py --help

示例:通过 TCP 发送 mixed text + plot 数据流:

python tools/test_plot.py --wire-format mixed --host 127.0.0.1 --port 8091

GUI 中对应配置为:

  • TransportTCP 127.0.0.1:8091
  • FramerMixedTextPlot
  • DecoderMixedTextPlot

示例:发送 XY plot 数据:

python tools/test_plot.py --wire-format mixed --format xy --channels 2

示例:发送固定长度 raw plot 帧:

python tools/test_plot.py --wire-format raw --channels 2 --framelen 256

GUI 中对应配置为:

  • FramerFixed
  • DecoderPlot
  • Sample typeF32
  • EndianLittle
  • Channels / Format 与脚本参数保持一致

Profiling

GUI 内置了一套轻量级性能日志,默认关闭。

开启方式:

RUST_LOG=xserial_gui::perf=info XSERIAL_GUI_PROFILE=1 cargo run -p xserial-gui

修改统计输出间隔:

RUST_LOG=xserial_gui::perf=info XSERIAL_GUI_PROFILE=1 XSERIAL_GUI_PROFILE_INTERVAL_MS=500 cargo run -p xserial-gui

日志会输出:

  • frame 耗时
  • 事件 drain 耗时
  • text / hex / plot 渲染耗时
  • plot 点数量统计

仓库目录

crates/
  xserial-core/
  xserial-client/
  xserial-gui/
  xserial-tui/
tools/
  test_plot.py

开发约定

  • 传输层、协议和 pipeline 逻辑优先放在 xserial-core
  • 会话管理和状态编排优先放在 xserial-client
  • UI 相关状态放在 xserial-guixserial-tui
  • 集成测试位于 crates/*/tests

当前状态

目前项目中最完整的是 GUI 路径。xserial-tui 已经在 workspace 中,但还没有达到和 GUI 同等的可用程度。