Prod2U 6400 host transport and hardware abstraction platform

root a4c9c0053a fix(host): keep shutdown Safe writable and stop starving GET_TEMPERATURE il y a 3 mois
api 5b0551f90b fix(host): close R5 safe delivery, SDK field parity, and release gates il y a 3 mois
cmd 3b32c98795 fix(host): make R5 gates honest for lease cancel, hthctl --file, capture, and RTL Python ABI il y a 3 mois
contracts 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
deploy 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
docs 5b0551f90b fix(host): close R5 safe delivery, SDK field parity, and release gates il y a 3 mois
internal a4c9c0053a fix(host): keep shutdown Safe writable and stop starving GET_TEMPERATURE il y a 3 mois
profiles 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
reviews 5b0551f90b fix(host): close R5 safe delivery, SDK field parity, and release gates il y a 3 mois
sdk 5b0551f90b fix(host): close R5 safe delivery, SDK field parity, and release gates il y a 3 mois
tests 3b32c98795 fix(host): make R5 gates honest for lease cancel, hthctl --file, capture, and RTL Python ABI il y a 3 mois
tools 3b32c98795 fix(host): make R5 gates honest for lease cancel, hthctl --file, capture, and RTL Python ABI il y a 3 mois
.gitignore 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
ACCEPTANCE_MATRIX.md 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
Makefile 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
README.zh-CN.md 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
buf.yaml 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
go.mod 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois
go.sum 0c53ba1d9f fix(host): close R3 safety lifecycle, serial cancel, and evidence gates il y a 3 mois

README.zh-CN.md

hth Linux 用户空间平台

hth 是高温罩设备在 Linux 宿主机用户空间 的访问与控制平台。它的目标不是训练模型,而是让后续的数据人员、控制算法人员和模型人员 不必理解串口帧、CRC、Command Type、FPGA 球位、PWM 或 STEP/DIR。

当前活动硬件协议来自 Prod2U 门百分比合同(见 docs/protocol-source-audit.zh-CN.md)。本文与所有 host/docs/* 均按该审计撰写。

一句话架构

CPLD/FPGA 控制板  --UART-->  hthd(唯一串口所有者)  --gRPC/UDS-->  observe.sock / control.sock
  • 领域 API:高温罩语义(温度、风扇占空比、PTC 占空比、门闭合百分比、Lease、故障)。
  • gRPC:该 API 的一种本地传输。第一版只走 Unix Domain Socket,不监听 TCP。
  • Python SDK(hth-sdk / import hth_sdk):给数据/模型程序用的客户端。
  • hthctl / hth-capture:运维与短时采集,不打开串口。

协议诚实性(必须先读)

当前真实 UART 合同:

事实 含义
门字节 0..100 闭合百分比。0 = 全开,100 = 全关。0 不是 STOP / HOLD / 心跳空操作
GET_MOTOR_STATUS (0x03) 存在;返回 31 字节 MOTOR_STATUS_DATA
无 ACK 串口 write 成功只表示字节交给了 OS。confirmation 最多是 UNCONFIRMED,永不把 SET_ALL 标成 CONFIRMED
Watchdog 30 s 仅 startup_complete 之后,由合法 SET_ALL commit 喂狗。GET 不喂
启动期 GET_TEMPERATURE 静默丢弃,无响应。Readiness = startup_complete 位
心跳 必须重发真实连续目标(含三个门百分比)。禁止把门改写成 0 当空操作
温度 ID temperature.channel.00 … 26。物理 DIMM/腔体映射 = UNKNOWN
风扇 RPM / 编码器 / 固件版本 NOT_SUPPORTED
硬件验证 NOT RUN。本仓库 不得声称生产可用硬件

旧 jog 合同(00=不启动 jog / 01 开 / 02 关,watchdog 10 s → FAN 20)已破坏性迁移,禁止复活。

为什么 hthd 独占串口

多个进程同时打开同一 UART 会导致:

  • 帧被拆碎、CRC 失败、半帧互相污染;
  • 两个控制者同时写 SET_ALL,latest-wins 在总线上变成竞态;
  • Watchdog 心跳与用户动作互相覆盖;
  • 无 ACK 时无法判断“谁写成功了”。

因此 只有 hthd 允许打开串口。Python 模型、Jupyter、容器、hthctl、采集程序都只连 Unix Socket。

仓库布局

host/
  api/proto/hth/api/v1/hth.proto   # 稳定 API 合同(hth.api.v1)
  cmd/                             # hthd / hthctl / hth-capture(Go 守护进程)
  internal/                        # 协议、后端、Lease、安全、gRPC
  profiles/prod2u-door-temp/       # 由 host-contract + golden 生成的 Profile
  sdk/python/                      # hth-sdk
  deploy/                          # systemd / udev 模板 / tmpfiles / 示例配置
  docs/                            # 中文文档

快速开始(Mock,不碰硬件)

# 守护进程(Go 侧;后端 mock,不打开串口)
hthd --backend=mock --config host/deploy/examples/hthd.mock.yaml

# Python SDK(可在无守护进程时用 in-process MockClient)
cd host/sdk/python
python3 -m pip install -e .
python3 examples/observe.py
python3 examples/snapshot.py
python3 examples/control_mock.py    # 默认 mock;拒绝危险真机动作
python3 examples/capture.py
python3 -m pytest -q tests

生成 Python protobuf stubs(真实 UDS 客户端需要):

python3 host/tools/gen_python_stubs.py

给两类后续人员

  • 数据人员:只加入 hth-observe 组,挂载 observe.sock,调用 GetSnapshot / SubscribeTelemetry。不要申请 Lease。
  • 模型/控制人员:加入 hth-control 组,先 AcquireControlLease,再用 ActionBatch 一次提交风扇+PTC+门百分比。用 ValidateAction 做干跑。

详见 docs/model-data-integration.zh-CN.md 与 docs/python-sdk-guide.zh-CN.md。

文档索引

文档 内容
protocol-source-audit.zh-CN.md 协议证据链(已写,勿覆盖)
architecture.zh-CN.md 运行架构与职责边界
api-contract.zh-CN.md 领域 API 与 gRPC 服务
signal-dictionary.zh-CN.md 稳定 ID、实测/估计/不支持
safety-contract.zh-CN.md Lease、心跳、门 0、无 ACK
failure-semantics.zh-CN.md 故障与确认语义
python-sdk-guide.zh-CN.md SDK 安装与示例
model-data-integration.zh-CN.md 数据订阅 / 模型 Lease
deployment.zh-CN.md systemd、udev 模板、容器挂 socket
operations.zh-CN.md 运维、doctor、日志
compatibility-policy.zh-CN.md hth.api.v1、保留 tag、版本拆分
known-gaps.zh-CN.md 已知缺口
ACCEPTANCE_MATRIX.md 验收矩阵

明确不在本仓库范围

神经网络、RL、MPC、PID、Kafka、数据湖、Kubernetes/Helm、Web 前端、公网 REST、直接操作真机 PTC/风扇/电机(除非未来任务明确授权)。

Hardware validation: NOT RUN