@onekeyfe/hd-transport 1.2.0-alpha.18 → 1.2.0-alpha.180
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/messages.test.js +137 -32
- package/__tests__/protocol-v2-ble-frame-writer.test.js +119 -0
- package/__tests__/protocol-v2-link-manager.test.js +246 -9
- package/__tests__/protocol-v2-usb-transport-base.test.js +42 -6
- package/__tests__/protocol-v2.test.js +632 -62
- package/__tests__/transport-log.test.js +79 -0
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +539 -285
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +718 -160
- package/dist/protocols/index.d.ts +17 -1
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/ble-frame-writer.d.ts +15 -0
- package/dist/protocols/v2/ble-frame-writer.d.ts.map +1 -0
- package/dist/protocols/v2/decode.d.ts +11 -0
- package/dist/protocols/v2/decode.d.ts.map +1 -1
- package/dist/protocols/v2/errors.d.ts +16 -0
- package/dist/protocols/v2/errors.d.ts.map +1 -0
- package/dist/protocols/v2/frame-assembler.d.ts.map +1 -1
- package/dist/protocols/v2/index.d.ts +2 -0
- package/dist/protocols/v2/index.d.ts.map +1 -1
- package/dist/protocols/v2/link-manager.d.ts +6 -0
- package/dist/protocols/v2/link-manager.d.ts.map +1 -1
- package/dist/protocols/v2/session.d.ts +16 -4
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/protocols/v2/usb-transport-base.d.ts +2 -0
- package/dist/protocols/v2/usb-transport-base.d.ts.map +1 -1
- package/dist/serialization/protobuf/encode.d.ts.map +1 -1
- package/dist/types/messages.d.ts +217 -202
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +21 -2
- package/dist/types/transport.d.ts.map +1 -1
- package/dist/utils/transportLog.d.ts +9 -0
- package/dist/utils/transportLog.d.ts.map +1 -0
- package/messages-protocol-v2.json +515 -540
- package/package.json +2 -2
- package/scripts/protobuf-types.js +7 -1
- package/src/constants.ts +30 -16
- package/src/index.ts +5 -1
- package/src/protocols/index.ts +114 -3
- package/src/protocols/v2/ble-frame-writer.ts +77 -0
- package/src/protocols/v2/crc8.ts +1 -1
- package/src/protocols/v2/decode.ts +49 -12
- package/src/protocols/v2/encode.ts +1 -1
- package/src/protocols/v2/errors.ts +54 -0
- package/src/protocols/v2/frame-assembler.ts +6 -4
- package/src/protocols/v2/index.ts +2 -0
- package/src/protocols/v2/link-manager.ts +110 -9
- package/src/protocols/v2/session.ts +260 -87
- package/src/protocols/v2/usb-transport-base.ts +42 -10
- package/src/serialization/protobuf/encode.ts +5 -1
- package/src/types/messages.ts +269 -258
- package/src/types/transport.ts +39 -7
- package/src/utils/transportLog.ts +102 -0
|
@@ -65,6 +65,7 @@ class FakeUsbTransport extends ProtocolV2UsbTransportBase {
|
|
|
65
65
|
this.nextReadError = undefined;
|
|
66
66
|
this.writeBlock = undefined;
|
|
67
67
|
this.readBlock = undefined;
|
|
68
|
+
this.coalesceNextResponses = false;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
callDevice(key, message, timeoutMs) {
|
|
@@ -118,6 +119,10 @@ class FakeUsbTransport extends ProtocolV2UsbTransportBase {
|
|
|
118
119
|
return { started, release };
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
coalesceNextTwoResponses() {
|
|
123
|
+
this.coalesceNextResponses = true;
|
|
124
|
+
}
|
|
125
|
+
|
|
121
126
|
getProtocolV2UsbSchemas() {
|
|
122
127
|
return schemas;
|
|
123
128
|
}
|
|
@@ -135,8 +140,22 @@ class FakeUsbTransport extends ProtocolV2UsbTransportBase {
|
|
|
135
140
|
{ message: 'ok' },
|
|
136
141
|
{ router: PROTOCOL_V2_CHANNEL_USB, seq }
|
|
137
142
|
);
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
if (this.coalesceNextResponses) {
|
|
144
|
+
this.coalesceNextResponses = false;
|
|
145
|
+
const nextResponse = ProtocolV2.encodeFrame(
|
|
146
|
+
schemas,
|
|
147
|
+
'Success',
|
|
148
|
+
{ message: 'ok' },
|
|
149
|
+
{ router: PROTOCOL_V2_CHANNEL_USB, seq: Number(seq) + 1 }
|
|
150
|
+
);
|
|
151
|
+
const packet = new Uint8Array(response.length + nextResponse.length);
|
|
152
|
+
packet.set(response);
|
|
153
|
+
packet.set(nextResponse, response.length);
|
|
154
|
+
this.packetQueues.set(key, [packet]);
|
|
155
|
+
} else {
|
|
156
|
+
const splitAt = Math.min(4, response.length);
|
|
157
|
+
this.packetQueues.set(key, [response.slice(0, splitAt), response.slice(splitAt)]);
|
|
158
|
+
}
|
|
140
159
|
|
|
141
160
|
const block = this.writeBlock;
|
|
142
161
|
if (block) {
|
|
@@ -198,7 +217,7 @@ describe('ProtocolV2UsbTransportBase', () => {
|
|
|
198
217
|
expect(transport.nativeResets).toEqual([['device-a', 'USB reconnected']]);
|
|
199
218
|
});
|
|
200
219
|
|
|
201
|
-
test('passes each queued call its
|
|
220
|
+
test('passes each queued call its remaining timeout context', async () => {
|
|
202
221
|
const transport = new FakeUsbTransport();
|
|
203
222
|
await transport.rotate('device-a');
|
|
204
223
|
|
|
@@ -207,11 +226,28 @@ describe('ProtocolV2UsbTransportBase', () => {
|
|
|
207
226
|
transport.callDevice('device-a', 'second', 222),
|
|
208
227
|
]);
|
|
209
228
|
|
|
210
|
-
expect(transport.readContexts).toEqual([
|
|
229
|
+
expect(transport.readContexts.slice(0, 2)).toEqual([
|
|
211
230
|
['device-a', 111],
|
|
212
231
|
['device-a', 111],
|
|
213
|
-
|
|
214
|
-
|
|
232
|
+
]);
|
|
233
|
+
const secondCallTimeouts = transport.readContexts.slice(2).map(([, timeoutMs]) => timeoutMs);
|
|
234
|
+
expect(secondCallTimeouts[0]).toBeGreaterThan(0);
|
|
235
|
+
expect(secondCallTimeouts[0]).toBeLessThanOrEqual(222);
|
|
236
|
+
expect(secondCallTimeouts[1]).toBe(secondCallTimeouts[0]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('keeps a coalesced response buffered for the next call', async () => {
|
|
240
|
+
const transport = new FakeUsbTransport();
|
|
241
|
+
await transport.rotate('device-a');
|
|
242
|
+
transport.coalesceNextTwoResponses();
|
|
243
|
+
|
|
244
|
+
await transport.callDevice('device-a', 'first');
|
|
245
|
+
await transport.callDevice('device-a', 'second');
|
|
246
|
+
|
|
247
|
+
expect(transport.readCounts.get('device-a')).toBe(1);
|
|
248
|
+
expect(transport.sentSeqs).toEqual([
|
|
249
|
+
['device-a', 1],
|
|
250
|
+
['device-a', 2],
|
|
215
251
|
]);
|
|
216
252
|
});
|
|
217
253
|
|