incyclist-devices 2.2.10-beta.0 → 2.3.0-beta.2

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.
Files changed (149) hide show
  1. package/lib/antv2/base/interface.js +2 -2
  2. package/lib/antv2/factories/index.d.ts +1 -0
  3. package/lib/antv2/factories/index.js +17 -0
  4. package/lib/antv2/fe/adapter.js +5 -4
  5. package/lib/antv2/index.d.ts +1 -0
  6. package/lib/antv2/index.js +12 -8
  7. package/lib/base/adpater.js +1 -1
  8. package/lib/ble/adapter-factory.d.ts +20 -24
  9. package/lib/ble/adapter-factory.js +13 -36
  10. package/lib/ble/base/adapter.d.ts +16 -5
  11. package/lib/ble/base/adapter.js +174 -57
  12. package/lib/ble/base/comms.d.ts +2 -74
  13. package/lib/ble/base/comms.js +3 -596
  14. package/lib/ble/base/interface.d.ts +96 -0
  15. package/lib/ble/base/interface.js +560 -0
  16. package/lib/ble/base/peripheral.d.ts +34 -0
  17. package/lib/ble/base/peripheral.js +286 -0
  18. package/lib/ble/base/sensor.d.ts +32 -0
  19. package/lib/ble/base/sensor.js +135 -0
  20. package/lib/ble/base/types.d.ts +7 -0
  21. package/lib/ble/base/types.js +7 -0
  22. package/lib/ble/bindings/mock.js +6 -0
  23. package/lib/ble/bindings/types.d.ts +3 -4
  24. package/lib/ble/ble-interface.d.ts +7 -4
  25. package/lib/ble/ble-interface.js +16 -2
  26. package/lib/ble/ble-peripheral.d.ts +1 -0
  27. package/lib/ble/ble-peripheral.js +7 -11
  28. package/lib/ble/consts.d.ts +0 -6
  29. package/lib/ble/consts.js +1 -7
  30. package/lib/ble/cp/adapter.d.ts +3 -3
  31. package/lib/ble/cp/adapter.js +12 -13
  32. package/lib/ble/cp/comm.d.ts +1 -1
  33. package/lib/ble/cp/comm.js +2 -2
  34. package/lib/ble/cp/index.d.ts +1 -1
  35. package/lib/ble/cp/index.js +2 -2
  36. package/lib/ble/cp/sensor.d.ts +27 -0
  37. package/lib/ble/cp/sensor.js +107 -0
  38. package/lib/ble/elite/comms.d.ts +1 -1
  39. package/lib/ble/elite/comms.js +2 -2
  40. package/lib/ble/factories/adapter-factory.d.ts +34 -0
  41. package/lib/ble/factories/adapter-factory.js +137 -0
  42. package/lib/ble/factories/index.d.ts +2 -0
  43. package/lib/ble/factories/index.js +18 -0
  44. package/lib/ble/factories/interface-factory.d.ts +7 -0
  45. package/lib/ble/factories/interface-factory.js +18 -0
  46. package/lib/ble/factories/types.d.ts +18 -0
  47. package/lib/ble/factories/types.js +2 -0
  48. package/lib/ble/fm/adapter.d.ts +9 -4
  49. package/lib/ble/fm/adapter.js +105 -108
  50. package/lib/ble/fm/comms.d.ts +1 -1
  51. package/lib/ble/fm/comms.js +3 -3
  52. package/lib/ble/fm/consts.d.ts +93 -0
  53. package/lib/ble/fm/consts.js +55 -1
  54. package/lib/ble/fm/index.d.ts +1 -1
  55. package/lib/ble/fm/index.js +2 -2
  56. package/lib/ble/fm/sensor.d.ts +44 -0
  57. package/lib/ble/fm/sensor.js +384 -0
  58. package/lib/ble/hr/adapter.d.ts +3 -3
  59. package/lib/ble/hr/adapter.js +5 -8
  60. package/lib/ble/hr/comm.d.ts +1 -1
  61. package/lib/ble/hr/comm.js +2 -2
  62. package/lib/ble/hr/index.d.ts +1 -1
  63. package/lib/ble/hr/index.js +2 -2
  64. package/lib/ble/hr/sensor.d.ts +17 -0
  65. package/lib/ble/hr/sensor.js +52 -0
  66. package/lib/ble/index.d.ts +4 -3
  67. package/lib/ble/index.js +29 -13
  68. package/lib/ble/tacx/adapter.d.ts +4 -2
  69. package/lib/ble/tacx/adapter.js +26 -66
  70. package/lib/ble/tacx/comms.d.ts +1 -1
  71. package/lib/ble/tacx/comms.js +2 -2
  72. package/lib/ble/tacx/consts.d.ts +23 -0
  73. package/lib/ble/tacx/consts.js +27 -0
  74. package/lib/ble/tacx/index.d.ts +1 -1
  75. package/lib/ble/tacx/index.js +2 -2
  76. package/lib/ble/tacx/sensor.d.ts +63 -0
  77. package/lib/ble/tacx/sensor.js +596 -0
  78. package/lib/ble/types.d.ts +81 -52
  79. package/lib/ble/utils.d.ts +7 -2
  80. package/lib/ble/utils.js +93 -9
  81. package/lib/ble/wahoo/adapter.d.ts +2 -2
  82. package/lib/ble/wahoo/adapter.js +4 -72
  83. package/lib/ble/wahoo/comms.d.ts +1 -1
  84. package/lib/ble/wahoo/comms.js +2 -2
  85. package/lib/ble/wahoo/consts.d.ts +16 -0
  86. package/lib/ble/wahoo/consts.js +7 -0
  87. package/lib/ble/wahoo/index.d.ts +1 -1
  88. package/lib/ble/wahoo/index.js +2 -2
  89. package/lib/ble/wahoo/sensor.d.ts +48 -0
  90. package/lib/ble/wahoo/sensor.js +356 -0
  91. package/lib/direct-connect/base/comms.d.ts +3 -0
  92. package/lib/direct-connect/base/comms.js +7 -0
  93. package/lib/direct-connect/base/interface.d.ts +75 -0
  94. package/lib/direct-connect/base/interface.js +311 -0
  95. package/lib/direct-connect/base/peripheral.d.ts +50 -0
  96. package/lib/direct-connect/base/peripheral.js +451 -0
  97. package/lib/direct-connect/base/sensor.d.ts +3 -0
  98. package/lib/direct-connect/base/sensor.js +7 -0
  99. package/lib/direct-connect/bindings/index.d.ts +1 -0
  100. package/lib/direct-connect/bindings/index.js +17 -0
  101. package/lib/direct-connect/bindings/types.d.ts +37 -0
  102. package/lib/direct-connect/bindings/types.js +2 -0
  103. package/lib/direct-connect/consts.d.ts +17 -0
  104. package/lib/direct-connect/consts.js +20 -0
  105. package/lib/direct-connect/index.d.ts +3 -0
  106. package/lib/direct-connect/index.js +22 -0
  107. package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
  108. package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
  109. package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
  110. package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
  111. package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
  112. package/lib/direct-connect/messages/DiscoverServices.js +33 -0
  113. package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
  114. package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
  115. package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
  116. package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
  117. package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
  118. package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
  119. package/lib/direct-connect/messages/error.d.ts +5 -0
  120. package/lib/direct-connect/messages/error.js +18 -0
  121. package/lib/direct-connect/messages/factory.d.ts +6 -0
  122. package/lib/direct-connect/messages/factory.js +44 -0
  123. package/lib/direct-connect/messages/index.d.ts +9 -0
  124. package/lib/direct-connect/messages/index.js +25 -0
  125. package/lib/direct-connect/messages/message.d.ts +20 -0
  126. package/lib/direct-connect/messages/message.js +90 -0
  127. package/lib/direct-connect/types.d.ts +24 -0
  128. package/lib/direct-connect/types.js +9 -0
  129. package/lib/direct-connect/utils.d.ts +5 -0
  130. package/lib/direct-connect/utils.js +73 -0
  131. package/lib/factories/adapters.js +14 -4
  132. package/lib/factories/interfaces.d.ts +2 -1
  133. package/lib/factories/interfaces.js +10 -7
  134. package/lib/index.d.ts +5 -4
  135. package/lib/index.js +6 -2
  136. package/lib/modes/antble-smarttrainer.d.ts +2 -16
  137. package/lib/modes/antble-smarttrainer.js +1 -98
  138. package/lib/modes/types.d.ts +1 -5
  139. package/lib/serial/bindings/tcp.d.ts +5 -4
  140. package/lib/serial/bindings/tcp.js +16 -23
  141. package/lib/types/device.d.ts +2 -1
  142. package/lib/types/device.js +1 -0
  143. package/lib/utils/calculations.d.ts +0 -1
  144. package/lib/utils/calculations.js +6 -22
  145. package/lib/utils/operation.d.ts +17 -0
  146. package/lib/utils/operation.js +20 -0
  147. package/lib/utils/task.d.ts +44 -0
  148. package/lib/utils/task.js +127 -0
  149. package/package.json +3 -1
