incyclist-devices 1.5.37 → 2.0.0-beta.1
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 +0 -0
- package/lib/adapters.d.ts +6 -0
- package/lib/adapters.js +30 -0
- package/lib/antv2/adapter-factory.d.ts +20 -10
- package/lib/antv2/adapter-factory.js +49 -33
- package/lib/antv2/adapter.d.ts +64 -0
- package/lib/antv2/adapter.js +299 -0
- package/lib/antv2/ant-interface.d.ts +11 -9
- package/lib/antv2/ant-interface.js +15 -11
- package/lib/antv2/fe/adapter.d.ts +25 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +14 -0
- package/lib/antv2/hr/adapter.js +73 -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 +22 -0
- package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/types.d.ts +19 -0
- package/lib/antv2/types.js +2 -0
- package/lib/antv2/utils.d.ts +1 -0
- package/lib/antv2/utils.js +181 -0
- package/lib/base/adpater.d.ts +56 -0
- package/lib/base/adpater.js +144 -0
- package/lib/ble/adapter-factory.d.ts +31 -0
- package/lib/ble/adapter-factory.js +96 -0
- package/lib/ble/adapter.d.ts +41 -0
- package/lib/ble/adapter.js +188 -0
- package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
- package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
- package/lib/ble/ble-interface.d.ts +15 -24
- package/lib/ble/ble-interface.js +32 -137
- package/lib/ble/ble-peripheral.d.ts +3 -3
- package/lib/ble/ble-peripheral.js +14 -14
- package/lib/ble/ble.d.ts +9 -81
- package/lib/ble/ble.js +1 -39
- package/lib/ble/consts.d.ts +2 -0
- package/lib/ble/consts.js +3 -1
- package/lib/ble/cp/adapter.d.ts +23 -0
- package/lib/ble/cp/adapter.js +124 -0
- package/lib/ble/cp/comm.d.ts +28 -0
- package/lib/ble/cp/comm.js +140 -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 +20 -0
- package/lib/ble/elite/adapter.js +127 -0
- package/lib/ble/elite/comms.d.ts +28 -0
- package/lib/ble/elite/comms.js +139 -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 +21 -0
- package/lib/ble/fm/adapter.js +190 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +3 -224
- 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 +25 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +17 -0
- package/lib/ble/hr/adapter.js +62 -0
- package/lib/ble/hr/comm.d.ts +15 -0
- package/lib/ble/hr/comm.js +52 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +8 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +93 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
- package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
- 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 +101 -0
- package/lib/ble/types.js +19 -0
- package/lib/ble/utils.d.ts +7 -0
- package/lib/ble/utils.js +95 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +93 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
- 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/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/index.d.ts +12 -0
- package/lib/index.js +38 -0
- package/lib/interfaces.d.ts +6 -0
- package/lib/interfaces.js +23 -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 +4 -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 +16 -0
- package/lib/serial/adapter.js +42 -0
- package/lib/serial/bindings/tcp.d.ts +44 -0
- package/lib/serial/bindings/tcp.js +270 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
- package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
- 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 +24 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
- 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} +214 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +290 -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 +13 -24
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
- 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 +58 -0
- package/lib/serial/serial-interface.js +283 -0
- package/lib/simulator/Simulator.d.ts +10 -25
- package/lib/simulator/Simulator.js +19 -83
- package/lib/types/adapter.d.ts +32 -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 +29 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +14 -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 +15 -11
- 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/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/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/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
- /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
- /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,15 +12,17 @@ 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
28
|
this.ignoreHrm = false;
|
|
@@ -47,11 +30,18 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
47
30
|
this.ignoreBike = false;
|
|
48
31
|
this.paused = false;
|
|
49
32
|
this.iv = null;
|
|
50
|
-
this.comms = new comms_1.default({
|
|
33
|
+
this.comms = new comms_1.default({ interface: settings.interface, port: settings.port, logger: this.logger });
|
|
34
|
+
this.capabilities = [
|
|
35
|
+
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Gear, capabilities_1.IncyclistCapability.HeartRate,
|
|
36
|
+
capabilities_1.IncyclistCapability.Control
|
|
37
|
+
];
|
|
51
38
|
}
|
|
52
39
|
isBike() { return true; }
|
|
53
40
|
isPower() { return true; }
|
|
54
41
|
isHrm() { return true; }
|
|
42
|
+
getProtocolName() {
|
|
43
|
+
return PROTOCOL_NAME;
|
|
44
|
+
}
|
|
55
45
|
isSame(device) {
|
|
56
46
|
if (!(device instanceof KettlerRacerAdapter))
|
|
57
47
|
return false;
|
|
@@ -68,7 +58,8 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
68
58
|
return this.settings.name || this.getProtocolName();
|
|
69
59
|
}
|
|
70
60
|
getPort() {
|
|
71
|
-
|
|
61
|
+
const settings = this.settings;
|
|
62
|
+
return settings.port;
|
|
72
63
|
}
|
|
73
64
|
setIgnoreHrm(ignore) {
|
|
74
65
|
this.ignoreHrm = ignore;
|
|
@@ -88,23 +79,9 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
88
79
|
getLogger() {
|
|
89
80
|
return this.logger;
|
|
90
81
|
}
|
|
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
82
|
setComputerMode() {
|
|
106
83
|
return this.send('setComputerMode', 'CP').then(response => {
|
|
107
|
-
this.
|
|
84
|
+
this.logEvent({ response });
|
|
108
85
|
if (response === 'ACK' || response === 'RUN') {
|
|
109
86
|
return true;
|
|
110
87
|
}
|
|
@@ -115,7 +92,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
115
92
|
}
|
|
116
93
|
setClientMode() {
|
|
117
94
|
return this.send('setClientMode', 'CM').then(response => {
|
|
118
|
-
this.
|
|
95
|
+
this.logEvent({ response });
|
|
119
96
|
if (response === 'ACK' || response === 'RUN') {
|
|
120
97
|
return true;
|
|
121
98
|
}
|
|
@@ -126,7 +103,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
126
103
|
}
|
|
127
104
|
reset() {
|
|
128
105
|
return this.send('reset', 'RS').then(response => {
|
|
129
|
-
this.
|
|
106
|
+
this.logEvent({ response });
|
|
130
107
|
if (response === 'ACK' || response === 'RUN') {
|
|
131
108
|
return true;
|
|
132
109
|
}
|
|
@@ -137,21 +114,21 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
137
114
|
}
|
|
138
115
|
getIdentifier() {
|
|
139
116
|
return this.send('getIdentifier', 'ID').then(response => {
|
|
140
|
-
this.
|
|
117
|
+
this.logEvent({ response });
|
|
141
118
|
return response.substring(0, 3);
|
|
142
119
|
});
|
|
143
120
|
}
|
|
144
|
-
|
|
121
|
+
getKettlerInterface() {
|
|
145
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
123
|
const res = yield this.send('getInterface', 'KI');
|
|
147
|
-
this.
|
|
124
|
+
this.logEvent({ interface: res });
|
|
148
125
|
return res;
|
|
149
126
|
});
|
|
150
127
|
}
|
|
151
128
|
getVersion() {
|
|
152
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
130
|
const res = yield this.send('getVersion', 'VE');
|
|
154
|
-
this.
|
|
131
|
+
this.logEvent({ version: res });
|
|
155
132
|
return res;
|
|
156
133
|
});
|
|
157
134
|
}
|
|
@@ -267,14 +244,14 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
267
244
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
245
|
var info = {};
|
|
269
246
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
270
|
-
this.
|
|
247
|
+
this.logEvent({ message: "checking device", port: this.getPort() });
|
|
271
248
|
let iv = undefined;
|
|
272
249
|
try {
|
|
273
250
|
if (!info.opened)
|
|
274
251
|
info.opened = yield this.waitForOpened();
|
|
275
252
|
iv = setTimeout(() => {
|
|
276
|
-
this.
|
|
277
|
-
|
|
253
|
+
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: 'timeout' });
|
|
254
|
+
resolve(false);
|
|
278
255
|
}, 5000);
|
|
279
256
|
if (!info.pcMode)
|
|
280
257
|
info.pcMode = yield this.setClientMode();
|
|
@@ -283,27 +260,28 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
283
260
|
if (!info.version)
|
|
284
261
|
info.version = yield this.getVersion();
|
|
285
262
|
try {
|
|
286
|
-
yield this.
|
|
263
|
+
yield this.getKettlerInterface();
|
|
287
264
|
}
|
|
288
265
|
catch (e) {
|
|
289
|
-
this.
|
|
266
|
+
this.logEvent({ message: 'could not get kettler interface', error: e.message });
|
|
290
267
|
}
|
|
291
268
|
clearTimeout(iv);
|
|
292
|
-
|
|
269
|
+
this.logEvent({ message: "checking device success", port: this.getPort(), info });
|
|
270
|
+
resolve(true);
|
|
293
271
|
}
|
|
294
272
|
catch (err) {
|
|
295
|
-
this.
|
|
273
|
+
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: err.message || err });
|
|
296
274
|
if (iv)
|
|
297
275
|
clearTimeout(iv);
|
|
298
276
|
iv = undefined;
|
|
299
|
-
|
|
277
|
+
resolve(false);
|
|
300
278
|
}
|
|
301
279
|
}));
|
|
302
280
|
});
|
|
303
281
|
}
|
|
304
282
|
start(props) {
|
|
305
283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
this.
|
|
284
|
+
this.logEvent({ message: 'start()' });
|
|
307
285
|
var info = {};
|
|
308
286
|
yield this.waitForOpened(true);
|
|
309
287
|
return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -317,13 +295,13 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
317
295
|
}
|
|
318
296
|
}
|
|
319
297
|
catch (e) {
|
|
320
|
-
this.
|
|
298
|
+
this.logEvent({ message: 'Error', error: e.message });
|
|
321
299
|
}
|
|
322
300
|
try {
|
|
323
301
|
yield this.setPower(100);
|
|
324
302
|
}
|
|
325
303
|
catch (e) {
|
|
326
|
-
this.
|
|
304
|
+
this.logEvent({ message: 'Error', error: e.message });
|
|
327
305
|
}
|
|
328
306
|
if (!info.data) {
|
|
329
307
|
yield this.update();
|
|
@@ -336,21 +314,21 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
336
314
|
yield this.reset();
|
|
337
315
|
}
|
|
338
316
|
catch (e) {
|
|
339
|
-
this.
|
|
317
|
+
this.logEvent({ message: 'Error', error: e.message });
|
|
340
318
|
}
|
|
341
319
|
throw (new Error(`could not start device, reason:${err.message}`));
|
|
342
320
|
}
|
|
343
321
|
}), 5, 1000)
|
|
344
322
|
.then((data) => {
|
|
345
323
|
this.startUpdatePull();
|
|
346
|
-
return
|
|
324
|
+
return true;
|
|
347
325
|
});
|
|
348
326
|
});
|
|
349
327
|
}
|
|
350
328
|
startUpdatePull() {
|
|
351
329
|
if (this.iv)
|
|
352
330
|
return;
|
|
353
|
-
this.
|
|
331
|
+
this.logEvent({ message: 'start regular device update' });
|
|
354
332
|
if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
|
|
355
333
|
return;
|
|
356
334
|
const ivSync = setInterval(() => {
|
|
@@ -366,7 +344,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
366
344
|
};
|
|
367
345
|
}
|
|
368
346
|
stop() {
|
|
369
|
-
this.
|
|
347
|
+
this.logEvent({ message: 'stop request' });
|
|
370
348
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
371
349
|
try {
|
|
372
350
|
if (this.iv) {
|
|
@@ -377,31 +355,17 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
377
355
|
this.iv = undefined;
|
|
378
356
|
}
|
|
379
357
|
yield this.waitForClosed();
|
|
380
|
-
this.
|
|
358
|
+
this.logEvent({ message: 'stop request completed' });
|
|
381
359
|
this.paused = undefined;
|
|
382
360
|
resolve(true);
|
|
383
361
|
}
|
|
384
362
|
catch (err) {
|
|
385
|
-
this.
|
|
363
|
+
this.logEvent({ message: 'stop error', error: err.message });
|
|
386
364
|
this.paused = undefined;
|
|
387
365
|
reject(err);
|
|
388
366
|
}
|
|
389
367
|
}));
|
|
390
368
|
}
|
|
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
369
|
mapData(bikeData) {
|
|
406
370
|
let data = {};
|
|
407
371
|
data.isPedalling = bikeData.cadence > 0;
|
|
@@ -453,13 +417,13 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
453
417
|
this.data = this.transformData(data, bikeData);
|
|
454
418
|
}
|
|
455
419
|
catch (err) {
|
|
456
|
-
this.
|
|
420
|
+
this.logEvent({ message: 'bike update error', error: err.message });
|
|
457
421
|
}
|
|
458
422
|
}
|
|
459
423
|
this.updateBusy = false;
|
|
460
424
|
})
|
|
461
425
|
.catch(err => {
|
|
462
|
-
this.
|
|
426
|
+
this.logEvent({ message: 'bike update error', error: err.message });
|
|
463
427
|
this.updateBusy = false;
|
|
464
428
|
});
|
|
465
429
|
});
|
|
@@ -468,7 +432,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
468
432
|
return __awaiter(this, void 0, void 0, function* () {
|
|
469
433
|
this.requestBusy = true;
|
|
470
434
|
try {
|
|
471
|
-
this.
|
|
435
|
+
this.logEvent({ message: 'sendRequest', request });
|
|
472
436
|
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
473
437
|
if (isReset) {
|
|
474
438
|
this.requestBusy = false;
|
|
@@ -485,7 +449,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
485
449
|
}
|
|
486
450
|
catch (err) {
|
|
487
451
|
this.requestBusy = false;
|
|
488
|
-
this.
|
|
452
|
+
this.logEvent({ message: 'error', fn: 'sendRequest()', error: err.message || err });
|
|
489
453
|
return;
|
|
490
454
|
}
|
|
491
455
|
});
|
|
@@ -497,7 +461,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
497
461
|
const cnt = processing.length;
|
|
498
462
|
processing.forEach((request, idx) => __awaiter(this, void 0, void 0, function* () {
|
|
499
463
|
if (cnt > 1 && idx < cnt - 1) {
|
|
500
|
-
this.
|
|
464
|
+
this.logEvent({ message: 'ignoring bike update request', request });
|
|
501
465
|
this.requests.shift();
|
|
502
466
|
return;
|
|
503
467
|
}
|
|
@@ -508,7 +472,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
508
472
|
this.requests.shift();
|
|
509
473
|
}
|
|
510
474
|
catch (err) {
|
|
511
|
-
this.
|
|
475
|
+
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack, request });
|
|
512
476
|
}
|
|
513
477
|
}
|
|
514
478
|
});
|
|
@@ -521,7 +485,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
521
485
|
if (this.updateBusy || this.requestBusy) {
|
|
522
486
|
return;
|
|
523
487
|
}
|
|
524
|
-
this.
|
|
488
|
+
this.logEvent({ message: 'bikeSync' });
|
|
525
489
|
if (!this.ignoreBike) {
|
|
526
490
|
yield this.sendRequests();
|
|
527
491
|
}
|
|
@@ -532,7 +496,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
532
496
|
return __awaiter(this, void 0, void 0, function* () {
|
|
533
497
|
if (this.paused)
|
|
534
498
|
return;
|
|
535
|
-
this.
|
|
499
|
+
this.logEvent({ message: 'sendUpdate', request, waiting: this.requests.length });
|
|
536
500
|
return yield this.processClientRequest(request);
|
|
537
501
|
});
|
|
538
502
|
}
|
|
@@ -546,7 +510,7 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
546
510
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true }) || {};
|
|
547
511
|
const prev = this.requests[this.requests.length - 1] || {};
|
|
548
512
|
if (bikeRequest.targetPower !== undefined && bikeRequest.targetPower !== prev.targetPower) {
|
|
549
|
-
this.
|
|
513
|
+
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
550
514
|
this.requests.push(bikeRequest);
|
|
551
515
|
}
|
|
552
516
|
}
|
|
@@ -556,44 +520,43 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
556
520
|
}
|
|
557
521
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
558
522
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate(request);
|
|
559
|
-
this.
|
|
523
|
+
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
560
524
|
this.requests.push(bikeRequest);
|
|
561
525
|
resolve(bikeRequest);
|
|
562
526
|
}));
|
|
563
527
|
}
|
|
528
|
+
connect() {
|
|
529
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
530
|
+
return yield this.waitForOpened(true);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
close() {
|
|
534
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
+
return yield this.waitForClosed();
|
|
536
|
+
});
|
|
537
|
+
}
|
|
564
538
|
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();
|
|
539
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
540
|
+
if (!retries) {
|
|
541
|
+
return yield this.comms.open();
|
|
585
542
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
543
|
+
else {
|
|
544
|
+
let opened;
|
|
545
|
+
let tries = 0;
|
|
546
|
+
while (!opened && tries < 3) {
|
|
547
|
+
try {
|
|
548
|
+
opened = yield this.comms.open();
|
|
549
|
+
if (opened)
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
}
|
|
554
|
+
tries++;
|
|
555
|
+
yield (0, utils_1.sleep)(500);
|
|
556
|
+
}
|
|
557
|
+
return false;
|
|
589
558
|
}
|
|
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);
|
|
559
|
+
});
|
|
597
560
|
}
|
|
598
561
|
waitForClosed() {
|
|
599
562
|
return new Promise((resolve, reject) => {
|
|
@@ -614,26 +577,20 @@ class KettlerRacerAdapter extends device_1.default {
|
|
|
614
577
|
this.comms.on('closed', onClose);
|
|
615
578
|
this.comms.on('opened', onOpen);
|
|
616
579
|
this.comms.on('error', onError);
|
|
617
|
-
this.
|
|
580
|
+
this.logEvent({ message: 'closing', port: this.getPort() });
|
|
618
581
|
this.comms.close();
|
|
619
582
|
}
|
|
620
583
|
catch (err) {
|
|
621
|
-
this.
|
|
584
|
+
this.logEvent({ message: 'error', fn: 'waitForClosed()', error: err.message || err });
|
|
622
585
|
reject(err);
|
|
623
586
|
}
|
|
624
587
|
});
|
|
625
588
|
}
|
|
626
589
|
getSupportedCyclingModes() {
|
|
627
|
-
return [power_meter_1.default,
|
|
590
|
+
return [power_meter_1.default, erg_1.default];
|
|
628
591
|
}
|
|
629
592
|
getDefaultCyclingMode() {
|
|
630
|
-
return new
|
|
631
|
-
}
|
|
632
|
-
setUserSettings(userSettings) {
|
|
633
|
-
this.settings.userSettings = userSettings;
|
|
634
|
-
}
|
|
635
|
-
setBikeSettings(bikeSettings) {
|
|
636
|
-
this.settings.bikeSettings = bikeSettings;
|
|
593
|
+
return new erg_1.default(this);
|
|
637
594
|
}
|
|
638
595
|
}
|
|
639
596
|
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
|
+
}
|