incyclist-devices 1.5.23 → 1.5.25
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/antv2/ant-device.d.ts +3 -0
- package/lib/antv2/ant-device.js +26 -0
- package/lib/antv2/ant-interface.js +6 -1
- package/lib/antv2/fe.d.ts +0 -1
- package/lib/antv2/fe.js +37 -13
- package/lib/antv2/hr.js +11 -5
- package/lib/antv2/pwr.js +11 -5
- package/package.json +1 -1
|
@@ -31,12 +31,15 @@ export default class AntAdapter extends IncyclistDevice implements Device {
|
|
|
31
31
|
onDataFn: OnDeviceDataCallback;
|
|
32
32
|
protected ivDataTimeout: NodeJS.Timer;
|
|
33
33
|
protected lastDataTS: number;
|
|
34
|
+
protected dataMsgCount: number;
|
|
35
|
+
private ivWaitForData;
|
|
34
36
|
constructor(sensor: ISensor, protocol: AntProtocol, settings?: any);
|
|
35
37
|
isBike(): boolean;
|
|
36
38
|
isPower(): boolean;
|
|
37
39
|
isHrm(): boolean;
|
|
38
40
|
getDisplayName(): string;
|
|
39
41
|
isSame(device: DeviceAdapter): boolean;
|
|
42
|
+
waitForData(timeout: number): Promise<unknown>;
|
|
40
43
|
getID(): string;
|
|
41
44
|
getName(): string;
|
|
42
45
|
getProfile(): string;
|
package/lib/antv2/ant-device.js
CHANGED
|
@@ -28,6 +28,7 @@ class AntAdapter extends device_1.default {
|
|
|
28
28
|
this.ignorePower = false;
|
|
29
29
|
this.deviceData = {};
|
|
30
30
|
this.data = {};
|
|
31
|
+
this.dataMsgCount = 0;
|
|
31
32
|
this.updateFrequency = exports.DEFAULT_UPDATE_FREQUENCY;
|
|
32
33
|
this.channel = undefined;
|
|
33
34
|
this.paused = false;
|
|
@@ -52,6 +53,29 @@ class AntAdapter extends device_1.default {
|
|
|
52
53
|
const adapter = device;
|
|
53
54
|
return (adapter.getID() === this.getID() && adapter.getProfile() === this.getProfile());
|
|
54
55
|
}
|
|
56
|
+
waitForData(timeout) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const startTs = Date.now();
|
|
59
|
+
const timeoutTs = startTs + timeout;
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
if (this.ivWaitForData)
|
|
62
|
+
return reject(new Error('busy'));
|
|
63
|
+
this.ivWaitForData = setInterval(() => {
|
|
64
|
+
const nowTs = Date.now();
|
|
65
|
+
if (nowTs > timeoutTs && this.dataMsgCount === 0) {
|
|
66
|
+
clearInterval(this.ivWaitForData);
|
|
67
|
+
this.ivWaitForData = undefined;
|
|
68
|
+
reject(new Error('No Data Received'));
|
|
69
|
+
}
|
|
70
|
+
if (this.dataMsgCount > 0) {
|
|
71
|
+
clearInterval(this.ivWaitForData);
|
|
72
|
+
this.ivWaitForData = undefined;
|
|
73
|
+
resolve(nowTs - startTs);
|
|
74
|
+
}
|
|
75
|
+
}, 500);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
55
79
|
getID() {
|
|
56
80
|
return this.sensor.getDeviceID().toString();
|
|
57
81
|
}
|
|
@@ -110,9 +134,11 @@ class AntAdapter extends device_1.default {
|
|
|
110
134
|
clearInterval(this.ivDataTimeout);
|
|
111
135
|
this.ivDataTimeout = undefined;
|
|
112
136
|
this.lastDataTS = undefined;
|
|
137
|
+
this.dataMsgCount = 0;
|
|
113
138
|
}
|
|
114
139
|
start(props) {
|
|
115
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
this.dataMsgCount = 0;
|
|
116
142
|
if (props && props.user)
|
|
117
143
|
this.userSettings = props.user;
|
|
118
144
|
if (props && props.bikeSettings)
|
|
@@ -235,9 +235,10 @@ class AntInterface extends events_1.default {
|
|
|
235
235
|
if (!this.isConnected || !this.device)
|
|
236
236
|
return true;
|
|
237
237
|
const channel = sensor.getChannel();
|
|
238
|
-
channel.removeAllListeners('data');
|
|
239
238
|
if (channel) {
|
|
240
239
|
try {
|
|
240
|
+
channel.flush();
|
|
241
|
+
channel.removeAllListeners('data');
|
|
241
242
|
return yield channel.stopSensor(sensor);
|
|
242
243
|
}
|
|
243
244
|
catch (err) {
|
|
@@ -245,6 +246,10 @@ class AntInterface extends events_1.default {
|
|
|
245
246
|
return false;
|
|
246
247
|
}
|
|
247
248
|
}
|
|
249
|
+
else {
|
|
250
|
+
this.logEvent({ message: 'could not stop sensor', error: 'no channel attached' });
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
248
253
|
});
|
|
249
254
|
}
|
|
250
255
|
isScanning() {
|
package/lib/antv2/fe.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export default class AntFEAdapter extends AntAdapter {
|
|
|
9
9
|
protected cyclingMode: CyclingMode;
|
|
10
10
|
protected distanceInternal?: number;
|
|
11
11
|
protected startProps: any;
|
|
12
|
-
protected msgCount: number;
|
|
13
12
|
protected isReconnecting: boolean;
|
|
14
13
|
constructor(sensor: ISensor, protocol: AntProtocol);
|
|
15
14
|
isBike(): boolean;
|
package/lib/antv2/fe.js
CHANGED
|
@@ -30,7 +30,7 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
30
30
|
this.deviceData = {
|
|
31
31
|
DeviceID: sensor.getDeviceID()
|
|
32
32
|
};
|
|
33
|
-
this.
|
|
33
|
+
this.dataMsgCount = 0;
|
|
34
34
|
this.logger = new gd_eventlog_1.EventLogger('Ant+FE');
|
|
35
35
|
this.isReconnecting = false;
|
|
36
36
|
}
|
|
@@ -118,13 +118,14 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
onDeviceData(deviceData) {
|
|
121
|
+
this.dataMsgCount++;
|
|
122
|
+
this.lastDataTS = Date.now();
|
|
121
123
|
if (!this.started || this.isStopped())
|
|
122
124
|
return;
|
|
123
|
-
this.msgCount++;
|
|
124
125
|
this.deviceData = deviceData;
|
|
125
|
-
this.
|
|
126
|
-
if (!this.ivDataTimeout)
|
|
126
|
+
if (this.dataMsgCount === 1) {
|
|
127
127
|
this.startDataTimeoutCheck();
|
|
128
|
+
}
|
|
128
129
|
try {
|
|
129
130
|
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
130
131
|
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
@@ -197,12 +198,12 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
197
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
199
|
_super.start.call(this, props);
|
|
199
200
|
this.startProps = props;
|
|
200
|
-
this.logger.logEvent({ message: '
|
|
201
|
-
this.msgCount = 0;
|
|
201
|
+
this.logger.logEvent({ message: 'starting device', props });
|
|
202
202
|
const opts = props || {};
|
|
203
203
|
const { args = {}, user = {} } = opts;
|
|
204
204
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
205
205
|
const { timeout = 20000 } = props || {};
|
|
206
|
+
const totalTimeout = timeout + 10000;
|
|
206
207
|
let to;
|
|
207
208
|
const stopTimeoutCheck = () => {
|
|
208
209
|
if (to) {
|
|
@@ -214,15 +215,33 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
214
215
|
yield this.stop();
|
|
215
216
|
reject(new Error(`could not start device, reason:timeout`));
|
|
216
217
|
to = null;
|
|
217
|
-
}),
|
|
218
|
+
}), totalTimeout);
|
|
218
219
|
this.setFEDefaultTimeout();
|
|
219
220
|
let success = false;
|
|
220
221
|
let status = { userSent: false, slopeSent: false };
|
|
221
222
|
let retry = 0;
|
|
223
|
+
let startSuccess = 0;
|
|
222
224
|
while (!success && retry < MAX_RETRIES) {
|
|
223
225
|
retry++;
|
|
224
226
|
if (!this.started) {
|
|
225
227
|
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
228
|
+
if (this.started) {
|
|
229
|
+
startSuccess++;
|
|
230
|
+
}
|
|
231
|
+
if (this.started && startSuccess === 1) {
|
|
232
|
+
try {
|
|
233
|
+
yield this.waitForData(timeout);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
stopTimeoutCheck();
|
|
237
|
+
try {
|
|
238
|
+
yield yield this.ant.stopSensor(this.sensor);
|
|
239
|
+
}
|
|
240
|
+
catch (_a) { }
|
|
241
|
+
this.started = false;
|
|
242
|
+
return reject(new Error(`could not start device, reason: ${err.message}`));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
226
245
|
status = { userSent: false, slopeSent: false };
|
|
227
246
|
}
|
|
228
247
|
if (!this.started) {
|
|
@@ -242,14 +261,14 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
242
261
|
catch (err) {
|
|
243
262
|
this.logger.logEvent({ message: 'sending FE message error', error: err.message });
|
|
244
263
|
try {
|
|
245
|
-
yield
|
|
264
|
+
yield this.ant.stopSensor(this.sensor);
|
|
246
265
|
}
|
|
247
|
-
catch (
|
|
266
|
+
catch (_b) { }
|
|
248
267
|
this.started = false;
|
|
249
268
|
}
|
|
250
269
|
success = status.userSent && status.slopeSent;
|
|
251
270
|
}
|
|
252
|
-
while (success && this.
|
|
271
|
+
while (success && this.dataMsgCount === 0) {
|
|
253
272
|
yield (0, utils_2.sleep)(500);
|
|
254
273
|
}
|
|
255
274
|
if (success) {
|
|
@@ -260,7 +279,10 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
260
279
|
else {
|
|
261
280
|
this.logger.logEvent({ message: 'start failed' });
|
|
262
281
|
stopTimeoutCheck();
|
|
263
|
-
|
|
282
|
+
if (this.started)
|
|
283
|
+
reject(new Error('could not start device, reason: could not send FE commands'));
|
|
284
|
+
else
|
|
285
|
+
reject(new Error('could not start device, reason: could not connect'));
|
|
264
286
|
}
|
|
265
287
|
}));
|
|
266
288
|
});
|
|
@@ -274,8 +296,10 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
274
296
|
stop: { get: () => super.stop }
|
|
275
297
|
});
|
|
276
298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
|
|
278
|
-
|
|
299
|
+
this.logger.logEvent({ message: 'stopping device' });
|
|
300
|
+
let stopped = yield this.ant.stopSensor(this.sensor);
|
|
301
|
+
yield _super.stop.call(this);
|
|
302
|
+
this.logger.logEvent({ message: 'stopping device done', success: stopped });
|
|
279
303
|
return stopped;
|
|
280
304
|
});
|
|
281
305
|
}
|
package/lib/antv2/hr.js
CHANGED
|
@@ -37,10 +37,11 @@ class AntHrAdapter extends ant_device_1.default {
|
|
|
37
37
|
return `${(0, utils_1.getBrand)(manID)} Hrm ${DeviceID}${hrmStr}`;
|
|
38
38
|
}
|
|
39
39
|
onDeviceData(deviceData) {
|
|
40
|
+
this.dataMsgCount++;
|
|
41
|
+
this.lastDataTS = Date.now();
|
|
40
42
|
if (!this.started)
|
|
41
43
|
return;
|
|
42
44
|
this.deviceData = deviceData;
|
|
43
|
-
this.lastDataTS = Date.now();
|
|
44
45
|
if (!this.ivDataTimeout)
|
|
45
46
|
this.startDataTimeoutCheck();
|
|
46
47
|
try {
|
|
@@ -67,7 +68,7 @@ class AntHrAdapter extends ant_device_1.default {
|
|
|
67
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
69
|
_super.start.call(this, props);
|
|
69
70
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const { timeout } = props || {};
|
|
71
|
+
const { timeout = 20000 } = props || {};
|
|
71
72
|
let to;
|
|
72
73
|
if (timeout) {
|
|
73
74
|
to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -76,9 +77,14 @@ class AntHrAdapter extends ant_device_1.default {
|
|
|
76
77
|
}), timeout);
|
|
77
78
|
}
|
|
78
79
|
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
try {
|
|
81
|
+
yield this.waitForData(timeout - 100);
|
|
82
|
+
if (to)
|
|
83
|
+
clearTimeout(to);
|
|
84
|
+
resolve(this.started);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
}
|
|
82
88
|
}));
|
|
83
89
|
});
|
|
84
90
|
}
|
package/lib/antv2/pwr.js
CHANGED
|
@@ -55,10 +55,11 @@ class AntPwrAdapter extends ant_device_1.default {
|
|
|
55
55
|
return logData;
|
|
56
56
|
}
|
|
57
57
|
onDeviceData(deviceData) {
|
|
58
|
+
this.dataMsgCount++;
|
|
59
|
+
this.lastDataTS = Date.now();
|
|
58
60
|
if (!this.started)
|
|
59
61
|
return;
|
|
60
62
|
this.deviceData = deviceData;
|
|
61
|
-
this.lastDataTS = Date.now();
|
|
62
63
|
if (!this.ivDataTimeout)
|
|
63
64
|
this.startDataTimeoutCheck();
|
|
64
65
|
try {
|
|
@@ -135,7 +136,7 @@ class AntPwrAdapter extends ant_device_1.default {
|
|
|
135
136
|
return true;
|
|
136
137
|
_super.start.call(this, props);
|
|
137
138
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
const { timeout } = props || {};
|
|
139
|
+
const { timeout = 20000 } = props || {};
|
|
139
140
|
let to;
|
|
140
141
|
if (timeout) {
|
|
141
142
|
to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -144,9 +145,14 @@ class AntPwrAdapter extends ant_device_1.default {
|
|
|
144
145
|
}), timeout);
|
|
145
146
|
}
|
|
146
147
|
this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
try {
|
|
149
|
+
yield this.waitForData(timeout - 100);
|
|
150
|
+
if (to)
|
|
151
|
+
clearTimeout(to);
|
|
152
|
+
resolve(this.started);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
}
|
|
150
156
|
}));
|
|
151
157
|
});
|
|
152
158
|
}
|