@onekeyfe/hd-transport-react-native 1.0.20-alpha.2 → 1.0.20

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.
@@ -6,9 +6,6 @@ export default class BleTransport {
6
6
  writeCharacteristic: Characteristic;
7
7
  notifyCharacteristic: Characteristic;
8
8
  nofitySubscription?: () => void;
9
- static MAX_RETRIES: number;
10
- static RETRY_DELAY: number;
11
9
  constructor(device: Device, writeCharacteristic: Characteristic, notifyCharacteristic: Characteristic);
12
- writeWithRetry(data: string, retryCount?: number): Promise<void>;
13
10
  }
14
11
  //# sourceMappingURL=BleTransport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAgB,MAAM,gCAAgC,CAAC;AAMtF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,SAAM;IAEb,mBAAmB,EAAE,cAAc,CAAC;IAEpC,oBAAoB,EAAE,cAAc,CAAC;IAErC,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAEhC,MAAM,CAAC,WAAW,SAAK;IAEvB,MAAM,CAAC,WAAW,SAAQ;gBAGxB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,cAAc,EACnC,oBAAoB,EAAE,cAAc;IAehC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,SAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BzF"}
1
+ {"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,SAAM;IAEb,mBAAmB,EAAE,cAAc,CAAC;IAEpC,oBAAoB,EAAE,cAAc,CAAC;IAErC,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;gBAG9B,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,cAAc,EACnC,oBAAoB,EAAE,cAAc;CAQvC"}
package/dist/index.d.ts CHANGED
@@ -32,7 +32,7 @@ declare class ReactNativeBleTransport {
32
32
  }>;
33
33
  _monitorCharacteristic(characteristic: Characteristic): () => void;
34
34
  release(uuid: string): Promise<boolean>;
35
- call(uuid: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey>;
35
+ call(uuid: string, name: string, data: Record<string, unknown>): Promise<transport.MessageFromOneKey | undefined>;
36
36
  stop(): void;
37
37
  cancel(): void;
38
38
  }
@@ -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,gCAAgC,CAAC;AAExC,OAAO,SAAkD,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAoBjE,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;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;gBAEX,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY;IAKvC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IA6FT,OAAO,CAAC,KAAK,EAAE,eAAe;;;IAmNpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IAgF/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAwHpE,IAAI;IAIJ,MAAM;CAOP"}
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,gCAAgC,CAAC;AAExC,OAAO,SAAkD,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAoBjE,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;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;gBAEX,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY;IAKvC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IA6FT,OAAO,CAAC,KAAK,EAAE,eAAe;;;IA2MpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IAkF/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA+FpE,IAAI;IAIJ,MAAM;CAOP"}
package/dist/index.js CHANGED
@@ -7,7 +7,6 @@ var ByteBuffer = require('bytebuffer');
7
7
  var transport = require('@onekeyfe/hd-transport');
8
8
  var hdShared = require('@onekeyfe/hd-shared');
9
9
  var BleManager = require('react-native-ble-manager');
10
- var hdCore = require('@onekeyfe/hd-core');
11
10
 
12
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
12
 
@@ -159,7 +158,6 @@ const isHeaderChunk = (chunk) => {
159
158
  return false;
160
159
  };
161
160
 
162
- const Log = hdCore.getLogger(hdCore.LoggerNames.HdBleTransport);
163
161
  class BleTransport {
164
162
  constructor(device, writeCharacteristic, notifyCharacteristic) {
165
163
  this.mtuSize = 20;
@@ -169,37 +167,7 @@ class BleTransport {
169
167
  this.notifyCharacteristic = notifyCharacteristic;
170
168
  console.log(`BleTransport(${String(this.id)}) new instance`);
171
169
  }
172
- writeWithRetry(data, retryCount = BleTransport.MAX_RETRIES) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- try {
175
- yield this.writeCharacteristic.writeWithoutResponse(data);
176
- }
177
- catch (error) {
178
- Log === null || Log === void 0 ? void 0 : Log.debug(`Write retry attempt ${BleTransport.MAX_RETRIES - retryCount + 1}, error: ${error}`);
179
- if (retryCount > 0) {
180
- yield hdCore.wait(BleTransport.RETRY_DELAY);
181
- if (error.errorCode === reactNativeBlePlx.BleErrorCode.DeviceDisconnected ||
182
- error.errorCode === reactNativeBlePlx.BleErrorCode.CharacteristicNotFound) {
183
- try {
184
- yield this.device.connect();
185
- yield this.device.discoverAllServicesAndCharacteristics();
186
- }
187
- catch (e) {
188
- Log === null || Log === void 0 ? void 0 : Log.debug(`Connect or discoverAllServicesAndCharacteristics error: ${e}`);
189
- }
190
- }
191
- else {
192
- Log === null || Log === void 0 ? void 0 : Log.debug(`writeCharacteristic error: ${error}`);
193
- }
194
- return this.writeWithRetry(data, retryCount - 1);
195
- }
196
- throw error;
197
- }
198
- });
199
- }
200
170
  }
