incyclist-devices 2.3.0 → 2.3.1
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/README.MD +55 -0
- package/lib/antv2/base/adapter.d.ts +2 -2
- package/lib/base/adpater.d.ts +4 -0
- package/lib/base/adpater.js +16 -2
- package/lib/ble/adapter-factory.d.ts +24 -20
- package/lib/ble/adapter-factory.js +36 -13
- package/lib/ble/base/adapter.d.ts +6 -3
- package/lib/ble/base/adapter.js +83 -49
- package/lib/ble/base/comms.d.ts +74 -2
- package/lib/ble/base/comms.js +596 -3
- package/lib/ble/base/interface.d.ts +19 -10
- package/lib/ble/base/interface.js +148 -73
- package/lib/ble/base/peripheral.d.ts +7 -3
- package/lib/ble/base/peripheral.js +76 -22
- package/lib/ble/base/sensor.d.ts +2 -1
- package/lib/ble/base/sensor.js +22 -3
- package/lib/ble/ble-interface.d.ts +4 -7
- package/lib/ble/ble-interface.js +2 -16
- package/lib/ble/ble-peripheral.d.ts +0 -1
- package/lib/ble/ble-peripheral.js +11 -7
- package/lib/ble/characteristics/csc/features.d.ts +10 -0
- package/lib/ble/characteristics/csc/features.js +19 -0
- package/lib/ble/characteristics/csc/measurement.d.ts +33 -0
- package/lib/ble/characteristics/csc/measurement.js +109 -0
- package/lib/ble/characteristics/types.d.ts +6 -0
- package/lib/ble/characteristics/types.js +2 -0
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/cp/comm.d.ts +1 -1
- package/lib/ble/cp/comm.js +2 -2
- package/lib/ble/csc/adapter.d.ts +17 -0
- package/lib/ble/csc/adapter.js +66 -0
- package/lib/ble/csc/index.d.ts +3 -0
- package/lib/ble/csc/index.js +19 -0
- package/lib/ble/csc/sensor.d.ts +21 -0
- package/lib/ble/csc/sensor.js +64 -0
- package/lib/ble/csc/types.d.ts +6 -0
- package/lib/ble/csc/types.js +2 -0
- package/lib/ble/elite/comms.d.ts +1 -1
- package/lib/ble/elite/comms.js +2 -2
- package/lib/ble/factories/adapter-factory.d.ts +8 -6
- package/lib/ble/factories/adapter-factory.js +33 -0
- package/lib/ble/factories/types.d.ts +18 -0
- package/lib/ble/factories/types.js +2 -0
- package/lib/ble/fm/adapter.d.ts +4 -3
- package/lib/ble/fm/adapter.js +53 -48
- package/lib/ble/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- package/lib/ble/fm/sensor.d.ts +1 -1
- package/lib/ble/fm/sensor.js +6 -5
- package/lib/ble/hr/comm.d.ts +1 -1
- package/lib/ble/hr/comm.js +2 -2
- package/lib/ble/index.js +2 -0
- package/lib/ble/tacx/adapter.d.ts +1 -1
- package/lib/ble/tacx/adapter.js +12 -10
- package/lib/ble/tacx/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/sensor.js +9 -3
- package/lib/ble/types.d.ts +8 -2
- package/lib/ble/utils.d.ts +1 -0
- package/lib/ble/utils.js +15 -2
- package/lib/ble/wahoo/adapter.d.ts +1 -0
- package/lib/ble/wahoo/adapter.js +14 -0
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/lib/ble/wahoo/sensor.js +3 -6
- package/lib/direct-connect/base/interface.d.ts +2 -1
- package/lib/direct-connect/base/interface.js +20 -10
- package/lib/direct-connect/base/peripheral.d.ts +4 -4
- package/lib/direct-connect/base/peripheral.js +181 -68
- package/lib/direct-connect/bindings/types.d.ts +2 -1
- package/lib/direct-connect/messages/message.d.ts +1 -0
- package/lib/direct-connect/messages/message.js +16 -1
- package/lib/factories/adapters.js +0 -2
- package/lib/modes/ant-fe-adv-st-mode.d.ts +7 -1
- package/lib/modes/ant-fe-adv-st-mode.js +4 -3
- package/lib/types/adapter.d.ts +3 -0
- package/lib/types/interface.d.ts +1 -0
- package/lib/utils/task.d.ts +3 -0
- package/lib/utils/task.js +12 -0
- package/package.json +1 -1
package/lib/ble/tacx/adapter.js
CHANGED
|
@@ -41,7 +41,7 @@ class BleTacxAdapter extends fm_1.BleFmAdapter {
|
|
|
41
41
|
initControl(props) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
43
|
var _a;
|
|
44
|
-
const sensor = this.
|
|
44
|
+
const sensor = this.getSensor();
|
|
45
45
|
const { user, wheelDiameter, gearRatio, bikeWeight = consts_1.DEFAULT_BIKE_WEIGHT } = props || {};
|
|
46
46
|
const userWeight = ((_a = user === null || user === void 0 ? void 0 : user.weight) !== null && _a !== void 0 ? _a : consts_1.DEFAULT_USER_WEIGHT);
|
|
47
47
|
sensor.sendTrackResistance(0.0);
|
|
@@ -51,15 +51,17 @@ class BleTacxAdapter extends fm_1.BleFmAdapter {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
checkCapabilities() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const before = this.capabilities.join(',');
|
|
56
|
+
const sensor = this.getSensor();
|
|
57
|
+
if (sensor.features && sensor.features.heartrate && !this.hasCapability(types_1.IncyclistCapability.HeartRate)) {
|
|
58
|
+
this.capabilities.push(types_1.IncyclistCapability.HeartRate);
|
|
59
|
+
}
|
|
60
|
+
const after = this.capabilities.join(',');
|
|
61
|
+
if (before !== after) {
|
|
62
|
+
this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
BleTacxAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
|
package/lib/ble/tacx/comms.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LegacyProfile } from "../../antv2/types";
|
|
2
2
|
import { CrankData } from "../cp";
|
|
3
3
|
import { IndoorBikeData } from "../fm";
|
|
4
|
-
import BleFitnessMachineDevice from "../fm/
|
|
4
|
+
import BleFitnessMachineDevice from "../fm/comms";
|
|
5
5
|
import { BleProtocol, IBlePeripheralConnector } from "../types";
|
|
6
6
|
import { BleFeBikeData } from "./types";
|
|
7
7
|
export default class TacxAdvancedFitnessMachineDevice extends BleFitnessMachineDevice {
|
package/lib/ble/tacx/comms.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const consts_1 = require("../consts");
|
|
16
|
-
const
|
|
16
|
+
const comms_1 = __importDefault(require("../fm/comms"));
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
var ANTMessages;
|
|
19
19
|
(function (ANTMessages) {
|
|
@@ -37,7 +37,7 @@ const PROFILE_ID = 'Tacx SmartTrainer';
|
|
|
37
37
|
const SYNC_BYTE = 0xA4;
|
|
38
38
|
const DEFAULT_CHANNEL = 5;
|
|
39
39
|
const ACKNOWLEDGED_DATA = 0x4F;
|
|
40
|
-
class TacxAdvancedFitnessMachineDevice extends
|
|
40
|
+
class TacxAdvancedFitnessMachineDevice extends comms_1.default {
|
|
41
41
|
constructor(props) {
|
|
42
42
|
super(props);
|
|
43
43
|
this.prevCrankData = undefined;
|
package/lib/ble/tacx/sensor.js
CHANGED
|
@@ -43,7 +43,7 @@ class TacxAdvancedFitnessMachineDevice extends sensor_1.default {
|
|
|
43
43
|
}
|
|
44
44
|
this.messageCnt++;
|
|
45
45
|
try {
|
|
46
|
-
const uuid = characteristic.
|
|
46
|
+
const uuid = (0, utils_1.beautifyUUID)(characteristic).toLowerCase();
|
|
47
47
|
let res = undefined;
|
|
48
48
|
if (uuid && (0, utils_1.matches)(uuid, this.tacxRx)) {
|
|
49
49
|
res = this.parseFECMessage(data);
|
|
@@ -452,8 +452,14 @@ class TacxAdvancedFitnessMachineDevice extends sensor_1.default {
|
|
|
452
452
|
sendMessage(message) {
|
|
453
453
|
return __awaiter(this, void 0, void 0, function* () {
|
|
454
454
|
this.logEvent({ message: 'write', characteristic: this.tacxTx, data: message.toString('hex') });
|
|
455
|
-
|
|
456
|
-
|
|
455
|
+
try {
|
|
456
|
+
yield this.write(this.tacxTx, message, { withoutResponse: true });
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
catch (err) {
|
|
460
|
+
this.logEvent({ message: 'write failed', characteristic: this.tacxTx, reason: err.message });
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
457
463
|
});
|
|
458
464
|
}
|
|
459
465
|
sendUserConfiguration(userWeight, bikeWeight, wheelDiameter, gearRatio) {
|
package/lib/ble/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "events";
|
|
2
2
|
import { EventLogger } from "gd-eventlog";
|
|
3
3
|
import { DeviceProperties, DeviceSettings, DeviceStartProperties, IncyclistInterface, IncyclistScanProps, InterfaceProps } from "../types";
|
|
4
|
-
export type BleProtocol = 'hr' | 'fm' | 'cp' | 'tacx' | 'wahoo' | 'elite';
|
|
4
|
+
export type BleProtocol = 'hr' | 'fm' | 'cp' | 'tacx' | 'wahoo' | 'elite' | 'csc';
|
|
5
5
|
export type BleInterfaceState = 'unknown' | 'resetting' | 'unsupported' | 'unauthorized' | 'poweredOff' | 'poweredOn';
|
|
6
6
|
export interface BleBinding extends EventEmitter {
|
|
7
7
|
startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error?: Error) => void): void;
|
|
@@ -13,11 +13,17 @@ export interface BleBinding extends EventEmitter {
|
|
|
13
13
|
state: BleInterfaceState;
|
|
14
14
|
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
15
15
|
}
|
|
16
|
+
export interface BleRawAdvertisement {
|
|
17
|
+
address?: string;
|
|
18
|
+
localName?: string;
|
|
19
|
+
serviceUuids?: string[];
|
|
20
|
+
rssi?: number;
|
|
21
|
+
}
|
|
16
22
|
export interface BleRawPeripheral extends EventEmitter {
|
|
17
23
|
id?: string;
|
|
18
24
|
address?: string;
|
|
19
25
|
name?: string;
|
|
20
|
-
services: [];
|
|
26
|
+
services: any[];
|
|
21
27
|
advertisement: any;
|
|
22
28
|
state: string;
|
|
23
29
|
connectAsync(): Promise<void>;
|
package/lib/ble/utils.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export declare const beautifyUUID: (str: string, withX?: boolean) => string;
|
|
|
19
19
|
export declare const fullUUID: (str: string) => string;
|
|
20
20
|
export declare const propertyVal: (properties: BleProperty[]) => number;
|
|
21
21
|
export declare const propertyFromVal: (val: number) => BleProperty[];
|
|
22
|
+
export declare const bit: (nr: any) => number;
|
|
22
23
|
export {};
|
package/lib/ble/utils.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.beautifyUUID = exports.parseUUID = void 0;
|
|
3
|
+
exports.bit = exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.beautifyUUID = exports.parseUUID = void 0;
|
|
4
4
|
exports.mapLegacyProfile = mapLegacyProfile;
|
|
5
5
|
exports.uuid = uuid;
|
|
6
6
|
exports.matches = matches;
|
|
7
7
|
exports.getPeripheralInfo = getPeripheralInfo;
|
|
8
8
|
exports.getCharachteristicsInfo = getCharachteristicsInfo;
|
|
9
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
9
10
|
function mapLegacyProfile(profile) {
|
|
10
11
|
switch (profile) {
|
|
11
12
|
case 'Smart Trainer': return { profile: 'Smart Trainer', protocol: 'fm' };
|
|
@@ -74,7 +75,15 @@ const parseUUID = (str) => {
|
|
|
74
75
|
};
|
|
75
76
|
exports.parseUUID = parseUUID;
|
|
76
77
|
const beautifyUUID = (str, withX = false) => {
|
|
77
|
-
|
|
78
|
+
let uuid;
|
|
79
|
+
try {
|
|
80
|
+
uuid = (0, exports.parseUUID)(str);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
const logger = new gd_eventlog_1.EventLogger('Incyclist');
|
|
84
|
+
logger.logEvent({ message: 'beautifyUUID error', uuid: str, error: err.message });
|
|
85
|
+
return str;
|
|
86
|
+
}
|
|
78
87
|
const parts = [
|
|
79
88
|
uuid.substring(0, 8),
|
|
80
89
|
uuid.substring(8, 12),
|
|
@@ -129,3 +138,7 @@ const propertyFromVal = (val) => {
|
|
|
129
138
|
return res;
|
|
130
139
|
};
|
|
131
140
|
exports.propertyFromVal = propertyFromVal;
|
|
141
|
+
const bit = (nr) => {
|
|
142
|
+
return (1 << nr);
|
|
143
|
+
};
|
|
144
|
+
exports.bit = bit;
|
package/lib/ble/wahoo/adapter.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -28,6 +37,11 @@ class BleWahooAdapter extends fm_1.BleFmAdapter {
|
|
|
28
37
|
updateSensor(peripheral) {
|
|
29
38
|
this.device = new sensor_1.default(peripheral, { logger: this.logger });
|
|
30
39
|
}
|
|
40
|
+
checkCapabilities() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
this.logEvent({ message: 'device capabilities updated', name: this.getSettings().name, interface: this.getSettings().interface, capabilities: this.capabilities });
|
|
43
|
+
});
|
|
44
|
+
}
|
|
31
45
|
}
|
|
32
46
|
BleWahooAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
|
|
33
47
|
exports.default = BleWahooAdapter;
|
package/lib/ble/wahoo/comms.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LegacyProfile } from "../../antv2/types";
|
|
2
2
|
import { CrankData } from "../cp";
|
|
3
3
|
import { IndoorBikeData } from "../fm";
|
|
4
|
-
import BleFitnessMachineDevice from "../fm/
|
|
4
|
+
import BleFitnessMachineDevice from "../fm/comms";
|
|
5
5
|
import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
|
|
6
6
|
export declare const enum OpCode {
|
|
7
7
|
unlock = 32,
|
package/lib/ble/wahoo/comms.js
CHANGED
|
@@ -15,10 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const _1 = require(".");
|
|
16
16
|
const consts_1 = require("../../base/consts");
|
|
17
17
|
const consts_2 = require("../consts");
|
|
18
|
-
const
|
|
18
|
+
const comms_1 = __importDefault(require("../fm/comms"));
|
|
19
19
|
const utils_1 = require("../utils");
|
|
20
20
|
const ErgWriteDelay = 2000;
|
|
21
|
-
class BleWahooDevice extends
|
|
21
|
+
class BleWahooDevice extends comms_1.default {
|
|
22
22
|
constructor(props) {
|
|
23
23
|
super(props);
|
|
24
24
|
this.prevCrankData = undefined;
|
package/lib/ble/wahoo/sensor.js
CHANGED
|
@@ -43,11 +43,8 @@ class BleWahooDevice extends sensor_1.default {
|
|
|
43
43
|
return [consts_2.INDOOR_BIKE_DATA, consts_2.FTMS_STATUS, consts_2.CSP_MEASUREMENT, consts_2.HR_MEASUREMENT];
|
|
44
44
|
}
|
|
45
45
|
onData(characteristic, data) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
return false;
|
|
49
|
-
const uuid = characteristic.toLowerCase();
|
|
50
|
-
let res = undefined;
|
|
46
|
+
const uuid = (0, utils_1.beautifyUUID)(characteristic).toLowerCase();
|
|
47
|
+
let res;
|
|
51
48
|
switch (uuid) {
|
|
52
49
|
case consts_2.CSP_MEASUREMENT:
|
|
53
50
|
res = this.parsePower(data);
|
|
@@ -62,7 +59,7 @@ class BleWahooDevice extends sensor_1.default {
|
|
|
62
59
|
res = this.parseFitnessMachineStatus(data);
|
|
63
60
|
break;
|
|
64
61
|
default:
|
|
65
|
-
this.logEvent({ message: 'data', uuid, data: data.toString('hex') });
|
|
62
|
+
this.logEvent({ message: 'data', uuid, data: Buffer.from(data).toString('hex') });
|
|
66
63
|
break;
|
|
67
64
|
}
|
|
68
65
|
if (res) {
|
|
@@ -29,6 +29,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
|
|
|
29
29
|
protected connected: boolean;
|
|
30
30
|
static getInstance(props?: InterfaceProps): DirectConnectInterface;
|
|
31
31
|
constructor(props: InterfaceProps);
|
|
32
|
+
setProps(props: InterfaceProps): void;
|
|
32
33
|
createPeripheral(announcement: MulticastDnsAnnouncement): IBlePeripheral;
|
|
33
34
|
createDeviceSetting(service: MulticastDnsAnnouncement): BleDeviceSettings;
|
|
34
35
|
createPeripheralFromSettings(settings: DeviceSettings): IBlePeripheral;
|
|
@@ -57,7 +58,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
|
|
|
57
58
|
interface: string;
|
|
58
59
|
name: string;
|
|
59
60
|
}[];
|
|
60
|
-
protected addService(service: MulticastDnsAnnouncement): void;
|
|
61
|
+
protected addService(service: MulticastDnsAnnouncement, source?: string): void;
|
|
61
62
|
protected find(service: MulticastDnsAnnouncement): Announcement;
|
|
62
63
|
protected getAll(): Announcement[];
|
|
63
64
|
setDebug(enabled: boolean): void;
|
|
@@ -27,6 +27,7 @@ class DirectConnectInterface extends events_1.default {
|
|
|
27
27
|
if (DirectConnectInterface._instance === undefined)
|
|
28
28
|
DirectConnectInterface._instance = new DirectConnectInterface(props);
|
|
29
29
|
else {
|
|
30
|
+
DirectConnectInterface._instance.setProps(props);
|
|
30
31
|
if (props.binding) {
|
|
31
32
|
DirectConnectInterface._instance.setBinding(props.binding);
|
|
32
33
|
}
|
|
@@ -54,9 +55,13 @@ class DirectConnectInterface extends events_1.default {
|
|
|
54
55
|
}
|
|
55
56
|
this.internalEvents = new events_1.default();
|
|
56
57
|
this.instance = ++instanceId;
|
|
57
|
-
|
|
58
|
+
const { enabled } = props;
|
|
59
|
+
if (this.binding && (enabled !== null && enabled !== void 0 ? enabled : false))
|
|
58
60
|
this.autoConnect();
|
|
59
61
|
}
|
|
62
|
+
setProps(props) {
|
|
63
|
+
this.props = props;
|
|
64
|
+
}
|
|
60
65
|
createPeripheral(announcement) {
|
|
61
66
|
return peripheral_1.DirectConnectPeripheral.create(announcement);
|
|
62
67
|
}
|
|
@@ -83,7 +88,7 @@ class DirectConnectInterface extends events_1.default {
|
|
|
83
88
|
setBinding(binding) {
|
|
84
89
|
const prev = this.binding;
|
|
85
90
|
this.binding = binding;
|
|
86
|
-
if (!prev)
|
|
91
|
+
if (!prev && this.props.enabled)
|
|
87
92
|
this.autoConnect();
|
|
88
93
|
}
|
|
89
94
|
getBinding() {
|
|
@@ -107,8 +112,11 @@ class DirectConnectInterface extends events_1.default {
|
|
|
107
112
|
this.getBinding().mdns.connect();
|
|
108
113
|
if (!reconnect)
|
|
109
114
|
this.logEvent({ message: 'starting multicast DNS scan ..' });
|
|
115
|
+
this.getBinding().mdns.find(null, (service) => {
|
|
116
|
+
this.addService(service, 'unfiltered');
|
|
117
|
+
});
|
|
110
118
|
this.getBinding().mdns.find({ type: DC_TYPE }, (service) => {
|
|
111
|
-
this.addService(service);
|
|
119
|
+
this.addService(service, DC_TYPE);
|
|
112
120
|
});
|
|
113
121
|
}
|
|
114
122
|
catch (err) {
|
|
@@ -159,11 +167,11 @@ class DirectConnectInterface extends events_1.default {
|
|
|
159
167
|
stopScan() {
|
|
160
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
169
|
if (!this.isScanning())
|
|
162
|
-
return
|
|
163
|
-
this.logEvent({ message: 'stopping scan ...' });
|
|
170
|
+
return true;
|
|
171
|
+
this.logEvent({ message: 'stopping scan ...', interface: 'wifi' });
|
|
164
172
|
const res = yield this.scanTask.stop();
|
|
165
173
|
delete this.scanTask;
|
|
166
|
-
return res;
|
|
174
|
+
return (res === true);
|
|
167
175
|
});
|
|
168
176
|
}
|
|
169
177
|
onScanDone() {
|
|
@@ -225,8 +233,8 @@ class DirectConnectInterface extends events_1.default {
|
|
|
225
233
|
buildDeviceSettings(matching = []) {
|
|
226
234
|
return matching.map((name) => ({ interface: DirectConnectInterface.INTERFACE_NAME, name }));
|
|
227
235
|
}
|
|
228
|
-
addService(service) {
|
|
229
|
-
var _a;
|
|
236
|
+
addService(service, source) {
|
|
237
|
+
var _a, _b;
|
|
230
238
|
try {
|
|
231
239
|
service.transport = this.getName();
|
|
232
240
|
const existing = this.find(service);
|
|
@@ -235,10 +243,12 @@ class DirectConnectInterface extends events_1.default {
|
|
|
235
243
|
this.services[idx] = { ts: Date.now(), service };
|
|
236
244
|
}
|
|
237
245
|
else {
|
|
238
|
-
this.logEvent({ message: 'device announced', device: service.name, announcement: service });
|
|
239
246
|
this.services.push({ ts: Date.now(), service });
|
|
247
|
+
if (!((_a = service.serviceUUIDs) === null || _a === void 0 ? void 0 : _a.length))
|
|
248
|
+
return;
|
|
249
|
+
this.logEvent({ message: 'device announced', device: service.name, announcement: service, source });
|
|
240
250
|
this.emitDevice(service);
|
|
241
|
-
(
|
|
251
|
+
(_b = this.matching) === null || _b === void 0 ? void 0 : _b.push(service.name);
|
|
242
252
|
}
|
|
243
253
|
}
|
|
244
254
|
catch (err) {
|
|
@@ -21,24 +21,24 @@ export declare class DirectConnectPeripheral implements IBlePeripheral {
|
|
|
21
21
|
constructor(announcement: MulticastDnsAnnouncement);
|
|
22
22
|
get services(): BleService[];
|
|
23
23
|
connect(): Promise<boolean>;
|
|
24
|
-
disconnect(): Promise<boolean>;
|
|
24
|
+
disconnect(connectionLost?: boolean): Promise<boolean>;
|
|
25
25
|
isConnected(): boolean;
|
|
26
26
|
isConnecting(): boolean;
|
|
27
27
|
onDisconnect(callback: () => void): void;
|
|
28
28
|
discoverServices(): Promise<string[]>;
|
|
29
29
|
discoverCharacteristics(serviceUUID: string): Promise<BleCharacteristic[]>;
|
|
30
|
-
subscribe(characteristicUUID: string, callback
|
|
30
|
+
subscribe(characteristicUUID: string, callback?: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
31
31
|
unsubscribe(characteristicUUID: string): Promise<boolean>;
|
|
32
32
|
subscribeAll(callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
33
33
|
subscribeSelected(characteristics: string[], callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
34
|
-
unsubscribeAll(): Promise<
|
|
34
|
+
unsubscribeAll(connectionLost?: boolean): Promise<void>;
|
|
35
35
|
read(characteristicUUID: string): Promise<Buffer>;
|
|
36
36
|
write(characteristicUUID: string, data: Buffer, options?: BleWriteProps): Promise<Buffer>;
|
|
37
37
|
protected startConnection(): Promise<boolean>;
|
|
38
38
|
protected onPortError(err: Error): void;
|
|
39
39
|
protected onPortClose(): Promise<void>;
|
|
40
40
|
protected getPath(): string;
|
|
41
|
-
protected stopConnection(): Promise<boolean>;
|
|
41
|
+
protected stopConnection(connectionLost?: boolean): Promise<boolean>;
|
|
42
42
|
protected getNextSeqNo(): number;
|
|
43
43
|
protected send(seqNo: number, data: Buffer): Promise<Buffer>;
|
|
44
44
|
protected getNextMessage(data: Buffer): Buffer;
|