incyclist-devices 2.1.0 → 2.1.2
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/lib/adapters.d.ts +1 -1
- package/lib/antv2/adapter-factory.d.ts +4 -15
- package/lib/antv2/adapter.d.ts +15 -15
- package/lib/antv2/adapter.js +67 -21
- package/lib/antv2/ant-interface.d.ts +3 -11
- package/lib/antv2/ant-interface.js +1 -1
- package/lib/antv2/base/adapter.d.ts +69 -0
- package/lib/antv2/base/adapter.js +439 -0
- package/lib/antv2/base/ant-interface.d.ts +35 -0
- package/lib/antv2/base/ant-interface.js +285 -0
- package/lib/antv2/base/binding.d.ts +13 -0
- package/lib/antv2/base/binding.js +27 -0
- package/lib/antv2/base/interface.d.ts +46 -0
- package/lib/antv2/base/interface.js +337 -0
- package/lib/antv2/cad/adapter.d.ts +10 -0
- package/lib/antv2/cad/adapter.js +25 -0
- package/lib/antv2/cad/index.d.ts +2 -0
- package/lib/antv2/cad/index.js +7 -0
- package/lib/antv2/consts.d.ts +2 -0
- package/lib/antv2/consts.js +5 -0
- package/lib/antv2/factories/adapter-factory.d.ts +14 -0
- package/lib/antv2/factories/adapter-factory.js +73 -0
- package/lib/antv2/factories/sensor-factory.d.ts +5 -0
- package/lib/antv2/factories/sensor-factory.js +22 -0
- package/lib/antv2/fe/adapter.d.ts +21 -30
- package/lib/antv2/fe/adapter.js +139 -251
- package/lib/antv2/hr/adapter.d.ts +6 -15
- package/lib/antv2/hr/adapter.js +7 -55
- package/lib/antv2/hr copy/adapter.d.ts +11 -0
- package/lib/antv2/hr copy/adapter.js +30 -0
- package/lib/antv2/hr copy/index.d.ts +2 -0
- package/lib/antv2/hr copy/index.js +7 -0
- package/lib/antv2/index.d.ts +5 -4
- package/lib/antv2/index.js +5 -3
- package/lib/antv2/pwr/adapter.d.ts +9 -33
- package/lib/antv2/pwr/adapter.js +19 -140
- package/lib/antv2/types.d.ts +32 -4
- package/lib/base/adpater.d.ts +39 -60
- package/lib/base/adpater.js +139 -161
- package/lib/base/consts.d.ts +4 -0
- package/lib/base/consts.js +9 -0
- package/lib/ble/adapter-factory.d.ts +10 -11
- package/lib/ble/base/adapter.d.ts +7 -14
- package/lib/ble/base/adapter.js +2 -36
- package/lib/ble/ble-interface.d.ts +5 -7
- package/lib/ble/cp/adapter.d.ts +6 -8
- package/lib/ble/cp/adapter.js +8 -27
- package/lib/ble/elite/adapter.d.ts +7 -8
- package/lib/ble/elite/adapter.js +5 -25
- package/lib/ble/fm/adapter.d.ts +6 -7
- package/lib/ble/fm/adapter.js +13 -34
- package/lib/ble/hr/adapter.d.ts +5 -8
- package/lib/ble/hr/adapter.js +2 -2
- package/lib/ble/peripheral-cache.d.ts +2 -3
- package/lib/ble/tacx/adapter.d.ts +2 -3
- package/lib/ble/tacx/adapter.js +8 -8
- package/lib/ble/types.d.ts +1 -2
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +6 -6
- package/lib/ble/wahoo/comms.js +16 -16
- package/lib/factories/adapters.d.ts +7 -0
- package/lib/factories/adapters.js +49 -0
- package/lib/factories/index.d.ts +3 -0
- package/lib/factories/index.js +10 -0
- package/lib/factories/interfaces.d.ts +7 -0
- package/lib/factories/interfaces.js +27 -0
- package/lib/index.d.ts +5 -6
- package/lib/index.js +4 -9
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +1 -1
- package/lib/modes/antble-erg.d.ts +1 -1
- package/lib/modes/antble-smarttrainer.d.ts +2 -2
- package/lib/modes/base.d.ts +5 -5
- package/lib/modes/daum-classic-standard.d.ts +3 -2
- package/lib/modes/daum-erg.d.ts +3 -3
- package/lib/modes/daum-premium-standard.d.ts +3 -2
- package/lib/modes/daum-smarttrainer.d.ts +3 -2
- package/lib/modes/kettler-erg.d.ts +3 -3
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +2 -2
- package/lib/modes/power-meter.d.ts +3 -2
- package/lib/modes/simulator.d.ts +2 -1
- package/lib/modes/types.d.ts +2 -13
- package/lib/serial/SinglePathScanner.d.ts +17 -0
- package/lib/serial/SinglePathScanner.js +87 -0
- package/lib/serial/adapter-factory.d.ts +6 -6
- package/lib/serial/adapter.d.ts +6 -11
- package/lib/serial/base/adapter.d.ts +17 -0
- package/lib/serial/base/adapter.js +67 -0
- package/lib/serial/base/comms.d.ts +62 -0
- package/lib/serial/base/comms.js +280 -0
- package/lib/serial/base/serial-interface.d.ts +36 -0
- package/lib/serial/base/serial-interface.js +288 -0
- package/lib/serial/base/serial-scanner.d.ts +16 -0
- package/lib/serial/base/serial-scanner.js +87 -0
- package/lib/serial/base/serialport.d.ts +17 -0
- package/lib/serial/base/serialport.js +87 -0
- package/lib/serial/comms.d.ts +2 -2
- package/lib/serial/daum/DaumAdapter.d.ts +12 -24
- package/lib/serial/daum/DaumAdapter.js +40 -59
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
- package/lib/serial/daum/classic/adapter.d.ts +8 -20
- package/lib/serial/daum/classic/adapter.js +28 -58
- package/lib/serial/daum/classic/comms.d.ts +4 -6
- package/lib/serial/daum/classic/comms.js +2 -2
- package/lib/serial/daum/classic/consts.d.ts +2 -0
- package/lib/serial/daum/classic/consts.js +5 -0
- package/lib/serial/daum/classic/mock.js +5 -4
- package/lib/serial/daum/classic/types.d.ts +8 -10
- package/lib/serial/daum/classic/utils.d.ts +1 -2
- package/lib/serial/daum/consts.d.ts +0 -19
- package/lib/serial/daum/consts.js +0 -22
- package/lib/serial/daum/premium/adapter.d.ts +8 -11
- package/lib/serial/daum/premium/adapter.js +27 -53
- package/lib/serial/daum/premium/comms.d.ts +4 -7
- package/lib/serial/daum/premium/comms.js +23 -22
- package/lib/serial/daum/premium/mock.d.ts +1 -1
- package/lib/serial/daum/premium/mock.js +2 -2
- package/lib/serial/daum/premium/types.d.ts +32 -17
- package/lib/serial/daum/premium/types.js +8 -8
- package/lib/serial/daum/premium/utils.d.ts +2 -3
- package/lib/serial/daum/premium/utils.js +3 -3
- package/lib/serial/daum/types.d.ts +4 -1
- package/lib/serial/daum/types.js +9 -1
- package/lib/serial/factories/adapter-factory.d.ts +14 -0
- package/lib/serial/factories/adapter-factory.js +30 -0
- package/lib/serial/index.d.ts +8 -5
- package/lib/serial/index.js +15 -15
- package/lib/serial/kettler/comms.d.ts +1 -1
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +11 -18
- package/lib/serial/kettler/ergo-racer/adapter.js +9 -21
- package/lib/serial/kettler/types.d.ts +8 -0
- package/lib/serial/kettler/types.js +2 -0
- package/lib/serial/serial-interface.d.ts +2 -32
- package/lib/serial/serial-interface.js +3 -76
- package/lib/serial/serial-scanner.d.ts +16 -0
- package/lib/serial/serial-scanner.js +87 -0
- package/lib/serial/serialport.d.ts +1 -13
- package/lib/serial/types.d.ts +45 -0
- package/lib/serial/types.js +9 -0
- package/lib/simulator/Simulator.d.ts +10 -13
- package/lib/simulator/Simulator.js +11 -23
- package/lib/types/Command.d.ts +8 -0
- package/lib/types/Command.js +2 -0
- package/lib/types/adapter.d.ts +22 -33
- package/lib/types/adapter.js +0 -68
- package/lib/types/command.d.ts +0 -8
- package/lib/types/command.js +0 -2
- package/lib/types/data.d.ts +12 -1
- package/lib/types/device.d.ts +8 -23
- package/lib/types/device.js +9 -8
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +22 -0
- package/lib/types/route.d.ts +0 -19
- package/lib/types/route.js +0 -2
- package/lib/types/types.d.ts +8 -0
- package/lib/types/types.js +2 -0
- package/lib/utils/utils.d.ts +2 -0
- package/lib/utils/utils.js +39 -4
- package/package.json +1 -1
package/lib/antv2/fe/adapter.js
CHANGED
|
@@ -12,94 +12,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const utils_1 = require("../utils");
|
|
18
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
15
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
16
|
+
const types_1 = require("../../types");
|
|
19
17
|
const ant_fe_adv_st_mode_1 = __importDefault(require("../../modes/ant-fe-adv-st-mode"));
|
|
20
|
-
const
|
|
21
|
-
const sensor_factory_1 = __importDefault(require("../sensor-factory"));
|
|
22
|
-
const capabilities_1 = require("../../types/capabilities");
|
|
23
|
-
const adpater_1 = require("../../base/adpater");
|
|
18
|
+
const consts_1 = require("../../base/consts");
|
|
24
19
|
const antble_erg_1 = __importDefault(require("../../modes/antble-erg"));
|
|
25
20
|
const antble_smarttrainer_1 = __importDefault(require("../../modes/antble-smarttrainer"));
|
|
26
21
|
const DEFAULT_BIKE_WEIGHT_MOUNTAIN = 14.5;
|
|
27
|
-
const MAX_RETRIES = 3;
|
|
28
|
-
class AntFeControl extends adpater_1.ControllableDevice {
|
|
29
|
-
getSupportedCyclingModes() {
|
|
30
|
-
return [antble_smarttrainer_1.default, antble_erg_1.default, ant_fe_adv_st_mode_1.default];
|
|
31
|
-
}
|
|
32
|
-
getDefaultCyclingMode() {
|
|
33
|
-
return new antble_smarttrainer_1.default(this.adapter);
|
|
34
|
-
}
|
|
35
|
-
sendInitCommands() {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
return true;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.AntFeControl = AntFeControl;
|
|
42
22
|
class AntFEAdapter extends adapter_1.default {
|
|
43
23
|
constructor(settings, props) {
|
|
44
|
-
if (settings.protocol && settings.profile !== AntFEAdapter.INCYCLIST_PROFILE_NAME)
|
|
45
|
-
throw new Error('Incorrect Profile');
|
|
46
|
-
if (!settings.protocol && settings.profile !== AntFEAdapter.ANT_PROFILE_NAME)
|
|
47
|
-
throw new Error('Incorrect Profile');
|
|
48
24
|
super(settings, props);
|
|
49
|
-
this.setControl(new AntFeControl(this, props));
|
|
50
|
-
this.deviceData = {
|
|
51
|
-
DeviceID: this.sensor.getDeviceID()
|
|
52
|
-
};
|
|
53
|
-
this.dataMsgCount = 0;
|
|
54
|
-
this.logger = new gd_eventlog_1.EventLogger('Ant+FE');
|
|
55
|
-
this.isReconnecting = false;
|
|
56
25
|
this.startProps = {};
|
|
57
|
-
this.sensorConnected = false;
|
|
58
26
|
this.capabilities = [
|
|
59
|
-
|
|
60
|
-
|
|
27
|
+
types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence,
|
|
28
|
+
types_1.IncyclistCapability.Control
|
|
61
29
|
];
|
|
62
30
|
}
|
|
63
|
-
createSensor(settings) {
|
|
64
|
-
const sensor = sensor_factory_1.default.create(AntFEAdapter.ANT_PROFILE_NAME, Number(settings.deviceID));
|
|
65
|
-
return sensor;
|
|
66
|
-
}
|
|
67
|
-
getName() {
|
|
68
|
-
if (this.settings.name)
|
|
69
|
-
return this.settings.name;
|
|
70
|
-
const deviceID = this.sensor.getDeviceID();
|
|
71
|
-
return `Ant+FE ${deviceID}`;
|
|
72
|
-
}
|
|
73
|
-
getUniqueName() {
|
|
74
|
-
if (this.settings.name)
|
|
75
|
-
return this.settings.name;
|
|
76
|
-
const { DeviceID, ManId } = this.deviceData;
|
|
77
|
-
const brand = (0, utils_1.getBrand)(ManId);
|
|
78
|
-
if (brand)
|
|
79
|
-
return `${brand} FE ${DeviceID}`;
|
|
80
|
-
else
|
|
81
|
-
return `${this.getName()}`;
|
|
82
|
-
}
|
|
83
31
|
getDisplayName() {
|
|
84
32
|
const { InstantaneousPower } = this.deviceData;
|
|
85
33
|
const pwrStr = InstantaneousPower ? ` (${InstantaneousPower})` : '';
|
|
86
34
|
return `${this.getUniqueName()}${pwrStr}`;
|
|
87
35
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
excludeList.forEach((key) => {
|
|
91
|
-
delete logData[key];
|
|
92
|
-
});
|
|
93
|
-
return logData;
|
|
36
|
+
isReconnecting() {
|
|
37
|
+
return this.promiseReconnect !== null && this.promiseReconnect !== undefined;
|
|
94
38
|
}
|
|
95
39
|
sendUpdate(request, forced = false) {
|
|
96
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
if ((this.paused || this.isReconnecting) && !forced)
|
|
41
|
+
if ((this.paused || this.isReconnecting()) && !forced)
|
|
98
42
|
return;
|
|
99
43
|
let isReset = request.reset && Object.keys(request).length === 1;
|
|
100
44
|
const update = isReset ? this.getCyclingMode().getBikeInitRequest() : this.getCyclingMode().sendBikeUpdate(request);
|
|
101
|
-
if (!update)
|
|
102
|
-
return;
|
|
103
45
|
this.logEvent({ message: 'send bike update requested', update, request });
|
|
104
46
|
try {
|
|
105
47
|
const fe = this.sensor;
|
|
@@ -122,200 +64,138 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
122
64
|
});
|
|
123
65
|
}
|
|
124
66
|
onDeviceData(deviceData) {
|
|
125
|
-
this.dataMsgCount++;
|
|
126
|
-
this.lastDataTS = Date.now();
|
|
127
67
|
super.onDeviceData(deviceData);
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.startDataTimeoutCheck();
|
|
68
|
+
if (deviceData.HeartRate && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
|
|
69
|
+
this.capabilities.push(types_1.IncyclistCapability.HeartRate);
|
|
70
|
+
this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
|
|
132
71
|
}
|
|
133
|
-
try {
|
|
134
|
-
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
135
|
-
this.logEvent({ message: 'onDeviceData', data: logData, paused: this.paused });
|
|
136
|
-
if (!this.canSendUpdate())
|
|
137
|
-
return;
|
|
138
|
-
let incyclistData = this.mapToCycleModeData(deviceData);
|
|
139
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
140
|
-
this.data = this.transformData(incyclistData);
|
|
141
|
-
this.emitData(this.data);
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
this.logEvent({ message: 'error', fn: 'onDeviceData()', error: err.message || err, stack: err.stack });
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
canSendUpdate() {
|
|
148
|
-
if (!this.hasDataListeners() || this.paused)
|
|
149
|
-
return false;
|
|
150
|
-
return super.canSendUpdate();
|
|
151
72
|
}
|
|
152
|
-
|
|
73
|
+
mapData(deviceData) {
|
|
153
74
|
const data = {
|
|
154
75
|
isPedalling: false,
|
|
155
76
|
power: 0,
|
|
156
|
-
pedalRpm:
|
|
77
|
+
pedalRpm: 0,
|
|
157
78
|
speed: 0,
|
|
158
|
-
heartrate: 0,
|
|
159
|
-
distanceInternal: 0,
|
|
160
|
-
slope: undefined,
|
|
161
|
-
time: undefined
|
|
162
79
|
};
|
|
163
80
|
data.speed = (deviceData.VirtualSpeed !== undefined ? deviceData.VirtualSpeed : (deviceData.RealSpeed || 0)) * 3.6;
|
|
164
81
|
data.slope = (deviceData.Incline !== undefined ? deviceData.Incline : data.slope);
|
|
165
82
|
data.power = (deviceData.InstantaneousPower !== undefined ? deviceData.InstantaneousPower : data.power);
|
|
166
|
-
data.time = (deviceData.ElapsedTime !== undefined ? deviceData.ElapsedTime : data.time);
|
|
167
83
|
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
168
|
-
data.isPedalling = data.pedalRpm > 0 ||
|
|
84
|
+
data.isPedalling = data.pedalRpm > 0 || data.power > 0;
|
|
85
|
+
if (deviceData.HeartRate !== undefined)
|
|
86
|
+
data.heartrate = deviceData.HeartRate;
|
|
87
|
+
if (deviceData.Distance !== undefined)
|
|
88
|
+
data.distanceInternal = deviceData.Distance;
|
|
89
|
+
if (deviceData.ElapsedTime !== undefined)
|
|
90
|
+
data.time = deviceData.ElapsedTime;
|
|
169
91
|
return data;
|
|
170
92
|
}
|
|
171
|
-
transformData(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
distance = bikeData.distanceInternal - this.distanceInternal;
|
|
177
|
-
}
|
|
178
|
-
if (bikeData.distanceInternal !== undefined)
|
|
179
|
-
this.distanceInternal = bikeData.distanceInternal;
|
|
180
|
-
const data = {
|
|
181
|
-
speed: bikeData.speed,
|
|
182
|
-
slope: bikeData.slope,
|
|
183
|
-
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
184
|
-
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
185
|
-
heartrate: bikeData.heartrate !== undefined ? Math.round(bikeData.heartrate) : undefined,
|
|
186
|
-
distance,
|
|
93
|
+
transformData(adapterData, deviceData) {
|
|
94
|
+
const data = Object.assign(this.data, {
|
|
95
|
+
power: adapterData.power,
|
|
96
|
+
speed: adapterData.speed,
|
|
97
|
+
cadence: adapterData.pedalRpm,
|
|
187
98
|
timestamp: Date.now()
|
|
188
|
-
};
|
|
189
|
-
|
|
99
|
+
});
|
|
100
|
+
if (adapterData.distanceInternal !== undefined) {
|
|
101
|
+
if (data.internalDistanceCounter !== undefined)
|
|
102
|
+
data.distance = adapterData.distanceInternal - data.internalDistanceCounter;
|
|
103
|
+
data.internalDistanceCounter = adapterData.distanceInternal;
|
|
104
|
+
}
|
|
105
|
+
if (deviceData.Distance)
|
|
106
|
+
data.deviceDistanceCounter = deviceData.Distance;
|
|
107
|
+
if (adapterData.heartrate)
|
|
108
|
+
data.heartrate = adapterData.heartrate;
|
|
109
|
+
if (adapterData.slope)
|
|
110
|
+
data.slope = adapterData.slope;
|
|
111
|
+
if (adapterData.time)
|
|
112
|
+
data.deviceTime = adapterData.time;
|
|
113
|
+
this.data = data;
|
|
190
114
|
}
|
|
191
|
-
start(props) {
|
|
115
|
+
start(props = {}) {
|
|
116
|
+
const _super = Object.create(null, {
|
|
117
|
+
start: { get: () => super.start }
|
|
118
|
+
});
|
|
192
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
120
|
+
return yield _super.start.call(this, props);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
resetStartStatus() {
|
|
124
|
+
const props = this.startProps;
|
|
125
|
+
const isReconnect = props.reconnect || false;
|
|
126
|
+
super.resetStartStatus();
|
|
127
|
+
if (isReconnect) {
|
|
128
|
+
delete props.reconnect;
|
|
129
|
+
this.startStatus.userInitialized = true;
|
|
130
|
+
this.startStatus.controlInitialized = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
startPreChecks(props) {
|
|
134
|
+
const _super = Object.create(null, {
|
|
135
|
+
startPreChecks: { get: () => super.startPreChecks }
|
|
136
|
+
});
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
this.startProps = props;
|
|
139
|
+
this.setFEDefaultTimeout();
|
|
140
|
+
return yield _super.startPreChecks.call(this, props);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
initControl() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
yield this.sendInititalUserMessage();
|
|
146
|
+
yield this.sendInitialRequest();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
sendInititalUserMessage() {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const props = this.startProps;
|
|
152
|
+
const { sensorStarted, hasData, userInitialized, timeout } = this.startStatus;
|
|
153
|
+
if (!sensorStarted || !hasData || userInitialized || timeout)
|
|
154
|
+
return;
|
|
207
155
|
const opts = props || {};
|
|
208
156
|
const { args = {}, user = {} } = opts;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
this.
|
|
235
|
-
if (this.sensorConnected) {
|
|
236
|
-
this.logEvent({ message: 'sensor started', props });
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (this.sensorConnected && !hasData) {
|
|
240
|
-
try {
|
|
241
|
-
yield this.waitForData(startupTimeout);
|
|
242
|
-
hasData = true;
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
stopTimeoutCheck();
|
|
246
|
-
try {
|
|
247
|
-
yield yield this.ant.stopSensor(this.sensor);
|
|
248
|
-
this.sensorConnected = false;
|
|
249
|
-
}
|
|
250
|
-
catch (_a) { }
|
|
251
|
-
this.started = false;
|
|
252
|
-
return reject(new Error('could not start device, reason:no data received'));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
status = { userSent: false, slopeSent: false };
|
|
256
|
-
if (!hasData) {
|
|
257
|
-
yield (0, utils_2.sleep)(reconnectTimeout);
|
|
258
|
-
continue;
|
|
157
|
+
const fe = this.sensor;
|
|
158
|
+
try {
|
|
159
|
+
const mode = this.getCyclingMode();
|
|
160
|
+
const bikeType = mode ? mode.getSetting('bikeType').toLowerCase() : 'race';
|
|
161
|
+
const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : consts_1.DEFAULT_BIKE_WEIGHT;
|
|
162
|
+
const userWeight = args.userWeight || user.weight || consts_1.DEFAULT_USER_WEIGHT;
|
|
163
|
+
const bikeWeight = args.bikeWeight || defaultBikeWeight;
|
|
164
|
+
this.startStatus.userInitialized = yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
this.logEvent({ message: 'sending FE message error', error: err.message });
|
|
168
|
+
this.startStatus.userInitialized = false;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
sendInitialRequest() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const { sensorStarted, hasData, controlInitialized, timeout } = this.startStatus;
|
|
175
|
+
if (!sensorStarted || !hasData || controlInitialized || timeout)
|
|
176
|
+
return;
|
|
177
|
+
const fe = this.sensor;
|
|
178
|
+
try {
|
|
179
|
+
const startRequest = this.getCyclingMode().getBikeInitRequest();
|
|
180
|
+
if (startRequest) {
|
|
181
|
+
if (startRequest.targetPower !== undefined && startRequest.targetPower !== null) {
|
|
182
|
+
this.startStatus.controlInitialized = yield fe.sendTargetPower(startRequest.targetPower);
|
|
259
183
|
}
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
const fe = this.sensor;
|
|
263
|
-
const mode = this.getCyclingMode();
|
|
264
|
-
const bikeType = mode ? mode.getSetting('bikeType').toLowerCase() : 'race';
|
|
265
|
-
const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : adpater_1.DEFAULT_BIKE_WEIGHT;
|
|
266
|
-
const userWeight = args.userWeight || user.weight || adpater_1.DEFAULT_USER_WEIGHT;
|
|
267
|
-
const bikeWeight = args.bikeWeight || defaultBikeWeight;
|
|
268
|
-
status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
|
|
269
|
-
if (!status.slopeSent) {
|
|
270
|
-
const startRequest = this.getCyclingMode().getBikeInitRequest();
|
|
271
|
-
if (startRequest) {
|
|
272
|
-
if (startRequest.targetPower !== undefined && startRequest.targetPower !== null) {
|
|
273
|
-
status.slopeSent = yield fe.sendTargetPower(startRequest.targetPower);
|
|
274
|
-
}
|
|
275
|
-
else if (startRequest.slope !== undefined && startRequest.slope !== null) {
|
|
276
|
-
status.slopeSent = yield fe.sendTrackResistance(startRequest.slope);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
status.slopeSent = true;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
status.slopeSent = yield fe.sendTrackResistance(0.0);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
288
|
-
this.logEvent({ message: 'sending FE message error', error: err.message });
|
|
289
|
-
this.started = false;
|
|
290
|
-
}
|
|
291
|
-
success = status.userSent && status.slopeSent;
|
|
184
|
+
else if (startRequest.slope !== undefined && startRequest.slope !== null) {
|
|
185
|
+
this.startStatus.controlInitialized = yield fe.sendTrackResistance(startRequest.slope);
|
|
292
186
|
}
|
|
293
187
|
else {
|
|
294
|
-
|
|
188
|
+
this.startStatus.controlInitialized = true;
|
|
295
189
|
}
|
|
296
190
|
}
|
|
297
|
-
if (success) {
|
|
298
|
-
this.logEvent({ message: 'ANT FE start success' });
|
|
299
|
-
this.started = true;
|
|
300
|
-
this.paused = false;
|
|
301
|
-
stopTimeoutCheck();
|
|
302
|
-
resolve(true);
|
|
303
|
-
}
|
|
304
191
|
else {
|
|
305
|
-
this.
|
|
306
|
-
stopTimeoutCheck();
|
|
307
|
-
if (!hasData) {
|
|
308
|
-
reject(new Error('could not start device, reason: no data received'));
|
|
309
|
-
}
|
|
310
|
-
else if (this.sensorConnected) {
|
|
311
|
-
reject(new Error('could not start device, reason: could not send FE commands'));
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
reject(new Error('could not start device, reason: could not connect'));
|
|
315
|
-
}
|
|
316
|
-
this.started = false;
|
|
192
|
+
this.startStatus.controlInitialized = yield fe.sendTrackResistance(0.0);
|
|
317
193
|
}
|
|
318
|
-
}
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
this.logEvent({ message: 'sending FE message error', error: err.message });
|
|
197
|
+
this.startStatus.controlInitialized = false;
|
|
198
|
+
}
|
|
319
199
|
});
|
|
320
200
|
}
|
|
321
201
|
setFEDefaultTimeout() {
|
|
@@ -330,20 +210,26 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
330
210
|
reconnect() {
|
|
331
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
332
212
|
this.logEvent({ message: 'reconnect to device' });
|
|
333
|
-
this.
|
|
334
|
-
|
|
335
|
-
yield this.stop();
|
|
336
|
-
yield this.start(this.startProps);
|
|
337
|
-
this.started = true;
|
|
338
|
-
this.isReconnecting = false;
|
|
339
|
-
this.logEvent({ message: 'reconnect success' });
|
|
340
|
-
return true;
|
|
341
|
-
}
|
|
342
|
-
catch (err) {
|
|
343
|
-
this.logEvent({ message: 'reconnect failed' });
|
|
344
|
-
this.isReconnecting = false;
|
|
345
|
-
return false;
|
|
213
|
+
if (this.promiseReconnect) {
|
|
214
|
+
return yield this.promiseReconnect;
|
|
346
215
|
}
|
|
216
|
+
const doReconnect = () => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
try {
|
|
218
|
+
yield this.stop();
|
|
219
|
+
yield this.start(Object.assign(Object.assign({}, this.startProps), { reconnect: true }));
|
|
220
|
+
this.started = true;
|
|
221
|
+
this.logEvent({ message: 'reconnect success' });
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
this.logEvent({ message: 'reconnect failed' });
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
this.promiseReconnect = doReconnect();
|
|
230
|
+
const res = yield this.promiseReconnect;
|
|
231
|
+
this.promiseReconnect = null;
|
|
232
|
+
return res;
|
|
347
233
|
});
|
|
348
234
|
}
|
|
349
235
|
sendInitCommands() {
|
|
@@ -357,16 +243,18 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
357
243
|
return true;
|
|
358
244
|
}
|
|
359
245
|
}
|
|
360
|
-
catch (
|
|
246
|
+
catch (err) {
|
|
361
247
|
return false;
|
|
362
248
|
}
|
|
363
249
|
}
|
|
364
|
-
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
250
|
+
return false;
|
|
367
251
|
});
|
|
368
252
|
}
|
|
369
253
|
}
|
|
370
254
|
AntFEAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
|
|
371
255
|
AntFEAdapter.ANT_PROFILE_NAME = 'FE';
|
|
256
|
+
AntFEAdapter.controllers = {
|
|
257
|
+
modes: [antble_smarttrainer_1.default, antble_erg_1.default, ant_fe_adv_st_mode_1.default],
|
|
258
|
+
default: antble_smarttrainer_1.default
|
|
259
|
+
};
|
|
372
260
|
exports.default = AntFEAdapter;
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { HeartRateSensorState,
|
|
2
|
-
import AntAdapter from "../adapter";
|
|
1
|
+
import { HeartRateSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
3
|
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export default class AntHrAdapter extends AntAdapter<NonControllableDevice<AntDeviceProperties>, HeartRateSensorState, HeartRateSensorData> {
|
|
9
|
-
static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
10
|
-
static ANT_PROFILE_NAME: Profile;
|
|
4
|
+
export default class AntHrAdapter extends AntAdapter<HeartRateSensorState> {
|
|
5
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
6
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
11
7
|
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
12
|
-
createSensor(settings: AntDeviceSettings): ISensor;
|
|
13
|
-
getName(): string;
|
|
14
|
-
getUniqueName(): string;
|
|
15
8
|
getDisplayName(): string;
|
|
16
|
-
|
|
17
|
-
mapData(deviceData: HeartRateSensorState): void;
|
|
9
|
+
mapToAdapterData(deviceData: HeartRateSensorState): void;
|
|
18
10
|
hasData(): boolean;
|
|
19
11
|
}
|
|
20
|
-
export {};
|
package/lib/antv2/hr/adapter.js
CHANGED
|
@@ -3,71 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const adapter_1 = __importDefault(require("../adapter"));
|
|
7
|
-
const
|
|
8
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
9
|
-
const sensor_factory_1 = __importDefault(require("../sensor-factory"));
|
|
10
|
-
const capabilities_1 = require("../../types/capabilities");
|
|
6
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
7
|
+
const types_1 = require("../../types");
|
|
11
8
|
class AntHrAdapter extends adapter_1.default {
|
|
12
9
|
constructor(settings, props) {
|
|
13
|
-
if (settings.protocol && settings.profile !== AntHrAdapter.INCYCLIST_PROFILE_NAME)
|
|
14
|
-
throw new Error('Incorrect Profile');
|
|
15
|
-
if (!settings.protocol && settings.profile !== AntHrAdapter.ANT_PROFILE_NAME)
|
|
16
|
-
throw new Error('Incorrect Profile');
|
|
17
10
|
super(settings, props);
|
|
18
|
-
this.
|
|
19
|
-
DeviceID: this.sensor.getDeviceID()
|
|
20
|
-
};
|
|
21
|
-
this.logger = new gd_eventlog_1.EventLogger('Ant+Hrm');
|
|
22
|
-
this.capabilities = [capabilities_1.IncyclistCapability.HeartRate];
|
|
23
|
-
}
|
|
24
|
-
createSensor(settings) {
|
|
25
|
-
return sensor_factory_1.default.create(AntHrAdapter.ANT_PROFILE_NAME, Number(settings.deviceID));
|
|
26
|
-
}
|
|
27
|
-
getName() {
|
|
28
|
-
if (this.settings.name)
|
|
29
|
-
return this.settings.name;
|
|
30
|
-
const deviceID = this.sensor.getDeviceID();
|
|
31
|
-
return `Ant+HR ${deviceID}`;
|
|
32
|
-
}
|
|
33
|
-
getUniqueName() {
|
|
34
|
-
if (this.settings.name)
|
|
35
|
-
return this.settings.name;
|
|
36
|
-
const { DeviceID, ManId } = this.deviceData;
|
|
37
|
-
const brand = (0, utils_1.getBrand)(ManId);
|
|
38
|
-
if (brand)
|
|
39
|
-
return `${brand} HR ${DeviceID}`;
|
|
40
|
-
else
|
|
41
|
-
return `${this.getName()}`;
|
|
11
|
+
this.capabilities = [types_1.IncyclistCapability.HeartRate];
|
|
42
12
|
}
|
|
43
13
|
getDisplayName() {
|
|
44
14
|
const { ComputedHeartRate } = this.deviceData;
|
|
45
15
|
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
46
16
|
return `${this.getUniqueName()}${hrmStr}`;
|
|
47
17
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.lastDataTS = Date.now();
|
|
51
|
-
super.onDeviceData(deviceData);
|
|
52
|
-
if (!this.started)
|
|
53
|
-
return;
|
|
54
|
-
if (!this.ivDataTimeout)
|
|
55
|
-
this.startDataTimeoutCheck();
|
|
56
|
-
try {
|
|
57
|
-
if (!this.canSendUpdate())
|
|
58
|
-
return;
|
|
59
|
-
this.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
60
|
-
if (this.paused)
|
|
61
|
-
return;
|
|
62
|
-
this.mapData(deviceData);
|
|
63
|
-
this.emitData(this.data);
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
mapData(deviceData) {
|
|
69
|
-
if (deviceData.ComputedHeartRate)
|
|
18
|
+
mapToAdapterData(deviceData) {
|
|
19
|
+
if (deviceData.ComputedHeartRate) {
|
|
70
20
|
this.data.heartrate = deviceData.ComputedHeartRate;
|
|
21
|
+
this.data.timestamp = Date.now();
|
|
22
|
+
}
|
|
71
23
|
}
|
|
72
24
|
hasData() {
|
|
73
25
|
return this.deviceData.ComputedHeartRate !== undefined && this.deviceData.ComputedHeartRate !== null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HeartRateSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
|
+
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
|
|
4
|
+
export default class AntHrAdapter extends AntAdapter<HeartRateSensorState> {
|
|
5
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
6
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
7
|
+
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
8
|
+
getDisplayName(): string;
|
|
9
|
+
mapToAdapterData(deviceData: HeartRateSensorState): void;
|
|
10
|
+
hasData(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 adapter_1 = __importDefault(require("../base/adapter"));
|
|
7
|
+
const types_1 = require("../../types");
|
|
8
|
+
class AntHrAdapter extends adapter_1.default {
|
|
9
|
+
constructor(settings, props) {
|
|
10
|
+
super(settings, props);
|
|
11
|
+
this.capabilities = [types_1.IncyclistCapability.HeartRate];
|
|
12
|
+
}
|
|
13
|
+
getDisplayName() {
|
|
14
|
+
const { ComputedHeartRate } = this.deviceData;
|
|
15
|
+
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
16
|
+
return `${this.getUniqueName()}${hrmStr}`;
|
|
17
|
+
}
|
|
18
|
+
mapToAdapterData(deviceData) {
|
|
19
|
+
if (deviceData.ComputedHeartRate) {
|
|
20
|
+
this.data.heartrate = deviceData.ComputedHeartRate;
|
|
21
|
+
this.data.timestamp = Date.now();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
hasData() {
|
|
25
|
+
return this.deviceData.ComputedHeartRate !== undefined && this.deviceData.ComputedHeartRate !== null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
AntHrAdapter.INCYCLIST_PROFILE_NAME = 'Heartrate Monitor';
|
|
29
|
+
AntHrAdapter.ANT_PROFILE_NAME = 'HR';
|
|
30
|
+
exports.default = AntHrAdapter;
|
|
@@ -0,0 +1,7 @@
|
|
|
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 adapter_1 = __importDefault(require("./adapter"));
|
|
7
|
+
exports.default = adapter_1.default;
|
package/lib/antv2/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import AntPwrAdapter from "./pwr";
|
|
2
2
|
import AntFEAdapter from "./fe";
|
|
3
3
|
import AntHrAdapter from "./hr";
|
|
4
|
-
import AntAdapterFactory from "./adapter-factory";
|
|
5
|
-
import AntInterface
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
4
|
+
import AntAdapterFactory from "./factories/adapter-factory";
|
|
5
|
+
import AntInterface from "./base/interface";
|
|
6
|
+
import { AntInterfaceProps } from "./types";
|
|
7
|
+
export { AntDeviceSettings, AntDeviceProperties, AntScanProps } from "./types";
|
|
8
|
+
export { AntAdapterFactory, AntFEAdapter, AntHrAdapter, AntPwrAdapter, AntInterface, AntInterfaceProps };
|