incyclist-devices 1.4.102 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +29 -0
- package/lib/antv2/fe.js +260 -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 -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 -719
- 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/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 +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
|
@@ -1,251 +1,251 @@
|
|
|
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 gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
-
const AntAdapter_1 = __importDefault(require("../AntAdapter"));
|
|
17
|
-
const utils_1 = require("../utils");
|
|
18
|
-
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
19
|
-
const floatVal = (d) => d ? parseFloat(d) : d;
|
|
20
|
-
const intVal = (d) => d ? parseInt(d) : d;
|
|
21
|
-
const hex = (v) => Math.abs(v).toString(16).toUpperCase();
|
|
22
|
-
const DEFAULT_START_TIMEOUT = 5000;
|
|
23
|
-
class AntFEAdapter extends AntAdapter_1.default {
|
|
24
|
-
constructor(DeviceID, port, stick, protocol) {
|
|
25
|
-
super(protocol);
|
|
26
|
-
this.logger = new gd_eventlog_1.EventLogger('Ant+PWR');
|
|
27
|
-
this.logger.logEvent({ message: 'Ant+PWR Adapter created', DeviceID, port });
|
|
28
|
-
this.deviceID = DeviceID;
|
|
29
|
-
this.port = port;
|
|
30
|
-
this.stick = stick;
|
|
31
|
-
this.deviceData = {
|
|
32
|
-
DeviceID
|
|
33
|
-
};
|
|
34
|
-
this.data = {};
|
|
35
|
-
this.started = false;
|
|
36
|
-
this.starting = false;
|
|
37
|
-
this.connected = false;
|
|
38
|
-
this.mode = this.getDefaultCyclingMode();
|
|
39
|
-
}
|
|
40
|
-
isBike() { return true; }
|
|
41
|
-
isHrm() { return false; }
|
|
42
|
-
isPower() { return true; }
|
|
43
|
-
getProfile() {
|
|
44
|
-
return 'Power Meter';
|
|
45
|
-
}
|
|
46
|
-
getName() {
|
|
47
|
-
return `Ant+PWR ${this.deviceID}`;
|
|
48
|
-
}
|
|
49
|
-
getDisplayName() {
|
|
50
|
-
const { DeviceID, ManId } = this.deviceData;
|
|
51
|
-
return `${(0, utils_1.getBrand)(ManId)} PWR ${DeviceID}`;
|
|
52
|
-
}
|
|
53
|
-
getCyclingMode() {
|
|
54
|
-
if (!this.mode)
|
|
55
|
-
this.mode = this.getDefaultCyclingMode();
|
|
56
|
-
return this.mode;
|
|
57
|
-
}
|
|
58
|
-
getDefaultCyclingMode() {
|
|
59
|
-
return new power_meter_1.default(this);
|
|
60
|
-
}
|
|
61
|
-
getSupportedCyclingModes() {
|
|
62
|
-
return [power_meter_1.default];
|
|
63
|
-
}
|
|
64
|
-
onAttached() {
|
|
65
|
-
this.logger.logEvent({ message: 'Device connected' });
|
|
66
|
-
this.connected = true;
|
|
67
|
-
}
|
|
68
|
-
getLogData(data, excludeList) {
|
|
69
|
-
const logData = JSON.parse(JSON.stringify(data));
|
|
70
|
-
excludeList.forEach((key) => {
|
|
71
|
-
delete logData[key];
|
|
72
|
-
});
|
|
73
|
-
return logData;
|
|
74
|
-
}
|
|
75
|
-
onDeviceData(deviceData) {
|
|
76
|
-
if (!this.started || this.isStopped())
|
|
77
|
-
return;
|
|
78
|
-
this.deviceData = deviceData;
|
|
79
|
-
try {
|
|
80
|
-
if (this.onDataFn && !(this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
81
|
-
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
82
|
-
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
83
|
-
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
84
|
-
let incyclistData = this.mapData(deviceData);
|
|
85
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
86
|
-
const data = this.transformData(incyclistData);
|
|
87
|
-
this.onDataFn(data);
|
|
88
|
-
this.lastUpdate = Date.now();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
onDeviceEvent(data) {
|
|
96
|
-
try {
|
|
97
|
-
const cmdInfo = this.currentCmd;
|
|
98
|
-
if (!cmdInfo)
|
|
99
|
-
return;
|
|
100
|
-
const msg = cmdInfo.msg.readUInt8(2);
|
|
101
|
-
const Constants = this.getProtocol().getAnt().Constants;
|
|
102
|
-
const { expectedResponse } = cmdInfo;
|
|
103
|
-
if (data.message === msg) {
|
|
104
|
-
if (expectedResponse === undefined && data.code === Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
105
|
-
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (expectedResponse === undefined && data.code !== Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
109
|
-
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (data.message === 1) {
|
|
114
|
-
if (expectedResponse !== undefined && data.code === expectedResponse) {
|
|
115
|
-
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (expectedResponse === undefined && (data.code === Constants.EVENT_TRANSFER_TX_COMPLETED || data.code === 3)) {
|
|
119
|
-
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (data.code === Constants.EVENT_TRANSFER_TX_FAILED || data.code === Constants.EVENT_CHANNEL_COLLISION) {
|
|
123
|
-
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (this.currentCmd !== undefined && data.message === Constants.MESSAGE_CHANNEL_ACKNOWLEDGED_DATA && data.code === 31) {
|
|
128
|
-
this.logger.log("could not send (TRANSFER_IN_PROGRESS)");
|
|
129
|
-
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
this.logger.logEvent({ message: "Incoming Event ", event: { message: hex(data.message), code: hex(data.code) } });
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
this.logger.logEvent({ message: 'Error', fn: 'parseEvent', event: { message: hex(data.message), code: hex(data.code) }, error: err.message || err });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
sendUpdate(request) {
|
|
139
|
-
if (this.paused)
|
|
140
|
-
return;
|
|
141
|
-
this.getCyclingMode().sendBikeUpdate(request);
|
|
142
|
-
}
|
|
143
|
-
mapData(deviceData) {
|
|
144
|
-
const data = {
|
|
145
|
-
isPedalling: false,
|
|
146
|
-
power: 0,
|
|
147
|
-
pedalRpm: 0,
|
|
148
|
-
speed: 0,
|
|
149
|
-
heartrate: 0,
|
|
150
|
-
distanceInternal: 0,
|
|
151
|
-
slope: undefined,
|
|
152
|
-
time: undefined
|
|
153
|
-
};
|
|
154
|
-
data.slope = (deviceData.Slope !== undefined ? deviceData.Slope : data.slope);
|
|
155
|
-
data.power = (deviceData.Power !== undefined ? deviceData.Power : data.power);
|
|
156
|
-
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
157
|
-
data.time = (deviceData.TimeStamp !== undefined ? deviceData.TimeStamp : data.time);
|
|
158
|
-
data.isPedalling = data.pedalRpm > 0;
|
|
159
|
-
return data;
|
|
160
|
-
}
|
|
161
|
-
transformData(bikeData) {
|
|
162
|
-
if (bikeData === undefined)
|
|
163
|
-
return;
|
|
164
|
-
let distance = 0;
|
|
165
|
-
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
166
|
-
distance = intVal(bikeData.distanceInternal - this.distanceInternal);
|
|
167
|
-
}
|
|
168
|
-
if (bikeData.distanceInternal !== undefined)
|
|
169
|
-
this.distanceInternal = bikeData.distanceInternal;
|
|
170
|
-
let data = {
|
|
171
|
-
speed: floatVal(bikeData.speed),
|
|
172
|
-
slope: floatVal(bikeData.slope),
|
|
173
|
-
power: intVal(bikeData.power),
|
|
174
|
-
cadence: intVal(bikeData.pedalRpm),
|
|
175
|
-
distance,
|
|
176
|
-
timestamp: Date.now()
|
|
177
|
-
};
|
|
178
|
-
if (this.ignorePower) {
|
|
179
|
-
delete data.power;
|
|
180
|
-
delete data.cadence;
|
|
181
|
-
}
|
|
182
|
-
if (this.ignoreBike) {
|
|
183
|
-
data = {};
|
|
184
|
-
}
|
|
185
|
-
return data;
|
|
186
|
-
}
|
|
187
|
-
start(props) {
|
|
188
|
-
const _super = Object.create(null, {
|
|
189
|
-
start: { get: () => super.start }
|
|
190
|
-
});
|
|
191
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
yield _super.start.call(this, props);
|
|
193
|
-
this.logger.logEvent({ message: 'start()', props });
|
|
194
|
-
const opts = props || {};
|
|
195
|
-
const { args = {} } = opts;
|
|
196
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
197
|
-
if (this.ignoreBike && this.ignorePower) {
|
|
198
|
-
this.logger.logEvent({ message: 'start() not done: bike disabled' });
|
|
199
|
-
return resolve(false);
|
|
200
|
-
}
|
|
201
|
-
if (this.starting) {
|
|
202
|
-
this.logger.logEvent({ message: 'start() not done: bike starting' });
|
|
203
|
-
return resolve(false);
|
|
204
|
-
}
|
|
205
|
-
if (this.started) {
|
|
206
|
-
this.logger.logEvent({ message: 'start() done: bike was already started' });
|
|
207
|
-
return resolve(true);
|
|
208
|
-
}
|
|
209
|
-
this.starting = true;
|
|
210
|
-
const Ant = this.getProtocol().getAnt();
|
|
211
|
-
const protocol = this.getProtocol();
|
|
212
|
-
let start = Date.now();
|
|
213
|
-
let timeout = start + (args.timeout || DEFAULT_START_TIMEOUT);
|
|
214
|
-
const iv = setInterval(() => {
|
|
215
|
-
if (Date.now() > timeout) {
|
|
216
|
-
clearInterval(iv);
|
|
217
|
-
this.starting = false;
|
|
218
|
-
reject(new Error('timeout'));
|
|
219
|
-
}
|
|
220
|
-
if (this.isStopped()) {
|
|
221
|
-
clearInterval(iv);
|
|
222
|
-
this.starting = false;
|
|
223
|
-
reject(new Error('stopped'));
|
|
224
|
-
}
|
|
225
|
-
}, 100);
|
|
226
|
-
protocol.attachSensors(this, Ant.BicyclePowerSensor, 'powerData')
|
|
227
|
-
.then(() => {
|
|
228
|
-
this.starting = false;
|
|
229
|
-
this.started = true;
|
|
230
|
-
clearInterval(iv);
|
|
231
|
-
resolve(true);
|
|
232
|
-
})
|
|
233
|
-
.catch(err => reject(err));
|
|
234
|
-
}));
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
stop() {
|
|
238
|
-
const _super = Object.create(null, {
|
|
239
|
-
stop: { get: () => super.stop }
|
|
240
|
-
});
|
|
241
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
yield _super.stop.call(this);
|
|
243
|
-
this.logger.logEvent({ message: 'stop()' });
|
|
244
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
this.starting = false;
|
|
246
|
-
return resolve(true);
|
|
247
|
-
}));
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
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 gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
+
const AntAdapter_1 = __importDefault(require("../AntAdapter"));
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
19
|
+
const floatVal = (d) => d ? parseFloat(d) : d;
|
|
20
|
+
const intVal = (d) => d ? parseInt(d) : d;
|
|
21
|
+
const hex = (v) => Math.abs(v).toString(16).toUpperCase();
|
|
22
|
+
const DEFAULT_START_TIMEOUT = 5000;
|
|
23
|
+
class AntFEAdapter extends AntAdapter_1.default {
|
|
24
|
+
constructor(DeviceID, port, stick, protocol) {
|
|
25
|
+
super(protocol);
|
|
26
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+PWR');
|
|
27
|
+
this.logger.logEvent({ message: 'Ant+PWR Adapter created', DeviceID, port });
|
|
28
|
+
this.deviceID = DeviceID;
|
|
29
|
+
this.port = port;
|
|
30
|
+
this.stick = stick;
|
|
31
|
+
this.deviceData = {
|
|
32
|
+
DeviceID
|
|
33
|
+
};
|
|
34
|
+
this.data = {};
|
|
35
|
+
this.started = false;
|
|
36
|
+
this.starting = false;
|
|
37
|
+
this.connected = false;
|
|
38
|
+
this.mode = this.getDefaultCyclingMode();
|
|
39
|
+
}
|
|
40
|
+
isBike() { return true; }
|
|
41
|
+
isHrm() { return false; }
|
|
42
|
+
isPower() { return true; }
|
|
43
|
+
getProfile() {
|
|
44
|
+
return 'Power Meter';
|
|
45
|
+
}
|
|
46
|
+
getName() {
|
|
47
|
+
return `Ant+PWR ${this.deviceID}`;
|
|
48
|
+
}
|
|
49
|
+
getDisplayName() {
|
|
50
|
+
const { DeviceID, ManId } = this.deviceData;
|
|
51
|
+
return `${(0, utils_1.getBrand)(ManId)} PWR ${DeviceID}`;
|
|
52
|
+
}
|
|
53
|
+
getCyclingMode() {
|
|
54
|
+
if (!this.mode)
|
|
55
|
+
this.mode = this.getDefaultCyclingMode();
|
|
56
|
+
return this.mode;
|
|
57
|
+
}
|
|
58
|
+
getDefaultCyclingMode() {
|
|
59
|
+
return new power_meter_1.default(this);
|
|
60
|
+
}
|
|
61
|
+
getSupportedCyclingModes() {
|
|
62
|
+
return [power_meter_1.default];
|
|
63
|
+
}
|
|
64
|
+
onAttached() {
|
|
65
|
+
this.logger.logEvent({ message: 'Device connected' });
|
|
66
|
+
this.connected = true;
|
|
67
|
+
}
|
|
68
|
+
getLogData(data, excludeList) {
|
|
69
|
+
const logData = JSON.parse(JSON.stringify(data));
|
|
70
|
+
excludeList.forEach((key) => {
|
|
71
|
+
delete logData[key];
|
|
72
|
+
});
|
|
73
|
+
return logData;
|
|
74
|
+
}
|
|
75
|
+
onDeviceData(deviceData) {
|
|
76
|
+
if (!this.started || this.isStopped())
|
|
77
|
+
return;
|
|
78
|
+
this.deviceData = deviceData;
|
|
79
|
+
try {
|
|
80
|
+
if (this.onDataFn && !(this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
81
|
+
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
82
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
83
|
+
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
84
|
+
let incyclistData = this.mapData(deviceData);
|
|
85
|
+
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
86
|
+
const data = this.transformData(incyclistData);
|
|
87
|
+
this.onDataFn(data);
|
|
88
|
+
this.lastUpdate = Date.now();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
onDeviceEvent(data) {
|
|
96
|
+
try {
|
|
97
|
+
const cmdInfo = this.currentCmd;
|
|
98
|
+
if (!cmdInfo)
|
|
99
|
+
return;
|
|
100
|
+
const msg = cmdInfo.msg.readUInt8(2);
|
|
101
|
+
const Constants = this.getProtocol().getAnt().Constants;
|
|
102
|
+
const { expectedResponse } = cmdInfo;
|
|
103
|
+
if (data.message === msg) {
|
|
104
|
+
if (expectedResponse === undefined && data.code === Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
105
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (expectedResponse === undefined && data.code !== Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
109
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (data.message === 1) {
|
|
114
|
+
if (expectedResponse !== undefined && data.code === expectedResponse) {
|
|
115
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (expectedResponse === undefined && (data.code === Constants.EVENT_TRANSFER_TX_COMPLETED || data.code === 3)) {
|
|
119
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (data.code === Constants.EVENT_TRANSFER_TX_FAILED || data.code === Constants.EVENT_CHANNEL_COLLISION) {
|
|
123
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (this.currentCmd !== undefined && data.message === Constants.MESSAGE_CHANNEL_ACKNOWLEDGED_DATA && data.code === 31) {
|
|
128
|
+
this.logger.log("could not send (TRANSFER_IN_PROGRESS)");
|
|
129
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.logger.logEvent({ message: "Incoming Event ", event: { message: hex(data.message), code: hex(data.code) } });
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
this.logger.logEvent({ message: 'Error', fn: 'parseEvent', event: { message: hex(data.message), code: hex(data.code) }, error: err.message || err });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
sendUpdate(request) {
|
|
139
|
+
if (this.paused)
|
|
140
|
+
return;
|
|
141
|
+
this.getCyclingMode().sendBikeUpdate(request);
|
|
142
|
+
}
|
|
143
|
+
mapData(deviceData) {
|
|
144
|
+
const data = {
|
|
145
|
+
isPedalling: false,
|
|
146
|
+
power: 0,
|
|
147
|
+
pedalRpm: 0,
|
|
148
|
+
speed: 0,
|
|
149
|
+
heartrate: 0,
|
|
150
|
+
distanceInternal: 0,
|
|
151
|
+
slope: undefined,
|
|
152
|
+
time: undefined
|
|
153
|
+
};
|
|
154
|
+
data.slope = (deviceData.Slope !== undefined ? deviceData.Slope : data.slope);
|
|
155
|
+
data.power = (deviceData.Power !== undefined ? deviceData.Power : data.power);
|
|
156
|
+
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
157
|
+
data.time = (deviceData.TimeStamp !== undefined ? deviceData.TimeStamp : data.time);
|
|
158
|
+
data.isPedalling = data.pedalRpm > 0;
|
|
159
|
+
return data;
|
|
160
|
+
}
|
|
161
|
+
transformData(bikeData) {
|
|
162
|
+
if (bikeData === undefined)
|
|
163
|
+
return;
|
|
164
|
+
let distance = 0;
|
|
165
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
166
|
+
distance = intVal(bikeData.distanceInternal - this.distanceInternal);
|
|
167
|
+
}
|
|
168
|
+
if (bikeData.distanceInternal !== undefined)
|
|
169
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
170
|
+
let data = {
|
|
171
|
+
speed: floatVal(bikeData.speed),
|
|
172
|
+
slope: floatVal(bikeData.slope),
|
|
173
|
+
power: intVal(bikeData.power),
|
|
174
|
+
cadence: intVal(bikeData.pedalRpm),
|
|
175
|
+
distance,
|
|
176
|
+
timestamp: Date.now()
|
|
177
|
+
};
|
|
178
|
+
if (this.ignorePower) {
|
|
179
|
+
delete data.power;
|
|
180
|
+
delete data.cadence;
|
|
181
|
+
}
|
|
182
|
+
if (this.ignoreBike) {
|
|
183
|
+
data = {};
|
|
184
|
+
}
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
start(props) {
|
|
188
|
+
const _super = Object.create(null, {
|
|
189
|
+
start: { get: () => super.start }
|
|
190
|
+
});
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
yield _super.start.call(this, props);
|
|
193
|
+
this.logger.logEvent({ message: 'start()', props });
|
|
194
|
+
const opts = props || {};
|
|
195
|
+
const { args = {} } = opts;
|
|
196
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
if (this.ignoreBike && this.ignorePower) {
|
|
198
|
+
this.logger.logEvent({ message: 'start() not done: bike disabled' });
|
|
199
|
+
return resolve(false);
|
|
200
|
+
}
|
|
201
|
+
if (this.starting) {
|
|
202
|
+
this.logger.logEvent({ message: 'start() not done: bike starting' });
|
|
203
|
+
return resolve(false);
|
|
204
|
+
}
|
|
205
|
+
if (this.started) {
|
|
206
|
+
this.logger.logEvent({ message: 'start() done: bike was already started' });
|
|
207
|
+
return resolve(true);
|
|
208
|
+
}
|
|
209
|
+
this.starting = true;
|
|
210
|
+
const Ant = this.getProtocol().getAnt();
|
|
211
|
+
const protocol = this.getProtocol();
|
|
212
|
+
let start = Date.now();
|
|
213
|
+
let timeout = start + (args.timeout || DEFAULT_START_TIMEOUT);
|
|
214
|
+
const iv = setInterval(() => {
|
|
215
|
+
if (Date.now() > timeout) {
|
|
216
|
+
clearInterval(iv);
|
|
217
|
+
this.starting = false;
|
|
218
|
+
reject(new Error('timeout'));
|
|
219
|
+
}
|
|
220
|
+
if (this.isStopped()) {
|
|
221
|
+
clearInterval(iv);
|
|
222
|
+
this.starting = false;
|
|
223
|
+
reject(new Error('stopped'));
|
|
224
|
+
}
|
|
225
|
+
}, 100);
|
|
226
|
+
protocol.attachSensors(this, Ant.BicyclePowerSensor, 'powerData')
|
|
227
|
+
.then(() => {
|
|
228
|
+
this.starting = false;
|
|
229
|
+
this.started = true;
|
|
230
|
+
clearInterval(iv);
|
|
231
|
+
resolve(true);
|
|
232
|
+
})
|
|
233
|
+
.catch(err => reject(err));
|
|
234
|
+
}));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
stop() {
|
|
238
|
+
const _super = Object.create(null, {
|
|
239
|
+
stop: { get: () => super.stop }
|
|
240
|
+
});
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
yield _super.stop.call(this);
|
|
243
|
+
this.logger.logEvent({ message: 'stop()' });
|
|
244
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
this.starting = false;
|
|
246
|
+
return resolve(true);
|
|
247
|
+
}));
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.default = AntFEAdapter;
|
package/lib/ant/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getBrand: (manId: any) => "ANT+" | "Garmin" | "Timex" | "Suunto" | "Seiko" | "Sigma" | "Polar" | "VDO" | "Wahoo" | "Elite" | "Tacx";
|
|
1
|
+
export declare const getBrand: (manId: any) => "ANT+" | "Garmin" | "Timex" | "Suunto" | "Seiko" | "Sigma" | "Polar" | "VDO" | "Wahoo" | "Elite" | "Tacx";
|
package/lib/ant/utils.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBrand = void 0;
|
|
4
|
-
const getBrand = (manId) => {
|
|
5
|
-
if (manId === undefined)
|
|
6
|
-
return "ANT+";
|
|
7
|
-
switch (manId) {
|
|
8
|
-
case 1: return "Garmin";
|
|
9
|
-
case 16: return "Timex";
|
|
10
|
-
case 23: return "Suunto";
|
|
11
|
-
case 52: return "Seiko";
|
|
12
|
-
case 53: return "Seiko";
|
|
13
|
-
case 70: return "Sigma";
|
|
14
|
-
case 123: return "Polar";
|
|
15
|
-
case 287: return "VDO";
|
|
16
|
-
case 32: return "Wahoo";
|
|
17
|
-
case 86: return "Elite";
|
|
18
|
-
case 89: return "Tacx";
|
|
19
|
-
default:
|
|
20
|
-
return "ANT+";
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
exports.getBrand = getBrand;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrand = void 0;
|
|
4
|
+
const getBrand = (manId) => {
|
|
5
|
+
if (manId === undefined)
|
|
6
|
+
return "ANT+";
|
|
7
|
+
switch (manId) {
|
|
8
|
+
case 1: return "Garmin";
|
|
9
|
+
case 16: return "Timex";
|
|
10
|
+
case 23: return "Suunto";
|
|
11
|
+
case 52: return "Seiko";
|
|
12
|
+
case 53: return "Seiko";
|
|
13
|
+
case 70: return "Sigma";
|
|
14
|
+
case 123: return "Polar";
|
|
15
|
+
case 287: return "VDO";
|
|
16
|
+
case 32: return "Wahoo";
|
|
17
|
+
case 86: return "Elite";
|
|
18
|
+
case 89: return "Tacx";
|
|
19
|
+
default:
|
|
20
|
+
return "ANT+";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.getBrand = getBrand;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import AntProtocol, { AntDeviceSettings } from "./incyclist-protocol";
|
|
2
|
+
import AntAdapter from "./ant-device";
|
|
3
|
+
export default class AdapterFactory {
|
|
4
|
+
static create(settings: {
|
|
5
|
+
configuration?: AntDeviceSettings;
|
|
6
|
+
detected?: {
|
|
7
|
+
profile: string;
|
|
8
|
+
deviceID: number;
|
|
9
|
+
};
|
|
10
|
+
}, protocol: AntProtocol): AntAdapter;
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const incyclist_protocol_1 = require("./incyclist-protocol");
|
|
7
|
+
const fe_1 = __importDefault(require("./fe"));
|
|
8
|
+
const hr_1 = __importDefault(require("./hr"));
|
|
9
|
+
const pwr_1 = __importDefault(require("./pwr"));
|
|
10
|
+
const sensor_factory_1 = __importDefault(require("./sensor-factory"));
|
|
11
|
+
const profiles = [
|
|
12
|
+
{ profile: 'PWR', Class: pwr_1.default },
|
|
13
|
+
{ profile: 'HR', Class: hr_1.default },
|
|
14
|
+
{ profile: 'FE', Class: fe_1.default },
|
|
15
|
+
];
|
|
16
|
+
class AdapterFactory {
|
|
17
|
+
static create(settings, protocol) {
|
|
18
|
+
let profile;
|
|
19
|
+
let deviceID;
|
|
20
|
+
if (settings && settings.configuration) {
|
|
21
|
+
profile = (0, incyclist_protocol_1.mapIncyclistProfile)(settings.configuration.profile);
|
|
22
|
+
deviceID = settings.configuration.deviceID;
|
|
23
|
+
}
|
|
24
|
+
else if (settings && settings.detected) {
|
|
25
|
+
profile = settings.detected.profile;
|
|
26
|
+
deviceID = settings.detected.deviceID;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const sensor = sensor_factory_1.default.create(profile, Number(deviceID));
|
|
32
|
+
if (sensor) {
|
|
33
|
+
const info = profiles.find(i => i.profile === profile);
|
|
34
|
+
if (!info)
|
|
35
|
+
return;
|
|
36
|
+
return new info.Class(sensor, protocol);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = AdapterFactory;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IAntDevice, IChannel } from 'incyclist-ant-plus';
|
|
3
|
+
import { AntInterfaceProps } from './ant-interface';
|
|
4
|
+
export default class AntDeviceBinding implements IAntDevice {
|
|
5
|
+
constructor(props: AntInterfaceProps);
|
|
6
|
+
open(): Promise<boolean>;
|
|
7
|
+
close(): Promise<boolean>;
|
|
8
|
+
getMaxChannels(): number;
|
|
9
|
+
getChannel(): IChannel;
|
|
10
|
+
freeChannel(channel: IChannel): void;
|
|
11
|
+
getDeviceNumber(): number;
|
|
12
|
+
write(data: Buffer): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class AntDeviceBinding {
|
|
4
|
+
constructor(props) { }
|
|
5
|
+
open() {
|
|
6
|
+
throw new Error('Method not implemented.');
|
|
7
|
+
}
|
|
8
|
+
close() {
|
|
9
|
+
throw new Error('Method not implemented.');
|
|
10
|
+
}
|
|
11
|
+
getMaxChannels() {
|
|
12
|
+
throw new Error('Method not implemented.');
|
|
13
|
+
}
|
|
14
|
+
getChannel() {
|
|
15
|
+
throw new Error('Method not implemented.');
|
|
16
|
+
}
|
|
17
|
+
freeChannel(channel) {
|
|
18
|
+
throw new Error('Method not implemented.');
|
|
19
|
+
}
|
|
20
|
+
getDeviceNumber() {
|
|
21
|
+
throw new Error('Method not implemented.');
|
|
22
|
+
}
|
|
23
|
+
write(data) {
|
|
24
|
+
throw new Error('Method not implemented.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = AntDeviceBinding;
|