201
- BleTransport.MAX_RETRIES = 5;
202
- BleTransport.RETRY_DELAY = 2000;
203
171
 
204
172
  const { check, buildBuffers, receiveOne, parseConfigure } = transport__default["default"];
205
173
  const transportCache = {};
@@ -479,24 +447,14 @@ class ReactNativeBleTransport {
479
447
  });
480
448
  const disconnectSubscription = device.onDisconnected(() => {
481
449
  var _a;
482
- try {
483
- this.Log.debug('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
484
- (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit('device-disconnect', {
485
- name: device === null || device === void 0 ? void 0 : device.name,
486
- id: device === null || device === void 0 ? void 0 : device.id,
487
- connectId: device === null || device === void 0 ? void 0 : device.id,
488
- });
489
- if (this.runPromise) {
490
- this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError));
491
- }
492
- }
493
- catch (e) {
494
- this.Log.debug('device disconnect error: ', e);
495
- }
496
- finally {
497
- this.release(uuid);
498
- disconnectSubscription === null || disconnectSubscription === void 0 ? void 0 : disconnectSubscription.remove();
499
- }
450
+ this.Log.debug('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
451
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit('device-disconnect', {
452
+ name: device === null || device === void 0 ? void 0 : device.name,
453
+ id: device === null || device === void 0 ? void 0 : device.id,
454
+ connectId: device === null || device === void 0 ? void 0 : device.id,
455
+ });
456
+ this.release(uuid);
457
+ disconnectSubscription === null || disconnectSubscription === void 0 ? void 0 : disconnectSubscription.remove();
500
458
  });
501
459
  return { uuid };
502
460
  });
@@ -505,7 +463,7 @@ class ReactNativeBleTransport {
505
463
  let bufferLength = 0;
506
464
  let buffer$1 = [];
507
465
  const subscription = characteristic.monitor((error, c) => {
508
- var _a, _b, _c, _d, _e, _f, _g;
466
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
509
467
  if (error) {
510
468
  this.Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
511
469
  if (this.runPromise) {
@@ -519,12 +477,12 @@ class ReactNativeBleTransport {
519
477
  if (((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot write client characteristic config descriptor')) ||
520
478
  ((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('Cannot find client characteristic config descriptor')) ||
521
479
  ((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('The handle is invalid'))) {
522
- this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure));
480
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure, (_f = error.message) !== null && _f !== void 0 ? _f : error.reason));
523
481
  this.Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
524
482
  return;
525
483
  }
526
- this.runPromise.reject(hdShared.ERRORS.TypedError(ERROR));
527
- this.Log.debug(': monitor notify error, and has unreleased Promise', Error);
484
+ this.runPromise.reject(hdShared.ERRORS.TypedError(ERROR, (_g = error.reason) !== null && _g !== void 0 ? _g : error.message));
485
+ this.Log.debug(': monitor notify error, and has unreleased Promise');
528
486
  }
529
487
  return;
530
488
  }
@@ -544,12 +502,12 @@ class ReactNativeBleTransport {
544
502
  const value = buffer.Buffer.from(buffer$1);
545
503
  bufferLength = 0;
546
504
  buffer$1 = [];
547
- (_f = this.runPromise) === null || _f === void 0 ? void 0 : _f.resolve(value.toString('hex'));
505
+ (_h = this.runPromise) === null || _h === void 0 ? void 0 : _h.resolve(value.toString('hex'));
548
506
  }
549
507
  }
550
508
  catch (error) {
551
509
  this.Log.debug('monitor data error: ', error);
552
- (_g = this.runPromise) === null || _g === void 0 ? void 0 : _g.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError));
510
+ (_j = this.runPromise) === null || _j === void 0 ? void 0 : _j.reject(error);
553
511
  }
554
512
  });
