incyclist-devices 3.0.29 → 3.0.31
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/cjs/ble/base/interface.js +3 -0
- package/lib/cjs/ble/base/peripheral.js +9 -3
- package/lib/cjs/ble/utils.js +12 -1
- package/lib/cjs/direct-connect/base/interface.js +3 -0
- package/lib/esm/ble/base/interface.js +3 -0
- package/lib/esm/ble/base/peripheral.js +10 -4
- package/lib/esm/ble/utils.js +10 -0
- package/lib/esm/direct-connect/base/interface.js +3 -0
- package/lib/types/ble/base/interface.d.ts +1 -0
- package/lib/types/ble/base/peripheral.d.ts +1 -0
- package/lib/types/ble/types.d.ts +1 -0
- package/lib/types/ble/utils.d.ts +1 -0
- package/lib/types/direct-connect/base/interface.d.ts +1 -0
- package/package.json +1 -1
|
@@ -718,6 +718,9 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
718
718
|
getExpectedServices() {
|
|
719
719
|
return this.getAdapterFactory().getAllSupportedServices();
|
|
720
720
|
}
|
|
721
|
+
getSupportedServices() {
|
|
722
|
+
return this.expectedServices;
|
|
723
|
+
}
|
|
721
724
|
logEvent(event) {
|
|
722
725
|
if (this.logDisabled && event.message !== 'Error')
|
|
723
726
|
return;
|
|
@@ -4,6 +4,7 @@ exports.BlePeripheral = void 0;
|
|
|
4
4
|
const utils_js_1 = require("../../utils/utils.js");
|
|
5
5
|
const utils_js_2 = require("../utils.js");
|
|
6
6
|
const interface_js_1 = require("./interface.js");
|
|
7
|
+
const SERVICE_COMPLETENESS_WHITELIST = ['MRK-R15'];
|
|
7
8
|
class BlePeripheral {
|
|
8
9
|
announcement;
|
|
9
10
|
connected = false;
|
|
@@ -159,7 +160,7 @@ class BlePeripheral {
|
|
|
159
160
|
const promise = this.discoverServicesPromise;
|
|
160
161
|
const res = await promise;
|
|
161
162
|
(0, utils_js_1.sleep)(0).then(() => { delete this.discoverServicesPromise; });
|
|
162
|
-
const isComplete = this.checkAnnouncedServices(res);
|
|
163
|
+
const isComplete = !this.isServiceCompletenessCheckApplicable() || this.checkAnnouncedServices(res);
|
|
163
164
|
this.serviceDiscoveryIncomplete = !isComplete;
|
|
164
165
|
if (!isComplete) {
|
|
165
166
|
const { name, address } = this.getInfo();
|
|
@@ -168,13 +169,18 @@ class BlePeripheral {
|
|
|
168
169
|
}
|
|
169
170
|
return res;
|
|
170
171
|
}
|
|
172
|
+
isServiceCompletenessCheckApplicable() {
|
|
173
|
+
const { name } = this.getInfo();
|
|
174
|
+
return !!name && SERVICE_COMPLETENESS_WHITELIST.some(prefix => name.startsWith(prefix));
|
|
175
|
+
}
|
|
171
176
|
checkAnnouncedServices(discovered) {
|
|
172
|
-
const
|
|
177
|
+
const expected = this.ble.getSupportedServices();
|
|
178
|
+
const announced = this.getAnnouncedServices().filter(a => expected.some(e => (0, utils_js_2.isSameServiceFamily)(a, e)));
|
|
173
179
|
const toBeChecked = discovered.map(x => (0, utils_js_2.beautifyUUID)(x));
|
|
174
180
|
const cntAnnounced = announced.length;
|
|
175
181
|
let cntVerified = 0;
|
|
176
182
|
for (const s of announced) {
|
|
177
|
-
if (toBeChecked.
|
|
183
|
+
if (toBeChecked.some(d => (0, utils_js_2.isSameServiceFamily)(s, d)))
|
|
178
184
|
cntVerified++;
|
|
179
185
|
}
|
|
180
186
|
return cntAnnounced === cntVerified;
|
package/lib/cjs/ble/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bit = exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.beautifyUUID = exports.parseUUID = void 0;
|
|
3
|
+
exports.bit = exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.isSameServiceFamily = exports.beautifyUUID = exports.parseUUID = void 0;
|
|
4
4
|
exports.mapLegacyProfile = mapLegacyProfile;
|
|
5
5
|
exports.uuid = uuid;
|
|
6
6
|
exports.matches = matches;
|
|
@@ -106,6 +106,17 @@ const beautifyUUID = (str, withX = false) => {
|
|
|
106
106
|
return parts.join('-');
|
|
107
107
|
};
|
|
108
108
|
exports.beautifyUUID = beautifyUUID;
|
|
109
|
+
const isSameServiceFamily = (uuid1, uuid2) => {
|
|
110
|
+
const a = (0, exports.beautifyUUID)(uuid1);
|
|
111
|
+
const b = (0, exports.beautifyUUID)(uuid2);
|
|
112
|
+
if (a === b)
|
|
113
|
+
return true;
|
|
114
|
+
const isCustom128 = (u) => u.length === 36;
|
|
115
|
+
if (isCustom128(a) && isCustom128(b))
|
|
116
|
+
return a.substring(9) === b.substring(9);
|
|
117
|
+
return false;
|
|
118
|
+
};
|
|
119
|
+
exports.isSameServiceFamily = isSameServiceFamily;
|
|
109
120
|
const fullUUID = (str) => {
|
|
110
121
|
if (!str)
|
|
111
122
|
return str;
|
|
@@ -66,6 +66,9 @@ class DirectConnectInterface extends node_events_1.EventEmitter {
|
|
|
66
66
|
createPeripheral(announcement) {
|
|
67
67
|
return peripheral_js_1.DirectConnectPeripheral.create(announcement);
|
|
68
68
|
}
|
|
69
|
+
getSupportedServices() {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
69
72
|
createDeviceSetting(service) {
|
|
70
73
|
try {
|
|
71
74
|
const name = service.name;
|
|
@@ -715,6 +715,9 @@ export class BleInterface extends EventEmitter {
|
|
|
715
715
|
getExpectedServices() {
|
|
716
716
|
return this.getAdapterFactory().getAllSupportedServices();
|
|
717
717
|
}
|
|
718
|
+
getSupportedServices() {
|
|
719
|
+
return this.expectedServices;
|
|
720
|
+
}
|
|
718
721
|
logEvent(event) {
|
|
719
722
|
if (this.logDisabled && event.message !== 'Error')
|
|
720
723
|
return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sleep } from "../../utils/utils.js";
|
|
2
|
-
import { beautifyUUID, fullUUID, matches } from "../utils.js";
|
|
2
|
+
import { beautifyUUID, fullUUID, isSameServiceFamily, matches } from "../utils.js";
|
|
3
3
|
import { BleInterface } from "./interface.js";
|
|
4
|
+
const SERVICE_COMPLETENESS_WHITELIST = ['MRK-R15'];
|
|
4
5
|
export class BlePeripheral {
|
|
5
6
|
announcement;
|
|
6
7
|
connected = false;
|
|
@@ -156,7 +157,7 @@ export class BlePeripheral {
|
|
|
156
157
|
const promise = this.discoverServicesPromise;
|
|
157
158
|
const res = await promise;
|
|
158
159
|
sleep(0).then(() => { delete this.discoverServicesPromise; });
|
|
159
|
-
const isComplete = this.checkAnnouncedServices(res);
|
|
160
|
+
const isComplete = !this.isServiceCompletenessCheckApplicable() || this.checkAnnouncedServices(res);
|
|
160
161
|
this.serviceDiscoveryIncomplete = !isComplete;
|
|
161
162
|
if (!isComplete) {
|
|
162
163
|
const { name, address } = this.getInfo();
|
|
@@ -165,13 +166,18 @@ export class BlePeripheral {
|
|
|
165
166
|
}
|
|
166
167
|
return res;
|
|
167
168
|
}
|
|
169
|
+
isServiceCompletenessCheckApplicable() {
|
|
170
|
+
const { name } = this.getInfo();
|
|
171
|
+
return !!name && SERVICE_COMPLETENESS_WHITELIST.some(prefix => name.startsWith(prefix));
|
|
172
|
+
}
|
|
168
173
|
checkAnnouncedServices(discovered) {
|
|
169
|
-
const
|
|
174
|
+
const expected = this.ble.getSupportedServices();
|
|
175
|
+
const announced = this.getAnnouncedServices().filter(a => expected.some(e => isSameServiceFamily(a, e)));
|
|
170
176
|
const toBeChecked = discovered.map(x => beautifyUUID(x));
|
|
171
177
|
const cntAnnounced = announced.length;
|
|
172
178
|
let cntVerified = 0;
|
|
173
179
|
for (const s of announced) {
|
|
174
|
-
if (toBeChecked.
|
|
180
|
+
if (toBeChecked.some(d => isSameServiceFamily(s, d)))
|
|
175
181
|
cntVerified++;
|
|
176
182
|
}
|
|
177
183
|
return cntAnnounced === cntVerified;
|
package/lib/esm/ble/utils.js
CHANGED
|
@@ -96,6 +96,16 @@ export const beautifyUUID = (str, withX = false) => {
|
|
|
96
96
|
}
|
|
97
97
|
return parts.join('-');
|
|
98
98
|
};
|
|
99
|
+
export const isSameServiceFamily = (uuid1, uuid2) => {
|
|
100
|
+
const a = beautifyUUID(uuid1);
|
|
101
|
+
const b = beautifyUUID(uuid2);
|
|
102
|
+
if (a === b)
|
|
103
|
+
return true;
|
|
104
|
+
const isCustom128 = (u) => u.length === 36;
|
|
105
|
+
if (isCustom128(a) && isCustom128(b))
|
|
106
|
+
return a.substring(9) === b.substring(9);
|
|
107
|
+
return false;
|
|
108
|
+
};
|
|
99
109
|
export const fullUUID = (str) => {
|
|
100
110
|
if (!str)
|
|
101
111
|
return str;
|
|
@@ -63,6 +63,9 @@ export default class DirectConnectInterface extends EventEmitter {
|
|
|
63
63
|
createPeripheral(announcement) {
|
|
64
64
|
return DirectConnectPeripheral.create(announcement);
|
|
65
65
|
}
|
|
66
|
+
getSupportedServices() {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
66
69
|
createDeviceSetting(service) {
|
|
67
70
|
try {
|
|
68
71
|
const name = service.name;
|
|
@@ -110,6 +110,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
|
|
|
110
110
|
protected getAdapterFactory(): BleAdapterFactory<TBleSensor>;
|
|
111
111
|
protected getConnectTimeout(): number;
|
|
112
112
|
protected getExpectedServices(): string[];
|
|
113
|
+
getSupportedServices(): string[];
|
|
113
114
|
logEvent(event: any): void;
|
|
114
115
|
logError(err: Error, fn: string, args?: any): void;
|
|
115
116
|
protected reset(): Promise<void>;
|
|
@@ -35,6 +35,7 @@ export declare class BlePeripheral implements IBlePeripheral {
|
|
|
35
35
|
protected onPeripheralDisconnect(): Promise<void>;
|
|
36
36
|
protected onPeripheralError(err: Error): void;
|
|
37
37
|
discoverServices(): Promise<string[]>;
|
|
38
|
+
protected isServiceCompletenessCheckApplicable(): boolean;
|
|
38
39
|
protected checkAnnouncedServices(discovered: string[]): boolean;
|
|
39
40
|
protected _discoverServices(): Promise<string[]>;
|
|
40
41
|
discoverCharacteristics(serviceUUID: string): Promise<BleCharacteristic[]>;
|
package/lib/types/ble/types.d.ts
CHANGED
|
@@ -150,6 +150,7 @@ export interface IBleInterface<T extends PeripheralAnnouncement> extends Incycli
|
|
|
150
150
|
waitForPeripheral(settings: DeviceSettings): Promise<IBlePeripheral>;
|
|
151
151
|
pauseDiscovery?(): Promise<void>;
|
|
152
152
|
resumeDiscovery?(): Promise<void>;
|
|
153
|
+
getSupportedServices(): string[];
|
|
153
154
|
}
|
|
154
155
|
export interface IBlePeripheral {
|
|
155
156
|
services: BleService[];
|
package/lib/types/ble/utils.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare function getPeripheralInfo(p: BleRawPeripheral): {
|
|
|
16
16
|
export declare function getCharachteristicsInfo(c: BleCharacteristic): string;
|
|
17
17
|
export declare const parseUUID: (str: string) => string;
|
|
18
18
|
export declare const beautifyUUID: (str: string, withX?: boolean) => string;
|
|
19
|
+
export declare const isSameServiceFamily: (uuid1: string, uuid2: string) => boolean;
|
|
19
20
|
export declare const fullUUID: (str: string) => string;
|
|
20
21
|
export declare const propertyVal: (properties: BleProperty[]) => number;
|
|
21
22
|
export declare const propertyFromVal: (val: number) => BleProperty[];
|
|
@@ -32,6 +32,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
|
|
|
32
32
|
constructor(props: InterfaceProps);
|
|
33
33
|
setProps(props: InterfaceProps): void;
|
|
34
34
|
createPeripheral(announcement: MulticastDnsAnnouncement): IBlePeripheral;
|
|
35
|
+
getSupportedServices(): string[];
|
|
35
36
|
createDeviceSetting(service: MulticastDnsAnnouncement): BleDeviceSettings;
|
|
36
37
|
createPeripheralFromSettings(settings: DeviceSettings): IBlePeripheral;
|
|
37
38
|
addKnownDevice(settings: BleDeviceSettings): void;
|