@onekeyfe/hd-transport-react-native 0.1.12 → 0.1.16
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -29
- package/package.json +4 -4
- package/src/index.ts +33 -29
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ declare class ReactNativeBleTransport {
|
|
|
16
16
|
stopped: boolean;
|
|
17
17
|
scanTimeout: number;
|
|
18
18
|
runPromise: Deferred<any> | null;
|
|
19
|
+
Log?: any;
|
|
19
20
|
constructor(options: TransportOptions);
|
|
20
|
-
init(): void;
|
|
21
|
+
init(logger: any): void;
|
|
21
22
|
configure(signedData: any): void;
|
|
22
23
|
listen(): void;
|
|
23
24
|
getPlxManager(): Promise<BleManager>;
|
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,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAa1F,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmBjE,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAa1F,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmBjE,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;gBAEE,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG;IAIhB,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IAsET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IA+JpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA4D/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAcpB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA+EpE,IAAI;IAIJ,MAAM;CAOP"}
|
package/dist/index.js
CHANGED
|
@@ -188,7 +188,9 @@ class ReactNativeBleTransport {
|
|
|
188
188
|
this.runPromise = null;
|
|
189
189
|
this.scanTimeout = (_a = options.scanTimeout) !== null && _a !== void 0 ? _a : 3000;
|
|
190
190
|
}
|
|
191
|
-
init() {
|
|
191
|
+
init(logger) {
|
|
192
|
+
this.Log = logger;
|
|
193
|
+
}
|
|
192
194
|
configure(signedData) {
|
|
193
195
|
const messages = parseConfigure(signedData);
|
|
194
196
|
this.configured = true;
|
|
@@ -212,7 +214,7 @@ class ReactNativeBleTransport {
|
|
|
212
214
|
yield subscribeBleOn(blePlxManager);
|
|
213
215
|
}
|
|
214
216
|
catch (error) {
|
|
215
|
-
|
|
217
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
216
218
|
reject(error);
|
|
217
219
|
return;
|
|
218
220
|
}
|
|
@@ -221,8 +223,8 @@ class ReactNativeBleTransport {
|
|
|
221
223
|
}, (error, device) => {
|
|
222
224
|
var _a, _b;
|
|
223
225
|
if (error) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
+
this.Log.debug('ble scan manager: ', blePlxManager);
|
|
227
|
+
this.Log.debug('ble scan error: ', error);
|
|
226
228
|
if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
|
|
227
229
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
228
230
|
}
|
|
@@ -235,16 +237,16 @@ class ReactNativeBleTransport {
|
|
|
235
237
|
return;
|
|
236
238
|
}
|
|
237
239
|
if (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)) {
|
|
238
|
-
|
|
240
|
+
this.Log.debug('search device start ======================');
|
|
239
241
|
const { name, localName, id } = device !== null && device !== void 0 ? device : {};
|
|
240
|
-
|
|
242
|
+
this.Log.debug(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}`);
|
|
241
243
|
addDevice(device);
|
|
242
|
-
|
|
244
|
+
this.Log.debug('search device end ======================\n');
|
|
243
245
|
}
|
|
244
246
|
});
|
|
245
247
|
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
246
248
|
for (const device of devices) {
|
|
247
|
-
|
|
249
|
+
this.Log.debug('search connected peripheral: ', device.id);
|
|
248
250
|
addDevice(device);
|
|
249
251
|
}
|
|
250
252
|
});
|
|
@@ -269,7 +271,7 @@ class ReactNativeBleTransport {
|
|
|
269
271
|
}
|
|
270
272
|
let device = null;
|
|
271
273
|
if (transportCache[uuid]) {
|
|
272
|
-
|
|
274
|
+
this.Log.debug('transport not be released, will release: ', uuid);
|
|
273
275
|
yield this.release(uuid);
|
|
274
276
|
}
|
|
275
277
|
const blePlxManager = yield this.getPlxManager();
|
|
@@ -277,7 +279,7 @@ class ReactNativeBleTransport {
|
|
|
277
279
|
yield subscribeBleOn(blePlxManager);
|
|
278
280
|
}
|
|
279
281
|
catch (error) {
|
|
280
|
-
|
|
282
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
281
283
|
throw error;
|
|
282
284
|
}
|
|
283
285
|
if (!device) {
|
|
@@ -287,16 +289,16 @@ class ReactNativeBleTransport {
|
|
|
287
289
|
if (!device) {
|
|
288
290
|
const connectedDevice = yield blePlxManager.connectedDevices(getBluetoothServiceUuids());
|
|
289
291
|
const deviceFilter = connectedDevice.filter(device => device.id === uuid);
|
|
290
|
-
|
|
292
|
+
this.Log.debug(`found connected device count: ${deviceFilter.length}`);
|
|
291
293
|
[device] = deviceFilter;
|
|
292
294
|
}
|
|
293
295
|
if (!device) {
|
|
294
|
-
|
|
296
|
+
this.Log.debug('try to connect to device: ', uuid);
|
|
295
297
|
try {
|
|
296
298
|
device = yield blePlxManager.connectToDevice(uuid, connectOptions);
|
|
297
299
|
}
|
|
298
300
|
catch (e) {
|
|
299
|
-
|
|
301
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
300
302
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
301
303
|
e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
302
304
|
connectOptions = {};
|
|
@@ -311,12 +313,12 @@ class ReactNativeBleTransport {
|
|
|
311
313
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
|
|
312
314
|
}
|
|
313
315
|
if (!(yield device.isConnected())) {
|
|
314
|
-
|
|
316
|
+
this.Log.debug('not connected, try to connect to device: ', uuid);
|
|
315
317
|
try {
|
|
316
318
|
yield device.connect(connectOptions);
|
|
317
319
|
}
|
|
318
320
|
catch (e) {
|
|
319
|
-
|
|
321
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
320
322
|
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
321
323
|
e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
322
324
|
connectOptions = {};
|
|
@@ -345,7 +347,7 @@ class ReactNativeBleTransport {
|
|
|
345
347
|
break;
|
|
346
348
|
}
|
|
347
349
|
catch (e) {
|
|
348
|
-
|
|
350
|
+
this.Log.error(e);
|
|
349
351
|
}
|
|
350
352
|
}
|
|
351
353
|
}
|
|
@@ -385,7 +387,7 @@ class ReactNativeBleTransport {
|
|
|
385
387
|
transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic);
|
|
386
388
|
transportCache[uuid] = transport;
|
|
387
389
|
const disconnectSubscription = device.onDisconnected(() => {
|
|
388
|
-
|
|
390
|
+
this.Log.debug('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
|
|
389
391
|
this.release(uuid);
|
|
390
392
|
disconnectSubscription === null || disconnectSubscription === void 0 ? void 0 : disconnectSubscription.remove();
|
|
391
393
|
});
|
|
@@ -398,10 +400,10 @@ class ReactNativeBleTransport {
|
|
|
398
400
|
const subscription = characteristic.monitor((error, c) => {
|
|
399
401
|
var _a, _b, _c;
|
|
400
402
|
if (error) {
|
|
401
|
-
|
|
403
|
+
this.Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
402
404
|
if (this.runPromise) {
|
|
403
405
|
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyError, (_a = error.reason) !== null && _a !== void 0 ? _a : error.message));
|
|
404
|
-
|
|
406
|
+
this.Log.debug(': monitor notify error, and has unreleased Promise');
|
|
405
407
|
}
|
|
406
408
|
return;
|
|
407
409
|
}
|
|
@@ -425,12 +427,12 @@ class ReactNativeBleTransport {
|
|
|
425
427
|
}
|
|
426
428
|
}
|
|
427
429
|
catch (error) {
|
|
428
|
-
|
|
430
|
+
this.Log.debug('monitor data error: ', error);
|
|
429
431
|
(_c = this.runPromise) === null || _c === void 0 ? void 0 : _c.reject(error);
|
|
430
432
|
}
|
|
431
433
|
});
|
|
432
434
|
return () => {
|
|
433
|
-
|
|
435
|
+
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
434
436
|
subscription.remove();
|
|
435
437
|
};
|
|
436
438
|
}
|
|
@@ -465,7 +467,7 @@ class ReactNativeBleTransport {
|
|
|
465
467
|
}
|
|
466
468
|
this.runPromise = hdShared.createDeferred();
|
|
467
469
|
const messages = this._messages;
|
|
468
|
-
|
|
470
|
+
this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
|
|
469
471
|
const buffers = buildBuffers(messages, name, data);
|
|
470
472
|
if (name === 'FirmwareUpload') {
|
|
471
473
|
const packetCapacity = reactNative.Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
|
|
@@ -477,14 +479,14 @@ class ReactNativeBleTransport {
|
|
|
477
479
|
index += 1;
|
|
478
480
|
if (chunk.offset === packetCapacity || index >= buffers.length) {
|
|
479
481
|
chunk.reset();
|
|
480
|
-
|
|
482
|
+
this.Log.debug('send more packet hex strting: ', chunk.toString('hex'));
|
|
481
483
|
try {
|
|
482
484
|
yield transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
|
|
483
485
|
chunk = ByteBuffer__default["default"].allocate(packetCapacity);
|
|
484
486
|
}
|
|
485
487
|
catch (e) {
|
|
486
488
|
this.runPromise = null;
|
|
487
|
-
|
|
489
|
+
this.Log.error('writeCharacteristic write error: ', e);
|
|
488
490
|
return;
|
|
489
491
|
}
|
|
490
492
|
}
|
|
@@ -493,7 +495,7 @@ class ReactNativeBleTransport {
|
|
|
493
495
|
else {
|
|
494
496
|
for (const o of buffers) {
|
|
495
497
|
const outData = o.toString('base64');
|
|
496
|
-
|
|
498
|
+
this.Log.debug('send hex strting: ', o.toString('hex'));
|
|
497
499
|
try {
|
|
498
500
|
yield transport.writeCharacteristic.writeWithoutResponse(outData);
|
|
499
501
|
}
|
|
@@ -502,7 +504,7 @@ class ReactNativeBleTransport {
|
|
|
502
504
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded);
|
|
503
505
|
}
|
|
504
506
|
this.runPromise = null;
|
|
505
|
-
|
|
507
|
+
this.Log.debug('writeCharacteristic write error: ', e);
|
|
506
508
|
return;
|
|
507
509
|
}
|
|
508
510
|
}
|
|
@@ -512,12 +514,12 @@ class ReactNativeBleTransport {
|
|
|
512
514
|
if (typeof response !== 'string') {
|
|
513
515
|
throw new Error('Returning data is not string.');
|
|
514
516
|
}
|
|
515
|
-
|
|
517
|
+
this.Log.debug('receive data: ', response);
|
|
516
518
|
const jsonData = receiveOne(messages, response);
|
|
517
519
|
return check.call(jsonData);
|
|
518
520
|
}
|
|
519
521
|
catch (e) {
|
|
520
|
-
|
|
522
|
+
this.Log.error('call error: ', e);
|
|
521
523
|
return e;
|
|
522
524
|
}
|
|
523
525
|
finally {
|
|
@@ -529,7 +531,7 @@ class ReactNativeBleTransport {
|
|
|
529
531
|
this.stopped = true;
|
|
530
532
|
}
|
|
531
533
|
cancel() {
|
|
532
|
-
|
|
534
|
+
this.Log.debug('transport-react-native canceled');
|
|
533
535
|
if (this.runPromise) ;
|
|
534
536
|
this.runPromise = null;
|
|
535
537
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "^0.1.
|
|
24
|
-
"@onekeyfe/hd-transport": "^0.1.
|
|
23
|
+
"@onekeyfe/hd-shared": "^0.1.16",
|
|
24
|
+
"@onekeyfe/hd-transport": "^0.1.16",
|
|
25
25
|
"react-native-ble-manager": "^8.1.0",
|
|
26
26
|
"react-native-ble-plx": "^2.0.3"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "e87fdbab30d6daa4f32e28259bd221d75b5d6aad"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -54,11 +54,15 @@ export default class ReactNativeBleTransport {
|
|
|
54
54
|
|
|
55
55
|
runPromise: Deferred<any> | null = null;
|
|
56
56
|
|
|
57
|
+
Log?: any;
|
|
58
|
+
|
|
57
59
|
constructor(options: TransportOptions) {
|
|
58
60
|
this.scanTimeout = options.scanTimeout ?? 3000;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
init() {
|
|
63
|
+
init(logger: any) {
|
|
64
|
+
this.Log = logger;
|
|
65
|
+
}
|
|
62
66
|
|
|
63
67
|
configure(signedData: any) {
|
|
64
68
|
const messages = parseConfigure(signedData);
|
|
@@ -90,7 +94,7 @@ export default class ReactNativeBleTransport {
|
|
|
90
94
|
try {
|
|
91
95
|
await subscribeBleOn(blePlxManager);
|
|
92
96
|
} catch (error) {
|
|
93
|
-
|
|
97
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
94
98
|
reject(error);
|
|
95
99
|
return;
|
|
96
100
|
}
|
|
@@ -102,8 +106,8 @@ export default class ReactNativeBleTransport {
|
|
|
102
106
|
},
|
|
103
107
|
(error, device) => {
|
|
104
108
|
if (error) {
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
this.Log.debug('ble scan manager: ', blePlxManager);
|
|
110
|
+
this.Log.debug('ble scan error: ', error);
|
|
107
111
|
if (
|
|
108
112
|
[BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(
|
|
109
113
|
error.errorCode
|
|
@@ -119,22 +123,22 @@ export default class ReactNativeBleTransport {
|
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
if (isOnekeyDevice(device?.name ?? null, device?.id)) {
|
|
122
|
-
|
|
126
|
+
this.Log.debug('search device start ======================');
|
|
123
127
|
|
|
124
128
|
const { name, localName, id } = device ?? {};
|
|
125
|
-
|
|
129
|
+
this.Log.debug(
|
|
126
130
|
`device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${id ?? ''}`
|
|
127
131
|
);
|
|
128
132
|
addDevice(device as unknown as Device);
|
|
129
133
|
|
|
130
|
-
|
|
134
|
+
this.Log.debug('search device end ======================\n');
|
|
131
135
|
}
|
|
132
136
|
}
|
|
133
137
|
);
|
|
134
138
|
|
|
135
139
|
getConnectedDeviceIds(getBluetoothServiceUuids()).then(devices => {
|
|
136
140
|
for (const device of devices) {
|
|
137
|
-
|
|
141
|
+
this.Log.debug('search connected peripheral: ', device.id);
|
|
138
142
|
addDevice(device as unknown as Device);
|
|
139
143
|
}
|
|
140
144
|
});
|
|
@@ -166,7 +170,7 @@ export default class ReactNativeBleTransport {
|
|
|
166
170
|
* If the transport is not released due to an exception operation
|
|
167
171
|
* it will be handled again here
|
|
168
172
|
*/
|
|
169
|
-
|
|
173
|
+
this.Log.debug('transport not be released, will release: ', uuid);
|
|
170
174
|
await this.release(uuid);
|
|
171
175
|
}
|
|
172
176
|
|
|
@@ -174,7 +178,7 @@ export default class ReactNativeBleTransport {
|
|
|
174
178
|
try {
|
|
175
179
|
await subscribeBleOn(blePlxManager);
|
|
176
180
|
} catch (error) {
|
|
177
|
-
|
|
181
|
+
this.Log.debug('subscribeBleOn error: ', error);
|
|
178
182
|
throw error;
|
|
179
183
|
}
|
|
180
184
|
|
|
@@ -186,16 +190,16 @@ export default class ReactNativeBleTransport {
|
|
|
186
190
|
if (!device) {
|
|
187
191
|
const connectedDevice = await blePlxManager.connectedDevices(getBluetoothServiceUuids());
|
|
188
192
|
const deviceFilter = connectedDevice.filter(device => device.id === uuid);
|
|
189
|
-
|
|
193
|
+
this.Log.debug(`found connected device count: ${deviceFilter.length}`);
|
|
190
194
|
[device] = deviceFilter;
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
if (!device) {
|
|
194
|
-
|
|
198
|
+
this.Log.debug('try to connect to device: ', uuid);
|
|
195
199
|
try {
|
|
196
200
|
device = await blePlxManager.connectToDevice(uuid, connectOptions);
|
|
197
201
|
} catch (e) {
|
|
198
|
-
|
|
202
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
199
203
|
if (
|
|
200
204
|
e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
|
|
201
205
|
e.errorCode === BleErrorCode.OperationCancelled
|
|
@@ -213,12 +217,12 @@ export default class ReactNativeBleTransport {
|
|
|
213
217
|
}
|
|
214
218
|
|
|
215
219
|
if (!(await device.isConnected())) {
|
|
216
|
-
|
|
220
|
+
this.Log.debug('not connected, try to connect to device: ', uuid);
|
|
217
221
|
|
|
218
222
|
try {
|
|
219
223
|
await device.connect(connectOptions);
|
|
220
224
|
} catch (e) {
|
|
221
|
-
|
|
225
|
+
this.Log.debug('try to connect to device has error: ', e);
|
|
222
226
|
if (
|
|
223
227
|
e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
|
|
224
228
|
e.errorCode === BleErrorCode.OperationCancelled
|
|
@@ -251,7 +255,7 @@ export default class ReactNativeBleTransport {
|
|
|
251
255
|
infos = getInfosForServiceUuid(serviceUuid, 'classic');
|
|
252
256
|
break;
|
|
253
257
|
} catch (e) {
|
|
254
|
-
|
|
258
|
+
this.Log.error(e);
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
}
|
|
@@ -303,7 +307,7 @@ export default class ReactNativeBleTransport {
|
|
|
303
307
|
transportCache[uuid] = transport;
|
|
304
308
|
|
|
305
309
|
const disconnectSubscription = device.onDisconnected(() => {
|
|
306
|
-
|
|
310
|
+
this.Log.debug('device disconnect: ', device?.id);
|
|
307
311
|
this.release(uuid);
|
|
308
312
|
disconnectSubscription?.remove();
|
|
309
313
|
});
|
|
@@ -316,7 +320,7 @@ export default class ReactNativeBleTransport {
|
|
|
316
320
|
let buffer: any[] = [];
|
|
317
321
|
const subscription = characteristic.monitor((error, c) => {
|
|
318
322
|
if (error) {
|
|
319
|
-
|
|
323
|
+
this.Log.debug(
|
|
320
324
|
`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${
|
|
321
325
|
error as unknown as string
|
|
322
326
|
}`
|
|
@@ -328,7 +332,7 @@ export default class ReactNativeBleTransport {
|
|
|
328
332
|
error.reason ?? error.message
|
|
329
333
|
)
|
|
330
334
|
);
|
|
331
|
-
|
|
335
|
+
this.Log.debug(': monitor notify error, and has unreleased Promise');
|
|
332
336
|
}
|
|
333
337
|
return;
|
|
334
338
|
}
|
|
@@ -360,13 +364,13 @@ export default class ReactNativeBleTransport {
|
|
|
360
364
|
this.runPromise?.resolve(value.toString('hex'));
|
|
361
365
|
}
|
|
362
366
|
} catch (error) {
|
|
363
|
-
|
|
367
|
+
this.Log.debug('monitor data error: ', error);
|
|
364
368
|
this.runPromise?.reject(error);
|
|
365
369
|
}
|
|
366
370
|
});
|
|
367
371
|
|
|
368
372
|
return () => {
|
|
369
|
-
|
|
373
|
+
this.Log.debug('remove characteristic monitor: ', characteristic.uuid);
|
|
370
374
|
subscription.remove();
|
|
371
375
|
};
|
|
372
376
|
}
|
|
@@ -405,7 +409,7 @@ export default class ReactNativeBleTransport {
|
|
|
405
409
|
|
|
406
410
|
this.runPromise = createDeferred();
|
|
407
411
|
const messages = this._messages;
|
|
408
|
-
|
|
412
|
+
this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
|
|
409
413
|
const buffers = buildBuffers(messages, name, data);
|
|
410
414
|
|
|
411
415
|
if (name === 'FirmwareUpload') {
|
|
@@ -418,13 +422,13 @@ export default class ReactNativeBleTransport {
|
|
|
418
422
|
index += 1;
|
|
419
423
|
if (chunk.offset === packetCapacity || index >= buffers.length) {
|
|
420
424
|
chunk.reset();
|
|
421
|
-
|
|
425
|
+
this.Log.debug('send more packet hex strting: ', chunk.toString('hex'));
|
|
422
426
|
try {
|
|
423
427
|
await transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
|
|
424
428
|
chunk = ByteBuffer.allocate(packetCapacity);
|
|
425
429
|
} catch (e) {
|
|
426
430
|
this.runPromise = null;
|
|
427
|
-
|
|
431
|
+
this.Log.error('writeCharacteristic write error: ', e);
|
|
428
432
|
return;
|
|
429
433
|
}
|
|
430
434
|
}
|
|
@@ -432,7 +436,7 @@ export default class ReactNativeBleTransport {
|
|
|
432
436
|
} else {
|
|
433
437
|
for (const o of buffers) {
|
|
434
438
|
const outData = o.toString('base64');
|
|
435
|
-
|
|
439
|
+
this.Log.debug('send hex strting: ', o.toString('hex'));
|
|
436
440
|
try {
|
|
437
441
|
await transport.writeCharacteristic.writeWithoutResponse(outData);
|
|
438
442
|
} catch (e) {
|
|
@@ -440,7 +444,7 @@ export default class ReactNativeBleTransport {
|
|
|
440
444
|
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded);
|
|
441
445
|
}
|
|
442
446
|
this.runPromise = null;
|
|
443
|
-
|
|
447
|
+
this.Log.debug('writeCharacteristic write error: ', e);
|
|
444
448
|
return;
|
|
445
449
|
}
|
|
446
450
|
}
|
|
@@ -453,11 +457,11 @@ export default class ReactNativeBleTransport {
|
|
|
453
457
|
throw new Error('Returning data is not string.');
|
|
454
458
|
}
|
|
455
459
|
|
|
456
|
-
|
|
460
|
+
this.Log.debug('receive data: ', response);
|
|
457
461
|
const jsonData = receiveOne(messages, response);
|
|
458
462
|
return check.call(jsonData);
|
|
459
463
|
} catch (e) {
|
|
460
|
-
|
|
464
|
+
this.Log.error('call error: ', e);
|
|
461
465
|
return e;
|
|
462
466
|
} finally {
|
|
463
467
|
this.runPromise = null;
|
|
@@ -469,7 +473,7 @@ export default class ReactNativeBleTransport {
|
|
|
469
473
|
}
|
|
470
474
|
|
|
471
475
|
cancel() {
|
|
472
|
-
|
|
476
|
+
this.Log.debug('transport-react-native canceled');
|
|
473
477
|
if (this.runPromise) {
|
|
474
478
|
// this.runPromise.reject(new Error('Transport_CallCanceled'));
|
|
475
479
|
}
|