|
|
@@ -1,7 +1,156 @@
|
|
|
-# Prod2U 6400 UART 抽象层(远端构建)
|
|
|
+# Prod2U 6400 抽象层使用说明
|
|
|
|
|
|
-该小型工具实现 6400 手动 UART/I2C 的 `SetAll`、`GetSnapshot`、CRC、ACK 解码和寄存器事务编码。
|
|
|
-通道 4 默认向量为:PTC18..23=100,Front3=30,Rear3=10,其余风扇=20。
|
|
|
+本目录是 6400-front-rear 的唯一活动 Host 抽象层,提供 Go、Python、
|
|
|
+Linux Shell 和 POSIX C 的可运行示例。它只生成和解析协议,不自动打开
|
|
|
+串口、不自动访问 I2C、不实现 MCU HAL、自动温控或 PID。
|
|
|
|
|
|
-它不实现 PID、自动温控或 MCU HAL;I2C 仅提供寄存器事务编码,不访问 `/dev/i2c-*`。`--dry-run` 只打印 Golden Frame;指定 `--port`
|
|
|
-时才打开 UART。生产使用前必须确认设备、波特率和串口独占权。
|
|
|
+## 1. 固定合同
|
|
|
+
|
|
|
+| 项目 | 值 |
|
|
|
+| --- | --- |
|
|
|
+| Product | 6400-front-rear |
|
|
|
+| Board | FCB V1.1 |
|
|
|
+| UART | 921600 8N1,A5 5A,CRC-16/CCITT-FALSE |
|
|
|
+| Host-I2C | 7-bit 0x2A,16-bit 寄存器地址,MSB first |
|
|
|
+| I2C 模式 | 100 kHz / 400 kHz,Repeated START,Sequential Read/Write |
|
|
|
+| SET_ALL | 32 bytes:PTC0..23、Front0..3、Rear0..3 |
|
|
|
+| 值域 | 每个 duty 为 0..100 |
|
|
|
+| Watchdog | 只有成功原子 SET_ALL 才加载 30 秒 |
|
|
|
+| SAFE | PTC=0%,Front=20%,Rear=20% |
|
|
|
+| 风扇语义 | 连接器侧高电平请求占空比;Front 反相一次,Rear 直通 |
|
|
|
+
|
|
|
+通道 4 示例:PTC18..23=100、Front3=30、Rear3=10,其余 PTC=0、
|
|
|
+其余风扇=20。
|
|
|
+
|
|
|
+合同文件:
|
|
|
+
|
|
|
+ manual-uart-contract.json
|
|
|
+ host-i2c-register-map.json
|
|
|
+
|
|
|
+Contract SHA-256:
|
|
|
+
|
|
|
+ 3d1db034f6b60bc3d747e882defe60b168d37eb356449d46933da824c1c0214a
|
|
|
+
|
|
|
+## 2. Go API
|
|
|
+
|
|
|
+工具链要求 Go 1.25,先运行:
|
|
|
+
|
|
|
+ go test ./...
|
|
|
+
|
|
|
+公共包导出:
|
|
|
+
|
|
|
+ import "prod2u6400-uartkit/pkg/hth6400"
|
|
|
+ SetAllFrame(SetAll) ([]byte, error)
|
|
|
+ GetSnapshotFrame() []byte
|
|
|
+ DecodeAckNack([]byte) (Ack, error)
|
|
|
+ DecodeSnapshot([]byte) ([]byte, error)
|
|
|
+ SetAllI2C(SetAll) ([]I2CTransaction, error)
|
|
|
+ GetSnapshotI2C() I2CTransaction
|
|
|
+ SnapshotReadI2C(length uint16, chunk int) ([]I2CTransaction, error)
|
|
|
+
|
|
|
+传输抽象名称:
|
|
|
+
|
|
|
+ UARTTransport
|
|
|
+ I2CRegisterTransport
|
|
|
+ MockTransport
|
|
|
+ ReplayTransport
|
|
|
+
|
|
|
+运行 Go Demo:
|
|
|
+
|
|
|
+ go run ./examples/go
|
|
|
+
|
|
|
+Demo 打印 UART HEX、I2C staging/command 字节序列、ACK 解码结果,
|
|
|
+并执行 MockTransport,不接触真实设备。
|
|
|
+
|
|
|
+## 3. Python API
|
|
|
+
|
|
|
+Python 实现只依赖标准库:
|
|
|
+
|
|
|
+ python3 python/test_hth6400.py
|
|
|
+ python3 examples/python/demo.py
|
|
|
+
|
|
|
+核心函数:
|
|
|
+
|
|
|
+ from hth6400 import (
|
|
|
+ SetAll, set_all_uart, set_all_i2c,
|
|
|
+ get_snapshot_i2c, snapshot_reads,
|
|
|
+ decode_frame, decode_ack_nack, decode_snapshot,
|
|
|
+ )
|
|
|
+
|
|
|
+set_all_i2c() 返回两个事务:
|
|
|
+
|
|
|
+1. 0x2A W: 01 00 + 32 bytes,写入 0x0100..0x011F;
|
|
|
+2. 0x2A W: 00 10 01,写入 COMMAND=SET_ALL。
|
|
|
+
|
|
|
+get_snapshot_i2c() 生成 00 10 02。读取 Snapshot 时先读
|
|
|
+0x0007/0x0008 长度,再用 snapshot_reads(length, chunk) 生成
|
|
|
+多个 0x0200 + offset 读取事务。
|
|
|
+
|
|
|
+## 4. Linux Shell / UART
|
|
|
+
|
|
|
+只打印 HEX:
|
|
|
+
|
|
|
+ /home/cxkj/bin/prod2u6400-uart --preset channel4 --dry-run
|
|
|
+ /home/cxkj/bin/prod2u6400-uart --preset safe --dry-run
|
|
|
+
|
|
|
+发送并以 HEX 接收(最多 5 秒):
|
|
|
+
|
|
|
+ DEV=/dev/ttyUSB2
|
|
|
+ HEX='A5 5A 01 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 14 14 14 14 14 14 14 E7 0A'
|
|
|
+ /home/cxkj/prod2u/deployments/hth-platform-6400/current/send_uart_hex_debug.sh "$DEV" "$HEX"
|
|
|
+
|
|
|
+标准脚本路径:
|
|
|
+
|
|
|
+ /home/cxkj/prod2u/deployments/hth-platform-6400/current/send_uart_hex_debug.sh
|
|
|
+
|
|
|
+脚本会设置 921600 8N1、raw、关闭软件流控,发送二进制帧并用
|
|
|
+xxd 输出接收字节。它不会循环重试或启动 daemon。
|
|
|
+
|
|
|
+## 5. POSIX C Demo
|
|
|
+
|
|
|
+examples/c/uart_set_all.c 是无第三方库的 Linux 串口示例:
|
|
|
+
|
|
|
+ cc -std=c11 -Wall -Wextra -O2 examples/c/uart_set_all.c -o /tmp/6400-uart-c
|
|
|
+ /tmp/6400-uart-c
|
|
|
+ /tmp/6400-uart-c /dev/ttyUSB2
|
|
|
+
|
|
|
+不提供设备参数时只打印 channel4 帧;只有显式指定设备时才发送。
|
|
|
+
|
|
|
+## 6. ACK/NACK 和 Snapshot
|
|
|
+
|
|
|
+ACK/NACK payload 顺序:
|
|
|
+
|
|
|
+ ok, request_type, status, detail
|
|
|
+
|
|
|
+状态码:
|
|
|
+
|
|
|
+ 0 OK
|
|
|
+ 1 UNSUPPORTED
|
|
|
+ 2 BAD_LENGTH
|
|
|
+ 3 BAD_VALUE
|
|
|
+ 4 SAFETY_LOCKED
|
|
|
+ 5 BUSY
|
|
|
+
|
|
|
+I2C 总线 ACK 只代表字节被接收,不能代表 SET_ALL 已原子生效。
|
|
|
+应用结果必须读取 RESPONSE_OK/COMMAND/STATUS/DETAIL。
|
|
|
+
|
|
|
+## 7. 设备和发布边界
|
|
|
+
|
|
|
+- 不生成 STM32/GD32 工程或 MCU HAL。
|
|
|
+- 不自动访问 /dev/i2c-*。
|
|
|
+- GUI 是离线 HEX/事务生成器,不自动连接 COM 或 I2C。
|
|
|
+- 真实硬件、JTAG、COM、风扇转速、气流和热性能需单独验证。
|
|
|
+- legacy-hth/ 仅为历史归档,不属于活动 API 或发布包。
|
|
|
+
|
|
|
+## 8. 目录说明
|
|
|
+
|
|
|
+ pkg/hth6400/ Go 公共 API
|
|
|
+ internal/protocol/ UART CRC/Frame codec
|
|
|
+ internal/i2creg/ 16-bit I2C 寄存器 codec
|
|
|
+ internal/transport/ UART/Mock/Replay 抽象
|
|
|
+ python/hth6400.py Python codec
|
|
|
+ examples/go/ Go Demo
|
|
|
+ examples/python/ Python Demo
|
|
|
+ examples/bash/ Shell Demo
|
|
|
+ examples/c/ POSIX C Demo
|
|
|
+ send_uart_hex_debug.sh 有界 UART HEX 收发脚本
|