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

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 (151) 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.d.ts +4 -0
  8. package/lib/base/adpater.js +17 -3
  9. package/lib/ble/adapter-factory.d.ts +20 -24
  10. package/lib/ble/adapter-factory.js +13 -36
  11. package/lib/ble/base/adapter.d.ts +19 -5
  12. package/lib/ble/base/adapter.js +211 -62
  13. package/lib/ble/base/comms.d.ts +2 -74
  14. package/lib/ble/base/comms.js +3 -596
  15. package/lib/ble/base/interface.d.ts +102 -0
  16. package/lib/ble/base/interface.js +591 -0
  17. package/lib/ble/base/peripheral.d.ts +35 -0
  18. package/lib/ble/base/peripheral.js +311 -0
  19. package/lib/ble/base/sensor.d.ts +32 -0
  20. package/lib/ble/base/sensor.js +135 -0
  21. package/lib/ble/base/types.d.ts +7 -0
  22. package/lib/ble/base/types.js +7 -0
  23. package/lib/ble/bindings/mock.js +6 -0
  24. package/lib/ble/bindings/types.d.ts +3 -4
  25. package/lib/ble/ble-interface.d.ts +7 -4
  26. package/lib/ble/ble-interface.js +16 -2
  27. package/lib/ble/ble-peripheral.d.ts +1 -0
  28. package/lib/ble/ble-peripheral.js +7 -11
  29. package/lib/ble/consts.d.ts +0 -6
  30. package/lib/ble/consts.js +1 -7
  31. package/lib/ble/cp/adapter.d.ts +3 -3
  32. package/lib/ble/cp/adapter.js +12 -13
  33. package/lib/ble/cp/comm.d.ts +1 -1
  34. package/lib/ble/cp/comm.js +2 -2
  35. package/lib/ble/cp/index.d.ts +1 -1
  36. package/lib/ble/cp/index.js +2 -2
  37. package/lib/ble/cp/sensor.d.ts +27 -0
  38. package/lib/ble/cp/sensor.js +107 -0
  39. package/lib/ble/elite/comms.d.ts +1 -1
  40. package/lib/ble/elite/comms.js +2 -2
  41. package/lib/ble/factories/adapter-factory.d.ts +34 -0
  42. package/lib/ble/factories/adapter-factory.js +137 -0
  43. package/lib/ble/factories/index.d.ts +2 -0
  44. package/lib/ble/factories/index.js +18 -0
  45. package/lib/ble/factories/interface-factory.d.ts +7 -0
  46. package/lib/ble/factories/interface-factory.js +18 -0
  47. package/lib/ble/factories/types.d.ts +18 -0
  48. package/lib/ble/factories/types.js +2 -0
  49. package/lib/ble/fm/adapter.d.ts +12 -6
  50. package/lib/ble/fm/adapter.js +100 -108
  51. package/lib/ble/fm/comms.d.ts +1 -1
  52. package/lib/ble/fm/comms.js +3 -3
  53. package/lib/ble/fm/consts.d.ts +93 -0
  54. package/lib/ble/fm/consts.js +55 -1
  55. package/lib/ble/fm/index.d.ts +1 -1
  56. package/lib/ble/fm/index.js +2 -2
  57. package/lib/ble/fm/sensor.d.ts +44 -0
  58. package/lib/ble/fm/sensor.js +384 -0
  59. package/lib/ble/hr/adapter.d.ts +3 -3
  60. package/lib/ble/hr/adapter.js +5 -8
  61. package/lib/ble/hr/comm.d.ts +1 -1
  62. package/lib/ble/hr/comm.js +2 -2
  63. package/lib/ble/hr/index.d.ts +1 -1
  64. package/lib/ble/hr/index.js +2 -2
  65. package/lib/ble/hr/sensor.d.ts +17 -0
  66. package/lib/ble/hr/sensor.js +52 -0
  67. package/lib/ble/index.d.ts +4 -3
  68. package/lib/ble/index.js +29 -13
  69. package/lib/ble/tacx/adapter.d.ts +4 -2
  70. package/lib/ble/tacx/adapter.js +26 -66
  71. package/lib/ble/tacx/comms.d.ts +1 -1
  72. package/lib/ble/tacx/comms.js +2 -2
  73. package/lib/ble/tacx/consts.d.ts +23 -0
  74. package/lib/ble/tacx/consts.js +27 -0
  75. package/lib/ble/tacx/index.d.ts +1 -1
  76. package/lib/ble/tacx/index.js +2 -2
  77. package/lib/ble/tacx/sensor.d.ts +63 -0
  78. package/lib/ble/tacx/sensor.js +596 -0
  79. package/lib/ble/types.d.ts +87 -52
  80. package/lib/ble/utils.d.ts +7 -2
  81. package/lib/ble/utils.js +93 -9
  82. package/lib/ble/wahoo/adapter.d.ts +2 -2
  83. package/lib/ble/wahoo/adapter.js +4 -72
  84. package/lib/ble/wahoo/comms.d.ts +1 -1
  85. package/lib/ble/wahoo/comms.js +2 -2
  86. package/lib/ble/wahoo/consts.d.ts +16 -0
  87. package/lib/ble/wahoo/consts.js +7 -0
  88. package/lib/ble/wahoo/index.d.ts +1 -1
  89. package/lib/ble/wahoo/index.js +2 -2
  90. package/lib/ble/wahoo/sensor.d.ts +48 -0
  91. package/lib/ble/wahoo/sensor.js +356 -0
  92. package/lib/direct-connect/base/comms.d.ts +3 -0
  93. package/lib/direct-connect/base/comms.js +7 -0
  94. package/lib/direct-connect/base/interface.d.ts +75 -0
  95. package/lib/direct-connect/base/interface.js +311 -0
  96. package/lib/direct-connect/base/peripheral.d.ts +50 -0
  97. package/lib/direct-connect/base/peripheral.js +522 -0
  98. package/lib/direct-connect/base/sensor.d.ts +3 -0
  99. package/lib/direct-connect/base/sensor.js +7 -0
  100. package/lib/direct-connect/bindings/index.d.ts +1 -0
  101. package/lib/direct-connect/bindings/index.js +17 -0
  102. package/lib/direct-connect/bindings/types.d.ts +37 -0
  103. package/lib/direct-connect/bindings/types.js +2 -0
  104. package/lib/direct-connect/consts.d.ts +17 -0
  105. package/lib/direct-connect/consts.js +20 -0
  106. package/lib/direct-connect/index.d.ts +3 -0
  107. package/lib/direct-connect/index.js +22 -0
  108. package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
  109. package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
  110. package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
  111. package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
  112. package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
  113. package/lib/direct-connect/messages/DiscoverServices.js +33 -0
  114. package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
  115. package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
  116. package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
  117. package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
  118. package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
  119. package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
  120. package/lib/direct-connect/messages/error.d.ts +5 -0
  121. package/lib/direct-connect/messages/error.js +18 -0
  122. package/lib/direct-connect/messages/factory.d.ts +6 -0
  123. package/lib/direct-connect/messages/factory.js +44 -0
  124. package/lib/direct-connect/messages/index.d.ts +9 -0
  125. package/lib/direct-connect/messages/index.js +25 -0
  126. package/lib/direct-connect/messages/message.d.ts +21 -0
  127. package/lib/direct-connect/messages/message.js +105 -0
  128. package/lib/direct-connect/types.d.ts +24 -0
  129. package/lib/direct-connect/types.js +9 -0
  130. package/lib/direct-connect/utils.d.ts +5 -0
  131. package/lib/direct-connect/utils.js +73 -0
  132. package/lib/factories/adapters.js +14 -4
  133. package/lib/factories/interfaces.d.ts +2 -1
  134. package/lib/factories/interfaces.js +10 -7
  135. package/lib/index.d.ts +5 -4
  136. package/lib/index.js +6 -2
  137. package/lib/modes/antble-smarttrainer.d.ts +2 -16
  138. package/lib/modes/antble-smarttrainer.js +1 -98
  139. package/lib/modes/types.d.ts +1 -5
  140. package/lib/serial/bindings/tcp.d.ts +5 -4
  141. package/lib/serial/bindings/tcp.js +16 -23
  142. package/lib/types/adapter.d.ts +3 -0
  143. package/lib/types/device.d.ts +2 -1
  144. package/lib/types/device.js +1 -0
  145. package/lib/utils/calculations.d.ts +0 -1
  146. package/lib/utils/calculations.js +6 -22
  147. package/lib/utils/operation.d.ts +17 -0
  148. package/lib/utils/operation.js +20 -0
  149. package/lib/utils/task.d.ts +47 -0
  150. package/lib/utils/task.js +139 -0
  151. package/package.json +3 -1
