本目录是 6400-front-rear 的唯一活动 Host 抽象层,提供 Go、Python、 Linux Shell 和 POSIX C 的可运行示例。它只生成和解析协议,不自动打开 串口、不自动访问 I2C、不实现 MCU HAL、自动温控或 PID。
| 项目 | 值 |
|---|---|
| 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
工具链要求 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,不接触真实设备。
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() 返回两个事务:
get_snapshot_i2c() 生成 00 10 02。读取 Snapshot 时先读 0x0007/0x0008 长度,再用 snapshot_reads(length, chunk) 生成 多个 0x0200 + offset 读取事务。
只打印 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。
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 帧;只有显式指定设备时才发送。
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。
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 收发脚本