package/lib/ble/consts.js CHANGED
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ELITE_TRAINER_SVC = exports.WAHOO_ADVANCED_TRAINER_CP_FULL = exports.WAHOO_ADVANCED_FTMS = exports.WAHOO_ADVANCED_TRAINER_CP = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.POWER_RANGE = exports.RES_LEVEL_RANGE = exports.FTMS_FEATURE = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
4
- exports.TACX_FE_C_BLE = '6e40fec1';
5
- exports.TACX_FE_C_RX = '6e40fec2';
6
- exports.TACX_FE_C_TX = '6e40fec3';
3
+ exports.ELITE_TRAINER_SVC = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.POWER_RANGE = exports.RES_LEVEL_RANGE = exports.FTMS_FEATURE = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = void 0;
7
4
  exports.FTMS = '1826';
8
5
  exports.FTMS_CP = '2ad9';
9
6
  exports.FTMS_STATUS = '2ada';
@@ -17,7 +14,4 @@ exports.CSP_FEATURE = '2a65';
17
14
  exports.HR_MEASUREMENT = '2a37';
18
15
  exports.CSC = '1816';
19
16
  exports.CSC_MEASUREMENT = '2a5b';
20
- exports.WAHOO_ADVANCED_TRAINER_CP = 'a026e005';
21
- exports.WAHOO_ADVANCED_FTMS = 'a026ee0b';
22
- exports.WAHOO_ADVANCED_TRAINER_CP_FULL = 'A026E005-0A7D-4AB3-97FA-F1500F9FEB8B';
23
17
  exports.ELITE_TRAINER_SVC = '347b0001';