@@ -16,33 +16,31 @@ const gd_eventlog_1 = require("gd-eventlog");
16
16
  const power_meter_1 = __importDefault(require("../../modes/power-meter"));
17
17
  const antble_smarttrainer_1 = __importDefault(require("../../modes/antble-smarttrainer"));
18
18
  const antble_erg_1 = __importDefault(require("../../modes/antble-erg"));
19
- const comms_1 = __importDefault(require("./comms"));
19
+ const sensor_1 = __importDefault(require("./sensor"));
20
20
  const adapter_1 = __importDefault(require("../base/adapter"));
21
21
  const consts_1 = require("./consts");
22
- const utils_1 = require("../../utils/utils");
23
22
  const types_1 = require("../../types");
23
+ const utils_1 = require("../../utils/utils");
24
24
  class BleFmAdapter extends adapter_1.default {
25
25
  constructor(settings, props) {
26
26
  super(settings, props);
27
27
  this.distanceInternal = 0;
28
+ this.requestControlRetryDelay = 1000;
28
29
  this.logger = new gd_eventlog_1.EventLogger('BLE-FM');
29
- const { id, address, name } = settings;
30
- const logger = this.logger;
31
- const ble = this.ble;
32
- this.device = new comms_1.default({ id, address, name, ble, logger });
30
+ this.device = new sensor_1.default(this.getPeripheral(), { logger: this.logger });
33
31
  this.capabilities = [
34
32
  types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence,
35
33
  types_1.IncyclistCapability.Control
36
34
  ];
37
35
  }
36
+ updateSensor(peripheral) {
37
+ this.device = new sensor_1.default(peripheral, { logger: this.logger });
38
+ }
38
39
  isSame(device) {
39
40
  if (!(device instanceof BleFmAdapter))
40
41
  return false;
41
42
  return this.isEqual(device.settings);
42
43
  }
43
- getName() {
44
- return `${this.device.name}`;
45
- }
46
44
  isControllable() {
47
45
  return true;
48
46
  }
@@ -70,6 +68,7 @@ class BleFmAdapter extends adapter_1.default {
70
68
  return new power_meter_1.default(this);
71
69
  }
72
70
  mapData(deviceData) {
71
+ var _a, _b, _c;
73
72
  const data = {
74
73
  isPedalling: false,
75
74
  power: 0,
@@ -80,9 +79,9 @@ class BleFmAdapter extends adapter_1.default {
80
79
  slope: undefined,
81
80
  time: undefined
82
81
  };
83
- data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
84
- data.pedalRpm = (deviceData.cadence !== undefined ? deviceData.cadence : data.pedalRpm);
85
- data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
82
+ data.power = (_a = deviceData === null || deviceData === void 0 ? void 0 : deviceData.instantaneousPower) !== null && _a !== void 0 ? _a : data.power;
83
+ data.pedalRpm = (_b = deviceData === null || deviceData === void 0 ? void 0 : deviceData.cadence) !== null && _b !== void 0 ? _b : data.pedalRpm;
84
+ data.time = (_c = deviceData === null || deviceData === void 0 ? void 0 : deviceData.time) !== null && _c !== void 0 ? _c : data.time;
86
85
  data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
87
86
  data.heartrate = deviceData.heartrate || data.heartrate;
88
87
  return data;
@@ -107,107 +106,100 @@ class BleFmAdapter extends adapter_1.default {
107
106
  };
108
107
  return data;
109
108
  }
110
- start() {
111
- return __awaiter(this, arguments, void 0, function* (props = {}) {
112
- const wasPaused = this.paused;
113
- const wasStopped = this.stopped;
114
- if (wasPaused)
115
- this.resume();
116
- if (wasStopped)
117
- this.stopped = false;
118
- if (this.started && !wasPaused && !wasStopped)
119
- return true;
120
- this.logEvent(Object.assign(Object.assign({ message: 'starting device' }, this.getSettings()), { protocol: this.getProtocolName(), props, isStarted: this.started, isConnected: this.getComms().isConnected() }));
121
- const { restart = wasPaused } = props;
122
- if (!restart && this.ble.isScanning() && !this.getComms().isConnected()) {
123
- }
124
- let scanOnly = props.scanOnly;
125
- if (this.ble.isScanning() && this.getComms().isConnected()) {
126
- scanOnly = true;
127
- }
128
- else {
129
- const { timeout = 20000 } = props || {};
130
- if (!this.connectPromise)
131
- this.connectPromise = this.connect();
132
- const res = yield Promise.race([
133
- this.connectPromise.then((connected) => {
134
- return { connected, reason: connected ? null : 'could not connect' };
135
- }),
136
- (0, utils_1.sleep)(timeout).then(() => ({ connected: false, reason: 'timeout' }))
137
- ]);
138
- this.connectPromise = undefined;
139
- const connected = res.connected;
140
- if (!connected) {
141
- throw new Error(`could not start device, reason:${res.reason}`);
142
- }
109
+ checkResume() {
110
+ const wasPaused = this.paused;
111
+ const wasStopped = this.stopped;
112
+ if (wasPaused)
113
+ this.resume();
114
+ this.stopped = false;
115
+ if (this.started && !wasPaused && !wasStopped)
116
+ return [wasPaused, true];
117
+ return [wasPaused, false];
118
+ }
119
+ initControl(_startProps) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ if (!this.isStarting())
122
+ return;
123
+ this.setConstants();
124
+ yield this.establishControl();
125
+ this.setConstants();
126
+ yield this.sendInitialRequest();
127
+ });
128
+ }
129
+ setConstants() {
130
+ const mode = this.getCyclingMode();
131
+ const sensor = this.getComms();
132
+ if (mode === null || mode === void 0 ? void 0 : mode.getSetting('bikeType')) {
133
+ const bikeType = mode.getSetting('bikeType').toLowerCase();
134
+ sensor.setCrr(consts_1.cRR);
135
+ switch (bikeType) {
136
+ case 'race':
137
+ sensor.setCw(consts_1.cwABike.race);
138
+ break;
139
+ case 'triathlon':
140
+ sensor.setCw(consts_1.cwABike.triathlon);
141
+ break;
142
+ case 'mountain':
143
+ sensor.setCw(consts_1.cwABike.mountain);
144
+ break;
143
145
  }
144
- try {
145
- const comms = this.device;
146
- if (comms) {
147
- if (!scanOnly) {
148
- const mode = this.getCyclingMode();
149
- if (mode && mode.getSetting('bikeType')) {
150
- const bikeType = mode.getSetting('bikeType').toLowerCase();
151
- comms.setCrr(consts_1.cRR);
152
- switch (bikeType) {
153
- case 'race':
154
- comms.setCw(consts_1.cwABike.race);
155
- break;
156
- case 'triathlon':
157
- comms.setCw(consts_1.cwABike.triathlon);
158
- break;
159
- case 'mountain':
160
- comms.setCw(consts_1.cwABike.mountain);
161
- break;
162
- }
146
+ }
147
+ }
148
+ establishControl() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ if (!this.isStarting())
151
+ return false;
152
+ let hasControl = false;
153
+ let tryCnt = 0;
154
+ const sensor = this.getComms();
155
+ return new Promise((resolve) => {
156
+ this.startTask.notifyOnStop(() => {
157
+ resolve(false);
158
+ });
159
+ const waitUntilControl = () => __awaiter(this, void 0, void 0, function* () {
160
+ while (!hasControl && this.isStarting()) {
161
+ if (tryCnt++ === 0) {
162
+ this.logEvent({ message: 'requesting control', device: this.getName(), interface: this.getInterface() });
163
163
  }
164
- let hasControl = yield comms.requestControl();
165
- if (!hasControl) {
166
- let retry = 1;
167
- while (!hasControl && retry < 3) {
168
- yield (0, utils_1.sleep)(1000);
169
- hasControl = yield comms.requestControl();
170
- retry++;
171
- }
164
+ hasControl = yield sensor.requestControl();
165
+ if (hasControl) {
166
+ this.logEvent({ message: 'control granted', device: this.getName(), interface: this.getInterface() });
167
+ resolve(this.isStarting());
168
+ }
169
+ else {
170
+ yield (0, utils_1.sleep)(this.requestControlRetryDelay);
172
171
  }
173
- if (!hasControl)
174
- throw new Error('could not establish control');
175
- const startRequest = this.getCyclingMode().getBikeInitRequest();
176
- yield this.sendUpdate(startRequest, true);
177
- }
178
- if (!this.started && !wasPaused) {
179
- comms.on('data', (data) => {
180
- this.onDeviceData(data);
181
- });
182
- comms.on('disconnected', this.emit);
183
- }
184
- const before = this.capabilities.join(',');
185
- if (comms.features.heartrate && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
186
- this.capabilities.push(types_1.IncyclistCapability.HeartRate);
187
- }
188
- if (comms.features.cadence && !this.hasCapability(types_1.IncyclistCapability.Cadence)) {
189
- this.capabilities.push(types_1.IncyclistCapability.Cadence);
190
- }
191
- if (comms.features.power && !this.hasCapability(types_1.IncyclistCapability.Power)) {
192
- this.capabilities.push(types_1.IncyclistCapability.Power);
193
- }
194
- const after = this.capabilities.join(',');
195
- if (before !== after) {
196
- this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
197
172
  }
198
- this.resetData();
199
- this.stopped = false;
200
- this.started = true;
201
- this.resume();
202
- return true;
203
- }
204
- }
205
- catch (err) {
206
- this.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
207
- throw new Error(`could not start device, reason:${err.message}`);
208
- }
173
+ });
174
+ waitUntilControl();
175
+ });
209
176
  });
210
177
  }
178
+ sendInitialRequest() {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ const startRequest = this.getCyclingMode().getBikeInitRequest();
181
+ yield this.sendUpdate(startRequest, true);
182
+ });
183
+ }
184
+ checkCapabilities() {
185
+ var _a, _b, _c;
186
+ const before = this.capabilities.join(',');
187
+ const sensor = this.getComms();
188
+ if (((_a = sensor.features) === null || _a === void 0 ? void 0 : _a.heartrate) && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
189
+ this.capabilities.push(types_1.IncyclistCapability.HeartRate);
190
+ }
191
+ if (((_b = sensor.features) === null || _b === void 0 ? void 0 : _b.cadence) && !this.hasCapability(types_1.IncyclistCapability.Cadence)) {
192
+ this.capabilities.push(types_1.IncyclistCapability.Cadence);
193
+ }
194
+ if (((_c = sensor.features) === null || _c === void 0 ? void 0 : _c.power) && !this.hasCapability(types_1.IncyclistCapability.Power)) {
195
+ this.capabilities.push(types_1.IncyclistCapability.Power);
196
+ }
197
+ const after = this.capabilities.join(',');
198
+ if (before !== after) {
199
+ this.logEvent({ message: 'device capabilities updated', name: this.getSettings().name, interface: this.getSettings().interface, capabilities: this.capabilities });
200
+ this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
201
+ }
202
+ }
211
203
  sendUpdate(request_1) {
212
204
  return __awaiter(this, arguments, void 0, function* (request, enforced = false) {
213
205
  if (!enforced && (this.paused || !this.device))
@@ -215,7 +207,7 @@ class BleFmAdapter extends adapter_1.default {
215
207
  try {
216
208
  const update = this.getCyclingMode().sendBikeUpdate(request);
217
209
  this.logEvent({ message: 'send bike update requested', profile: this.getProfile(), update, request });
218
- const device = this.device;
210
+ const device = this.getComms();
219
211
  if (update.slope !== undefined) {
220
212
  yield device.setSlope(update.slope);
221
213
  }
@@ -1,6 +1,6 @@
1
1
  import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
2
2
  import { IndoorBikeData, IndoorBikeFeatures } from "./types";
3
- import { BleComms } from "../base/comms";
3
+ import { BleComms } from "../base/sensor";
4
4
  import { LegacyProfile } from "../../antv2/types";
5
5
  export default class BleFitnessMachineDevice extends BleComms {
6
6
  static protocol: BleProtocol;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const consts_1 = require("../consts");
13
- const comms_1 = require("../base/comms");
13
+ const sensor_1 = require("../base/sensor");
14
14
  const utils_1 = require("../utils");
15
15
  const bit = (nr) => (1 << nr);
16
16
  const IndoorBikeDataFlag = {
@@ -66,7 +66,7 @@ const TargetSettingFeatureFlag = {
66
66
  SpinDownControlSupported: bit(15),
67
67
  TargetedCadenceConfigurationSupported: bit(16)
68
68
  };
69
- class BleFitnessMachineDevice extends comms_1.BleComms {
69
+ class BleFitnessMachineDevice extends sensor_1.BleComms {
70
70
  constructor(props) {
71
71
  super(props);
72
72
  this.features = undefined;
@@ -92,7 +92,7 @@ class BleFitnessMachineDevice extends comms_1.BleComms {
92
92
  subscribeWriteResponse(cuuid) {
93
93
  return __awaiter(this, void 0, void 0, function* () {
94
94
  this.logEvent({ message: 'subscribe to CP response', characteristics: cuuid });
95
- const connector = this.ble.peripheralCache.getConnector(this.peripheral);
95
+ const connector = this.getPeripheral();
96
96
  const isAlreadySubscribed = connector.isSubscribed(cuuid);
97
97
  if (!isAlreadySubscribed) {
98
98
  connector.removeAllListeners(cuuid);
@@ -4,3 +4,96 @@ export declare const cwABike: {
4
4
  mountain: number;
5
5
  };
6
6
  export declare const cRR = 0.0036;
7
+ export declare const enum OpCode {
8
+ RequestControl = 0,
9
+ Reset = 1,
10
+ SetTargetSpeed = 2,
11
+ SetTargetInclination = 3,
12
+ SetTargetResistance = 4,
13
+ SetTargetPower = 5,
14
+ SetTargetHeartRate = 6,
15
+ StartOrResume = 7,
16
+ StopOrPause = 8,
17
+ SetIndoorBikeSimulation = 17,
18
+ SetWheelCircumference = 18,
19
+ SpinDownControl = 19,
20
+ SetTargetedCadence = 20,
21
+ ResponseCode = 128
22
+ }
23
+ export declare const enum FitnessMachineStatusOpCode {
24
+ Reset = 1,
25
+ FitnessMachineStoppedOrPaused = 2,
26
+ FitnessMachineStoppedBySafetyKey = 3,
27
+ FitnessMachineStartedOrResumed = 4,
28
+ TargetSpeedChanged = 5,
29
+ TargetInclineChanged = 6,
30
+ TargetResistanceLevelChanged = 7,
31
+ TargetPowerChanged = 8,
32
+ TargetHeartRateChanged = 9,
33
+ TargetExpendedEnergyChanged = 10,
34
+ IndoorBikeSimulationParametersChanged = 18,
35
+ WheelCircumferenceChanged = 19,
36
+ SpinDownStatus = 20,
37
+ TargetedCadenceChanged = 21,
38
+ ControlPermissionLost = 255
39
+ }
40
+ export declare const enum OpCodeResut {
41
+ Success = 1,
42
+ OpCodeNotSupported = 2,
43
+ InvalidParameter = 3,
44
+ OperationFailed = 4,
45
+ ControlNotPermitted = 5
46
+ }
47
+ export declare const IndoorBikeDataFlag: {
48
+ MoreData: number;
49
+ AverageSpeedPresent: number;
50
+ InstantaneousCadence: number;
51
+ AverageCadencePresent: number;
52
+ TotalDistancePresent: number;
53
+ ResistanceLevelPresent: number;
54
+ InstantaneousPowerPresent: number;
55
+ AveragePowerPresent: number;
56
+ ExpendedEnergyPresent: number;
57
+ HeartRatePresent: number;
58
+ MetabolicEquivalentPresent: number;
59
+ ElapsedTimePresent: number;
60
+ RemainingTimePresent: number;
61
+ };
62
+ export declare const FitnessMachineFeatureFlag: {
63
+ AverageSpeedSupported: number;
64
+ CadenceSupported: number;
65
+ TotalDistanceSupported: number;
66
+ InclinationSupported: number;
67
+ ElevationGainSupported: number;
68
+ PaceSupported: number;
69
+ StepCountSupported: number;
70
+ ResistanceLevelSupported: number;
71
+ StrideCountSupported: number;
72
+ ExpendedEnergySupported: number;
73
+ HeartRateMeasurementSupported: number;
74
+ MetabolicEquivalentSupported: number;
75
+ ElapsedTimeSupported: number;
76
+ RemainingTimeSupported: number;
77
+ PowerMeasurementSupported: number;
78
+ ForceOnBeltAndPowerOutputSupported: number;
79
+ UserDataRetentionSupported: number;
80
+ };
81
+ export declare const TargetSettingFeatureFlag: {
82
+ SpeedTargetSettingSupported: number;
83
+ InclinationTargetSettingSupported: number;
84
+ ResistanceTargetSettingSupported: number;
85
+ PowerTargetSettingSupported: number;
86
+ HeartRateTargetSettingSupported: number;
87
+ TargetedExpendedEnergyConfigurationSupported: number;
88
+ TargetedStepNumberConfigurationSupported: number;
89
+ TargetedStrideNumberConfigurationSupported: number;
90
+ TargetedDistanceConfigurationSupported: number;
91
+ TargetedTrainingTimeConfigurationSupported: number;
92
+ TargetedTimeInTwoHeartRateZonesConfigurationSupported: number;
93
+ TargetedTimeInThreeHeartRateZonesConfigurationSupported: number;
94
+ TargetedTimeInFiveHeartRateZonesConfigurationSupported: number;
95
+ IndoorBikeSimulationParametersSupported: number;
96
+ WheelCircumferenceConfigurationSupported: number;
97
+ SpinDownControlSupported: number;
98
+ TargetedCadenceConfigurationSupported: number;
99
+ };
@@ -1,9 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cRR = exports.cwABike = void 0;
3
+ exports.TargetSettingFeatureFlag = exports.FitnessMachineFeatureFlag = exports.IndoorBikeDataFlag = exports.cRR = exports.cwABike = void 0;
4
4
  exports.cwABike = {
5
5
  race: 0.35,
6
6
  triathlon: 0.29,
7
7
  mountain: 0.57
8
8
  };
9
9
  exports.cRR = 0.0036;
10
+ const bit = (nr) => (1 << nr);
11
+ exports.IndoorBikeDataFlag = {
12
+ MoreData: bit(0),
13
+ AverageSpeedPresent: bit(1),
14
+ InstantaneousCadence: bit(2),
15
+ AverageCadencePresent: bit(3),
16
+ TotalDistancePresent: bit(4),
17
+ ResistanceLevelPresent: bit(5),
18
+ InstantaneousPowerPresent: bit(6),
19
+ AveragePowerPresent: bit(7),
20
+ ExpendedEnergyPresent: bit(8),
21
+ HeartRatePresent: bit(9),
22
+ MetabolicEquivalentPresent: bit(10),
23
+ ElapsedTimePresent: bit(11),
24
+ RemainingTimePresent: bit(12)
25
+ };
26
+ exports.FitnessMachineFeatureFlag = {
27
+ AverageSpeedSupported: bit(0),
28
+ CadenceSupported: bit(1),
29
+ TotalDistanceSupported: bit(2),
30
+ InclinationSupported: bit(3),
31
+ ElevationGainSupported: bit(4),
32
+ PaceSupported: bit(5),
33
+ StepCountSupported: bit(6),
34
+ ResistanceLevelSupported: bit(7),
35
+ StrideCountSupported: bit(8),
36
+ ExpendedEnergySupported: bit(9),
37
+ HeartRateMeasurementSupported: bit(10),
38
+ MetabolicEquivalentSupported: bit(11),
39
+ ElapsedTimeSupported: bit(12),
40
+ RemainingTimeSupported: bit(13),
41
+ PowerMeasurementSupported: bit(14),
42
+ ForceOnBeltAndPowerOutputSupported: bit(15),
43
+ UserDataRetentionSupported: bit(16)
44
+ };
45
+ exports.TargetSettingFeatureFlag = {
46
+ SpeedTargetSettingSupported: bit(0),
47
+ InclinationTargetSettingSupported: bit(1),
48
+ ResistanceTargetSettingSupported: bit(2),
49
+ PowerTargetSettingSupported: bit(3),
50
+ HeartRateTargetSettingSupported: bit(4),
51
+ TargetedExpendedEnergyConfigurationSupported: bit(5),
52
+ TargetedStepNumberConfigurationSupported: bit(6),
53
+ TargetedStrideNumberConfigurationSupported: bit(7),
54
+ TargetedDistanceConfigurationSupported: bit(8),
55
+ TargetedTrainingTimeConfigurationSupported: bit(9),
56
+ TargetedTimeInTwoHeartRateZonesConfigurationSupported: bit(10),
57
+ TargetedTimeInThreeHeartRateZonesConfigurationSupported: bit(11),
58
+ TargetedTimeInFiveHeartRateZonesConfigurationSupported: bit(12),
59
+ IndoorBikeSimulationParametersSupported: bit(13),
60
+ WheelCircumferenceConfigurationSupported: bit(14),
61
+ SpinDownControlSupported: bit(15),
62
+ TargetedCadenceConfigurationSupported: bit(16)
63
+ };
@@ -1,4 +1,4 @@
1
- import BleFmComms from './comms';
1
+ import BleFmComms from './sensor';
2
2
  import BleFmAdapter from './adapter';
3
3
  import { IndoorBikeData } from './types';
4
4
  import { cRR, cwABike } from './consts';
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cwABike = exports.cRR = exports.BleFmComms = exports.BleFmAdapter = void 0;
7
- const comms_1 = __importDefault(require("./comms"));
8
- exports.BleFmComms = comms_1.default;
7
+ const sensor_1 = __importDefault(require("./sensor"));
8
+ exports.BleFmComms = sensor_1.default;
9
9
  const adapter_1 = __importDefault(require("./adapter"));
10
10
  exports.BleFmAdapter = adapter_1.default;
11
11
  const consts_1 = require("./consts");
@@ -0,0 +1,44 @@
1
+ import { LegacyProfile } from "../../antv2/types";
2
+ import { BleProtocol, BleWriteProps } from "../types";
3
+ import { IndoorBikeData, IndoorBikeFeatures } from "./types";
4
+ import { TBleSensor } from "../base/sensor";
5
+ export default class BleFitnessMachineDevice 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: number;
11
+ protected data: IndoorBikeData;
12
+ protected _features: IndoorBikeFeatures;
13
+ protected hasControl: boolean;
14
+ protected isCheckingControl: boolean;
15
+ protected isCPSubscribed: boolean;
16
+ protected crr: number;
17
+ protected cw: number;
18
+ protected windSpeed: number;
19
+ protected wheelSize: number;
20
+ constructor(peripheral: any, props?: any);
21
+ get features(): IndoorBikeFeatures;
22
+ reset(): void;
23
+ protected getRequiredCharacteristics(): Array<string>;
24
+ onData(characteristic: string, data: Buffer): boolean;
25
+ setCrr(crr: number): void;
26
+ getCrr(): number;
27
+ setCw(cw: number): void;
28
+ getCw(): number;
29
+ setWindSpeed(windSpeed: number): void;
30
+ getWindSpeed(): number;
31
+ requestControl(): Promise<boolean>;
32
+ setTargetPower(power: number): Promise<boolean>;
33
+ setSlope(slope: any): Promise<boolean>;
34
+ protected parseHrm(_data: Uint8Array): IndoorBikeData;
35
+ protected parseIndoorBikeData(_data: Uint8Array): IndoorBikeData;
36
+ protected parseFitnessMachineStatus(_data: Uint8Array): IndoorBikeData;
37
+ protected getFitnessMachineFeatures(): Promise<IndoorBikeFeatures | undefined>;
38
+ protected writeFtmsMessage(requestedOpCode: any, data: any, props?: BleWriteProps): Promise<number>;
39
+ setTargetInclination(inclination: number): Promise<boolean>;
40
+ setIndoorBikeSimulation(windSpeed: number, gradient: number, crr: number, cw: number): Promise<boolean>;
41
+ startRequest(): Promise<boolean>;
42
+ stopRequest(): Promise<boolean>;
43
+ PauseRequest(): Promise<boolean>;
44
+ }