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/ble/pwr.js
CHANGED
|
@@ -1,321 +1,321 @@
|
|
|
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.PwrAdapter = void 0;
|
|
35
|
-
const ble_device_1 = require("./ble-device");
|
|
36
|
-
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
37
|
-
const ble_1 = require("./ble");
|
|
38
|
-
const
|
|
39
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
40
|
-
const consts_1 = require("./consts");
|
|
41
|
-
const power_meter_1 = __importDefault(require("../modes/power-meter"));
|
|
42
|
-
class BleCyclingPowerDevice extends ble_device_1.BleDevice {
|
|
43
|
-
constructor(props) {
|
|
44
|
-
super(props);
|
|
45
|
-
this.instantaneousPower = undefined;
|
|
46
|
-
this.balance = undefined;
|
|
47
|
-
this.accTorque = undefined;
|
|
48
|
-
this.rpm = undefined;
|
|
49
|
-
this.timeOffset = 0;
|
|
50
|
-
this.time = undefined;
|
|
51
|
-
this.currentCrankData = undefined;
|
|
52
|
-
this.prevCrankData = undefined;
|
|
53
|
-
}
|
|
54
|
-
isMatching(characteristics) {
|
|
55
|
-
if (!characteristics)
|
|
56
|
-
return false;
|
|
57
|
-
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
58
|
-
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
59
|
-
return hasCPMeasurement && hasCPFeature;
|
|
60
|
-
}
|
|
61
|
-
init() {
|
|
62
|
-
const _super = Object.create(null, {
|
|
63
|
-
init: { get: () => super.init }
|
|
64
|
-
});
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
try {
|
|
67
|
-
yield _super.init.call(this);
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
return Promise.resolve(false);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
getProfile() {
|
|
75
|
-
return 'Power Meter';
|
|
76
|
-
}
|
|
77
|
-
getServiceUUids() {
|
|
78
|
-
return BleCyclingPowerDevice.services;
|
|
79
|
-
}
|
|
80
|
-
parseCrankData(crankData) {
|
|
81
|
-
if (!this.prevCrankData)
|
|
82
|
-
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
83
|
-
const c = this.currentCrankData = crankData;
|
|
84
|
-
const p = this.prevCrankData;
|
|
85
|
-
let rpm = this.rpm;
|
|
86
|
-
let hasUpdate = c.time !== p.time;
|
|
87
|
-
if (hasUpdate) {
|
|
88
|
-
let time = c.time - p.time;
|
|
89
|
-
let revs = c.revolutions - p.revolutions;
|
|
90
|
-
if (c.time < p.time) {
|
|
91
|
-
time += 0x10000;
|
|
92
|
-
this.timeOffset += 0x10000;
|
|
93
|
-
}
|
|
94
|
-
if (c.revolutions < p.revolutions)
|
|
95
|
-
revs += 0x10000;
|
|
96
|
-
rpm = 1024 * 60 * revs / time;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
100
|
-
rpm = 0;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const cntUpdateMissing = p.cntUpdateMissing;
|
|
104
|
-
this.prevCrankData = this.currentCrankData;
|
|
105
|
-
if (hasUpdate)
|
|
106
|
-
this.prevCrankData.cntUpdateMissing = 0;
|
|
107
|
-
else
|
|
108
|
-
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
109
|
-
return { rpm, time: this.timeOffset + c.time };
|
|
110
|
-
}
|
|
111
|
-
parsePower(_data) {
|
|
112
|
-
const data = Buffer.from(_data);
|
|
113
|
-
try {
|
|
114
|
-
let offset = 4;
|
|
115
|
-
const flags = data.readUInt16LE(0);
|
|
116
|
-
this.instantaneousPower = data.readUInt16LE(2);
|
|
117
|
-
if (flags & 0x1)
|
|
118
|
-
this.balance = data.readUInt8(offset++);
|
|
119
|
-
if (flags & 0x4) {
|
|
120
|
-
this.accTorque = data.readUInt16LE(offset);
|
|
121
|
-
offset += 2;
|
|
122
|
-
}
|
|
123
|
-
if (flags & 0x10) {
|
|
124
|
-
}
|
|
125
|
-
if (flags & 0x20) {
|
|
126
|
-
const crankData = {
|
|
127
|
-
revolutions: data.readUInt16LE(offset),
|
|
128
|
-
time: data.readUInt16LE(offset + 2)
|
|
129
|
-
};
|
|
130
|
-
const { rpm, time } = this.parseCrankData(crankData);
|
|
131
|
-
this.rpm = rpm;
|
|
132
|
-
this.time = time;
|
|
133
|
-
offset += 4;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
}
|
|
138
|
-
const { instantaneousPower, balance, accTorque, rpm, time } = this;
|
|
139
|
-
return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
|
|
140
|
-
}
|
|
141
|
-
onData(characteristic, data) {
|
|
142
|
-
const hasData = super.onData(characteristic, data);
|
|
143
|
-
if (!hasData)
|
|
144
|
-
return false;
|
|
145
|
-
if ((0, ble_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
|
|
146
|
-
const res = this.parsePower(data);
|
|
147
|
-
this.emit('data', res);
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
reset() {
|
|
153
|
-
this.instantaneousPower = undefined;
|
|
154
|
-
this.balance = undefined;
|
|
155
|
-
this.accTorque = undefined;
|
|
156
|
-
this.rpm = undefined;
|
|
157
|
-
this.timeOffset = 0;
|
|
158
|
-
this.time = undefined;
|
|
159
|
-
this.currentCrankData = undefined;
|
|
160
|
-
this.prevCrankData = undefined;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.default = BleCyclingPowerDevice;
|
|
164
|
-
BleCyclingPowerDevice.services = [consts_1.CSP];
|
|
165
|
-
BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
166
|
-
BleCyclingPowerDevice.detectionPriority = 1;
|
|
167
|
-
ble_interface_1.default.register('BleCyclingPowerDevice', 'cp', BleCyclingPowerDevice, BleCyclingPowerDevice.services);
|
|
168
|
-
class PwrAdapter extends
|
|
169
|
-
constructor(device, protocol) {
|
|
170
|
-
super(protocol);
|
|
171
|
-
this.ignore = false;
|
|
172
|
-
this.paused = false;
|
|
173
|
-
this.distanceInternal = 0;
|
|
174
|
-
this.device = device;
|
|
175
|
-
this.ble = protocol.ble;
|
|
176
|
-
this.mode = this.getDefaultCyclingMode();
|
|
177
|
-
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
178
|
-
}
|
|
179
|
-
isBike() { return true; }
|
|
180
|
-
isHrm() { return false; }
|
|
181
|
-
isPower() { return true; }
|
|
182
|
-
isSame(device) {
|
|
183
|
-
if (!(device instanceof PwrAdapter))
|
|
184
|
-
return false;
|
|
185
|
-
const adapter = device;
|
|
186
|
-
return (adapter.getName() === this.getName() && adapter.getProfile() === this.getProfile());
|
|
187
|
-
}
|
|
188
|
-
getProfile() {
|
|
189
|
-
return 'Power Meter';
|
|
190
|
-
}
|
|
191
|
-
getName() {
|
|
192
|
-
return `${this.device.name}`;
|
|
193
|
-
}
|
|
194
|
-
getDisplayName() {
|
|
195
|
-
const { name, instantaneousPower: power } = this.device;
|
|
196
|
-
const powerStr = power ? ` (${power})` : '';
|
|
197
|
-
return `${name}${powerStr}`;
|
|
198
|
-
}
|
|
199
|
-
getCyclingMode() {
|
|
200
|
-
if (!this.mode)
|
|
201
|
-
this.mode = this.getDefaultCyclingMode();
|
|
202
|
-
return this.mode;
|
|
203
|
-
}
|
|
204
|
-
getDefaultCyclingMode() {
|
|
205
|
-
return new power_meter_1.default(this);
|
|
206
|
-
}
|
|
207
|
-
getSupportedCyclingModes() {
|
|
208
|
-
return [power_meter_1.default];
|
|
209
|
-
}
|
|
210
|
-
getPort() {
|
|
211
|
-
return 'ble';
|
|
212
|
-
}
|
|
213
|
-
getWeight() {
|
|
214
|
-
let userWeight =
|
|
215
|
-
let bikeWeight =
|
|
216
|
-
if (this.userSettings && this.userSettings.weight) {
|
|
217
|
-
userWeight = Number(this.userSettings.weight);
|
|
218
|
-
}
|
|
219
|
-
if (this.bikeSettings && this.bikeSettings.weight) {
|
|
220
|
-
bikeWeight = Number(this.bikeSettings.weight);
|
|
221
|
-
}
|
|
222
|
-
return bikeWeight + userWeight;
|
|
223
|
-
}
|
|
224
|
-
setIgnoreBike(ignore) {
|
|
225
|
-
this.ignore = ignore;
|
|
226
|
-
}
|
|
227
|
-
setIgnorePower(ignore) {
|
|
228
|
-
this.ignore = ignore;
|
|
229
|
-
}
|
|
230
|
-
onDeviceData(deviceData) {
|
|
231
|
-
if (this.prevDataTS && Date.now() - this.prevDataTS < 1000)
|
|
232
|
-
return;
|
|
233
|
-
this.prevDataTS = Date.now();
|
|
234
|
-
this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
235
|
-
let incyclistData = this.mapData(deviceData);
|
|
236
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
237
|
-
const data = this.transformData(incyclistData);
|
|
238
|
-
if (this.onDataFn && !this.ignore && !this.paused)
|
|
239
|
-
this.onDataFn(data);
|
|
240
|
-
}
|
|
241
|
-
mapData(deviceData) {
|
|
242
|
-
const data = {
|
|
243
|
-
isPedalling: false,
|
|
244
|
-
power: 0,
|
|
245
|
-
pedalRpm: undefined,
|
|
246
|
-
speed: 0,
|
|
247
|
-
heartrate: 0,
|
|
248
|
-
distanceInternal: 0,
|
|
249
|
-
slope: undefined,
|
|
250
|
-
time: undefined
|
|
251
|
-
};
|
|
252
|
-
data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
|
|
253
|
-
data.pedalRpm = (deviceData.rpm !== undefined ? deviceData.rpm : data.pedalRpm);
|
|
254
|
-
data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
|
|
255
|
-
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
256
|
-
return data;
|
|
257
|
-
}
|
|
258
|
-
transformData(bikeData) {
|
|
259
|
-
if (this.ignore) {
|
|
260
|
-
return {};
|
|
261
|
-
}
|
|
262
|
-
if (bikeData === undefined)
|
|
263
|
-
return;
|
|
264
|
-
let distance = 0;
|
|
265
|
-
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
266
|
-
distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
|
|
267
|
-
}
|
|
268
|
-
if (bikeData.distanceInternal !== undefined)
|
|
269
|
-
this.distanceInternal = bikeData.distanceInternal;
|
|
270
|
-
let data = {
|
|
271
|
-
speed: bikeData.speed,
|
|
272
|
-
slope: bikeData.slope,
|
|
273
|
-
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
274
|
-
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
275
|
-
distance,
|
|
276
|
-
timestamp: Date.now()
|
|
277
|
-
};
|
|
278
|
-
return data;
|
|
279
|
-
}
|
|
280
|
-
start(props) {
|
|
281
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
if (props && props.user)
|
|
283
|
-
this.userSettings = props.user;
|
|
284
|
-
if (props && props.bikeSettings)
|
|
285
|
-
this.bikeSettings = props.bikeSettings;
|
|
286
|
-
this.logger.logEvent({ message: 'csp: start requested', profile: this.getProfile(), props });
|
|
287
|
-
try {
|
|
288
|
-
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
289
|
-
if (bleDevice) {
|
|
290
|
-
this.device = bleDevice;
|
|
291
|
-
bleDevice.on('data', (data) => {
|
|
292
|
-
this.onDeviceData(data);
|
|
293
|
-
});
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
catch (err) {
|
|
298
|
-
this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
|
|
299
|
-
throw new Error(`could not start device, reason:${err.message}`);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
stop() {
|
|
304
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
-
this.logger.logEvent({ message: 'stop requested', profile: this.getProfile() });
|
|
306
|
-
this.distanceInternal = 0;
|
|
307
|
-
this.device.reset();
|
|
308
|
-
return this.device.disconnect();
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
sendUpdate(request) {
|
|
312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
if (this.paused)
|
|
314
|
-
return;
|
|
315
|
-
this.getCyclingMode().sendBikeUpdate(request);
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
pause() { this.paused = true; return Promise.resolve(true); }
|
|
319
|
-
resume() { this.paused = false; return Promise.resolve(true); }
|
|
320
|
-
}
|
|
321
|
-
exports.PwrAdapter = PwrAdapter;
|
|
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.PwrAdapter = void 0;
|
|
35
|
+
const ble_device_1 = require("./ble-device");
|
|
36
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
37
|
+
const ble_1 = require("./ble");
|
|
38
|
+
const device_1 = __importStar(require("../device"));
|
|
39
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
40
|
+
const consts_1 = require("./consts");
|
|
41
|
+
const power_meter_1 = __importDefault(require("../modes/power-meter"));
|
|
42
|
+
class BleCyclingPowerDevice extends ble_device_1.BleDevice {
|
|
43
|
+
constructor(props) {
|
|
44
|
+
super(props);
|
|
45
|
+
this.instantaneousPower = undefined;
|
|
46
|
+
this.balance = undefined;
|
|
47
|
+
this.accTorque = undefined;
|
|
48
|
+
this.rpm = undefined;
|
|
49
|
+
this.timeOffset = 0;
|
|
50
|
+
this.time = undefined;
|
|
51
|
+
this.currentCrankData = undefined;
|
|
52
|
+
this.prevCrankData = undefined;
|
|
53
|
+
}
|
|
54
|
+
isMatching(characteristics) {
|
|
55
|
+
if (!characteristics)
|
|
56
|
+
return false;
|
|
57
|
+
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
58
|
+
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
59
|
+
return hasCPMeasurement && hasCPFeature;
|
|
60
|
+
}
|
|
61
|
+
init() {
|
|
62
|
+
const _super = Object.create(null, {
|
|
63
|
+
init: { get: () => super.init }
|
|
64
|
+
});
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
yield _super.init.call(this);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
return Promise.resolve(false);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
getProfile() {
|
|
75
|
+
return 'Power Meter';
|
|
76
|
+
}
|
|
77
|
+
getServiceUUids() {
|
|
78
|
+
return BleCyclingPowerDevice.services;
|
|
79
|
+
}
|
|
80
|
+
parseCrankData(crankData) {
|
|
81
|
+
if (!this.prevCrankData)
|
|
82
|
+
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
83
|
+
const c = this.currentCrankData = crankData;
|
|
84
|
+
const p = this.prevCrankData;
|
|
85
|
+
let rpm = this.rpm;
|
|
86
|
+
let hasUpdate = c.time !== p.time;
|
|
87
|
+
if (hasUpdate) {
|
|
88
|
+
let time = c.time - p.time;
|
|
89
|
+
let revs = c.revolutions - p.revolutions;
|
|
90
|
+
if (c.time < p.time) {
|
|
91
|
+
time += 0x10000;
|
|
92
|
+
this.timeOffset += 0x10000;
|
|
93
|
+
}
|
|
94
|
+
if (c.revolutions < p.revolutions)
|
|
95
|
+
revs += 0x10000;
|
|
96
|
+
rpm = 1024 * 60 * revs / time;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
100
|
+
rpm = 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
104
|
+
this.prevCrankData = this.currentCrankData;
|
|
105
|
+
if (hasUpdate)
|
|
106
|
+
this.prevCrankData.cntUpdateMissing = 0;
|
|
107
|
+
else
|
|
108
|
+
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
109
|
+
return { rpm, time: this.timeOffset + c.time };
|
|
110
|
+
}
|
|
111
|
+
parsePower(_data) {
|
|
112
|
+
const data = Buffer.from(_data);
|
|
113
|
+
try {
|
|
114
|
+
let offset = 4;
|
|
115
|
+
const flags = data.readUInt16LE(0);
|
|
116
|
+
this.instantaneousPower = data.readUInt16LE(2);
|
|
117
|
+
if (flags & 0x1)
|
|
118
|
+
this.balance = data.readUInt8(offset++);
|
|
119
|
+
if (flags & 0x4) {
|
|
120
|
+
this.accTorque = data.readUInt16LE(offset);
|
|
121
|
+
offset += 2;
|
|
122
|
+
}
|
|
123
|
+
if (flags & 0x10) {
|
|
124
|
+
}
|
|
125
|
+
if (flags & 0x20) {
|
|
126
|
+
const crankData = {
|
|
127
|
+
revolutions: data.readUInt16LE(offset),
|
|
128
|
+
time: data.readUInt16LE(offset + 2)
|
|
129
|
+
};
|
|
130
|
+
const { rpm, time } = this.parseCrankData(crankData);
|
|
131
|
+
this.rpm = rpm;
|
|
132
|
+
this.time = time;
|
|
133
|
+
offset += 4;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
}
|
|
138
|
+
const { instantaneousPower, balance, accTorque, rpm, time } = this;
|
|
139
|
+
return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
|
|
140
|
+
}
|
|
141
|
+
onData(characteristic, data) {
|
|
142
|
+
const hasData = super.onData(characteristic, data);
|
|
143
|
+
if (!hasData)
|
|
144
|
+
return false;
|
|
145
|
+
if ((0, ble_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
|
|
146
|
+
const res = this.parsePower(data);
|
|
147
|
+
this.emit('data', res);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
reset() {
|
|
153
|
+
this.instantaneousPower = undefined;
|
|
154
|
+
this.balance = undefined;
|
|
155
|
+
this.accTorque = undefined;
|
|
156
|
+
this.rpm = undefined;
|
|
157
|
+
this.timeOffset = 0;
|
|
158
|
+
this.time = undefined;
|
|
159
|
+
this.currentCrankData = undefined;
|
|
160
|
+
this.prevCrankData = undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.default = BleCyclingPowerDevice;
|
|
164
|
+
BleCyclingPowerDevice.services = [consts_1.CSP];
|
|
165
|
+
BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
166
|
+
BleCyclingPowerDevice.detectionPriority = 1;
|
|
167
|
+
ble_interface_1.default.register('BleCyclingPowerDevice', 'cp', BleCyclingPowerDevice, BleCyclingPowerDevice.services);
|
|
168
|
+
class PwrAdapter extends device_1.default {
|
|
169
|
+
constructor(device, protocol) {
|
|
170
|
+
super(protocol);
|
|
171
|
+
this.ignore = false;
|
|
172
|
+
this.paused = false;
|
|
173
|
+
this.distanceInternal = 0;
|
|
174
|
+
this.device = device;
|
|
175
|
+
this.ble = protocol.ble;
|
|
176
|
+
this.mode = this.getDefaultCyclingMode();
|
|
177
|
+
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
178
|
+
}
|
|
179
|
+
isBike() { return true; }
|
|
180
|
+
isHrm() { return false; }
|
|
181
|
+
isPower() { return true; }
|
|
182
|
+
isSame(device) {
|
|
183
|
+
if (!(device instanceof PwrAdapter))
|
|
184
|
+
return false;
|
|
185
|
+
const adapter = device;
|
|
186
|
+
return (adapter.getName() === this.getName() && adapter.getProfile() === this.getProfile());
|
|
187
|
+
}
|
|
188
|
+
getProfile() {
|
|
189
|
+
return 'Power Meter';
|
|
190
|
+
}
|
|
191
|
+
getName() {
|
|
192
|
+
return `${this.device.name}`;
|
|
193
|
+
}
|
|
194
|
+
getDisplayName() {
|
|
195
|
+
const { name, instantaneousPower: power } = this.device;
|
|
196
|
+
const powerStr = power ? ` (${power})` : '';
|
|
197
|
+
return `${name}${powerStr}`;
|
|
198
|
+
}
|
|
199
|
+
getCyclingMode() {
|
|
200
|
+
if (!this.mode)
|
|
201
|
+
this.mode = this.getDefaultCyclingMode();
|
|
202
|
+
return this.mode;
|
|
203
|
+
}
|
|
204
|
+
getDefaultCyclingMode() {
|
|
205
|
+
return new power_meter_1.default(this);
|
|
206
|
+
}
|
|
207
|
+
getSupportedCyclingModes() {
|
|
208
|
+
return [power_meter_1.default];
|
|
209
|
+
}
|
|
210
|
+
getPort() {
|
|
211
|
+
return 'ble';
|
|
212
|
+
}
|
|
213
|
+
getWeight() {
|
|
214
|
+
let userWeight = device_1.DEFAULT_USER_WEIGHT;
|
|
215
|
+
let bikeWeight = device_1.DEFAULT_BIKE_WEIGHT;
|
|
216
|
+
if (this.userSettings && this.userSettings.weight) {
|
|
217
|
+
userWeight = Number(this.userSettings.weight);
|
|
218
|
+
}
|
|
219
|
+
if (this.bikeSettings && this.bikeSettings.weight) {
|
|
220
|
+
bikeWeight = Number(this.bikeSettings.weight);
|
|
221
|
+
}
|
|
222
|
+
return bikeWeight + userWeight;
|
|
223
|
+
}
|
|
224
|
+
setIgnoreBike(ignore) {
|
|
225
|
+
this.ignore = ignore;
|
|
226
|
+
}
|
|
227
|
+
setIgnorePower(ignore) {
|
|
228
|
+
this.ignore = ignore;
|
|
229
|
+
}
|
|
230
|
+
onDeviceData(deviceData) {
|
|
231
|
+
if (this.prevDataTS && Date.now() - this.prevDataTS < 1000)
|
|
232
|
+
return;
|
|
233
|
+
this.prevDataTS = Date.now();
|
|
234
|
+
this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
235
|
+
let incyclistData = this.mapData(deviceData);
|
|
236
|
+
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
237
|
+
const data = this.transformData(incyclistData);
|
|
238
|
+
if (this.onDataFn && !this.ignore && !this.paused)
|
|
239
|
+
this.onDataFn(data);
|
|
240
|
+
}
|
|
241
|
+
mapData(deviceData) {
|
|
242
|
+
const data = {
|
|
243
|
+
isPedalling: false,
|
|
244
|
+
power: 0,
|
|
245
|
+
pedalRpm: undefined,
|
|
246
|
+
speed: 0,
|
|
247
|
+
heartrate: 0,
|
|
248
|
+
distanceInternal: 0,
|
|
249
|
+
slope: undefined,
|
|
250
|
+
time: undefined
|
|
251
|
+
};
|
|
252
|
+
data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
|
|
253
|
+
data.pedalRpm = (deviceData.rpm !== undefined ? deviceData.rpm : data.pedalRpm);
|
|
254
|
+
data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
|
|
255
|
+
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
256
|
+
return data;
|
|
257
|
+
}
|
|
258
|
+
transformData(bikeData) {
|
|
259
|
+
if (this.ignore) {
|
|
260
|
+
return {};
|
|
261
|
+
}
|
|
262
|
+
if (bikeData === undefined)
|
|
263
|
+
return;
|
|
264
|
+
let distance = 0;
|
|
265
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
266
|
+
distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
|
|
267
|
+
}
|
|
268
|
+
if (bikeData.distanceInternal !== undefined)
|
|
269
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
270
|
+
let data = {
|
|
271
|
+
speed: bikeData.speed,
|
|
272
|
+
slope: bikeData.slope,
|
|
273
|
+
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
274
|
+
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
275
|
+
distance,
|
|
276
|
+
timestamp: Date.now()
|
|
277
|
+
};
|
|
278
|
+
return data;
|
|
279
|
+
}
|
|
280
|
+
start(props) {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
if (props && props.user)
|
|
283
|
+
this.userSettings = props.user;
|
|
284
|
+
if (props && props.bikeSettings)
|
|
285
|
+
this.bikeSettings = props.bikeSettings;
|
|
286
|
+
this.logger.logEvent({ message: 'csp: start requested', profile: this.getProfile(), props });
|
|
287
|
+
try {
|
|
288
|
+
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
289
|
+
if (bleDevice) {
|
|
290
|
+
this.device = bleDevice;
|
|
291
|
+
bleDevice.on('data', (data) => {
|
|
292
|
+
this.onDeviceData(data);
|
|
293
|
+
});
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
|
|
299
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
stop() {
|
|
304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
this.logger.logEvent({ message: 'stop requested', profile: this.getProfile() });
|
|
306
|
+
this.distanceInternal = 0;
|
|
307
|
+
this.device.reset();
|
|
308
|
+
return this.device.disconnect();
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
sendUpdate(request) {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
if (this.paused)
|
|
314
|
+
return;
|
|
315
|
+
this.getCyclingMode().sendBikeUpdate(request);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
pause() { this.paused = true; return Promise.resolve(true); }
|
|
319
|
+
resume() { this.paused = false; return Promise.resolve(true); }
|
|
320
|
+
}
|
|
321
|
+
exports.PwrAdapter = PwrAdapter;
|