android: port official MAG-Cx UsbCommunication handshake verbatim (66b/66c/66f 800ms, cali file fetch via 670+EP0x84, BasePara parse)

This commit is contained in:
ZXCLI
2026-09-10 02:28:46 +08:00
parent 8ecd50228a
commit b29d7fd377
5 changed files with 281 additions and 177 deletions
+34
View File
@@ -316,6 +316,40 @@
`first run on this host: fetching cali file...``cali fetched+cached`
`first reads [0] n=...` → frames 递增 → 出图。
## 用户反馈修复 第十六轮(2026-09-10,反编译官方 MAG-Cx Java 源码,按其逐行重写 USB 层)
- [x] **jadx 反编译官方普通版**C:\Tools\jadx-1.5.1,产物 C:\Tools\jadx-out):
`sdk/UsbCommunication.java` 就是能在这台手机上跑通的完整 USB 协议 Java 实现。
- [x] **官方真实协议(P2DCmd/D2PCmd 常量全表)**
- P2D66b=GetParameter1、66c=GetParameter2、66f=GetCaliInfo、670=GetCaliFile、
671=SendCaliFile、672=SetShutterState(FFC)、673=StartTransferImg、
674=StopTransferImg、675=GetLifeTime、676=SetLaserState、677=PowerSave、
679=SetFrameRate;全部 4 字节小端(intToByteArray LE,排除字节序假设)。
- D2P 响应:0x5BB5B55B=BasePara1serial/hw+devType/sw/宽/高/fps/gain/flip/
interFrame/interLine/gfid/gsk14 int=56B+4=60B,与日志完全吻合)、
0x5BB5B55C=BasePara2、0x5BB5B55D=SendCaliFile ack、0x5BB5B55E={i32 size,
i32 reserved, i64 date}、0x5BB5B561=lifetime。
- [x] **官方连接序列(UsbCommunication.connect + startTransfer**
1) 66b**不读 ack**waitAck 对 GetParameter1/2/GetCaliInfo 是 default=true
→ recvCmd 64B/800ms → BasePara1
2) 66c → 64B/800ms → BasePara2
3) 66f → 64B/800ms → CaliInfo{size,reserved,date}
4) 缓存 `{caliDir}/{productType}.{serial}.{date}`devType3=core160)命中→
直接 startTransfer;未命中→启动 ThreadCaliRecv0x84、16KB 块、800ms/读、
无数据 5s 放弃)+ 发 670waitForCmdAck 读 ack)→ 收满后 startTransfer
5) startTransfernative startProcess(…, caliPath)= loadDdt 拉到的文件)
→ setEX/ExtPara/放大倍率(native,非 USB)→ 起线程 → 5ms → 673(读 ack)。
- **TIMEOUT=800ms 全线统一**(我们此前的 400ms 是响应缺失的直接嫌疑);
- 图像帧尾校验 drop=type 0/1FFC 触发=按 GetLifeTime 开机时间表(devType3
走 imageStableCounter 分支)+ 双击/消息触发,均为 672。
- [x] **IrSession 按上述逐行重写**(保留:会话互斥、CLEAR_HALT 恢复、DETACHED、
no_stream_data 提示;去掉:5s re-kick、延迟 66b)。BasePara1 解析出 identity
serial/devType/宽/高/fps+ lastInfo0BasePara2 存 lastInfo1MDT 用)。
no_handshake 状态屏显"相机无应答,请拔插重试"。
- [x] 构建+单测全过;APK 已更新(11.87MB)。
- 预期日志:GetParameter1 resp=0x5BB5B55B len=60 → GetParameter2 → GetCaliInfo
cali size=…date=…)→ 下载(首次)或 cache hit → frames 递增。
## 待办
- 真机USB实测(温度绝对值标定、FFC/录像/MDT保存端到端)——进行中: