Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
9a55c53
chore: add gstack skill routing rules to CLAUDE.md
wabicai Apr 24, 2026
b4148f6
feat(protobuf-build): generate messages-pro2.json from firmware-pro2 …
wabicai Apr 27, 2026
1cce5ca
feat(transport): Protocol V2 wire format + WebUSB/BLE transports for …
wabicai Apr 27, 2026
57a464a
feat(core): Pro2 device type + Protocol V2 firmware update + filesyst…
wabicai Apr 27, 2026
245c54a
feat(playground): Pro2 debug page + Vercel deployment
wabicai Apr 27, 2026
f9ea495
feat(expo-example): connection-type picker + Pro2 firmware update UI
wabicai Apr 27, 2026
735d4a7
docs(transport): Protocol V1/V2 architecture + Pro2 message catalog
wabicai Apr 27, 2026
90bd1bd
fix(hd-cli): jest config + minor pinentry/sdk cleanups
wabicai Apr 27, 2026
b75d336
feat: add protocol v2 transport layer
wabicai Apr 28, 2026
799c747
fix: handle protocol v2 firmware update flow
wabicai Apr 29, 2026
acd955f
chore: add pro2 demo references
wabicai Apr 29, 2026
7eded0e
fix: stabilize protocol v2 firmware update flow
wabicai May 6, 2026
db45934
feat: add pro2 firmware playground deployment
wabicai May 6, 2026
02a676c
feat: align pro2 protocol v2 playground
wabicai May 7, 2026
ab094c5
fix: speed up pro2 debug device connect
wabicai May 7, 2026
2efdb54
fix: filewrite log
wabicai May 7, 2026
6ddf13b
fix: decode protocol v2 file read bytes
wabicai May 7, 2026
77f5cf5
refactor: organize protocol transport layers
wabicai May 8, 2026
6ba7425
fix: separate protocol v2 firmware update flow
wabicai May 8, 2026
0428690
fix: support protocol v2 lowlevel ble framing
wabicai May 8, 2026
dbfb882
fix: align native lowlevel examples with protocol v2 sdk
wabicai May 8, 2026
afb0793
docs: clarify protocol v2 crc8 framing
wabicai May 8, 2026
c8fb299
fix: fireware update
wabicai May 9, 2026
4e132a6
fix: optimize pro2 file progress logging
wabicai May 9, 2026
585f71b
feat: update pro2 firmware demos
wabicai May 11, 2026
454bb8f
fix: speed up rn protocol v2 ble writes
wabicai May 11, 2026
661a465
fix: relax pro2 debug firmware completion
wabicai May 11, 2026
c88f3e5
chore: merge onekey and bump prerelease
wabicai May 11, 2026
f70c62b
fix: handle pro2 firmware reboot disconnect
wabicai May 11, 2026
8c5d009
feat: support ble demo for speed test
wabicai May 11, 2026
88ec305
chore: bump hardware packages to 1.1.26-alpha.30
wabicai May 11, 2026
0ce19a6
feat: include legacy messages in pro2 schema
wabicai May 15, 2026
7af5644
fix: reuse protocol v2 initialization
wabicai May 15, 2026
23083f6
fix: skip webusb v2 probe for pro2 descriptor
wabicai May 15, 2026
1d0dda8
feat: redesign chain methods workspace
wabicai May 15, 2026
cf1f498
fix: improve protocol v2 logging and chains layout
wabicai May 15, 2026
1f24fd9
fix: skip protocol v2 device info during init
wabicai May 15, 2026
79e238d
feat: improve pro2 signer debug flow
wabicai May 15, 2026
c209505
feat: refine pro2 chain debug logs
wabicai May 15, 2026
1d721df
feat: add expo example to vercel preview
wabicai May 15, 2026
a8f5111
fix: prepare expo example during vercel build
wabicai May 15, 2026
f1e3a93
fix: resolve pro2 preview lint errors
wabicai May 15, 2026
6dcd839
feat: add chain method batch test
wabicai May 16, 2026
4b7dcc0
chore: commit playground debug updates
wabicai May 16, 2026
b55d026
fix: support pro2 passphrase session state
wabicai May 18, 2026
db2a9d3
fix: show full request json previews
wabicai May 19, 2026
9fbad95
feat: support pro2 protocol v2 usb flows
wabicai May 20, 2026
88315ad
fix: guard optional usb interfaces
wabicai May 20, 2026
66abb5a
fix: skip protocol v2 device info during init
wabicai May 20, 2026
d26dc48
feat: expose pro2 onboarding payload
wabicai May 20, 2026
6f4963a
fix: prevent expo payload controls overlap
wabicai May 20, 2026
73a8ecb
chore: watch package changes in monitor
wabicai May 20, 2026
b6e9bc8
fix: expose chain method parameters
wabicai May 21, 2026
a65c3d2
fix: harden protocol v2 transport handling
wabicai May 21, 2026
43d912e
fix: harden lowlevel protocol v2 detection
wabicai May 21, 2026
648fa99
fix: harden pro2 ble detection and v2 api validation
wabicai May 21, 2026
04f9205
chore: bump packages to alpha.32
wabicai May 21, 2026
c589e49
fix: reset usb transport cancel state
wabicai May 21, 2026
0670dc5
Align expo playground chain test cases
wabicai May 22, 2026
1733a2f
feat: add pro2 update workflow playground
wabicai May 22, 2026
00a3931
fix: configure playground social metadata
wabicai May 22, 2026
efff44f
fix: handle protocol v2 signing compatibility
wabicai May 22, 2026
1ca666c
chore: update pro2 device update binaries
wabicai May 22, 2026
34f0f67
chore: update pro2 update page copy
wabicai May 22, 2026
e4e6f60
fix: default pro2 playground connection path
wabicai May 22, 2026
ff1863a
feat(core): unify device info api
wabicai May 26, 2026
f66354a
fix(expo-playground): update conflux transaction sample
wabicai May 26, 2026
3a5eb26
fix(core): unify passphrase state payload
wabicai May 26, 2026
fea79f7
fix: handle Pro2 BLE protocol detection
wabicai May 27, 2026
d4c9de8
feat: redesign onboarding status protocol with OnboardingStep enum
wabicai May 28, 2026
8835fd0
chore(release): bump version to 1.1.27-alpha.36
wabicai May 29, 2026
3bcdacb
fix(ci): commit yarn.lock changes before lerna publish
wabicai May 29, 2026
854fc3d
fix(ble): preserve protocol hints on release and increase connection …
wabicai May 29, 2026
ff58ceb
chore(release): bump version to 1.1.27-alpha.37
wabicai May 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .codegraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# CodeGraph data files
# These are local to each machine and should not be committed