@@ -1,7 +1,7 @@
1
- import BleCyclingPowerDevice from './comm';
1
+ import BleCyclingPowerDevice from './sensor';
2
2
  import BleAdapter from '../base/adapter';
3
3
  import { PowerData } from './types';
4
- import { BleDeviceSettings } from '../types';
4
+ import { BleDeviceSettings, IBlePeripheral } from '../types';
5
5
  import { DeviceProperties, IncyclistBikeData, IncyclistAdapterData, ControllerConfig, IAdapter } from '../../types';
6
6
  import { LegacyProfile } from '../../antv2/types';
7
7
  import { UpdateRequest } from '../../modes/types';
@@ -11,8 +11,8 @@ export default class PwrAdapter extends BleAdapter<PowerData, BleCyclingPowerDev
11
11
  distanceInternal: number;
12
12
  constructor(settings: BleDeviceSettings, props?: DeviceProperties);
13
13
  isSame(device: IAdapter): boolean;
14
+ updateSensor(peripheral: IBlePeripheral): void;
14
15
  getProfile(): LegacyProfile;
15
- getName(): string;
16
16
  getDisplayName(): string;
17
17
  mapData(deviceData: PowerData): IncyclistBikeData;
18
18
  transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const gd_eventlog_1 = require("gd-eventlog");
16
- const comm_1 = __importDefault(require("./comm"));
16
+ const sensor_1 = __importDefault(require("./sensor"));
17
17
  const adapter_1 = __importDefault(require("../base/adapter"));
18
18
  const types_1 = require("../../types");
19
19
  const power_meter_1 = __importDefault(require("../../modes/power-meter"));
