Files
MAG160C/csdk/WINDOWS_TESTING.md

122 lines
4.4 KiB
Markdown
Raw Permalink 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.
# Windows 测试与 USB 抓包指南
## 1. 已安装的工具
| 工具 | 位置 | 用途 |
|---|---|---|
| USBPcap 1.5.4 | `C:\Program Files\USBPcap\` | USB 抓包驱动 + USBPcapCMD.exe |
| Wireshark 4.6.7 | `C:\Program Files\Wireshark\` | 查看 .pcap 抓包文件 |
| libusb-1.0 (x64) | `csdk\third_party\libusb\win64\` | 本地构建用(TI CCS 的 64 位 DLL + dlltool 生成的导入库) |
| MinGW gcc 14.2 | `C:\mingw64\bin\gcc.exe` | 编译 |
注意:USBPcap/Wireshark 安装后**需要重启**才能加载驱动。
本机当前没有 VID 0x833C 设备 —— 插入相机后按下面流程测试。
## 2. 构建(Windows 无 CMake 环境时用 MinGW 直接编)
```powershell
$lb = "C:\Project\MAG160C\csdk\third_party\libusb\win64"
$srcs = @(
"csdk\src\mag160c_error.c","csdk\src\mag160c_frame.c",
"csdk\src\mag160c_temp.c","csdk\src\mag160c_tcm.c",
"csdk\src\mag160c_ir.c")
gcc -std=c11 -Icsdk\include -Icsdk\src -I$lb `
-DMAG160C_STATIC -DMAG160C_HAS_LIBUSB=1 -DMAG160C_HAS_THREADS=1 `
$srcs csdk\tools\mag160c_cli.c $lb\libusb-1.0.x64.a `
-o build-artifacts\csdk_cli_libusb.exe -lpthread
Copy-Item $lb\libusb-1.0.dll build-artifacts\
```
或装 CMake 后: `cmake -B build -S csdk && cmake --build build`(会自动用 third_party 里的 libusb)。
## 3. 无硬件验证(纯计算 + 协议构造)
```powershell
.\build-artifacts\csdk_cli_libusb.exe tcm-rotate 5
# 7e 00 07 85 02 77 00 01 00 05 7f
.\build-artifacts\csdk_cli_libusb.exe tcm-light green blink
# 7e 00 09 87 02 32 00 01 01 00 ff 00 35
.\build-artifacts\csdk_cli_libusb.exe frame-test
.\build-artifacts\csdk_cli_libusb.exe temp-test
.\build-artifacts\csdk_cli_libusb.exe ir-info # 应显示 "no device with VID 0x833c"
```
## 4. 有硬件验证
插入相机(VID 0x833C)后:
```powershell
# 确认系统看到设备
Get-PnpDevice -PresentOnly | Where-Object { $_.InstanceId -match "833C" }
# 枚举 + 信息
.\build-artifacts\csdk_cli_libusb.exe ir-info
# 触发 FFC(会真实发包)
.\build-artifacts\csdk_cli_libusb.exe ffc
# 启动流(帧回调打印)+ 停止
.\build-artifacts\csdk_cli_libusb.exe start
.\build-artifacts\csdk_cli_libusb.exe stop
```
预期:ir-info 显示 width=160 height=120;FFC 返回 OK;start 后 USBPcap
抓包应看到 EP 0x03 上 `6b b6 b6 72``6b b6 b6 73` 的 8 字节写、EP 0x82 的响应读、
EP 0x81 上 `1b b1 b1 1b` 开头的帧流。
## 5. USB 抓包(USBPcap + Wireshark
USBPcap 需要管理员权限。列出捕获设备:
```powershell
# 管理员 PowerShell
& "C:\Program Files\USBPcap\USBPcapCMD.exe" -d
```
输出示例:
```
1. \\.\USBPcap1 USB Root Hub (xHCI)
2. \\.\USBPcap2 USB Root Hub (xHCI)
...
```
开始抓包(抓所有 USB 根集线器,输出 pcap 文件):
```powershell
# 管理员 PowerShell,抓 30 秒(-A 30
& "C:\Program Files\USBPcap\USBPcapCMD.exe" -d "\\.\USBPcap1" -o C:\captures\mag1.pcap -A 30
& "C:\Program Files\USBPcap\USBPcapCMD.exe" -d "\\.\USBPcap2" -o C:\captures\mag2.pcap -A 30
```
另开一个窗口跑 `csdk_cli_libusb.exe ffc` / `start`,让包被捕获。
在 Wireshark 中打开 pcap,过滤:
- 找到相机设备(右键设备名查看)
- 过滤 `usb.idVendor == 0x833c`
- 看 bulk OUT 到 0x03 的 8 字节包、bulk IN 0x82 的响应、0x81 的帧流
也可以用 Wireshark 图形界面直接选 USBPcap 接口开始抓(需要重启后驱动生效)。
## 6. 抓包结果对照(逆向验证清单)
| 包 | 期望 |
|---|---|
| 链接后第一个命令 | `6b b6 b6 6f 00 00 00 00` (GET_INFO) |
| FFC | `6b b6 b6 72 <param 4B>` |
| Start | 50ms 后 `6b b6 b6 73 00 00 00 00` |
| Stop | `6b b6 b6 74 00 00 00 00` |
| 响应 | `5b b5 b5 5b` + 0x38 字节(payload +0x10=width, +0x14=height) |
| 帧流 | `1b b1 b1 1b` ... 数据在 +0x1c ... `1c b1 b1 1b` |
如与期望不符,将 pcap 保存到 `analysis/captures/` 并记录差异,用于修正协议。
## 2026-08-10 Post-reboot verification (USBPcap live capture)
- After a system reboot the USBPcap filter driver binds to the root hubs.
On this machine the MAG160C device appears on \\\\.\USBPcap4 (AMD xHCI).
Capture with: USBPcapCMD -d \\.\USBPcap4 -o out.pcap -A -s 65535
- The csdk's own traffic (analysis/captures/csdk_verified.pcap) matches the
official demo byte-for-byte at the sequence level:
66b -> 66c -> 66f -> FFC(0) x2 -> START -> frames (15 fps) -> STOP.
- USBPcap capture replaces the libusb0.dll shim for routine sniffing.