incyclist-devices 1.5.38 → 2.0.0
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/README.MD +238 -0
- package/lib/adapters.d.ts +7 -0
- package/lib/adapters.js +49 -0
- package/lib/antv2/adapter-factory.d.ts +21 -10
- package/lib/antv2/adapter-factory.js +51 -33
- package/lib/antv2/adapter.d.ts +65 -0
- package/lib/antv2/adapter.js +310 -0
- package/lib/antv2/ant-interface.d.ts +17 -11
- package/lib/antv2/ant-interface.js +41 -31
- package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +1 -1
- package/lib/antv2/{ant-binding.js → binding.js} +1 -1
- package/lib/antv2/fe/adapter.d.ts +28 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +106 -90
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +15 -0
- package/lib/antv2/hr/adapter.js +76 -0
- package/lib/antv2/hr/index.d.ts +2 -0
- package/lib/antv2/hr/index.js +7 -0
- package/lib/antv2/index.d.ts +7 -0
- package/lib/antv2/index.js +20 -0
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
- package/lib/antv2/pwr/adapter.d.ts +24 -0
- package/lib/antv2/pwr/adapter.js +141 -0
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +22 -0
- package/lib/antv2/types.js +5 -0
- package/lib/antv2/utils.d.ts +4 -0
- package/lib/antv2/utils.js +192 -0
- package/lib/base/adpater.d.ts +68 -0
- package/lib/base/adpater.js +183 -0
- package/lib/ble/adapter-factory.d.ts +33 -0
- package/lib/ble/adapter-factory.js +105 -0
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/base/adapter.js +290 -0
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-device.d.ts → base/comms.d.ts} +31 -16
- package/lib/ble/{ble-device.js → base/comms.js} +193 -55
- package/lib/ble/bindings/index.d.ts +2 -0
- package/lib/ble/bindings/index.js +8 -0
- package/lib/ble/bindings/linux.d.ts +15 -0
- package/lib/ble/bindings/linux.js +39 -0
- package/lib/ble/bindings/mock.d.ts +9 -0
- package/lib/ble/bindings/mock.js +108 -0
- package/lib/ble/bindings/types.d.ts +57 -0
- package/lib/ble/bindings/types.js +96 -0
- package/lib/ble/ble-interface.d.ts +38 -59
- package/lib/ble/ble-interface.js +254 -462
- package/lib/ble/ble-peripheral.d.ts +7 -5
- package/lib/ble/ble-peripheral.js +52 -21
- package/lib/ble/consts.d.ts +3 -0
- package/lib/ble/consts.js +4 -1
- package/lib/ble/cp/adapter.d.ts +22 -0
- package/lib/ble/cp/adapter.js +111 -0
- package/lib/ble/cp/comm.d.ts +31 -0
- package/lib/ble/cp/comm.js +125 -0
- package/lib/ble/cp/index.d.ts +4 -0
- package/lib/ble/cp/index.js +10 -0
- package/lib/ble/cp/types.d.ts +13 -0
- package/lib/ble/cp/types.js +2 -0
- package/lib/ble/elite/adapter.d.ts +19 -0
- package/lib/ble/elite/adapter.js +120 -0
- package/lib/ble/elite/comms.d.ts +32 -0
- package/lib/ble/elite/comms.js +126 -0
- package/lib/ble/elite/index.d.ts +3 -0
- package/lib/ble/elite/index.js +10 -0
- package/lib/ble/fm/adapter.d.ts +22 -0
- package/lib/ble/fm/adapter.js +249 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +34 -277
- package/lib/ble/fm/consts.d.ts +6 -0
- package/lib/ble/fm/consts.js +9 -0
- package/lib/ble/fm/index.d.ts +5 -0
- package/lib/ble/fm/index.js +13 -0
- package/lib/ble/fm/types.d.ts +30 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +14 -0
- package/lib/ble/hr/adapter.js +45 -0
- package/lib/ble/hr/comm.d.ts +19 -0
- package/lib/ble/hr/comm.js +56 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +9 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +99 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +11 -43
- package/lib/ble/{tacx.js → tacx/comms.js} +23 -155
- package/lib/ble/tacx/index.d.ts +4 -0
- package/lib/ble/tacx/index.js +10 -0
- package/lib/ble/tacx/types.d.ts +25 -0
- package/lib/ble/tacx/types.js +2 -0
- package/lib/ble/types.d.ts +128 -0
- package/lib/ble/types.js +2 -0
- package/lib/ble/utils.d.ts +17 -0
- package/lib/ble/utils.js +54 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +95 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +11 -44
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +29 -129
- package/lib/ble/wahoo/index.d.ts +4 -0
- package/lib/ble/wahoo/index.js +10 -0
- package/lib/ble/wahoo/types.d.ts +19 -0
- package/lib/ble/wahoo/types.js +2 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +34 -0
- package/lib/interfaces.d.ts +7 -0
- package/lib/interfaces.js +27 -0
- package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
- package/lib/{ble → modes}/ble-erg-mode.js +2 -2
- package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
- package/lib/{ble → modes}/ble-st-mode.js +1 -1
- package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +8 -4
- package/lib/modes/power-meter.d.ts +3 -3
- package/lib/modes/simulator.d.ts +2 -2
- package/lib/modes/simulator.js +1 -1
- package/lib/serial/adapter-factory.d.ts +12 -0
- package/lib/serial/adapter-factory.js +30 -0
- package/lib/serial/adapter.d.ts +21 -0
- package/lib/serial/adapter.js +61 -0
- package/lib/serial/bindings/tcp.d.ts +45 -0
- package/lib/serial/bindings/tcp.js +284 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +14 -23
- package/lib/{daum → serial/daum}/DaumAdapter.js +57 -97
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
- package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
- package/lib/serial/daum/classic/adapter.d.ts +29 -0
- package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
- package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
- package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
- package/lib/serial/daum/classic/mock.d.ts +96 -0
- package/lib/serial/daum/classic/mock.js +365 -0
- package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
- package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
- package/lib/serial/daum/premium/adapter.d.ts +25 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +107 -47
- package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
- package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +215 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +289 -0
- package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
- package/lib/serial/daum/premium/types.d.ts +12 -0
- package/lib/serial/daum/premium/types.js +2 -0
- package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
- package/lib/{daum → serial/daum}/premium/utils.js +22 -63
- package/lib/serial/index.d.ts +9 -0
- package/lib/serial/index.js +49 -0
- package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
- package/lib/{kettler → serial/kettler}/comms.js +71 -32
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +14 -28
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +102 -169
- package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
- package/lib/serial/kettler/ergo-racer/mock.js +216 -0
- package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
- package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
- package/lib/serial/serial-interface.d.ts +60 -0
- package/lib/serial/serial-interface.js +309 -0
- package/lib/simulator/Simulator.d.ts +12 -25
- package/lib/simulator/Simulator.js +26 -87
- package/lib/types/adapter.d.ts +39 -0
- package/lib/types/adapter.js +2 -0
- package/lib/types/capabilities.d.ts +8 -0
- package/lib/types/capabilities.js +12 -0
- package/lib/types/data.d.ts +12 -0
- package/lib/types/data.js +2 -0
- package/lib/types/device.d.ts +32 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +18 -0
- package/lib/types/interface.js +2 -0
- package/lib/types/route.d.ts +2 -2
- package/lib/types/user.d.ts +1 -1
- package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
- package/lib/{utils.js → utils/utils.js} +5 -1
- package/package.json +16 -14
- package/lib/DeviceSupport.d.ts +0 -36
- package/lib/DeviceSupport.js +0 -82
- package/lib/ant/AntAdapter.d.ts +0 -50
- package/lib/ant/AntAdapter.js +0 -109
- package/lib/ant/AntScanner.d.ts +0 -60
- package/lib/ant/AntScanner.js +0 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
- package/lib/ant/antfe/AntFEAdapter.js +0 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
- package/lib/ant/antpwr/pwr-adapter.js +0 -251
- package/lib/ant/utils.d.ts +0 -1
- package/lib/ant/utils.js +0 -23
- package/lib/antv2/AntAdapter.d.ts +0 -48
- package/lib/antv2/AntAdapter.js +0 -104
- package/lib/antv2/ant-device.d.ts +0 -59
- package/lib/antv2/ant-device.js +0 -161
- package/lib/antv2/fe.d.ts +0 -32
- package/lib/antv2/hr.d.ts +0 -18
- package/lib/antv2/hr.js +0 -102
- package/lib/antv2/incyclist-protocol.d.ts +0 -37
- package/lib/antv2/incyclist-protocol.js +0 -126
- package/lib/antv2/pwr.d.ts +0 -28
- package/lib/antv2/pwr.js +0 -171
- package/lib/ble/ble.d.ts +0 -129
- package/lib/ble/ble.js +0 -86
- package/lib/ble/elite.d.ts +0 -90
- package/lib/ble/elite.js +0 -322
- package/lib/ble/fm.d.ts +0 -125
- package/lib/ble/hrm.d.ts +0 -48
- package/lib/ble/hrm.js +0 -134
- package/lib/ble/incyclist-protocol.d.ts +0 -31
- package/lib/ble/incyclist-protocol.js +0 -153
- package/lib/ble/pwr.d.ts +0 -89
- package/lib/ble/pwr.js +0 -322
- package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
- package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
- package/lib/daum/classic/DaumClassicProtocol.js +0 -185
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
- package/lib/daum/premium/tcpserial.d.ts +0 -33
- package/lib/daum/premium/tcpserial.js +0 -123
- package/lib/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
- package/lib/kettler/ergo-racer/protocol.js +0 -203
- package/lib/protocol.d.ts +0 -74
- package/lib/protocol.js +0 -41
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -33
- package/lib/serialport/bindings/tcp.d.ts +0 -20
- package/lib/serialport/bindings/tcp.js +0 -33
- package/lib/serialport/index.d.ts +0 -2
- package/lib/serialport/index.js +0 -29
- package/lib/serialport/serialport.d.ts +0 -29
- package/lib/serialport/serialport.js +0 -87
- /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
- /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
- /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
- /package/lib/{daum → serial/daum}/constants.js +0 -0
- /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
- /package/lib/{serialport.js → serial/serialport.js} +0 -0
- /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
- /package/lib/{calculations.js → utils/calculations.js} +0 -0
|
@@ -1,23 +1,4 @@
|
|
|
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
|
-
};
|
|
21
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,27 +12,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
13
|
};
|
|
33
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
const device_1 = __importStar(require("../../device"));
|
|
35
15
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
36
16
|
const comms_1 = __importDefault(require("../comms"));
|
|
37
|
-
const utils_1 = require("
|
|
38
|
-
const power_meter_1 = __importDefault(require("
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
17
|
+
const utils_1 = require("../../../utils/utils");
|
|
18
|
+
const power_meter_1 = __importDefault(require("../../../modes/power-meter"));
|
|
19
|
+
const erg_1 = __importDefault(require("./modes/erg"));
|
|
20
|
+
const adapter_1 = require("../../adapter");
|
|
21
|
+
const capabilities_1 = require("../../../types/capabilities");
|
|
22
|
+
const PROTOCOL_NAME = 'Kettler Racer';
|
|
23
|
+
class KettlerRacerAdapter extends adapter_1.SerialIncyclistDevice {
|
|
24
|
+
constructor(settings, props) {
|
|
25
|
+
super(settings, props);
|
|
43
26
|
this.requests = [];
|
|
44
27
|
this.logger = new gd_eventlog_1.EventLogger('KettlerRacer');
|
|
45
|
-
this.ignoreHrm = false;
|
|
46
|
-
this.ignorePower = false;
|
|
47
|
-
this.ignoreBike = false;
|
|
48
28
|
this.paused = false;
|
|
49
29
|
this.iv = null;
|
|
50
|
-
this.comms = new comms_1.default({
|
|
30
|
+
this.comms = new comms_1.default({ interface: settings.interface, port: settings.port, logger: this.logger });
|
|
31
|
+
this.capabilities = [
|
|
32
|
+
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Gear, capabilities_1.IncyclistCapability.HeartRate,
|
|
33
|
+
capabilities_1.IncyclistCapability.Control
|
|
34
|
+
];
|
|
51
35
|
}
|
|
52
36
|
isBike() { return true; }
|
|
53
37
|
isPower() { return true; }
|
|
54
38
|
isHrm() { return true; }
|
|
39
|
+
getProtocolName() {
|
|
40
|
+
return PROTOCOL_NAME;
|
|
41
|
+
}
|
|
55
42
|
isSame(device) {
|
|
56
43
|
if (!(device instanceof KettlerRacerAdapter))
|
|
57
44
|
return false;
|
|
@@ -68,16 +55,8 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
68
55
|
return this.settings.name || this.getProtocolName();
|
|
69
56
|
}
|
|
70
57
|
getPort() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
setIgnoreHrm(ignore) {
|
|
74
|
-
this.ignoreHrm = ignore;
|
|
75
|
-
}
|
|
76
|
-
setIgnorePower(ignore) {
|
|
77
|
-
this.ignorePower = ignore;
|
|
78
|
-
}
|
|
79
|
-
setIgnoreBike(ignore) {
|
|
80
|
-
this.ignoreBike = ignore;
|
|
58
|
+
const settings = this.settings;
|
|
59
|
+
return settings.port;
|
|
81
60
|
}
|
|
82
61
|
_getComms() {
|
|
83
62
|
return this.comms;
|
|
@@ -88,23 +67,9 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
88
67
|
getLogger() {
|
|
89
68
|
return this.logger;
|
|
90
69
|
}
|
|
91
|
-
getUserSettings() {
|
|
92
|
-
return this.settings.userSettings || { weight: device_1.DEFAULT_USER_WEIGHT };
|
|
93
|
-
}
|
|
94
|
-
getWeight() {
|
|
95
|
-
let userWeight = device_1.DEFAULT_USER_WEIGHT;
|
|
96
|
-
let bikeWeight = device_1.DEFAULT_BIKE_WEIGHT;
|
|
97
|
-
if (this.settings.userSettings && this.settings.userSettings.weight) {
|
|
98
|
-
userWeight = this.settings.userSettings.weight;
|
|
99
|
-
}
|
|
100
|
-
if (this.settings.bikeSettings && this.settings.bikeSettings.weight) {
|
|
101
|
-
userWeight = this.settings.bikeSettings.weight;
|
|
102
|
-
}
|
|
103
|
-
return bikeWeight + userWeight;
|
|
104
|
-
}
|
|
105
70
|
setComputerMode() {
|
|
106
71
|
return this.send('setComputerMode', 'CP').then(response => {
|
|
107
|
-
this.
|
|
72
|
+
this.logEvent({ response });
|
|
108
73
|
if (response === 'ACK' || response === 'RUN') {
|
|
109
74
|
return true;
|
|
110
75
|
}
|
|
@@ -115,7 +80,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
115
80
|
}
|
|
116
81
|
setClientMode() {
|
|
117
82
|
return this.send('setClientMode', 'CM').then(response => {
|
|
118
|
-
this.
|
|
83
|
+
this.logEvent({ response });
|
|
119
84
|
if (response === 'ACK' || response === 'RUN') {
|
|
120
85
|
return true;
|
|
121
86
|
}
|
|
@@ -126,7 +91,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
126
91
|
}
|
|
127
92
|
reset() {
|
|
128
93
|
return this.send('reset', 'RS').then(response => {
|
|
129
|
-
this.
|
|
94
|
+
this.logEvent({ response });
|
|
130
95
|
if (response === 'ACK' || response === 'RUN') {
|
|
131
96
|
return true;
|
|
132
97
|
}
|
|
@@ -137,21 +102,21 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
137
102
|
}
|
|
138
103
|
getIdentifier() {
|
|
139
104
|
return this.send('getIdentifier', 'ID').then(response => {
|
|
140
|
-
this.
|
|
105
|
+
this.logEvent({ response });
|
|
141
106
|
return response.substring(0, 3);
|
|
142
107
|
});
|
|
143
108
|
}
|
|
144
|
-
|
|
109
|
+
getKettlerInterface() {
|
|
145
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
111
|
const res = yield this.send('getInterface', 'KI');
|
|
147
|
-
this.
|
|
112
|
+
this.logEvent({ interface: res });
|
|
148
113
|
return res;
|
|
149
114
|
});
|
|
150
115
|
}
|
|
151
116
|
getVersion() {
|
|
152
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
118
|
const res = yield this.send('getVersion', 'VE');
|
|
154
|
-
this.
|
|
119
|
+
this.logEvent({ version: res });
|
|
155
120
|
return res;
|
|
156
121
|
});
|
|
157
122
|
}
|
|
@@ -267,14 +232,14 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
267
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
233
|
var info = {};
|
|
269
234
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
270
|
-
this.
|
|
235
|
+
this.logEvent({ message: "checking device", port: this.getPort() });
|
|
271
236
|
let iv = undefined;
|
|
272
237
|
try {
|
|
273
238
|
if (!info.opened)
|
|
274
239
|
info.opened = yield this.waitForOpened();
|
|
275
240
|
iv = setTimeout(() => {
|
|
276
|
-
this.
|
|
277
|
-
|
|
241
|
+
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: 'timeout' });
|
|
242
|
+
resolve(false);
|
|
278
243
|
}, 5000);
|
|
279
244
|
if (!info.pcMode)
|
|
280
245
|
info.pcMode = yield this.setClientMode();
|
|
@@ -283,27 +248,28 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
283
248
|
if (!info.version)
|
|
284
249
|
info.version = yield this.getVersion();
|
|
285
250
|
try {
|
|
286
|
-
yield this.
|
|
251
|
+
yield this.getKettlerInterface();
|
|
287
252
|
}
|
|
288
253
|
catch (e) {
|
|
289
|
-
this.
|
|
254
|
+
this.logEvent({ message: 'could not get kettler interface', error: e.message });
|
|
290
255
|
}
|
|
291
256
|
clearTimeout(iv);
|
|
292
|
-
|
|
257
|
+
this.logEvent({ message: "checking device success", port: this.getPort(), info });
|
|
258
|
+
resolve(true);
|
|
293
259
|
}
|
|
294
260
|
catch (err) {
|
|
295
|
-
this.
|
|
261
|
+
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: err.message || err });
|
|
296
262
|
if (iv)
|
|
297
263
|
clearTimeout(iv);
|
|
298
264
|
iv = undefined;
|
|
299
|
-
|
|
265
|
+
resolve(false);
|
|
300
266
|
}
|
|
301
267
|
}));
|
|
302
268
|
});
|
|
303
269
|
}
|
|
304
270
|
start(props) {
|
|
305
271
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
this.
|
|
272
|
+
this.logEvent({ message: 'start()' });
|
|
307
273
|
var info = {};
|
|
308
274
|
yield this.waitForOpened(true);
|
|
309
275
|
return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -317,13 +283,13 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
317
283
|
}
|
|
318
284
|
}
|
|
319
285
|
catch (e) {
|
|
320
|
-
this.
|
|
286
|
+
this.logEvent({ message: 'Error', error: e.message });
|
|
321
287
|
}
|
|
322
288
|
try {
|
|
323
289
|
yield this.setPower(100);
|
|
324
290
|
}
|
|
325
291
|
catch (e) {
|
|
326
|
-
this.
|
|
292
|
+
this.logEvent({ message: 'Error', error: e.message });
|
|
327
293
|
}
|
|
328
294
|
if (!info.data) {
|
|
329
295
|
yield this.update();
|
|
@@ -336,37 +302,38 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
336
302
|
yield this.reset();
|
|
337
303
|
}
|
|
338
304
|
catch (e) {
|
|
339
|
-
this.
|
|
305
|
+
this.logEvent({ message: 'Error', error: e.message });
|
|
340
306
|
}
|
|
341
307
|
throw (new Error(`could not start device, reason:${err.message}`));
|
|
342
308
|
}
|
|
343
309
|
}), 5, 1000)
|
|
344
310
|
.then((data) => {
|
|
345
311
|
this.startUpdatePull();
|
|
346
|
-
return
|
|
312
|
+
return true;
|
|
347
313
|
});
|
|
348
314
|
});
|
|
349
315
|
}
|
|
350
316
|
startUpdatePull() {
|
|
351
317
|
if (this.iv)
|
|
352
318
|
return;
|
|
353
|
-
this.
|
|
354
|
-
if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
|
|
355
|
-
return;
|
|
319
|
+
this.logEvent({ message: 'start regular device update' });
|
|
356
320
|
const ivSync = setInterval(() => {
|
|
357
321
|
this.bikeSync();
|
|
358
|
-
},
|
|
322
|
+
}, this.pullFrequency);
|
|
359
323
|
const ivUpdate = setInterval(() => {
|
|
360
|
-
this.
|
|
324
|
+
this.emitData(this.data);
|
|
361
325
|
this.refreshRequests();
|
|
362
|
-
},
|
|
326
|
+
}, this.pullFrequency);
|
|
363
327
|
this.iv = {
|
|
364
328
|
sync: ivSync,
|
|
365
329
|
update: ivUpdate
|
|
366
330
|
};
|
|
367
331
|
}
|
|
332
|
+
canSendUpdate() {
|
|
333
|
+
return !this.isPaused();
|
|
334
|
+
}
|
|
368
335
|
stop() {
|
|
369
|
-
this.
|
|
336
|
+
this.logEvent({ message: 'stop request' });
|
|
370
337
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
371
338
|
try {
|
|
372
339
|
if (this.iv) {
|
|
@@ -377,31 +344,17 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
377
344
|
this.iv = undefined;
|
|
378
345
|
}
|
|
379
346
|
yield this.waitForClosed();
|
|
380
|
-
this.
|
|
347
|
+
this.logEvent({ message: 'stop request completed' });
|
|
381
348
|
this.paused = undefined;
|
|
382
349
|
resolve(true);
|
|
383
350
|
}
|
|
384
351
|
catch (err) {
|
|
385
|
-
this.
|
|
352
|
+
this.logEvent({ message: 'stop error', error: err.message });
|
|
386
353
|
this.paused = undefined;
|
|
387
354
|
reject(err);
|
|
388
355
|
}
|
|
389
356
|
}));
|
|
390
357
|
}
|
|
391
|
-
pause() {
|
|
392
|
-
this.logger.logEvent({ message: 'pause' });
|
|
393
|
-
return new Promise(resolve => {
|
|
394
|
-
this.paused = true;
|
|
395
|
-
resolve(true);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
resume() {
|
|
399
|
-
this.logger.logEvent({ message: 'resume' });
|
|
400
|
-
return new Promise(resolve => {
|
|
401
|
-
this.paused = false;
|
|
402
|
-
resolve(true);
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
358
|
mapData(bikeData) {
|
|
406
359
|
let data = {};
|
|
407
360
|
data.isPedalling = bikeData.cadence > 0;
|
|
@@ -422,21 +375,13 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
422
375
|
data.heartrate = internalData.heartrate;
|
|
423
376
|
data.timestamp = Date.now();
|
|
424
377
|
data.deviceTime = bikeData.time;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
this.prevDistance = internalData.distanceInternal;
|
|
433
|
-
}
|
|
434
|
-
if (this.ignoreHrm)
|
|
435
|
-
delete this.data.heartrate;
|
|
436
|
-
if (this.ignorePower) {
|
|
437
|
-
delete this.data.power;
|
|
438
|
-
delete this.data.cadence;
|
|
439
|
-
}
|
|
378
|
+
data.speed = internalData.speed;
|
|
379
|
+
data.power = internalData.power;
|
|
380
|
+
data.cadence = internalData.pedalRpm;
|
|
381
|
+
data.distance = distance;
|
|
382
|
+
data.deviceDistanceCounter = bikeData.distance;
|
|
383
|
+
data.internalDistanceCounter = internalData.distanceInternal;
|
|
384
|
+
this.prevDistance = internalData.distanceInternal;
|
|
440
385
|
return data;
|
|
441
386
|
}
|
|
442
387
|
update() {
|
|
@@ -451,15 +396,16 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
451
396
|
data = this.getCyclingMode().updateData(data);
|
|
452
397
|
this.internalData = data;
|
|
453
398
|
this.data = this.transformData(data, bikeData);
|
|
399
|
+
this.emitData(this.data);
|
|
454
400
|
}
|
|
455
401
|
catch (err) {
|
|
456
|
-
this.
|
|
402
|
+
this.logEvent({ message: 'bike update error', error: err.message });
|
|
457
403
|
}
|
|
458
404
|
}
|
|
459
405
|
this.updateBusy = false;
|
|
460
406
|
})
|
|
461
407
|
.catch(err => {
|
|
462
|
-
this.
|
|
408
|
+
this.logEvent({ message: 'bike update error', error: err.message });
|
|
463
409
|
this.updateBusy = false;
|
|
464
410
|
});
|
|
465
411
|
});
|
|
@@ -468,7 +414,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
468
414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
469
415
|
this.requestBusy = true;
|
|
470
416
|
try {
|
|
471
|
-
this.
|
|
417
|
+
this.logEvent({ message: 'sendRequest', request });
|
|
472
418
|
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
473
419
|
if (isReset) {
|
|
474
420
|
this.requestBusy = false;
|
|
@@ -485,7 +431,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
485
431
|
}
|
|
486
432
|
catch (err) {
|
|
487
433
|
this.requestBusy = false;
|
|
488
|
-
this.
|
|
434
|
+
this.logEvent({ message: 'error', fn: 'sendRequest()', error: err.message || err });
|
|
489
435
|
return;
|
|
490
436
|
}
|
|
491
437
|
});
|
|
@@ -497,7 +443,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
497
443
|
const cnt = processing.length;
|
|
498
444
|
processing.forEach((request, idx) => __awaiter(this, void 0, void 0, function* () {
|
|
499
445
|
if (cnt > 1 && idx < cnt - 1) {
|
|
500
|
-
this.
|
|
446
|
+
this.logEvent({ message: 'ignoring bike update request', request });
|
|
501
447
|
this.requests.shift();
|
|
502
448
|
return;
|
|
503
449
|
}
|
|
@@ -508,7 +454,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
508
454
|
this.requests.shift();
|
|
509
455
|
}
|
|
510
456
|
catch (err) {
|
|
511
|
-
this.
|
|
457
|
+
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack, request });
|
|
512
458
|
}
|
|
513
459
|
}
|
|
514
460
|
});
|
|
@@ -521,10 +467,8 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
521
467
|
if (this.updateBusy || this.requestBusy) {
|
|
522
468
|
return;
|
|
523
469
|
}
|
|
524
|
-
this.
|
|
525
|
-
|
|
526
|
-
yield this.sendRequests();
|
|
527
|
-
}
|
|
470
|
+
this.logEvent({ message: 'bikeSync' });
|
|
471
|
+
yield this.sendRequests();
|
|
528
472
|
yield this.update();
|
|
529
473
|
});
|
|
530
474
|
}
|
|
@@ -532,21 +476,17 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
532
476
|
return __awaiter(this, void 0, void 0, function* () {
|
|
533
477
|
if (this.paused)
|
|
534
478
|
return;
|
|
535
|
-
this.
|
|
479
|
+
this.logEvent({ message: 'sendUpdate', request, waiting: this.requests.length });
|
|
536
480
|
return yield this.processClientRequest(request);
|
|
537
481
|
});
|
|
538
482
|
}
|
|
539
|
-
sendData() {
|
|
540
|
-
if (this.onDataFn)
|
|
541
|
-
this.onDataFn(this.data);
|
|
542
|
-
}
|
|
543
483
|
refreshRequests() {
|
|
544
484
|
if (this.kettlerData.cadence === 0)
|
|
545
485
|
return;
|
|
546
486
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true }) || {};
|
|
547
487
|
const prev = this.requests[this.requests.length - 1] || {};
|
|
548
488
|
if (bikeRequest.targetPower !== undefined && bikeRequest.targetPower !== prev.targetPower) {
|
|
549
|
-
this.
|
|
489
|
+
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
550
490
|
this.requests.push(bikeRequest);
|
|
551
491
|
}
|
|
552
492
|
}
|
|
@@ -556,44 +496,43 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
556
496
|
}
|
|
557
497
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
558
498
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate(request);
|
|
559
|
-
this.
|
|
499
|
+
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
560
500
|
this.requests.push(bikeRequest);
|
|
561
501
|
resolve(bikeRequest);
|
|
562
502
|
}));
|
|
563
503
|
}
|
|
504
|
+
connect() {
|
|
505
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
506
|
+
return yield this.waitForOpened(true);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
close() {
|
|
510
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
511
|
+
return yield this.waitForClosed();
|
|
512
|
+
});
|
|
513
|
+
}
|
|
564
514
|
waitForOpened(retries = false) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
resolve(true);
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
const cleanup = () => {
|
|
572
|
-
this.comms.removeAllListeners();
|
|
573
|
-
};
|
|
574
|
-
const onOpen = () => {
|
|
575
|
-
resolve(true);
|
|
576
|
-
cleanup();
|
|
577
|
-
};
|
|
578
|
-
const onError = (err) => { reject(err); cleanup(); };
|
|
579
|
-
const onClose = () => { cleanup(); };
|
|
580
|
-
this.comms.on('opened', onOpen);
|
|
581
|
-
this.comms.on('closed', onClose);
|
|
582
|
-
this.comms.on('error', onError);
|
|
583
|
-
this.logger.logEvent({ message: 'opening', port: this.getPort() });
|
|
584
|
-
this.comms.open();
|
|
515
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
516
|
+
if (!retries) {
|
|
517
|
+
return yield this.comms.open();
|
|
585
518
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
519
|
+
else {
|
|
520
|
+
let opened;
|
|
521
|
+
let tries = 0;
|
|
522
|
+
while (!opened && tries < 3) {
|
|
523
|
+
try {
|
|
524
|
+
opened = yield this.comms.open();
|
|
525
|
+
if (opened)
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
catch (err) {
|
|
529
|
+
}
|
|
530
|
+
tries++;
|
|
531
|
+
yield (0, utils_1.sleep)(500);
|
|
532
|
+
}
|
|
533
|
+
return false;
|
|
589
534
|
}
|
|
590
|
-
};
|
|
591
|
-
if (!retries) {
|
|
592
|
-
return new Promise((resolve, reject) => run(resolve, reject));
|
|
593
|
-
}
|
|
594
|
-
return (0, utils_1.runWithRetries)(() => {
|
|
595
|
-
return new Promise((resolve, reject) => run(resolve, reject));
|
|
596
|
-
}, 3, 1000);
|
|
535
|
+
});
|
|
597
536
|
}
|
|
598
537
|
waitForClosed() {
|
|
599
538
|
return new Promise((resolve, reject) => {
|
|
@@ -614,26 +553,20 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
614
553
|
this.comms.on('closed', onClose);
|
|
615
554
|
this.comms.on('opened', onOpen);
|
|
616
555
|
this.comms.on('error', onError);
|
|
617
|
-
this.
|
|
556
|
+
this.logEvent({ message: 'closing', port: this.getPort() });
|
|
618
557
|
this.comms.close();
|
|
619
558
|
}
|
|
620
559
|
catch (err) {
|
|
621
|
-
this.
|
|
560
|
+
this.logEvent({ message: 'error', fn: 'waitForClosed()', error: err.message || err });
|
|
622
561
|
reject(err);
|
|
623
562
|
}
|
|
624
563
|
});
|
|
625
564
|
}
|
|
626
565
|
getSupportedCyclingModes() {
|
|
627
|
-
return [power_meter_1.default,
|
|
566
|
+
return [power_meter_1.default, erg_1.default];
|
|
628
567
|
}
|
|
629
568
|
getDefaultCyclingMode() {
|
|
630
|
-
return new
|
|
631
|
-
}
|
|
632
|
-
setUserSettings(userSettings) {
|
|
633
|
-
this.settings.userSettings = userSettings;
|
|
634
|
-
}
|
|
635
|
-
setBikeSettings(bikeSettings) {
|
|
636
|
-
this.settings.bikeSettings = bikeSettings;
|
|
569
|
+
return new erg_1.default(this);
|
|
637
570
|
}
|
|
638
571
|
}
|
|
639
572
|
exports.default = KettlerRacerAdapter;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { MockBindingInterface, MockPortBinding, CreatePortOptions } from '@serialport/binding-mock';
|
|
3
|
+
import { BindingInterface, PortInfo } from '@serialport/bindings-interface';
|
|
4
|
+
import { User } from '../../../types/user';
|
|
5
|
+
export type MockProps = {
|
|
6
|
+
interface: string;
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
export interface KettlerRacerMockBindingInterface extends BindingInterface<KettlerRacerMockBinding> {
|
|
10
|
+
reset(): void;
|
|
11
|
+
createPort(path: string, opt?: CreatePortOptions): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const KettlerRacerMock: MockBindingInterface;
|
|
14
|
+
export declare class KettlerRacerMockImpl {
|
|
15
|
+
static _instance: KettlerRacerMockImpl;
|
|
16
|
+
static getInstance(): KettlerRacerMockImpl;
|
|
17
|
+
static reset(): void;
|
|
18
|
+
simulators: Map<string, KettlerRacerSimulator>;
|
|
19
|
+
ports: {
|
|
20
|
+
path: string;
|
|
21
|
+
binding: KettlerRacerMockBinding;
|
|
22
|
+
}[];
|
|
23
|
+
constructor();
|
|
24
|
+
setSimulator(path: string, simulator: KettlerRacerSimulator): void;
|
|
25
|
+
getSimulator(path: any): KettlerRacerSimulator;
|
|
26
|
+
reset(): void;
|
|
27
|
+
createPort(path: string, options?: CreatePortOptions): void;
|
|
28
|
+
list(): Promise<PortInfo[]>;
|
|
29
|
+
open(options: any): Promise<KettlerRacerMockBinding>;
|
|
30
|
+
}
|
|
31
|
+
export declare class KettlerRacerSimulator {
|
|
32
|
+
identifier: string;
|
|
33
|
+
version: string;
|
|
34
|
+
bikeType: string;
|
|
35
|
+
ifVersion: string;
|
|
36
|
+
power: number;
|
|
37
|
+
requestedPower: number;
|
|
38
|
+
person: User;
|
|
39
|
+
cadence: number;
|
|
40
|
+
distance: number;
|
|
41
|
+
speed: number;
|
|
42
|
+
heartrate: number;
|
|
43
|
+
time: number;
|
|
44
|
+
energy: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class KettlerRacerMockBinding extends MockPortBinding {
|
|
47
|
+
waitingForCommand: boolean;
|
|
48
|
+
waitingForAck: boolean;
|
|
49
|
+
prevCommand: Buffer;
|
|
50
|
+
simulator: KettlerRacerSimulator;
|
|
51
|
+
handlers: Map<string, (payload: string) => void>;
|
|
52
|
+
constructor(parent: MockPortBinding);
|
|
53
|
+
getPath(): string;
|
|
54
|
+
initHandlers(): void;
|
|
55
|
+
write(buffer: Buffer): Promise<void>;
|
|
56
|
+
processData(buffer: Buffer): Promise<void>;
|
|
57
|
+
onSetComputerMode(_payload: string): void;
|
|
58
|
+
onSetClientMode(_payload: string): void;
|
|
59
|
+
onReset(_payload: string): void;
|
|
60
|
+
onGetIdentifier(_payload: string): void;
|
|
61
|
+
onGetVersion(_payload: string): void;
|
|
62
|
+
onGetKettlerInfo(_payload: string): void;
|
|
63
|
+
onSetPower(payload: string): void;
|
|
64
|
+
onGetStatus(): void;
|
|
65
|
+
sendResponse(msg: string): void;
|
|
66
|
+
}
|