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
|
@@ -0,0 +1,337 @@
|
|
|
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 events_1 = __importDefault(require("events"));
|
|
16
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
+
const sensor_factory_1 = __importDefault(require("../factories/sensor-factory"));
|
|
18
|
+
const utils_1 = require("../../utils/utils");
|
|
19
|
+
class AntInterface extends events_1.default {
|
|
20
|
+
static getInstance(props = {}) {
|
|
21
|
+
if (AntInterface._instance === undefined)
|
|
22
|
+
AntInterface._instance = new AntInterface(props);
|
|
23
|
+
return AntInterface._instance;
|
|
24
|
+
}
|
|
25
|
+
static hasInstance() {
|
|
26
|
+
return AntInterface._instance !== undefined;
|
|
27
|
+
}
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super();
|
|
30
|
+
this.props = props;
|
|
31
|
+
this.device = undefined;
|
|
32
|
+
this.connected = false;
|
|
33
|
+
this.connectPromise = null;
|
|
34
|
+
this.logEnabled = props.log || true;
|
|
35
|
+
const { binding, logger } = props;
|
|
36
|
+
this.setLogger(logger || new gd_eventlog_1.EventLogger('Ant+'));
|
|
37
|
+
if (binding) {
|
|
38
|
+
this.setBinding(binding);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getName() {
|
|
42
|
+
return AntInterface.INTERFACE_NAME;
|
|
43
|
+
}
|
|
44
|
+
getBinding() {
|
|
45
|
+
return this.Binding;
|
|
46
|
+
}
|
|
47
|
+
setBinding(binding) {
|
|
48
|
+
this.Binding = binding;
|
|
49
|
+
}
|
|
50
|
+
getLogger() {
|
|
51
|
+
return this.logger;
|
|
52
|
+
}
|
|
53
|
+
setLogger(logger) {
|
|
54
|
+
this.logger = logger;
|
|
55
|
+
}
|
|
56
|
+
enableLogging() {
|
|
57
|
+
this.logEnabled = true;
|
|
58
|
+
}
|
|
59
|
+
disableLogging() {
|
|
60
|
+
this.logEnabled = false;
|
|
61
|
+
}
|
|
62
|
+
logEvent(event) {
|
|
63
|
+
if (!this.logEnabled || !this.logger)
|
|
64
|
+
return;
|
|
65
|
+
this.logger.logEvent(event);
|
|
66
|
+
const w = global.window;
|
|
67
|
+
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || (0, utils_1.isTrue)(process.env.ANT_DEBUG)) {
|
|
68
|
+
console.log('~~~ ANT', event);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
isConnected() {
|
|
72
|
+
return this.connected && this.device !== undefined;
|
|
73
|
+
}
|
|
74
|
+
connect() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
if (this.isConnected())
|
|
77
|
+
return true;
|
|
78
|
+
if (this.connectPromise) {
|
|
79
|
+
return yield this.connectPromise;
|
|
80
|
+
}
|
|
81
|
+
const _connect = () => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
try {
|
|
83
|
+
this.logEvent({ message: 'ANT+ connecting ...' });
|
|
84
|
+
const device = new this.Binding(Object.assign(Object.assign({}, this.props), { logger: this.logger }));
|
|
85
|
+
const opened = yield device.open();
|
|
86
|
+
if (!opened) {
|
|
87
|
+
this.logEvent({ message: 'ANT+ not connected' });
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
this.device = device;
|
|
91
|
+
this.connected = true;
|
|
92
|
+
this.logEvent({ message: 'ANT+ connected' });
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
this.logEvent({ message: 'error', fn: 'connect', error: err.message, stack: err.stack });
|
|
97
|
+
this.connected = false;
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
this.connectPromise = _connect();
|
|
102
|
+
return yield this.connectPromise;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
disconnect() {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
this.logEvent({ message: 'ANT+ disconnecting ...' });
|
|
108
|
+
let closed = false;
|
|
109
|
+
if (this.device) {
|
|
110
|
+
try {
|
|
111
|
+
closed = yield this.device.close();
|
|
112
|
+
}
|
|
113
|
+
catch (_a) {
|
|
114
|
+
closed = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
closed = true;
|
|
119
|
+
}
|
|
120
|
+
this.logEvent({ message: 'ANT+ disconnected' });
|
|
121
|
+
this.connectPromise = null;
|
|
122
|
+
this.scanPromise = null;
|
|
123
|
+
this.connected = false;
|
|
124
|
+
return closed;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
onError(profile, error) {
|
|
128
|
+
this.logEvent({ message: 'ANT+ERROR:', profile, error });
|
|
129
|
+
}
|
|
130
|
+
onData(profile, id, data, tag) {
|
|
131
|
+
this.emit('data', profile, id, data, tag);
|
|
132
|
+
}
|
|
133
|
+
getReconnectPause() {
|
|
134
|
+
return 1000;
|
|
135
|
+
}
|
|
136
|
+
scannerWaitForConnection() {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
let scanFinished = false;
|
|
139
|
+
let scanStopRequested = false;
|
|
140
|
+
this.activeScan.emitter.once('timeout', () => {
|
|
141
|
+
this.activeScan.emitter.removeAllListeners();
|
|
142
|
+
scanFinished = true;
|
|
143
|
+
});
|
|
144
|
+
this.activeScan.emitter.once('stop', () => {
|
|
145
|
+
scanStopRequested = true;
|
|
146
|
+
this.activeScan.emitter.removeAllListeners();
|
|
147
|
+
});
|
|
148
|
+
while (!this.isConnected() && !scanFinished && !scanStopRequested) {
|
|
149
|
+
const connected = yield this.connect();
|
|
150
|
+
if (!connected)
|
|
151
|
+
yield (0, utils_1.sleep)(this.getReconnectPause());
|
|
152
|
+
}
|
|
153
|
+
if (scanStopRequested)
|
|
154
|
+
this.emit('scan stopped', true);
|
|
155
|
+
this.activeScan.emitter.removeAllListeners();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
scan(props = {}) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
this.logEvent({ message: 'starting scan ..' });
|
|
161
|
+
if (this.isScanning()) {
|
|
162
|
+
return yield this.scanPromise;
|
|
163
|
+
}
|
|
164
|
+
this.activeScan = { emitter: new events_1.default() };
|
|
165
|
+
const _scan = () => new Promise((done) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const detected = [];
|
|
167
|
+
const onDetected = (profile, deviceID) => {
|
|
168
|
+
if (deviceID && detected.find(s => s.deviceID === deviceID && s.profile === profile) === undefined) {
|
|
169
|
+
try {
|
|
170
|
+
detected.push({ interface: this.getName(), profile, deviceID });
|
|
171
|
+
this.emit('device', { interface: 'ant', profile, deviceID });
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
this.logEvent({ message: 'error', fn: 'onDetected', error: err.message, stack: err.stack });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const addListeners = (channel) => {
|
|
179
|
+
channel.on('detected', onDetected);
|
|
180
|
+
channel.on('data', this.onData.bind(this));
|
|
181
|
+
channel.on('error', this.onError.bind(this));
|
|
182
|
+
};
|
|
183
|
+
const removeListeners = (channel) => {
|
|
184
|
+
channel.off('detected', onDetected);
|
|
185
|
+
channel.off('data', this.onData.bind(this));
|
|
186
|
+
channel.off('error', this.onError.bind(this));
|
|
187
|
+
};
|
|
188
|
+
yield this.scannerWaitForConnection();
|
|
189
|
+
if (!this.isConnected()) {
|
|
190
|
+
return done(detected);
|
|
191
|
+
}
|
|
192
|
+
let channel;
|
|
193
|
+
channel = this.device.getChannel();
|
|
194
|
+
if (!channel)
|
|
195
|
+
return done(detected);
|
|
196
|
+
this.activeScan.channel = channel;
|
|
197
|
+
channel.setProps({ logger: this.logger });
|
|
198
|
+
const sensors = sensor_factory_1.default.createAll();
|
|
199
|
+
sensors.forEach((sensor) => {
|
|
200
|
+
channel.attach(sensor);
|
|
201
|
+
});
|
|
202
|
+
addListeners(channel);
|
|
203
|
+
try {
|
|
204
|
+
const success = yield channel.startScanner();
|
|
205
|
+
this.logEvent({ message: 'scan started', success });
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
this.logEvent({ message: 'scan could not be started', error: err.message, stack: err.stack });
|
|
209
|
+
removeListeners(channel);
|
|
210
|
+
return done(detected);
|
|
211
|
+
}
|
|
212
|
+
this.activeScan.emitter.on('stop', () => __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
this.activeScan.emitter.removeAllListeners();
|
|
214
|
+
this.emit('stop-scan');
|
|
215
|
+
const stopped = yield this.activeScan.channel.stopScanner();
|
|
216
|
+
this.logEvent({ message: 'scan stopped' });
|
|
217
|
+
removeListeners(channel);
|
|
218
|
+
this.activeScan = undefined;
|
|
219
|
+
this.scanPromise = null;
|
|
220
|
+
this.emit('scan stopped', stopped);
|
|
221
|
+
done(detected);
|
|
222
|
+
}));
|
|
223
|
+
this.activeScan.emitter.on('timeout', () => __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
this.activeScan.emitter.removeAllListeners();
|
|
225
|
+
this.emit('stop-scan');
|
|
226
|
+
removeListeners(channel);
|
|
227
|
+
done(detected);
|
|
228
|
+
}));
|
|
229
|
+
}));
|
|
230
|
+
const { timeout } = props;
|
|
231
|
+
this.scanPromise = _scan();
|
|
232
|
+
if (timeout) {
|
|
233
|
+
const res = yield (0, utils_1.waitWithTimeout)(this.scanPromise, timeout, () => {
|
|
234
|
+
var _a;
|
|
235
|
+
(_a = this.activeScan) === null || _a === void 0 ? void 0 : _a.emitter.emit('timeout');
|
|
236
|
+
});
|
|
237
|
+
return res || [];
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const res = yield this.scanPromise;
|
|
241
|
+
this.scanPromise = null;
|
|
242
|
+
this.activeScan = null;
|
|
243
|
+
return res;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
isScanning() {
|
|
248
|
+
return this.scanPromise !== undefined && this.scanPromise !== null;
|
|
249
|
+
}
|
|
250
|
+
stopScan() {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
this.logEvent({ message: 'stopping scan ..' });
|
|
253
|
+
if (!this.isScanning())
|
|
254
|
+
return true;
|
|
255
|
+
return new Promise(done => {
|
|
256
|
+
this.activeScan.emitter.emit('stop');
|
|
257
|
+
this.once('scan stopped', (res) => {
|
|
258
|
+
done(res);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
startSensor(sensor, onDeviceData) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
if (!this.isConnected()) {
|
|
266
|
+
const connected = yield this.connect();
|
|
267
|
+
if (!connected)
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
let channel;
|
|
271
|
+
channel = this.device.getChannel();
|
|
272
|
+
if (!channel)
|
|
273
|
+
return false;
|
|
274
|
+
channel.setProps({ logger: this.logger });
|
|
275
|
+
const onData = (profile, deviceID, data, tag) => {
|
|
276
|
+
if (profile === sensor.getProfile() && deviceID === sensor.getDeviceID())
|
|
277
|
+
this.onData(profile, deviceID, data, tag);
|
|
278
|
+
onDeviceData(data);
|
|
279
|
+
};
|
|
280
|
+
channel.on('data', onData);
|
|
281
|
+
sensor.setChannel(channel);
|
|
282
|
+
try {
|
|
283
|
+
const started = yield channel.startSensor(sensor);
|
|
284
|
+
if (!started) {
|
|
285
|
+
this.logEvent({ message: 'could not start sensor' });
|
|
286
|
+
channel.off('data', onData);
|
|
287
|
+
}
|
|
288
|
+
return started;
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
this.logEvent({ message: 'could not start sensor', error: err.message, stack: err.stack });
|
|
292
|
+
channel.off('data', onData);
|
|
293
|
+
try {
|
|
294
|
+
yield channel.stopSensor(sensor);
|
|
295
|
+
}
|
|
296
|
+
catch (_a) { }
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
stopSensor(sensor) {
|
|
302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
if (!this.isConnected()) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
const channel = sensor.getChannel();
|
|
307
|
+
if (channel) {
|
|
308
|
+
try {
|
|
309
|
+
if (!channel.flush) {
|
|
310
|
+
this.logEvent({ message: 'old version of ant-channel detected' });
|
|
311
|
+
channel.flush = () => {
|
|
312
|
+
const c = channel;
|
|
313
|
+
c.messageQueue.forEach(msg => { msg.resolve(false); });
|
|
314
|
+
c.messageQueue = [];
|
|
315
|
+
c.isWriting = false;
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
channel.flush();
|
|
319
|
+
channel.removeAllListeners('data');
|
|
320
|
+
const stopped = yield channel.stopSensor(sensor);
|
|
321
|
+
return stopped;
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
this.logEvent({ message: 'could not stop sensor', error: err.message, deviceID: sensor.getDeviceID(), stack: err.stack });
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
this.logEvent({ message: 'could not stop sensor', deviceID: sensor.getDeviceID(), error: 'no channel attached' });
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
AntInterface._instance = undefined;
|
|
336
|
+
AntInterface.INTERFACE_NAME = 'ant';
|
|
337
|
+
exports.default = AntInterface;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CadenceSensorState, 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<CadenceSensorState> {
|
|
5
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
6
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
7
|
+
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
8
|
+
mapToAdapterData(deviceData: CadenceSensorState): void;
|
|
9
|
+
hasData(): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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.Cadence];
|
|
12
|
+
}
|
|
13
|
+
mapToAdapterData(deviceData) {
|
|
14
|
+
if (deviceData.CalculatedCadence) {
|
|
15
|
+
this.data.cadence = deviceData.CalculatedCadence;
|
|
16
|
+
this.data.timestamp = Date.now();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
hasData() {
|
|
20
|
+
return this.deviceData.CalculatedCadence !== undefined && this.deviceData.CalculatedCadence !== null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
AntHrAdapter.INCYCLIST_PROFILE_NAME = 'Cadence Sensor';
|
|
24
|
+
AntHrAdapter.ANT_PROFILE_NAME = 'CAD';
|
|
25
|
+
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
|
+
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData, AntAdapterInfo, AdapterQuery } from "../types";
|
|
4
|
+
export default class AntAdapterFactory {
|
|
5
|
+
protected static _instance: AntAdapterFactory | undefined;
|
|
6
|
+
protected adapters: AntAdapterInfo[];
|
|
7
|
+
static getInstance(): AntAdapterFactory;
|
|
8
|
+
constructor();
|
|
9
|
+
register<TDeviceData extends BaseDeviceData>(antProfile: Profile, incyclistProfile: LegacyProfile, Adapter: typeof AntAdapter<TDeviceData>): void;
|
|
10
|
+
_getAll(): AntAdapterInfo[];
|
|
11
|
+
getAdapter(query?: AdapterQuery): any;
|
|
12
|
+
createInstance(settings: AntDeviceSettings, props?: AntDeviceProperties): any;
|
|
13
|
+
createFromDetected(profile: Profile, deviceID: number, props?: AntDeviceProperties): any;
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
_getAll() {
|
|
21
|
+
return this.adapters;
|
|
22
|
+
}
|
|
23
|
+
getAdapter(query) {
|
|
24
|
+
const { antProfile, incyclistProfile } = query;
|
|
25
|
+
if (!antProfile && !incyclistProfile)
|
|
26
|
+
throw new Error('Illegal arguments: either "antProfile" or "incyclistProfile" must be set');
|
|
27
|
+
let found;
|
|
28
|
+
if (antProfile)
|
|
29
|
+
found = this.adapters.find(a => a.antProfile === antProfile);
|
|
30
|
+
if (!found && incyclistProfile)
|
|
31
|
+
found = this.adapters.find(a => a.incyclistProfile === incyclistProfile);
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
createInstance(settings, props) {
|
|
35
|
+
let info;
|
|
36
|
+
const { profile, protocol } = settings;
|
|
37
|
+
let isLegacy = false;
|
|
38
|
+
if (protocol) {
|
|
39
|
+
try {
|
|
40
|
+
const incyclistProfile = profile;
|
|
41
|
+
info = this.getAdapter({ incyclistProfile });
|
|
42
|
+
isLegacy = (info !== undefined && info !== null);
|
|
43
|
+
}
|
|
44
|
+
catch (_a) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!isLegacy) {
|
|
49
|
+
const antProfile = profile;
|
|
50
|
+
try {
|
|
51
|
+
info = this.getAdapter({ antProfile });
|
|
52
|
+
}
|
|
53
|
+
catch (_b) { }
|
|
54
|
+
}
|
|
55
|
+
if (info && info.Adapter) {
|
|
56
|
+
const { deviceID, interface: ifName } = settings;
|
|
57
|
+
const { antProfile } = info;
|
|
58
|
+
return new info.Adapter({ profile: antProfile, interface: ifName, deviceID }, props);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
createFromDetected(profile, deviceID, props) {
|
|
62
|
+
const info = this.getAdapter({ antProfile: profile });
|
|
63
|
+
if (!info || !info.Adapter)
|
|
64
|
+
return;
|
|
65
|
+
const settings = Object.assign({}, {
|
|
66
|
+
profile: info.antProfile,
|
|
67
|
+
deviceID: deviceID.toString(),
|
|
68
|
+
interface: 'ant'
|
|
69
|
+
});
|
|
70
|
+
return new info.Adapter(settings, props);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.default = AntAdapterFactory;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const incyclist_ant_plus_1 = require("incyclist-ant-plus");
|
|
4
|
+
const incyclist_ant_plus_2 = require("incyclist-ant-plus");
|
|
5
|
+
const profiles = [
|
|
6
|
+
{ profile: 'PWR', Class: incyclist_ant_plus_2.BicyclePowerSensor },
|
|
7
|
+
{ profile: 'HR', Class: incyclist_ant_plus_2.HeartRateSensor },
|
|
8
|
+
{ profile: 'FE', Class: incyclist_ant_plus_2.FitnessEquipmentSensor },
|
|
9
|
+
{ profile: 'CAD', Class: incyclist_ant_plus_1.CadenceSensor },
|
|
10
|
+
];
|
|
11
|
+
class SensorFactory {
|
|
12
|
+
static create(profile, deviceID) {
|
|
13
|
+
const info = profiles.find(i => i.profile === profile);
|
|
14
|
+
if (!info)
|
|
15
|
+
return;
|
|
16
|
+
return new info.Class(deviceID);
|
|
17
|
+
}
|
|
18
|
+
static createAll() {
|
|
19
|
+
return profiles.map(info => new info.Class());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = SensorFactory;
|
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
import { FitnessEquipmentSensorState,
|
|
2
|
-
import AntAdapter from "../adapter";
|
|
3
|
-
import
|
|
1
|
+
import { FitnessEquipmentSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
|
+
import { UpdateRequest } from '../../modes/types';
|
|
4
4
|
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
power: number;
|
|
10
|
-
cadence: number;
|
|
11
|
-
heartrate: number;
|
|
12
|
-
distance: number;
|
|
13
|
-
timestamp: number;
|
|
14
|
-
};
|
|
15
|
-
export declare class AntFeControl extends ControllableDevice<AntDeviceProperties> {
|
|
16
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
17
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
18
|
-
sendInitCommands(): Promise<boolean>;
|
|
5
|
+
import { IncyclistBikeData, ControllerConfig } from "../../types";
|
|
6
|
+
interface AntFEStartDeviceProperties extends AntDeviceProperties {
|
|
7
|
+
reconnect?: boolean;
|
|
8
|
+
reconnectTimeout?: number;
|
|
19
9
|
}
|
|
20
|
-
export default class AntFEAdapter extends AntAdapter<
|
|
21
|
-
static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
22
|
-
static ANT_PROFILE_NAME: Profile;
|
|
10
|
+
export default class AntFEAdapter extends AntAdapter<FitnessEquipmentSensorState> {
|
|
11
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
12
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
13
|
+
protected static controllers: ControllerConfig;
|
|
23
14
|
protected distanceInternal?: number;
|
|
24
15
|
protected startProps: AntDeviceProperties;
|
|
25
|
-
protected
|
|
26
|
-
protected sensorConnected: boolean;
|
|
16
|
+
protected promiseReconnect: Promise<boolean>;
|
|
27
17
|
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
28
|
-
createSensor(settings: AntDeviceSettings): ISensor;
|
|
29
|
-
getName(): string;
|
|
30
|
-
getUniqueName(): string;
|
|
31
18
|
getDisplayName(): string;
|
|
32
|
-
|
|
19
|
+
isReconnecting(): boolean;
|
|
33
20
|
sendUpdate(request: UpdateRequest, forced?: boolean): Promise<void>;
|
|
34
21
|
onDeviceData(deviceData: FitnessEquipmentSensorState): void;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
mapData(deviceData: FitnessEquipmentSensorState): IncyclistBikeData;
|
|
23
|
+
transformData(adapterData: IncyclistBikeData, deviceData: FitnessEquipmentSensorState): void;
|
|
24
|
+
start(props?: AntFEStartDeviceProperties): Promise<boolean>;
|
|
25
|
+
resetStartStatus(): void;
|
|
26
|
+
startPreChecks(props: AntFEStartDeviceProperties): Promise<'done' | 'connected' | 'connection-failed'>;
|
|
27
|
+
initControl(): Promise<void>;
|
|
28
|
+
sendInititalUserMessage(): Promise<void>;
|
|
29
|
+
sendInitialRequest(): Promise<void>;
|
|
39
30
|
setFEDefaultTimeout(): void;
|
|
40
31
|
stop(): Promise<boolean>;
|
|
41
32
|
reconnect(): Promise<boolean>;
|