incyclist-devices 3.0.53 → 3.0.54

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.
@@ -8,6 +8,7 @@ const SERVICE_COMPLETENESS_WHITELIST = ['MRK-R15'];
8
8
  const POST_CONNECT_DISCOVERY_ATTEMPTS = 4;
9
9
  const POST_CONNECT_DISCOVERY_BACKOFF_MS = 1000;
10
10
  const BLE_DISCONNECT_STEP_TIMEOUT = 3000;
11
+ const BLE_RELEASE_LINK_TIMEOUT = 1500;
11
12
  class BlePeripheral {
12
13
  announcement;
13
14
  connected = false;
@@ -22,6 +23,9 @@ class BlePeripheral {
22
23
  serviceDiscoveryIncomplete = false;
23
24
  discoverServicesPromise;
24
25
  discoverCharacteristicsPromise = {};
26
+ knownCharacteristics = new Set();
27
+ usedCharacteristics = new Set();
28
+ characteristicsDiscovered = false;
25
29
  awaitingPostConnectDiscovery = false;
26
30
  onErrorHandler = this.onPeripheralError.bind(this);
27
31
  constructor(announcement) {
@@ -110,6 +114,7 @@ class BlePeripheral {
110
114
  c.removeAllListeners();
111
115
  });
112
116
  this.characteristics = {};
117
+ this.characteristicsDiscovered = false;
113
118
  this.subscribed = [];
114
119
  const peripheral = this.getPeripheral();
115
120
  if (peripheral) {
@@ -244,7 +249,7 @@ class BlePeripheral {
244
249
  this.logEvent({ message: 'discover services and characteristics', name, address, service: serviceUUID });
245
250
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([serviceUUID], [])
246
251
  .catch(() => ({ services: [], characteristics: [] }));
247
- res.characteristics.forEach(c => this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c);
252
+ res.characteristics.forEach(c => this.cacheCharacteristic(c));
248
253
  this.logEvent({ message: 'discover services and characteristics result', name, address, service: serviceUUID });
249
254
  return res.characteristics.map(c => {
250
255
  const { uuid, properties, name, _serviceUuid } = c;
@@ -274,6 +279,7 @@ class BlePeripheral {
274
279
  c.off('data', onData);
275
280
  c.on('data', onData);
276
281
  }
282
+ this.markUsed(characteristicUUID);
277
283
  return true;
278
284
  }
279
285
  let c = await this.queryRawCharacteristic(characteristicUUID).catch(() => null);
@@ -281,6 +287,7 @@ class BlePeripheral {
281
287
  this.logEvent({ message: 'peripheral subscribe failed', characteristic: (0, utils_js_2.beautifyUUID)(characteristicUUID), reason: 'not found' });
282
288
  return false;
283
289
  }
290
+ this.markUsed(characteristicUUID);
284
291
  return new Promise((resolve, reject) => {
285
292
  const info = this.subscribed.find(s => s.uuid === characteristicUUID);
286
293
  if (info) {
@@ -396,6 +403,40 @@ class BlePeripheral {
396
403
  return false;
397
404
  }
398
405
  }
406
+ cacheCharacteristic(c) {
407
+ const uuid = (0, utils_js_2.beautifyUUID)(c.uuid);
408
+ this.characteristics[uuid] = c;
409
+ this.knownCharacteristics.add(uuid);
410
+ }
411
+ markUsed(characteristicUUID) {
412
+ this.usedCharacteristics.add((0, utils_js_2.beautifyUUID)(characteristicUUID));
413
+ }
414
+ async verifyCharacteristics() {
415
+ if (!this.connected)
416
+ return { missing: [], missingUsed: [] };
417
+ if (!this.characteristicsDiscovered) {
418
+ await this.discoverAllCharacteristics();
419
+ }
420
+ const present = new Set(Object.keys(this.characteristics));
421
+ const missing = Array.from(this.knownCharacteristics).filter(uuid => !present.has(uuid));
422
+ const missingUsed = missing.filter(uuid => this.usedCharacteristics.has(uuid));
423
+ return { missing, missingUsed };
424
+ }
425
+ async releaseLink() {
426
+ const peripheral = this.getPeripheral();
427
+ if (!peripheral)
428
+ return;
429
+ const { name, address } = this.getInfo();
430
+ this.logEvent({ message: 'release link before reconnect', name, address });
431
+ try {
432
+ const disconnected = peripheral.disconnectAsync
433
+ ? peripheral.disconnectAsync()
434
+ : new Promise((done) => { void peripheral.disconnect(() => { done(); }); });
435
+ await (0, utils_js_1.runWithTimeout)(disconnected, BLE_RELEASE_LINK_TIMEOUT);
436
+ }
437
+ catch {
438
+ }
439
+ }
399
440
  async discoverAllCharacteristics() {
400
441
  const attempts = this.awaitingPostConnectDiscovery ? POST_CONNECT_DISCOVERY_ATTEMPTS : 1;
401
442
  return this.discoverAllCharacteristicsAttempt(1, attempts);
@@ -424,10 +465,11 @@ class BlePeripheral {
424
465
  delete this.characteristics[existing];
425
466
  });
426
467
  res.characteristics.forEach(c => {
427
- this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c;
468
+ this.cacheCharacteristic(c);
428
469
  found.push(c.uuid);
429
470
  uuids.push((0, utils_js_2.beautifyUUID)(c.uuid));
430
471
  });
472
+ this.characteristicsDiscovered = true;
431
473
  this.logEvent({ message: 'discover all characteristics result', name, address, uuids: uuids.join('|') });
432
474
  return found;
433
475
  }
@@ -448,7 +490,7 @@ class BlePeripheral {
448
490
  delete this.characteristics[requestedUuid];
449
491
  });
450
492
  res.characteristics.forEach(c => {
451
- this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c;
493
+ this.cacheCharacteristic(c);
452
494
  found.push(c.uuid);
453
495
  });
454
496
  return found;
@@ -493,6 +535,7 @@ class BlePeripheral {
493
535
  return Promise.reject(new Error('characteristic not found: ' + characteristicUUID));
494
536
  }
495
537
  }
538
+ this.markUsed(characteristicUUID);
496
539
  return new Promise((resolve, reject) => {
497
540
  c.read((err, data) => {
498
541
  if (err) {
@@ -516,6 +559,7 @@ class BlePeripheral {
516
559
  return Promise.reject(new Error('characteristic not found: ' + characteristicUUID));
517
560
  }
518
561
  }
562
+ this.markUsed(characteristicUUID);
519
563
  const signal = options?.signal;
520
564
  return new Promise((resolve, reject) => {
521
565
  let settled = false;
@@ -9,6 +9,7 @@ class TBleSensor extends node_events_1.EventEmitter {
9
9
  peripheral;
10
10
  static protocol;
11
11
  static RECONNECT_ATTEMPT_TIMEOUT = 20000;
12
+ static RECONNECT_CHARACTERISTICS_TIMEOUT = 30000;
12
13
  logger;
13
14
  stopRequested = false;
14
15
  subscribeSuccess = false;
@@ -16,6 +17,10 @@ class TBleSensor extends node_events_1.EventEmitter {
16
17
  connectPromise;
17
18
  reconnectAttemptTimeout = TBleSensor.RECONNECT_ATTEMPT_TIMEOUT;
18
19
  reconnectCount = 0;
20
+ reconnectCharacteristicsTimeout = TBleSensor.RECONNECT_CHARACTERISTICS_TIMEOUT;
21
+ reconnectStartedAt = 0;
22
+ reconnectAttempts = 0;
23
+ reconnectIncomplete = false;
19
24
  onDataHandler;
20
25
  logEvent(event, ...args) {
21
26
  try {
@@ -145,11 +150,19 @@ class TBleSensor extends node_events_1.EventEmitter {
145
150
  if (connectionLost) {
146
151
  this.emit('connctionLost');
147
152
  }
153
+ this.reconnectStartedAt = Date.now();
154
+ this.reconnectAttempts = 0;
148
155
  await (0, utils_js_1.sleep)(500);
156
+ if (connectionLost) {
157
+ await this.releaseLink();
158
+ }
149
159
  success = await this.reconnectUntilDone(name, address);
150
160
  if (connectionLost && success) {
151
161
  this.emit('connctionRecovered');
152
162
  }
163
+ if (connectionLost && !success && this.reconnectIncomplete) {
164
+ this.emit('connctionRecoveryFailed');
165
+ }
153
166
  this.logEvent({ message: 'reconnect sensor completed', success, stopRequested: this.stopRequested });
154
167
  return success;
155
168
  }
@@ -157,6 +170,11 @@ class TBleSensor extends node_events_1.EventEmitter {
157
170
  const success = await this.reconnectAttempt(name, address);
158
171
  if (success || this.stopRequested)
159
172
  return success;
173
+ if (this.reconnectIncomplete && Date.now() - this.reconnectStartedAt >= this.reconnectCharacteristicsTimeout) {
174
+ this.logEvent({ message: 'reconnect sensor failed', name, address, reason: 'used characteristics missing',
175
+ attempts: this.reconnectAttempts, duration: Date.now() - this.reconnectStartedAt });
176
+ return false;
177
+ }
160
178
  await (0, utils_js_1.sleep)(1000);
161
179
  if (this.stopRequested)
162
180
  return false;
@@ -164,8 +182,14 @@ class TBleSensor extends node_events_1.EventEmitter {
164
182
  return this.reconnectUntilDone(name, address);
165
183
  }
166
184
  async reconnectAttempt(name, address) {
185
+ this.reconnectIncomplete = false;
186
+ this.reconnectAttempts++;
167
187
  try {
168
- return await (0, utils_js_1.runWithTimeout)(this.connectAndSubscribe(), this.reconnectAttemptTimeout);
188
+ const success = await (0, utils_js_1.runWithTimeout)(this.connectAndSubscribe(), this.reconnectAttemptTimeout);
189
+ if (!success && this.reconnectIncomplete) {
190
+ await this.abortIncompleteReconnectAttempt();
191
+ }
192
+ return success;
169
193
  }
170
194
  catch (err) {
171
195
  if (err?.message === 'Timeout') {
@@ -179,7 +203,49 @@ class TBleSensor extends node_events_1.EventEmitter {
179
203
  if (!connected)
180
204
  return false;
181
205
  const subscribed = await this.subscribe();
182
- return subscribed && this.isConnected();
206
+ if (!subscribed || !this.isConnected())
207
+ return false;
208
+ return await this.checkCharacteristicsRestored();
209
+ }
210
+ async checkCharacteristicsRestored() {
211
+ if (!this.peripheral?.verifyCharacteristics)
212
+ return true;
213
+ let result;
214
+ try {
215
+ result = await this.peripheral.verifyCharacteristics();
216
+ }
217
+ catch (err) {
218
+ this.logEvent({ message: 'reconnect: characteristics check failed', reason: err?.message });
219
+ return true;
220
+ }
221
+ if (!result || result.missing.length === 0)
222
+ return true;
223
+ const { name, address } = this.peripheral.getInfo() ?? {};
224
+ const details = { name, address, attempt: this.reconnectAttempts, duration: Date.now() - this.reconnectStartedAt,
225
+ missing: result.missing.join('|'), missingUsed: result.missingUsed.join('|') };
226
+ if (result.missingUsed.length === 0) {
227
+ this.logEvent({ message: 'reconnect: unused characteristics missing', ...details });
228
+ return true;
229
+ }
230
+ this.reconnectIncomplete = true;
231
+ this.logEvent({ message: 'reconnect: used characteristics missing', ...details });
232
+ return false;
233
+ }
234
+ async abortIncompleteReconnectAttempt() {
235
+ delete this.connectPromise;
236
+ this.onDisconnect();
237
+ try {
238
+ await (0, utils_js_1.runWithTimeout)(this.peripheral.disconnect(), this.reconnectAttemptTimeout);
239
+ }
240
+ catch {
241
+ }
242
+ }
243
+ async releaseLink() {
244
+ try {
245
+ await this.peripheral?.releaseLink?.();
246
+ }
247
+ catch {
248
+ }
183
249
  }
184
250
  async abortReconnectAttempt(name, address) {
185
251
  this.logEvent({ message: 'reconnect sensor attempt timeout', name, address, timeout: this.reconnectAttemptTimeout });
@@ -5,6 +5,7 @@ const SERVICE_COMPLETENESS_WHITELIST = ['MRK-R15'];
5
5
  const POST_CONNECT_DISCOVERY_ATTEMPTS = 4;
6
6
  const POST_CONNECT_DISCOVERY_BACKOFF_MS = 1000;
7
7
  const BLE_DISCONNECT_STEP_TIMEOUT = 3000;
8
+ const BLE_RELEASE_LINK_TIMEOUT = 1500;
8
9
  export class BlePeripheral {
9
10
  announcement;
10
11
  connected = false;
@@ -19,6 +20,9 @@ export class BlePeripheral {
19
20
  serviceDiscoveryIncomplete = false;
20
21
  discoverServicesPromise;
21
22
  discoverCharacteristicsPromise = {};
23
+ knownCharacteristics = new Set();
24
+ usedCharacteristics = new Set();
25
+ characteristicsDiscovered = false;
22
26
  awaitingPostConnectDiscovery = false;
23
27
  onErrorHandler = this.onPeripheralError.bind(this);
24
28
  constructor(announcement) {
@@ -107,6 +111,7 @@ export class BlePeripheral {
107
111
  c.removeAllListeners();
108
112
  });
109
113
  this.characteristics = {};
114
+ this.characteristicsDiscovered = false;
110
115
  this.subscribed = [];
111
116
  const peripheral = this.getPeripheral();
112
117
  if (peripheral) {
@@ -241,7 +246,7 @@ export class BlePeripheral {
241
246
  this.logEvent({ message: 'discover services and characteristics', name, address, service: serviceUUID });
242
247
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([serviceUUID], [])
243
248
  .catch(() => ({ services: [], characteristics: [] }));
244
- res.characteristics.forEach(c => this.characteristics[beautifyUUID(c.uuid)] = c);
249
+ res.characteristics.forEach(c => this.cacheCharacteristic(c));
245
250
  this.logEvent({ message: 'discover services and characteristics result', name, address, service: serviceUUID });
246
251
  return res.characteristics.map(c => {
247
252
  const { uuid, properties, name, _serviceUuid } = c;
@@ -271,6 +276,7 @@ export class BlePeripheral {
271
276
  c.off('data', onData);
272
277
  c.on('data', onData);
273
278
  }
279
+ this.markUsed(characteristicUUID);
274
280
  return true;
275
281
  }
276
282
  let c = await this.queryRawCharacteristic(characteristicUUID).catch(() => null);
@@ -278,6 +284,7 @@ export class BlePeripheral {
278
284
  this.logEvent({ message: 'peripheral subscribe failed', characteristic: beautifyUUID(characteristicUUID), reason: 'not found' });
279
285
  return false;
280
286
  }
287
+ this.markUsed(characteristicUUID);
281
288
  return new Promise((resolve, reject) => {
282
289
  const info = this.subscribed.find(s => s.uuid === characteristicUUID);
283
290
  if (info) {
@@ -393,6 +400,40 @@ export class BlePeripheral {
393
400
  return false;
394
401
  }
395
402
  }
403
+ cacheCharacteristic(c) {
404
+ const uuid = beautifyUUID(c.uuid);
405
+ this.characteristics[uuid] = c;
406
+ this.knownCharacteristics.add(uuid);
407
+ }
408
+ markUsed(characteristicUUID) {
409
+ this.usedCharacteristics.add(beautifyUUID(characteristicUUID));
410
+ }
411
+ async verifyCharacteristics() {
412
+ if (!this.connected)
413
+ return { missing: [], missingUsed: [] };
414
+ if (!this.characteristicsDiscovered) {
415
+ await this.discoverAllCharacteristics();
416
+ }
417
+ const present = new Set(Object.keys(this.characteristics));
418
+ const missing = Array.from(this.knownCharacteristics).filter(uuid => !present.has(uuid));
419
+ const missingUsed = missing.filter(uuid => this.usedCharacteristics.has(uuid));
420
+ return { missing, missingUsed };
421
+ }
422
+ async releaseLink() {
423
+ const peripheral = this.getPeripheral();
424
+ if (!peripheral)
425
+ return;
426
+ const { name, address } = this.getInfo();
427
+ this.logEvent({ message: 'release link before reconnect', name, address });
428
+ try {
429
+ const disconnected = peripheral.disconnectAsync
430
+ ? peripheral.disconnectAsync()
431
+ : new Promise((done) => { void peripheral.disconnect(() => { done(); }); });
432
+ await runWithTimeout(disconnected, BLE_RELEASE_LINK_TIMEOUT);
433
+ }
434
+ catch {
435
+ }
436
+ }
396
437
  async discoverAllCharacteristics() {
397
438
  const attempts = this.awaitingPostConnectDiscovery ? POST_CONNECT_DISCOVERY_ATTEMPTS : 1;
398
439
  return this.discoverAllCharacteristicsAttempt(1, attempts);
@@ -421,10 +462,11 @@ export class BlePeripheral {
421
462
  delete this.characteristics[existing];
422
463
  });
423
464
  res.characteristics.forEach(c => {
424
- this.characteristics[beautifyUUID(c.uuid)] = c;
465
+ this.cacheCharacteristic(c);
425
466
  found.push(c.uuid);
426
467
  uuids.push(beautifyUUID(c.uuid));
427
468
  });
469
+ this.characteristicsDiscovered = true;
428
470
  this.logEvent({ message: 'discover all characteristics result', name, address, uuids: uuids.join('|') });
429
471
  return found;
430
472
  }
@@ -445,7 +487,7 @@ export class BlePeripheral {
445
487
  delete this.characteristics[requestedUuid];
446
488
  });
447
489
  res.characteristics.forEach(c => {
448
- this.characteristics[beautifyUUID(c.uuid)] = c;
490
+ this.cacheCharacteristic(c);
449
491
  found.push(c.uuid);
450
492
  });
451
493
  return found;
@@ -490,6 +532,7 @@ export class BlePeripheral {
490
532
  return Promise.reject(new Error('characteristic not found: ' + characteristicUUID));
491
533
  }
492
534
  }
535
+ this.markUsed(characteristicUUID);
493
536
  return new Promise((resolve, reject) => {
494
537
  c.read((err, data) => {
495
538
  if (err) {
@@ -513,6 +556,7 @@ export class BlePeripheral {
513
556
  return Promise.reject(new Error('characteristic not found: ' + characteristicUUID));
514
557
  }
515
558
  }
559
+ this.markUsed(characteristicUUID);
516
560
  const signal = options?.signal;
517
561
  return new Promise((resolve, reject) => {
518
562
  let settled = false;
@@ -6,6 +6,7 @@ export class TBleSensor extends EventEmitter {
6
6
  peripheral;
7
7
  static protocol;
8
8
  static RECONNECT_ATTEMPT_TIMEOUT = 20000;
9
+ static RECONNECT_CHARACTERISTICS_TIMEOUT = 30000;
9
10
  logger;
10
11
  stopRequested = false;
11
12
  subscribeSuccess = false;
@@ -13,6 +14,10 @@ export class TBleSensor extends EventEmitter {
13
14
  connectPromise;
14
15
  reconnectAttemptTimeout = TBleSensor.RECONNECT_ATTEMPT_TIMEOUT;
15
16
  reconnectCount = 0;
17
+ reconnectCharacteristicsTimeout = TBleSensor.RECONNECT_CHARACTERISTICS_TIMEOUT;
18
+ reconnectStartedAt = 0;
19
+ reconnectAttempts = 0;
20
+ reconnectIncomplete = false;
16
21
  onDataHandler;
17
22
  logEvent(event, ...args) {
18
23
  try {
@@ -142,11 +147,19 @@ export class TBleSensor extends EventEmitter {
142
147
  if (connectionLost) {
143
148
  this.emit('connctionLost');
144
149
  }
150
+ this.reconnectStartedAt = Date.now();
151
+ this.reconnectAttempts = 0;
145
152
  await sleep(500);
153
+ if (connectionLost) {
154
+ await this.releaseLink();
155
+ }
146
156
  success = await this.reconnectUntilDone(name, address);
147
157
  if (connectionLost && success) {
148
158
  this.emit('connctionRecovered');
149
159
  }
160
+ if (connectionLost && !success && this.reconnectIncomplete) {
161
+ this.emit('connctionRecoveryFailed');
162
+ }
150
163
  this.logEvent({ message: 'reconnect sensor completed', success, stopRequested: this.stopRequested });
151
164
  return success;
152
165
  }
@@ -154,6 +167,11 @@ export class TBleSensor extends EventEmitter {
154
167
  const success = await this.reconnectAttempt(name, address);
155
168
  if (success || this.stopRequested)
156
169
  return success;
170
+ if (this.reconnectIncomplete && Date.now() - this.reconnectStartedAt >= this.reconnectCharacteristicsTimeout) {
171
+ this.logEvent({ message: 'reconnect sensor failed', name, address, reason: 'used characteristics missing',
172
+ attempts: this.reconnectAttempts, duration: Date.now() - this.reconnectStartedAt });
173
+ return false;
174
+ }
157
175
  await sleep(1000);
158
176
  if (this.stopRequested)
159
177
  return false;
@@ -161,8 +179,14 @@ export class TBleSensor extends EventEmitter {
161
179
  return this.reconnectUntilDone(name, address);
162
180
  }
163
181
  async reconnectAttempt(name, address) {
182
+ this.reconnectIncomplete = false;
183
+ this.reconnectAttempts++;
164
184
  try {
165
- return await runWithTimeout(this.connectAndSubscribe(), this.reconnectAttemptTimeout);
185
+ const success = await runWithTimeout(this.connectAndSubscribe(), this.reconnectAttemptTimeout);
186
+ if (!success && this.reconnectIncomplete) {
187
+ await this.abortIncompleteReconnectAttempt();
188
+ }
189
+ return success;
166
190
  }
167
191
  catch (err) {
168
192
  if (err?.message === 'Timeout') {
@@ -176,7 +200,49 @@ export class TBleSensor extends EventEmitter {
176
200
  if (!connected)
177
201
  return false;
178
202
  const subscribed = await this.subscribe();
179
- return subscribed && this.isConnected();
203
+ if (!subscribed || !this.isConnected())
204
+ return false;
205
+ return await this.checkCharacteristicsRestored();
206
+ }
207
+ async checkCharacteristicsRestored() {
208
+ if (!this.peripheral?.verifyCharacteristics)
209
+ return true;
210
+ let result;
211
+ try {
212
+ result = await this.peripheral.verifyCharacteristics();
213
+ }
214
+ catch (err) {
215
+ this.logEvent({ message: 'reconnect: characteristics check failed', reason: err?.message });
216
+ return true;
217
+ }
218
+ if (!result || result.missing.length === 0)
219
+ return true;
220
+ const { name, address } = this.peripheral.getInfo() ?? {};
221
+ const details = { name, address, attempt: this.reconnectAttempts, duration: Date.now() - this.reconnectStartedAt,
222
+ missing: result.missing.join('|'), missingUsed: result.missingUsed.join('|') };
223
+ if (result.missingUsed.length === 0) {
224
+ this.logEvent({ message: 'reconnect: unused characteristics missing', ...details });
225
+ return true;
226
+ }
227
+ this.reconnectIncomplete = true;
228
+ this.logEvent({ message: 'reconnect: used characteristics missing', ...details });
229
+ return false;
230
+ }
231
+ async abortIncompleteReconnectAttempt() {
232
+ delete this.connectPromise;
233
+ this.onDisconnect();
234
+ try {
235
+ await runWithTimeout(this.peripheral.disconnect(), this.reconnectAttemptTimeout);
236
+ }
237
+ catch {
238
+ }
239
+ }
240
+ async releaseLink() {
241
+ try {
242
+ await this.peripheral?.releaseLink?.();
243
+ }
244
+ catch {
245
+ }
180
246
  }
181
247
  async abortReconnectAttempt(name, address) {
182
248
  this.logEvent({ message: 'reconnect sensor attempt timeout', name, address, timeout: this.reconnectAttemptTimeout });
@@ -17,6 +17,9 @@ export declare class BlePeripheral implements IBlePeripheral {
17
17
  protected serviceDiscoveryIncomplete: boolean;
18
18
  protected discoverServicesPromise: Promise<string[]> | undefined;
19
19
  protected discoverCharacteristicsPromise: Record<string, Promise<BleCharacteristic[]> | undefined>;
20
+ protected knownCharacteristics: Set<string>;
21
+ protected usedCharacteristics: Set<string>;
22
+ protected characteristicsDiscovered: boolean;
20
23
  protected awaitingPostConnectDiscovery: boolean;
21
24
  protected onErrorHandler: any;
22
25
  constructor(announcement: BlePeripheralAnnouncement);
@@ -45,6 +48,13 @@ export declare class BlePeripheral implements IBlePeripheral {
45
48
  subscribe(characteristicUUID: string, callback: (characteristicUuid: string, data: Buffer, isNotify?: boolean) => void): Promise<boolean>;
46
49
  unsubscribe(characteristicUUID: string): Promise<boolean>;
47
50
  subscribeSelected(characteristics: string[], callback: (characteristicUuid: string, data: Buffer, isNotify?: boolean) => void): Promise<boolean>;
51
+ protected cacheCharacteristic(c: BleRawCharacteristic): void;
52
+ protected markUsed(characteristicUUID: string): void;
53
+ verifyCharacteristics(): Promise<{
54
+ missing: string[];
55
+ missingUsed: string[];
56
+ }>;
57
+ releaseLink(): Promise<void>;
48
58
  discoverAllCharacteristics(): Promise<string[]>;
49
59
  protected discoverAllCharacteristicsAttempt(attempt: number, maxAttempts: number): Promise<string[]>;
50
60
  protected queryAllCharacteristics(): Promise<string[]>;
@@ -6,6 +6,7 @@ export declare class TBleSensor extends EventEmitter implements IBleSensor {
6
6
  protected peripheral: IBlePeripheral;
7
7
  static readonly protocol: BleProtocol;
8
8
  static readonly RECONNECT_ATTEMPT_TIMEOUT = 20000;
9
+ static readonly RECONNECT_CHARACTERISTICS_TIMEOUT = 30000;
9
10
  protected logger: EventLogger;
10
11
  protected stopRequested: boolean;
11
12
  protected subscribeSuccess: boolean;
@@ -13,6 +14,10 @@ export declare class TBleSensor extends EventEmitter implements IBleSensor {
13
14
  protected connectPromise: Promise<boolean> | undefined;
14
15
  protected reconnectAttemptTimeout: number;
15
16
  protected reconnectCount: number;
17
+ protected reconnectCharacteristicsTimeout: number;
18
+ protected reconnectStartedAt: number;
19
+ protected reconnectAttempts: number;
20
+ protected reconnectIncomplete: boolean;
16
21
  protected onDataHandler: any;
17
22
  logEvent(event: any, ...args: any): void;
18
23
  constructor(peripheral: IBlePeripheral, props?: {
@@ -39,6 +44,9 @@ export declare class TBleSensor extends EventEmitter implements IBleSensor {
39
44
  protected reconnectUntilDone(name: string, address: string): Promise<boolean>;
40
45
  protected reconnectAttempt(name: string, address: string): Promise<boolean>;
41
46
  protected connectAndSubscribe(): Promise<boolean>;
47
+ protected checkCharacteristicsRestored(): Promise<boolean>;
48
+ protected abortIncompleteReconnectAttempt(): Promise<void>;
49
+ protected releaseLink(): Promise<void>;
42
50
  protected abortReconnectAttempt(name: string, address: string): Promise<void>;
43
51
  reset(): void;
44
52
  isConnected(): boolean;
@@ -173,6 +173,11 @@ export interface IBlePeripheral {
173
173
  getAnnouncedServices(): string[];
174
174
  getDiscoveredServices(): string[];
175
175
  getInterface(): IBleInterface<any>;
176
+ verifyCharacteristics?(): Promise<{
177
+ missing: string[];
178
+ missingUsed: string[];
179
+ }>;
180
+ releaseLink?(): Promise<void>;
176
181
  }
177
182
  export interface IBleSensor extends EventEmitter {
178
183
  startSensor(): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.53",
3
+ "version": "3.0.54",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",