@@ -22,9 +22,7 @@ class PwrAdapter extends adapter_1.default {
22
22
  super(settings, props);
23
23
  this.distanceInternal = 0;
24
24
  this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
25
- const { id, address, name } = settings;
26
- const logger = this.logger;
27
- this.device = new comm_1.default({ id, address, name, logger });
25
+ this.device = new sensor_1.default(this.getPeripheral(), { logger: this.logger });
28
26
  this.capabilities = [
29
27
  types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Speed
30
28
  ];
@@ -34,19 +32,20 @@ class PwrAdapter extends adapter_1.default {
34
32
  return false;
35
33
  return this.isEqual(device.settings);
36
34
  }
35
+ updateSensor(peripheral) {
36
+ this.device = new sensor_1.default(peripheral, { logger: this.logger });
37
+ }
37
38
  getProfile() {
38
39
  return 'Power Meter';
39
40
  }
40
- getName() {
41
- return `${this.device.name}`;
42
- }
43
41
  getDisplayName() {
44
- const { name } = this.device;
42
+ const name = this.getName();
45
43
  const { instantaneousPower: power } = this.deviceData;
46
44
  const powerStr = power ? ` (${power})` : '';
47
45
  return `${name}${powerStr}`;
48
46
  }
49
47
  mapData(deviceData) {
48
+ var _a, _b, _c;
50
49
  const data = {
51
50
  isPedalling: false,
52
51
  power: 0,
@@ -57,9 +56,9 @@ class PwrAdapter extends adapter_1.default {
57
56
  slope: undefined,
58
57
  time: undefined
59
58
  };
60
- data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
61
- data.pedalRpm = (deviceData.rpm !== undefined ? deviceData.rpm : data.pedalRpm);
62
- data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
59
+ data.power = (_a = deviceData === null || deviceData === void 0 ? void 0 : deviceData.instantaneousPower) !== null && _a !== void 0 ? _a : data.power;
60
+ data.pedalRpm = (_b = deviceData === null || deviceData === void 0 ? void 0 : deviceData.rpm) !== null && _b !== void 0 ? _b : data.pedalRpm;
61
+ data.time = (_c = deviceData === null || deviceData === void 0 ? void 0 : deviceData.time) !== null && _c !== void 0 ? _c : data.time;
63
62
  data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
64
63
  return data;
65
64
  }
@@ -93,10 +92,10 @@ class PwrAdapter extends adapter_1.default {
93
92
  try {
94
93
  if (this.isPaused() || this.isStopped())
95
94
  return;
96
- return yield this.getCyclingMode().sendBikeUpdate(request);
95
+ return this.getCyclingMode().sendBikeUpdate(request);
97
96
  }
98
97
  catch (err) {
99
- this.logEvent({ message: 'Error', fn: 'sendUpdate', error: err.message });
98
+ this.logEvent({ message: 'Error', fn: 'BleCP:sendUpdate', error: err.message });
100
99
  }
101
100
  });
102
101
  }
@@ -1,5 +1,5 @@
1
1
  import { CrankData, PowerData } from './types';
2
- import { BleComms } from '../base/comms';
2
+ import { BleComms } from '../base/sensor';
3
3
  import { LegacyProfile } from '../../antv2/types';
4
4
  import { BleProtocol, IBlePeripheralConnector } from '../types';
