incyclist-devices 3.0.19 → 3.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.
@@ -405,7 +405,12 @@ class BleInterface extends node_events_1.EventEmitter {
405
405
  }
406
406
  const isWahoo = this.checkForWahooEnhancement(announcement);
407
407
  if (isWahoo) {
408
- this.processWahooAnnouncement(announcement);
408
+ this.processEnrichedAnnouncement(announcement);
409
+ return;
410
+ }
411
+ const isTacx = this.checkForTacxEnhancement(announcement);
412
+ if (isTacx) {
413
+ this.processEnrichedAnnouncement(announcement);
409
414
  return;
410
415
  }
411
416
  this.addService(announcement);
@@ -419,7 +424,7 @@ class BleInterface extends node_events_1.EventEmitter {
419
424
  }
420
425
  return false;
421
426
  }
422
- processWahooAnnouncement(announcement) {
427
+ processEnrichedAnnouncement(announcement) {
423
428
  if (this.isCompleting(announcement)) {
424
429
  return;
425
430
  }
@@ -429,6 +434,19 @@ class BleInterface extends node_events_1.EventEmitter {
429
434
  this.addService(announcement);
430
435
  });
431
436
  }
437
+ checkForTacxEnhancement(announcement) {
438
+ const name = announcement?.name?.toUpperCase();
439
+ if (name.startsWith('TACX')) {
440
+ const supported = announcement.serviceUUIDs.map(s => (0, utils_js_1.beautifyUUID)(s));
441
+ const tacxService = (0, utils_js_1.beautifyUUID)('6E40FEC1-B5A3-F393-E0A9-E50E24DCCA9E');
442
+ const cp = (0, utils_js_1.beautifyUUID)('1818');
443
+ const fe = (0, utils_js_1.beautifyUUID)('1826');
444
+ if (supported.includes(cp) && !supported.includes(fe) && !supported.includes(tacxService)) {
445
+ return true;
446
+ }
447
+ }
448
+ return false;
449
+ }
432
450
  buildAnnouncement(peripheral) {
433
451
  return {
434
452
  advertisement: peripheral.advertisement,
@@ -163,8 +163,9 @@ class BlePeripheral {
163
163
  async _discoverServices() {
164
164
  if (!this.getPeripheral())
165
165
  return [];
166
+ const { name, address } = this.getInfo();
166
167
  if (this.getPeripheral().discoverServicesAsync) {
167
- this.logEvent({ message: 'discover services', address: this.getPeripheral().address });
168
+ this.logEvent({ message: 'discover services', name, address });
168
169
  const peripheral = this.getPeripheral();
169
170
  let services = [];
170
171
  if (peripheral?.discoverServicesAsync) {
@@ -172,14 +173,14 @@ class BlePeripheral {
172
173
  .catch(() => []);
173
174
  }
174
175
  this.discoveredServiceUUIds = services.map(s => (0, utils_js_2.beautifyUUID)(s.uuid));
175
- this.logEvent({ message: 'discover services result', address: this.getPeripheral().address, services: this.discoveredServiceUUIds });
176
+ this.logEvent({ message: 'discover services result', name, address, services: this.discoveredServiceUUIds });
176
177
  return services.map(s => s.uuid);
177
178
  }
178
179
  else {
179
- this.logEvent({ message: 'discover services and characteristics', address: this.getPeripheral().address });
180
+ this.logEvent({ message: 'discover services and characteristics', name, address });
180
181
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
181
182
  this.discoveredServiceUUIds = res.services.map(s => (0, utils_js_2.beautifyUUID)(s.uuid));
182
- this.logEvent({ message: 'discover services result', address: this.getPeripheral().address, services: this.discoveredServiceUUIds });
183
+ this.logEvent({ message: 'discover services result', name, address, services: this.discoveredServiceUUIds });
183
184
  return res.services.map(s => s.uuid);
184
185
  }
185
186
  }
@@ -193,10 +194,12 @@ class BlePeripheral {
193
194
  async _discoverCharacteristics(serviceUUID) {
194
195
  if (!this.getPeripheral())
195
196
  return [];
196
- this.logEvent({ message: 'discover services and characteristics', service: serviceUUID, address: this.getPeripheral().address });
197
+ const { name, address } = this.getInfo();
198
+ this.logEvent({ message: 'discover services and characteristics', name, address, service: serviceUUID });
197
199
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([serviceUUID], [])
198
200
  .catch(() => ({ services: [], characteristics: [] }));
199
201
  res.characteristics.forEach(c => this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c);
202
+ this.logEvent({ message: 'discover services and characteristics result', name, address, service: serviceUUID });
200
203
  return res.characteristics.map(c => {
201
204
  const { uuid, properties, name, _serviceUuid } = c;
202
205
  return { uuid, properties, name, _serviceUuid };
@@ -318,6 +321,15 @@ class BlePeripheral {
318
321
  if (!success)
319
322
  retry.push(c);
320
323
  }
324
+ else {
325
+ const uuid = (0, utils_js_2.beautifyUUID)(element);
326
+ if (c?.properties) {
327
+ this.logEvent({ message: 'cannot subscribe', uuid, reason: 'invalid type', properties: c.properties.join('|') });
328
+ }
329
+ else {
330
+ this.logEvent({ message: 'cannot subscribe', uuid, reason: 'not found' });
331
+ }
332
+ }
321
333
  }
322
334
  for (const element of retry) {
323
335
  const c = element;
@@ -332,12 +344,17 @@ class BlePeripheral {
332
344
  }
333
345
  async discoverAllCharacteristics() {
334
346
  try {
347
+ const { name, address } = this.getInfo();
348
+ this.logEvent({ message: 'discover all characteristics', name, address });
335
349
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
336
350
  const found = [];
351
+ const uuids = [];
337
352
  res.characteristics.forEach(c => {
338
353
  this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c;
339
354
  found.push(c.uuid);
355
+ uuids.push((0, utils_js_2.beautifyUUID)(c.uuid));
340
356
  });
357
+ this.logEvent({ message: 'discover all characteristics result', name, address, uuids: uuids.join('|') });
341
358
  return found;
342
359
  }
343
360
  catch (err) {
@@ -402,7 +402,12 @@ export class BleInterface extends EventEmitter {
402
402
  }
403
403
  const isWahoo = this.checkForWahooEnhancement(announcement);
404
404
  if (isWahoo) {
405
- this.processWahooAnnouncement(announcement);
405
+ this.processEnrichedAnnouncement(announcement);
406
+ return;
407
+ }
408
+ const isTacx = this.checkForTacxEnhancement(announcement);
409
+ if (isTacx) {
410
+ this.processEnrichedAnnouncement(announcement);
406
411
  return;
407
412
  }
408
413
  this.addService(announcement);
@@ -416,7 +421,7 @@ export class BleInterface extends EventEmitter {
416
421
  }
417
422
  return false;
418
423
  }
419
- processWahooAnnouncement(announcement) {
424
+ processEnrichedAnnouncement(announcement) {
420
425
  if (this.isCompleting(announcement)) {
421
426
  return;
422
427
  }
@@ -426,6 +431,19 @@ export class BleInterface extends EventEmitter {
426
431
  this.addService(announcement);
427
432
  });
428
433
  }
434
+ checkForTacxEnhancement(announcement) {
435
+ const name = announcement?.name?.toUpperCase();
436
+ if (name.startsWith('TACX')) {
437
+ const supported = announcement.serviceUUIDs.map(s => beautifyUUID(s));
438
+ const tacxService = beautifyUUID('6E40FEC1-B5A3-F393-E0A9-E50E24DCCA9E');
439
+ const cp = beautifyUUID('1818');
440
+ const fe = beautifyUUID('1826');
441
+ if (supported.includes(cp) && !supported.includes(fe) && !supported.includes(tacxService)) {
442
+ return true;
443
+ }
444
+ }
445
+ return false;
446
+ }
429
447
  buildAnnouncement(peripheral) {
430
448
  return {
431
449
  advertisement: peripheral.advertisement,
@@ -160,8 +160,9 @@ export class BlePeripheral {
160
160
  async _discoverServices() {
161
161
  if (!this.getPeripheral())
162
162
  return [];
163
+ const { name, address } = this.getInfo();
163
164
  if (this.getPeripheral().discoverServicesAsync) {
164
- this.logEvent({ message: 'discover services', address: this.getPeripheral().address });
165
+ this.logEvent({ message: 'discover services', name, address });
165
166
  const peripheral = this.getPeripheral();
166
167
  let services = [];
167
168
  if (peripheral?.discoverServicesAsync) {
@@ -169,14 +170,14 @@ export class BlePeripheral {
169
170
  .catch(() => []);
170
171
  }
171
172
  this.discoveredServiceUUIds = services.map(s => beautifyUUID(s.uuid));
172
- this.logEvent({ message: 'discover services result', address: this.getPeripheral().address, services: this.discoveredServiceUUIds });
173
+ this.logEvent({ message: 'discover services result', name, address, services: this.discoveredServiceUUIds });
173
174
  return services.map(s => s.uuid);
174
175
  }
175
176
  else {
176
- this.logEvent({ message: 'discover services and characteristics', address: this.getPeripheral().address });
177
+ this.logEvent({ message: 'discover services and characteristics', name, address });
177
178
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
178
179
  this.discoveredServiceUUIds = res.services.map(s => beautifyUUID(s.uuid));
179
- this.logEvent({ message: 'discover services result', address: this.getPeripheral().address, services: this.discoveredServiceUUIds });
180
+ this.logEvent({ message: 'discover services result', name, address, services: this.discoveredServiceUUIds });
180
181
  return res.services.map(s => s.uuid);
181
182
  }
182
183
  }
@@ -190,10 +191,12 @@ export class BlePeripheral {
190
191
  async _discoverCharacteristics(serviceUUID) {
191
192
  if (!this.getPeripheral())
192
193
  return [];
193
- this.logEvent({ message: 'discover services and characteristics', service: serviceUUID, address: this.getPeripheral().address });
194
+ const { name, address } = this.getInfo();
195
+ this.logEvent({ message: 'discover services and characteristics', name, address, service: serviceUUID });
194
196
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([serviceUUID], [])
195
197
  .catch(() => ({ services: [], characteristics: [] }));
196
198
  res.characteristics.forEach(c => this.characteristics[beautifyUUID(c.uuid)] = c);
199
+ this.logEvent({ message: 'discover services and characteristics result', name, address, service: serviceUUID });
197
200
  return res.characteristics.map(c => {
198
201
  const { uuid, properties, name, _serviceUuid } = c;
199
202
  return { uuid, properties, name, _serviceUuid };
@@ -315,6 +318,15 @@ export class BlePeripheral {
315
318
  if (!success)
316
319
  retry.push(c);
317
320
  }
321
+ else {
322
+ const uuid = beautifyUUID(element);
323
+ if (c?.properties) {
324
+ this.logEvent({ message: 'cannot subscribe', uuid, reason: 'invalid type', properties: c.properties.join('|') });
325
+ }
326
+ else {
327
+ this.logEvent({ message: 'cannot subscribe', uuid, reason: 'not found' });
328
+ }
329
+ }
318
330
  }
319
331
  for (const element of retry) {
320
332
  const c = element;
@@ -329,12 +341,17 @@ export class BlePeripheral {
329
341
  }
330
342
  async discoverAllCharacteristics() {
331
343
  try {
344
+ const { name, address } = this.getInfo();
345
+ this.logEvent({ message: 'discover all characteristics', name, address });
332
346
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
333
347
  const found = [];
348
+ const uuids = [];
334
349
  res.characteristics.forEach(c => {
335
350
  this.characteristics[beautifyUUID(c.uuid)] = c;
336
351
  found.push(c.uuid);
352
+ uuids.push(beautifyUUID(c.uuid));
337
353
  });
354
+ this.logEvent({ message: 'discover all characteristics result', name, address, uuids: uuids.join('|') });
338
355
  return found;
339
356
  }
340
357
  catch (err) {
@@ -79,7 +79,8 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
79
79
  protected discoverPeripherals(): Promise<void>;
80
80
  protected onPeripheralFound(peripheral: BleRawPeripheral): void;
81
81
  protected checkForWahooEnhancement(announcement: BlePeripheralAnnouncement): boolean;
82
- protected processWahooAnnouncement(announcement: BlePeripheralAnnouncement): void;
82
+ protected processEnrichedAnnouncement(announcement: BlePeripheralAnnouncement): void;
83
+ protected checkForTacxEnhancement(announcement: BlePeripheralAnnouncement): boolean;
83
84
  protected buildAnnouncement(peripheral: BleRawPeripheral): BlePeripheralAnnouncement;
84
85
  protected updateWithServices(announcement: BlePeripheralAnnouncement): Promise<BlePeripheralAnnouncement>;
85
86
  protected discoverServices(announcement: BlePeripheralAnnouncement): Promise<string[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.19",
3
+ "version": "3.0.20",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",