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/antv2/fe.js
CHANGED
|
@@ -1,262 +1,262 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const ant_device_1 = __importDefault(require("./ant-device"));
|
|
16
|
-
const utils_1 = require("../ant/utils");
|
|
17
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
18
|
-
const ant_fe_st_mode_1 = __importDefault(require("../ant/antfe/ant-fe-st-mode"));
|
|
19
|
-
const ant_fe_erg_mode_1 = __importDefault(require("../ant/antfe/ant-fe-erg-mode"));
|
|
20
|
-
const ant_fe_adv_st_mode_1 = __importDefault(require("../ant/antfe/ant-fe-adv-st-mode"));
|
|
21
|
-
const DEFAULT_USER_WEIGHT = 75;
|
|
22
|
-
const DEFAULT_BIKE_WEIGHT = 10;
|
|
23
|
-
const DEFAULT_BIKE_WEIGHT_MOUNTAIN = 14.5;
|
|
24
|
-
class AntFEAdapter extends ant_device_1.default {
|
|
25
|
-
constructor(sensor, protocol) {
|
|
26
|
-
super(sensor, protocol);
|
|
27
|
-
this.started = false;
|
|
28
|
-
this.deviceData = {
|
|
29
|
-
DeviceID: sensor.getDeviceID()
|
|
30
|
-
};
|
|
31
|
-
this.msgCount = 0;
|
|
32
|
-
this.logger = new gd_eventlog_1.EventLogger('Ant+FE');
|
|
33
|
-
}
|
|
34
|
-
isBike() { return true; }
|
|
35
|
-
isHrm() { return false; }
|
|
36
|
-
isPower() { return true; }
|
|
37
|
-
getName() {
|
|
38
|
-
const deviceID = this.sensor.getDeviceID();
|
|
39
|
-
return `Ant+FE ${deviceID}`;
|
|
40
|
-
}
|
|
41
|
-
getDisplayName() {
|
|
42
|
-
const { DeviceID, ManId } = this.deviceData;
|
|
43
|
-
return `${(0, utils_1.getBrand)(ManId)} FE ${DeviceID}`;
|
|
44
|
-
}
|
|
45
|
-
getSupportedCyclingModes() {
|
|
46
|
-
return [ant_fe_st_mode_1.default, ant_fe_erg_mode_1.default, ant_fe_adv_st_mode_1.default];
|
|
47
|
-
}
|
|
48
|
-
setCyclingMode(mode, settings) {
|
|
49
|
-
let selectedMode;
|
|
50
|
-
if (typeof mode === 'string') {
|
|
51
|
-
const supported = this.getSupportedCyclingModes();
|
|
52
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
53
|
-
if (CyclingModeClass) {
|
|
54
|
-
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
selectedMode = this.getDefaultCyclingMode();
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
selectedMode = mode;
|
|
61
|
-
}
|
|
62
|
-
this.cyclingMode = selectedMode;
|
|
63
|
-
this.cyclingMode.setSettings(settings);
|
|
64
|
-
}
|
|
65
|
-
getCyclingMode() {
|
|
66
|
-
if (!this.cyclingMode)
|
|
67
|
-
this.cyclingMode = this.getDefaultCyclingMode();
|
|
68
|
-
return this.cyclingMode;
|
|
69
|
-
}
|
|
70
|
-
getDefaultCyclingMode() {
|
|
71
|
-
return new ant_fe_st_mode_1.default(this);
|
|
72
|
-
}
|
|
73
|
-
getLogData(data, excludeList) {
|
|
74
|
-
const logData = JSON.parse(JSON.stringify(data));
|
|
75
|
-
excludeList.forEach((key) => {
|
|
76
|
-
delete logData[key];
|
|
77
|
-
});
|
|
78
|
-
return logData;
|
|
79
|
-
}
|
|
80
|
-
sendUpdate(request) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
if (this.paused)
|
|
83
|
-
return;
|
|
84
|
-
const update = this.getCyclingMode().sendBikeUpdate(request);
|
|
85
|
-
this.logger.logEvent({ message: 'send bike update requested', update, request });
|
|
86
|
-
try {
|
|
87
|
-
const fe = this.sensor;
|
|
88
|
-
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
89
|
-
if (isReset)
|
|
90
|
-
yield fe.sendTrackResistance(0);
|
|
91
|
-
if (update.slope !== undefined) {
|
|
92
|
-
yield fe.sendTrackResistance(update.slope);
|
|
93
|
-
}
|
|
94
|
-
if (update.targetPower !== undefined) {
|
|
95
|
-
yield fe.sendTargetPower(update.targetPower);
|
|
96
|
-
}
|
|
97
|
-
else if (request.maxPower !== undefined) {
|
|
98
|
-
if (this.data.power && this.data.power > request.maxPower)
|
|
99
|
-
yield fe.sendTargetPower(request.maxPower);
|
|
100
|
-
}
|
|
101
|
-
else if (request.minPower !== undefined) {
|
|
102
|
-
if (this.data.power && this.data.power < request.minPower)
|
|
103
|
-
yield fe.sendTargetPower(request.minPower);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
this.logger.logEvent({ message: 'sendBikeUpdate() error', error: err.message });
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
onDeviceData(deviceData) {
|
|
112
|
-
if (!this.started || this.isStopped())
|
|
113
|
-
return;
|
|
114
|
-
this.deviceData = deviceData;
|
|
115
|
-
try {
|
|
116
|
-
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
117
|
-
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
118
|
-
if (this.onDataFn && !(this.ignoreHrm && this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
119
|
-
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
120
|
-
let incyclistData = this.mapData(deviceData);
|
|
121
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
122
|
-
const data = this.transformData(incyclistData);
|
|
123
|
-
this.onDataFn(data);
|
|
124
|
-
this.lastUpdate = Date.now();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
this.logger.logEvent({ message: 'error', fn: 'onDeviceData()', error: err.message || err, stack: err.stack });
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
mapData(deviceData) {
|
|
133
|
-
const data = {
|
|
134
|
-
isPedalling: false,
|
|
135
|
-
power: 0,
|
|
136
|
-
pedalRpm: undefined,
|
|
137
|
-
speed: 0,
|
|
138
|
-
heartrate: 0,
|
|
139
|
-
distanceInternal: 0,
|
|
140
|
-
slope: undefined,
|
|
141
|
-
time: undefined
|
|
142
|
-
};
|
|
143
|
-
data.speed = (deviceData.VirtualSpeed !== undefined ? deviceData.VirtualSpeed : (deviceData.RealSpeed || 0)) * 3.6;
|
|
144
|
-
data.slope = (deviceData.Incline !== undefined ? deviceData.Incline : data.slope);
|
|
145
|
-
data.power = (deviceData.InstantaneousPower !== undefined ? deviceData.InstantaneousPower : data.power);
|
|
146
|
-
data.time = (deviceData.ElapsedTime !== undefined ? deviceData.ElapsedTime : data.time);
|
|
147
|
-
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
148
|
-
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
149
|
-
return data;
|
|
150
|
-
}
|
|
151
|
-
transformData(bikeData) {
|
|
152
|
-
if (bikeData === undefined)
|
|
153
|
-
return;
|
|
154
|
-
let distance = 0;
|
|
155
|
-
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
156
|
-
distance = bikeData.distanceInternal - this.distanceInternal;
|
|
157
|
-
}
|
|
158
|
-
if (bikeData.distanceInternal !== undefined)
|
|
159
|
-
this.distanceInternal = bikeData.distanceInternal;
|
|
160
|
-
let data = {
|
|
161
|
-
speed: bikeData.speed,
|
|
162
|
-
slope: bikeData.slope,
|
|
163
|
-
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
164
|
-
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
165
|
-
heartrate: bikeData.heartrate !== undefined ? Math.round(bikeData.heartrate) : undefined,
|
|
166
|
-
distance,
|
|
167
|
-
timestamp: Date.now()
|
|
168
|
-
};
|
|
169
|
-
if (this.ignorePower) {
|
|
170
|
-
delete data.power;
|
|
171
|
-
delete data.cadence;
|
|
172
|
-
}
|
|
173
|
-
if (this.ignoreBike) {
|
|
174
|
-
data = { heartrate: data.heartrate };
|
|
175
|
-
}
|
|
176
|
-
if (this.ignoreHrm || !this.isHrm())
|
|
177
|
-
delete data.heartrate;
|
|
178
|
-
return data;
|
|
179
|
-
}
|
|
180
|
-
start(props) {
|
|
181
|
-
const _super = Object.create(null, {
|
|
182
|
-
start: { get: () => super.start }
|
|
183
|
-
});
|
|
184
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
_super.start.call(this, props);
|
|
186
|
-
this.logger.logEvent({ message: 'start', props });
|
|
187
|
-
this.msgCount = 0;
|
|
188
|
-
const opts = props || {};
|
|
189
|
-
const { args = {}, user = {} } = opts;
|
|
190
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
const { timeout = 20000 } = props || {};
|
|
192
|
-
let start = Date.now();
|
|
193
|
-
let startTimeout = start + timeout;
|
|
194
|
-
const status = { userSent: false, slopeSent: false };
|
|
195
|
-
let iv;
|
|
196
|
-
const stopInterval = () => {
|
|
197
|
-
if (iv)
|
|
198
|
-
clearInterval(iv);
|
|
199
|
-
iv = undefined;
|
|
200
|
-
};
|
|
201
|
-
if (timeout) {
|
|
202
|
-
iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
if (Date.now() > startTimeout) {
|
|
204
|
-
stopInterval();
|
|
205
|
-
yield this.stop();
|
|
206
|
-
reject(new Error(`could not start device, reason:timeout`));
|
|
207
|
-
}
|
|
208
|
-
if (this.started && this.msgCount > 1 && status.userSent) {
|
|
209
|
-
this.logger.logEvent({ message: 'start success' });
|
|
210
|
-
stopInterval();
|
|
211
|
-
}
|
|
212
|
-
}), 100);
|
|
213
|
-
}
|
|
214
|
-
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
215
|
-
if (!this.started) {
|
|
216
|
-
stopInterval();
|
|
217
|
-
this.stop();
|
|
218
|
-
return reject(new Error(`could not start device`));
|
|
219
|
-
}
|
|
220
|
-
try {
|
|
221
|
-
const fe = this.sensor;
|
|
222
|
-
const mode = this.getCyclingMode();
|
|
223
|
-
const bikeType = mode ? mode.getSetting('bikeType').toLowerCase() : 'race';
|
|
224
|
-
const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : DEFAULT_BIKE_WEIGHT;
|
|
225
|
-
const userWeight = args.userWeight || user.weight || DEFAULT_USER_WEIGHT;
|
|
226
|
-
const bikeWeight = args.bikeWeight || defaultBikeWeight;
|
|
227
|
-
let i = 0;
|
|
228
|
-
while (i < 3 && (!status.userSent || !status.slopeSent)) {
|
|
229
|
-
if (!timeout || iv)
|
|
230
|
-
status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
|
|
231
|
-
if (!timeout || iv)
|
|
232
|
-
status.slopeSent = status.slopeSent || (yield fe.sendTrackResistance(0.0));
|
|
233
|
-
i++;
|
|
234
|
-
}
|
|
235
|
-
stopInterval();
|
|
236
|
-
if (status.userSent) {
|
|
237
|
-
this.logger.logEvent({ message: 'start success' });
|
|
238
|
-
return resolve(true);
|
|
239
|
-
}
|
|
240
|
-
this.logger.logEvent({ message: 'start failure' });
|
|
241
|
-
this.stop();
|
|
242
|
-
return reject(new Error(`could not start device, reason: could not send commands`));
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
reject(new Error(`could not start device, reason:${error.message}`));
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
}));
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
stop() {
|
|
252
|
-
const _super = Object.create(null, {
|
|
253
|
-
stop: { get: () => super.stop }
|
|
254
|
-
});
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
const stopped = yield this.ant.stopSensor(this.sensor);
|
|
257
|
-
_super.stop.call(this);
|
|
258
|
-
return stopped;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
exports.default = AntFEAdapter;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ant_device_1 = __importDefault(require("./ant-device"));
|
|
16
|
+
const utils_1 = require("../ant/utils");
|
|
17
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
18
|
+
const ant_fe_st_mode_1 = __importDefault(require("../ant/antfe/ant-fe-st-mode"));
|
|
19
|
+
const ant_fe_erg_mode_1 = __importDefault(require("../ant/antfe/ant-fe-erg-mode"));
|
|
20
|
+
const ant_fe_adv_st_mode_1 = __importDefault(require("../ant/antfe/ant-fe-adv-st-mode"));
|
|
21
|
+
const DEFAULT_USER_WEIGHT = 75;
|
|
22
|
+
const DEFAULT_BIKE_WEIGHT = 10;
|
|
23
|
+
const DEFAULT_BIKE_WEIGHT_MOUNTAIN = 14.5;
|
|
24
|
+
class AntFEAdapter extends ant_device_1.default {
|
|
25
|
+
constructor(sensor, protocol) {
|
|
26
|
+
super(sensor, protocol);
|
|
27
|
+
this.started = false;
|
|
28
|
+
this.deviceData = {
|
|
29
|
+
DeviceID: sensor.getDeviceID()
|
|
30
|
+
};
|
|
31
|
+
this.msgCount = 0;
|
|
32
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+FE');
|
|
33
|
+
}
|
|
34
|
+
isBike() { return true; }
|
|
35
|
+
isHrm() { return false; }
|
|
36
|
+
isPower() { return true; }
|
|
37
|
+
getName() {
|
|
38
|
+
const deviceID = this.sensor.getDeviceID();
|
|
39
|
+
return `Ant+FE ${deviceID}`;
|
|
40
|
+
}
|
|
41
|
+
getDisplayName() {
|
|
42
|
+
const { DeviceID, ManId } = this.deviceData;
|
|
43
|
+
return `${(0, utils_1.getBrand)(ManId)} FE ${DeviceID}`;
|
|
44
|
+
}
|
|
45
|
+
getSupportedCyclingModes() {
|
|
46
|
+
return [ant_fe_st_mode_1.default, ant_fe_erg_mode_1.default, ant_fe_adv_st_mode_1.default];
|
|
47
|
+
}
|
|
48
|
+
setCyclingMode(mode, settings) {
|
|
49
|
+
let selectedMode;
|
|
50
|
+
if (typeof mode === 'string') {
|
|
51
|
+
const supported = this.getSupportedCyclingModes();
|
|
52
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
53
|
+
if (CyclingModeClass) {
|
|
54
|
+
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
selectedMode = this.getDefaultCyclingMode();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
selectedMode = mode;
|
|
61
|
+
}
|
|
62
|
+
this.cyclingMode = selectedMode;
|
|
63
|
+
this.cyclingMode.setSettings(settings);
|
|
64
|
+
}
|
|
65
|
+
getCyclingMode() {
|
|
66
|
+
if (!this.cyclingMode)
|
|
67
|
+
this.cyclingMode = this.getDefaultCyclingMode();
|
|
68
|
+
return this.cyclingMode;
|
|
69
|
+
}
|
|
70
|
+
getDefaultCyclingMode() {
|
|
71
|
+
return new ant_fe_st_mode_1.default(this);
|
|
72
|
+
}
|
|
73
|
+
getLogData(data, excludeList) {
|
|
74
|
+
const logData = JSON.parse(JSON.stringify(data));
|
|
75
|
+
excludeList.forEach((key) => {
|
|
76
|
+
delete logData[key];
|
|
77
|
+
});
|
|
78
|
+
return logData;
|
|
79
|
+
}
|
|
80
|
+
sendUpdate(request) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (this.paused)
|
|
83
|
+
return;
|
|
84
|
+
const update = this.getCyclingMode().sendBikeUpdate(request);
|
|
85
|
+
this.logger.logEvent({ message: 'send bike update requested', update, request });
|
|
86
|
+
try {
|
|
87
|
+
const fe = this.sensor;
|
|
88
|
+
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
89
|
+
if (isReset)
|
|
90
|
+
yield fe.sendTrackResistance(0);
|
|
91
|
+
if (update.slope !== undefined) {
|
|
92
|
+
yield fe.sendTrackResistance(update.slope);
|
|
93
|
+
}
|
|
94
|
+
if (update.targetPower !== undefined) {
|
|
95
|
+
yield fe.sendTargetPower(update.targetPower);
|
|
96
|
+
}
|
|
97
|
+
else if (request.maxPower !== undefined) {
|
|
98
|
+
if (this.data.power && this.data.power > request.maxPower)
|
|
99
|
+
yield fe.sendTargetPower(request.maxPower);
|
|
100
|
+
}
|
|
101
|
+
else if (request.minPower !== undefined) {
|
|
102
|
+
if (this.data.power && this.data.power < request.minPower)
|
|
103
|
+
yield fe.sendTargetPower(request.minPower);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
this.logger.logEvent({ message: 'sendBikeUpdate() error', error: err.message });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
onDeviceData(deviceData) {
|
|
112
|
+
if (!this.started || this.isStopped())
|
|
113
|
+
return;
|
|
114
|
+
this.deviceData = deviceData;
|
|
115
|
+
try {
|
|
116
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
117
|
+
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
118
|
+
if (this.onDataFn && !(this.ignoreHrm && this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
119
|
+
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
120
|
+
let incyclistData = this.mapData(deviceData);
|
|
121
|
+
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
122
|
+
const data = this.transformData(incyclistData);
|
|
123
|
+
this.onDataFn(data);
|
|
124
|
+
this.lastUpdate = Date.now();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
this.logger.logEvent({ message: 'error', fn: 'onDeviceData()', error: err.message || err, stack: err.stack });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
mapData(deviceData) {
|
|
133
|
+
const data = {
|
|
134
|
+
isPedalling: false,
|
|
135
|
+
power: 0,
|
|
136
|
+
pedalRpm: undefined,
|
|
137
|
+
speed: 0,
|
|
138
|
+
heartrate: 0,
|
|
139
|
+
distanceInternal: 0,
|
|
140
|
+
slope: undefined,
|
|
141
|
+
time: undefined
|
|
142
|
+
};
|
|
143
|
+
data.speed = (deviceData.VirtualSpeed !== undefined ? deviceData.VirtualSpeed : (deviceData.RealSpeed || 0)) * 3.6;
|
|
144
|
+
data.slope = (deviceData.Incline !== undefined ? deviceData.Incline : data.slope);
|
|
145
|
+
data.power = (deviceData.InstantaneousPower !== undefined ? deviceData.InstantaneousPower : data.power);
|
|
146
|
+
data.time = (deviceData.ElapsedTime !== undefined ? deviceData.ElapsedTime : data.time);
|
|
147
|
+
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
148
|
+
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
149
|
+
return data;
|
|
150
|
+
}
|
|
151
|
+
transformData(bikeData) {
|
|
152
|
+
if (bikeData === undefined)
|
|
153
|
+
return;
|
|
154
|
+
let distance = 0;
|
|
155
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
156
|
+
distance = bikeData.distanceInternal - this.distanceInternal;
|
|
157
|
+
}
|
|
158
|
+
if (bikeData.distanceInternal !== undefined)
|
|
159
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
160
|
+
let data = {
|
|
161
|
+
speed: bikeData.speed,
|
|
162
|
+
slope: bikeData.slope,
|
|
163
|
+
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
164
|
+
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
165
|
+
heartrate: bikeData.heartrate !== undefined ? Math.round(bikeData.heartrate) : undefined,
|
|
166
|
+
distance,
|
|
167
|
+
timestamp: Date.now()
|
|
168
|
+
};
|
|
169
|
+
if (this.ignorePower) {
|
|
170
|
+
delete data.power;
|
|
171
|
+
delete data.cadence;
|
|
172
|
+
}
|
|
173
|
+
if (this.ignoreBike) {
|
|
174
|
+
data = { heartrate: data.heartrate };
|
|
175
|
+
}
|
|
176
|
+
if (this.ignoreHrm || !this.isHrm())
|
|
177
|
+
delete data.heartrate;
|
|
178
|
+
return data;
|
|
179
|
+
}
|
|
180
|
+
start(props) {
|
|
181
|
+
const _super = Object.create(null, {
|
|
182
|
+
start: { get: () => super.start }
|
|
183
|
+
});
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
_super.start.call(this, props);
|
|
186
|
+
this.logger.logEvent({ message: 'start', props });
|
|
187
|
+
this.msgCount = 0;
|
|
188
|
+
const opts = props || {};
|
|
189
|
+
const { args = {}, user = {} } = opts;
|
|
190
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const { timeout = 20000 } = props || {};
|
|
192
|
+
let start = Date.now();
|
|
193
|
+
let startTimeout = start + timeout;
|
|
194
|
+
const status = { userSent: false, slopeSent: false };
|
|
195
|
+
let iv;
|
|
196
|
+
const stopInterval = () => {
|
|
197
|
+
if (iv)
|
|
198
|
+
clearInterval(iv);
|
|
199
|
+
iv = undefined;
|
|
200
|
+
};
|
|
201
|
+
if (timeout) {
|
|
202
|
+
iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
if (Date.now() > startTimeout) {
|
|
204
|
+
stopInterval();
|
|
205
|
+
yield this.stop();
|
|
206
|
+
reject(new Error(`could not start device, reason:timeout`));
|
|
207
|
+
}
|
|
208
|
+
if (this.started && this.msgCount > 1 && status.userSent) {
|
|
209
|
+
this.logger.logEvent({ message: 'start success' });
|
|
210
|
+
stopInterval();
|
|
211
|
+
}
|
|
212
|
+
}), 100);
|
|
213
|
+
}
|
|
214
|
+
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
215
|
+
if (!this.started) {
|
|
216
|
+
stopInterval();
|
|
217
|
+
this.stop();
|
|
218
|
+
return reject(new Error(`could not start device`));
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const fe = this.sensor;
|
|
222
|
+
const mode = this.getCyclingMode();
|
|
223
|
+
const bikeType = mode ? mode.getSetting('bikeType').toLowerCase() : 'race';
|
|
224
|
+
const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : DEFAULT_BIKE_WEIGHT;
|
|
225
|
+
const userWeight = args.userWeight || user.weight || DEFAULT_USER_WEIGHT;
|
|
226
|
+
const bikeWeight = args.bikeWeight || defaultBikeWeight;
|
|
227
|
+
let i = 0;
|
|
228
|
+
while (i < 3 && (!status.userSent || !status.slopeSent)) {
|
|
229
|
+
if (!timeout || iv)
|
|
230
|
+
status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
|
|
231
|
+
if (!timeout || iv)
|
|
232
|
+
status.slopeSent = status.slopeSent || (yield fe.sendTrackResistance(0.0));
|
|
233
|
+
i++;
|
|
234
|
+
}
|
|
235
|
+
stopInterval();
|
|
236
|
+
if (status.userSent) {
|
|
237
|
+
this.logger.logEvent({ message: 'start success' });
|
|
238
|
+
return resolve(true);
|
|
239
|
+
}
|
|
240
|
+
this.logger.logEvent({ message: 'start failure' });
|
|
241
|
+
this.stop();
|
|
242
|
+
return reject(new Error(`could not start device, reason: could not send commands`));
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
reject(new Error(`could not start device, reason:${error.message}`));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
}));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
stop() {
|
|
252
|
+
const _super = Object.create(null, {
|
|
253
|
+
stop: { get: () => super.stop }
|
|
254
|
+
});
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
const stopped = yield this.ant.stopSensor(this.sensor);
|
|
257
|
+
_super.stop.call(this);
|
|
258
|
+
return stopped;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.default = AntFEAdapter;
|
package/lib/antv2/hr.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ISensor } from "incyclist-ant-plus";
|
|
2
|
-
import AntAdapter from "./ant-device";
|
|
3
|
-
import AntProtocol from "./incyclist-protocol";
|
|
4
|
-
import { EventLogger } from "gd-eventlog";
|
|
5
|
-
export default class AntHrAdapter extends AntAdapter {
|
|
6
|
-
protected started: boolean;
|
|
7
|
-
protected logger: EventLogger;
|
|
8
|
-
constructor(sensor: ISensor, protocol: AntProtocol);
|
|
9
|
-
isBike(): boolean;
|
|
10
|
-
isHrm(): boolean;
|
|
11
|
-
isPower(): boolean;
|
|
12
|
-
getName(): string;
|
|
13
|
-
getDisplayName(): string;
|
|
14
|
-
onDeviceData(deviceData: any): void;
|
|
15
|
-
updateData(data: any, deviceData: any): any;
|
|
16
|
-
start(props?: any): Promise<any>;
|
|
17
|
-
stop(): Promise<boolean>;
|
|
18
|
-
}
|
|
1
|
+
import { ISensor } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "./ant-device";
|
|
3
|
+
import AntProtocol from "./incyclist-protocol";
|
|
4
|
+
import { EventLogger } from "gd-eventlog";
|
|
5
|
+
export default class AntHrAdapter extends AntAdapter {
|
|
6
|
+
protected started: boolean;
|
|
7
|
+
protected logger: EventLogger;
|
|
8
|
+
constructor(sensor: ISensor, protocol: AntProtocol);
|
|
9
|
+
isBike(): boolean;
|
|
10
|
+
isHrm(): boolean;
|
|
11
|
+
isPower(): boolean;
|
|
12
|
+
getName(): string;
|
|
13
|
+
getDisplayName(): string;
|
|
14
|
+
onDeviceData(deviceData: any): void;
|
|
15
|
+
updateData(data: any, deviceData: any): any;
|
|
16
|
+
start(props?: any): Promise<any>;
|
|
17
|
+
stop(): Promise<boolean>;
|
|
18
|
+
}
|