incyclist-devices 1.4.30 → 1.4.33
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/ble/ble-device.js +1 -1
- package/lib/ble/ble-interface.js +11 -7
- package/lib/ble/ble.d.ts +1 -0
- package/lib/ble/ble.js +10 -0
- package/package.json +1 -1
package/lib/ble/ble-device.js
CHANGED
|
@@ -89,7 +89,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
89
89
|
characteristics.forEach(c => {
|
|
90
90
|
if (c.properties.find(p => p === 'notify')) {
|
|
91
91
|
c.on('data', (data, _isNotification) => {
|
|
92
|
-
this.onData(c.uuid, data);
|
|
92
|
+
this.onData(ble_1.uuid(c.uuid), data);
|
|
93
93
|
});
|
|
94
94
|
c.subscribe((err) => {
|
|
95
95
|
if (err)
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -94,7 +94,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
94
94
|
self.connectState.isOpened = false;
|
|
95
95
|
self.connectState.isConnected = false;
|
|
96
96
|
self.connectState.isConnecting = false;
|
|
97
|
-
|
|
97
|
+
self.logEvent({ message: 'connect result: error', error: err.message });
|
|
98
98
|
return reject(new Error(err.message));
|
|
99
99
|
}
|
|
100
100
|
};
|
|
@@ -173,10 +173,10 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
173
173
|
});
|
|
174
174
|
};
|
|
175
175
|
if (typeof services === 'string') {
|
|
176
|
-
return get(deviceTypes, (s) => s === services);
|
|
176
|
+
return get(deviceTypes, (s) => s === ble_1.uuid(services));
|
|
177
177
|
}
|
|
178
178
|
if (Array.isArray(services)) {
|
|
179
|
-
return get(deviceTypes, s => services.includes(s));
|
|
179
|
+
return get(deviceTypes, s => services.map(ble_1.uuid).includes(s));
|
|
180
180
|
}
|
|
181
181
|
return [];
|
|
182
182
|
}
|
|
@@ -236,6 +236,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
236
236
|
yield this.connect();
|
|
237
237
|
}
|
|
238
238
|
const detectedPeripherals = {};
|
|
239
|
+
this.devices = [];
|
|
239
240
|
if (scanForDevice)
|
|
240
241
|
this.logEvent({ message: 'search device request', device, deviceTypes });
|
|
241
242
|
else
|
|
@@ -275,13 +276,16 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
275
276
|
const d = new C({ peripheral });
|
|
276
277
|
d.setInterface(this);
|
|
277
278
|
if (scanForDevice) {
|
|
278
|
-
if ((device.id &&
|
|
279
|
+
if ((device.id && device.id !== '' && d.id === device.id) ||
|
|
280
|
+
(device.address && device.address !== '' && d.address === device.address) ||
|
|
281
|
+
(device.name && device.name !== '' && d.name === device.name))
|
|
279
282
|
cntFound++;
|
|
280
283
|
}
|
|
281
284
|
else
|
|
282
285
|
cntFound++;
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
const existing = this.devices.find(i => i.device.id === d.id);
|
|
287
|
+
if (cntFound > 0 && !existing) {
|
|
288
|
+
this.logEvent({ message: 'scan: device found', device: d.name, address: d.address, services: d.services.join(',') });
|
|
285
289
|
this.devices.push({ device: d, isConnected: false });
|
|
286
290
|
this.emit('device', d);
|
|
287
291
|
}
|
|
@@ -301,7 +305,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
301
305
|
});
|
|
302
306
|
this.scanState.timeout = setTimeout(() => {
|
|
303
307
|
this.scanState.timeout = null;
|
|
304
|
-
this.logEvent({ message: 'scan result: devices found', devices: this.devices.map(i => i.device.name) });
|
|
308
|
+
this.logEvent({ message: 'scan result: devices found', devices: this.devices.map(i => i.device.name + (!i.device.name || i.device.name === '') ? `addr=${i.device.address}` : '') });
|
|
305
309
|
resolve(this.devices.map(i => i.device));
|
|
306
310
|
bleBinding.stopScanning(() => {
|
|
307
311
|
this.scanState.isScanning = false;
|
package/lib/ble/ble.d.ts
CHANGED
package/lib/ble/ble.js
CHANGED
|
@@ -49,3 +49,13 @@ var BleState;
|
|
|
49
49
|
BleState["POWERED_OFF"] = "poweredOff";
|
|
50
50
|
BleState["POWERED_ON"] = "poweredOn";
|
|
51
51
|
})(BleState = exports.BleState || (exports.BleState = {}));
|
|
52
|
+
exports.uuid = (s) => {
|
|
53
|
+
if (s) {
|
|
54
|
+
if (s.includes('-')) {
|
|
55
|
+
const parts = s.split('-');
|
|
56
|
+
const uuidNo = parseInt('0x' + parts[0]);
|
|
57
|
+
return uuidNo.toString(16);
|
|
58
|
+
}
|
|
59
|
+
return s;
|
|
60
|
+
}
|
|
61
|
+
};
|