Commit 312143a
refactor(transport): rename protocols to V1/V2, isolate Pro2 firmware update path
This change does three independent things; together they replace the
ad-hoc Pro2 dispatch the previous WIP added with a single per-device
source of truth, and stop the V1 firmware update flow from carrying
V2-aware branches.
1. Rename Proto V0 / legacy V2 → Protocol V1 / V2
The earlier WIP used "V2" for the legacy 64-byte 0x3F protocol
(Pro1 / Touch / Mini / Classic) and "V0" for Pro2's 0x5A framing,
borrowed from the firmware-side "Proto V0 / Proto Link" naming.
That ordering reads backwards for SDK consumers — Pro1 should be
V1, Pro2 should be V2. Rename everything (types, constants, schema
field names, log tags, directories, docs) on the SDK side. Wire
format is unchanged.
- `packages/hd-transport/src/serialization/protocol/` → `protocol-v1/`
- `packages/hd-transport/src/serialization/protocol-v0/` → `protocol-v2/`
- `ProtocolV2` (chunked) → `ProtocolV1`; `ProtocolV0` → `ProtocolV2`
- `parseProtoV0Frame` / `buildProtoV0Frame` / `ProtoV0Frame` →
`parseProtoV2Frame` / `buildProtoV2Frame` / `ProtoV2Frame`
- `PROTOCOL_V0_SYS_MESSAGE_THRESHOLD` → `PROTOCOL_V2_SYS_MESSAGE_THRESHOLD`
- `pro2Protocol` namespace export → `protoV2`
- `configureProtocolV0` / `configureProV0` aliases collapse into
a single `configureProtocolV2` entry on the Transport interface
- `ProtocolType` union flips from `'V2' | 'V0'` to `'V1' | 'V2'`
- All `'V0'` / `'V2'` literals routed through the type are flipped
(Tron `messageType: 'V1' | 'V2'` is unrelated and untouched)
- docs/transport.md and docs/pro2-protocol.md rewritten to match
2. Approach B: single source of truth for protocol routing
Previously TransportManager.reconfigure was being called with a
`protocolType` argument from Device.initialize() to "swap" the
active schema between V1 and V2. That swap was largely cosmetic —
the transport already holds both schemas after configure(), and
call() routes per-path via getProtocolType(). The reconfigure
branch for V1 even re-parsed the entire default schema on every
V1 device init.
- Drop `protocolType` parameter on `TransportManager.reconfigure()`;
it now only handles features-based messageVersion swaps (e.g.
Touch classic vs latest), which is its original purpose
- Remove the redundant `reconfigure(undefined, 'V1')` call at the
top of `Device.initialize()` and the `reconfigure(undefined, 'V2')`
call inside `_initializePro2()`
- Promote `Transport.getProtocolType(path)` from optional to
required; add `'V1'` returns to single-protocol transports
(Emulator / Http / Lowlevel / ReactNative / NodeUsb /
ElectronBle); WebUsb keeps its PID-based detection; Pro2 BLE
stays hardcoded `'V2'`
- Pro2 synthetic features now include `device_id` derived from
the descriptor (path / id) so downstream `getDeviceUUID(features)`
stops returning undefined for Pro2
3. Isolate Pro2 firmware update from V1 path
The previous WIP wove `isPro2Device()` checks into the V1 update
flow (validateDeviceAndVersion, executeUpdate, etc.). Pull that
out so V1 reads exactly as it did in HEAD, and Pro2 takes a
dedicated branch:
- `FirmwareUpdateV3.run()` early-returns into `runProtocolV2()`
when `descriptor.protocolType === 'V2'`. V1 path below is
character-for-character the original.
- `runProtocolV2()` reuses common helpers
(`prepareResourceBinary`, `prepareFirmwareAndBleBinary`,
`prepareBootloaderBinary`) and Pro2-only helpers in BaseMethod
(`pro2CreateFolder` / `pro2CommonUpdateProcess` /
`pro2StartFirmwareUpdate` / `fileWriteWithRetry`).
- Pro2 file paths align with the pro2-debug script: `vol1:` root
instead of V1's `0:updates/`. Resource files go to `vol1:res/`.
- `pro2EnterBootloader()` sends `Reboot { reboot_type: BootLoader }`
via the SDK's existing `this.reboot()` helper (typedCall under
the hood, tolerates the device dropping USB during reboot). No
raw WebUSB. A 1.5s settle wait is the placeholder for the
reconnect / Ping handshake to add once Pro2 bootloader-mode is
finalized on the firmware side.
- Pro2 doesn't expose GetFeatures, so completion detection is the
`FirmwareUpdate` Success response itself (matches pro2-debug's
synchronous behavior). No GetFeatures polling.
- Drop the `getFirmwareUpdateStrategy()` strategy abstraction and
the `FirmwareUpdateProtocol` type from BaseMethod. They were V1
contamination — V1 now calls `emmcCommonUpdateProcess` /
`createUpdatesFolderIfNotExists` / `startEmmcFirmwareUpdate`
directly, as it did before.
- Pro2 protocol constants
(`PROTOCOL_V2_USB_PID` / `PROTOCOL_V2_FILE_CHUNK_SIZE` /
channel + packet-source enums) extracted to
`hd-transport/src/constants.ts` and imported by both transports.
USB callProtocolV2 stays without channel/packetSrc options
(USB endpoints reach the main MCU directly) while BLE keeps
`PROTOCOL_V2_CHANNEL_BLE_UART` and `PROTOCOL_V2_PACKET_SRC_COMMAND`
because of the BLE-coprocessor → main-MCU UART bridge.
Known follow-ups (not in this commit):
- `PROTOCOL_V2_USB_PID = 0x53c1` shares the value with
Classic/Mini/Pro/Touch firmware in `ONEKEY_WEBUSB_FILTER`. Safe
only while Pro2 is the only PID-0x53c1 device in the test
environment. Update once Pro2 firmware ships with its own PID.
- Pro2 bootloader handoff in `pro2EnterBootloader()` waits a flat
1.5s. Replace with reconnect + Ping verification when Pro2
bootloader-mode behavior is finalized.
Verified: tsc --noEmit clean across hd-transport / hd-transport-* /
core (apart from 4 pre-existing typedCall errors on Pro2-only
messages that exist on this branch independently of this change);
ESLint clean on every file touched.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3905be4 commit 312143a
29 files changed
Lines changed: 632 additions & 358 deletions
File tree
- docs
- packages
- core/src
- api
- firmware
- data-manager
- device
- hd-transport-emulator/src
- hd-transport-http/src
- hd-transport-lowlevel/src
- hd-transport-react-native/src
- hd-transport-usb/src
- hd-transport-web-device/src
- hd-transport/src
- serialization
- protocol-v1
- protocol-v2
- types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
| 122 | + | |
| 123 | + | |
124 | 124 | | |
125 | | - | |
126 | | - | |
| 125 | + | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
| 141 | + | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
| 164 | + | |
| 165 | + | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
| 101 | + | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
129 | | - | |
| 133 | + | |
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
133 | 137 | | |
134 | | - | |
135 | | - | |
| 138 | + | |
| 139 | + | |
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
139 | | - | |
| 143 | + | |
140 | 144 | | |
141 | | - | |
| 145 | + | |
142 | 146 | | |
143 | 147 | | |
144 | 148 | | |
145 | | - | |
146 | | - | |
| 149 | + | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | | - | |
150 | | - | |
| 153 | + | |
| 154 | + | |
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| |||
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
198 | | - | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
201 | 205 | | |
| |||
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
240 | | - | |
| 244 | + | |
241 | 245 | | |
242 | 246 | | |
243 | 247 | | |
| |||
252 | 256 | | |
253 | 257 | | |
254 | 258 | | |
255 | | - | |
256 | | - | |
| 259 | + | |
| 260 | + | |
257 | 261 | | |
258 | 262 | | |
259 | | - | |
260 | | - | |
| 263 | + | |
| 264 | + | |
261 | 265 | | |
0 commit comments