incyclist-devices 2.0.18 → 2.0.19

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.
@@ -483,6 +483,7 @@ class BleComms extends events_1.default {
483
483
  throw new Error('not connected');
484
484
  try {
485
485
  const { withoutResponse, timeout } = props || {};
486
+ let fireAndForget = withoutResponse;
486
487
  const connector = this.ble.peripheralCache.getConnector(this.peripheral);
487
488
  const isAlreadySubscribed = connector.isSubscribed(characteristicUuid);
488
489
  if (!withoutResponse && !this.workerIv) {
@@ -495,8 +496,14 @@ class BleComms extends events_1.default {
495
496
  this.onData(uuid, data);
496
497
  });
497
498
  this.logEvent({ message: 'write:subscribing ', characteristic: characteristicUuid });
498
- yield connector.subscribe(characteristicUuid);
499
- this.subscribedCharacteristics.push(characteristicUuid);
499
+ try {
500
+ yield connector.subscribe(characteristicUuid);
501
+ this.subscribedCharacteristics.push(characteristicUuid);
502
+ }
503
+ catch (err) {
504
+ this.logEvent({ message: 'write:subscribing failed', characteristic: characteristicUuid, error: err.message });
505
+ fireAndForget = true;
506
+ }
500
507
  }
501
508
  return new Promise((resolve, reject) => {
502
509
  const characteristic = this.characteristics.find(c => c.uuid === characteristicUuid || (0, utils_2.uuid)(c.uuid) === characteristicUuid);
@@ -504,9 +511,9 @@ class BleComms extends events_1.default {
504
511
  reject(new Error('Characteristic not found'));
505
512
  return;
506
513
  }
507
- if (withoutResponse) {
508
- this.logEvent({ message: 'writing', data: data.toString('hex'), withoutResponse });
509
- characteristic.write(data, withoutResponse);
514
+ if (fireAndForget) {
515
+ this.logEvent({ message: 'writing', data: data.toString('hex'), withoutResponse: 'true' });
516
+ characteristic.write(data, true);
510
517
  resolve(new ArrayBuffer(0));
511
518
  return;
512
519
  }
@@ -24,8 +24,8 @@ class BlePeripheralConnector {
24
24
  if (!this.peripheral || !this.ble)
25
25
  throw new Error('Illegal Arguments');
26
26
  this.state = { subscribed: [], isConnected: false, isConnecting: false, isInitialized: false, isInitializing: false, isSubscribing: false };
27
- this.services = undefined;
28
- this.characteristics = undefined;
27
+ this.services = [];
28
+ this.characteristics = [];
29
29
  this.logger = new gd_eventlog_1.EventLogger('BLE');
30
30
  }
31
31
  logEvent(event) {
@@ -92,18 +92,19 @@ class BlePeripheralConnector {
92
92
  }
93
93
  return new Promise((done) => __awaiter(this, void 0, void 0, function* () {
94
94
  this.state.isInitializing = true;
95
- this.characteristics = undefined;
96
- this.services = undefined;
95
+ this.characteristics = [];
96
+ this.services = [];
97
97
  try {
98
98
  this.emitter.once('disconnect', () => {
99
99
  done(false);
100
100
  });
101
101
  const res = yield this.peripheral.discoverSomeServicesAndCharacteristicsAsync([], []);
102
102
  if (this.state.isInitializing) {
103
- this.characteristics = res.characteristics;
104
- this.services = res.services.map(s => typeof (s) === 'string' ? s : s.uuid);
103
+ this.characteristics = res.characteristics || [];
104
+ const services = res.services || [];
105
+ this.services = services.map(s => typeof (s) === 'string' ? s : s.uuid);
105
106
  this.state.isInitializing = false;
106
- this.state.isInitialized = this.characteristics !== undefined && this.services !== undefined;
107
+ this.state.isInitialized = this.characteristics !== undefined && this.services !== undefined && this.characteristics.length > 0 && this.services.length > 0;
107
108
  this.logEvent({ message: 'initialize done', peripheral: this.peripheral.address, state: this.state });
108
109
  return done(true);
109
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",