Skip to content

feat(serial): POSIX 写超时加长 + 周期发送速率预警 - #8

Merged
Gyanano merged 1 commit into
developfrom
feature/tx-send-guard
Sep 2, 2026
Merged

feat(serial): POSIX 写超时加长 + 周期发送速率预警#8
Gyanano merged 1 commit into
developfrom
feature/tx-send-guard

Conversation

@Gyanano

@Gyanano Gyanano commented Sep 2, 2026

Copy link
Copy Markdown
Owner

背景

RFC #3 Step 2 人工硬件测试暴露:115200 8N1 下 2560 字节 / 100ms 周期发送(需求 25.6 KB/s)超过线路物理容量(11.52 KB/s),内核 TX 缓冲区写满后 write_all 阻塞超过端口 50ms 超时,弹 Failed to send data: Operation timed out。物理超限无法根治,但可以①消除临界速率的误报②在配置阶段就提示用户。

改动

  • 后端serial_manager.rs):POSIX 下写句柄超时 50ms → 1000ms。serialport 的超时是每次 poll 独立计时且存在每个 handle 结构体上,读循环的 50ms 不受影响。Windows 克隆句柄共享 COMMTIMEOUTS,保持原值(代码内注释说明)。
  • 前端SendPanel):周期发送需求速率 > 线路容量 90% 时显示 amber 预警(容量按 波特率 ÷ 每字节线位数 计算,含数据位/校验位/停止位;负载含 Hex 对数 / UTF-8 字节数 / 校验和长度)。中英 i18n。

验证

  • cargo test 32/32 全绿,零警告;npm run build 通过
  • 有头应用真实启动验证:界面渲染正常,FTDI 设备正确枚举
  • 速率阈值人工核对:115200 + 2560B/100ms(2.2× 超限)→ 预警;115200 + 2560B/250ms(89%)→ 不预警;2M + 同速率 → 不预警
  • 预警 UI 的交互展示与 1s 写超时的实际效果待人工硬件复测确认

范围外

TX write-behind 队列(背压 + 失败上报 + Windows 共享超时约束)→ #7,依赖 RFC #3 Step 4 事件通道。


Note

Medium Risk
Changes serial write timeout behavior on Unix (affects all TX) and adds client-side rate heuristics that may not match backend encoding exactly.

Overview
Addresses spurious send timeouts when bursty or large payloads fill the kernel TX buffer, and adds up-front UI feedback when periodic sending cannot physically keep up with the line.

On POSIX, the write handle’s port timeout is raised from 50 ms to 1000 ms after connect (read clone stays at 50 ms). Windows is unchanged because cloned handles share COMMTIMEOUTS.

SendPanel now receives SerialConfig and, when scheduled sending is enabled, estimates line capacity (baud rate ÷ framing bits) and required send rate (payload bytes per interval, including checksum). If demand exceeds ~90% of capacity, an amber warning shows estimated rate vs capacity (en/zh i18n).

Reviewed by Cursor Bugbot for commit edbdc39. Bugbot is set up for automated code reviews on this repo. Configure here.

Exposed by hardware testing after RFC #3 Step 2: at 115200 8N1 a 2560 B /
100 ms scheduled send (25.6 KB/s) overruns the 11.52 KB/s line capacity and
fails with 'Operation timed out' once the kernel TX buffer fills.

- Backend: give the write handle a 1000 ms timeout on POSIX (timeout lives
  per-handle there, so the 50 ms read loop is unaffected). Windows shares
  COMMTIMEOUTS across cloned handles, so the write side keeps the builder
  value there. Per-poll timeout semantics mean borderline rates with bursts
  now drain instead of failing spuriously.
- Frontend: SendPanel warns when a scheduled send's required rate exceeds
  90% of the line capacity derived from baud/data/parity/stop bits, so
  physically impossible rates are flagged before the user hits timeouts.

Remaining TX-queue work (write-behind thread, backpressure, failure
reporting) tracked in #7 — needs RFC #3 Step 4 events as its channel.
@cursor

cursor Bot commented Sep 2, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_db63cf7c-c83e-4500-a20a-45d2dfd4312d)

@Gyanano
Gyanano merged commit 7ddab38 into develop Sep 2, 2026
3 checks passed
@Gyanano
Gyanano deleted the feature/tx-send-guard branch September 2, 2026 10:31
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.

1 participant