incyclist-devices 1.5.11 → 1.5.13
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/LICENSE +0 -0
- package/lib/DeviceSupport.d.ts +36 -36
- package/lib/DeviceSupport.js +82 -82
- package/lib/ant/AntAdapter.d.ts +50 -50
- package/lib/ant/AntAdapter.js +109 -109
- package/lib/ant/AntScanner.d.ts +60 -60
- package/lib/ant/AntScanner.js +651 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +83 -83
- package/lib/ant/antfe/AntFEAdapter.js +652 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +9 -9
- package/lib/ant/antfe/ant-fe-adv-st-mode.js +51 -51
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +6 -6
- package/lib/ant/antfe/ant-fe-erg-mode.js +14 -14
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +5 -5
- package/lib/ant/antfe/ant-fe-st-mode.js +13 -13
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +16 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +130 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +49 -49
- package/lib/ant/antpwr/pwr-adapter.js +251 -251
- package/lib/ant/utils.d.ts +1 -1
- package/lib/ant/utils.js +23 -23
- package/lib/antv2/AntAdapter.d.ts +48 -0
- package/lib/antv2/AntAdapter.js +104 -0
- package/lib/antv2/adapter-factory.d.ts +11 -11
- package/lib/antv2/adapter-factory.js +40 -40
- package/lib/antv2/ant-binding.d.ts +13 -13
- package/lib/antv2/ant-binding.js +27 -27
- package/lib/antv2/ant-device.d.ts +51 -51
- package/lib/antv2/ant-device.js +115 -115
- package/lib/antv2/ant-interface.d.ts +37 -37
- package/lib/antv2/ant-interface.js +255 -255
- package/lib/antv2/fe.d.ts +29 -29
- package/lib/antv2/fe.js +262 -262
- package/lib/antv2/hr.d.ts +18 -18
- package/lib/antv2/hr.js +93 -93
- package/lib/antv2/incyclist-protocol.d.ts +37 -37
- package/lib/antv2/incyclist-protocol.js +126 -126
- package/lib/antv2/pwr.d.ts +28 -28
- package/lib/antv2/pwr.js +163 -163
- package/lib/antv2/sensor-factory.d.ts +5 -5
- package/lib/antv2/sensor-factory.js +20 -20
- package/lib/ble/ble-device.d.ts +63 -63
- package/lib/ble/ble-device.js +444 -444
- package/lib/ble/ble-erg-mode.d.ts +18 -18
- package/lib/ble/ble-erg-mode.js +132 -132
- package/lib/ble/ble-interface.d.ts +100 -100
- package/lib/ble/ble-interface.js +721 -721
- package/lib/ble/ble-peripheral.d.ts +36 -36
- package/lib/ble/ble-peripheral.js +200 -200
- package/lib/ble/ble-st-mode.d.ts +15 -15
- package/lib/ble/ble-st-mode.js +95 -95
- package/lib/ble/ble.d.ts +129 -129
- package/lib/ble/ble.js +86 -86
- package/lib/ble/consts.d.ts +14 -14
- package/lib/ble/consts.js +17 -17
- package/lib/ble/elite.d.ts +90 -90
- package/lib/ble/elite.js +322 -322
- package/lib/ble/fm.d.ts +125 -125
- package/lib/ble/fm.js +745 -745
- package/lib/ble/hrm.d.ts +48 -48
- package/lib/ble/hrm.js +134 -134
- package/lib/ble/incyclist-protocol.d.ts +31 -31
- package/lib/ble/incyclist-protocol.js +153 -153
- package/lib/ble/pwr.d.ts +89 -89
- package/lib/ble/pwr.js +321 -321
- package/lib/ble/tacx.d.ts +92 -90
- package/lib/ble/tacx.js +763 -731
- package/lib/ble/wahoo-kickr.d.ts +98 -98
- package/lib/ble/wahoo-kickr.js +496 -496
- package/lib/calculations.d.ts +13 -13
- package/lib/calculations.js +150 -150
- package/lib/cycling-mode.d.ts +76 -76
- package/lib/cycling-mode.js +79 -79
- package/lib/daum/DaumAdapter.d.ts +67 -66
- package/lib/daum/DaumAdapter.js +405 -396
- package/lib/daum/DaumPowerMeterCyclingMode.d.ts +8 -8
- package/lib/daum/DaumPowerMeterCyclingMode.js +21 -21
- package/lib/daum/ERGCyclingMode.d.ts +26 -26
- package/lib/daum/ERGCyclingMode.js +201 -201
- package/lib/daum/SmartTrainerCyclingMode.d.ts +41 -41
- package/lib/daum/SmartTrainerCyclingMode.js +344 -344
- package/lib/daum/classic/DaumClassicAdapter.d.ts +27 -22
- package/lib/daum/classic/DaumClassicAdapter.js +189 -183
- package/lib/daum/classic/DaumClassicCyclingMode.d.ts +13 -13
- package/lib/daum/classic/DaumClassicCyclingMode.js +97 -97
- package/lib/daum/classic/DaumClassicProtocol.d.ts +27 -27
- package/lib/daum/classic/DaumClassicProtocol.js +185 -185
- package/lib/daum/classic/bike.d.ts +68 -68
- package/lib/daum/classic/bike.js +467 -467
- package/lib/daum/classic/utils.d.ts +13 -13
- package/lib/daum/classic/utils.js +143 -143
- package/lib/daum/constants.d.ts +19 -19
- package/lib/daum/constants.js +22 -22
- package/lib/daum/premium/DaumClassicCyclingMode.d.ts +14 -14
- package/lib/daum/premium/DaumClassicCyclingMode.js +86 -86
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +16 -16
- package/lib/daum/premium/DaumPremiumAdapter.js +163 -163
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +32 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +207 -207
- package/lib/daum/premium/bike.d.ts +127 -127
- package/lib/daum/premium/bike.js +904 -904
- package/lib/daum/premium/tcpserial.d.ts +33 -33
- package/lib/daum/premium/tcpserial.js +123 -123
- package/lib/daum/premium/utils.d.ts +62 -62
- package/lib/daum/premium/utils.js +376 -376
- package/lib/device.d.ts +92 -92
- package/lib/device.js +71 -71
- package/lib/kettler/comms.d.ts +59 -59
- package/lib/kettler/comms.js +242 -242
- package/lib/kettler/ergo-racer/ERGCyclingMode.d.ts +25 -25
- package/lib/kettler/ergo-racer/ERGCyclingMode.js +144 -144
- package/lib/kettler/ergo-racer/adapter.d.ts +101 -101
- package/lib/kettler/ergo-racer/adapter.js +639 -639
- package/lib/kettler/ergo-racer/protocol.d.ts +41 -41
- package/lib/kettler/ergo-racer/protocol.js +203 -203
- package/lib/modes/power-base.d.ts +20 -20
- package/lib/modes/power-base.js +70 -70
- package/lib/modes/power-meter.d.ts +20 -20
- package/lib/modes/power-meter.js +78 -78
- package/lib/modes/simulator.d.ts +29 -29
- package/lib/modes/simulator.js +140 -140
- package/lib/protocol.d.ts +74 -74
- package/lib/protocol.js +41 -41
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +33 -33
- package/lib/simulator/Simulator.d.ts +69 -69
- package/lib/simulator/Simulator.js +288 -288
- package/lib/types/command.d.ts +8 -8
- package/lib/types/command.js +2 -2
- package/lib/types/route.d.ts +24 -24
- package/lib/types/route.js +9 -9
- package/lib/types/user.d.ts +11 -11
- package/lib/types/user.js +9 -9
- package/lib/utils.d.ts +14 -14
- package/lib/utils.js +114 -114
- package/package.json +47 -47
package/lib/daum/DaumAdapter.js
CHANGED
|
@@ -1,396 +1,405 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
const device_1 = __importStar(require("../device"));
|
|
35
|
-
const ERGCyclingMode_1 = __importDefault(require("./ERGCyclingMode"));
|
|
36
|
-
const SmartTrainerCyclingMode_1 = __importDefault(require("./SmartTrainerCyclingMode"));
|
|
37
|
-
const DaumPowerMeterCyclingMode_1 = __importDefault(require("./DaumPowerMeterCyclingMode"));
|
|
38
|
-
const utils_1 = require("../utils");
|
|
39
|
-
class DaumAdapterBase extends device_1.default {
|
|
40
|
-
constructor(props, bike) {
|
|
41
|
-
super(props);
|
|
42
|
-
this.requests = [];
|
|
43
|
-
this.adapterTime = 0;
|
|
44
|
-
this.requestBusy = false;
|
|
45
|
-
this.updateBusy = false;
|
|
46
|
-
this.bike = bike;
|
|
47
|
-
this.stopped = false;
|
|
48
|
-
this.paused = false;
|
|
49
|
-
this.cyclingData = {
|
|
50
|
-
isPedalling: false,
|
|
51
|
-
time: 0,
|
|
52
|
-
power: 0,
|
|
53
|
-
pedalRpm: 0,
|
|
54
|
-
speed: 0,
|
|
55
|
-
distanceInternal: 0,
|
|
56
|
-
heartrate: 0
|
|
57
|
-
};
|
|
58
|
-
this.deviceData = {};
|
|
59
|
-
const options = props || {};
|
|
60
|
-
this.cyclingMode = options.cyclingMode;
|
|
61
|
-
this.setUserSettings(options.userSettings);
|
|
62
|
-
this.setBikeSettings(options.bikeSettings);
|
|
63
|
-
}
|
|
64
|
-
setCyclingMode(mode, settings) {
|
|
65
|
-
let selectedMode;
|
|
66
|
-
if (typeof mode === 'string') {
|
|
67
|
-
const supported = this.getSupportedCyclingModes();
|
|
68
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
69
|
-
if (CyclingModeClass) {
|
|
70
|
-
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
selectedMode = this.getDefaultCyclingMode();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
selectedMode = mode;
|
|
77
|
-
}
|
|
78
|
-
this.cyclingMode = selectedMode;
|
|
79
|
-
this.cyclingMode.setSettings(settings);
|
|
80
|
-
}
|
|
81
|
-
getSupportedCyclingModes() {
|
|
82
|
-
return [ERGCyclingMode_1.default, SmartTrainerCyclingMode_1.default, DaumPowerMeterCyclingMode_1.default];
|
|
83
|
-
}
|
|
84
|
-
getCyclingMode() {
|
|
85
|
-
if (!this.cyclingMode)
|
|
86
|
-
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
87
|
-
return this.cyclingMode;
|
|
88
|
-
}
|
|
89
|
-
getDefaultCyclingMode() {
|
|
90
|
-
return new ERGCyclingMode_1.default(this);
|
|
91
|
-
}
|
|
92
|
-
setUserSettings(userSettings) {
|
|
93
|
-
this.userSettings = userSettings || {};
|
|
94
|
-
if (this.bike) {
|
|
95
|
-
if (!this.bike.settings)
|
|
96
|
-
this.bike.settings = { user: {} };
|
|
97
|
-
if (!this.bike.settings.user)
|
|
98
|
-
this.bike.settings.user = {};
|
|
99
|
-
this.bike.settings.user.weight = this.userSettings.weight || device_1.DEFAULT_USER_WEIGHT;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
setBikeSettings(bikeSettings) {
|
|
103
|
-
this.bikeSettings = bikeSettings || {};
|
|
104
|
-
if (this.bike) {
|
|
105
|
-
if (!this.bike.settings)
|
|
106
|
-
this.bike.settings = {};
|
|
107
|
-
this.bike.settings.weight = this.userSettings.weight || device_1.DEFAULT_BIKE_WEIGHT;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
getWeight() {
|
|
111
|
-
const userWeight = Number(this.userSettings.weight || device_1.DEFAULT_USER_WEIGHT);
|
|
112
|
-
const bikeWeight = Number(this.bikeSettings.weight || device_1.DEFAULT_BIKE_WEIGHT);
|
|
113
|
-
return bikeWeight + userWeight;
|
|
114
|
-
}
|
|
115
|
-
getCurrentBikeData() {
|
|
116
|
-
throw new Error('Method not implemented.');
|
|
117
|
-
}
|
|
118
|
-
getBike() {
|
|
119
|
-
return this.bike;
|
|
120
|
-
}
|
|
121
|
-
isBike() {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
isPower() {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
isHrm() {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
isSame(device) {
|
|
131
|
-
if (!(device instanceof DaumAdapterBase))
|
|
132
|
-
return false;
|
|
133
|
-
const adapter = device;
|
|
134
|
-
return (adapter.getName() === this.getName() && adapter.getPort() === this.getPort());
|
|
135
|
-
}
|
|
136
|
-
setIgnoreHrm(ignore) {
|
|
137
|
-
this.ignoreHrm = ignore;
|
|
138
|
-
}
|
|
139
|
-
setIgnoreBike(ignore) {
|
|
140
|
-
this.ignoreBike = ignore;
|
|
141
|
-
}
|
|
142
|
-
isStopped() {
|
|
143
|
-
return this.stopped;
|
|
144
|
-
}
|
|
145
|
-
initData() {
|
|
146
|
-
this.distanceInternal = undefined;
|
|
147
|
-
this.paused = false;
|
|
148
|
-
this.stopped = false;
|
|
149
|
-
this.cyclingData = {
|
|
150
|
-
isPedalling: false,
|
|
151
|
-
time: 0,
|
|
152
|
-
power: 0,
|
|
153
|
-
pedalRpm: 0,
|
|
154
|
-
speed: 0,
|
|
155
|
-
distanceInternal: 0,
|
|
156
|
-
heartrate: 0
|
|
157
|
-
};
|
|
158
|
-
this.deviceData = {};
|
|
159
|
-
this.currentRequest = {};
|
|
160
|
-
this.requests = [];
|
|
161
|
-
const name = this.getCyclingMode().getName();
|
|
162
|
-
const settings = this.getCyclingMode().getSettings();
|
|
163
|
-
this.setCyclingMode(name, settings);
|
|
164
|
-
}
|
|
165
|
-
start(props) {
|
|
166
|
-
throw new Error('Method not implemented.');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (this.iv)
|
|
170
|
-
return;
|
|
171
|
-
if (this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
this.
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
this.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
const device_1 = __importStar(require("../device"));
|
|
35
|
+
const ERGCyclingMode_1 = __importDefault(require("./ERGCyclingMode"));
|
|
36
|
+
const SmartTrainerCyclingMode_1 = __importDefault(require("./SmartTrainerCyclingMode"));
|
|
37
|
+
const DaumPowerMeterCyclingMode_1 = __importDefault(require("./DaumPowerMeterCyclingMode"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
39
|
+
class DaumAdapterBase extends device_1.default {
|
|
40
|
+
constructor(props, bike) {
|
|
41
|
+
super(props);
|
|
42
|
+
this.requests = [];
|
|
43
|
+
this.adapterTime = 0;
|
|
44
|
+
this.requestBusy = false;
|
|
45
|
+
this.updateBusy = false;
|
|
46
|
+
this.bike = bike;
|
|
47
|
+
this.stopped = false;
|
|
48
|
+
this.paused = false;
|
|
49
|
+
this.cyclingData = {
|
|
50
|
+
isPedalling: false,
|
|
51
|
+
time: 0,
|
|
52
|
+
power: 0,
|
|
53
|
+
pedalRpm: 0,
|
|
54
|
+
speed: 0,
|
|
55
|
+
distanceInternal: 0,
|
|
56
|
+
heartrate: 0
|
|
57
|
+
};
|
|
58
|
+
this.deviceData = {};
|
|
59
|
+
const options = props || {};
|
|
60
|
+
this.cyclingMode = options.cyclingMode;
|
|
61
|
+
this.setUserSettings(options.userSettings);
|
|
62
|
+
this.setBikeSettings(options.bikeSettings);
|
|
63
|
+
}
|
|
64
|
+
setCyclingMode(mode, settings) {
|
|
65
|
+
let selectedMode;
|
|
66
|
+
if (typeof mode === 'string') {
|
|
67
|
+
const supported = this.getSupportedCyclingModes();
|
|
68
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
69
|
+
if (CyclingModeClass) {
|
|
70
|
+
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
selectedMode = this.getDefaultCyclingMode();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
selectedMode = mode;
|
|
77
|
+
}
|
|
78
|
+
this.cyclingMode = selectedMode;
|
|
79
|
+
this.cyclingMode.setSettings(settings);
|
|
80
|
+
}
|
|
81
|
+
getSupportedCyclingModes() {
|
|
82
|
+
return [ERGCyclingMode_1.default, SmartTrainerCyclingMode_1.default, DaumPowerMeterCyclingMode_1.default];
|
|
83
|
+
}
|
|
84
|
+
getCyclingMode() {
|
|
85
|
+
if (!this.cyclingMode)
|
|
86
|
+
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
87
|
+
return this.cyclingMode;
|
|
88
|
+
}
|
|
89
|
+
getDefaultCyclingMode() {
|
|
90
|
+
return new ERGCyclingMode_1.default(this);
|
|
91
|
+
}
|
|
92
|
+
setUserSettings(userSettings) {
|
|
93
|
+
this.userSettings = userSettings || {};
|
|
94
|
+
if (this.bike) {
|
|
95
|
+
if (!this.bike.settings)
|
|
96
|
+
this.bike.settings = { user: {} };
|
|
97
|
+
if (!this.bike.settings.user)
|
|
98
|
+
this.bike.settings.user = {};
|
|
99
|
+
this.bike.settings.user.weight = this.userSettings.weight || device_1.DEFAULT_USER_WEIGHT;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
setBikeSettings(bikeSettings) {
|
|
103
|
+
this.bikeSettings = bikeSettings || {};
|
|
104
|
+
if (this.bike) {
|
|
105
|
+
if (!this.bike.settings)
|
|
106
|
+
this.bike.settings = {};
|
|
107
|
+
this.bike.settings.weight = this.userSettings.weight || device_1.DEFAULT_BIKE_WEIGHT;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
getWeight() {
|
|
111
|
+
const userWeight = Number(this.userSettings.weight || device_1.DEFAULT_USER_WEIGHT);
|
|
112
|
+
const bikeWeight = Number(this.bikeSettings.weight || device_1.DEFAULT_BIKE_WEIGHT);
|
|
113
|
+
return bikeWeight + userWeight;
|
|
114
|
+
}
|
|
115
|
+
getCurrentBikeData() {
|
|
116
|
+
throw new Error('Method not implemented.');
|
|
117
|
+
}
|
|
118
|
+
getBike() {
|
|
119
|
+
return this.bike;
|
|
120
|
+
}
|
|
121
|
+
isBike() {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
isPower() {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
isHrm() {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
isSame(device) {
|
|
131
|
+
if (!(device instanceof DaumAdapterBase))
|
|
132
|
+
return false;
|
|
133
|
+
const adapter = device;
|
|
134
|
+
return (adapter.getName() === this.getName() && adapter.getPort() === this.getPort());
|
|
135
|
+
}
|
|
136
|
+
setIgnoreHrm(ignore) {
|
|
137
|
+
this.ignoreHrm = ignore;
|
|
138
|
+
}
|
|
139
|
+
setIgnoreBike(ignore) {
|
|
140
|
+
this.ignoreBike = ignore;
|
|
141
|
+
}
|
|
142
|
+
isStopped() {
|
|
143
|
+
return this.stopped;
|
|
144
|
+
}
|
|
145
|
+
initData() {
|
|
146
|
+
this.distanceInternal = undefined;
|
|
147
|
+
this.paused = false;
|
|
148
|
+
this.stopped = false;
|
|
149
|
+
this.cyclingData = {
|
|
150
|
+
isPedalling: false,
|
|
151
|
+
time: 0,
|
|
152
|
+
power: 0,
|
|
153
|
+
pedalRpm: 0,
|
|
154
|
+
speed: 0,
|
|
155
|
+
distanceInternal: 0,
|
|
156
|
+
heartrate: 0
|
|
157
|
+
};
|
|
158
|
+
this.deviceData = {};
|
|
159
|
+
this.currentRequest = {};
|
|
160
|
+
this.requests = [];
|
|
161
|
+
const name = this.getCyclingMode().getName();
|
|
162
|
+
const settings = this.getCyclingMode().getSettings();
|
|
163
|
+
this.setCyclingMode(name, settings);
|
|
164
|
+
}
|
|
165
|
+
start(props) {
|
|
166
|
+
throw new Error('Method not implemented.');
|
|
167
|
+
}
|
|
168
|
+
stopUpdatePull() {
|
|
169
|
+
if (!this.iv)
|
|
170
|
+
return;
|
|
171
|
+
if (this.iv.sync)
|
|
172
|
+
clearInterval(this.iv.sync);
|
|
173
|
+
if (this.iv.update)
|
|
174
|
+
clearInterval(this.iv.update);
|
|
175
|
+
this.iv = undefined;
|
|
176
|
+
}
|
|
177
|
+
startUpdatePull() {
|
|
178
|
+
if (this.iv)
|
|
179
|
+
return;
|
|
180
|
+
if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
|
|
181
|
+
return;
|
|
182
|
+
const ivSync = setInterval(() => {
|
|
183
|
+
this.bikeSync();
|
|
184
|
+
}, 1000);
|
|
185
|
+
const ivUpdate = setInterval(() => {
|
|
186
|
+
this.sendData();
|
|
187
|
+
this.refreshRequests();
|
|
188
|
+
}, 1000);
|
|
189
|
+
this.iv = {
|
|
190
|
+
sync: ivSync,
|
|
191
|
+
update: ivUpdate
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
connect() {
|
|
195
|
+
if (!this.bike.isConnected())
|
|
196
|
+
this.bike.connect();
|
|
197
|
+
}
|
|
198
|
+
close() {
|
|
199
|
+
return this.bike.saveClose();
|
|
200
|
+
}
|
|
201
|
+
logEvent(event) {
|
|
202
|
+
if (!this.logger)
|
|
203
|
+
return;
|
|
204
|
+
this.logger.logEvent(event);
|
|
205
|
+
}
|
|
206
|
+
stop() {
|
|
207
|
+
this.logEvent({ message: 'stop request' });
|
|
208
|
+
this.stopped = true;
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
try {
|
|
211
|
+
if (this.iv) {
|
|
212
|
+
if (this.iv.sync)
|
|
213
|
+
clearInterval(this.iv.sync);
|
|
214
|
+
if (this.iv.update)
|
|
215
|
+
clearInterval(this.iv.update);
|
|
216
|
+
this.iv = undefined;
|
|
217
|
+
}
|
|
218
|
+
this.logEvent({ message: 'stop request completed' });
|
|
219
|
+
this.paused = undefined;
|
|
220
|
+
resolve(true);
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
this.logEvent({ message: 'stop error', error: err.message });
|
|
224
|
+
reject(err);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
pause() {
|
|
229
|
+
this.logEvent({ message: 'pause' });
|
|
230
|
+
return new Promise(resolve => {
|
|
231
|
+
this.paused = true;
|
|
232
|
+
resolve(true);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
resume() {
|
|
236
|
+
this.logEvent({ message: 'resume' });
|
|
237
|
+
return new Promise(resolve => {
|
|
238
|
+
this.paused = false;
|
|
239
|
+
resolve(true);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
sendUpdate(request) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
if (this.paused)
|
|
245
|
+
return;
|
|
246
|
+
this.logEvent({ message: 'sendUpdate', request, waiting: this.requests.length });
|
|
247
|
+
return yield this.processClientRequest(request);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
sendData() {
|
|
251
|
+
if (this.onDataFn)
|
|
252
|
+
this.onDataFn(this.deviceData);
|
|
253
|
+
}
|
|
254
|
+
update() {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
this.updateBusy = true;
|
|
257
|
+
this.getCurrentBikeData()
|
|
258
|
+
.then(bikeData => {
|
|
259
|
+
this.updateData(this.cyclingData, bikeData);
|
|
260
|
+
this.transformData();
|
|
261
|
+
this.updateBusy = false;
|
|
262
|
+
})
|
|
263
|
+
.catch(err => {
|
|
264
|
+
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
|
|
265
|
+
const { isPedalling, power, pedalRpm, speed, distanceInternal, heartrate, slope } = this.cyclingData;
|
|
266
|
+
this.updateData(this.cyclingData, { isPedalling, power, pedalRpm, speed, distanceInternal, heartrate, slope });
|
|
267
|
+
this.transformData();
|
|
268
|
+
this.updateBusy = false;
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
sendRequests() {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
if (this.requests.length > 0) {
|
|
275
|
+
const processing = [...this.requests];
|
|
276
|
+
const cnt = processing.length;
|
|
277
|
+
processing.forEach((request, idx) => __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
if (cnt > 1 && idx < cnt - 1) {
|
|
279
|
+
this.logEvent({ message: 'ignoring bike update request', request });
|
|
280
|
+
this.requests.shift();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
}));
|
|
284
|
+
const request = processing[0];
|
|
285
|
+
try {
|
|
286
|
+
yield this.sendRequest(request);
|
|
287
|
+
this.requests.shift();
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack, request });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
bikeSync() {
|
|
296
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
+
if (this.paused) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (this.updateBusy || this.requestBusy) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
this.logEvent({ message: 'bikeSync' });
|
|
304
|
+
if (!this.ignoreBike) {
|
|
305
|
+
yield this.sendRequests();
|
|
306
|
+
}
|
|
307
|
+
yield this.update();
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
updateData(prev, bikeData) {
|
|
311
|
+
let data = {};
|
|
312
|
+
data.isPedalling = bikeData.cadence > 0;
|
|
313
|
+
data.power = bikeData.power;
|
|
314
|
+
data.pedalRpm = bikeData.cadence;
|
|
315
|
+
data.speed = bikeData.speed;
|
|
316
|
+
data.heartrate = bikeData.heartrate;
|
|
317
|
+
data.distanceInternal = bikeData.distanceInternal;
|
|
318
|
+
data.gear = bikeData.gear;
|
|
319
|
+
data.time = bikeData.time;
|
|
320
|
+
if (bikeData.slope)
|
|
321
|
+
data.slope = bikeData.slope;
|
|
322
|
+
this.cyclingData = this.getCyclingMode().updateData(data);
|
|
323
|
+
return this.cyclingData;
|
|
324
|
+
}
|
|
325
|
+
transformData() {
|
|
326
|
+
if (this.cyclingData === undefined)
|
|
327
|
+
return;
|
|
328
|
+
let distance = 0;
|
|
329
|
+
if (this.distanceInternal !== undefined && this.cyclingData.distanceInternal !== undefined) {
|
|
330
|
+
distance = this.cyclingData.distanceInternal - this.distanceInternal;
|
|
331
|
+
}
|
|
332
|
+
if (this.cyclingData.distanceInternal !== undefined)
|
|
333
|
+
this.distanceInternal = this.cyclingData.distanceInternal;
|
|
334
|
+
let data = {
|
|
335
|
+
speed: this.cyclingData.speed,
|
|
336
|
+
slope: this.cyclingData.slope,
|
|
337
|
+
power: (0, utils_1.intVal)(this.cyclingData.power),
|
|
338
|
+
cadence: (0, utils_1.intVal)(this.cyclingData.pedalRpm),
|
|
339
|
+
heartrate: (0, utils_1.intVal)(this.cyclingData.heartrate),
|
|
340
|
+
distance,
|
|
341
|
+
timestamp: Date.now(),
|
|
342
|
+
deviceTime: this.cyclingData.time,
|
|
343
|
+
deviceDistanceCounter: this.cyclingData.distanceInternal
|
|
344
|
+
};
|
|
345
|
+
if (this.ignoreHrm)
|
|
346
|
+
delete data.heartrate;
|
|
347
|
+
if (this.ignorePower) {
|
|
348
|
+
delete data.power;
|
|
349
|
+
delete data.cadence;
|
|
350
|
+
}
|
|
351
|
+
if (this.ignoreBike) {
|
|
352
|
+
data = { heartrate: data.heartrate };
|
|
353
|
+
}
|
|
354
|
+
this.deviceData = data;
|
|
355
|
+
}
|
|
356
|
+
sendRequest(request) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
358
|
+
this.requestBusy = true;
|
|
359
|
+
try {
|
|
360
|
+
this.logEvent({ message: 'sendRequest', request });
|
|
361
|
+
const bike = this.getBike();
|
|
362
|
+
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
363
|
+
if (isReset) {
|
|
364
|
+
this.requestBusy = false;
|
|
365
|
+
return {};
|
|
366
|
+
}
|
|
367
|
+
if (request.slope !== undefined) {
|
|
368
|
+
yield bike.setSlope(request.slope);
|
|
369
|
+
}
|
|
370
|
+
if (request.targetPower !== undefined) {
|
|
371
|
+
yield bike.setPower(request.targetPower);
|
|
372
|
+
}
|
|
373
|
+
this.requestBusy = false;
|
|
374
|
+
return request;
|
|
375
|
+
}
|
|
376
|
+
catch (err) {
|
|
377
|
+
this.requestBusy = false;
|
|
378
|
+
this.logEvent({ message: 'sendRequest error', error: err.message || err });
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
refreshRequests() {
|
|
384
|
+
if (!this.cyclingData.isPedalling || this.cyclingData.pedalRpm === 0)
|
|
385
|
+
return;
|
|
386
|
+
let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true }) || {};
|
|
387
|
+
const prev = this.requests[this.requests.length - 1] || {};
|
|
388
|
+
if (bikeRequest.targetPower !== undefined && bikeRequest.targetPower !== prev.targetPower) {
|
|
389
|
+
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
390
|
+
this.requests.push(bikeRequest);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
processClientRequest(request) {
|
|
394
|
+
if (request.slope !== undefined) {
|
|
395
|
+
this.cyclingData.slope = request.slope;
|
|
396
|
+
}
|
|
397
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
398
|
+
let bikeRequest = this.getCyclingMode().sendBikeUpdate(request);
|
|
399
|
+
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
400
|
+
this.requests.push(bikeRequest);
|
|
401
|
+
resolve(bikeRequest);
|
|
402
|
+
}));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
exports.default = DaumAdapterBase;
|