incyclist-devices 2.1.1 → 2.1.3

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 (41) hide show
  1. package/lib/antv2/base/adapter.d.ts +13 -7
  2. package/lib/antv2/base/adapter.js +162 -89
  3. package/lib/antv2/base/interface.d.ts +46 -0
  4. package/lib/antv2/base/interface.js +343 -0
  5. package/lib/antv2/factories/adapter-factory.d.ts +4 -4
  6. package/lib/antv2/factories/adapter-factory.js +17 -9
  7. package/lib/antv2/fe/adapter.d.ts +7 -11
  8. package/lib/antv2/fe/adapter.js +50 -145
  9. package/lib/antv2/index.d.ts +1 -1
  10. package/lib/antv2/index.js +2 -2
  11. package/lib/antv2/types.d.ts +9 -0
  12. package/lib/base/adpater.js +10 -2
  13. package/lib/ble/adapter-factory.d.ts +9 -8
  14. package/lib/ble/base/adapter.d.ts +13 -10
  15. package/lib/ble/base/adapter.js +9 -8
  16. package/lib/ble/base/types.d.ts +2 -0
  17. package/lib/ble/base/types.js +2 -0
  18. package/lib/ble/ble-interface.d.ts +0 -4
  19. package/lib/ble/ble-interface.js +0 -11
  20. package/lib/ble/cp/adapter.d.ts +5 -3
  21. package/lib/ble/cp/adapter.js +1 -7
  22. package/lib/ble/elite/adapter.d.ts +5 -3
  23. package/lib/ble/elite/adapter.js +1 -7
  24. package/lib/ble/fm/adapter.d.ts +4 -3
  25. package/lib/ble/fm/adapter.js +1 -6
  26. package/lib/ble/hr/adapter.d.ts +4 -2
  27. package/lib/ble/hr/adapter.js +1 -3
  28. package/lib/ble/peripheral-cache.d.ts +3 -1
  29. package/lib/ble/tacx/adapter.d.ts +3 -1
  30. package/lib/ble/tacx/adapter.js +1 -0
  31. package/lib/ble/wahoo/adapter.d.ts +3 -1
  32. package/lib/ble/wahoo/adapter.js +1 -0
  33. package/lib/factories/interfaces.d.ts +1 -1
  34. package/lib/factories/interfaces.js +2 -2
  35. package/lib/modes/power-base.js +1 -4
  36. package/lib/serial/base/serial-interface.js +1 -1
  37. package/lib/serial/base/serial-scanner.js +2 -2
  38. package/lib/serial/daum/classic/mock.js +1 -1
  39. package/lib/utils/utils.d.ts +1 -0
  40. package/lib/utils/utils.js +18 -1
  41. package/package.json +1 -1
@@ -13,22 +13,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const adapter_1 = __importDefault(require("../base/adapter"));
16
+ const types_1 = require("../../types");
16
17
  const ant_fe_adv_st_mode_1 = __importDefault(require("../../modes/ant-fe-adv-st-mode"));
17
- const utils_1 = require("../../utils/utils");
18
- const capabilities_1 = require("../../types/capabilities");
19
18
  const consts_1 = require("../../base/consts");
20
19
  const antble_erg_1 = __importDefault(require("../../modes/antble-erg"));
21
20
  const antble_smarttrainer_1 = __importDefault(require("../../modes/antble-smarttrainer"));
22
21
  const DEFAULT_BIKE_WEIGHT_MOUNTAIN = 14.5;
