incyclist-devices 1.4.58 → 1.4.61
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.
|
@@ -61,6 +61,8 @@ export default class BleInterface extends BleInterfaceClass {
|
|
|
61
61
|
disconnect(): Promise<boolean>;
|
|
62
62
|
isConnected(): boolean;
|
|
63
63
|
getDevicesFromServices(deviceTypes: (typeof BleDeviceClass)[], services: string | string[]): (typeof BleDeviceClass)[];
|
|
64
|
+
getAllSupportedServices(): any[];
|
|
65
|
+
getAllSupportedDeviceTypes(): (typeof BleDeviceClass)[];
|
|
64
66
|
getServicesFromDeviceTypes(deviceTypes: (typeof BleDeviceClass)[]): string[];
|
|
65
67
|
getServicesFromDevice(device: BleDeviceClass): string[];
|
|
66
68
|
waitForConnectFinished(timeout: any): Promise<unknown>;
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -18,8 +18,6 @@ const ble_1 = require("./ble");
|
|
|
18
18
|
const ble_peripheral_1 = __importDefault(require("./ble-peripheral"));
|
|
19
19
|
const CONNECT_TIMEOUT = 5000;
|
|
20
20
|
const DEFAULT_SCAN_TIMEOUT = 20000;
|
|
21
|
-
const BACKGROUND_SCAN_TIMEOUT = 30000;
|
|
22
|
-
const DEFAULT_SERVICES = ['1818', '180d', '1826'];
|
|
23
21
|
class BleInterface extends ble_1.BleInterfaceClass {
|
|
24
22
|
constructor(props = {}) {
|
|
25
23
|
super(props);
|
|
@@ -76,14 +74,6 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
76
74
|
const timeout = props.timeout || 2000;
|
|
77
75
|
const runBackgroundScan = () => {
|
|
78
76
|
return;
|
|
79
|
-
this.scanState.isBackgroundScan = true;
|
|
80
|
-
this.scan({ timeout: BACKGROUND_SCAN_TIMEOUT, isBackgroundScan: true })
|
|
81
|
-
.then(() => {
|
|
82
|
-
this.scanState.isBackgroundScan = false;
|
|
83
|
-
})
|
|
84
|
-
.catch(() => {
|
|
85
|
-
this.scanState.isBackgroundScan = false;
|
|
86
|
-
});
|
|
87
77
|
};
|
|
88
78
|
return new Promise((resolve, reject) => {
|
|
89
79
|
if (this.connectState.isConnected) {
|
|
@@ -223,6 +213,25 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
223
213
|
}
|
|
224
214
|
return [];
|
|
225
215
|
}
|
|
216
|
+
getAllSupportedServices() {
|
|
217
|
+
const supported = BleInterface.deviceClasses;
|
|
218
|
+
const res = [];
|
|
219
|
+
if (supported && supported.length > 0) {
|
|
220
|
+
supported.forEach(dc => {
|
|
221
|
+
if (dc && dc.services) {
|
|
222
|
+
dc.services.forEach(s => {
|
|
223
|
+
if (!res.includes(s))
|
|
224
|
+
res.push(s);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return res;
|
|
230
|
+
}
|
|
231
|
+
getAllSupportedDeviceTypes() {
|
|
232
|
+
const supported = BleInterface.deviceClasses;
|
|
233
|
+
return supported.map(dc => dc.Class);
|
|
234
|
+
}
|
|
226
235
|
getServicesFromDeviceTypes(deviceTypes) {
|
|
227
236
|
let services = [];
|
|
228
237
|
try {
|
|
@@ -369,7 +378,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
369
378
|
this.scanState.isConnecting = true;
|
|
370
379
|
const existing = this.devices.find(i => (!profile || i.device.getProfile() === profile) && (i.device.address === requested.address || i.device.id === requested.id || i.device.name === requested.name));
|
|
371
380
|
if (existing) {
|
|
372
|
-
|
|
381
|
+
yield existing.device.connect();
|
|
373
382
|
this.scanState.isConnecting = false;
|
|
374
383
|
return existing.device;
|
|
375
384
|
}
|
|
@@ -453,7 +462,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
453
462
|
}
|
|
454
463
|
scan(props) {
|
|
455
464
|
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
-
const { timeout = DEFAULT_SCAN_TIMEOUT, deviceTypes = [], requested } = props;
|
|
465
|
+
const { timeout = DEFAULT_SCAN_TIMEOUT, deviceTypes = [], requested, isBackgroundScan } = props;
|
|
457
466
|
let profile;
|
|
458
467
|
if (requested)
|
|
459
468
|
profile = requested instanceof ble_1.BleDeviceClass ?
|
|
@@ -461,7 +470,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
461
470
|
requested.profile;
|
|
462
471
|
const { id, address, name } = requested || {};
|
|
463
472
|
const scanForDevice = (requested !== null && requested !== undefined);
|
|
464
|
-
const services = (props.isBackgroundScan || !deviceTypes || deviceTypes.length === 0) ?
|
|
473
|
+
const services = (props.isBackgroundScan || !deviceTypes || deviceTypes.length === 0) ? this.getAllSupportedServices() : this.getServicesFromDeviceTypes(deviceTypes);
|
|
465
474
|
const bleBinding = this.getBinding();
|
|
466
475
|
if (!bleBinding)
|
|
467
476
|
return Promise.reject(new Error('no binding defined'));
|
|
@@ -470,7 +479,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
470
479
|
}
|
|
471
480
|
const peripheralsProcessed = [];
|
|
472
481
|
const devicesProcessed = [];
|
|
473
|
-
this.logEvent({ message: 'scan()', props, scanState: this.scanState,
|
|
482
|
+
this.logEvent({ message: 'scan()', props: { timeout, isBackgroundScan }, scanState: this.scanState,
|
|
474
483
|
peripheralCache: this.peripheralCache.map(i => ({ address: i.address, ts: i.ts, name: i.peripheral ? i.peripheral.advertisement.localName : '' })),
|
|
475
484
|
deviceCache: this.devices.map(i => ({ address: i.device.address, profile: i.device.getProfile(), isConnected: i.isConnected }))
|
|
476
485
|
});
|
|
@@ -485,7 +494,8 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
485
494
|
}
|
|
486
495
|
else {
|
|
487
496
|
opStr = 'scan';
|
|
488
|
-
|
|
497
|
+
const supported = BleInterface.deviceClasses.map(dc => ({ id: dc.id, type: dc.type, services: dc.services }));
|
|
498
|
+
this.logEvent({ message: 'scan start', services, supported });
|
|
489
499
|
}
|
|
490
500
|
if (this.scanState.isScanning) {
|
|
491
501
|
try {
|
|
@@ -506,6 +516,8 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
506
516
|
const knownDevices = this.devices.map(i => ({ name: i.device.name, address: i.device.address, isConnected: i.isConnected, connectState: i.device.getConnectState() }));
|
|
507
517
|
this.logEvent({ message: `${opStr}: check if already registered`, device: { name, address }, knownDevices });
|
|
508
518
|
const existing = this.devices.find(i => (i.device.address === address || i.device.name === name || i.device.id === id));
|
|
519
|
+
if (existing)
|
|
520
|
+
this.logEvent({ message: `${opStr}: device already registered`, device: { name, address } });
|
|
509
521
|
}
|
|
510
522
|
}
|
|
511
523
|
const onTimeout = () => {
|
|
@@ -539,8 +551,6 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
539
551
|
if (isPeripheralProcessed)
|
|
540
552
|
return;
|
|
541
553
|
peripheralsProcessed.push(peripheral.address);
|
|
542
|
-
let chachedPeripheralInfo = this.peripheralCache.find(i => i.address === peripheral.address);
|
|
543
|
-
const str = fromCache ? 'added' : 'detected';
|
|
544
554
|
const characteristics = yield this.getCharacteristics(peripheral);
|
|
545
555
|
const DeviceClasses = this.getDeviceClasses(peripheral, { profile });
|
|
546
556
|
let cntFound = 0;
|
|
@@ -39,7 +39,7 @@ const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
|
39
39
|
const fm_1 = __importStar(require("./fm"));
|
|
40
40
|
const hrm_1 = __importStar(require("./hrm"));
|
|
41
41
|
const pwr_1 = __importStar(require("./pwr"));
|
|
42
|
-
const
|
|
42
|
+
const wahoo_kickr_1 = __importDefault(require("./wahoo-kickr"));
|
|
43
43
|
class BleProtocol extends DeviceProtocol_1.default {
|
|
44
44
|
constructor(binding) {
|
|
45
45
|
super();
|
|
@@ -79,9 +79,13 @@ class BleProtocol extends DeviceProtocol_1.default {
|
|
|
79
79
|
if (fromDevice)
|
|
80
80
|
device = bleDevice;
|
|
81
81
|
else {
|
|
82
|
-
device = this.ble.findDeviceInCache(Object.assign(Object.assign({}, props()), { profile
|
|
83
|
-
if (!device)
|
|
84
|
-
|
|
82
|
+
device = this.ble.findDeviceInCache(Object.assign(Object.assign({}, props()), { profile }));
|
|
83
|
+
if (!device) {
|
|
84
|
+
if (profile.toLocaleLowerCase() === 'wahoo smart trainer')
|
|
85
|
+
device = new wahoo_kickr_1.default(props());
|
|
86
|
+
else
|
|
87
|
+
device = new fm_1.default(props());
|
|
88
|
+
}
|
|
85
89
|
}
|
|
86
90
|
return new fm_1.FmAdapter(device, this);
|
|
87
91
|
case 'cp':
|
|
@@ -109,6 +113,7 @@ class BleProtocol extends DeviceProtocol_1.default {
|
|
|
109
113
|
}
|
|
110
114
|
});
|
|
111
115
|
this.logger.logEvent({ message: 'scan started' });
|
|
116
|
+
const supportedDeviceTypes = this.ble.getAllSupportedDeviceTypes();
|
|
112
117
|
yield this.ble.scan({ deviceTypes: supportedDeviceTypes, timeout: 20000 });
|
|
113
118
|
if (props && props.onScanFinished) {
|
|
114
119
|
props.onScanFinished(props.id);
|