@onekeyfe/hd-transport-react-native 1.2.0-alpha.10 → 1.2.0-alpha.12
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/dist/bleStrategy.d.ts +0 -2
- package/dist/bleStrategy.d.ts.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -97
- package/dist/subscribeBleOn.d.ts.map +1 -1
- package/dist/transportLog.d.ts +13 -0
- package/dist/transportLog.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/__tests__/bleStrategy.test.ts +1 -6
- package/src/__tests__/protocolV2Link.test.ts +28 -22
- package/src/bleStrategy.ts +0 -25
- package/src/index.ts +38 -135
- package/src/subscribeBleOn.ts +0 -2
- package/src/transportLog.ts +18 -0
package/dist/bleStrategy.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ export type BleWriteCapability = {
|
|
|
3
3
|
isWritableWithResponse?: boolean | null;
|
|
4
4
|
isWritableWithoutResponse?: boolean | null;
|
|
5
5
|
};
|
|
6
|
-
export type BleWriteMode = 'withResponse' | 'withoutResponse';
|
|
7
6
|
export declare function hasWritableCapability(characteristic: BleWriteCapability): boolean;
|
|
8
|
-
export declare function resolveBleWriteMode(characteristic: BleWriteCapability, preferredMode?: BleWriteMode): BleWriteMode;
|
|
9
7
|
export declare function resolveProtocolV2PacketCapacity({ platform, iosPacketLength, androidPacketLength, mtu, }: {
|
|
10
8
|
platform: BlePlatform;
|
|
11
9
|
iosPacketLength?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,kBAAkB,WAEvE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,eAAmC,EACnC,mBAA2C,EAC3C,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,UAWA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -37,20 +37,12 @@ type ResolvedBleCharacteristics = {
|
|
|
37
37
|
type ProtocolV2BleTuning = {
|
|
38
38
|
iosPacketLength?: number;
|
|
39
39
|
androidPacketLength?: number;
|
|
40
|
-
highVolumeWriteBurstSize?: number;
|
|
41
|
-
highVolumeWritePauseMs?: number;
|
|
42
|
-
highVolumeWriteFlushDelayMs?: number;
|
|
43
|
-
highVolumeWriteWithResponse?: boolean;
|
|
44
40
|
};
|
|
45
41
|
declare function configureProtocolV2BleTuning(tuning?: ProtocolV2BleTuning): void;
|
|
46
42
|
declare function resetProtocolV2BleTuning(): void;
|
|
47
43
|
declare function getProtocolV2BleTuning(): {
|
|
48
44
|
iosPacketLength: number;
|
|
49
45
|
androidPacketLength: number;
|
|
50
|
-
highVolumeWriteBurstSize: number;
|
|
51
|
-
highVolumeWritePauseMs: number;
|
|
52
|
-
highVolumeWriteFlushDelayMs: number;
|
|
53
|
-
highVolumeWriteWithResponse: boolean;
|
|
54
46
|
};
|
|
55
47
|
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
56
48
|
declare class ReactNativeBleTransport {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAGjB,KAAK,oBAAoB,EAE1B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -138,21 +138,6 @@ const isSameBleUuid = (left, right) => {
|
|
|
138
138
|
function hasWritableCapability(characteristic) {
|
|
139
139
|
return !!(characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse);
|
|
140
140
|
}
|
|
141
|
-
function resolveBleWriteMode(characteristic, preferredMode = 'withoutResponse') {
|
|
142
|
-
if (preferredMode === 'withoutResponse' && characteristic.isWritableWithoutResponse) {
|
|
143
|
-
return 'withoutResponse';
|
|
144
|
-
}
|
|
145
|
-
if (preferredMode === 'withResponse' && characteristic.isWritableWithResponse) {
|
|
146
|
-
return 'withResponse';
|
|
147
|
-
}
|
|
148
|
-
if (characteristic.isWritableWithoutResponse) {
|
|
149
|
-
return 'withoutResponse';
|
|
150
|
-
}
|
|
151
|
-
if (characteristic.isWritableWithResponse) {
|
|
152
|
-
return 'withResponse';
|
|
153
|
-
}
|
|
154
|
-
return preferredMode;
|
|
155
|
-
}
|
|
156
141
|
function resolveProtocolV2PacketCapacity({ platform, iosPacketLength = IOS_PACKET_LENGTH, androidPacketLength = ANDROID_PACKET_LENGTH, mtu, }) {
|
|
157
142
|
if (platform === 'ios') {
|
|
158
143
|
return iosPacketLength;
|
|
@@ -189,7 +174,6 @@ const timer = process.env.NODE_ENV === 'development'
|
|
|
189
174
|
const subscribeBleOn = (bleManager, ms = 1000) => new Promise((resolve, reject) => {
|
|
190
175
|
let done = false;
|
|
191
176
|
const subscription = bleManager.onStateChange(state => {
|
|
192
|
-
console.log('ble state -> ', state);
|
|
193
177
|
if (state === 'PoweredOn') {
|
|
194
178
|
if (done)
|
|
195
179
|
return;
|
|
@@ -261,6 +245,18 @@ class BleTransport {
|
|
|
261
245
|
BleTransport.MAX_RETRIES = 5;
|
|
262
246
|
BleTransport.RETRY_DELAY = 2000;
|
|
263
247
|
|
|
248
|
+
function createTransportCallLog(name, protocol, data) {
|
|
249
|
+
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
250
|
+
return {
|
|
251
|
+
name,
|
|
252
|
+
protocol,
|
|
253
|
+
file_name: data.file_name,
|
|
254
|
+
hash: data.hash,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return { name, protocol };
|
|
258
|
+
}
|
|
259
|
+
|
|
264
260
|
const { check, ProtocolV1, parseConfigure } = transport__default["default"];
|
|
265
261
|
const Log = bleLogger;
|
|
266
262
|
const transportCache = {};
|
|
@@ -299,16 +295,9 @@ const PROTOCOL_V2_PROBE_TIMEOUT_MS = 10000;
|
|
|
299
295
|
const DEVICE_SCAN_TIMEOUT_MS = 8000;
|
|
300
296
|
const IOS_NOTIFY_READY_DELAY_MS = 150;
|
|
301
297
|
const ANDROID_NOTIFY_READY_DELAY_MS = 300;
|
|
302
|
-
const HIGH_VOLUME_WRITE_BURST_SIZE = reactNative.Platform.OS === 'ios' ? 4 : 6;
|
|
303
|
-
const HIGH_VOLUME_WRITE_PAUSE_MS = reactNative.Platform.OS === 'ios' ? 6 : 2;
|
|
304
|
-
const HIGH_VOLUME_WRITE_FLUSH_DELAY_MS = reactNative.Platform.OS === 'ios' ? 20 : 8;
|
|
305
298
|
const DEFAULT_PROTOCOL_V2_BLE_TUNING = {
|
|
306
299
|
iosPacketLength: IOS_PACKET_LENGTH,
|
|
307
300
|
androidPacketLength: ANDROID_PACKET_LENGTH,
|
|
308
|
-
highVolumeWriteBurstSize: HIGH_VOLUME_WRITE_BURST_SIZE,
|
|
309
|
-
highVolumeWritePauseMs: HIGH_VOLUME_WRITE_PAUSE_MS,
|
|
310
|
-
highVolumeWriteFlushDelayMs: HIGH_VOLUME_WRITE_FLUSH_DELAY_MS,
|
|
311
|
-
highVolumeWriteWithResponse: false,
|
|
312
301
|
};
|
|
313
302
|
let protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
|
|
314
303
|
const normalizePositiveInteger = (value, fallback) => {
|
|
@@ -318,20 +307,15 @@ const normalizePositiveInteger = (value, fallback) => {
|
|
|
318
307
|
return Math.floor(normalized);
|
|
319
308
|
};
|
|
320
309
|
function configureProtocolV2BleTuning(tuning = {}) {
|
|
321
|
-
var _a;
|
|
322
310
|
protocolV2BleTuning = {
|
|
323
311
|
iosPacketLength: normalizePositiveInteger(tuning.iosPacketLength, protocolV2BleTuning.iosPacketLength),
|
|
324
312
|
androidPacketLength: normalizePositiveInteger(tuning.androidPacketLength, protocolV2BleTuning.androidPacketLength),
|
|
325
|
-
highVolumeWriteBurstSize: normalizePositiveInteger(tuning.highVolumeWriteBurstSize, protocolV2BleTuning.highVolumeWriteBurstSize),
|
|
326
|
-
highVolumeWritePauseMs: normalizePositiveInteger(tuning.highVolumeWritePauseMs, protocolV2BleTuning.highVolumeWritePauseMs),
|
|
327
|
-
highVolumeWriteFlushDelayMs: normalizePositiveInteger(tuning.highVolumeWriteFlushDelayMs, protocolV2BleTuning.highVolumeWriteFlushDelayMs),
|
|
328
|
-
highVolumeWriteWithResponse: (_a = tuning.highVolumeWriteWithResponse) !== null && _a !== void 0 ? _a : protocolV2BleTuning.highVolumeWriteWithResponse,
|
|
329
313
|
};
|
|
330
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
314
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
|
|
331
315
|
}
|
|
332
316
|
function resetProtocolV2BleTuning() {
|
|
333
317
|
protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
|
|
334
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
318
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning reset', protocolV2BleTuning);
|
|
335
319
|
}
|
|
336
320
|
function getProtocolV2BleTuning() {
|
|
337
321
|
return Object.assign({}, protocolV2BleTuning);
|
|
@@ -371,9 +355,10 @@ const requestAndroidMtu = (device) => __awaiter(void 0, void 0, void 0, function
|
|
|
371
355
|
return device;
|
|
372
356
|
try {
|
|
373
357
|
const mtuDevice = yield device.requestMTU(ANDROID_REQUEST_MTU);
|
|
374
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
358
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] MTU configured', {
|
|
359
|
+
deviceId: device.id,
|
|
375
360
|
requested: ANDROID_REQUEST_MTU,
|
|
376
|
-
|
|
361
|
+
actual: mtuDevice.mtu,
|
|
377
362
|
});
|
|
378
363
|
return mtuDevice;
|
|
379
364
|
}
|
|
@@ -453,7 +438,6 @@ class ReactNativeBleTransport {
|
|
|
453
438
|
this.protocolV2Links
|
|
454
439
|
.invalidateAllLinks('Protocol V2 schema reconfigured')
|
|
455
440
|
.catch(error => Log === null || Log === void 0 ? void 0 : Log.debug('Protocol V2 schema link cleanup failed:', error));
|
|
456
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 schema configured');
|
|
457
441
|
}
|
|
458
442
|
listen() {
|
|
459
443
|
}
|
|
@@ -652,7 +636,6 @@ class ReactNativeBleTransport {
|
|
|
652
636
|
}, (error, device) => {
|
|
653
637
|
var _a, _b, _c;
|
|
654
638
|
if (error) {
|
|
655
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('ble scan manager: ', blePlxManager);
|
|
656
639
|
Log === null || Log === void 0 ? void 0 : Log.debug('ble scan error: ', error);
|
|
657
640
|
if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
|
|
658
641
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
@@ -675,22 +658,8 @@ class ReactNativeBleTransport {
|
|
|
675
658
|
const isOneKey = hdShared.isOnekeyDevice((_b = device === null || device === void 0 ? void 0 : device.name) !== null && _b !== void 0 ? _b : null, device === null || device === void 0 ? void 0 : device.id) ||
|
|
676
659
|
hdShared.isOnekeyDevice((_c = device === null || device === void 0 ? void 0 : device.localName) !== null && _c !== void 0 ? _c : null, device === null || device === void 0 ? void 0 : device.id) ||
|
|
677
660
|
hasKnownOneKeyService(device);
|
|
678
|
-
const shouldTraceCandidate = !!displayName && /onekey|bixinkey|pro\s*2|pro\b|touch|^k\d|^t\d/i.test(displayName);
|
|
679
|
-
if (shouldTraceCandidate) {
|
|
680
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] scan candidate', {
|
|
681
|
-
name: device === null || device === void 0 ? void 0 : device.name,
|
|
682
|
-
localName: device === null || device === void 0 ? void 0 : device.localName,
|
|
683
|
-
id: device === null || device === void 0 ? void 0 : device.id,
|
|
684
|
-
serviceUUIDs: device === null || device === void 0 ? void 0 : device.serviceUUIDs,
|
|
685
|
-
accepted: isOneKey,
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
661
|
if (isOneKey) {
|
|
689
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('search device start ======================');
|
|
690
|
-
const { name, localName, id, serviceUUIDs } = device !== null && device !== void 0 ? device : {};
|
|
691
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}\nserviceUUIDs: ${(serviceUUIDs !== null && serviceUUIDs !== void 0 ? serviceUUIDs : []).join(',')}`);
|
|
692
662
|
addDevice(device);
|
|
693
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('search device end ======================\n');
|
|
694
663
|
}
|
|
695
664
|
else if (displayName && /\bpro\s*2\b/i.test(displayName)) {
|
|
696
665
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Pro2-like BLE device was not accepted:', {
|
|
@@ -703,7 +672,6 @@ class ReactNativeBleTransport {
|
|
|
703
672
|
});
|
|
704
673
|
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
705
674
|
for (const device of devices) {
|
|
706
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('search connected peripheral: ', device.id);
|
|
707
675
|
addDevice(device);
|
|
708
676
|
}
|
|
709
677
|
});
|
|
@@ -716,6 +684,12 @@ class ReactNativeBleTransport {
|
|
|
716
684
|
this.deviceProtocolHints.set(device.id, protocolHint);
|
|
717
685
|
}
|
|
718
686
|
deviceList.push(Object.assign(Object.assign({}, device), { name: displayName, commType: 'ble' }));
|
|
687
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] OneKey BLE device discovered', {
|
|
688
|
+
deviceId: device.id,
|
|
689
|
+
name: displayName,
|
|
690
|
+
serviceUUIDs: device.serviceUUIDs,
|
|
691
|
+
protocolHint,
|
|
692
|
+
});
|
|
719
693
|
}
|
|
720
694
|
};
|
|
721
695
|
timer.timeout(() => {
|
|
@@ -1045,23 +1019,11 @@ class ReactNativeBleTransport {
|
|
|
1045
1019
|
if (!protocol) {
|
|
1046
1020
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${uuid}`);
|
|
1047
1021
|
}
|
|
1048
|
-
|
|
1049
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', {
|
|
1050
|
-
file_name: data === null || data === void 0 ? void 0 : data.file_name,
|
|
1051
|
-
hash: data === null || data === void 0 ? void 0 : data.hash,
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
else if (transport.LogBlockCommand.has(name)) {
|
|
1055
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' protocol: ', protocol);
|
|
1056
|
-
}
|
|
1057
|
-
else {
|
|
1058
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
|
|
1059
|
-
}
|
|
1022
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('transport call', createTransportCallLog(name, protocol, data));
|
|
1060
1023
|
if (protocol === 'V2') {
|
|
1061
1024
|
return this.callProtocolV2(uuid, name, data, options);
|
|
1062
1025
|
}
|
|
1063
1026
|
const forceRun = name === 'Initialize' || name === 'Cancel';
|
|
1064
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native call this.runPromise', this.runPromise);
|
|
1065
1027
|
if (this.runPromise && !forceRun) {
|
|
1066
1028
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportCallInProgress);
|
|
1067
1029
|
}
|
|
@@ -1140,7 +1102,7 @@ class ReactNativeBleTransport {
|
|
|
1140
1102
|
});
|
|
1141
1103
|
}
|
|
1142
1104
|
else if (name === 'FirmwareUpload') {
|
|
1143
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport]
|
|
1105
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Firmware upload transport configured', {
|
|
1144
1106
|
packetCapacity: FIRMWARE_UPLOAD_WRITE_PACKET_CAPACITY,
|
|
1145
1107
|
burstSize: FIRMWARE_UPLOAD_WRITE_BURST_SIZE,
|
|
1146
1108
|
pauseMs: FIRMWARE_UPLOAD_WRITE_PAUSE_MS,
|
|
@@ -1229,7 +1191,6 @@ class ReactNativeBleTransport {
|
|
|
1229
1191
|
if (typeof response !== 'string') {
|
|
1230
1192
|
throw new Error('Returning data is not string.');
|
|
1231
1193
|
}
|
|
1232
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('receive data: ', response);
|
|
1233
1194
|
const jsonData = ProtocolV1.decodeMessage(messages, response);
|
|
1234
1195
|
return check.call(jsonData);
|
|
1235
1196
|
}
|
|
@@ -1257,7 +1218,6 @@ class ReactNativeBleTransport {
|
|
|
1257
1218
|
disconnect(session) {
|
|
1258
1219
|
var _a, _b, _c, _d, _e;
|
|
1259
1220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1260
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native transport resetSession: ', session);
|
|
1261
1221
|
yield this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
|
|
1262
1222
|
const transport = transportCache[session];
|
|
1263
1223
|
if (transport === null || transport === void 0 ? void 0 : transport.disconnectSubscription) {
|
|
@@ -1350,14 +1310,22 @@ class ReactNativeBleTransport {
|
|
|
1350
1310
|
if (expectedProtocol === 'V1') {
|
|
1351
1311
|
if (yield this.probeProtocolV1(uuid)) {
|
|
1352
1312
|
this.deviceProtocol.set(uuid, 'V1');
|
|
1353
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(
|
|
1313
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1314
|
+
deviceId: uuid,
|
|
1315
|
+
protocol: 'V1',
|
|
1316
|
+
source: 'expected',
|
|
1317
|
+
});
|
|
1354
1318
|
return 'V1';
|
|
1355
1319
|
}
|
|
1356
1320
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1357
1321
|
}
|
|
1358
1322
|
if (expectedProtocol === 'V2') {
|
|
1359
1323
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1360
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(
|
|
1324
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1325
|
+
deviceId: uuid,
|
|
1326
|
+
protocol: 'V2',
|
|
1327
|
+
source: 'expected',
|
|
1328
|
+
});
|
|
1361
1329
|
return 'V2';
|
|
1362
1330
|
}
|
|
1363
1331
|
const probeOrder = protocolHint === 'V2' || this.deviceProtocol.get(uuid) === 'V2' ? ['V2', 'V1'] : ['V1', 'V2'];
|
|
@@ -1369,7 +1337,11 @@ class ReactNativeBleTransport {
|
|
|
1369
1337
|
const detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
|
|
1370
1338
|
if (detected) {
|
|
1371
1339
|
this.deviceProtocol.set(uuid, protocol);
|
|
1372
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(
|
|
1340
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1341
|
+
deviceId: uuid,
|
|
1342
|
+
protocol,
|
|
1343
|
+
source: 'probe',
|
|
1344
|
+
});
|
|
1373
1345
|
return protocol;
|
|
1374
1346
|
}
|
|
1375
1347
|
}
|
|
@@ -1537,7 +1509,7 @@ class ReactNativeBleTransport {
|
|
|
1537
1509
|
}
|
|
1538
1510
|
});
|
|
1539
1511
|
}
|
|
1540
|
-
writeProtocolV2Frame(transport, frame
|
|
1512
|
+
writeProtocolV2Frame(transport, frame) {
|
|
1541
1513
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1542
1514
|
const tuning = getProtocolV2BleTuning();
|
|
1543
1515
|
const packetCapacity = resolveProtocolV2PacketCapacity({
|
|
@@ -1546,28 +1518,10 @@ class ReactNativeBleTransport {
|
|
|
1546
1518
|
androidPacketLength: tuning.androidPacketLength,
|
|
1547
1519
|
mtu: reactNative.Platform.OS === 'android' ? transport.mtuSize : undefined,
|
|
1548
1520
|
});
|
|
1549
|
-
const writeWithResponse = !!(options === null || options === void 0 ? void 0 : options.writeWithResponse) || (!!(options === null || options === void 0 ? void 0 : options.highVolume) && tuning.highVolumeWriteWithResponse);
|
|
1550
|
-
const writeMode = resolveBleWriteMode(transport.writeCharacteristic, writeWithResponse ? 'withResponse' : 'withoutResponse');
|
|
1551
|
-
const shouldThrottle = !!(options === null || options === void 0 ? void 0 : options.highVolume) && writeMode === 'withoutResponse';
|
|
1552
|
-
let packetsWritten = 0;
|
|
1553
1521
|
for (let offset = 0; offset < frame.length; offset += packetCapacity) {
|
|
1554
1522
|
const chunk = frame.slice(offset, offset + packetCapacity);
|
|
1555
1523
|
const base64 = buffer.Buffer.from(chunk).toString('base64');
|
|
1556
|
-
|
|
1557
|
-
yield transport.writeCharacteristic.writeWithResponse(base64);
|
|
1558
|
-
}
|
|
1559
|
-
else {
|
|
1560
|
-
yield transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1561
|
-
}
|
|
1562
|
-
packetsWritten += 1;
|
|
1563
|
-
if (shouldThrottle &&
|
|
1564
|
-
packetsWritten % tuning.highVolumeWriteBurstSize === 0 &&
|
|
1565
|
-
offset + packetCapacity < frame.length) {
|
|
1566
|
-
yield delay(tuning.highVolumeWritePauseMs);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
if (shouldThrottle) {
|
|
1570
|
-
yield delay(tuning.highVolumeWriteFlushDelayMs);
|
|
1524
|
+
yield transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1571
1525
|
}
|
|
1572
1526
|
});
|
|
1573
1527
|
}
|
|
@@ -1581,12 +1535,10 @@ class ReactNativeBleTransport {
|
|
|
1581
1535
|
const highVolumeWrite = transport.LogBlockCommand.has(name);
|
|
1582
1536
|
if (highVolumeWrite) {
|
|
1583
1537
|
const tuning = getProtocolV2BleTuning();
|
|
1584
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 high-volume write
|
|
1538
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 high-volume write configured', {
|
|
1539
|
+
name,
|
|
1540
|
+
writeMode: 'withoutResponse',
|
|
1585
1541
|
packetCapacity: reactNative.Platform.OS === 'ios' ? tuning.iosPacketLength : tuning.androidPacketLength,
|
|
1586
|
-
burstSize: tuning.highVolumeWriteBurstSize,
|
|
1587
|
-
pauseMs: tuning.highVolumeWritePauseMs,
|
|
1588
|
-
flushDelayMs: tuning.highVolumeWriteFlushDelayMs,
|
|
1589
|
-
writeWithResponse: tuning.highVolumeWriteWithResponse,
|
|
1590
1542
|
});
|
|
1591
1543
|
}
|
|
1592
1544
|
try {
|
|
@@ -1616,12 +1568,10 @@ class ReactNativeBleTransport {
|
|
|
1616
1568
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1617
1569
|
this.resetProtocolV2Frames(uuid);
|
|
1618
1570
|
},
|
|
1619
|
-
writeFrame: (frame
|
|
1571
|
+
writeFrame: (frame) => __awaiter(this, void 0, void 0, function* () {
|
|
1620
1572
|
assertCurrentGeneration();
|
|
1621
1573
|
const currentTransport = this.getCachedTransport(uuid);
|
|
1622
|
-
yield this.writeProtocolV2Frame(currentTransport, frame
|
|
1623
|
-
highVolume: context.highVolume,
|
|
1624
|
-
});
|
|
1574
|
+
yield this.writeProtocolV2Frame(currentTransport, frame);
|
|
1625
1575
|
}),
|
|
1626
1576
|
readFrame: () => __awaiter(this, void 0, void 0, function* () {
|
|
1627
1577
|
assertCurrentGeneration();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribeBleOn.d.ts","sourceRoot":"","sources":["../src/subscribeBleOn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAgB,aAAa,kBAAc,QAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"subscribeBleOn.d.ts","sourceRoot":"","sources":["../src/subscribeBleOn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAgB,aAAa,kBAAc,QAAQ,IAAI,CAmB9E,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
2
|
+
export declare function createTransportCallLog(name: string, protocol: ProtocolType, data: Record<string, unknown>): {
|
|
3
|
+
name: string;
|
|
4
|
+
protocol: ProtocolType;
|
|
5
|
+
file_name: unknown;
|
|
6
|
+
hash: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
name: string;
|
|
9
|
+
protocol: ProtocolType;
|
|
10
|
+
file_name?: undefined;
|
|
11
|
+
hash?: undefined;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=transportLog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transportLog.d.ts","sourceRoot":"","sources":["../src/transportLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;EAY9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.12",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"lint:fix": "eslint . --fix"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@onekeyfe/hd-core": "1.2.0-alpha.
|
|
23
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
22
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.12",
|
|
23
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.12",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.12",
|
|
25
25
|
"@onekeyfe/react-native-ble-utils": "^0.1.4",
|
|
26
26
|
"react-native-ble-plx": "3.5.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "3601e8003c96a2a4ca7856e865d16f48c0c5b758"
|
|
29
29
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hasWritableCapability,
|
|
3
|
-
resolveBleWriteMode,
|
|
4
|
-
resolveProtocolV2PacketCapacity,
|
|
5
|
-
} from '../bleStrategy';
|
|
1
|
+
import { hasWritableCapability, resolveProtocolV2PacketCapacity } from '../bleStrategy';
|
|
6
2
|
|
|
7
3
|
describe('React Native BLE strategy', () => {
|
|
8
4
|
test('accepts writeWithoutResponse-only characteristics', () => {
|
|
@@ -12,7 +8,6 @@ describe('React Native BLE strategy', () => {
|
|
|
12
8
|
};
|
|
13
9
|
|
|
14
10
|
expect(hasWritableCapability(characteristic)).toBe(true);
|
|
15
|
-
expect(resolveBleWriteMode(characteristic)).toBe('withoutResponse');
|
|
16
11
|
});
|
|
17
12
|
|
|
18
13
|
test('falls back to Android default ATT payload when MTU is unavailable', () => {
|
|
@@ -107,28 +107,27 @@ const createHarness = () => {
|
|
|
107
107
|
return { remove: jest.fn() };
|
|
108
108
|
}),
|
|
109
109
|
};
|
|
110
|
+
const handleWrite = (base64: string) => {
|
|
111
|
+
const frame = Buffer.from(base64, 'base64');
|
|
112
|
+
sentSeqs.push(frame[6]);
|
|
113
|
+
if (shouldRespond) {
|
|
114
|
+
const response = ProtocolV2.encodeFrame(
|
|
115
|
+
schemas,
|
|
116
|
+
'Success',
|
|
117
|
+
{ message: 'ok' },
|
|
118
|
+
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
119
|
+
);
|
|
120
|
+
notifyCallback?.(null, { value: Buffer.from(response).toString('base64') });
|
|
121
|
+
}
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
};
|
|
110
124
|
const writeCharacteristic = {
|
|
111
125
|
uuid: '0002',
|
|
112
126
|
deviceID: uuid,
|
|
113
127
|
isWritableWithResponse: true,
|
|
114
128
|
isWritableWithoutResponse: true,
|
|
115
|
-
writeWithResponse: jest.fn(
|
|
116
|
-
|
|
117
|
-
sentSeqs.push(frame[6]);
|
|
118
|
-
if (shouldRespond) {
|
|
119
|
-
const response = ProtocolV2.encodeFrame(
|
|
120
|
-
schemas,
|
|
121
|
-
'Success',
|
|
122
|
-
{ message: 'ok' },
|
|
123
|
-
{ router: PROTOCOL_V2_CHANNEL_BLE_UART }
|
|
124
|
-
);
|
|
125
|
-
notifyCallback?.(null, { value: Buffer.from(response).toString('base64') });
|
|
126
|
-
}
|
|
127
|
-
return Promise.resolve();
|
|
128
|
-
}),
|
|
129
|
-
writeWithoutResponse: jest.fn(async (base64: string) => {
|
|
130
|
-
await writeCharacteristic.writeWithResponse(base64);
|
|
131
|
-
}),
|
|
129
|
+
writeWithResponse: jest.fn(handleWrite),
|
|
130
|
+
writeWithoutResponse: jest.fn(handleWrite),
|
|
132
131
|
};
|
|
133
132
|
const device = {
|
|
134
133
|
id: uuid,
|
|
@@ -156,6 +155,7 @@ const createHarness = () => {
|
|
|
156
155
|
transport,
|
|
157
156
|
uuid,
|
|
158
157
|
sentSeqs,
|
|
158
|
+
writeCharacteristic,
|
|
159
159
|
setShouldRespond(value: boolean) {
|
|
160
160
|
shouldRespond = value;
|
|
161
161
|
},
|
|
@@ -208,14 +208,20 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
208
208
|
await transport.release(uuid, true);
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
-
test('
|
|
212
|
-
const { transport, uuid } = createHarness();
|
|
213
|
-
const writeSpy = jest.spyOn(transport as any, 'writeProtocolV2Frame');
|
|
211
|
+
test('uses withoutResponse for normal and high-volume calls', async () => {
|
|
212
|
+
const { transport, uuid, writeCharacteristic } = createHarness();
|
|
214
213
|
|
|
215
214
|
await transport.acquire({ uuid });
|
|
216
|
-
|
|
215
|
+
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(1);
|
|
216
|
+
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
217
|
+
|
|
218
|
+
await transport.call(uuid, 'Ping', { message: 'normal' });
|
|
219
|
+
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(2);
|
|
220
|
+
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
217
221
|
|
|
218
|
-
|
|
222
|
+
await transport.call(uuid, 'FileWrite', {});
|
|
223
|
+
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledTimes(3);
|
|
224
|
+
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
219
225
|
await transport.release(uuid, true);
|
|
220
226
|
});
|
|
221
227
|
|
package/src/bleStrategy.ts
CHANGED
|
@@ -7,35 +7,10 @@ export type BleWriteCapability = {
|
|
|
7
7
|
isWritableWithoutResponse?: boolean | null;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export type BleWriteMode = 'withResponse' | 'withoutResponse';
|
|
11
|
-
|
|
12
10
|
export function hasWritableCapability(characteristic: BleWriteCapability) {
|
|
13
11
|
return !!(characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse);
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export function resolveBleWriteMode(
|
|
17
|
-
characteristic: BleWriteCapability,
|
|
18
|
-
preferredMode: BleWriteMode = 'withoutResponse'
|
|
19
|
-
): BleWriteMode {
|
|
20
|
-
if (preferredMode === 'withoutResponse' && characteristic.isWritableWithoutResponse) {
|
|
21
|
-
return 'withoutResponse';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (preferredMode === 'withResponse' && characteristic.isWritableWithResponse) {
|
|
25
|
-
return 'withResponse';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (characteristic.isWritableWithoutResponse) {
|
|
29
|
-
return 'withoutResponse';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (characteristic.isWritableWithResponse) {
|
|
33
|
-
return 'withResponse';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return preferredMode;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
14
|
export function resolveProtocolV2PacketCapacity({
|
|
40
15
|
platform,
|
|
41
16
|
iosPacketLength = IOS_PACKET_LENGTH,
|
package/src/index.ts
CHANGED
|
@@ -23,11 +23,7 @@ import transport, {
|
|
|
23
23
|
import { ERRORS, HardwareErrorCode, createDeferred, isOnekeyDevice } from '@onekeyfe/hd-shared';
|
|
24
24
|
|
|
25
25
|
import { getConnectedDeviceIds, onDeviceBondState, pairDevice } from './BleManager';
|
|
26
|
-
import {
|
|
27
|
-
hasWritableCapability,
|
|
28
|
-
resolveBleWriteMode,
|
|
29
|
-
resolveProtocolV2PacketCapacity,
|
|
30
|
-
} from './bleStrategy';
|
|
26
|
+
import { hasWritableCapability, resolveProtocolV2PacketCapacity } from './bleStrategy';
|
|
31
27
|
import { subscribeBleOn } from './subscribeBleOn';
|
|
32
28
|
import {
|
|
33
29
|
ANDROID_PACKET_LENGTH,
|
|
@@ -41,6 +37,7 @@ import { isHeaderChunk } from './utils/validateNotify';
|
|
|
41
37
|
import BleTransport from './BleTransport';
|
|
42
38
|
import timer from './utils/timer';
|
|
43
39
|
import { bleLogger, setBleLogger } from './logger';
|
|
40
|
+
import { createTransportCallLog } from './transportLog';
|
|
44
41
|
|
|
45
42
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
46
43
|
import type { Characteristic, Device, Subscription } from 'react-native-ble-plx';
|
|
@@ -112,17 +109,9 @@ const PROTOCOL_V2_PROBE_TIMEOUT_MS = 10_000;
|
|
|
112
109
|
const DEVICE_SCAN_TIMEOUT_MS = 8000;
|
|
113
110
|
const IOS_NOTIFY_READY_DELAY_MS = 150;
|
|
114
111
|
const ANDROID_NOTIFY_READY_DELAY_MS = 300;
|
|
115
|
-
const HIGH_VOLUME_WRITE_BURST_SIZE = Platform.OS === 'ios' ? 4 : 6;
|
|
116
|
-
const HIGH_VOLUME_WRITE_PAUSE_MS = Platform.OS === 'ios' ? 6 : 2;
|
|
117
|
-
const HIGH_VOLUME_WRITE_FLUSH_DELAY_MS = Platform.OS === 'ios' ? 20 : 8;
|
|
118
|
-
|
|
119
112
|
export type ProtocolV2BleTuning = {
|
|
120
113
|
iosPacketLength?: number;
|
|
121
114
|
androidPacketLength?: number;
|
|
122
|
-
highVolumeWriteBurstSize?: number;
|
|
123
|
-
highVolumeWritePauseMs?: number;
|
|
124
|
-
highVolumeWriteFlushDelayMs?: number;
|
|
125
|
-
highVolumeWriteWithResponse?: boolean;
|
|
126
115
|
};
|
|
127
116
|
|
|
128
117
|
type ResolvedProtocolV2BleTuning = Required<ProtocolV2BleTuning>;
|
|
@@ -130,10 +119,6 @@ type ResolvedProtocolV2BleTuning = Required<ProtocolV2BleTuning>;
|
|
|
130
119
|
const DEFAULT_PROTOCOL_V2_BLE_TUNING: ResolvedProtocolV2BleTuning = {
|
|
131
120
|
iosPacketLength: IOS_PACKET_LENGTH,
|
|
132
121
|
androidPacketLength: ANDROID_PACKET_LENGTH,
|
|
133
|
-
highVolumeWriteBurstSize: HIGH_VOLUME_WRITE_BURST_SIZE,
|
|
134
|
-
highVolumeWritePauseMs: HIGH_VOLUME_WRITE_PAUSE_MS,
|
|
135
|
-
highVolumeWriteFlushDelayMs: HIGH_VOLUME_WRITE_FLUSH_DELAY_MS,
|
|
136
|
-
highVolumeWriteWithResponse: false,
|
|
137
122
|
};
|
|
138
123
|
|
|
139
124
|
let protocolV2BleTuning: ResolvedProtocolV2BleTuning = { ...DEFAULT_PROTOCOL_V2_BLE_TUNING };
|
|
@@ -154,27 +139,13 @@ export function configureProtocolV2BleTuning(tuning: ProtocolV2BleTuning = {}) {
|
|
|
154
139
|
tuning.androidPacketLength,
|
|
155
140
|
protocolV2BleTuning.androidPacketLength
|
|
156
141
|
),
|
|
157
|
-
highVolumeWriteBurstSize: normalizePositiveInteger(
|
|
158
|
-
tuning.highVolumeWriteBurstSize,
|
|
159
|
-
protocolV2BleTuning.highVolumeWriteBurstSize
|
|
160
|
-
),
|
|
161
|
-
highVolumeWritePauseMs: normalizePositiveInteger(
|
|
162
|
-
tuning.highVolumeWritePauseMs,
|
|
163
|
-
protocolV2BleTuning.highVolumeWritePauseMs
|
|
164
|
-
),
|
|
165
|
-
highVolumeWriteFlushDelayMs: normalizePositiveInteger(
|
|
166
|
-
tuning.highVolumeWriteFlushDelayMs,
|
|
167
|
-
protocolV2BleTuning.highVolumeWriteFlushDelayMs
|
|
168
|
-
),
|
|
169
|
-
highVolumeWriteWithResponse:
|
|
170
|
-
tuning.highVolumeWriteWithResponse ?? protocolV2BleTuning.highVolumeWriteWithResponse,
|
|
171
142
|
};
|
|
172
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
143
|
+
Log?.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
|
|
173
144
|
}
|
|
174
145
|
|
|
175
146
|
export function resetProtocolV2BleTuning() {
|
|
176
147
|
protocolV2BleTuning = { ...DEFAULT_PROTOCOL_V2_BLE_TUNING };
|
|
177
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
148
|
+
Log?.debug('[ReactNativeBleTransport] BLE tuning reset', protocolV2BleTuning);
|
|
178
149
|
}
|
|
179
150
|
|
|
180
151
|
export function getProtocolV2BleTuning() {
|
|
@@ -223,9 +194,10 @@ const requestAndroidMtu = async (device: Device) => {
|
|
|
223
194
|
|
|
224
195
|
try {
|
|
225
196
|
const mtuDevice = await device.requestMTU(ANDROID_REQUEST_MTU);
|
|
226
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
197
|
+
Log?.debug('[ReactNativeBleTransport] MTU configured', {
|
|
198
|
+
deviceId: device.id,
|
|
227
199
|
requested: ANDROID_REQUEST_MTU,
|
|
228
|
-
|
|
200
|
+
actual: mtuDevice.mtu,
|
|
229
201
|
});
|
|
230
202
|
return mtuDevice;
|
|
231
203
|
} catch (error) {
|
|
@@ -343,7 +315,6 @@ export default class ReactNativeBleTransport {
|
|
|
343
315
|
this.protocolV2Links
|
|
344
316
|
.invalidateAllLinks('Protocol V2 schema reconfigured')
|
|
345
317
|
.catch(error => Log?.debug('Protocol V2 schema link cleanup failed:', error));
|
|
346
|
-
Log?.debug('[ReactNativeBleTransport] Protocol V2 schema configured');
|
|
347
318
|
}
|
|
348
319
|
|
|
349
320
|
listen() {
|
|
@@ -581,7 +552,6 @@ export default class ReactNativeBleTransport {
|
|
|
581
552
|
},
|
|
582
553
|
(error, device) => {
|
|
583
554
|
if (error) {
|
|
584
|
-
Log?.debug('ble scan manager: ', blePlxManager);
|
|
585
555
|
Log?.debug('ble scan error: ', error);
|
|
586
556
|
if (
|
|
587
557
|
[BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(
|
|
@@ -609,29 +579,8 @@ export default class ReactNativeBleTransport {
|
|
|
609
579
|
isOnekeyDevice(device?.name ?? null, device?.id) ||
|
|
610
580
|
isOnekeyDevice(device?.localName ?? null, device?.id) ||
|
|
611
581
|
hasKnownOneKeyService(device);
|
|
612
|
-
const shouldTraceCandidate =
|
|
613
|
-
!!displayName && /onekey|bixinkey|pro\s*2|pro\b|touch|^k\d|^t\d/i.test(displayName);
|
|
614
|
-
|
|
615
|
-
if (shouldTraceCandidate) {
|
|
616
|
-
Log?.debug('[ReactNativeBleTransport] scan candidate', {
|
|
617
|
-
name: device?.name,
|
|
618
|
-
localName: device?.localName,
|
|
619
|
-
id: device?.id,
|
|
620
|
-
serviceUUIDs: device?.serviceUUIDs,
|
|
621
|
-
accepted: isOneKey,
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
|
|
625
582
|
if (isOneKey) {
|
|
626
|
-
Log?.debug('search device start ======================');
|
|
627
|
-
const { name, localName, id, serviceUUIDs } = device ?? {};
|
|
628
|
-
Log?.debug(
|
|
629
|
-
`device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${
|
|
630
|
-
id ?? ''
|
|
631
|
-
}\nserviceUUIDs: ${(serviceUUIDs ?? []).join(',')}`
|
|
632
|
-
);
|
|
633
583
|
addDevice(device as unknown as Device);
|
|
634
|
-
Log?.debug('search device end ======================\n');
|
|
635
584
|
} else if (displayName && /\bpro\s*2\b/i.test(displayName)) {
|
|
636
585
|
Log?.debug('[ReactNativeBleTransport] Pro2-like BLE device was not accepted:', {
|
|
637
586
|
name: device?.name,
|
|
@@ -645,7 +594,6 @@ export default class ReactNativeBleTransport {
|
|
|
645
594
|
|
|
646
595
|
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
647
596
|
for (const device of devices) {
|
|
648
|
-
Log?.debug('search connected peripheral: ', device.id);
|
|
649
597
|
addDevice(device as unknown as Device);
|
|
650
598
|
}
|
|
651
599
|
});
|
|
@@ -662,6 +610,12 @@ export default class ReactNativeBleTransport {
|
|
|
662
610
|
name: displayName,
|
|
663
611
|
commType: 'ble',
|
|
664
612
|
} as IOneKeyDevice);
|
|
613
|
+
Log?.debug('[ReactNativeBleTransport] OneKey BLE device discovered', {
|
|
614
|
+
deviceId: device.id,
|
|
615
|
+
name: displayName,
|
|
616
|
+
serviceUUIDs: device.serviceUUIDs,
|
|
617
|
+
protocolHint,
|
|
618
|
+
});
|
|
665
619
|
}
|
|
666
620
|
};
|
|
667
621
|
|
|
@@ -1075,33 +1029,13 @@ export default class ReactNativeBleTransport {
|
|
|
1075
1029
|
`Device protocol has not been detected for ${uuid}`
|
|
1076
1030
|
);
|
|
1077
1031
|
}
|
|
1078
|
-
|
|
1079
|
-
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
1080
|
-
Log?.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', {
|
|
1081
|
-
file_name: data?.file_name,
|
|
1082
|
-
hash: data?.hash,
|
|
1083
|
-
});
|
|
1084
|
-
} else if (LogBlockCommand.has(name)) {
|
|
1085
|
-
Log?.debug('transport-react-native', 'call-', ' name: ', name, ' protocol: ', protocol);
|
|
1086
|
-
} else {
|
|
1087
|
-
Log?.debug(
|
|
1088
|
-
'transport-react-native',
|
|
1089
|
-
'call-',
|
|
1090
|
-
' name: ',
|
|
1091
|
-
name,
|
|
1092
|
-
' data: ',
|
|
1093
|
-
data,
|
|
1094
|
-
' protocol: ',
|
|
1095
|
-
protocol
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1032
|
+
Log?.debug('transport call', createTransportCallLog(name, protocol, data));
|
|
1098
1033
|
|
|
1099
1034
|
if (protocol === 'V2') {
|
|
1100
1035
|
return this.callProtocolV2(uuid, name, data, options);
|
|
1101
1036
|
}
|
|
1102
1037
|
|
|
1103
1038
|
const forceRun = name === 'Initialize' || name === 'Cancel';
|
|
1104
|
-
Log?.debug('transport-react-native call this.runPromise', this.runPromise);
|
|
1105
1039
|
if (this.runPromise && !forceRun) {
|
|
1106
1040
|
throw ERRORS.TypedError(HardwareErrorCode.TransportCallInProgress);
|
|
1107
1041
|
}
|
|
@@ -1199,14 +1133,13 @@ export default class ReactNativeBleTransport {
|
|
|
1199
1133
|
}
|
|
1200
1134
|
);
|
|
1201
1135
|
} else if (name === 'FirmwareUpload') {
|
|
1202
|
-
Log?.debug('[ReactNativeBleTransport]
|
|
1136
|
+
Log?.debug('[ReactNativeBleTransport] Firmware upload transport configured', {
|
|
1203
1137
|
packetCapacity: FIRMWARE_UPLOAD_WRITE_PACKET_CAPACITY,
|
|
1204
1138
|
burstSize: FIRMWARE_UPLOAD_WRITE_BURST_SIZE,
|
|
1205
1139
|
pauseMs: FIRMWARE_UPLOAD_WRITE_PAUSE_MS,
|
|
1206
1140
|
flushDelayMs: FIRMWARE_UPLOAD_WRITE_FLUSH_DELAY_MS,
|
|
1207
1141
|
maxRetries: FIRMWARE_UPLOAD_WRITE_MAX_RETRIES,
|
|
1208
1142
|
});
|
|
1209
|
-
|
|
1210
1143
|
await writeFirmwareUploadChunkedData(
|
|
1211
1144
|
buffers,
|
|
1212
1145
|
async data => {
|
|
@@ -1260,7 +1193,6 @@ export default class ReactNativeBleTransport {
|
|
|
1260
1193
|
for (const o of buffers) {
|
|
1261
1194
|
const outData = o.toString('base64');
|
|
1262
1195
|
// Upload resources on low-end phones may OOM
|
|
1263
|
-
// this.Log.debug('send hex strting: ', o.toString('hex'));
|
|
1264
1196
|
try {
|
|
1265
1197
|
await transport.writeCharacteristic.writeWithoutResponse(outData);
|
|
1266
1198
|
} catch (e) {
|
|
@@ -1298,7 +1230,6 @@ export default class ReactNativeBleTransport {
|
|
|
1298
1230
|
throw new Error('Returning data is not string.');
|
|
1299
1231
|
}
|
|
1300
1232
|
|
|
1301
|
-
Log?.debug('receive data: ', response);
|
|
1302
1233
|
const jsonData = ProtocolV1.decodeMessage(messages, response);
|
|
1303
1234
|
return check.call(jsonData);
|
|
1304
1235
|
} catch (e) {
|
|
@@ -1321,7 +1252,6 @@ export default class ReactNativeBleTransport {
|
|
|
1321
1252
|
}
|
|
1322
1253
|
|
|
1323
1254
|
async disconnect(session: string) {
|
|
1324
|
-
Log?.debug('transport-react-native transport resetSession: ', session);
|
|
1325
1255
|
await this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
|
|
1326
1256
|
const transport = transportCache[session];
|
|
1327
1257
|
|
|
@@ -1443,7 +1373,11 @@ export default class ReactNativeBleTransport {
|
|
|
1443
1373
|
if (expectedProtocol === 'V1') {
|
|
1444
1374
|
if (await this.probeProtocolV1(uuid)) {
|
|
1445
1375
|
this.deviceProtocol.set(uuid, 'V1');
|
|
1446
|
-
Log?.debug(
|
|
1376
|
+
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1377
|
+
deviceId: uuid,
|
|
1378
|
+
protocol: 'V1',
|
|
1379
|
+
source: 'expected',
|
|
1380
|
+
});
|
|
1447
1381
|
return 'V1';
|
|
1448
1382
|
}
|
|
1449
1383
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
@@ -1453,7 +1387,11 @@ export default class ReactNativeBleTransport {
|
|
|
1453
1387
|
// 免探测路径:调用方显式承诺该设备是 V2(例如固件升级重启后的重连场景,
|
|
1454
1388
|
// 上层已经探测过协议并通过 expectedProtocol 传回),这里不再重复探测。
|
|
1455
1389
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1456
|
-
Log?.debug(
|
|
1390
|
+
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1391
|
+
deviceId: uuid,
|
|
1392
|
+
protocol: 'V2',
|
|
1393
|
+
source: 'expected',
|
|
1394
|
+
});
|
|
1457
1395
|
return 'V2';
|
|
1458
1396
|
}
|
|
1459
1397
|
|
|
@@ -1473,7 +1411,11 @@ export default class ReactNativeBleTransport {
|
|
|
1473
1411
|
protocol === 'V1' ? await this.probeProtocolV1(uuid) : await this.probeProtocolV2(uuid);
|
|
1474
1412
|
if (detected) {
|
|
1475
1413
|
this.deviceProtocol.set(uuid, protocol);
|
|
1476
|
-
Log?.debug(
|
|
1414
|
+
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1415
|
+
deviceId: uuid,
|
|
1416
|
+
protocol,
|
|
1417
|
+
source: 'probe',
|
|
1418
|
+
});
|
|
1477
1419
|
return protocol;
|
|
1478
1420
|
}
|
|
1479
1421
|
}
|
|
@@ -1659,11 +1601,7 @@ export default class ReactNativeBleTransport {
|
|
|
1659
1601
|
}
|
|
1660
1602
|
}
|
|
1661
1603
|
|
|
1662
|
-
private async writeProtocolV2Frame(
|
|
1663
|
-
transport: BleTransport,
|
|
1664
|
-
frame: Uint8Array,
|
|
1665
|
-
options?: { highVolume?: boolean; writeWithResponse?: boolean }
|
|
1666
|
-
) {
|
|
1604
|
+
private async writeProtocolV2Frame(transport: BleTransport, frame: Uint8Array) {
|
|
1667
1605
|
const tuning = getProtocolV2BleTuning();
|
|
1668
1606
|
const packetCapacity = resolveProtocolV2PacketCapacity({
|
|
1669
1607
|
platform: Platform.OS,
|
|
@@ -1671,36 +1609,10 @@ export default class ReactNativeBleTransport {
|
|
|
1671
1609
|
androidPacketLength: tuning.androidPacketLength,
|
|
1672
1610
|
mtu: Platform.OS === 'android' ? transport.mtuSize : undefined,
|
|
1673
1611
|
});
|
|
1674
|
-
const writeWithResponse =
|
|
1675
|
-
!!options?.writeWithResponse || (!!options?.highVolume && tuning.highVolumeWriteWithResponse);
|
|
1676
|
-
const writeMode = resolveBleWriteMode(
|
|
1677
|
-
transport.writeCharacteristic,
|
|
1678
|
-
writeWithResponse ? 'withResponse' : 'withoutResponse'
|
|
1679
|
-
);
|
|
1680
|
-
const shouldThrottle = !!options?.highVolume && writeMode === 'withoutResponse';
|
|
1681
|
-
let packetsWritten = 0;
|
|
1682
|
-
|
|
1683
1612
|
for (let offset = 0; offset < frame.length; offset += packetCapacity) {
|
|
1684
1613
|
const chunk = frame.slice(offset, offset + packetCapacity);
|
|
1685
1614
|
const base64 = Buffer.from(chunk).toString('base64');
|
|
1686
|
-
|
|
1687
|
-
await transport.writeCharacteristic.writeWithResponse(base64);
|
|
1688
|
-
} else {
|
|
1689
|
-
await transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1690
|
-
}
|
|
1691
|
-
packetsWritten += 1;
|
|
1692
|
-
|
|
1693
|
-
if (
|
|
1694
|
-
shouldThrottle &&
|
|
1695
|
-
packetsWritten % tuning.highVolumeWriteBurstSize === 0 &&
|
|
1696
|
-
offset + packetCapacity < frame.length
|
|
1697
|
-
) {
|
|
1698
|
-
await delay(tuning.highVolumeWritePauseMs);
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
if (shouldThrottle) {
|
|
1703
|
-
await delay(tuning.highVolumeWriteFlushDelayMs);
|
|
1615
|
+
await transport.writeCharacteristic.writeWithoutResponse(base64);
|
|
1704
1616
|
}
|
|
1705
1617
|
}
|
|
1706
1618
|
|
|
@@ -1722,18 +1634,11 @@ export default class ReactNativeBleTransport {
|
|
|
1722
1634
|
|
|
1723
1635
|
if (highVolumeWrite) {
|
|
1724
1636
|
const tuning = getProtocolV2BleTuning();
|
|
1725
|
-
Log?.debug(
|
|
1726
|
-
'[ReactNativeBleTransport] Protocol V2 high-volume write uses throttled writeWithoutResponse:',
|
|
1637
|
+
Log?.debug('[ReactNativeBleTransport] Protocol V2 high-volume write configured', {
|
|
1727
1638
|
name,
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
burstSize: tuning.highVolumeWriteBurstSize,
|
|
1732
|
-
pauseMs: tuning.highVolumeWritePauseMs,
|
|
1733
|
-
flushDelayMs: tuning.highVolumeWriteFlushDelayMs,
|
|
1734
|
-
writeWithResponse: tuning.highVolumeWriteWithResponse,
|
|
1735
|
-
}
|
|
1736
|
-
);
|
|
1639
|
+
writeMode: 'withoutResponse',
|
|
1640
|
+
packetCapacity: Platform.OS === 'ios' ? tuning.iosPacketLength : tuning.androidPacketLength,
|
|
1641
|
+
});
|
|
1737
1642
|
}
|
|
1738
1643
|
|
|
1739
1644
|
try {
|
|
@@ -1767,12 +1672,10 @@ export default class ReactNativeBleTransport {
|
|
|
1767
1672
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
1768
1673
|
this.resetProtocolV2Frames(uuid);
|
|
1769
1674
|
},
|
|
1770
|
-
writeFrame: async (frame: Uint8Array
|
|
1675
|
+
writeFrame: async (frame: Uint8Array) => {
|
|
1771
1676
|
assertCurrentGeneration();
|
|
1772
1677
|
const currentTransport = this.getCachedTransport(uuid);
|
|
1773
|
-
await this.writeProtocolV2Frame(currentTransport, frame
|
|
1774
|
-
highVolume: context.highVolume,
|
|
1775
|
-
});
|
|
1678
|
+
await this.writeProtocolV2Frame(currentTransport, frame);
|
|
1776
1679
|
},
|
|
1777
1680
|
readFrame: async () => {
|
|
1778
1681
|
assertCurrentGeneration();
|
package/src/subscribeBleOn.ts
CHANGED
|
@@ -9,8 +9,6 @@ export const subscribeBleOn = (bleManager: BlePlxManager, ms = 1000): Promise<vo
|
|
|
9
9
|
let done = false;
|
|
10
10
|
|
|
11
11
|
const subscription = bleManager.onStateChange(state => {
|
|
12
|
-
console.log('ble state -> ', state);
|
|
13
|
-
|
|
14
12
|
if (state === 'PoweredOn') {
|
|
15
13
|
if (done) return;
|
|
16
14
|
clearTimeout();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
export function createTransportCallLog(
|
|
4
|
+
name: string,
|
|
5
|
+
protocol: ProtocolType,
|
|
6
|
+
data: Record<string, unknown>
|
|
7
|
+
) {
|
|
8
|
+
if (name === 'ResourceUpdate' || name === 'ResourceAck') {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
protocol,
|
|
12
|
+
file_name: data.file_name,
|
|
13
|
+
hash: data.hash,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return { name, protocol };
|
|
18
|
+
}
|