23
- const MAX_RETRIES = 3;
24
22
  class AntFEAdapter extends adapter_1.default {
25
23
  constructor(settings, props) {
26
24
  super(settings, props);
27
25
  this.startProps = {};
28
- this.sensorConnected = false;
29
26
  this.capabilities = [
30
- capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence,
31
- capabilities_1.IncyclistCapability.Control
27
+ types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence,
28
+ types_1.IncyclistCapability.Control
32
29
  ];
33
30
  }
34
31
  getDisplayName() {
@@ -36,9 +33,6 @@ class AntFEAdapter extends adapter_1.default {
36
33
  const pwrStr = InstantaneousPower ? ` (${InstantaneousPower})` : '';
37
34
  return `${this.getUniqueName()}${pwrStr}`;
38
35
  }
39
- getDefaultReconnectDelay() {
40
- return 2000;
41
- }
42
36
  isReconnecting() {
43
37
  return this.promiseReconnect !== null && this.promiseReconnect !== undefined;
44
38
  }
@@ -48,7 +42,7 @@ class AntFEAdapter extends adapter_1.default {
48
42
  return;
49
43
  let isReset = request.reset && Object.keys(request).length === 1;
50
44
  const update = isReset ? this.getCyclingMode().getBikeInitRequest() : this.getCyclingMode().sendBikeUpdate(request);
51
- this.logEvent({ message: 'send bike update requested', update, request });
45
+ this.logEvent({ message: 'send bike update requested', device: this.getName(), update, request });
52
46
  try {
53
47
  const fe = this.sensor;
54
48
  if (update.slope !== undefined) {
@@ -65,14 +59,14 @@ class AntFEAdapter extends adapter_1.default {
65
59
  yield this.reconnect();
66
60
  }
67
61
  }
68
- this.logEvent({ message: 'sendBikeUpdate() error', error: err.message });
62
+ this.logEvent({ message: 'sendBikeUpdate() error', device: this.getName(), error: err.message });
69
63
  }
70
64
  });
71
65
  }
