incyclist-devices 2.1.2 → 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.
- package/lib/antv2/base/adapter.d.ts +0 -1
- package/lib/antv2/base/adapter.js +16 -22
- package/lib/antv2/base/interface.js +10 -4
- package/lib/antv2/fe/adapter.js +7 -7
- package/lib/base/adpater.js +10 -2
- package/lib/ble/adapter-factory.d.ts +9 -8
- package/lib/ble/base/adapter.d.ts +13 -10
- package/lib/ble/base/adapter.js +9 -8
- package/lib/ble/base/types.d.ts +2 -0
- package/lib/ble/base/types.js +2 -0
- package/lib/ble/ble-interface.d.ts +0 -4
- package/lib/ble/ble-interface.js +0 -11
- package/lib/ble/cp/adapter.d.ts +5 -3
- package/lib/ble/cp/adapter.js +1 -7
- package/lib/ble/elite/adapter.d.ts +5 -3
- package/lib/ble/elite/adapter.js +1 -7
- package/lib/ble/fm/adapter.d.ts +4 -3
- package/lib/ble/fm/adapter.js +1 -6
- package/lib/ble/hr/adapter.d.ts +4 -2
- package/lib/ble/hr/adapter.js +1 -3
- package/lib/ble/peripheral-cache.d.ts +3 -1
- package/lib/ble/tacx/adapter.d.ts +3 -1
- package/lib/ble/tacx/adapter.js +1 -0
- package/lib/ble/wahoo/adapter.d.ts +3 -1
- package/lib/ble/wahoo/adapter.js +1 -0
- package/lib/modes/power-base.js +1 -4
- package/package.json +1 -1
|
@@ -55,7 +55,6 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData> extends Incy
|
|
|
55
55
|
checkCapabilities(): Promise<void>;
|
|
56
56
|
initControl(): Promise<void>;
|
|
57
57
|
getDefaultStartupTimeout(): number;
|
|
58
|
-
sendUpdate(request: any): void;
|
|
59
58
|
startPreChecks(props: AntDeviceProperties): Promise<'done' | 'connected' | 'connection-failed'>;
|
|
60
59
|
resetStartStatus(): void;
|
|
61
60
|
isStartSuccess(): boolean;
|
|
@@ -188,10 +188,11 @@ class AntAdapter extends adpater_1.default {
|
|
|
188
188
|
return id.toString();
|
|
189
189
|
}
|
|
190
190
|
getName() {
|
|
191
|
+
var _a;
|
|
191
192
|
if (this.settings.name)
|
|
192
193
|
return this.settings.name;
|
|
193
|
-
const deviceID = this.
|
|
194
|
-
const profile = this.sensor.getProfile();
|
|
194
|
+
const deviceID = this.getID();
|
|
195
|
+
const profile = (_a = this.sensor) === null || _a === void 0 ? void 0 : _a.getProfile();
|
|
195
196
|
return `Ant+${profile} ${deviceID}`;
|
|
196
197
|
}
|
|
197
198
|
getUniqueName() {
|
|
@@ -250,16 +251,6 @@ class AntAdapter extends adpater_1.default {
|
|
|
250
251
|
getDefaultStartupTimeout() {
|
|
251
252
|
return 20000;
|
|
252
253
|
}
|
|
253
|
-
sendUpdate(request) {
|
|
254
|
-
if (!this.isControllable())
|
|
255
|
-
return;
|
|
256
|
-
if (this.isPaused() || this.isStopped())
|
|
257
|
-
return;
|
|
258
|
-
if (!this.hasCapability(types_2.IncyclistCapability.Control))
|
|
259
|
-
this.getCyclingMode().sendBikeUpdate(request);
|
|
260
|
-
else
|
|
261
|
-
throw new Error('method not implemented');
|
|
262
|
-
}
|
|
263
254
|
startPreChecks(props) {
|
|
264
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
256
|
const wasPaused = this.paused;
|
|
@@ -294,7 +285,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
294
285
|
reportStartStatus() {
|
|
295
286
|
const success = this.isStartSuccess();
|
|
296
287
|
if (success) {
|
|
297
|
-
this.logEvent({ message: 'start device success' });
|
|
288
|
+
this.logEvent({ message: 'start device success', device: this.getName() });
|
|
298
289
|
this.started = true;
|
|
299
290
|
this.paused = false;
|
|
300
291
|
return true;
|
|
@@ -305,15 +296,15 @@ class AntAdapter extends adpater_1.default {
|
|
|
305
296
|
if (interrupted)
|
|
306
297
|
return;
|
|
307
298
|
if (!sensorStarted) {
|
|
308
|
-
this.logEvent({ message: 'start device failed', reason: 'could not connect' });
|
|
299
|
+
this.logEvent({ message: 'start device failed', device: this.getName(), reason: 'could not connect' });
|
|
309
300
|
throw new Error('could not start device, reason:could not connect');
|
|
310
301
|
}
|
|
311
302
|
else if (!hasData) {
|
|
312
|
-
this.logEvent({ message: 'start device failed', reason: 'no data received' });
|
|
303
|
+
this.logEvent({ message: 'start device failed', device: this.getName(), reason: 'no data received' });
|
|
313
304
|
throw new Error('could not start device, reason:no data received');
|
|
314
305
|
}
|
|
315
306
|
else {
|
|
316
|
-
this.logEvent({ message: 'start device failed', reason: 'could not send FE commands' });
|
|
307
|
+
this.logEvent({ message: 'start device failed', device: this.getName(), reason: 'could not send FE commands' });
|
|
317
308
|
throw new Error('could not start device, reason:could not send FE commands');
|
|
318
309
|
}
|
|
319
310
|
}
|
|
@@ -323,10 +314,10 @@ class AntAdapter extends adpater_1.default {
|
|
|
323
314
|
const { sensorStarted, hasData, timeout } = this.startStatus;
|
|
324
315
|
if ((sensorStarted && hasData) || !sensorStarted || timeout)
|
|
325
316
|
return;
|
|
326
|
-
this.logEvent({ message: 'wait for sensor data', });
|
|
317
|
+
this.logEvent({ message: 'wait for sensor data', device: this.getName() });
|
|
327
318
|
this.startStatus.hasData = yield this.waitForData(startupTimeout);
|
|
328
319
|
if (this.startStatus.hasData)
|
|
329
|
-
this.logEvent({ message: 'sensor data received', });
|
|
320
|
+
this.logEvent({ message: 'sensor data received', device: this.getName() });
|
|
330
321
|
});
|
|
331
322
|
}
|
|
332
323
|
initSensor(props) {
|
|
@@ -334,7 +325,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
334
325
|
this.startStatus.sensorStarted = this.sensorConnected;
|
|
335
326
|
if (this.startStatus.sensorStarted || this.startStatus.sensorStarted)
|
|
336
327
|
return;
|
|
337
|
-
this.logEvent({ message: 'start sensor', props });
|
|
328
|
+
this.logEvent({ message: 'start sensor', device: this.getName(), props });
|
|
338
329
|
try {
|
|
339
330
|
this.sensorConnected = yield this.startSensor();
|
|
340
331
|
if (this.sensorConnected) {
|
|
@@ -343,7 +334,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
343
334
|
}
|
|
344
335
|
}
|
|
345
336
|
catch (err) {
|
|
346
|
-
this.logEvent({ message: 'start sensor failed', reason: err.message, props });
|
|
337
|
+
this.logEvent({ message: 'start sensor failed', device: this.getName(), reason: err.message, props });
|
|
347
338
|
}
|
|
348
339
|
});
|
|
349
340
|
}
|
|
@@ -354,7 +345,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
354
345
|
return this.started;
|
|
355
346
|
if (preCheckResult === 'connection-failed')
|
|
356
347
|
throw new Error(`could not start device, reason:could not connect`);
|
|
357
|
-
this.logEvent({ message: 'starting device', props, isStarted: this.started });
|
|
348
|
+
this.logEvent({ message: 'starting device', device: this.getName(), props, isStarted: this.started });
|
|
358
349
|
this.resetStartStatus();
|
|
359
350
|
this.resetData();
|
|
360
351
|
const { startupTimeout = this.getDefaultStartupTimeout() } = props || {};
|
|
@@ -379,7 +370,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
379
370
|
success = this.isStartSuccess();
|
|
380
371
|
}
|
|
381
372
|
catch (err) {
|
|
382
|
-
this.logEvent({ message: 'error', fn: 'start#doStart', error: err.message, stack: err.stack });
|
|
373
|
+
this.logEvent({ message: 'error', fn: 'start#doStart', device: this.getName(), error: err.message, stack: err.stack });
|
|
383
374
|
}
|
|
384
375
|
}
|
|
385
376
|
this.reportStartStatus();
|
|
@@ -392,6 +383,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
392
383
|
if (err.message === 'Timeout') {
|
|
393
384
|
this.started = false;
|
|
394
385
|
this.startStatus.timeout = true;
|
|
386
|
+
this.logEvent({ message: 'start device failed', device: this.getName(), reason: 'timeout' });
|
|
395
387
|
throw new Error(`could not start device, reason:timeout`);
|
|
396
388
|
}
|
|
397
389
|
throw err;
|
|
@@ -402,6 +394,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
402
394
|
stop() {
|
|
403
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
404
396
|
let stopped;
|
|
397
|
+
this.logger.logEvent({ message: 'stopping device', device: this.getName() });
|
|
405
398
|
this.promiseWaitForData = null;
|
|
406
399
|
if (this.startStatus)
|
|
407
400
|
this.startStatus.interrupted = true;
|
|
@@ -416,6 +409,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
416
409
|
this.stopped = true;
|
|
417
410
|
this.paused = false;
|
|
418
411
|
this.removeAllListeners();
|
|
412
|
+
this.logEvent({ message: 'stopping device finished', device: this.getName(), stopped });
|
|
419
413
|
return stopped;
|
|
420
414
|
});
|
|
421
415
|
}
|
|
@@ -134,6 +134,7 @@ class AntInterface extends events_1.default {
|
|
|
134
134
|
return 1000;
|
|
135
135
|
}
|
|
136
136
|
scannerWaitForConnection() {
|
|
137
|
+
var _a;
|
|
137
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
139
|
let scanFinished = false;
|
|
139
140
|
let scanStopRequested = false;
|
|
@@ -152,7 +153,7 @@ class AntInterface extends events_1.default {
|
|
|
152
153
|
}
|
|
153
154
|
if (scanStopRequested)
|
|
154
155
|
this.emit('scan stopped', true);
|
|
155
|
-
this.activeScan.emitter.removeAllListeners();
|
|
156
|
+
(_a = this.activeScan) === null || _a === void 0 ? void 0 : _a.emitter.removeAllListeners();
|
|
156
157
|
});
|
|
157
158
|
}
|
|
158
159
|
scan(props = {}) {
|
|
@@ -162,8 +163,8 @@ class AntInterface extends events_1.default {
|
|
|
162
163
|
return yield this.scanPromise;
|
|
163
164
|
}
|
|
164
165
|
this.activeScan = { emitter: new events_1.default() };
|
|
166
|
+
const detected = [];
|
|
165
167
|
const _scan = () => new Promise((done) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
const detected = [];
|
|
167
168
|
const onDetected = (profile, deviceID) => {
|
|
168
169
|
if (deviceID && detected.find(s => s.deviceID === deviceID && s.profile === profile) === undefined) {
|
|
169
170
|
try {
|
|
@@ -222,19 +223,23 @@ class AntInterface extends events_1.default {
|
|
|
222
223
|
}));
|
|
223
224
|
this.activeScan.emitter.on('timeout', () => __awaiter(this, void 0, void 0, function* () {
|
|
224
225
|
this.activeScan.emitter.removeAllListeners();
|
|
226
|
+
yield this.activeScan.channel.stopScanner();
|
|
225
227
|
this.emit('stop-scan');
|
|
226
228
|
removeListeners(channel);
|
|
229
|
+
this.logEvent({ message: 'scan finished(timeout) ..' });
|
|
227
230
|
done(detected);
|
|
228
231
|
}));
|
|
229
232
|
}));
|
|
230
233
|
const { timeout } = props;
|
|
231
234
|
this.scanPromise = _scan();
|
|
232
235
|
if (timeout) {
|
|
233
|
-
|
|
236
|
+
yield (0, utils_1.waitWithTimeout)(this.scanPromise, timeout, () => {
|
|
234
237
|
var _a;
|
|
235
238
|
(_a = this.activeScan) === null || _a === void 0 ? void 0 : _a.emitter.emit('timeout');
|
|
236
239
|
});
|
|
237
|
-
|
|
240
|
+
this.scanPromise = null;
|
|
241
|
+
this.activeScan = null;
|
|
242
|
+
return detected;
|
|
238
243
|
}
|
|
239
244
|
else {
|
|
240
245
|
const res = yield this.scanPromise;
|
|
@@ -255,6 +260,7 @@ class AntInterface extends events_1.default {
|
|
|
255
260
|
return new Promise(done => {
|
|
256
261
|
this.activeScan.emitter.emit('stop');
|
|
257
262
|
this.once('scan stopped', (res) => {
|
|
263
|
+
this.logEvent({ message: 'stopping scan done ..' });
|
|
258
264
|
done(res);
|
|
259
265
|
});
|
|
260
266
|
});
|
package/lib/antv2/fe/adapter.js
CHANGED
|
@@ -42,7 +42,7 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
42
42
|
return;
|
|
43
43
|
let isReset = request.reset && Object.keys(request).length === 1;
|
|
44
44
|
const update = isReset ? this.getCyclingMode().getBikeInitRequest() : this.getCyclingMode().sendBikeUpdate(request);
|
|
45
|
-
this.logEvent({ message: 'send bike update requested', update, request });
|
|
45
|
+
this.logEvent({ message: 'send bike update requested', device: this.getName(), update, request });
|
|
46
46
|
try {
|
|
47
47
|
const fe = this.sensor;
|
|
48
48
|
if (update.slope !== undefined) {
|
|
@@ -59,7 +59,7 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
59
59
|
yield this.reconnect();
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
this.logEvent({ message: 'sendBikeUpdate() error', error: err.message });
|
|
62
|
+
this.logEvent({ message: 'sendBikeUpdate() error', device: this.getName(), error: err.message });
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
}
|
|
@@ -164,7 +164,7 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
164
164
|
this.startStatus.userInitialized = yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio);
|
|
165
165
|
}
|
|
166
166
|
catch (err) {
|
|
167
|
-
this.logEvent({ message: 'sending FE message error', error: err.message });
|
|
167
|
+
this.logEvent({ message: 'sending FE message error', device: this.getName(), error: err.message });
|
|
168
168
|
this.startStatus.userInitialized = false;
|
|
169
169
|
}
|
|
170
170
|
});
|
|
@@ -193,7 +193,7 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
catch (err) {
|
|
196
|
-
this.logEvent({ message: 'sending FE message error', error: err.message });
|
|
196
|
+
this.logEvent({ message: 'sending FE message error', device: this.getName(), error: err.message });
|
|
197
197
|
this.startStatus.controlInitialized = false;
|
|
198
198
|
}
|
|
199
199
|
});
|
|
@@ -209,7 +209,7 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
209
209
|
}
|
|
210
210
|
reconnect() {
|
|
211
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
this.logEvent({ message: 'reconnect to device' });
|
|
212
|
+
this.logEvent({ message: 'reconnect to device', device: this.getName() });
|
|
213
213
|
if (this.promiseReconnect) {
|
|
214
214
|
return yield this.promiseReconnect;
|
|
215
215
|
}
|
|
@@ -218,11 +218,11 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
218
218
|
yield this.stop();
|
|
219
219
|
yield this.start(Object.assign(Object.assign({}, this.startProps), { reconnect: true }));
|
|
220
220
|
this.started = true;
|
|
221
|
-
this.logEvent({ message: 'reconnect success' });
|
|
221
|
+
this.logEvent({ message: 'reconnect success', device: this.getName() });
|
|
222
222
|
return true;
|
|
223
223
|
}
|
|
224
224
|
catch (err) {
|
|
225
|
-
this.logEvent({ message: 'reconnect failed' });
|
|
225
|
+
this.logEvent({ message: 'reconnect failed', device: this.getName() });
|
|
226
226
|
return false;
|
|
227
227
|
}
|
|
228
228
|
});
|
package/lib/base/adpater.js
CHANGED
|
@@ -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() {
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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():
|
|
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:
|
|
27
|
-
mapData(deviceData:
|
|
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;
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
}
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -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;
|
package/lib/ble/cp/adapter.d.ts
CHANGED
|
@@ -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
|
-
|
|
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():
|
|
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
|
}
|
package/lib/ble/cp/adapter.js
CHANGED
|
@@ -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
|
-
|
|
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():
|
|
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
|
}
|
package/lib/ble/elite/adapter.js
CHANGED
|
@@ -109,14 +109,8 @@ class BleEliteAdapter extends adapter_1.default {
|
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
sendUpdate(request) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
if (this.paused)
|
|
115
|
-
return;
|
|
116
|
-
this.getCyclingMode().sendBikeUpdate(request);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
112
|
}
|
|
113
|
+
BleEliteAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
|
|
120
114
|
BleEliteAdapter.controllers = {
|
|
121
115
|
modes: [power_meter_1.default],
|
|
122
116
|
default: power_meter_1.default
|
package/lib/ble/fm/adapter.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import BleFitnessMachineDevice from './comms';
|
|
1
2
|
import BleAdapter from '../base/adapter';
|
|
2
3
|
import ICyclingMode, { CyclingMode } from '../../modes/types';
|
|
3
4
|
import { IndoorBikeData } from './types';
|
|
4
5
|
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from '../types';
|
|
5
6
|
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../../types';
|
|
6
|
-
|
|
7
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
8
|
+
export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessMachineDevice> {
|
|
9
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
7
10
|
distanceInternal: number;
|
|
8
11
|
connectPromise: Promise<boolean>;
|
|
9
12
|
constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
|
|
10
13
|
isSame(device: IAdapter): boolean;
|
|
11
|
-
getProfile(): string;
|
|
12
14
|
getName(): string;
|
|
13
|
-
getDisplayName(): string;
|
|
14
15
|
isControllable(): boolean;
|
|
15
16
|
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
16
17
|
getDefaultCyclingMode(): ICyclingMode;
|
package/lib/ble/fm/adapter.js
CHANGED
|
@@ -40,15 +40,9 @@ class BleFmAdapter extends adapter_1.default {
|
|
|
40
40
|
return false;
|
|
41
41
|
return this.isEqual(device.settings);
|
|
42
42
|
}
|
|
43
|
-
getProfile() {
|
|
44
|
-
return 'Smart Trainer';
|
|
45
|
-
}
|
|
46
43
|
getName() {
|
|
47
44
|
return `${this.device.name}`;
|
|
48
45
|
}
|
|
49
|
-
getDisplayName() {
|
|
50
|
-
return this.getName();
|
|
51
|
-
}
|
|
52
46
|
isControllable() {
|
|
53
47
|
return true;
|
|
54
48
|
}
|
|
@@ -258,4 +252,5 @@ class BleFmAdapter extends adapter_1.default {
|
|
|
258
252
|
});
|
|
259
253
|
}
|
|
260
254
|
}
|
|
255
|
+
BleFmAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
|
|
261
256
|
exports.default = BleFmAdapter;
|
package/lib/ble/hr/adapter.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import BleAdapter from '../base/adapter';
|
|
2
|
+
import BleHrmDevice from './comm';
|
|
2
3
|
import { IncyclistAdapterData, IAdapter, DeviceProperties } from '../../types';
|
|
3
4
|
import { BleDeviceSettings } from '../types';
|
|
4
5
|
import { HrmData } from './types';
|
|
5
|
-
|
|
6
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
7
|
+
export default class HrmAdapter extends BleAdapter<HrmData, BleHrmDevice> {
|
|
8
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
6
9
|
ignore: boolean;
|
|
7
10
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
8
11
|
isSame(device: IAdapter): boolean;
|
|
9
|
-
getProfile(): string;
|
|
10
12
|
getName(): string;
|
|
11
13
|
getDisplayName(): string;
|
|
12
14
|
mapData(deviceData: HrmData): IncyclistAdapterData;
|
package/lib/ble/hr/adapter.js
CHANGED
|
@@ -25,9 +25,6 @@ class HrmAdapter extends adapter_1.default {
|
|
|
25
25
|
return false;
|
|
26
26
|
return this.isEqual(device.settings);
|
|
27
27
|
}
|
|
28
|
-
getProfile() {
|
|
29
|
-
return 'Heartrate Monitor';
|
|
30
|
-
}
|
|
31
28
|
getName() {
|
|
32
29
|
return `${this.device.name}`;
|
|
33
30
|
}
|
|
@@ -42,4 +39,5 @@ class HrmAdapter extends adapter_1.default {
|
|
|
42
39
|
return { heartrate };
|
|
43
40
|
}
|
|
44
41
|
}
|
|
42
|
+
HrmAdapter.INCYCLIST_PROFILE_NAME = 'Heartrate Monitor';
|
|
45
43
|
exports.default = HrmAdapter;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import BleAdapter from "./base/adapter";
|
|
2
|
+
import { BleComms } from "./base/comms";
|
|
3
|
+
import { BleDeviceData } from "./base/types";
|
|
2
4
|
import BlePeripheralConnector from "./ble-peripheral";
|
|
3
5
|
import { BleCharacteristic, BlePeripheral } from "./types";
|
|
4
6
|
export interface PeripheralState {
|
|
@@ -18,7 +20,7 @@ export interface PeripheralCacheItem {
|
|
|
18
20
|
}
|
|
19
21
|
export default class BlePeripheralCache {
|
|
20
22
|
peripherals: PeripheralCacheItem[];
|
|
21
|
-
findAdapter(adapter: BleAdapter): PeripheralCacheItem;
|
|
23
|
+
findAdapter(adapter: BleAdapter<BleDeviceData, BleComms>): PeripheralCacheItem;
|
|
22
24
|
getConnector(peripheral: BlePeripheral): BlePeripheralConnector;
|
|
23
25
|
getPeripheral(query: {
|
|
24
26
|
id?: string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { BleFmAdapter } from '../fm';
|
|
2
2
|
import { BleDeviceSettings, BleStartProperties } from '../types';
|
|
3
3
|
import { DeviceProperties, IAdapter } from '../../types';
|
|
4
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
4
5
|
export default class BleTacxFEAdapter extends BleFmAdapter {
|
|
6
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
5
7
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
6
8
|
isSame(device: IAdapter): boolean;
|
|
7
|
-
getProfile():
|
|
9
|
+
getProfile(): LegacyProfile;
|
|
8
10
|
start(props?: BleStartProperties): Promise<any>;
|
|
9
11
|
}
|
package/lib/ble/tacx/adapter.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { BleFmAdapter } from '../fm';
|
|
2
2
|
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from '../types';
|
|
3
3
|
import { IAdapter } from '../../types';
|
|
4
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
4
5
|
export default class BleWahooAdapter extends BleFmAdapter {
|
|
6
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
5
7
|
constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
|
|
6
8
|
isSame(device: IAdapter): boolean;
|
|
7
|
-
getProfile():
|
|
9
|
+
getProfile(): LegacyProfile;
|
|
8
10
|
start(props?: BleStartProperties): Promise<any>;
|
|
9
11
|
}
|
package/lib/ble/wahoo/adapter.js
CHANGED
package/lib/modes/power-base.js
CHANGED
|
@@ -22,10 +22,7 @@ class PowerBasedCyclingModeBase extends base_1.CyclingModeBase {
|
|
|
22
22
|
return slope || 0;
|
|
23
23
|
}
|
|
24
24
|
initLogger(defaultLogName) {
|
|
25
|
-
|
|
26
|
-
this.logger = a.getLogger();
|
|
27
|
-
if (!this.logger)
|
|
28
|
-
this.logger = new gd_eventlog_1.EventLogger(defaultLogName);
|
|
25
|
+
this.logger = new gd_eventlog_1.EventLogger(defaultLogName);
|
|
29
26
|
}
|
|
30
27
|
getWeight() {
|
|
31
28
|
const a = this.adapter;
|