# Database
*.db
*.db-wal
*.db-shm

# Cache
cache/

# Logs
*.log

# Hook markers
.dirty
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ packages/connect-examples/react-native-demo/
packages/connect-examples/native-android-example/
packages/connect-examples/native-ios-example/
packages/connect-examples/developer-portal/
.claude/
24 changes: 23 additions & 1 deletion .github/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,29 @@

<head>
<meta charset="UTF-8">
<title>Hardware SDK Examples</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OneKey Developer Playground</title>
<meta name="description"
content="Interactive playground for OneKey Hardware SDK. Test hardware wallet APIs, manage devices, and explore blockchain integrations.">
<meta name="theme-color" content="#000000">
<meta property="og:title" content="OneKey Developer Playground">
<meta property="og:description"
content="Interactive playground for OneKey Hardware SDK. Test hardware wallet APIs and blockchain integrations.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://hardware-example.onekeytest.com/expo-playground/">
<meta property="og:image" content="https://hardware-example.onekeytest.com/expo-playground/og.jpg">
<meta property="og:image:secure_url" content="https://hardware-example.onekeytest.com/expo-playground/og.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="OneKey Developer Playground">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="OneKey Developer Playground">
<meta name="twitter:description"
content="Interactive playground for OneKey Hardware SDK. Test hardware wallet APIs and blockchain integrations.">
<meta name="twitter:creator" content="@OneKeyHQ">
<meta name="twitter:site" content="@OneKeyHQ">
<meta name="twitter:image" content="https://hardware-example.onekeytest.com/expo-playground/og.jpg">
<meta name="twitter:image:alt" content="OneKey Developer Playground">
<script>
// 简化的路由分发器
(function () {
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/package-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ jobs:
echo "🔨 Building packages..."
yarn build


- name: Commit lockfile changes
run: |
if [ -n "$(git status --porcelain yarn.lock)" ]; then
echo "📦 Committing yarn.lock changes from CI environment..."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add yarn.lock
git commit -m "chore: update yarn.lock [skip ci]"
else
echo "✅ yarn.lock is clean"
fi

- name: Publish to NPM
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ packages/connect-examples/expo-example/web-build

# Expo web export
**/web-build
.vercel
.env*.local
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "submodules/firmware"]
path = submodules/firmware
url = https://github.com/OneKeyHQ/firmware.git
[submodule "submodules/firmware-pro2"]
path = submodules/firmware-pro2
url = https://github.com/OneKeyHQ/firmware-pro2.git
branch = dev
107 changes: 59 additions & 48 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
# OneKey Hardware SDK - Claude 文档指引
# Claude / Agent 工作入口

## 📚 Context7 文档支持
这份文件只放协作者入口和工程约束,不承载完整技术说明。详细文档以 `docs/README.md` 为索引。

本项目已在 Context7 上索引,可通过 MCP 工具获取最新文档和代码示例:
## 先读什么

按任务类型选择入口:

| 任务 | 首选文档 |
| --------------------------------------- | --------------------------------------- |
| 了解整体架构 | `docs/architecture.md` |
| 调试 WebUSB / BLE / TransportManager | `docs/transport.md` |
| 处理 Pro2 / Protocol V2 / firmware-pro2 | `docs/protocol-v2.md` |
| 链集成、签名、地址派生 | `docs/chain.md`、`docs/chain-evm.md` |
| SLIP39、PIN、设备安全状态 | `docs/slip39.md`、`docs/attachToPin.md` |
| 设备方法支持矩阵 | `docs/device-method-support.md` |

完整目录见 `docs/README.md`。

## 当前架构边界

- Protocol V1 服务 Classic / Mini / Touch / Pro 等现有设备,USB 和 BLE 都支持。
- Protocol V2 服务 Pro2,USB 和 BLE 都支持。
- 协议判断必须在连接后主动探测,不能依赖 PID、productName 或 descriptor。
- WebUSB / Electron BLE / React Native BLE 都通过 `GetProtoVersion` 探测 V2,失败或超时回落 V1。
- `desktop-web-ble` 是默认 Electron BLE 入口,不再按设备型号拆分 env alias。
- Protocol V2 不走传统 `Initialize/GetFeatures`,而是 `Ping + DeviceGetDeviceInfo` 后通过 `Protocol V2 feature adapter` 归一成 `Features`;早期固件不支持完整信息时才回退最小 `Features`。

## Protocol V2 改动注意事项

- `messages-protocol-v2.json` 来源是 `submodules/firmware-pro2/sys/protobuf/onekey_protocol/latest`。
- 当前 Protocol V2 schema 依赖 `firmware-pro2` 的 `origin/dev_romloader_split`,因为该分支包含 `Filesystem*`、`DeviceFirmwareUpdate`、`DeviceReboot` 等消息。
- Protocol V2 文件操作应使用 `FilesystemFileWrite` / `FilesystemDirMake` 等新消息名。
- Protocol V2 固件安装应使用 `DeviceFirmwareUpdate.targets` 显式传入 resource、bootloader、firmware 路径。
- 如果修改 protobuf,优先改生成脚本并重新生成 JSON/types,不要手改生成产物。

## 常用验证命令

根目录目前没有 `build:all` script;全仓构建入口是 `yarn build`(`lerna run build`)。协议和 protobuf 变更建议先按依赖顺序验证:

```bash
yarn --cwd packages/hd-transport test --runInBand
yarn --cwd packages/hd-transport build
yarn --cwd packages/hd-transport-web-device build
yarn --cwd packages/hd-transport-react-native build
yarn --cwd packages/hd-common-connect-sdk build
yarn --cwd packages/core build
NODE_OPTIONS=--max-old-space-size=8192 yarn lint --quiet
git diff --check
```

全仓 lint 容易吃内存,默认加 `NODE_OPTIONS=--max-old-space-size=8192`。

## Context7

本项目可通过 Context7 查询:

```json
{
Expand All @@ -11,63 +62,23 @@
}
```

**使用方法**:
- 使用 `mcp__context7__get-library-docs` 工具获取文档
- Library ID: `/onekeyhq/hardware-js-sdk`
- 可指定 topic 参数聚焦特定主题,如 `transport`、`signing`、`bip39` 等

## 📁 问题分流指引

根据问题类型,请参考对应的专业文档:

### 🔌 连接与传输问题
**症状**: WebUSB权限错误、设备连接失败、传输超时
- 📖 **参考**: [docs/transport.md](./docs/transport.md)
- 🤖 **Agent**: hardware-sdk-expert

### ⛓️ 区块链集成问题
**症状**: 签名失败、地址生成错误、交易构建问题
- 📖 **参考**: [docs/chain.md](./docs/chain.md)
- 🤖 **Agent**: hardware-sdk-expert
查询主题建议使用精确 topic,例如 `transport`、`Protocol V2`、`firmware update`、`signing`、`SLIP39`。

### 🔐 助记词与密钥管理
**症状**: SLIP39恢复失败、密钥派生错误、种子生成问题
- 📖 **参考**: [docs/slip39.md](./docs/slip39.md)
- 🤖 **Agent**: hardware-sdk-expert
## CLI 入口

### 🏗️ 架构与开发问题
**症状**: 构建失败、依赖问题、monorepo结构疑问
- 📖 **参考**: [docs/architecture.md](./docs/architecture.md)
- 🤖 **Agent**: hardware-sdk-expert
`@onekeyfe/cli` 是完整钱包 CLI:

### 🤖 AI Agent 集成 / CLI 使用
**症状**: CLI 命令使用、Agent Skill 配置、链支持查询
- 📖 **文档**: developer-portal 的 `agent-integration.mdx`
- 🔧 **`@onekeyfe/cli`**(`onekey` 命令)— 全功能钱包 CLI:`auth login` 选择登录方式(mnemonic / app-transfer / hardware),`balance` / `transfer` / `swap` / `device ...` 等业务命令登录后自动沿用该模式
- 🔧 **`@onekeyfe/hardware-cli`**(`onekey-hw` 命令)— 纯硬件钱包 CLI,AI Agent 直连设备优先选它

如果你要**通过 `onekey` CLI 使用硬件钱包**:
```bash
npm install -g @onekeyfe/cli

# Step 1:登录时选择硬件模式(--hardware 只在 auth login 上有)
onekey auth login --hardware

# Step 2:登录后的业务命令不需要再加 flag,自动走硬件钱包
onekey balance --chain eth
onekey device search
onekey device firmware
```

如果要**只调硬件操作、不走 onekey 账户体系**(更轻、AI Agent 场景友好):
`@onekeyfe/hardware-cli` 是纯硬件 CLI,更适合 AI Agent 直连设备:

```bash
npm install -g @onekeyfe/hardware-cli
onekey-hw search
onekey-hw get-address --chain evm --use-empty-passphrase
```

## 🤖 专业Agent

**hardware-sdk-expert** - 硬件SDK架构专家
- 擅长:三层架构分析、WebUSB/BLE协议、BIP32/BIP39/SLIP39
- 工作方式:优先查阅相关文档,然后进行代码分析
162 changes: 162 additions & 0 deletions OneKey_Pro2_Deep_Dive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# OneKey Pro 1 vs Pro 2 协议深度对比与 SDK 接入指南

## 1. GetFeatures 字段详表与差异分析

下表对比了 Pro 1 (Legacy) 与 Pro 2 (Proto V0) 的 `Features` 消息字段。**加粗部分**表示 Pro 2 中新增、变更或具有重大逻辑差异的字段。

| 字段名 | Pro 1 (Legacy) | Pro 2 (Proto V0) | 说明 |
| :--- | :--- | :--- | :--- |
| `vendor` | "onekey.so" | "onekey.so" | 保持一致。 |
| `major_version` | 固件主版本 | 固件主版本 | 逻辑一致。 |
| `device_id` | 字符串 (Legacy ID) | **UUID 字符串** | Pro 2 采用标准 UUID 格式。 |
| `model` | "Pro" | "Pro" | 均为 Pro 系列。 |
| **`onekey_serial`** | 不支持 | **UUID 硬件序列号** | **Pro 2 新增**,用于唯一标识物理硬件。 |
| **`se_type`** | 不支持 | **SE 芯片型号枚举** | **Pro 2 新增**,区分 SE608A 等不同 SE 芯片。 |
| **`se_state`** | 不支持 | **SE 运行状态** | **Pro 2 新增**,标识 SE 处于 Boot 还是 App 模式。 |
| **`se_ver`** | 字符串 | **结构化版本号** | Pro 2 的 SE 版本信息更详细,支持子系统判定。 |
| **`ble_ver`** | 字符串 | **结构化版本号** | Pro 2 蓝牙固件版本,用于判定 BLE 功能支持。 |
| **`bootloader_version`**| 不支持 | **独立版本号** | **Pro 2 新增**,用于判定是否支持极速固件更新。 |
| `initialized` | bool | bool | 逻辑一致。 |
| `unlocked` | bool | bool | 逻辑一致。 |
| **`session_id`** | 随机字符串 | **ZBus Session ID** | Pro 2 中该 ID 与内部实时任务队列绑定。 |
| **`capabilities`** | 基础功能枚举 | **扩展功能枚举** | Pro 2 增加了对新链(如 Sui, Aptos)的原生支持标识。 |
| **`request_id`** | **不支持** | **4 字节整型** | **核心差异**:Pro 2 在链路层支持异步请求标识。 |

---

## 2. OnekeyFeatures (10025/10026) 专项对比

`OnekeyFeatures` 是 OneKey 硬件特有的扩展接口,用于提供比标准 `Features` 更深度的硬件全栈状态。

### 2.1 字段深度定义 (Pro 2 强化版)
在 Pro 2 中,由于采用了 **RTOS + 多子系统** 架构,该接口返回的信息大幅增加。

| 字段分类 | 关键字段 | Pro 1 (Legacy) | Pro 2 (Proto V0) | 说明 |
| :--- | :--- | :--- | :--- | :--- |
| **基础信息** | `onekey_device_type` | PRO (5) | PRO (5) | 保持一致。 |
| **版本控制** | `onekey_boot_version` | 基础版本 | **含 Build ID 的详细版本** | 用于判定固件包兼容性。 |
| **序列号** | `onekey_serial_no` | 硬件 SN | **UUID 格式 SN** | 物理层面的唯一标识。 |
| **多 SE 状态** | **`onekey_se01_state`** | 仅支持单 SE | **支持 01-04 四个槽位** | **Pro 2 核心改动**:支持查询多个安全芯片状态。 |
| | **`onekey_se01_ver`** | 单一字符串 | **结构化版本信息** | 细化了 SE 内部固件版本。 |
| **连接信息** | `onekey_ble_name` | 蓝牙名称 | 蓝牙名称 | 逻辑一致。 |

### 2.2 Pro 2 内部实现逻辑
* **异步获取**:不同于 Pro 1 的静态读取,Pro 2 的 `OnekeyGetFeatures` 会触发一次内部的 **ZBus 广播**。
* **任务协同**:`Foreground` 任务接收请求后,会向 `SE Agent` 任务请求最新的安全芯片状态,汇总后再通过 USB 返回。
* **SDK 建议**:在 Pro 2 连接后,应**优先调用 `OnekeyGetFeatures`**,以获取最完整的硬件拓扑信息。

---

## 3. 私有协议扩展 (Private Range: 60000+)

Pro 2 引入了一系列专门用于工程测试和文件管理的私有协议(基于 `webusb_test.html` 整理):

| Message ID | 消息名称 | 用途 |
| :--- | :--- | :--- |
| 60206 | `Ping` | 新协议连通性测试。 |
| 60800 | `FixPermission` | 修复 eMMC 文件系统权限。 |
| 60801 / 60802 | `PathInfo` / `Query` | 查询设备内部文件信息。 |
| 60804 / 60805 | `FileRead` / `Write` | **极速文件传输**:单包可达 2048B。 |
| 61000 | `FirmwareUpdate` | 触发 V3 固件更新流程。 |

---

## 4. 通讯时序图对比

### 2.1 Pro 1: Legacy 64 字节分包模式
Pro 1 受到物理 HID 报告大小限制,必须进行严格的分包。

```mermaid
sequenceDiagram
participant SDK as hardware-js-sdk
participant USB as WebUSB
participant MCU as Pro 1 MCU

Note over SDK: 封装消息 (如 GetAddress)
SDK->>SDK: Protobuf 序列化
SDK->>SDK: 添加 6 字节 Header (## + Type + Size)

Note over SDK: 分包 (每包 64 字节)
SDK->>USB: transferOut (Packet 1: Header + Data)
USB->>MCU: 接收首包,解析总长度
SDK->>USB: transferOut (Packet 2: Data)
USB->>MCU: 接收续包
SDK->>USB: transferOut (Packet 3: Data...)

Note over MCU: 业务处理...

MCU->>USB: 返回首包 (## + Type + Size)
USB-->>SDK: transferIn (64B)
MCU->>USB: 返回续包...
USB-->>SDK: transferIn (64B)
```

### 2.2 Pro 2: Proto V0 长帧模式
Pro 2 利用新协议消除了分包开销,支持高达 2048 字节的单帧传输。

```mermaid
sequenceDiagram
participant SDK as hardware-js-sdk
participant USB as WebUSB
participant MCU as Pro 2 MCU (RTOS)

Note over SDK: 封装消息 (如 GetAddress)
SDK->>SDK: Protobuf 序列化
SDK->>SDK: 计算全帧 CRC8 (Init: 0x30)
SDK->>SDK: 构造帧 [0x5A][Len][CRC_H][Router][Attr][Seq][Payload][CRC_A]

Note over SDK: 单帧传输 (无需 SDK 分包)
SDK->>USB: transferOut (单次最大 2048B)
USB->>MCU: 硬件 DMA 直接接收全帧

Note over MCU: 校验 CRC8 & 任务分发
MCU->>MCU: ZBus Dispatch to Crypto Task

Note over MCU: 返回响应
MCU->>USB: 发送响应帧 (0x5A 起始)
USB-->>SDK: transferIn (一次性读取完整响应)
```

---

## 3. SDK 协议自动探测逻辑 (Dynamic Detection)

鉴于 Pro 1 未来也可能升级支持新协议,SDK **不能**仅依赖 PID 来写死协议。建议采用以下探测流程:

### 3.1 探测流程 (Handshake)
1. **尝试新协议**:SDK 初始化后,先发送一个 **Proto V0 (0x5A)** 格式的 `GetFeatures`。
2. **监听首字节**:
* 如果返回数据以 `0x5A` 开头 -> **确认为 Pro 2 协议模式**。
* 如果返回数据以 `0x3F` (WebUSB) 开头,且后续为 `0x23 0x23` -> **确认为 Legacy 模式**。
3. **持久化标志**:在当前 `Device` 实例中记录 `protocolType`,后续 `Call` 直接调用对应序列化器。

### 3.2 伪代码实现
```typescript
async function detectProtocol(device) {
try {
// 1. 尝试用新协议打招呼
const probePacket = Pro2Serializer.buildProbePacket();
await device.transferOut(probePacket);

const res = await device.transferIn(64);
const firstByte = res.data.getUint8(0);

if (firstByte === 0x5A) {
return 'PROTO_V0';
} else if (firstByte === 0x3F) {
return 'LEGACY';
}
} catch (e) {
// 容错处理:默认回退到 Legacy
return 'LEGACY';
}
}
```

## 4. 接入建议

* **无状态处理**:虽然 Pro 2 内部支持状态,但为了兼容性,SDK 建议依然在 `acquire` 后执行一次协议探测 + `GetFeatures`。
* **字节序陷阱**:再次提醒,新协议所有的 `Length` 和 `MessageID` 均为 **Little-Endian (小端)**,这与 Legacy 的大端序完全相反。

---
*文档版本:2026-03-18*
Loading
Loading