72
66
  onDeviceData(deviceData) {
73
67
  super.onDeviceData(deviceData);
74
- if (deviceData.HeartRate && !this.hasCapability(capabilities_1.IncyclistCapability.HeartRate)) {
75
- this.capabilities.push(capabilities_1.IncyclistCapability.HeartRate);
68
+ if (deviceData.HeartRate && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
69
+ this.capabilities.push(types_1.IncyclistCapability.HeartRate);
76
70
  this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
77
71
  }
78
72
  }
@@ -118,134 +112,45 @@ class AntFEAdapter extends adapter_1.default {
118
112
  data.deviceTime = adapterData.time;
119
113
  this.data = data;
120
114
  }
121
- start(props) {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- const isReconnect = (props === null || props === void 0 ? void 0 : props.reconnect) || false;
124
- const startProps = Object.assign({}, props || {});
125
- delete startProps.reconnect;
126
- return yield this.performStart(props, isReconnect);
115
+ start(props = {}) {
116
+ const _super = Object.create(null, {
117
+ start: { get: () => super.start }
127
118
  });
128
- }
129
- performStart(props, isReconnect) {
130
119
  return __awaiter(this, void 0, void 0, function* () {
131
- const wasPaused = this.paused;
132
- const wasStopped = this.stopped;
133
- this.startProps = props;
134
- if (wasPaused)
135
- this.resume();
136
- this.stopped = false;
137
- if (this.started && !wasPaused && !wasStopped) {
138
- return true;
139
- }
140
- const connected = yield this.connect();
141
- if (!connected)
142
- throw new Error(`could not start device, reason:could not connect`);
143
- this.logEvent({ message: 'starting device', props, isStarted: this.started, isReconnecting: isReconnect });
144
- const { startupTimeout = this.getDefaultStartupTimeout(), reconnectTimeout = this.getDefaultReconnectDelay() } = props || {};
145
- const totalTimeout = Math.min(startupTimeout + 10000, startupTimeout * 2);
146
- let status = { timeout: false, sensorStarted: false, hasData: false, userSent: false, slopeSent: false };
147
- const doStart = () => __awaiter(this, void 0, void 0, function* () {
148
- this.setFEDefaultTimeout();
149
- let success = false;
150
- let retry = 0;
151
- if (isReconnect) {
152
- status.userSent = true;
153
- status.slopeSent = true;
154
- }
155
- while (!success && retry < MAX_RETRIES && !status.timeout) {
156
- if (retry !== 0) {
157
- console.log('~~~ RETRY', status);
158
- }
159
- retry++;
160
- yield this.initSensor(status, props);
161
- yield this.waitForInitialData(status, startupTimeout);
162
- yield this.sendInititalUserMessage(status, props);
163
- yield this.sendInitialRequest(status, props);
164
- if (!status.hasData) {
165
- yield this.stopSensor();
166
- yield (0, utils_1.sleep)(reconnectTimeout);
167
- continue;
168
- }
169
- success = status.sensorStarted && status.hasData && status.userSent && status.slopeSent;
170
- }
171
- if (success) {
172
- this.logEvent({ message: 'ANT FE start success' });
173
- this.started = true;
174
- this.paused = false;
175
- return true;
176
- }
177
- else {
178
- this.started = false;
179
- if (!status.sensorStarted) {
180
- this.logEvent({ message: 'ANT FE start failed', reason: 'could not connect' });
181
- throw new Error('could not start device, reason:could not connect');
182
- }
183
- else if (!status.hasData) {
184
- this.logEvent({ message: 'ANT FE start failed', reason: 'no data received' });
185
- throw new Error('could not start device, reason:no data received');
186
- }
187
- else {
188
- this.logEvent({ message: 'ANT FE start failed', reason: 'could not send FE commands' });
189
- throw new Error('could not start device, reason:could not send FE commands');
190
- }
191
- }
192
- });
193
- try {
194
- yield (0, utils_1.runWithTimeout)(doStart(), totalTimeout);
195
- }
196
- catch (err) {
197
- if (err.message === 'Timeout') {
198
- this.started = false;
199
- status.timeout = true;
200
- throw new Error(`could not start device, reason:timeout`);
201
- }
202
- throw err;
203
- }
204
- return true;
120
+ return yield _super.start.call(this, props);
205
121
  });
206
122
  }
207
- waitForInitialData(status, startupTimeout) {
208
- return __awaiter(this, void 0, void 0, function* () {
209
- if ((status.sensorStarted && status.hasData) || !status.sensorStarted || status.timeout)
210
- return;
211
- this.logEvent({ message: 'wait for sensor data', });
212
- status.hasData = yield this.waitForData(startupTimeout);
213
- if (status.hasData)
214
- this.logEvent({ message: 'sensor data received', });
215
- });
123
+ resetStartStatus() {
124
+ const props = this.startProps;
125
+ const isReconnect = props.reconnect || false;
126
+ super.resetStartStatus();
127
+ if (isReconnect) {
128
+ delete props.reconnect;
129
+ this.startStatus.userInitialized = true;
130
+ this.startStatus.controlInitialized = true;
131
+ }
216
132
  }
217
- stopSensor() {
133
+ startPreChecks(props) {
134
+ const _super = Object.create(null, {
135
+ startPreChecks: { get: () => super.startPreChecks }
136
+ });
218
137
  return __awaiter(this, void 0, void 0, function* () {
219
- if (!this.sensorConnected)
220
- return;
221
- try {
222
- yield yield this.ant.stopSensor(this.sensor);
223
- this.sensorConnected = false;
224
- }
225
- catch (_a) { }
138
+ this.startProps = props;
139
+ this.setFEDefaultTimeout();
140
+ return yield _super.startPreChecks.call(this, props);
226
141
  });
227
142
  }
228
- initSensor(status, props) {
143
+ initControl() {
229
144
  return __awaiter(this, void 0, void 0, function* () {
230
- status.sensorStarted = this.sensorConnected;
231
- if (status.sensorStarted || status.timeout)
232
- return;
233
- this.logEvent({ message: 'start sensor', props });
234
- try {
235
- this.sensorConnected = yield this.startSensor();
236
- if (this.sensorConnected) {
237
- this.logEvent({ message: 'sensor started', props });
238
- status.sensorStarted = true;
239
- }
240
- }
241
- catch (err) {
242
- this.logEvent({ message: 'start sensor failed', reason: err.message, props });
243
- }
145
+ yield this.sendInititalUserMessage();
146
+ yield this.sendInitialRequest();
244
147
  });
245
148
  }
246
- sendInititalUserMessage(status, props) {
149
+ sendInititalUserMessage() {
247
150
  return __awaiter(this, void 0, void 0, function* () {
248
- if (!status.sensorStarted || !status.hasData || status.userSent || status.timeout)
151
+ const props = this.startProps;
152
+ const { sensorStarted, hasData, userInitialized, timeout } = this.startStatus;
153
+ if (!sensorStarted || !hasData || userInitialized || timeout)
249
154
  return;
250
155
  const opts = props || {};
251
156
  const { args = {}, user = {} } = opts;
@@ -256,39 +161,40 @@ class AntFEAdapter extends adapter_1.default {
256
161
  const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : consts_1.DEFAULT_BIKE_WEIGHT;
257
162
  const userWeight = args.userWeight || user.weight || consts_1.DEFAULT_USER_WEIGHT;
258
163
  const bikeWeight = args.bikeWeight || defaultBikeWeight;
259
- status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
164
+ this.startStatus.userInitialized = yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio);
260
165
  }
261
166
  catch (err) {
262
- this.logEvent({ message: 'sending FE message error', error: err.message });
263
- status.userSent = false;
167
+ this.logEvent({ message: 'sending FE message error', device: this.getName(), error: err.message });
168
+ this.startStatus.userInitialized = false;
264
169
  }
265
170
  });
266
171
  }
267
- sendInitialRequest(status, props) {
172
+ sendInitialRequest() {
268
173
  return __awaiter(this, void 0, void 0, function* () {
269
- if (!status.sensorStarted || !status.hasData || status.slopeSent || status.timeout)
174
+ const { sensorStarted, hasData, controlInitialized, timeout } = this.startStatus;
175
+ if (!sensorStarted || !hasData || controlInitialized || timeout)
270
176
  return;
271
177
  const fe = this.sensor;
272
178
  try {
273
179
  const startRequest = this.getCyclingMode().getBikeInitRequest();
274
180
  if (startRequest) {
275
181
  if (startRequest.targetPower !== undefined && startRequest.targetPower !== null) {
276
- status.slopeSent = yield fe.sendTargetPower(startRequest.targetPower);
182
+ this.startStatus.controlInitialized = yield fe.sendTargetPower(startRequest.targetPower);
277
183
  }
278
184
  else if (startRequest.slope !== undefined && startRequest.slope !== null) {
279
- status.slopeSent = yield fe.sendTrackResistance(startRequest.slope);
185
+ this.startStatus.controlInitialized = yield fe.sendTrackResistance(startRequest.slope);
280
186
  }
281
187
  else {
282
- status.slopeSent = true;
188
+ this.startStatus.controlInitialized = true;
283
189
  }
284
190
  }
285
191
  else {
286
- status.slopeSent = yield fe.sendTrackResistance(0.0);
192
+ this.startStatus.controlInitialized = yield fe.sendTrackResistance(0.0);
287
193
  }
288
194
  }
289
195
  catch (err) {
290
- this.logEvent({ message: 'sending FE message error', error: err.message });
291
- status.slopeSent = false;
196
+ this.logEvent({ message: 'sending FE message error', device: this.getName(), error: err.message });
197
+ this.startStatus.controlInitialized = false;
292
198
  }
293
199
  });
294
200
  }
@@ -303,20 +209,20 @@ class AntFEAdapter extends adapter_1.default {
303
209
  }
304
210
  reconnect() {
305
211
  return __awaiter(this, void 0, void 0, function* () {
306
- this.logEvent({ message: 'reconnect to device' });
212
+ this.logEvent({ message: 'reconnect to device', device: this.getName() });
307
213
  if (this.promiseReconnect) {
308
214
  return yield this.promiseReconnect;
309
215
  }
310
216
  const doReconnect = () => __awaiter(this, void 0, void 0, function* () {
311
217
  try {
312
218
  yield this.stop();
313
- yield this.performStart(this.startProps, true);
219
+ yield this.start(Object.assign(Object.assign({}, this.startProps), { reconnect: true }));
314
220
  this.started = true;
315
- this.logEvent({ message: 'reconnect success' });
221
+ this.logEvent({ message: 'reconnect success', device: this.getName() });
316
222
  return true;
317
223
  }
318
224
  catch (err) {
319
- this.logEvent({ message: 'reconnect failed' });
225
+ this.logEvent({ message: 'reconnect failed', device: this.getName() });
320
226
  return false;
321
227
  }
322
228
  });
@@ -338,7 +244,6 @@ class AntFEAdapter extends adapter_1.default {
338
244
  }
339
245
  }
340
246
  catch (err) {
341
- console.log(err);
342
247
  return false;
343
248
  }
344
249
  }
@@ -2,7 +2,7 @@ import AntPwrAdapter from "./pwr";
2
2
  import AntFEAdapter from "./fe";
3
3
  import AntHrAdapter from "./hr";
4
4
  import AntAdapterFactory from "./factories/adapter-factory";
5
- import AntInterface from "./base/ant-interface";
5
+ import AntInterface from "./base/interface";
6
6
  import { AntInterfaceProps } from "./types";
7
7
  export { AntDeviceSettings, AntDeviceProperties, AntScanProps } from "./types";
8
8
  export { AntAdapterFactory, AntFEAdapter, AntHrAdapter, AntPwrAdapter, AntInterface, AntInterfaceProps };
@@ -13,8 +13,8 @@ exports.AntHrAdapter = hr_1.default;
13
13
  const cad_1 = __importDefault(require("./cad"));
14
14
  const adapter_factory_1 = __importDefault(require("./factories/adapter-factory"));
15
15
  exports.AntAdapterFactory = adapter_factory_1.default;
16
- const ant_interface_1 = __importDefault(require("./base/ant-interface"));
17
- exports.AntInterface = ant_interface_1.default;
16
+ const interface_1 = __importDefault(require("./base/interface"));
17
+ exports.AntInterface = interface_1.default;
18
18
  const af = adapter_factory_1.default.getInstance();
19
19
  af.register('PWR', 'Power Meter', pwr_1.default);
20
20
  af.register('HR', 'Heartrate Monitor', hr_1.default);
@@ -4,6 +4,7 @@ import AntAdapter from './base/adapter';
4
4
  export interface AntDeviceSettings extends DeviceSettings {
5
5
  deviceID?: string;
6
6
  profile: Profile | LegacyProfile;
7
+ interface: string;
7
8
  protocol?: string;
8
9
  }
9
10
  export type LegacyProfile = 'Heartrate Monitor' | 'Power Meter' | 'Smart Trainer' | 'Speed Sensor' | 'Cadence Sensor' | 'Speed + Cadence Sensor';
@@ -40,3 +41,11 @@ export interface ConnectState {
40
41
  connected: boolean;
41
42
  connecting: boolean;
42
43
  }
44
+ export interface AdapterStartStatus {
45
+ timeout: boolean;
46
+ sensorStarted: boolean;
47
+ hasData: boolean;
48
+ userInitialized?: boolean;
49
+ controlInitialized?: boolean;
50
+ interrupted?: boolean;
51
+ }
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const types_1 = require("../types");
15
16
  const events_1 = __importDefault(require("events"));
16
17
  const consts_1 = require("./consts");
17
18
  class IncyclistDevice extends events_1.default {
@@ -42,7 +43,7 @@ class IncyclistDevice extends events_1.default {
42
43
  getName() {
43
44
  return this.settings.name;
44
45
  }
45
- getID() { throw new Error('not implemented'); }
46
+ getID() { return ''; }
46
47
  getUniqueName() {
47
48
  throw new Error("Method not implemented.");
48
49
  }
@@ -62,12 +63,14 @@ class IncyclistDevice extends events_1.default {
62
63
  stop() { throw new Error("Method not implemented."); }
63
64
  pause() {
64
65
  return __awaiter(this, void 0, void 0, function* () {
66
+ this.logEvent({ message: 'pausing device', device: this.getName() });
65
67
  this.paused = true;
66
68
  return true;
67
69
  });
68
70
  }
69
71
  resume() {
70
72
  return __awaiter(this, void 0, void 0, function* () {
73
+ this.logger.logEvent({ message: 'resuming device', device: this.getName() });
71
74
  this.paused = false;
72
75
  return true;
73
76
  });
@@ -170,7 +173,12 @@ class IncyclistDevice extends events_1.default {
170
173
  sendUpdate(request) {
171
174
  if (!this.isControllable())
172
175
  return;
173
- throw new Error("Method not implemented.");
176
+ if (this.isPaused() || this.isStopped())
177
+ return;
178
+ if (!this.hasCapability(types_1.IncyclistCapability.Control))
179
+ this.getCyclingMode().sendBikeUpdate(request);
180
+ else
181
+ throw new Error('method not implemented');
174
182
  }
175
183
  setUser(user) {
176
184
  this.user = user;
@@ -2,29 +2,30 @@ import BleAdapter from "./base/adapter";
2
2
  import { BleDeviceSettings, BleProtocol } from "./types";
3
3
  import { DeviceProperties } from "../types";
4
4
  import { BleComms } from "./base/comms";
5
+ import { BleDeviceData } from "./base/types";
5
6
  export interface BleAdapterInfo {
6
7
  protocol: BleProtocol;
7
- Adapter: typeof BleAdapter;
8
+ Adapter: typeof BleAdapter<BleDeviceData, BleComms>;
8
9
  Comm: typeof BleComms;
9
10
  }
10
11
  export default class BleAdapterFactory {
11
12
  static _instance: BleAdapterFactory;
12
13
  implementations: BleAdapterInfo[];
13
- instances: Array<BleAdapter>;
14
+ instances: Array<BleAdapter<BleDeviceData, BleComms>>;
14
15
  static getInstance(): BleAdapterFactory;
15
16
  constructor();
16
17
  getAdapterInfo(protocol: BleProtocol): BleAdapterInfo;
17
18
  getAll(): BleAdapterInfo[];
18
- createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter;
19
+ createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, BleComms>;
19
20
  removeInstance(query: {
20
21
  settings?: BleDeviceSettings;
21
- adapter?: BleAdapter;
22
+ adapter?: BleAdapter<BleDeviceData, BleComms>;
22
23
  }): void;
23
- find(settings?: BleDeviceSettings): BleAdapter;
24
- register(protocol: BleProtocol, Adapter: typeof BleAdapter, Comm: typeof BleComms): void;
25
- getAllInstances(): Array<BleAdapter>;
24
+ find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData, BleComms>;
25
+ register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData, BleComms>, Comm: typeof BleComms): void;
26
+ getAllInstances(): Array<BleAdapter<BleDeviceData, BleComms>>;
26
27
  getAllSupportedComms(): (typeof BleComms)[];
27
- getAllSupportedAdapters(): Array<(typeof BleAdapter)>;
28
+ getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData, BleComms>)>;
28
29
  getAllSupportedServices(): string[];
29
30
  getDeviceClasses(peripheral: any, props?: {
30
31
  protocol?: BleProtocol;
@@ -3,28 +3,31 @@ import { BleComms } from "./comms";
3
3
  import BleInterface from "../ble-interface";
4
4
  import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from "../types";
5
5
  import { IAdapter, IncyclistBikeData, IncyclistAdapterData, DeviceProperties } from "../../types";
6
- export default class BleAdapter extends IncyclistDevice<BleDeviceProperties> {
7
- ble: BleInterface;
8
- deviceData: any;
9
- data: IncyclistAdapterData;
10
- dataMsgCount: number;
11
- lastDataTS: number;
12
- device: BleComms;
6
+ import { BleDeviceData } from "./types";
7
+ import { LegacyProfile } from "../../antv2/types";
8
+ export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice extends BleComms> extends IncyclistDevice<BleDeviceProperties> {
9
+ protected ble: BleInterface;
10
+ protected deviceData: TDeviceData;
11
+ protected data: IncyclistAdapterData;
12
+ protected dataMsgCount: number;
13
+ protected lastDataTS: number;
14
+ protected device: TDevice;
13
15
  constructor(settings: BleDeviceSettings, props?: DeviceProperties);
14
16
  getUniqueName(): string;
15
17
  connect(): Promise<boolean>;
16
18
  close(): Promise<boolean>;
17
- getComms(): BleComms;
19
+ getComms(): TDevice;
18
20
  isEqual(settings: BleDeviceSettings): boolean;
19
21
  isSame(adapter: IAdapter): boolean;
20
22
  isConnected(): boolean;
21
23
  resetData(): void;
22
24
  getInterface(): string;
25
+ getProfile(): LegacyProfile;
23
26
  getProtocolName(): string;
24
27
  getID(): string;
25
28
  getName(): string;
26
- onDeviceData(deviceData: any): void;
27
- mapData(deviceData: any): IncyclistAdapterData | IncyclistBikeData;
29
+ onDeviceData(deviceData: TDeviceData): void;
30
+ mapData(deviceData: TDeviceData): IncyclistAdapterData | IncyclistBikeData;
28
31
  transformData(data: IncyclistBikeData): IncyclistAdapterData;
29
32
  getSettings(): BleDeviceSettings;
30
33
  setProperties(props: BleDeviceProperties): void;
@@ -27,9 +27,10 @@ class BleAdapter extends adpater_1.default {
27
27
  this.ble = ble_interface_1.default.getInstance();
28
28
  }
29
29
  getUniqueName() {
30
+ var _a;
30
31
  const settings = this.settings;
31
- if (settings.name.match(/[0-9]/g) || settings.address === undefined)
32
- return this.settings.name;
32
+ if (((_a = settings.name) === null || _a === void 0 ? void 0 : _a.match(/[0-9]/g)) || settings.address === undefined)
33
+ return this.getName();
33
34
  else {
34
35
  const addressHash = settings.address.substring(0, 2) + settings.address.slice(-2);
35
36
  return `${this.getName()} ${addressHash}`;
@@ -56,11 +57,7 @@ class BleAdapter extends adpater_1.default {
56
57
  return __awaiter(this, void 0, void 0, function* () {
57
58
  if (!this.device || !this.isConnected())
58
59
  return true;
59
- if (this.device) {
60
- yield this.device.disconnect();
61
- this.ble.removeConnectedDevice(this);
62
- return true;
63
- }
60
+ return yield this.device.disconnect();
64
61
  });
65
62
  }
66
63
  getComms() {
@@ -94,13 +91,17 @@ class BleAdapter extends adpater_1.default {
94
91
  getInterface() {
95
92
  return INTERFACE_NAME;
96
93
  }
94
+ getProfile() {
95
+ const C = this.constructor;
96
+ return C['INCYCLIST_PROFILE_NAME'];
97
+ }
97
98
  getProtocolName() {
98
99
  const settings = this.settings;
99
100
  return settings.protocol;
100
101
  }
101
102
  getID() {
102
103
  const settings = this.settings;
103
- return settings.id;
104
+ return settings.id || settings.address;
104
105
  }
105
106
  getName() {
106
107
  const settings = this.settings;
@@ -0,0 +1,2 @@
1
+ export interface BleDeviceData {
2
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,7 +5,6 @@ import BleAdapterFactory from './adapter-factory';
5
5
  import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic } from './types';
6
6
  import { BleComms } from './base/comms';
7
7
  import { IncyclistInterface, IncyclistScanProps } from '../types';
8
- import BleAdapter from './base/adapter';
9
8
  import BlePeripheralCache from './peripheral-cache';
10
9
  import EventEmitter from 'events';
11
10
  export interface ScanState {
@@ -39,7 +38,6 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
39
38
  logger: EventLogger;
40
39
  props: BleInterfaceProps;
41
40
  binding: BleBinding;
42
- connectedDevices: Array<BleAdapter>;
43
41
  sensorIsConnecting: boolean;
44
42
  emittingAdapters: {
45
43
  comms: BleComms;
@@ -78,6 +76,4 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
78
76
  scan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
79
77
  stopScan(): Promise<boolean>;
80
78
  isScanning(): boolean;
81
- addConnectedDevice(device: BleAdapter): void;
82
- removeConnectedDevice(device: BleAdapter): void;
83
79
  }
@@ -47,7 +47,6 @@ class BleInterface extends events_1.default {
47
47
  if (props.binding)
48
48
  this.setBinding(props.binding);
49
49
  this.peripheralCache = new peripheral_cache_1.default();
50
- this.connectedDevices = [];
51
50
  if (props.logger)
52
51
  this.logger = props.logger;
53
52
  else
@@ -542,15 +541,5 @@ class BleInterface extends events_1.default {
542
541
  isScanning() {
543
542
  return this.scanState.isScanning === true;
544
543
  }
545
- addConnectedDevice(device) {
546
- const idx = this.connectedDevices.findIndex(d => d.isSame(device));
547
- if (idx === -1)
548
- this.connectedDevices.push(device);
549
- }
550
- removeConnectedDevice(device) {
551
- const idx = this.connectedDevices.findIndex(d => d.isSame(device));
552
- if (idx !== -1)
553
- this.connectedDevices.splice(idx);
554
- }
555
544
  }
556
545
  exports.default = BleInterface;
@@ -1,17 +1,19 @@
1
+ import BleCyclingPowerDevice from './comm';
1
2
  import BleAdapter from '../base/adapter';
2
3
  import { PowerData } from './types';
3
4
  import { BleDeviceSettings } from '../types';
4
5
  import { DeviceProperties, IncyclistBikeData, IncyclistAdapterData, ControllerConfig, IAdapter } from '../../types';
5
- export default class PwrAdapter extends BleAdapter {
6
+ import { LegacyProfile } from '../../antv2/types';
7
+ export default class PwrAdapter extends BleAdapter<PowerData, BleCyclingPowerDevice> {
8
+ protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
6
9
  protected static controllers: ControllerConfig;
7
10
  distanceInternal: number;
8
11
  constructor(settings: BleDeviceSettings, props?: DeviceProperties);
9
12
  isSame(device: IAdapter): boolean;
10
- getProfile(): string;
13
+ getProfile(): LegacyProfile;
11
14
  getName(): string;
12
15
  getDisplayName(): string;
13
16
  mapData(deviceData: PowerData): IncyclistBikeData;
14
17
  transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
15
- sendUpdate(request: any): Promise<void>;
16
18
  stop(): Promise<boolean>;
17
19
  }
@@ -82,13 +82,6 @@ class PwrAdapter extends adapter_1.default {
82
82
  };
83
83
  return data;
84
84
  }
85
- sendUpdate(request) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- if (this.paused)
88
- return;
89
- this.getCyclingMode().sendBikeUpdate(request);
90
- });
91
- }
92
85
  stop() {
93
86
  const _super = Object.create(null, {
94
87
  stop: { get: () => super.stop }
@@ -101,6 +94,7 @@ class PwrAdapter extends adapter_1.default {
101
94
  });
102
95
  }
103
96
  }
97
+ PwrAdapter.INCYCLIST_PROFILE_NAME = 'Power Meter';
104
98
  PwrAdapter.controllers = {
105
99
  modes: [power_meter_1.default],
106
100
  default: power_meter_1.default
@@ -1,19 +1,21 @@
1
1
  import BleAdapter from '../base/adapter';
2
+ import BleEliteDevice from './comms';
2
3
  import ICyclingMode from '../../modes/types';
3
4
  import { PowerData } from '../cp';
4
5
  import { DeviceProperties, IncyclistAdapterData, IncyclistBikeData, ControllerConfig, IAdapter } from '../../types';
5
6
  import { BleDeviceSettings } from '../types';
6
- export default class BleEliteAdapter extends BleAdapter {
7
+ import { LegacyProfile } from '../../antv2/types';
8
+ export default class BleEliteAdapter extends BleAdapter<PowerData, BleEliteDevice> {
9
+ protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
7
10
  protected static controllers: ControllerConfig;
8
11
  distanceInternal: number;
9
12
  constructor(settings: BleDeviceSettings, props?: DeviceProperties);
10
13
  isSame(device: IAdapter): boolean;
11
- getProfile(): string;
14
+ getProfile(): LegacyProfile;
12
15
  getName(): string;
13
16
  getDefaultCyclingMode(): ICyclingMode;
14
17
  getSupportedCyclingModes(): any[];
15
18
  mapData(deviceData: PowerData): IncyclistBikeData;
16
19
  transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
17
20
  start(props?: any): Promise<any>;
18
- sendUpdate(request: any): Promise<void>;
19
21
  }