ethercat-linux/docs/8b-test-report.md
Tony Cao f0163d8d70 800B PDO variant + long-term stability evidence + analysis docs
- twin_layout_blob_sized generalized: multi-entry TwinCAT line format
  (1 real @240bit + N continuation + remainder entry); 1024B path kept
  byte-identical; 800B = 27 entries verified on hardware
- 800B constants (PAYLOAD/SM 800), deployed as el6695_rt_800b
- 10-min + 5h stability runs: 18M cycles, zero errors, zero mismatches,
  PLC nMismatch frozen over the whole run (monitor_5h.csv evidence)
- docs: 800B plan/design/verification/test-report chapters,
  jitter analysis (NFS rootfs stall primary cause), D2000 dev plan
- scripts: 800B deploy/relink/verify, mismatch-delta, 5h monitor
2026-08-06 01:10:50 +08:00

232 lines
9.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# EL6695 8B 双向通讯 — 测试文档
> **版本**: 1.1(新增 §8 800B 测试)
> **日期**: 2026-07-27
> **结论**: ✅ 全部通过
> **配套文档**: `8b-bridge-design.md`、`8b-verification-methodology.md`
---
## 1. 测试环境
### 1.1 硬件
| 项 | 值 |
|---|---|
| TwinCAT PC | Windows,TwinCAT 3.1.4026.24,网卡 "以太网 2" (TwinCAT-Intel PCI, MAC 00-15-17-8A-B3-DA) |
| 目标 AmsNetId | `169.254.176.217.1.1` |
| E-bus | EK1100 → EL2202 → EL1252 → EL2262 → EL2008 → EL6851-0010 → EL6022 → **EL6695** → EL9011 |
| J1900 | Linux 6.6.135-rt74 (PREEMPT_RT), IP `192.168.68.100`, eth1 直连 EL6695 X1 |
| 跳板机 | `tonycao@192.168.58.8`(SSH 免密) |
### 1.2 软件
| 项 | 位置 |
|---|---|
| TwinCAT 工程 | `C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Primary\TwinCATProject1.sln` |
| J1900 程序源码 | `C:\Users\tonycao\work\ethercat-linux`(Rust, ethercrab 0.7 本地 patch) |
| J1900 程序(8B XOR 版) | `/root/gateway/el6695_rt_8b_xor` |
| 1KB 版备份 | `/root/gateway/el6695_rt_1k.bak`;tsproj 备份 `TwinCATProject1.tsproj.bak-1k` |
### 1.3 工具脚本(`ethercat-linux/scripts/`)
| 脚本 | 用途 |
|---|---|
| `tc-deploy-retry.ps1` | 打开工程 → 构建 → 激活 → 重启运行时(全 COM 调用带 RPC 重试) |
| `tc-relink.ps1` | 用 `LinkVariables` API 重建整数组链接并激活 |
| `tc-ads-watch.ps1` | ADS 循环采样 aOut1/aIn1/bSync/nMatchLag 并做 XOR 还原展示 |
| `tc-diag-online.ps1` | 导出 EtherCAT 主站在线 XML + PLC 变量 |
| `tc-errors.ps1` | 读取 TwinCAT 错误消息与 VS 错误列表 |
| `tc-open-project.ps1` | 在可见 XAE 中打开工程并连接目标(供人工查看 Online 页) |
---
## 2. 测试步骤(复现流程)
### 2.1 部署 TwinCAT 配置
```powershell
# 关闭残留 XAE,然后构建+激活+重启
Get-Process TcXaeShell -ErrorAction SilentlyContinue | Stop-Process -Force
powershell -NoProfile -ExecutionPolicy Bypass `
-File C:\Users\tonycao\work\ethercat-linux\scripts\tc-deploy-retry.ps1
# 期望: build done (LastBuildInfo=0) / activated / restart issued
```
激活后校验 _Boot 中 EL6695 的实际配置(应见 SM2 len=8、SM3 len=8,且事件日志无 `size not allowed`):
```powershell
python C:\Users\tonycao\work\ethercat-linux\tmp_check_boot.py
Get-WinEvent -LogName Application -MaxEvents 1000 |
Where-Object { $_.TimeCreated -gt (Get-Date).AddMinutes(-5) -and $_.Message -match 'EL6695' }
```
### 2.2 启动 J1900 数据环
```bash
ssh -J tonycao@192.168.58.8 root@192.168.68.100 \
"nohup /root/gateway/el6695_rt_8b_xor eth1 --mode ticker --duration 600 > /tmp/ticker_xor.log 2>&1 &"
# 期望日志: SM2/SM3 len=8 → SAFEOP achieved → OP achieved → running: ticker loop
```
注意顺序:**必须先激活 TwinCAT,再启动 ticker**(EL6695 固件在主站切换时擦除用户 OD,配置与数据循环须同一会话)。
### 2.3 采样验证
```powershell
powershell -NoProfile -ExecutionPolicy Bypass `
-File C:\Users\tonycao\work\ethercat-linux\scripts\tc-ads-watch.ps1
```
---
## 3. 测试结果
### 3.1 设备配置确认(激活后 _Boot tszip)
```
SM2: 001c08006400010003000000000000000000001c64010000 (start=0x1C00 len=8 ✓)
SM3: 008e08002000010004000000000000000200008e20010000 (start=0x8E00 len=8 ✓)
PDO 0x1608/0x1A08 条目: ARRAY [0..7] OF BYTE (GUID {FE565D85-927B-2D08-1043-124F5F921E35}) ✓
Windows 事件日志: 无 EL6695 错误 ✓
```
### 3.2 J1900 侧运行日志
```
SM2: start=0x1C00 len=8 ctrl=0x64 enable=0x00
SM3: start=0x8E00 len=8 ctrl=0x20 enable=0x00
>>> OP achieved! <<<
S tms=1000 cyc=1000 raw=62198 proc=435389 txe=0 rxe=0 stale=0% mono=0 cerr=0 mism=0
...
(120s 运行全程 stale=0%, txe=0, rxe=0)
```
### 3.3 TwinCAT 侧连续采样(24 秒,8 次)
| # | nCycles | bSync | lag | aOut1 (发送, 8B) | aIn1 (接收, 8B) | aIn1^5A |
|---|---|---|---|---|---|---|
| 1 | 343616 | True | 4 | `58-78-98-B8-D8-F8-18-38` | `02-22-C2-E2-82-A2-42-62` | `58-78-98-B8-D8-F8-18-38` ✓8/8 |
| 2 | 346668 | True | 4 | `38-58-78-98-B8-D8-F8-18` | `6D-0D-2D-CD-ED-8D-AD-4D` | byte0 时差 ±1 |
| 3 | 349688 | True | 4 | `04-24-44-64-84-A4-C4-E4` | `59-79-19-39-D9-F9-99-B9` | byte0 时差 ±1 |
| 4 | 352710 | True | 4 | `DC-FC-1C-3C-5C-7C-9C-BC` | `84-A4-44-64-04-24-C4-E4` | byte0 时差 ±2 |
| 5 | 355745 | True | 4 | `AD-CD-ED-0D-2D-4D-6D-8D` | `F6-96-B6-56-76-16-36-D6` | `AC-CC-EC-0C-2C-4C-6C-8C` ✓8/8 |
| 6 | 358768 | True | 4 | `7D-9D-BD-DD-FD-1D-3D-5D` | `27-C7-E7-87-A7-47-67-07` | `7D-9D-BD-DD-FD-1D-3D-5D` ✓8/8 |
| 7 | 361792 | True | 4 | `58-78-98-B8-D8-F8-18-38` | `00-20-C0-E0-80-A0-40-60` | byte0 时差 ±2 |
| 8 | 364829 | True | 4 | `2A-4A-6A-8A-AA-CA-EA-0A` | `73-13-33-D3-F3-93-B3-53` | byte0 时差 ±1 |
- `nMismatch` 在 24s 观测窗口内**恒定不变**(零新增失配;窗口前的累计值来自 ticker 未启动期间);
- `lag=4` 全程稳定;
- byte0 的 ±1/±2 差异为 ADS 分次读快照时差,见验证说明文档 §4.1。
### 3.4 XAE 在线人工核对
`tc-open-project.ps1` 打开工程后:
`I/O → 设备 1 (EtherCAT) → 模块 3 (EK1100) → 模块 10 (EL6695) → IO Inputs / IO Outputs → Online 页`,
可见 8 个字节全部持续变化。
---
## 4. 测试项与结论
| # | 测试项 | 方法 | 结果 |
|---|---|---|---|
| T1 | TwinCAT 配置激活 | tc-deploy-retry + tszip 解析 | ✅ SM2/SM3=8B 保留,无事件错误 |
| T2 | J1900 侧到达 OP | ticker 日志 | ✅ SAFEOP/OP achieved |
| T3 | TwinCAT→J1900 数据流 | J1900 rx_buf 非零 + stale=0% | ✅ |
| T4 | J1900→TwinCAT 数据流 | aIn1 整组历史环匹配 | ✅ |
| T5 | 8 字节逐一有效 | 逐字节图案 + XOR 还原比对 | ✅ 8/8 |
| T6 | 软件处理证明 | XOR 0x5A 变换 | ✅ |
| T7 | 桥接延迟测量 | nMatchLag | ✅ 4 周期恒定 |
| T8 | 持续稳定性 | 24s bSync 全真 + nMismatch 零增长 + 120s J1900 零错误 | ✅ |
---
## 5. 故障排查速查(本次实测遇到)
| 现象 | 检查点 | 命令/位置 |
|---|---|---|
| aIn1 全 0 | J1900 ticker 是否在跑(必须先激活 TwinCAT 再启动) | `ssh -J ... "ps aux | grep el6695"` |
| SM3 被清零 / `size not allowed` | 0x1A01 诊断 PDO 是否仍挂在 SM3 | tsproj `Index="#x1a01"` 行不应有 `SyncMan="3"` |
| PDO 条目名被改回 [0..1023] | 是否手写了 `18071995-...` 命名空间 GUID | 改用 PLC 生成的随机 GUID 类型 |
| 只有 1 字节过 bridge | 链接是否指向 `[0]` 元素 | 运行 `tc-relink.ps1` 重建链接 |
| RPC_E_CALL_REJECTED | VS 忙/模态 | 等 30s 重试;`tc-list-vs-windows.ps1` 查对话框 |
| J1900 侧 layout_ok=false | 预期内(8B 单条目映射与 1KB 校验规则不同),不影响数据 | 忽略 |
---
## 6. 回退到 1KB 配置
```powershell
# 1. 恢复 tsproj
Copy-Item "C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Primary\TwinCATProject1.tsproj.bak-1k" `
"C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Primary\TwinCATProject1.tsproj" -Force
# 2. 恢复 PLC 代码(GVL/MAIN 的 1024 数组与 1KB 校验逻辑)——从 git 历史或备份还原
# 3. 重新部署 + 重建链接
# 4. J1900 使用 1KB 二进制: /root/gateway/el6695_rt_1k.bak
# 5. J1900 源码恢复: git checkout src/main.rs src/bridge.rs 后改回 PAYLOAD_LEN=1024 相关常量重新编译
```
## 7. 修订历史
| 日期 | 内容 |
|---|---|
| 2026-07-27 | 初版:8B 双向交换全部测试通过 |
---
## 8. 800B 变体测试(2026-07-28)
### 8.1 环境差异
| 项 | 值 |
|---|---|
| TwinCAT 工程 | `TwinCAT_EL6695_Primary_800B`(1kHz 任务) |
| PDO 尺寸 | 800B(SM2/SM3 = 0x0320) |
| J1900 二进制 | `/root/gateway/el6695_rt_800b` |
| 校验脚本 | `scripts/tc-ads-verify-800b.ps1`、`tc-ads-mismatch-delta.ps1`、`tc-relink-800b.ps1`、`tc-deploy-retry-800b.ps1` |
### 8.2 配置确认(激活后 _Boot tszip)
```
SM2: 001c200364... (start=0x1C00 len=0x0320=800 ✓ 保留)
SM3: 008e200320... (start=0x8E00 len=0x0320=800 ✓ 保留)
PDO 条目: ARRAY [0..799] OF BYTE (GUID {7D10FDFE-13E3-A012-D822-BE30F7D36D23})
事件日志: 无 EL6695 错误
```
### 8.3 功能验证
| 项 | 结果 |
|---|---|
| J1900 映射 blob | 27 条目(26×240+160bit)被固件接受,SAFEOP/OP 通过 |
| 处理证明 | `proc = raw*7+3` 逐样本精确(如 107636 → 753455) |
| PLC 校验 | bSync=True,lag=4 |
| 图案覆盖 | aIn1 非零 775776/800;[16..263]+[280..799] 逐字节 `(seq+i)%256` 抽查全对 |
### 8.4 10 分钟稳定性(600,000 周期)
| 指标 | 结果 |
|---|---|
| 周期完整 | 600000 周期 / 600.0s,零丢失 |
| 传输错误 | tx_err=0, rx_err=0 |
| J1900 图案失配 | mism=0 |
| PLC nMismatch | 295s 运行窗口零增长;90s 确认测试 delta=0 |
| stale | 2999 周期(0.5%) |
| 周期抖动 | 均值 4.89µs / p99 5.4µs(单次 499µs 离群) |
| exec | 均值 384µs / p99 400µs |
| FPRD / FPWR | 139µs / 244µs |
注:起止时刻的 nMismatch 增长均为**对端缺席期**的预期累积(ticker 未启动/已停止),运行窗口内零失配。
### 8.5 800B 特有故障记录
| # | 故障 | 根因 | 处置 |
|---|---|---|---|
| F1 | relink 激活时 EL6695 SAFEOP 失败(AL 0x0003) | 激活与运行中的 ticker 会话并发冲突 | J1900 空闲后重新激活即恢复;流程约定:**先激活 TwinCAT,后启动 ticker,激活期间 J1900 必须空闲** |
| F2 | 数据通但每周期固定 16 字节失配 | 图案区 [16..799] 覆盖 J1900 统计字段 [264..279] | 图案区改为 [16..263]+[280..799](MAIN 与校验循环同步修改) |
### 8.6 回退
800B 工程为独立副本,不影响 8B/1kHz 主工程;切回:重新激活 `TwinCAT_EL6695_Primary`(`tc-deploy-retry.ps1`),J1900 使用 `el6695_rt_8b_xor`