incyclist-devices 1.4.94 → 1.4.95

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.
@@ -56,7 +56,9 @@ class BleInterface extends ble_1.BleInterfaceClass {
56
56
  if (this.logger) {
57
57
  this.logger.logEvent(event);
58
58
  }
59
- console.log('~~BLE:', event);
59
+ if (process.env.BLE_DEBUG) {
60
+ console.log('~~BLE:', event);
61
+ }
60
62
  }
61
63
  onStateChange(state) {
62
64
  if (state !== ble_1.BleState.POWERED_ON) {
@@ -566,8 +568,9 @@ class BleInterface extends ble_1.BleInterfaceClass {
566
568
  const onPeripheralFound = (peripheral, fromCache = false) => __awaiter(this, void 0, void 0, function* () {
567
569
  if (!peripheral || !peripheral.advertisement || !peripheral.advertisement.localName || !peripheral.advertisement.serviceUuids || peripheral.advertisement.serviceUuids.length === 0)
568
570
  return;
569
- if (fromCache)
571
+ if (fromCache) {
570
572
  this.logEvent({ message: 'adding from Cache', peripheral: peripheral.address });
573
+ }
571
574
  else {
572
575
  const { id, name, address, advertisement = {} } = peripheral;
573
576
  this.logEvent({ message: 'BLE scan: found device', peripheral: { id, name, address, services: advertisement.serviceUuids } });
@@ -584,66 +587,62 @@ class BleInterface extends ble_1.BleInterfaceClass {
584
587
  const services = connectedServices ? connectedServices.map(cs => cs.uuid) : undefined;
585
588
  const connectedPeripheral = connector.getPeripheral();
586
589
  const { id, name, address, advertisement = {} } = connectedPeripheral;
587
- const DeviceClasses = this.getDeviceClasses(connectedPeripheral, { profile, services });
590
+ const DeviceClasses = this.getDeviceClasses(connectedPeripheral, { profile, services }) || [];
588
591
  this.logEvent({ message: 'BLE scan: device connected', peripheral: { id, name, address, services: advertisement.serviceUuids }, services, classes: DeviceClasses.map(c => c.prototype.constructor.name) });
589
592
  let cntFound = 0;
590
- DeviceClasses.forEach((DeviceClass) => __awaiter(this, void 0, void 0, function* () {
591
- if (!DeviceClass)
592
- return;
593
- if (scanForDevice && cntFound > 0)
594
- return;
595
- const d = this.createDevice(DeviceClass, peripheral, characteristics);
596
- if (!d) {
597
- this.logEvent({ message: `${opStr}: could not create device `, DeviceClass });
598
- return;
599
- }
600
- try {
601
- this.logEvent({ message: `${opStr}: connecting `, device: d.name, profile: d.getProfile(), address: d.address });
602
- yield d.connect();
603
- }
604
- catch (err) {
605
- this.logEvent({ message: 'error', fn: 'onPeripheralFound()', error: err.message || err, stack: err.stack });
606
- }
607
- if (scanForDevice) {
608
- if ((id && id !== '' && d.id === id) ||
609
- (address && address !== '' && d.address === address) ||
610
- (name && name !== '' && d.name === name))
611
- cntFound++;
612
- }
613
- else
593
+ const DeviceClass = DeviceClasses.sort((a, b) => (a.detectionPriority || 0 - b.detectionPriority || 0))[0];
594
+ if (!DeviceClass)
595
+ return;
596
+ if (scanForDevice && cntFound > 0)
597
+ return;
598
+ const d = this.createDevice(DeviceClass, peripheral, characteristics);
599
+ if (!d) {
600
+ this.logEvent({ message: `${opStr}: could not create device `, DeviceClass });
601
+ return;
602
+ }
603
+ try {
604
+ this.logEvent({ message: `${opStr}: connecting `, device: d.name, profile: d.getProfile(), address: d.address });
605
+ yield d.connect();
606
+ }
607
+ catch (err) {
608
+ this.logEvent({ message: 'error', fn: 'onPeripheralFound()', error: err.message || err, stack: err.stack });
609
+ }
610
+ if (scanForDevice) {
611
+ if ((id && id !== '' && d.id === id) ||
612
+ (address && address !== '' && d.address === address) ||
613
+ (name && name !== '' && d.name === name))
614
614
  cntFound++;
615
- const existing = devicesProcessed.find(device => device.id === d.id && device.getProfile() === d.getProfile());
616
- if (!scanForDevice && cntFound > 0 && !existing) {
617
- this.logEvent({ message: `${opStr}: device found`, device: d.name, profile: d.getProfile(), address: d.address, services: d.services.join(',') });
618
- this.addDeviceToCache(d, peripheral.state === 'connected');
619
- devicesProcessed.push(d);
620
- this.emit('device', d);
621
- return;
622
- }
623
- if (scanForDevice && cntFound > 0) {
624
- this.logEvent({ message: `${opStr}: device found`, device: d.name, profile: d.getProfile(), address: d.address, services: d.services.join(',') });
625
- this.addDeviceToCache(d, peripheral.state === 'connected');
626
- devicesProcessed.push(d);
627
- this.emit('device', d);
628
- process.nextTick(() => {
629
- if (this.scanState.timeout) {
630
- clearTimeout(this.scanState.timeout);
631
- this.scanState.timeout = null;
632
- }
633
- this.logEvent({ message: `${opStr}: stop scanning`, requested: scanForDevice ? { name, address, profile } : undefined, });
634
- bleBinding.stopScanning(() => {
635
- this.getBinding().removeAllListeners('discover');
636
- this.scanState.isScanning = false;
637
- resolve([d]);
638
- });
615
+ }
616
+ else
617
+ cntFound++;
618
+ const existing = devicesProcessed.find(device => device.id === d.id && device.getProfile() === d.getProfile());
619
+ if (!scanForDevice && cntFound > 0 && !existing) {
620
+ this.logEvent({ message: `${opStr}: device found`, device: d.name, profile: d.getProfile(), address: d.address, services: d.services.join(',') });
621
+ this.addDeviceToCache(d, peripheral.state === 'connected');
622
+ devicesProcessed.push(d);
623
+ this.emit('device', d);
624
+ return;
625
+ }
626
+ if (scanForDevice && cntFound > 0) {
627
+ this.logEvent({ message: `${opStr}: device found`, device: d.name, profile: d.getProfile(), address: d.address, services: d.services.join(',') });
628
+ this.addDeviceToCache(d, peripheral.state === 'connected');
629
+ devicesProcessed.push(d);
630
+ this.emit('device', d);
631
+ process.nextTick(() => {
632
+ if (this.scanState.timeout) {
633
+ clearTimeout(this.scanState.timeout);
634
+ this.scanState.timeout = null;
635
+ }
636
+ this.logEvent({ message: `${opStr}: stop scanning`, requested: scanForDevice ? { name, address, profile } : undefined, });
637
+ bleBinding.stopScanning(() => {
638
+ this.getBinding().removeAllListeners('discover');
639
+ this.scanState.isScanning = false;
640
+ resolve([d]);
639
641
  });
640
- }
641
- }));
642
+ });
643
+ }
642
644
  });
643
645
  this.logEvent({ message: `${opStr}: start scanning`, requested: scanForDevice ? { name, address, profile } : undefined, timeout });
644
- this.peripheralCache.forEach(i => {
645
- onPeripheralFound(i.peripheral, true);
646
- });
647
646
  let services = [];
648
647
  if (scanForDevice) {
649
648
  if (props.requested instanceof ble_1.BleDeviceClass) {
package/lib/ble/fm.d.ts CHANGED
@@ -45,6 +45,7 @@ declare type IndoorBikeFeatures = {
45
45
  export default class BleFitnessMachineDevice extends BleDevice {
46
46
  static services: string[];
47
47
  static characteristics: string[];
48
+ static detectionPriority: number;
48
49
  data: IndoorBikeData;
49
50
  features: IndoorBikeFeatures;
50
51
  hasControl: boolean;
package/lib/ble/fm.js CHANGED
@@ -101,7 +101,6 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
101
101
  const hasStatus = characteristics.find(c => c === consts_1.FTMS_STATUS) !== undefined;
102
102
  const hasCP = characteristics.find(c => c === consts_1.FTMS_CP) !== undefined;
103
103
  const hasIndoorBike = characteristics.find(c => c === consts_1.INDOOR_BIKE_DATA) !== undefined;
104
- const hasTacx = characteristics.find(c => c === consts_1.TACX_FE_C_RX) !== undefined && characteristics.find(c => c === consts_1.TACX_FE_C_TX) !== undefined;
105
104
  return hasStatus && hasCP && hasIndoorBike;
106
105
  }
107
106
  subscribeWriteResponse(cuuid) {
@@ -185,8 +184,8 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
185
184
  return BleFitnessMachineDevice.services;
186
185
  }
187
186
  isBike() {
188
- return this.features !== undefined &&
189
- (this.features.targetSettings & TargetSettingFeatureFlag.IndoorBikeSimulationParametersSupported) !== 0;
187
+ return this.features === undefined ||
188
+ ((this.features.targetSettings & TargetSettingFeatureFlag.IndoorBikeSimulationParametersSupported) !== 0);
190
189
  }
191
190
  isPower() {
192
191
  if (this.hasService('1818'))
@@ -539,6 +538,7 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
539
538
  exports.default = BleFitnessMachineDevice;
540
539
  BleFitnessMachineDevice.services = [consts_1.FTMS];
541
540
  BleFitnessMachineDevice.characteristics = ['2acc', consts_1.INDOOR_BIKE_DATA, '2ad6', '2ad8', consts_1.FTMS_CP, consts_1.FTMS_STATUS];
541
+ BleFitnessMachineDevice.detectionPriority = 100;
542
542
  ble_interface_1.default.register('BleFitnessMachineDevice', 'fm', BleFitnessMachineDevice, BleFitnessMachineDevice.services);
543
543
  class FmAdapter extends Device_1.default {
544
544
  constructor(device, protocol) {
package/lib/ble/hrm.d.ts CHANGED
@@ -14,6 +14,7 @@ declare type HrmData = {
14
14
  export default class BleHrmDevice extends BleDevice {
15
15
  static services: string[];
16
16
  static characteristics: string[];
17
+ static detectionPriority: number;
17
18
  heartrate: number;
18
19
  rr: number;
19
20
  constructor(props?: any);
package/lib/ble/hrm.js CHANGED
@@ -65,6 +65,7 @@ class BleHrmDevice extends ble_device_1.BleDevice {
65
65
  exports.default = BleHrmDevice;
66
66
  BleHrmDevice.services = ['180d'];
67
67
  BleHrmDevice.characteristics = ['2a37', '2a38', '2a39', '2a3c'];
68
+ BleHrmDevice.detectionPriority = 1;
68
69
  ble_interface_1.default.register('BleHrmDevice', 'hr', BleHrmDevice, BleHrmDevice.services);
69
70
  class HrmAdapter extends Device_1.default {
70
71
  constructor(device, protocol) {
package/lib/ble/pwr.d.ts CHANGED
@@ -24,6 +24,7 @@ declare type CrankData = {
24
24
  export default class BleCyclingPowerDevice extends BleDevice {
25
25
  static services: string[];
26
26
  static characteristics: string[];
27
+ static detectionPriority: number;
27
28
  instantaneousPower: number;
28
29
  balance: number;
29
30
  accTorque: number;
package/lib/ble/pwr.js CHANGED
@@ -163,6 +163,7 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
163
163
  exports.default = BleCyclingPowerDevice;
164
164
  BleCyclingPowerDevice.services = [consts_1.CSP];
165
165
  BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
166
+ BleCyclingPowerDevice.detectionPriority = 1;
166
167
  ble_interface_1.default.register('BleCyclingPowerDevice', 'cp', BleCyclingPowerDevice, BleCyclingPowerDevice.services);
167
168
  class PwrAdapter extends Device_1.default {
168
169
  constructor(device, protocol) {
package/lib/ble/tacx.d.ts CHANGED
@@ -28,6 +28,7 @@ export default class TacxAdvancedFitnessMachineDevice extends BleFitnessMachineD
28
28
  static services: string[];
29
29
  static characteristics: string[];
30
30
  static PROFILE: string;
31
+ static detectionPriority: number;
31
32
  prevCrankData: CrankData;
32
33
  currentCrankData: CrankData;
33
34
  timeOffset: number;
package/lib/ble/tacx.js CHANGED
@@ -84,7 +84,6 @@ class TacxAdvancedFitnessMachineDevice extends fm_1.default {
84
84
  return false;
85
85
  const hasTacxCP = characteristics.find(c => (0, ble_1.matches)(c, consts_1.TACX_FE_C_RX)) !== undefined &&
86
86
  characteristics.find(c => (0, ble_1.matches)(c, consts_1.TACX_FE_C_TX)) !== undefined;
87
- const hasFTMS = characteristics.find(c => (0, ble_1.matches)(c, consts_1.FTMS_CP)) !== undefined;
88
87
  return hasTacxCP;
89
88
  }
90
89
  setCharacteristicUUIDs(uuids) {
@@ -658,6 +657,7 @@ exports.default = TacxAdvancedFitnessMachineDevice;
658
657
  TacxAdvancedFitnessMachineDevice.services = [consts_1.TACX_FE_C_BLE];
659
658
  TacxAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', consts_1.TACX_FE_C_RX, consts_1.TACX_FE_C_TX];
660
659
  TacxAdvancedFitnessMachineDevice.PROFILE = PROFILE_ID;
660
+ TacxAdvancedFitnessMachineDevice.detectionPriority = 10;
661
661
  ble_interface_1.default.register('TacxBleFEDevice', 'tacx-ble-fec', TacxAdvancedFitnessMachineDevice, TacxAdvancedFitnessMachineDevice.services);
662
662
  class TacxBleFEAdapter extends fm_1.FmAdapter {
663
663
  constructor(device, protocol) {
@@ -42,6 +42,7 @@ declare type CrankData = {
42
42
  export default class WahooAdvancedFitnessMachineDevice extends BleFitnessMachineDevice {
43
43
  static services: string[];
44
44
  static characteristics: string[];
45
+ static detectionPriority: number;
45
46
  prevCrankData: CrankData;
46
47
  currentCrankData: CrankData;
47
48
  timeOffset: number;
@@ -424,6 +424,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
424
424
  exports.default = WahooAdvancedFitnessMachineDevice;
425
425
  WahooAdvancedFitnessMachineDevice.services = [consts_1.CSP];
426
426
  WahooAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', consts_1.WAHOO_ADVANCED_TRAINER_CP];
427
+ WahooAdvancedFitnessMachineDevice.detectionPriority = 5;
427
428
  ble_interface_1.default.register('WahooAdvancedFitnessMachineDevice', 'wahoo-fm', WahooAdvancedFitnessMachineDevice, WahooAdvancedFitnessMachineDevice.services);
428
429
  class WahooAdvancedFmAdapter extends fm_1.FmAdapter {
429
430
  constructor(device, protocol) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.4.94",
3
+ "version": "1.4.95",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",