5
5
  export default class BleCyclingPowerDevice extends BleComms {
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const consts_1 = require("../consts");
4
4
  const utils_1 = require("../utils");
5
- const comms_1 = require("../base/comms");
6
- class BleCyclingPowerDevice extends comms_1.BleComms {
5
+ const sensor_1 = require("../base/sensor");
6
+ class BleCyclingPowerDevice extends sensor_1.BleComms {
7
7
  constructor() {
8
8
  super(...arguments);
9
9
  this.instantaneousPower = undefined;
@@ -1,4 +1,4 @@
1
1
  import { PowerData, CrankData } from './types';
2
2
  import BlePwrAdapter from './adapter';
3
- import BlePwrComms from './comm';
3
+ import BlePwrComms from './sensor';
4
4
  export { PowerData, CrankData, BlePwrAdapter, BlePwrComms };
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BlePwrComms = exports.BlePwrAdapter = void 0;
7
7
  const adapter_1 = __importDefault(require("./adapter"));
8
8
  exports.BlePwrAdapter = adapter_1.default;
9
- const comm_1 = __importDefault(require("./comm"));
10
- exports.BlePwrComms = comm_1.default;
9
+ const sensor_1 = __importDefault(require("./sensor"));
10
+ exports.BlePwrComms = sensor_1.default;
@@ -0,0 +1,27 @@
1
+ import { CrankData, PowerData } from './types';
2
+ import { LegacyProfile } from '../../antv2/types';
3
+ import { BleProtocol } from '../types';
4
+ import { TBleSensor } from '../base/sensor';
5
+ export default class BleCyclingPowerDevice extends TBleSensor {
6
+ static readonly profile: LegacyProfile;
7
+ static readonly protocol: BleProtocol;
8
+ static readonly services: string[];
9
+ static readonly characteristics: string[];
10
+ static readonly detectionPriority = 1;
11
+ instantaneousPower: number;
12
+ balance: number;
13
+ accTorque: number;
14
+ rpm: number;
15
+ timeOffset: number;
16
+ time: number;
17
+ currentCrankData: CrankData;
18
+ prevCrankData: CrankData;
19
+ parseCrankData(crankData: any): {
20
+ rpm: number;
21
+ time: any;
22
+ };
23
+ parsePower(_data: Uint8Array): PowerData;
24
+ protected getRequiredCharacteristics(): Array<string>;
25
+ onData(characteristic: string, data: Buffer): boolean;
26
+ reset(): void;
27
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const consts_1 = require("../consts");
4
+ const utils_1 = require("../utils");
5
+ const sensor_1 = require("../base/sensor");
6
+ class BleCyclingPowerDevice extends sensor_1.TBleSensor {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.instantaneousPower = undefined;
10
+ this.balance = undefined;
11
+ this.accTorque = undefined;
12
+ this.rpm = undefined;
13
+ this.timeOffset = 0;
14
+ this.time = undefined;
15
+ this.currentCrankData = undefined;
16
+ this.prevCrankData = undefined;
17
+ }
18
+ parseCrankData(crankData) {
19
+ if (!this.prevCrankData)
20
+ this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
21
+ const c = this.currentCrankData = crankData;
22
+ const p = this.prevCrankData;
23
+ let rpm = this.rpm;
24
+ let hasUpdate = c.time !== p.time;
25
+ if (hasUpdate) {
26
+ let time = c.time - p.time;
27
+ let revs = c.revolutions - p.revolutions;
28
+ if (c.time < p.time) {
29
+ time += 0x10000;
30
+ this.timeOffset += 0x10000;
31
+ }
32
+ if (c.revolutions < p.revolutions)
33
+ revs += 0x10000;
34
+ rpm = 1024 * 60 * revs / time;
35
+ }
36
+ else if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
37
+ rpm = 0;
38
+ }
39
+ const cntUpdateMissing = p.cntUpdateMissing;
40
+ this.prevCrankData = this.currentCrankData;
41
+ if (hasUpdate)
42
+ this.prevCrankData.cntUpdateMissing = 0;
43
+ else
44
+ this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
45
+ return { rpm, time: this.timeOffset + c.time };
46
+ }
47
+ parsePower(_data) {
48
+ const data = Buffer.from(_data);
49
+ try {
50
+ let offset = 4;
51
+ const flags = data.readUInt16LE(0);
52
+ this.instantaneousPower = data.readUInt16LE(2);
53
+ if (flags & 0x1)
54
+ this.balance = data.readUInt8(offset++);
55
+ if (flags & 0x4) {
56
+ this.accTorque = data.readUInt16LE(offset);
57
+ offset += 2;
58
+ }
59
+ if (flags & 0x10) {
60
+ offset += 6;
61
+ }
62
+ if (flags & 0x20) {
63
+ const crankData = {
64
+ revolutions: data.readUInt16LE(offset),
65
+ time: data.readUInt16LE(offset + 2)
66
+ };
67
+ const { rpm, time } = this.parseCrankData(crankData);
68
+ this.rpm = rpm;
69
+ this.time = time;
70
+ }
71
+ }
72
+ catch (err) {
73
+ }
74
+ const { instantaneousPower, balance, accTorque, rpm, time } = this;
75
+ return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
76
+ }
77
+ getRequiredCharacteristics() {
78
+ return [consts_1.CSP_MEASUREMENT];
79
+ }
80
+ onData(characteristic, data) {
81
+ const hasData = super.onData(characteristic, data);
82
+ if (!hasData)
83
+ return false;
84
+ if ((0, utils_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
85
+ const res = this.parsePower(data);
86
+ this.emit('data', res);
87
+ return false;
88
+ }
89
+ return true;
90
+ }
91
+ reset() {
92
+ this.instantaneousPower = undefined;
93
+ this.balance = undefined;
94
+ this.accTorque = undefined;
95
+ this.rpm = undefined;
96
+ this.timeOffset = 0;
97
+ this.time = undefined;
98
+ this.currentCrankData = undefined;
99
+ this.prevCrankData = undefined;
100
+ }
101
+ }
102
+ BleCyclingPowerDevice.profile = 'Power Meter';
103
+ BleCyclingPowerDevice.protocol = 'cp';
104
+ BleCyclingPowerDevice.services = [consts_1.CSP];
105
+ BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
106
+ BleCyclingPowerDevice.detectionPriority = 1;
107
+ exports.default = BleCyclingPowerDevice;
@@ -1,5 +1,5 @@
1
1
  import { LegacyProfile } from "../../antv2/types";
2
- import { BleComms } from "../base/comms";
2
+ import { BleComms } from "../base/sensor";
3
3
  import { CrankData, PowerData } from "../cp";
4
4
  import { BleProtocol, IBlePeripheralConnector } from "../types";
5
5
  export default class BleEliteDevice extends BleComms {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const _1 = require(".");
4
- const comms_1 = require("../base/comms");
4
+ const sensor_1 = require("../base/sensor");
5
5
  const consts_1 = require("../consts");
6
6
  const utils_1 = require("../utils");
7
- class BleEliteDevice extends comms_1.BleComms {
7
+ class BleEliteDevice extends sensor_1.BleComms {
8
8
  constructor(props) {
9
9
  super(props);
10
10
  this.instantaneousPower = undefined;
@@ -0,0 +1,34 @@
1
+ import BleAdapter from "../base/adapter";
2
+ import { BleDeviceSettings, BleProtocol } from "../types";
3
+ import { DeviceProperties } from "../../types";
4
+ import { BleDeviceData } from "../base/types";
5
+ import { TBleSensor } from "../base/sensor";
6
+ import { BleAdapterInfo, TBleAdapterFactory } from "./types";
7
+ export declare class BleAdapterFactory<T extends TBleSensor> implements TBleAdapterFactory<T> {
8
+ transport: string;
9
+ static readonly _instances: Record<string, BleAdapterFactory<any>>;
10
+ implementations: BleAdapterInfo<any>[];
11
+ instances: Array<BleAdapter<BleDeviceData, T>>;
12
+ static getInstance(transport: string): BleAdapterFactory<any>;
13
+ constructor(transport: string);
14
+ getAdapterInfo(protocol: BleProtocol): BleAdapterInfo<T>;
15
+ getAll(): BleAdapterInfo<T>[];
16
+ createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, T>;
17
+ removeInstance(query: {
18
+ settings?: BleDeviceSettings;
19
+ adapter?: BleAdapter<BleDeviceData, T>;
20
+ }): void;
21
+ find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData, T>;
22
+ register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData, T>, Sensor: typeof TBleSensor): void;
23
+ getAllInstances(): Array<BleAdapter<BleDeviceData, T>>;
24
+ getAllSupportedSensors(): (typeof TBleSensor)[];
25
+ getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData, T>)>;
26
+ getServices(info: BleAdapterInfo<T>): string[];
27
+ getAllSupportedServices(): string[];
28
+ getProtocol(services: string[]): BleProtocol;
29
+ protected getMatchingSensors(services: string[], props?: {
30
+ protocol?: BleProtocol;
31
+ services?: string[];
32
+ }): TBleSensor[];
33
+ getSensorsFromServices(sensorTypes: (typeof TBleSensor)[], services: string | string[]): TBleSensor[];
34
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BleAdapterFactory = void 0;
4
+ const utils_1 = require("../utils");
5
+ class BleAdapterFactory {
6
+ static getInstance(transport) {
7
+ if (!BleAdapterFactory._instances[transport])
8
+ BleAdapterFactory._instances[transport] = new BleAdapterFactory(transport);
9
+ return BleAdapterFactory._instances[transport];
10
+ }
11
+ constructor(transport) {
12
+ this.transport = transport;
13
+ this.implementations = [];
14
+ this.instances = [];
15
+ }
16
+ getAdapterInfo(protocol) {
17
+ return this.implementations.find(a => a.protocol === protocol);
18
+ }
19
+ getAll() {
20
+ return this.implementations;
21
+ }
22
+ createInstance(settings, props) {
23
+ let { profile, protocol } = settings;
24
+ const adapterSettings = Object.assign({}, settings);
25
+ if (profile) {
26
+ try {
27
+ const mapping = (0, utils_1.mapLegacyProfile)(profile);
28
+ protocol = adapterSettings.protocol = mapping.protocol;
29
+ delete adapterSettings.profile;
30
+ }
31
+ catch (_a) {
32
+ delete settings.profile;
33
+ }
34
+ }
35
+ const existing = this.find(adapterSettings);
36
+ if (existing) {
37
+ existing.setProperties(props);
38
+ return existing;
39
+ }
40
+ const info = this.getAdapterInfo(protocol);
41
+ if (!(info === null || info === void 0 ? void 0 : info.Adapter))
42
+ return;
43
+ const AdapterClass = info.Adapter;
44
+ const adapter = new AdapterClass(adapterSettings, props);
45
+ this.instances.push(adapter);
46
+ return adapter;
47
+ }
48
+ removeInstance(query) {
49
+ let idx = -1;
50
+ if (query.settings) {
51
+ idx = this.instances.findIndex(a => a.isEqual(query.settings));
52
+ }
53
+ else if (query.adapter) {
54
+ idx = this.instances.findIndex(a => a.isEqual(query.adapter.getSettings()));
55
+ }
56
+ if (idx !== -1)
57
+ this.instances.splice(idx);
58
+ }
59
+ find(settings) {
60
+ return this.instances.find(a => a.isEqual(settings));
61
+ }
62
+ register(protocol, Adapter, Sensor) {
63
+ const info = { protocol, Adapter, Sensor };
64
+ const existing = this.implementations.findIndex(a => a.protocol === protocol);
65
+ if (existing !== -1)
66
+ this.implementations[existing] = info;
67
+ else
68
+ this.implementations.push(info);
69
+ }
70
+ getAllInstances() {
71
+ return this.instances;
72
+ }
73
+ getAllSupportedSensors() {
74
+ const supported = this.getAll();
75
+ return supported.map(info => info.Sensor);
76
+ }
77
+ getAllSupportedAdapters() {
78
+ const supported = this.getAll();
79
+ return supported.map(info => info.Adapter);
80
+ }
81
+ getServices(info) {
82
+ const Sensor = info.Sensor;
83
+ if (!Sensor)
84
+ return [];
85
+ const sensor = new Sensor(null, {});
86
+ return sensor.getServiceUUids().map(utils_1.fullUUID);
87
+ }
88
+ getAllSupportedServices() {
89
+ const supported = this.getAll();
90
+ const res = [];
91
+ if (supported && supported.length > 0) {
92
+ supported.forEach(info => {
93
+ const services = this.getServices(info);
94
+ services.forEach(s => {
95
+ if (!res.includes(s))
96
+ res.push(s);
97
+ });
98
+ });
99
+ }
100
+ return res;
101
+ }
102
+ getProtocol(services) {
103
+ const matching = this.getMatchingSensors(services);
104
+ if (!(matching === null || matching === void 0 ? void 0 : matching.length)) {
105
+ return;
106
+ }
107
+ if (matching.length === 1) {
108
+ return matching[0].getProtocol();
109
+ }
110
+ matching.sort((a, b) => b.getDetectionPriority() - a.getDetectionPriority());
111
+ return matching[0].getProtocol();
112
+ }
113
+ getMatchingSensors(services, props = {}) {
114
+ let sensors;
115
+ const { protocol } = props;
116
+ const classes = this.getAllSupportedSensors();
117
+ sensors = this.getSensorsFromServices(classes, services);
118
+ if (protocol && (sensors === null || sensors === void 0 ? void 0 : sensors.length) > 0) {
119
+ return sensors.filter(sensor => {
120
+ if (sensor.getProtocol() !== protocol)
121
+ return false;
122
+ return true;
123
+ });
124
+ }
125
+ return sensors;
126
+ }
127
+ getSensorsFromServices(sensorTypes, services) {
128
+ if (!sensorTypes || !Array.isArray(sensorTypes) || sensorTypes.length === 0) {
129
+ return [];
130
+ }
131
+ let serviceUUIDs = Array.isArray(services) ? services : [services];
132
+ const types = sensorTypes.map(SensorType => new SensorType(null)).filter(sensor => sensor.isMatching(serviceUUIDs));
133
+ return types;
134
+ }
135
+ }
136
+ exports.BleAdapterFactory = BleAdapterFactory;
137
+ BleAdapterFactory._instances = {};
@@ -0,0 +1,2 @@
1
+ export * from './adapter-factory';
2
+ export * from './interface-factory';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./adapter-factory"), exports);
18
+ __exportStar(require("./interface-factory"), exports);
@@ -0,0 +1,7 @@
1
+ import { InterfaceFactory } from "../base/types";
2
+ import { IBleInterface } from "../types";
3
+ export declare class BleMultiTransportInterfaceFactory {
4
+ static readonly registered: Record<string, typeof InterfaceFactory>;
5
+ static register(transport: string, Class: typeof InterfaceFactory): void;
6
+ static createInstance(transport: string): IBleInterface<any>;
7
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BleMultiTransportInterfaceFactory = void 0;
4
+ class BleMultiTransportInterfaceFactory {
5
+ static register(transport, Class) {
6
+ this.registered[transport] = Class;
7
+ }
8
+ static createInstance(transport) {
9
+ var _a;
10
+ if (this.registered[transport]) {
11
+ const Class = this.registered[transport];
12
+ const iface = (_a = new Class()) === null || _a === void 0 ? void 0 : _a.getInterface();
13
+ return iface;
14
+ }
15
+ }
16
+ }
17
+ exports.BleMultiTransportInterfaceFactory = BleMultiTransportInterfaceFactory;
18
+ BleMultiTransportInterfaceFactory.registered = {};
@@ -0,0 +1,18 @@
1
+ import { DeviceProperties } from "../../types";
2
+ import BleAdapter from "../base/adapter";
3
+ import { TBleSensor } from "../base/sensor";
4
+ import { BleDeviceData } from "../base/types";
5
+ import { BleDeviceSettings, BleProtocol } from "../types";
6
+ export interface TBleAdapterFactory<T extends TBleSensor> {
7
+ createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, T>;
8
+ removeInstance(query: {
9
+ settings?: BleDeviceSettings;
10
+ adapter?: BleAdapter<BleDeviceData, T>;
11
+ }): void;
12
+ getProtocol(services: string[]): BleProtocol;
13
+ }
14
+ export interface BleAdapterInfo<T extends TBleSensor> {
15
+ protocol: BleProtocol;
16
+ Adapter: typeof BleAdapter<BleDeviceData, T>;
17
+ Sensor: typeof TBleSensor;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,8 @@
1
- import BleFitnessMachineDevice from './comms';
1
+ import BleFitnessMachineDevice from './sensor';
2
2
  import BleAdapter from '../base/adapter';
3
3
  import ICyclingMode, { CyclingMode } from '../../modes/types';
4
4
  import { IndoorBikeData } from './types';
5
- import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from '../types';
5
+ import { BleDeviceProperties, BleDeviceSettings, BleStartProperties, IBlePeripheral } from '../types';
6
6
  import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../../types';
7
7
  import { LegacyProfile } from '../../antv2/types';
8
8
  export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessMachineDevice> {
@@ -10,14 +10,19 @@ export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessM
10
10
  distanceInternal: number;
11
11
  connectPromise: Promise<boolean>;
12
12
  constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
13
+ updateSensor(peripheral: IBlePeripheral): void;
13
14
  isSame(device: IAdapter): boolean;
14
- getName(): string;
15
15
  isControllable(): boolean;
16
16
  getSupportedCyclingModes(): Array<typeof CyclingMode>;
17
17
  getDefaultCyclingMode(): ICyclingMode;
18
18
  mapData(deviceData: IndoorBikeData): IncyclistBikeData;
19
19
  transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
20
- start(props?: BleStartProperties): Promise<any>;
20
+ protected checkResume(): boolean[];
21
+ protected initControl(_startProps?: BleStartProperties): Promise<void>;
22
+ protected setConstants(): void;
23
+ protected establishControl(): Promise<boolean>;
24
+ protected sendInitialRequest(): Promise<void>;
25
+ protected checkCapabilities(): void;
21
26
  sendUpdate(request: any, enforced?: boolean): Promise<void>;
22
27
  sendInitCommands(): Promise<boolean>;
23
28
  }