incyclist-devices 2.1.33 → 2.1.35
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.
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { IChannel, ISensor, Profile } from 'incyclist-ant-plus';
|
|
3
4
|
import AntInterface from './interface';
|
|
4
5
|
import IncyclistDevice from '../../base/adpater';
|
|
5
6
|
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData, AdapterStartStatus } from '../types';
|
|
6
7
|
import { IAdapter, IncyclistAdapterData, IncyclistBikeData, IncyclistCapability } from '../../types';
|
|
8
|
+
import EventEmitter from 'events';
|
|
7
9
|
export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
|
|
8
10
|
sensor: ISensor;
|
|
9
11
|
data: IncyclistAdapterData;
|
|
@@ -26,6 +28,7 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData> extends Incy
|
|
|
26
28
|
protected sensorConnected: boolean;
|
|
27
29
|
protected startStatus: AdapterStartStatus;
|
|
28
30
|
protected startupRetryPause: number;
|
|
31
|
+
protected internalEmitter: EventEmitter;
|
|
29
32
|
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
30
33
|
getProfileName(): Profile;
|
|
31
34
|
getLegacyProfileName(): LegacyProfile;
|
|
@@ -21,12 +21,14 @@ const utils_2 = require("../utils");
|
|
|
21
21
|
const consts_1 = require("../consts");
|
|
22
22
|
const sensor_factory_1 = __importDefault(require("../factories/sensor-factory"));
|
|
23
23
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
24
|
+
const events_1 = __importDefault(require("events"));
|
|
24
25
|
const INTERFACE_NAME = 'ant';
|
|
25
26
|
const MAX_RETRIES = 3;
|
|
26
27
|
class AntAdapter extends adpater_1.default {
|
|
27
28
|
constructor(settings, props) {
|
|
28
29
|
super(settings, props);
|
|
29
30
|
this.startupRetryPause = 1000;
|
|
31
|
+
this.internalEmitter = new events_1.default();
|
|
30
32
|
const profile = this.getProfileName();
|
|
31
33
|
if (settings.protocol && settings.profile !== this.getLegacyProfileName())
|
|
32
34
|
throw new Error('Incorrect Profile');
|
|
@@ -126,7 +128,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
126
128
|
if (!ManId && deviceData.ManId) {
|
|
127
129
|
this.emit('device-info', this.getSettings(), { manufacturer: (0, utils_2.getBrand)(deviceData.ManId) });
|
|
128
130
|
}
|
|
129
|
-
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
131
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData', '_RawData']);
|
|
130
132
|
this.logEvent({ message: 'onDeviceData', data: logData, paused: this.paused, started: this.started, canEmit: this.canEmitData() });
|
|
131
133
|
if (this.isStopped() || !this.canEmitData())
|
|
132
134
|
return;
|
|
@@ -331,6 +333,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
331
333
|
});
|
|
332
334
|
}
|
|
333
335
|
initSensor(props) {
|
|
336
|
+
var _a, _b;
|
|
334
337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
335
338
|
this.startStatus.sensorStarted = this.sensorConnected;
|
|
336
339
|
if (this.startStatus.sensorStarted || this.startStatus.sensorStarted)
|
|
@@ -339,7 +342,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
339
342
|
try {
|
|
340
343
|
this.sensorConnected = yield this.startSensor();
|
|
341
344
|
if (this.sensorConnected) {
|
|
342
|
-
this.logEvent({ message: 'sensor started', device: this.getName(), props });
|
|
345
|
+
this.logEvent({ message: 'sensor started', device: this.getName(), channel: (_b = (_a = this.sensor) === null || _a === void 0 ? void 0 : _a.getChannel()) === null || _b === void 0 ? void 0 : _b.getChannelNo(), props });
|
|
343
346
|
this.startStatus.sensorStarted = true;
|
|
344
347
|
}
|
|
345
348
|
else {
|
|
@@ -390,8 +393,15 @@ class AntAdapter extends adpater_1.default {
|
|
|
390
393
|
this.reportStartStatus();
|
|
391
394
|
return this.started;
|
|
392
395
|
});
|
|
396
|
+
const checkInterrupt = () => new Promise(done => {
|
|
397
|
+
this.internalEmitter.on('stop', () => {
|
|
398
|
+
this.started = false;
|
|
399
|
+
this.startStatus.interrupted = true;
|
|
400
|
+
done(false);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
393
403
|
try {
|
|
394
|
-
yield (0, utils_1.runWithTimeout)(doStart(), totalTimeout);
|
|
404
|
+
yield (0, utils_1.runWithTimeout)(Promise.race([doStart(), checkInterrupt()]), totalTimeout);
|
|
395
405
|
}
|
|
396
406
|
catch (err) {
|
|
397
407
|
if (err.message === 'Timeout') {
|
|
@@ -409,6 +419,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
409
419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
410
420
|
let stopped;
|
|
411
421
|
this.logger.logEvent({ message: 'stopping device', device: this.getName() });
|
|
422
|
+
this.internalEmitter.emit('stop');
|
|
412
423
|
this.promiseWaitForData = null;
|
|
413
424
|
if (this.startStatus) {
|
|
414
425
|
this.startStatus.interrupted = true;
|
|
@@ -431,7 +442,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
431
442
|
}
|
|
432
443
|
startSensor() {
|
|
433
444
|
return __awaiter(this, void 0, void 0, function* () {
|
|
434
|
-
return this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
445
|
+
return yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
|
|
435
446
|
});
|
|
436
447
|
}
|
|
437
448
|
stopSensor() {
|
package/lib/base/adpater.js
CHANGED
|
@@ -67,9 +67,12 @@ class IncyclistDevice extends events_1.default {
|
|
|
67
67
|
}
|
|
68
68
|
restart(pause) {
|
|
69
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
this.logger.logEvent({ message: 'restarting device', device: this.getName() });
|
|
70
71
|
const stopped = yield this.stop();
|
|
71
|
-
if (!stopped)
|
|
72
|
+
if (!stopped && !this.isStopped()) {
|
|
73
|
+
this.logger.logEvent({ message: 'restarting device - stop failed', device: this.getName() });
|
|
72
74
|
return false;
|
|
75
|
+
}
|
|
73
76
|
if (pause)
|
|
74
77
|
yield (0, utils_1.sleep)(pause);
|
|
75
78
|
return yield this.start();
|
|
@@ -160,7 +160,7 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
160
160
|
}
|
|
161
161
|
const user = this.getUser();
|
|
162
162
|
const { route, onStatusUpdate, gear } = props;
|
|
163
|
-
if (this.requiresProgramUpload()) {
|
|
163
|
+
if (route && this.requiresProgramUpload()) {
|
|
164
164
|
const bikeType = this.getCyclingMode().getSetting('bikeType');
|
|
165
165
|
if (!info.upload) {
|
|
166
166
|
info.upload = yield this.getComms().programUpload(bikeType, route, onStatusUpdate);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-devices",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.35",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@serialport/bindings-interface": "^1.2.2",
|
|
6
6
|
"@serialport/parser-byte-length": "^9.0.1",
|
|
7
7
|
"@serialport/parser-delimiter": "^9.0.1",
|
|
8
8
|
"@serialport/parser-readline": "^10.5.0",
|
|
9
9
|
"@serialport/stream": "^10.5.0",
|
|
10
|
-
"incyclist-ant-plus": "^0.
|
|
10
|
+
"incyclist-ant-plus": "^0.3.0",
|
|
11
11
|
"win32filetime": "^1.0.2"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|