555
513
  return () => {
@@ -599,42 +557,27 @@ class ReactNativeBleTransport {
599
557
  this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
600
558
  }
601
559
  const buffers = buildBuffers(messages, name, data);
602
- function writeChunkedData(buffers, writeFunction, onError) {
603
- return __awaiter(this, void 0, void 0, function* () {
604
- const packetCapacity = reactNative.Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
605
- let index = 0;
606
- let chunk = ByteBuffer__default["default"].allocate(packetCapacity);
607
- while (index < buffers.length) {
608
- const buffer = buffers[index].toBuffer();
609
- chunk.append(buffer);
610
- index += 1;
611
- if (chunk.offset === packetCapacity || index >= buffers.length) {
612
- chunk.reset();
613
- try {
614
- yield writeFunction(chunk.toString('base64'));
615
- chunk = ByteBuffer__default["default"].allocate(packetCapacity);
616
- }
617
- catch (e) {
618
- onError(e);
619
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError);
620
- }
560
+ if (name === 'FirmwareUpload' || name === 'EmmcFileWrite') {
561
+ const packetCapacity = reactNative.Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
562
+ let index = 0;
563
+ let chunk = ByteBuffer__default["default"].allocate(packetCapacity);
564
+ while (index < buffers.length) {
565
+ const buffer = buffers[index].toBuffer();
566
+ chunk.append(buffer);
567
+ index += 1;
568
+ if (chunk.offset === packetCapacity || index >= buffers.length) {
569
+ chunk.reset();
570
+ try {
571
+ yield transport$1.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
572
+ chunk = ByteBuffer__default["default"].allocate(packetCapacity);
573
+ }
574
+ catch (e) {
575
+ this.runPromise = null;
576
+ this.Log.error('writeCharacteristic write error: ', e);
577
+ return;
621
578
  }
622
579
  }
623
- });
624
- }
625
- if (name === 'EmmcFileWrite') {
626
- yield writeChunkedData(buffers, data => transport$1.writeWithRetry(data), e => {
627
- this.runPromise = null;
628
- this.Log.error('writeCharacteristic write error: ', e);
629
- });
630
- }
631
- else if (name === 'FirmwareUpload') {
632
- yield writeChunkedData(buffers, (data) => __awaiter(this, void 0, void 0, function* () {
633
- yield transport$1.writeCharacteristic.writeWithoutResponse(data);
634
- }), e => {
635
- this.runPromise = null;
636
- this.Log.error('writeCharacteristic write error: ', e);
637
- });
580
+ }
638
581
  }
639
582
  else {
640
583
  for (const o of buffers) {
@@ -648,12 +591,10 @@ class ReactNativeBleTransport {
648
591
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceDisconnected) {
649
592
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded);
650
593
  }
651
- else if (e.errorCode === reactNativeBlePlx.BleErrorCode.OperationStartFailed) {
594
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.OperationStartFailed) {
652
595
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, e.reason);
653
596
  }
654
- else {
655
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError);
656
- }
597
+ return;
657
598
  }
658
599
  }
659
600
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.0.20-alpha.2",
3
+ "version": "1.0.20",
4
4
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -19,10 +19,10 @@
19
19
  "lint:fix": "eslint . --fix"
20
20
  },
21
21
  "dependencies": {
22
- "@onekeyfe/hd-shared": "^1.0.20-alpha.2",
23
- "@onekeyfe/hd-transport": "^1.0.20-alpha.2",
22
+ "@onekeyfe/hd-shared": "^1.0.20",
23
+ "@onekeyfe/hd-transport": "^1.0.20",
24
24
  "@onekeyfe/react-native-ble-plx": "3.0.1",
25
25
  "react-native-ble-manager": "^8.1.0"
26
26
  },
