incyclist-devices 1.4.23 → 1.4.26
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/CyclingMode.js +1 -0
- package/lib/Device.js +1 -0
- package/lib/DeviceProtocol.d.ts +1 -0
- package/lib/DeviceProtocol.js +2 -0
- package/lib/DeviceSupport.js +21 -8
- package/lib/ant/AntAdapter.js +1 -0
- package/lib/ant/AntScanner.js +30 -13
- package/lib/ant/antfe/AntFEAdapter.js +7 -26
- package/lib/ant/anthrm/AntHrmAdapter.js +1 -12
- package/lib/ant/antpwr/AntPWRAdapter.d.ts +24 -0
- package/lib/ant/antpwr/AntPWRAdapter.js +252 -0
- package/lib/ant/antpwr/pwr-adapter.d.ts +48 -0
- package/lib/ant/antpwr/pwr-adapter.js +248 -0
- package/lib/ant/utils.js +3 -1
- package/lib/calculations.js +3 -3
- package/lib/daum/DaumAdapter.d.ts +2 -2
- package/lib/daum/DaumAdapter.js +43 -27
- package/lib/daum/DaumPowerMeterCyclingMode.d.ts +8 -0
- package/lib/daum/DaumPowerMeterCyclingMode.js +21 -0
- package/lib/daum/ERGCyclingMode.d.ts +3 -6
- package/lib/daum/ERGCyclingMode.js +15 -27
- package/lib/daum/SmartTrainerCyclingMode.js +1 -0
- package/lib/daum/classic/DaumClassicAdapter.js +2 -2
- package/lib/daum/classic/DaumClassicProtocol.js +19 -7
- package/lib/daum/classic/bike.js +26 -26
- package/lib/daum/classic/utils.js +1 -0
- package/lib/daum/constants.js +1 -0
- package/lib/daum/premium/DaumClassicCyclingMode.d.ts +2 -2
- package/lib/daum/premium/DaumClassicCyclingMode.js +2 -2
- package/lib/daum/premium/DaumPremiumAdapter.js +2 -2
- package/lib/daum/premium/DaumPremiumProtocol.js +19 -7
- package/lib/daum/premium/bike.js +18 -17
- package/lib/daum/premium/tcpserial.js +0 -1
- package/lib/daum/premium/utils.js +1 -0
- package/lib/kettler/comms.js +2 -1
- package/lib/kettler/ergo-racer/adapter.js +22 -10
- package/lib/kettler/ergo-racer/modes/power-meter.d.ts +2 -2
- package/lib/kettler/ergo-racer/modes/power-meter.js +12 -4
- package/lib/kettler/ergo-racer/protocol.js +19 -7
- package/lib/modes/power-base.d.ts +20 -0
- package/lib/modes/power-base.js +70 -0
- package/lib/modes/power-meter.d.ts +20 -0
- package/lib/modes/power-meter.js +71 -0
- package/lib/modes/simulator.d.ts +27 -0
- package/lib/modes/simulator.js +118 -0
- package/lib/simulator/Simulator.js +23 -10
- package/lib/types/route.js +1 -0
- package/lib/types/user.js +1 -0
- package/lib/utils.js +3 -1
- package/package.json +2 -1
package/lib/CyclingMode.js
CHANGED
package/lib/Device.js
CHANGED
package/lib/DeviceProtocol.d.ts
CHANGED
package/lib/DeviceProtocol.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INTERFACE = void 0;
|
|
3
4
|
exports.INTERFACE = {
|
|
4
5
|
SERIAL: 'serial',
|
|
5
6
|
ANT: 'ant',
|
|
@@ -21,6 +22,7 @@ class DeviceProtocolBase {
|
|
|
21
22
|
scan(props) { throw new Error('not implemented'); }
|
|
22
23
|
stopScan() { throw new Error('not implemented'); }
|
|
23
24
|
isScanning() { throw new Error('not implemented'); }
|
|
25
|
+
add(props) { throw new Error('Method not implemented.'); }
|
|
24
26
|
getDevices() { return this.devices; }
|
|
25
27
|
setAnt(antClass) { DeviceProtocolBase.setAnt(antClass); }
|
|
26
28
|
getAnt() { return DeviceProtocolBase.getAnt(); }
|
package/lib/DeviceSupport.js
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
5
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
15
|
if (mod && mod.__esModule) return mod;
|
|
7
16
|
var result = {};
|
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
|
9
|
-
result
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
10
19
|
return result;
|
|
11
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
12
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.CyclingModeProperyType = exports.AntScanner = exports.Protocols = exports.Device = exports.INTERFACE = exports.DeviceRegistry = exports.DeviceProtocolBase = void 0;
|
|
13
26
|
const DeviceRegistry_1 = __importDefault(require("./DeviceRegistry"));
|
|
14
27
|
exports.DeviceRegistry = DeviceRegistry_1.default;
|
|
15
28
|
const Device_1 = __importDefault(require("./Device"));
|
|
16
29
|
exports.Device = Device_1.default;
|
|
17
30
|
const DeviceProtocol_1 = __importStar(require("./DeviceProtocol"));
|
|
18
31
|
exports.DeviceProtocolBase = DeviceProtocol_1.default;
|
|
19
|
-
exports
|
|
32
|
+
Object.defineProperty(exports, "INTERFACE", { enumerable: true, get: function () { return DeviceProtocol_1.INTERFACE; } });
|
|
20
33
|
const Simulator_1 = __importDefault(require("./simulator/Simulator"));
|
|
21
34
|
const DaumPremiumProtocol_1 = __importDefault(require("./daum/premium/DaumPremiumProtocol"));
|
|
22
35
|
const DaumClassicProtocol_1 = __importDefault(require("./daum/classic/DaumClassicProtocol"));
|
|
23
36
|
const protocol_1 = __importDefault(require("./kettler/ergo-racer/protocol"));
|
|
24
37
|
const AntScanner_1 = require("./ant/AntScanner");
|
|
25
|
-
exports
|
|
38
|
+
Object.defineProperty(exports, "AntScanner", { enumerable: true, get: function () { return AntScanner_1.AntScanner; } });
|
|
26
39
|
const CyclingMode_1 = require("./CyclingMode");
|
|
27
|
-
exports
|
|
40
|
+
Object.defineProperty(exports, "CyclingModeProperyType", { enumerable: true, get: function () { return CyclingMode_1.CyclingModeProperyType; } });
|
|
28
41
|
const Protocols = {
|
|
29
42
|
SimulatorProtocol: Simulator_1.default,
|
|
30
43
|
DaumClassicProtocol: DaumClassicProtocol_1.default,
|
package/lib/ant/AntAdapter.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_UPDATE_FREQUENCY = void 0;
|
|
6
7
|
const Device_1 = __importDefault(require("../Device"));
|
|
7
8
|
exports.DEFAULT_UPDATE_FREQUENCY = 1000;
|
|
8
9
|
class AntAdapter extends Device_1.default {
|
package/lib/ant/AntScanner.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,20 +27,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
28
|
});
|
|
10
29
|
};
|
|
11
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12
|
-
if (mod && mod.__esModule) return mod;
|
|
13
|
-
var result = {};
|
|
14
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
15
|
-
result["default"] = mod;
|
|
16
|
-
return result;
|
|
17
|
-
};
|
|
18
30
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
32
|
};
|
|
21
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.AntScanner = exports.AntProtocol = void 0;
|
|
22
35
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
23
36
|
const DeviceProtocol_1 = __importStar(require("../DeviceProtocol"));
|
|
24
37
|
const AntHrmAdapter_1 = __importDefault(require("./anthrm/AntHrmAdapter"));
|
|
38
|
+
const pwr_adapter_1 = __importDefault(require("./antpwr/pwr-adapter"));
|
|
25
39
|
const AntFEAdapter_1 = __importDefault(require("./antfe/AntFEAdapter"));
|
|
26
40
|
const LOGGER_NAME = 'ANT+Scanner';
|
|
27
41
|
const DEFAULT_SCAN_TIMEOUT = 30000;
|
|
@@ -89,7 +103,8 @@ class AntProtocol extends DeviceProtocol_1.default {
|
|
|
89
103
|
this.scanning = false;
|
|
90
104
|
this.profiles = [
|
|
91
105
|
{ name: 'Heartrate Monitor', Adapter: AntHrmAdapter_1.default },
|
|
92
|
-
{ name: 'Smart Trainer', Adapter: AntFEAdapter_1.default }
|
|
106
|
+
{ name: 'Smart Trainer', Adapter: AntFEAdapter_1.default },
|
|
107
|
+
{ name: 'Power Meter', Adapter: pwr_adapter_1.default }
|
|
93
108
|
];
|
|
94
109
|
}
|
|
95
110
|
add(settings) {
|
|
@@ -229,23 +244,25 @@ class AntProtocol extends DeviceProtocol_1.default {
|
|
|
229
244
|
});
|
|
230
245
|
}
|
|
231
246
|
if (!open) {
|
|
232
|
-
let detachedKernelDriver = false;
|
|
233
247
|
while (devices.length) {
|
|
234
248
|
let device;
|
|
235
249
|
try {
|
|
236
250
|
device = devices.shift();
|
|
237
251
|
device.open();
|
|
238
252
|
const iface = device.interfaces[0];
|
|
253
|
+
let kernelDriverActive = undefined;
|
|
254
|
+
let claimRequested = false;
|
|
239
255
|
try {
|
|
240
|
-
|
|
241
|
-
|
|
256
|
+
kernelDriverActive = iface.isKernelDriverActive();
|
|
257
|
+
if (kernelDriverActive) {
|
|
242
258
|
iface.detachKernelDriver();
|
|
243
259
|
}
|
|
260
|
+
claimRequested = true;
|
|
261
|
+
iface.claim();
|
|
244
262
|
}
|
|
245
263
|
catch (kernelErr) {
|
|
246
|
-
this.logger.logEvent({ message: 'Kernel Error', error: kernelErr.message });
|
|
264
|
+
this.logger.logEvent({ message: 'Kernel Error', error: kernelErr.message, kernelDriverActive, claimRequested });
|
|
247
265
|
}
|
|
248
|
-
iface.claim();
|
|
249
266
|
break;
|
|
250
267
|
}
|
|
251
268
|
catch (deviceErr) {
|
|
@@ -52,7 +52,7 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
52
52
|
getDisplayName() {
|
|
53
53
|
const { DeviceID, ManId, ComputedHeartRate } = this.deviceData;
|
|
54
54
|
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
55
|
-
return `${utils_1.getBrand(ManId)} FE ${DeviceID}${hrmStr}`;
|
|
55
|
+
return `${(0, utils_1.getBrand)(ManId)} FE ${DeviceID}${hrmStr}`;
|
|
56
56
|
}
|
|
57
57
|
onAttached() {
|
|
58
58
|
this.logger.logEvent({ message: 'Device connected' });
|
|
@@ -233,7 +233,7 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
233
233
|
trackResistanceSent: false,
|
|
234
234
|
userSent: false,
|
|
235
235
|
};
|
|
236
|
-
utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
(0, utils_2.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
237
237
|
if (this.isStopped())
|
|
238
238
|
resolve(false);
|
|
239
239
|
try {
|
|
@@ -287,28 +287,9 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
287
287
|
yield _super.stop.call(this);
|
|
288
288
|
this.logger.logEvent({ message: 'stop()' });
|
|
289
289
|
this.stopWorker();
|
|
290
|
-
const Messages = this.getProtocol().getAnt().Messages;
|
|
291
|
-
const stick = this.stick;
|
|
292
|
-
const channel = this.channel;
|
|
293
290
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
294
291
|
this.starting = false;
|
|
295
292
|
return resolve(true);
|
|
296
|
-
if (!this.started && !this.connected)
|
|
297
|
-
return resolve(false);
|
|
298
|
-
try {
|
|
299
|
-
stick.write(Messages.openChannel(channel));
|
|
300
|
-
const protocol = this.getProtocol();
|
|
301
|
-
yield protocol.detachSensor(this);
|
|
302
|
-
this.started = false;
|
|
303
|
-
this.connected = false;
|
|
304
|
-
this.logger.logEvent({ message: 'stop() finished' });
|
|
305
|
-
resolve(true);
|
|
306
|
-
}
|
|
307
|
-
catch (err) {
|
|
308
|
-
this.connected = false;
|
|
309
|
-
this.logger.logEvent({ message: 'stop() error', error: err.message });
|
|
310
|
-
reject(err);
|
|
311
|
-
}
|
|
312
293
|
}));
|
|
313
294
|
});
|
|
314
295
|
}
|
|
@@ -318,18 +299,18 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
318
299
|
try {
|
|
319
300
|
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
320
301
|
if (request.slope !== undefined) {
|
|
321
|
-
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTrackResistance(request.slope); }), 2, 100);
|
|
302
|
+
yield (0, utils_2.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTrackResistance(request.slope); }), 2, 100);
|
|
322
303
|
}
|
|
323
304
|
if (request.targetPower !== undefined) {
|
|
324
|
-
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.targetPower); }), 2, 100);
|
|
305
|
+
yield (0, utils_2.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.targetPower); }), 2, 100);
|
|
325
306
|
}
|
|
326
307
|
else if (request.maxPower !== undefined) {
|
|
327
308
|
if (this.data.power && this.data.power > request.maxPower)
|
|
328
|
-
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.maxPower); }), 2, 100);
|
|
309
|
+
yield (0, utils_2.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.maxPower); }), 2, 100);
|
|
329
310
|
}
|
|
330
311
|
else if (request.minPower !== undefined) {
|
|
331
312
|
if (this.data.power && this.data.power < request.minPower)
|
|
332
|
-
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.minPower); }), 2, 100);
|
|
313
|
+
yield (0, utils_2.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.minPower); }), 2, 100);
|
|
333
314
|
}
|
|
334
315
|
}
|
|
335
316
|
catch (err) {
|
|
@@ -414,7 +395,7 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
414
395
|
this.currentCmd = this.queue.dequeue();
|
|
415
396
|
this.currentCmd.tsStart = Date.now();
|
|
416
397
|
const { msg, logStr } = this.currentCmd;
|
|
417
|
-
this.logger.logEvent({ message: "sending", cmd: logStr, msg: utils_2.hexstr(msg), queueSize: this.queue.size() });
|
|
398
|
+
this.logger.logEvent({ message: "sending", cmd: logStr, msg: (0, utils_2.hexstr)(msg), queueSize: this.queue.size() });
|
|
418
399
|
if (this.stick)
|
|
419
400
|
this.stick.write(msg);
|
|
420
401
|
}
|
|
@@ -43,7 +43,7 @@ class AntHrmAdapter extends AntAdapter_1.default {
|
|
|
43
43
|
getDisplayName() {
|
|
44
44
|
const { DeviceID, manID, ComputedHeartRate } = this.deviceData;
|
|
45
45
|
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
46
|
-
return `${utils_1.getBrand(manID)} Hrm ${DeviceID}${hrmStr}`;
|
|
46
|
+
return `${(0, utils_1.getBrand)(manID)} Hrm ${DeviceID}${hrmStr}`;
|
|
47
47
|
}
|
|
48
48
|
onDeviceData(deviceData) {
|
|
49
49
|
if (!this.started)
|
|
@@ -123,17 +123,6 @@ class AntHrmAdapter extends AntAdapter_1.default {
|
|
|
123
123
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
this.starting = false;
|
|
125
125
|
return resolve(true);
|
|
126
|
-
this.started = false;
|
|
127
|
-
if (this.ignoreHrm)
|
|
128
|
-
return resolve(false);
|
|
129
|
-
try {
|
|
130
|
-
const protocol = this.getProtocol();
|
|
131
|
-
yield protocol.detachSensor(this);
|
|
132
|
-
resolve(true);
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
reject(err);
|
|
136
|
-
}
|
|
137
126
|
}));
|
|
138
127
|
});
|
|
139
128
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import AntAdapter from '../AntAdapter';
|
|
2
|
+
export default class AntFEAdapter extends AntAdapter {
|
|
3
|
+
started: boolean;
|
|
4
|
+
starting: boolean;
|
|
5
|
+
connected: boolean;
|
|
6
|
+
distanceInternal?: number;
|
|
7
|
+
workerId?: any;
|
|
8
|
+
currentCmd?: any;
|
|
9
|
+
constructor(DeviceID: any, port: any, stick: any, protocol: any);
|
|
10
|
+
isBike(): boolean;
|
|
11
|
+
isHrm(): boolean;
|
|
12
|
+
isPower(): boolean;
|
|
13
|
+
getProfile(): string;
|
|
14
|
+
getName(): string;
|
|
15
|
+
getDisplayName(): string;
|
|
16
|
+
onAttached(): void;
|
|
17
|
+
getLogData(data: any, excludeList: any): any;
|
|
18
|
+
onDeviceData(deviceData: any): void;
|
|
19
|
+
onDeviceEvent(data: any): void;
|
|
20
|
+
updateData(data: any, deviceData: any): any;
|
|
21
|
+
transformData(bikeData: any): any;
|
|
22
|
+
start(props?: any): Promise<any>;
|
|
23
|
+
stop(): Promise<boolean>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
+
const AntAdapter_1 = __importDefault(require("../AntAdapter"));
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const floatVal = (d) => d ? parseFloat(d) : d;
|
|
19
|
+
const intVal = (d) => d ? parseInt(d) : d;
|
|
20
|
+
const hex = (v) => Math.abs(v).toString(16).toUpperCase();
|
|
21
|
+
const DEFAULT_START_TIMEOUT = 5000;
|
|
22
|
+
class AntFEAdapter extends AntAdapter_1.default {
|
|
23
|
+
constructor(DeviceID, port, stick, protocol) {
|
|
24
|
+
super(protocol);
|
|
25
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+PWR');
|
|
26
|
+
this.logger.logEvent({ message: 'Ant+PWR Adapter created', DeviceID, port });
|
|
27
|
+
this.deviceID = DeviceID;
|
|
28
|
+
this.port = port;
|
|
29
|
+
this.stick = stick;
|
|
30
|
+
this.deviceData = {
|
|
31
|
+
DeviceID
|
|
32
|
+
};
|
|
33
|
+
this.data = {};
|
|
34
|
+
this.started = false;
|
|
35
|
+
this.starting = false;
|
|
36
|
+
this.connected = false;
|
|
37
|
+
}
|
|
38
|
+
isBike() { return true; }
|
|
39
|
+
isHrm() { return false; }
|
|
40
|
+
isPower() { return true; }
|
|
41
|
+
getProfile() {
|
|
42
|
+
return 'Power Meter';
|
|
43
|
+
}
|
|
44
|
+
getName() {
|
|
45
|
+
return `Ant+PWR ${this.deviceID}`;
|
|
46
|
+
}
|
|
47
|
+
getDisplayName() {
|
|
48
|
+
const { DeviceID, ManId } = this.deviceData;
|
|
49
|
+
return `${utils_1.getBrand(ManId)} PWR ${DeviceID}`;
|
|
50
|
+
}
|
|
51
|
+
onAttached() {
|
|
52
|
+
this.logger.logEvent({ message: 'Device connected' });
|
|
53
|
+
this.connected = true;
|
|
54
|
+
}
|
|
55
|
+
getLogData(data, excludeList) {
|
|
56
|
+
const logData = JSON.parse(JSON.stringify(data));
|
|
57
|
+
excludeList.forEach((key) => {
|
|
58
|
+
delete logData[key];
|
|
59
|
+
});
|
|
60
|
+
return logData;
|
|
61
|
+
}
|
|
62
|
+
onDeviceData(deviceData) {
|
|
63
|
+
if (!this.started || this.isStopped())
|
|
64
|
+
return;
|
|
65
|
+
this.deviceData = deviceData;
|
|
66
|
+
try {
|
|
67
|
+
if (this.onDataFn && !(this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
68
|
+
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
69
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
70
|
+
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
71
|
+
this.data = this.updateData(this.data, deviceData);
|
|
72
|
+
const data = this.transformData(this.data);
|
|
73
|
+
this.onDataFn(data);
|
|
74
|
+
this.lastUpdate = Date.now();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
onDeviceEvent(data) {
|
|
82
|
+
try {
|
|
83
|
+
const cmdInfo = this.currentCmd;
|
|
84
|
+
if (!cmdInfo)
|
|
85
|
+
return;
|
|
86
|
+
const msg = cmdInfo.msg.readUInt8(2);
|
|
87
|
+
const Constants = this.getProtocol().getAnt().Constants;
|
|
88
|
+
const { expectedResponse } = cmdInfo;
|
|
89
|
+
if (data.message === msg) {
|
|
90
|
+
if (expectedResponse === undefined && data.code === Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
91
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (expectedResponse === undefined && data.code !== Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
95
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (data.message === 1) {
|
|
100
|
+
if (expectedResponse !== undefined && data.code === expectedResponse) {
|
|
101
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (expectedResponse === undefined && (data.code === Constants.EVENT_TRANSFER_TX_COMPLETED || data.code === 3)) {
|
|
105
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (data.code === Constants.EVENT_TRANSFER_TX_FAILED || data.code === Constants.EVENT_CHANNEL_COLLISION) {
|
|
109
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (this.currentCmd !== undefined && data.message === Constants.MESSAGE_CHANNEL_ACKNOWLEDGED_DATA && data.code === 31) {
|
|
114
|
+
this.logger.log("could not send (TRANSFER_IN_PROGRESS)");
|
|
115
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.logger.logEvent({ message: "Incoming Event ", event: { message: hex(data.message), code: hex(data.code) } });
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
this.logger.logEvent({ message: 'Error', fn: 'parseEvent', event: { message: hex(data.message), code: hex(data.code) }, error: err.message || err });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
updateData(data, deviceData) {
|
|
125
|
+
return;
|
|
126
|
+
if (data.distanceOffs === undefined)
|
|
127
|
+
data.distanceOffs = 0;
|
|
128
|
+
data.speed = (deviceData.VirtualSpeed !== undefined ? deviceData.VirtualSpeed : deviceData.RealSpeed) * 3.6;
|
|
129
|
+
data.slope = (deviceData.Incline !== undefined ? deviceData.Incline : data.slope);
|
|
130
|
+
data.power = (deviceData.InstantaneousPower !== undefined ? deviceData.InstantaneousPower : data.power);
|
|
131
|
+
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
132
|
+
data.heartrate = (deviceData.HeartRate !== undefined ? deviceData.HeartRate : data.heartrate);
|
|
133
|
+
if (deviceData.Distance !== undefined && deviceData.Distance !== 0) {
|
|
134
|
+
data.distanceInternal = deviceData.Distance - data.distanceOffs;
|
|
135
|
+
data.distance = data.distanceInternal / 1000;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (this.lastUpdate && deviceData.Cadence !== undefined && deviceData.Cadence > 0 && data.speed) {
|
|
139
|
+
const t = (Date.now() - this.lastUpdate) / 1000;
|
|
140
|
+
const prevDistance = data.distanceInternal || 0;
|
|
141
|
+
data.distanceInternal = Math.round(data.speed / 3.6 * t) + prevDistance;
|
|
142
|
+
data.distance = data.distanceInternal / 1000;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return data;
|
|
146
|
+
}
|
|
147
|
+
transformData(bikeData) {
|
|
148
|
+
return;
|
|
149
|
+
if (bikeData === undefined)
|
|
150
|
+
return;
|
|
151
|
+
let distance = 0;
|
|
152
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
153
|
+
distance = intVal(bikeData.distanceInternal - this.distanceInternal);
|
|
154
|
+
}
|
|
155
|
+
if (bikeData.distanceInternal !== undefined)
|
|
156
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
157
|
+
let data = {
|
|
158
|
+
speed: floatVal(bikeData.speed),
|
|
159
|
+
slope: floatVal(bikeData.slope),
|
|
160
|
+
power: intVal(bikeData.power),
|
|
161
|
+
cadence: intVal(bikeData.pedalRpm),
|
|
162
|
+
heartrate: intVal(bikeData.heartrate),
|
|
163
|
+
distance,
|
|
164
|
+
timestamp: Date.now()
|
|
165
|
+
};
|
|
166
|
+
if (this.ignorePower) {
|
|
167
|
+
delete data.power;
|
|
168
|
+
delete data.cadence;
|
|
169
|
+
}
|
|
170
|
+
if (this.ignoreBike) {
|
|
171
|
+
data = { heartrate: data.heartrate };
|
|
172
|
+
}
|
|
173
|
+
if (this.ignoreHrm)
|
|
174
|
+
delete data.heartrate;
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
start(props) {
|
|
178
|
+
const _super = Object.create(null, {
|
|
179
|
+
start: { get: () => super.start }
|
|
180
|
+
});
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
yield _super.start.call(this, props);
|
|
183
|
+
this.logger.logEvent({ message: 'start()', props });
|
|
184
|
+
const opts = props || {};
|
|
185
|
+
const { args = {} } = opts;
|
|
186
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
if (this.ignoreBike && this.ignorePower) {
|
|
188
|
+
this.logger.logEvent({ message: 'start() not done: bike disabled' });
|
|
189
|
+
return resolve(false);
|
|
190
|
+
}
|
|
191
|
+
if (this.starting) {
|
|
192
|
+
this.logger.logEvent({ message: 'start() not done: bike starting' });
|
|
193
|
+
return resolve(false);
|
|
194
|
+
}
|
|
195
|
+
if (this.started) {
|
|
196
|
+
this.logger.logEvent({ message: 'start() done: bike was already started' });
|
|
197
|
+
return resolve(true);
|
|
198
|
+
}
|
|
199
|
+
this.starting = true;
|
|
200
|
+
const Ant = this.getProtocol().getAnt();
|
|
201
|
+
const protocol = this.getProtocol();
|
|
202
|
+
let start = Date.now();
|
|
203
|
+
let timeout = start + (args.timeout || DEFAULT_START_TIMEOUT);
|
|
204
|
+
const iv = setInterval(() => {
|
|
205
|
+
if (Date.now() > timeout) {
|
|
206
|
+
clearInterval(iv);
|
|
207
|
+
this.starting = false;
|
|
208
|
+
reject(new Error('timeout'));
|
|
209
|
+
}
|
|
210
|
+
if (this.isStopped()) {
|
|
211
|
+
clearInterval(iv);
|
|
212
|
+
this.starting = false;
|
|
213
|
+
reject(new Error('stopped'));
|
|
214
|
+
}
|
|
215
|
+
}, 100);
|
|
216
|
+
protocol.attachSensors(this, Ant.BicyclePowerSensor, 'powerData')
|
|
217
|
+
.then(() => {
|
|
218
|
+
this.starting = false;
|
|
219
|
+
this.started = true;
|
|
220
|
+
clearInterval(iv);
|
|
221
|
+
resolve(true);
|
|
222
|
+
})
|
|
223
|
+
.catch(err => reject(err));
|
|
224
|
+
}));
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
stop() {
|
|
228
|
+
const _super = Object.create(null, {
|
|
229
|
+
stop: { get: () => super.stop }
|
|
230
|
+
});
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
yield _super.stop.call(this);
|
|
233
|
+
this.logger.logEvent({ message: 'stop()' });
|
|
234
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
this.starting = false;
|
|
236
|
+
return resolve(true);
|
|
237
|
+
this.started = false;
|
|
238
|
+
if (this.ignoreHrm)
|
|
239
|
+
return resolve(false);
|
|
240
|
+
try {
|
|
241
|
+
const protocol = this.getProtocol();
|
|
242
|
+
yield protocol.detachSensor(this);
|
|
243
|
+
resolve(true);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
reject(err);
|
|
247
|
+
}
|
|
248
|
+
}));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.default = AntFEAdapter;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import AntAdapter from '../AntAdapter';
|
|
2
|
+
import { IncyclistBikeData } from '../../CyclingMode';
|
|
3
|
+
import CyclingMode from '../../CyclingMode';
|
|
4
|
+
import { DeviceData } from '../../Device';
|
|
5
|
+
export declare type AntPwrData = {
|
|
6
|
+
DeviceID: number;
|
|
7
|
+
PedalPower?: number;
|
|
8
|
+
RightPedalPower?: number;
|
|
9
|
+
LeftPedalPower?: number;
|
|
10
|
+
Cadence?: number;
|
|
11
|
+
AccumulatedPower?: number;
|
|
12
|
+
Power?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
EventCount?: number;
|
|
15
|
+
TimeStamp?: number;
|
|
16
|
+
Slope?: number;
|
|
17
|
+
TorqueTicksStamp?: number;
|
|
18
|
+
CalculatedCadence?: number;
|
|
19
|
+
CalculatedTorque?: number;
|
|
20
|
+
CalculatedPower?: number;
|
|
21
|
+
};
|
|
22
|
+
export default class AntFEAdapter extends AntAdapter {
|
|
23
|
+
started: boolean;
|
|
24
|
+
starting: boolean;
|
|
25
|
+
connected: boolean;
|
|
26
|
+
distanceInternal?: number;
|
|
27
|
+
workerId?: any;
|
|
28
|
+
currentCmd?: any;
|
|
29
|
+
mode: CyclingMode;
|
|
30
|
+
constructor(DeviceID: any, port: any, stick: any, protocol: any);
|
|
31
|
+
isBike(): boolean;
|
|
32
|
+
isHrm(): boolean;
|
|
33
|
+
isPower(): boolean;
|
|
34
|
+
getProfile(): string;
|
|
35
|
+
getName(): string;
|
|
36
|
+
getDisplayName(): string;
|
|
37
|
+
getCyclingMode(): CyclingMode;
|
|
38
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
39
|
+
onAttached(): void;
|
|
40
|
+
getLogData(data: any, excludeList: any): any;
|
|
41
|
+
onDeviceData(deviceData: AntPwrData): void;
|
|
42
|
+
onDeviceEvent(data: any): void;
|
|
43
|
+
sendUpdate(request: any): void;
|
|
44
|
+
mapData(deviceData: AntPwrData): IncyclistBikeData;
|
|
45
|
+
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
46
|
+
start(props?: any): Promise<any>;
|
|
47
|
+
stop(): Promise<boolean>;
|
|
48
|
+
}
|