incyclist-devices 1.4.100 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/lib/DeviceSupport.d.ts +36 -34
- package/lib/DeviceSupport.js +82 -78
- 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/adapter-factory.d.ts +11 -0
- package/lib/antv2/adapter-factory.js +40 -0
- package/lib/antv2/ant-binding.d.ts +13 -0
- package/lib/antv2/ant-binding.js +27 -0
- package/lib/antv2/ant-device.d.ts +51 -0
- package/lib/antv2/ant-device.js +115 -0
- package/lib/antv2/ant-interface.d.ts +37 -0
- package/lib/antv2/ant-interface.js +239 -0
- package/lib/antv2/fe.d.ts +28 -0
- package/lib/antv2/fe.js +237 -0
- package/lib/antv2/hr.d.ts +18 -0
- package/lib/antv2/hr.js +93 -0
- package/lib/antv2/incyclist-protocol.d.ts +37 -0
- package/lib/antv2/incyclist-protocol.js +126 -0
- package/lib/antv2/pwr.d.ts +28 -0
- package/lib/antv2/pwr.js +163 -0
- package/lib/antv2/sensor-factory.d.ts +5 -0
- package/lib/antv2/sensor-factory.js +20 -0
- package/lib/ble/ble-device.d.ts +63 -63
- package/lib/ble/ble-device.js +444 -442
- 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 -717
- 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 -102
- 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/fm.d.ts +125 -125
- package/lib/ble/fm.js +745 -739
- 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 +147 -147
- package/lib/ble/pwr.d.ts +89 -89
- package/lib/ble/pwr.js +321 -321
- package/lib/ble/tacx.d.ts +90 -90
- package/lib/ble/tacx.js +731 -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/{CyclingMode.d.ts → cycling-mode.d.ts} +76 -76
- package/lib/{CyclingMode.js → cycling-mode.js} +79 -79
- package/lib/daum/DaumAdapter.d.ts +66 -66
- package/lib/daum/DaumAdapter.js +396 -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 +18 -18
- package/lib/daum/classic/DaumClassicAdapter.js +146 -146
- 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 +64 -64
- package/lib/daum/classic/bike.js +456 -456
- 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 +12 -12
- package/lib/daum/premium/DaumPremiumAdapter.js +131 -131
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +32 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +207 -207
- package/lib/daum/premium/bike.d.ts +123 -123
- package/lib/daum/premium/bike.js +894 -894
- 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 → device.d.ts} +92 -92
- package/lib/{Device.js → 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/{DeviceProtocol.d.ts → protocol.d.ts} +74 -74
- package/lib/{DeviceProtocol.js → protocol.js} +41 -41
- package/lib/{DeviceRegistry.d.ts → registry.d.ts} +8 -8
- package/lib/{DeviceRegistry.js → 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 -46
package/lib/antv2/fe.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
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.logger = new gd_eventlog_1.EventLogger('Ant+FE');
|
|
32
|
+
}
|
|
33
|
+
isBike() { return true; }
|
|
34
|
+
isHrm() { return false; }
|
|
35
|
+
isPower() { return true; }
|
|
36
|
+
getName() {
|
|
37
|
+
const deviceID = this.sensor.getDeviceID();
|
|
38
|
+
return `Ant+FE ${deviceID}`;
|
|
39
|
+
}
|
|
40
|
+
getDisplayName() {
|
|
41
|
+
const { DeviceID, ManId } = this.deviceData;
|
|
42
|
+
return `${(0, utils_1.getBrand)(ManId)} FE ${DeviceID}`;
|
|
43
|
+
}
|
|
44
|
+
getSupportedCyclingModes() {
|
|
45
|
+
return [ant_fe_st_mode_1.default, ant_fe_erg_mode_1.default, ant_fe_adv_st_mode_1.default];
|
|
46
|
+
}
|
|
47
|
+
setCyclingMode(mode, settings) {
|
|
48
|
+
let selectedMode;
|
|
49
|
+
if (typeof mode === 'string') {
|
|
50
|
+
const supported = this.getSupportedCyclingModes();
|
|
51
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
52
|
+
if (CyclingModeClass) {
|
|
53
|
+
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
selectedMode = this.getDefaultCyclingMode();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
selectedMode = mode;
|
|
60
|
+
}
|
|
61
|
+
this.cyclingMode = selectedMode;
|
|
62
|
+
this.cyclingMode.setSettings(settings);
|
|
63
|
+
}
|
|
64
|
+
getCyclingMode() {
|
|
65
|
+
if (!this.cyclingMode)
|
|
66
|
+
this.cyclingMode = this.getDefaultCyclingMode();
|
|
67
|
+
return this.cyclingMode;
|
|
68
|
+
}
|
|
69
|
+
getDefaultCyclingMode() {
|
|
70
|
+
return new ant_fe_st_mode_1.default(this);
|
|
71
|
+
}
|
|
72
|
+
getLogData(data, excludeList) {
|
|
73
|
+
const logData = JSON.parse(JSON.stringify(data));
|
|
74
|
+
excludeList.forEach((key) => {
|
|
75
|
+
delete logData[key];
|
|
76
|
+
});
|
|
77
|
+
return logData;
|
|
78
|
+
}
|
|
79
|
+
sendUpdate(request) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (this.paused)
|
|
82
|
+
return;
|
|
83
|
+
const update = this.getCyclingMode().sendBikeUpdate(request);
|
|
84
|
+
this.logger.logEvent({ message: 'send bike update requested', update, request });
|
|
85
|
+
try {
|
|
86
|
+
const fe = this.sensor;
|
|
87
|
+
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
88
|
+
if (isReset)
|
|
89
|
+
yield fe.sendTrackResistance(0);
|
|
90
|
+
if (update.slope !== undefined) {
|
|
91
|
+
yield fe.sendTrackResistance(update.slope);
|
|
92
|
+
}
|
|
93
|
+
if (update.targetPower !== undefined) {
|
|
94
|
+
yield fe.sendTargetPower(update.targetPower);
|
|
95
|
+
}
|
|
96
|
+
else if (request.maxPower !== undefined) {
|
|
97
|
+
if (this.data.power && this.data.power > request.maxPower)
|
|
98
|
+
yield fe.sendTargetPower(request.maxPower);
|
|
99
|
+
}
|
|
100
|
+
else if (request.minPower !== undefined) {
|
|
101
|
+
if (this.data.power && this.data.power < request.minPower)
|
|
102
|
+
yield fe.sendTargetPower(request.minPower);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
this.logger.logEvent({ message: 'sendBikeUpdate() error', error: err.message });
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
onDeviceData(deviceData) {
|
|
111
|
+
if (!this.started || this.isStopped())
|
|
112
|
+
return;
|
|
113
|
+
this.deviceData = deviceData;
|
|
114
|
+
try {
|
|
115
|
+
if (this.onDataFn && !(this.ignoreHrm && this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
116
|
+
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
117
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
118
|
+
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
119
|
+
let incyclistData = this.mapData(deviceData);
|
|
120
|
+
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
121
|
+
const data = this.transformData(incyclistData);
|
|
122
|
+
this.onDataFn(data);
|
|
123
|
+
this.lastUpdate = Date.now();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
mapData(deviceData) {
|
|
131
|
+
const data = {
|
|
132
|
+
isPedalling: false,
|
|
133
|
+
power: 0,
|
|
134
|
+
pedalRpm: undefined,
|
|
135
|
+
speed: 0,
|
|
136
|
+
heartrate: 0,
|
|
137
|
+
distanceInternal: 0,
|
|
138
|
+
slope: undefined,
|
|
139
|
+
time: undefined
|
|
140
|
+
};
|
|
141
|
+
data.speed = (deviceData.VirtualSpeed !== undefined ? deviceData.VirtualSpeed : (deviceData.RealSpeed || 0)) * 3.6;
|
|
142
|
+
data.slope = (deviceData.Incline !== undefined ? deviceData.Incline : data.slope);
|
|
143
|
+
data.power = (deviceData.InstantaneousPower !== undefined ? deviceData.InstantaneousPower : data.power);
|
|
144
|
+
data.time = (deviceData.ElapsedTime !== undefined ? deviceData.ElapsedTime : data.time);
|
|
145
|
+
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
146
|
+
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
transformData(bikeData) {
|
|
150
|
+
if (bikeData === undefined)
|
|
151
|
+
return;
|
|
152
|
+
let distance = 0;
|
|
153
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
154
|
+
distance = bikeData.distanceInternal - this.distanceInternal;
|
|
155
|
+
}
|
|
156
|
+
if (bikeData.distanceInternal !== undefined)
|
|
157
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
158
|
+
let data = {
|
|
159
|
+
speed: bikeData.speed,
|
|
160
|
+
slope: bikeData.slope,
|
|
161
|
+
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
162
|
+
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
163
|
+
heartrate: bikeData.heartrate !== undefined ? Math.round(bikeData.heartrate) : undefined,
|
|
164
|
+
distance,
|
|
165
|
+
timestamp: Date.now()
|
|
166
|
+
};
|
|
167
|
+
if (this.ignorePower) {
|
|
168
|
+
delete data.power;
|
|
169
|
+
delete data.cadence;
|
|
170
|
+
}
|
|
171
|
+
if (this.ignoreBike) {
|
|
172
|
+
data = { heartrate: data.heartrate };
|
|
173
|
+
}
|
|
174
|
+
if (this.ignoreHrm)
|
|
175
|
+
delete data.heartrate;
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
start(props) {
|
|
179
|
+
const _super = Object.create(null, {
|
|
180
|
+
start: { get: () => super.start }
|
|
181
|
+
});
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
_super.start.call(this, props);
|
|
184
|
+
const opts = props || {};
|
|
185
|
+
const { args = {}, user = {} } = opts;
|
|
186
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const { timeout } = props || {};
|
|
188
|
+
let to;
|
|
189
|
+
if (timeout) {
|
|
190
|
+
to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
yield this.stop();
|
|
192
|
+
reject(new Error(`could not start device, reason:timeout`));
|
|
193
|
+
}), timeout);
|
|
194
|
+
}
|
|
195
|
+
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
196
|
+
if (to)
|
|
197
|
+
clearTimeout(to);
|
|
198
|
+
if (!this.started) {
|
|
199
|
+
return reject(new Error(`could not start device`));
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const fe = this.sensor;
|
|
203
|
+
const mode = this.getCyclingMode();
|
|
204
|
+
const bikeType = mode ? mode.getSetting('bikeType').toLowerCase() : 'race';
|
|
205
|
+
const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : DEFAULT_BIKE_WEIGHT;
|
|
206
|
+
const userWeight = args.userWeight || user.weight || DEFAULT_USER_WEIGHT;
|
|
207
|
+
const bikeWeight = args.bikeWeight || defaultBikeWeight;
|
|
208
|
+
const status = { userSent: false, slopeSent: false };
|
|
209
|
+
let i = 0;
|
|
210
|
+
while (i < 3 && !status.userSent && !status.slopeSent) {
|
|
211
|
+
status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
|
|
212
|
+
status.slopeSent = status.slopeSent || (yield fe.sendTrackResistance(0.0));
|
|
213
|
+
i++;
|
|
214
|
+
}
|
|
215
|
+
if (status.userSent)
|
|
216
|
+
return resolve(true);
|
|
217
|
+
return reject(new Error(`could not start device, reason: could not send commands`));
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
reject(new Error(`could not start device, reason:${error.message}`));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}));
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
stop() {
|
|
227
|
+
const _super = Object.create(null, {
|
|
228
|
+
stop: { get: () => super.stop }
|
|
229
|
+
});
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const stopped = yield this.ant.stopSensor(this.sensor);
|
|
232
|
+
_super.stop.call(this);
|
|
233
|
+
return stopped;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.default = AntFEAdapter;
|
|
@@ -0,0 +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
|
+
}
|
package/lib/antv2/hr.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
class AntHrAdapter extends ant_device_1.default {
|
|
19
|
+
constructor(sensor, protocol) {
|
|
20
|
+
super(sensor, protocol);
|
|
21
|
+
this.started = false;
|
|
22
|
+
this.deviceData = {
|
|
23
|
+
DeviceID: sensor.getDeviceID()
|
|
24
|
+
};
|
|
25
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+Hrm');
|
|
26
|
+
}
|
|
27
|
+
isBike() { return false; }
|
|
28
|
+
isHrm() { return true; }
|
|
29
|
+
isPower() { return false; }
|
|
30
|
+
getName() {
|
|
31
|
+
const deviceID = this.sensor.getDeviceID();
|
|
32
|
+
return `Ant+Hrm ${deviceID}`;
|
|
33
|
+
}
|
|
34
|
+
getDisplayName() {
|
|
35
|
+
const { DeviceID, manID, ComputedHeartRate } = this.deviceData;
|
|
36
|
+
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
37
|
+
return `${(0, utils_1.getBrand)(manID)} Hrm ${DeviceID}${hrmStr}`;
|
|
38
|
+
}
|
|
39
|
+
onDeviceData(deviceData) {
|
|
40
|
+
if (!this.started)
|
|
41
|
+
return;
|
|
42
|
+
this.deviceData = deviceData;
|
|
43
|
+
try {
|
|
44
|
+
if (this.onDataFn && !this.ignoreHrm && !this.paused) {
|
|
45
|
+
if (this.lastUpdate === undefined || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
46
|
+
this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
47
|
+
const data = this.updateData(this.data, deviceData);
|
|
48
|
+
this.onDataFn(data);
|
|
49
|
+
this.lastUpdate = Date.now();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
updateData(data, deviceData) {
|
|
57
|
+
data.heartrate = deviceData.ComputedHeartRate;
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
start(props) {
|
|
61
|
+
const _super = Object.create(null, {
|
|
62
|
+
start: { get: () => super.start }
|
|
63
|
+
});
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
_super.start.call(this, props);
|
|
66
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const { timeout } = props || {};
|
|
68
|
+
let to;
|
|
69
|
+
if (timeout) {
|
|
70
|
+
to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
yield this.stop();
|
|
72
|
+
reject(new Error(`could not start device, reason:timeout`));
|
|
73
|
+
}), timeout);
|
|
74
|
+
}
|
|
75
|
+
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
76
|
+
if (to)
|
|
77
|
+
clearTimeout(to);
|
|
78
|
+
resolve(this.started);
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
stop() {
|
|
83
|
+
const _super = Object.create(null, {
|
|
84
|
+
stop: { get: () => super.stop }
|
|
85
|
+
});
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const stopped = yield this.ant.stopSensor(this.sensor);
|
|
88
|
+
_super.stop.call(this);
|
|
89
|
+
return stopped;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.default = AntHrAdapter;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventLogger } from "gd-eventlog";
|
|
2
|
+
import DeviceProtocolBase, { DeviceProtocol, DeviceSettings, ScanProps } from "../protocol";
|
|
3
|
+
import AntDeviceBinding from './ant-binding';
|
|
4
|
+
import AntAdapter from "./ant-device";
|
|
5
|
+
import AntInterface from "./ant-interface";
|
|
6
|
+
export declare const mapAntProfile: (antProfile: any) => "SmartTrainer" | "Heartrate Monitor" | "Power Meter";
|
|
7
|
+
export declare const mapIncyclistProfile: (incyclistProfile: any) => "PWR" | "HR" | "FE";
|
|
8
|
+
export interface AntDeviceSettings extends DeviceSettings {
|
|
9
|
+
deviceID?: string;
|
|
10
|
+
profile: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AntScanProps extends ScanProps {
|
|
13
|
+
timeout?: number;
|
|
14
|
+
profiles?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface AntScannerProps {
|
|
17
|
+
timeout?: number;
|
|
18
|
+
profiles?: string[];
|
|
19
|
+
}
|
|
20
|
+
export default class AntProtocol extends DeviceProtocolBase implements DeviceProtocol {
|
|
21
|
+
logger: EventLogger;
|
|
22
|
+
ant: AntInterface;
|
|
23
|
+
binding: typeof AntDeviceBinding;
|
|
24
|
+
getAnt(): AntInterface;
|
|
25
|
+
constructor();
|
|
26
|
+
logEvent(event: any): void;
|
|
27
|
+
scan(props: AntScanProps): Promise<void>;
|
|
28
|
+
stopScan(): Promise<void>;
|
|
29
|
+
isScanning(): boolean;
|
|
30
|
+
createDevice(request: AntDeviceSettings | AntAdapter): AntAdapter;
|
|
31
|
+
add(settings: AntDeviceSettings): AntAdapter;
|
|
32
|
+
getName(): string;
|
|
33
|
+
getInterfaces(): Array<string>;
|
|
34
|
+
isBike(): boolean;
|
|
35
|
+
isHrm(): boolean;
|
|
36
|
+
isPower(): boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
exports.mapIncyclistProfile = exports.mapAntProfile = void 0;
|
|
35
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
36
|
+
const protocol_1 = __importStar(require("../protocol"));
|
|
37
|
+
const registry_1 = __importDefault(require("../registry"));
|
|
38
|
+
const adapter_factory_1 = __importDefault(require("./adapter-factory"));
|
|
39
|
+
const ant_device_1 = __importDefault(require("./ant-device"));
|
|
40
|
+
const ant_interface_1 = __importDefault(require("./ant-interface"));
|
|
41
|
+
const mapAntProfile = (antProfile) => {
|
|
42
|
+
switch (antProfile) {
|
|
43
|
+
case 'HR': return 'Heartrate Monitor';
|
|
44
|
+
case 'PWR': return 'Power Meter';
|
|
45
|
+
case 'FE': return 'SmartTrainer';
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.mapAntProfile = mapAntProfile;
|
|
49
|
+
const mapIncyclistProfile = (incyclistProfile) => {
|
|
50
|
+
switch (incyclistProfile) {
|
|
51
|
+
case 'Heartrate Monitor': return 'HR';
|
|
52
|
+
case 'Power Meter': return 'PWR';
|
|
53
|
+
case 'SmartTrainer': return 'FE';
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.mapIncyclistProfile = mapIncyclistProfile;
|
|
57
|
+
class AntProtocol extends protocol_1.default {
|
|
58
|
+
constructor() {
|
|
59
|
+
super();
|
|
60
|
+
}
|
|
61
|
+
getAnt() {
|
|
62
|
+
if (this.ant)
|
|
63
|
+
return this.ant;
|
|
64
|
+
this.ant = ant_interface_1.default.getInstance();
|
|
65
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+');
|
|
66
|
+
return this.ant;
|
|
67
|
+
}
|
|
68
|
+
logEvent(event) {
|
|
69
|
+
if (!this.logger)
|
|
70
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+');
|
|
71
|
+
if (this.logger)
|
|
72
|
+
this.logger.logEvent(event);
|
|
73
|
+
}
|
|
74
|
+
scan(props) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const { id, onDeviceFound, onScanFinished } = props || {};
|
|
77
|
+
const ant = this.getAnt();
|
|
78
|
+
ant.on('detected', (profile, deviceID) => {
|
|
79
|
+
console.log('detected', profile, deviceID);
|
|
80
|
+
if (onDeviceFound) {
|
|
81
|
+
const detected = { profile, deviceID };
|
|
82
|
+
const device = adapter_factory_1.default.create({ detected }, this);
|
|
83
|
+
onDeviceFound(device, this);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
this.logEvent({ message: 'scan' });
|
|
87
|
+
yield ant.scan(props);
|
|
88
|
+
if (onScanFinished) {
|
|
89
|
+
onScanFinished(id);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
stopScan() {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const ant = this.getAnt();
|
|
96
|
+
yield ant.stopScan();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
isScanning() {
|
|
100
|
+
const ant = this.getAnt();
|
|
101
|
+
return ant.isScanning();
|
|
102
|
+
}
|
|
103
|
+
createDevice(request) {
|
|
104
|
+
const fromAdapter = request instanceof ant_device_1.default;
|
|
105
|
+
let device = undefined;
|
|
106
|
+
if (fromAdapter)
|
|
107
|
+
device = request;
|
|
108
|
+
else {
|
|
109
|
+
device = adapter_factory_1.default.create({ configuration: request }, this);
|
|
110
|
+
}
|
|
111
|
+
return device;
|
|
112
|
+
}
|
|
113
|
+
add(settings) {
|
|
114
|
+
this.logEvent({ message: 'adding device', settings });
|
|
115
|
+
const device = this.createDevice(settings);
|
|
116
|
+
this.devices.push(device);
|
|
117
|
+
return device;
|
|
118
|
+
}
|
|
119
|
+
getName() { return 'Ant'; }
|
|
120
|
+
getInterfaces() { return [protocol_1.INTERFACE.ANT]; }
|
|
121
|
+
isBike() { return true; }
|
|
122
|
+
isHrm() { return true; }
|
|
123
|
+
isPower() { return true; }
|
|
124
|
+
}
|
|
125
|
+
exports.default = AntProtocol;
|
|
126
|
+
registry_1.default.register(new AntProtocol());
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import CyclingMode, { IncyclistBikeData } from '../cycling-mode';
|
|
6
|
+
import { DeviceData } from "../device";
|
|
7
|
+
export default class AntPwrAdapter extends AntAdapter {
|
|
8
|
+
protected started: boolean;
|
|
9
|
+
protected logger: EventLogger;
|
|
10
|
+
protected mode: CyclingMode;
|
|
11
|
+
protected distanceInternal?: number;
|
|
12
|
+
constructor(sensor: ISensor, protocol: AntProtocol);
|
|
13
|
+
isBike(): boolean;
|
|
14
|
+
isHrm(): boolean;
|
|
15
|
+
isPower(): boolean;
|
|
16
|
+
getName(): string;
|
|
17
|
+
getDisplayName(): string;
|
|
18
|
+
getCyclingMode(): CyclingMode;
|
|
19
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
20
|
+
getSupportedCyclingModes(): any[];
|
|
21
|
+
getLogData(data: any, excludeList: any): any;
|
|
22
|
+
onDeviceData(deviceData: any): void;
|
|
23
|
+
sendUpdate(request: any): void;
|
|
24
|
+
mapData(deviceData: any): IncyclistBikeData;
|
|
25
|
+
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
26
|
+
start(props?: any): Promise<any>;
|
|
27
|
+
stop(): Promise<boolean>;
|
|
28
|
+
}
|