27
- "gitHead": "11e08c519bfb9ca0a010cbf02d50e14acbd570ec"
27
+ "gitHead": "c1fd68371775203bf6ac57059c0a72eda6fa7fba"
28
28
  }
@@ -1,8 +1,4 @@
1
- import { Device, Characteristic, BleErrorCode } from '@onekeyfe/react-native-ble-plx';
2
- import { getLogger, LoggerNames, wait } from '@onekeyfe/hd-core';
3
- // import { wait } from '@onekeyfe/hd-core/src/utils';
4
-
5
- const Log = getLogger(LoggerNames.HdBleTransport);
1
+ import { Device, Characteristic } from '@onekeyfe/react-native-ble-plx';
6
2
 
7
3
  export default class BleTransport {
8
4
  id: string;
@@ -17,10 +13,6 @@ export default class BleTransport {
17
13
 
18
14
  nofitySubscription?: () => void;
19
15
 
20
- static MAX_RETRIES = 5;
21
-
22
- static RETRY_DELAY = 2000;
23
-
24
16
  constructor(
25
17
  device: Device,
26
18
  writeCharacteristic: Characteristic,
@@ -32,38 +24,4 @@ export default class BleTransport {
32
24
  this.notifyCharacteristic = notifyCharacteristic;
33
25
  console.log(`BleTransport(${String(this.id)}) new instance`);
34
26
  }
35
-
36
- /**
37
- * @description only for pro / touch , while upgrade firmware
38
- * @param data
39
- * @param retryCount
40
- * @returns
41
- */
42
- async writeWithRetry(data: string, retryCount = BleTransport.MAX_RETRIES): Promise<void> {
43
- try {
44
- await this.writeCharacteristic.writeWithoutResponse(data);
45
- } catch (error) {
46
- Log?.debug(
47
- `Write retry attempt ${BleTransport.MAX_RETRIES - retryCount + 1}, error: ${error}`
48
- );
49
- if (retryCount > 0) {
50
- await wait(BleTransport.RETRY_DELAY);
51
- if (
52
- error.errorCode === BleErrorCode.DeviceDisconnected ||
53
- error.errorCode === BleErrorCode.CharacteristicNotFound
54
- ) {
55
- try {
56
- await this.device.connect();
57
- await this.device.discoverAllServicesAndCharacteristics();
58
- } catch (e) {
59
- Log?.debug(`Connect or discoverAllServicesAndCharacteristics error: ${e}`);
60
- }
61
- } else {
62
- Log?.debug(`writeCharacteristic error: ${error}`);
63
- }
64
- return this.writeWithRetry(data, retryCount - 1);
65
- }
66
- throw error;
67
- }
68
- }
69
27
  }
package/src/index.ts CHANGED
@@ -374,22 +374,14 @@ export default class ReactNativeBleTransport {
374
374
  });
375
375
 
376
376
  const disconnectSubscription = device.onDisconnected(() => {
377
- try {
378
- this.Log.debug('device disconnect: ', device?.id);
379
- this.emitter?.emit('device-disconnect', {
380
- name: device?.name,
381
- id: device?.id,
382
- connectId: device?.id,
383
- });
384
- if (this.runPromise) {
385
- this.runPromise.reject(ERRORS.TypedError(HardwareErrorCode.BleConnectedError));
386
- }
387
- } catch (e) {
388
- this.Log.debug('device disconnect error: ', e);
389
- } finally {
390
- this.release(uuid);
391
- disconnectSubscription?.remove();
392
- }
377
+ this.Log.debug('device disconnect: ', device?.id);
378
+ this.emitter?.emit('device-disconnect', {
379
+ name: device?.name,
380
+ id: device?.id,
381
+ connectId: device?.id,
382
+ });
383
+ this.release(uuid);
384
+ disconnectSubscription?.remove();
393
385
  });
394
386
 
395
387
  return { uuid };
@@ -423,17 +415,19 @@ export default class ReactNativeBleTransport {
423
415
  error.reason?.includes('The handle is invalid')
424
416
  ) {
425
417
  this.runPromise.reject(
426
- ERRORS.TypedError(HardwareErrorCode.BleCharacteristicNotifyChangeFailure)
418
+ ERRORS.TypedError(
419
+ HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
420
+ error.message ?? error.reason
421
+ )
427
422
  );
428
423
  this.Log.debug(
429
424
  `${HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`
430
425
  );
431
426
  return;
432
427
  }
433
- this.runPromise.reject(ERRORS.TypedError(ERROR));
434
- this.Log.debug(': monitor notify error, and has unreleased Promise', Error);
428
+ this.runPromise.reject(ERRORS.TypedError(ERROR, error.reason ?? error.message));
429
+ this.Log.debug(': monitor notify error, and has unreleased Promise');
435
430
  }
