Skip to content

fix(ostool-server): support stable multi-port USB serial identities - #215

Merged
ZR233 merged 1 commit into
mainfrom
fix/usb-serial
Nov 4, 2026
Merged

ZR233 merged 1 commit into
mainfrom
fix/usb-serial

Conversation

@YanLien

@YanLien YanLien commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

问题说明

FT4232H 等多接口 USB 串口设备的多个端口共享同一序列号。原有解析逻辑直接选择首个匹配项,无法可靠区分控制台与继电器接口,结果依赖设备枚举顺序。

本 PR 支持通过包含接口信息的 /dev/serial/by-id/ 路径绑定串口,并在匹配存在歧义时明确报错。

修改内容

  • 增加 usb_id 配置和发现字段,默认标识优先级为 usb_id、序列号、usb_path。
  • 按配置指定的标识字段检查全部候选端口,重复匹配时提示使用接口级标识。
  • 保留唯一序列号和既有 usb_path 配置的兼容性,支持有效符号链接直接解析。
  • 将 usb_id 接入端口别名、继电器串口选择、API 和 Web UI,便于识别和保存指定接口。
  • 补充串口解析测试及配置文档;调整部分原子更新写法,保持计数溢出检查和内存序。

旧序列号配置能够唯一定位端口时保持兼容;存在多个匹配时,需要改用 usb_id 或 usb_path。

测试验证

针对提交 65b9f9c 的本地验证记录:

  • cargo fmt --all -- --check:通过。
  • cargo test -p ostool-server --target x86_64-unknown-linux-gnu:173 项单元测试、12 项集成测试通过。
  • cargo clippy -p ostool-server --target x86_64-unknown-linux-gnu --all-features:通过,保留 9 条既有警告。
  • pnpm --dir ostool-server/webui test:30 项测试通过。
  • pnpm --dir ostool-server/webui build:通过。

@ZR233
ZR233 merged commit c8198fd into main Nov 4, 2026
2 checks passed
@ZR233
ZR233 deleted the fix/usb-serial branch November 4, 2026 04:12
@github-actions github-actions Bot mentioned this pull request Nov 4, 2026

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本 PR 为多接口 USB 串口增加 /dev/serial/by-id 身份及重复序列号歧义处理,并将新身份接入继电器串口选择和 API/Web UI。主要影响 board 持久化串口 key、串口会话/继电器定位及管理页面;唯一序列号与既有 usb_path 配置在后端仍可解析,改动总体聚焦于这些串口契约(另有网络测试计数器的原子更新调整)。

验证方面,PR head 的两个 GitHub Actions check 均成功。本地无法复跑:环境缺少 cargo 和 pnpm。未发现此前针对本 PR 的 review 或 issue comments。相近的 PR #206 是另一项已合并的自动串口绑定改动,并非重复提案。

剩余问题仅为下方的 UI 兼容性提示:新 primary USB ID 会让现存序列号配置在 board 编辑页显示成未检测到,虽然后端仍可解析。除该提示外,本次审查未发现其他阻塞问题。

Powered by gpt-6-luna

(None, None)
};
let usb_id = by_id_map.get(port.port_name.as_str()).cloned();
let (primary_key_kind, primary_key_value) = if let Some(usb_id) = usb_id.clone() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个优先级切换会让已有 serial_number:<SN> 配置在 BoardEditor 中变成“当前未检测到”:serialOptions 只生成 primary key 选项,而 SerialDetails 也只用 primary key value 查找。对于现在具有 usb_id 的端口,已保存的 SN 不再匹配 primary 值,尽管后端仍能解析它。请让 UI 按当前保存的 key kind 对应字段查找/保留该端口,或暴露所有稳定身份作为选项,以免现有配置在编辑时呈现为断开的设备。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants