incyclist-devices 2.1.32 → 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.
- package/lib/antv2/base/adapter.d.ts +3 -0
- package/lib/antv2/base/adapter.js +15 -4
- package/lib/base/adpater.js +4 -1
- package/lib/serial/daum/DaumAdapter.d.ts +1 -0
- package/lib/serial/daum/DaumAdapter.js +8 -1
- package/lib/serial/daum/classic/adapter.js +19 -4
- package/lib/serial/daum/premium/adapter.d.ts +1 -1
- package/lib/serial/daum/premium/adapter.js +25 -9
- package/package.json +2 -2
- package/lib/adapters.d.ts +0 -7
- package/lib/adapters.js +0 -49
- package/lib/antv2/adapter-factory.d.ts +0 -14
- package/lib/antv2/adapter-factory.js +0 -65
- package/lib/antv2/adapter.d.ts +0 -54
- package/lib/antv2/adapter.js +0 -291
- package/lib/antv2/ant-interface.d.ts +0 -35
- package/lib/antv2/ant-interface.js +0 -285
- package/lib/antv2/base/ant-interface.d.ts +0 -35
- package/lib/antv2/base/ant-interface.js +0 -285
- package/lib/antv2/binding.d.ts +0 -13
- package/lib/antv2/binding.js +0 -27
- package/lib/antv2/hr copy/adapter.d.ts +0 -11
- package/lib/antv2/hr copy/adapter.js +0 -30
- package/lib/antv2/hr copy/index.d.ts +0 -2
- package/lib/antv2/hr copy/index.js +0 -7
- package/lib/antv2/sensor-factory.d.ts +0 -5
- package/lib/antv2/sensor-factory.js +0 -20
- package/lib/interfaces.d.ts +0 -7
- package/lib/interfaces.js +0 -27
- package/lib/serial/SinglePathScanner.d.ts +0 -17
- package/lib/serial/SinglePathScanner.js +0 -87
- package/lib/serial/adapter-factory.d.ts +0 -14
- package/lib/serial/adapter-factory.js +0 -30
- package/lib/serial/adapter.d.ts +0 -17
- package/lib/serial/adapter.js +0 -67
- package/lib/serial/comm.d.ts +0 -7
- package/lib/serial/comm.js +0 -2
- package/lib/serial/comms.d.ts +0 -62
- package/lib/serial/comms.js +0 -280
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +0 -2
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +0 -5
- package/lib/serial/daum/consts.d.ts +0 -0
- package/lib/serial/daum/consts.js +0 -0
- package/lib/serial/serial-interface.d.ts +0 -36
- package/lib/serial/serial-interface.js +0 -288
- package/lib/serial/serial-scanner.d.ts +0 -16
- package/lib/serial/serial-scanner.js +0 -87
- package/lib/serial/serialport.d.ts +0 -17
- package/lib/serial/serialport.js +0 -87
- package/lib/types/Command.d.ts +0 -8
- package/lib/types/Command.js +0 -2
- package/lib/types/command.d.ts +0 -0
- package/lib/types/command.js +0 -0
- package/lib/types/route.d.ts +0 -0
- package/lib/types/route.js +0 -0
- package/lib/types/types.d.ts +0 -8
- package/lib/types/types.js +0 -2
|
@@ -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();
|
|
@@ -24,6 +24,7 @@ export default class DaumAdapter<S extends SerialDeviceSettings, P extends Devic
|
|
|
24
24
|
updateBusy: boolean;
|
|
25
25
|
startPromise: Promise<boolean>;
|
|
26
26
|
checkPromise: Promise<boolean>;
|
|
27
|
+
internalEmitter: EventEmitter;
|
|
27
28
|
constructor(settings: S, props?: P);
|
|
28
29
|
getPort(): string;
|
|
29
30
|
getSerialInterface(): SerialInterface;
|
|
@@ -26,6 +26,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
26
26
|
this.adapterTime = 0;
|
|
27
27
|
this.requestBusy = false;
|
|
28
28
|
this.updateBusy = false;
|
|
29
|
+
this.internalEmitter = new events_1.default();
|
|
29
30
|
this.iv = undefined;
|
|
30
31
|
this.deviceData = {
|
|
31
32
|
isPedalling: false,
|
|
@@ -216,7 +217,9 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
216
217
|
this.started = true;
|
|
217
218
|
return true;
|
|
218
219
|
}));
|
|
220
|
+
this.internalEmitter.emit('start');
|
|
219
221
|
const started = yield this.startPromise;
|
|
222
|
+
this.internalEmitter.emit('started', started);
|
|
220
223
|
this.startPromise = undefined;
|
|
221
224
|
return started;
|
|
222
225
|
}
|
|
@@ -340,8 +343,11 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
340
343
|
}
|
|
341
344
|
stop() {
|
|
342
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
343
|
-
|
|
346
|
+
console.log('~~~ STOP', this.stopped);
|
|
347
|
+
if (this.stopped) {
|
|
344
348
|
return true;
|
|
349
|
+
}
|
|
350
|
+
this.internalEmitter.emit('stop');
|
|
345
351
|
this.logEvent({ message: 'stop request', port: this.getPort() });
|
|
346
352
|
if (this.paused)
|
|
347
353
|
this.resume();
|
|
@@ -355,6 +361,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
355
361
|
this.logEvent({ message: 'stop request failed', port: this.getPort(), reason: err.message });
|
|
356
362
|
throw (err);
|
|
357
363
|
}
|
|
364
|
+
this.internalEmitter.emit('stopped', this.stopped);
|
|
358
365
|
return this.stopped;
|
|
359
366
|
});
|
|
360
367
|
}
|
|
@@ -99,9 +99,14 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
99
99
|
const user = this.getUser();
|
|
100
100
|
const { gear = consts_1.DEFAULT_GEAR } = props;
|
|
101
101
|
this.initData();
|
|
102
|
+
let stopped = false;
|
|
102
103
|
let startState = {};
|
|
103
|
-
|
|
104
|
+
const start = () => __awaiter(this, void 0, void 0, function* () {
|
|
104
105
|
try {
|
|
106
|
+
if (stopped) {
|
|
107
|
+
this.started = false;
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
105
110
|
this.logEvent({ message: 'start attempt', isRelaunch, isConnected: this.getComms().isConnected() });
|
|
106
111
|
if (!isRelaunch && !this.getComms().isConnected()) {
|
|
107
112
|
yield this.verifyConnection();
|
|
@@ -136,13 +141,15 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
136
141
|
startState.checkRunData = true;
|
|
137
142
|
const data = yield this.getComms().runData();
|
|
138
143
|
if (startRequest.targetPower && startRequest.targetPower !== 25 && data.power === 25) {
|
|
139
|
-
throw new Error('invalid device response: runData');
|
|
144
|
+
throw (new Error('invalid device response: runData'));
|
|
140
145
|
}
|
|
141
146
|
this.started = true;
|
|
142
147
|
this.startUpdatePull();
|
|
143
|
-
return true;
|
|
148
|
+
return (true);
|
|
144
149
|
}
|
|
145
150
|
catch (err) {
|
|
151
|
+
if (stopped)
|
|
152
|
+
return false;
|
|
146
153
|
this.logEvent({ message: 'start attempt failed', error: err.message });
|
|
147
154
|
this.started = false;
|
|
148
155
|
if (startState.checkRunData) {
|
|
@@ -150,7 +157,15 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
150
157
|
}
|
|
151
158
|
throw (new Error(`could not start device, reason:${err.message}`));
|
|
152
159
|
}
|
|
153
|
-
})
|
|
160
|
+
});
|
|
161
|
+
const checkInterrupt = () => new Promise(done => {
|
|
162
|
+
this.internalEmitter.on('stop', () => {
|
|
163
|
+
stopped = true;
|
|
164
|
+
this.started = false;
|
|
165
|
+
done(false);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return (0, utils_1.runWithRetries)(() => Promise.race([start(), checkInterrupt()]), 5, 1000);
|
|
154
169
|
}
|
|
155
170
|
getCurrentBikeData() {
|
|
156
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -21,7 +21,7 @@ export default class DaumPremiumAdapter extends DaumAdapter<SerialDeviceSettings
|
|
|
21
21
|
getStartRetries(): number;
|
|
22
22
|
getStartRetryTimeout(): number;
|
|
23
23
|
restart(pause?: number): Promise<boolean>;
|
|
24
|
-
performStart(props?: DaumPremiumDeviceProperties, _isRelaunch?: boolean, wasPaused?: boolean): Promise<
|
|
24
|
+
performStart(props?: DaumPremiumDeviceProperties, _isRelaunch?: boolean, wasPaused?: boolean): Promise<any>;
|
|
25
25
|
requiresProgramUpload(): boolean;
|
|
26
26
|
getCurrentBikeData(): Promise<IncyclistBikeData>;
|
|
27
27
|
getDeviceInfo(): Promise<any>;
|
|
@@ -139,8 +139,12 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
139
139
|
if (!wasPaused)
|
|
140
140
|
yield this.stop();
|
|
141
141
|
var info = {};
|
|
142
|
-
|
|
142
|
+
let stopped = false;
|
|
143
|
+
this.stopped = false;
|
|
144
|
+
const start = () => __awaiter(this, void 0, void 0, function* () {
|
|
143
145
|
try {
|
|
146
|
+
if (stopped)
|
|
147
|
+
return false;
|
|
144
148
|
if (wasPaused) {
|
|
145
149
|
info.deviceType = 'Resumed';
|
|
146
150
|
info.version = "Resumed";
|
|
@@ -156,7 +160,7 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
156
160
|
}
|
|
157
161
|
const user = this.getUser();
|
|
158
162
|
const { route, onStatusUpdate, gear } = props;
|
|
159
|
-
if (this.requiresProgramUpload()) {
|
|
163
|
+
if (route && this.requiresProgramUpload()) {
|
|
160
164
|
const bikeType = this.getCyclingMode().getSetting('bikeType');
|
|
161
165
|
if (!info.upload) {
|
|
162
166
|
info.upload = yield this.getComms().programUpload(bikeType, route, onStatusUpdate);
|
|
@@ -177,21 +181,33 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
177
181
|
if (!this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
178
182
|
info.gear = yield this.getComms().setGear(this.deviceData.gear || gear || DEFAULT_GEAR);
|
|
179
183
|
}
|
|
180
|
-
return;
|
|
184
|
+
return true;
|
|
181
185
|
}
|
|
182
186
|
catch (err) {
|
|
187
|
+
if (stopped)
|
|
188
|
+
return false;
|
|
183
189
|
if (info.connected && !info.deviceType) {
|
|
184
190
|
yield (0, utils_1.sleep)(500);
|
|
185
191
|
yield this.reconnect();
|
|
186
192
|
}
|
|
187
193
|
throw (err);
|
|
188
194
|
}
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
});
|
|
196
|
+
const checkInterrupt = () => new Promise(done => {
|
|
197
|
+
this.internalEmitter.on('stop', () => {
|
|
198
|
+
stopped = true;
|
|
199
|
+
this.started = false;
|
|
200
|
+
done(false);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
const started = yield (0, utils_1.runWithRetries)(() => Promise.race([start(), checkInterrupt()]), this.getStartRetries(), this.getStartRetryTimeout());
|
|
204
|
+
if (started) {
|
|
205
|
+
this.stopped = false;
|
|
206
|
+
this.paused = false;
|
|
207
|
+
this.started = true;
|
|
208
|
+
this.startUpdatePull();
|
|
209
|
+
}
|
|
210
|
+
return started;
|
|
195
211
|
});
|
|
196
212
|
}
|
|
197
213
|
requiresProgramUpload() {
|
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": {
|
package/lib/adapters.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IncyclistDeviceAdapter } from "./base/adpater";
|
|
2
|
-
import { DeviceProperties, DeviceSettings } from "./types/device";
|
|
3
|
-
export default class AdapterFactory {
|
|
4
|
-
static adapters: IncyclistDeviceAdapter[];
|
|
5
|
-
static reset(): void;
|
|
6
|
-
static create(settings: DeviceSettings, props?: DeviceProperties): any;
|
|
7
|
-
}
|
package/lib/adapters.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const antv2_1 = require("./antv2");
|
|
4
|
-
const ble_1 = require("./ble");
|
|
5
|
-
const serial_1 = require("./serial");
|
|
6
|
-
const Simulator_1 = require("./simulator/Simulator");
|
|
7
|
-
const device_1 = require("./types/device");
|
|
8
|
-
class AdapterFactory {
|
|
9
|
-
static reset() {
|
|
10
|
-
AdapterFactory.adapters = [];
|
|
11
|
-
ble_1.BleAdapterFactory.getInstance().instances = [];
|
|
12
|
-
}
|
|
13
|
-
static create(settings, props) {
|
|
14
|
-
const adapters = AdapterFactory.adapters;
|
|
15
|
-
if (!settings.interface && settings.protocol === 'Simulator') {
|
|
16
|
-
const adapter = new Simulator_1.Simulator(settings);
|
|
17
|
-
if (adapter) {
|
|
18
|
-
adapters.push(adapter);
|
|
19
|
-
}
|
|
20
|
-
return adapter;
|
|
21
|
-
}
|
|
22
|
-
const existing = adapters.find(a => a.isEqual(settings));
|
|
23
|
-
if (existing)
|
|
24
|
-
return existing;
|
|
25
|
-
const ifaceName = typeof settings.interface === 'string' ? settings.interface : settings.interface.getName();
|
|
26
|
-
let adapter;
|
|
27
|
-
switch (ifaceName) {
|
|
28
|
-
case device_1.INTERFACE.SERIAL:
|
|
29
|
-
case device_1.INTERFACE.TCPIP:
|
|
30
|
-
adapter = serial_1.SerialAdapterFactory.getInstance().createInstance(settings, props);
|
|
31
|
-
break;
|
|
32
|
-
case device_1.INTERFACE.ANT:
|
|
33
|
-
adapter = antv2_1.AntAdapterFactory.getInstance().createInstance(settings, props);
|
|
34
|
-
break;
|
|
35
|
-
case device_1.INTERFACE.BLE:
|
|
36
|
-
adapter = ble_1.BleAdapterFactory.getInstance().createInstance(settings, props);
|
|
37
|
-
break;
|
|
38
|
-
case device_1.INTERFACE.SIMULATOR:
|
|
39
|
-
adapter = new Simulator_1.Simulator(settings, props);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
if (adapter) {
|
|
43
|
-
adapters.push(adapter);
|
|
44
|
-
}
|
|
45
|
-
return adapter;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
AdapterFactory.adapters = [];
|
|
49
|
-
exports.default = AdapterFactory;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Profile } from "incyclist-ant-plus";
|
|
2
|
-
import AntAdapter from "./base/adapter";
|
|
3
|
-
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData } from "./types";
|
|
4
|
-
import { AntAdapterInfo, AdapterQuery } from "./types";
|
|
5
|
-
export default class AntAdapterFactory {
|
|
6
|
-
static _instance: AntAdapterFactory;
|
|
7
|
-
adapters: AntAdapterInfo[];
|
|
8
|
-
static getInstance(): AntAdapterFactory;
|
|
9
|
-
constructor();
|
|
10
|
-
register<TDeviceData extends BaseDeviceData>(antProfile: Profile, incyclistProfile: LegacyProfile, Adapter: typeof AntAdapter<TDeviceData>): void;
|
|
11
|
-
getAdapter(query?: AdapterQuery): any;
|
|
12
|
-
createInstance(settings: AntDeviceSettings, props?: AntDeviceProperties): any;
|
|
13
|
-
createFromDetected(profile: Profile, deviceID: number, props?: AntDeviceProperties): any;
|
|
14
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class AntAdapterFactory {
|
|
4
|
-
static getInstance() {
|
|
5
|
-
if (!AntAdapterFactory._instance)
|
|
6
|
-
AntAdapterFactory._instance = new AntAdapterFactory();
|
|
7
|
-
return AntAdapterFactory._instance;
|
|
8
|
-
}
|
|
9
|
-
constructor() {
|
|
10
|
-
this.adapters = [];
|
|
11
|
-
}
|
|
12
|
-
register(antProfile, incyclistProfile, Adapter) {
|
|
13
|
-
const info = Object.assign({}, { antProfile, incyclistProfile, Adapter });
|
|
14
|
-
const existing = this.adapters.findIndex(a => a.antProfile === antProfile);
|
|
15
|
-
if (existing !== -1)
|
|
16
|
-
this.adapters[existing] = info;
|
|
17
|
-
else
|
|
18
|
-
this.adapters.push(info);
|
|
19
|
-
}
|
|
20
|
-
getAdapter(query) {
|
|
21
|
-
const { antProfile, incyclistProfile } = query;
|
|
22
|
-
if (!antProfile && !incyclistProfile)
|
|
23
|
-
throw new Error('Illegal arguments: either "antProfile" or "incyclistProfile" must be set');
|
|
24
|
-
let found;
|
|
25
|
-
if (antProfile)
|
|
26
|
-
found = this.adapters.find(a => a.antProfile === antProfile);
|
|
27
|
-
if (incyclistProfile)
|
|
28
|
-
found = this.adapters.find(a => a.incyclistProfile === incyclistProfile);
|
|
29
|
-
return found;
|
|
30
|
-
}
|
|
31
|
-
createInstance(settings, props) {
|
|
32
|
-
let info;
|
|
33
|
-
const { profile, protocol } = settings;
|
|
34
|
-
let isLegacy = false;
|
|
35
|
-
if (protocol) {
|
|
36
|
-
try {
|
|
37
|
-
const incyclistProfile = profile;
|
|
38
|
-
info = this.getAdapter({ incyclistProfile });
|
|
39
|
-
isLegacy = true;
|
|
40
|
-
}
|
|
41
|
-
catch (_a) {
|
|
42
|
-
isLegacy = false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!isLegacy) {
|
|
46
|
-
const antProfile = profile;
|
|
47
|
-
info = this.getAdapter({ antProfile });
|
|
48
|
-
}
|
|
49
|
-
if (info && info.Adapter)
|
|
50
|
-
return new info.Adapter(settings, props);
|
|
51
|
-
}
|
|
52
|
-
createFromDetected(profile, deviceID, props) {
|
|
53
|
-
const info = this.getAdapter({ antProfile: profile });
|
|
54
|
-
if (!info || !info.Adapter)
|
|
55
|
-
return;
|
|
56
|
-
const settings = Object.assign({}, {
|
|
57
|
-
profile: info.incyclistProfile,
|
|
58
|
-
deviceID: deviceID.toString(),
|
|
59
|
-
interface: 'ant',
|
|
60
|
-
protocol: 'Ant'
|
|
61
|
-
});
|
|
62
|
-
return new info.Adapter(settings, props);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.default = AntAdapterFactory;
|
package/lib/antv2/adapter.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IChannel, ISensor, Profile } from 'incyclist-ant-plus';
|
|
3
|
-
import AntInterface from './ant-interface';
|
|
4
|
-
import IncyclistDevice from '../base/adpater';
|
|
5
|
-
import { AntDeviceProperties, AntDeviceSettings, BaseDeviceData } from './types';
|
|
6
|
-
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../types';
|
|
7
|
-
export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
|
|
8
|
-
sensor: ISensor;
|
|
9
|
-
data: IncyclistAdapterData;
|
|
10
|
-
deviceData: TDeviceData;
|
|
11
|
-
updateFrequency: number;
|
|
12
|
-
channel: IChannel;
|
|
13
|
-
ant: AntInterface;
|
|
14
|
-
userSettings: {
|
|
15
|
-
weight?: number;
|
|
16
|
-
};
|
|
17
|
-
bikeSettings: {
|
|
18
|
-
weight?: number;
|
|
19
|
-
};
|
|
20
|
-
onDataFn: (data: IncyclistAdapterData) => void;
|
|
21
|
-
startupRetryPause: number;
|
|
22
|
-
protected ivDataTimeout: NodeJS.Timeout;
|
|
23
|
-
protected lastDataTS: number;
|
|
24
|
-
protected dataMsgCount: number;
|
|
25
|
-
protected ivWaitForData: NodeJS.Timeout;
|
|
26
|
-
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
27
|
-
createSensor(settings: AntDeviceSettings): ISensor;
|
|
28
|
-
isEqual(settings: AntDeviceSettings): boolean;
|
|
29
|
-
connect(): Promise<boolean>;
|
|
30
|
-
close(): Promise<boolean>;
|
|
31
|
-
resetData(): void;
|
|
32
|
-
isSame(device: IAdapter): boolean;
|
|
33
|
-
hasData(): boolean;
|
|
34
|
-
mapData(deviceData: TDeviceData): IncyclistBikeData;
|
|
35
|
-
transformData(data: IncyclistBikeData): void;
|
|
36
|
-
mapToAdapterData(deviceData: any): void;
|
|
37
|
-
onDeviceData(deviceData: TDeviceData): void;
|
|
38
|
-
isWaitingForData(): boolean;
|
|
39
|
-
waitForData(timeout: number): Promise<boolean>;
|
|
40
|
-
getID(): string;
|
|
41
|
-
getName(): string;
|
|
42
|
-
getInterface(): string;
|
|
43
|
-
getProfile(): Profile;
|
|
44
|
-
getLogData(data: any, excludeList: any): any;
|
|
45
|
-
triggerTimeoutCheck(): void;
|
|
46
|
-
startDataTimeoutCheck(): void;
|
|
47
|
-
stopDataTimeoutCheck(): void;
|
|
48
|
-
check(): Promise<boolean>;
|
|
49
|
-
checkCapabilities(): Promise<void>;
|
|
50
|
-
initControl(): Promise<void>;
|
|
51
|
-
sendUpdate(request: any): void;
|
|
52
|
-
start(props?: AntDeviceProperties): Promise<boolean>;
|
|
53
|
-
stop(): Promise<boolean>;
|
|
54
|
-
}
|