436
-
437
431
  return;
438
432
  }
439
433
 
@@ -465,7 +459,7 @@ export default class ReactNativeBleTransport {
465
459
  }
466
460
  } catch (error) {
467
461
  this.Log.debug('monitor data error: ', error);
468
- this.runPromise?.reject(ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError));
462
+ this.runPromise?.reject(error);
469
463
  }
470
464
  });
471
465
 
@@ -522,55 +516,30 @@ export default class ReactNativeBleTransport {
522
516
  this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
523
517
  }
524
518
 
525
- const buffers = buildBuffers(messages, name, data) as Array<ByteBuffer>;
519
+ const buffers = buildBuffers(messages, name, data);
526
520
 
527
- async function writeChunkedData(
528
- buffers: ByteBuffer[],
529
- writeFunction: (data: string) => Promise<void>,
530
- onError: (e: any) => void
531
- ) {
521
+ if (name === 'FirmwareUpload' || name === 'EmmcFileWrite') {
532
522
  const packetCapacity = Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
533
523
  let index = 0;
534
524
  let chunk = ByteBuffer.allocate(packetCapacity);
535
-
536
525
  while (index < buffers.length) {
537
526
  const buffer = buffers[index].toBuffer();
538
527
  chunk.append(buffer);
539
528
  index += 1;
540
-
541
529
  if (chunk.offset === packetCapacity || index >= buffers.length) {
542
530
  chunk.reset();
531
+ // Upgrading Packet Logs, Too much content to ignore
532
+ // this.Log.debug('send more packet hex strting: ', chunk.toString('hex'));
543
533
  try {
544
- await writeFunction(chunk.toString('base64'));
534
+ await transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
545
535
  chunk = ByteBuffer.allocate(packetCapacity);
546
536
  } catch (e) {
547
- onError(e);
548
- throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError);
537
+ this.runPromise = null;
538
+ this.Log.error('writeCharacteristic write error: ', e);
539
+ return;
549
540
  }
550
541
  }
551
542
  }
552
- }
553
-
554
- if (name === 'EmmcFileWrite') {
555
- await writeChunkedData(
556
- buffers,
557
- data => transport.writeWithRetry(data),
558
- e => {
559
- this.runPromise = null;
560
- this.Log.error('writeCharacteristic write error: ', e);
561
- }
562
- );
563
- } else if (name === 'FirmwareUpload') {
564
- await writeChunkedData(
565
- buffers,
566
- async data => {
567
- await transport.writeCharacteristic.writeWithoutResponse(data);
568
- },
569
- e => {
570
- this.runPromise = null;
571
- this.Log.error('writeCharacteristic write error: ', e);
572
- }
573
- );
574
543
  } else {
575
544
  for (const o of buffers) {
576
545
  const outData = o.toString('base64');
@@ -583,11 +552,11 @@ export default class ReactNativeBleTransport {
583
552
  this.runPromise = null;
584
553
  if (e.errorCode === BleErrorCode.DeviceDisconnected) {
585
554
  throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded);
586
- } else if (e.errorCode === BleErrorCode.OperationStartFailed) {
555
+ }
556
+ if (e.errorCode === BleErrorCode.OperationStartFailed) {
587
557
  throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError, e.reason);
588
- } else {
589
- throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError);
590
558
  }
559
+ return;
591
560
  }
592
561
  }
593
562
  }