incyclist-devices 1.4.25 → 1.4.28
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/Device.d.ts +1 -1
- package/lib/Device.js +2 -2
- package/lib/DeviceProtocol.d.ts +2 -1
- package/lib/DeviceProtocol.js +1 -0
- package/lib/DeviceSupport.d.ts +6 -1
- package/lib/DeviceSupport.js +9 -0
- package/lib/ant/AntScanner.js +7 -5
- package/lib/ant/antfe/AntFEAdapter.js +0 -19
- package/lib/ant/anthrm/AntHrmAdapter.js +0 -11
- package/lib/ant/antpwr/pwr-adapter.js +0 -11
- package/lib/ble/ble-device.d.ts +36 -0
- package/lib/ble/ble-device.js +174 -0
- package/lib/ble/ble-interface.d.ts +57 -0
- package/lib/ble/ble-interface.js +347 -0
- package/lib/ble/ble.d.ts +81 -0
- package/lib/ble/ble.js +51 -0
- package/lib/ble/hrm.d.ts +48 -0
- package/lib/ble/hrm.js +128 -0
- package/lib/ble/incyclist-protocol.d.ts +31 -0
- package/lib/ble/incyclist-protocol.js +106 -0
- package/lib/ble/pwr.d.ts +32 -0
- package/lib/ble/pwr.js +96 -0
- package/lib/daum/DaumAdapter.d.ts +2 -2
- package/lib/daum/premium/tcpserial.js +0 -1
- package/lib/modes/power-base.js +16 -6
- package/package.json +2 -1
package/lib/Device.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export interface DeviceAdapter extends Device {
|
|
|
49
49
|
sendUpdate(request: any): void;
|
|
50
50
|
onData(callback: OnDeviceDataCallback): void;
|
|
51
51
|
}
|
|
52
|
-
export default class
|
|
52
|
+
export default class IncyclistDevice implements DeviceAdapter {
|
|
53
53
|
protocol: DeviceProtocol;
|
|
54
54
|
detected: boolean;
|
|
55
55
|
selected: boolean;
|
package/lib/Device.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_BIKE_WEIGHT = 10;
|
|
4
4
|
exports.DEFAULT_USER_WEIGHT = 75;
|
|
5
|
-
class
|
|
5
|
+
class IncyclistDevice {
|
|
6
6
|
constructor(proto) {
|
|
7
7
|
this.protocol = proto;
|
|
8
8
|
this.detected = false;
|
|
@@ -42,4 +42,4 @@ class DeviceAdapterBase {
|
|
|
42
42
|
this.onDataFn = callback;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
exports.default =
|
|
45
|
+
exports.default = IncyclistDevice;
|
package/lib/DeviceProtocol.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare type Device = {
|
|
|
16
16
|
};
|
|
17
17
|
export interface DeviceSettings {
|
|
18
18
|
name: string;
|
|
19
|
-
port
|
|
19
|
+
port?: string;
|
|
20
20
|
userSettings?: User;
|
|
21
21
|
bikeSettings?: any;
|
|
22
22
|
}
|
|
@@ -64,6 +64,7 @@ export default class DeviceProtocolBase {
|
|
|
64
64
|
getSerialPort(): void;
|
|
65
65
|
setNetImpl(netClass: any): void;
|
|
66
66
|
getNetImpl(): any;
|
|
67
|
+
setBinding(_bindingClass: any): void;
|
|
67
68
|
static setAnt(antClass: any): void;
|
|
68
69
|
static getAnt(): any;
|
|
69
70
|
static setSerialPort(serialClass: any): void;
|
package/lib/DeviceProtocol.js
CHANGED
|
@@ -29,6 +29,7 @@ class DeviceProtocolBase {
|
|
|
29
29
|
getSerialPort() { DeviceProtocolBase.getSerialPort(); }
|
|
30
30
|
setNetImpl(netClass) { DeviceProtocolBase.setNetImpl(netClass); }
|
|
31
31
|
getNetImpl() { return DeviceProtocolBase.getNetImpl(); }
|
|
32
|
+
setBinding(_bindingClass) { }
|
|
32
33
|
static setAnt(antClass) { _ant = antClass; }
|
|
33
34
|
static getAnt() { return _ant; }
|
|
34
35
|
static setSerialPort(serialClass) { _serial = serialClass; }
|
package/lib/DeviceSupport.d.ts
CHANGED
|
@@ -6,11 +6,16 @@ import DaumPremiumProtocol from './daum/premium/DaumPremiumProtocol';
|
|
|
6
6
|
import DaumClassicProtocol from './daum/classic/DaumClassicProtocol';
|
|
7
7
|
import KettlerRacerProtocol from './kettler/ergo-racer/protocol';
|
|
8
8
|
import { AntScanner } from './ant/AntScanner';
|
|
9
|
+
import BleProtocol from './ble/incyclist-protocol';
|
|
9
10
|
import { CyclingModeProperyType } from './CyclingMode';
|
|
11
|
+
import BleInterface from './ble/ble-interface';
|
|
12
|
+
import BleHrmDevice from './ble/hrm';
|
|
13
|
+
import BleCyclingPowerDevice from './ble/pwr';
|
|
10
14
|
declare const Protocols: {
|
|
11
15
|
SimulatorProtocol: typeof SimulatorProtocol;
|
|
12
16
|
DaumClassicProtocol: typeof DaumClassicProtocol;
|
|
13
17
|
DaumPremiumProtocol: typeof DaumPremiumProtocol;
|
|
14
18
|
KettlerRacerProtocol: typeof KettlerRacerProtocol;
|
|
19
|
+
BleProtocol: typeof BleProtocol;
|
|
15
20
|
};
|
|
16
|
-
export { DeviceProtocolBase, DeviceProtocol, DeviceRegistry, INTERFACE, DeviceAdapter as Device, Protocols, AntScanner, CyclingModeProperyType };
|
|
21
|
+
export { DeviceProtocolBase, DeviceProtocol, DeviceRegistry, INTERFACE, DeviceAdapter as Device, Protocols, AntScanner, BleProtocol, CyclingModeProperyType, BleInterface, BleHrmDevice, BleCyclingPowerDevice };
|
package/lib/DeviceSupport.js
CHANGED
|
@@ -23,12 +23,21 @@ const DaumClassicProtocol_1 = __importDefault(require("./daum/classic/DaumClassi
|
|
|
23
23
|
const protocol_1 = __importDefault(require("./kettler/ergo-racer/protocol"));
|
|
24
24
|
const AntScanner_1 = require("./ant/AntScanner");
|
|
25
25
|
exports.AntScanner = AntScanner_1.AntScanner;
|
|
26
|
+
const incyclist_protocol_1 = __importDefault(require("./ble/incyclist-protocol"));
|
|
27
|
+
exports.BleProtocol = incyclist_protocol_1.default;
|
|
26
28
|
const CyclingMode_1 = require("./CyclingMode");
|
|
27
29
|
exports.CyclingModeProperyType = CyclingMode_1.CyclingModeProperyType;
|
|
30
|
+
const ble_interface_1 = __importDefault(require("./ble/ble-interface"));
|
|
31
|
+
exports.BleInterface = ble_interface_1.default;
|
|
32
|
+
const hrm_1 = __importDefault(require("./ble/hrm"));
|
|
33
|
+
exports.BleHrmDevice = hrm_1.default;
|
|
34
|
+
const pwr_1 = __importDefault(require("./ble/pwr"));
|
|
35
|
+
exports.BleCyclingPowerDevice = pwr_1.default;
|
|
28
36
|
const Protocols = {
|
|
29
37
|
SimulatorProtocol: Simulator_1.default,
|
|
30
38
|
DaumClassicProtocol: DaumClassicProtocol_1.default,
|
|
31
39
|
DaumPremiumProtocol: DaumPremiumProtocol_1.default,
|
|
32
40
|
KettlerRacerProtocol: protocol_1.default,
|
|
41
|
+
BleProtocol: incyclist_protocol_1.default
|
|
33
42
|
};
|
|
34
43
|
exports.Protocols = Protocols;
|
package/lib/ant/AntScanner.js
CHANGED
|
@@ -231,23 +231,25 @@ class AntProtocol extends DeviceProtocol_1.default {
|
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
if (!open) {
|
|
234
|
-
let detachedKernelDriver = false;
|
|
235
234
|
while (devices.length) {
|
|
236
235
|
let device;
|
|
237
236
|
try {
|
|
238
237
|
device = devices.shift();
|
|
239
238
|
device.open();
|
|
240
239
|
const iface = device.interfaces[0];
|
|
240
|
+
let kernelDriverActive = undefined;
|
|
241
|
+
let claimRequested = false;
|
|
241
242
|
try {
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
kernelDriverActive = iface.isKernelDriverActive();
|
|
244
|
+
if (kernelDriverActive) {
|
|
244
245
|
iface.detachKernelDriver();
|
|
245
246
|
}
|
|
247
|
+
claimRequested = true;
|
|
248
|
+
iface.claim();
|
|
246
249
|
}
|
|
247
250
|
catch (kernelErr) {
|
|
248
|
-
this.logger.logEvent({ message: 'Kernel Error', error: kernelErr.message });
|
|
251
|
+
this.logger.logEvent({ message: 'Kernel Error', error: kernelErr.message, kernelDriverActive, claimRequested });
|
|
249
252
|
}
|
|
250
|
-
iface.claim();
|
|
251
253
|
break;
|
|
252
254
|
}
|
|
253
255
|
catch (deviceErr) {
|
|
@@ -287,28 +287,9 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
287
287
|
yield _super.stop.call(this);
|
|
288
288
|
this.logger.logEvent({ message: 'stop()' });
|
|
289
289
|
this.stopWorker();
|
|
290
|
-
const Messages = this.getProtocol().getAnt().Messages;
|
|
291
|
-
const stick = this.stick;
|
|
292
|
-
const channel = this.channel;
|
|
293
290
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
294
291
|
this.starting = false;
|
|
295
292
|
return resolve(true);
|
|
296
|
-
if (!this.started && !this.connected)
|
|
297
|
-
return resolve(false);
|
|
298
|
-
try {
|
|
299
|
-
stick.write(Messages.openChannel(channel));
|
|
300
|
-
const protocol = this.getProtocol();
|
|
301
|
-
yield protocol.detachSensor(this);
|
|
302
|
-
this.started = false;
|
|
303
|
-
this.connected = false;
|
|
304
|
-
this.logger.logEvent({ message: 'stop() finished' });
|
|
305
|
-
resolve(true);
|
|
306
|
-
}
|
|
307
|
-
catch (err) {
|
|
308
|
-
this.connected = false;
|
|
309
|
-
this.logger.logEvent({ message: 'stop() error', error: err.message });
|
|
310
|
-
reject(err);
|
|
311
|
-
}
|
|
312
293
|
}));
|
|
313
294
|
});
|
|
314
295
|
}
|
|
@@ -123,17 +123,6 @@ class AntHrmAdapter extends AntAdapter_1.default {
|
|
|
123
123
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
this.starting = false;
|
|
125
125
|
return resolve(true);
|
|
126
|
-
this.started = false;
|
|
127
|
-
if (this.ignoreHrm)
|
|
128
|
-
return resolve(false);
|
|
129
|
-
try {
|
|
130
|
-
const protocol = this.getProtocol();
|
|
131
|
-
yield protocol.detachSensor(this);
|
|
132
|
-
resolve(true);
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
reject(err);
|
|
136
|
-
}
|
|
137
126
|
}));
|
|
138
127
|
});
|
|
139
128
|
}
|
|
@@ -241,17 +241,6 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
241
241
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
242
242
|
this.starting = false;
|
|
243
243
|
return resolve(true);
|
|
244
|
-
this.started = false;
|
|
245
|
-
if (this.ignoreHrm)
|
|
246
|
-
return resolve(false);
|
|
247
|
-
try {
|
|
248
|
-
const protocol = this.getProtocol();
|
|
249
|
-
yield protocol.detachSensor(this);
|
|
250
|
-
resolve(true);
|
|
251
|
-
}
|
|
252
|
-
catch (err) {
|
|
253
|
-
reject(err);
|
|
254
|
-
}
|
|
255
244
|
}));
|
|
256
245
|
});
|
|
257
246
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventLogger } from "gd-eventlog";
|
|
3
|
+
import { BleInterfaceClass, BleDeviceClass, BlePeripheral, BleCharacteristic, BleDeviceProps, ConnectProps } from "./ble";
|
|
4
|
+
interface ConnectState {
|
|
5
|
+
isConnecting: boolean;
|
|
6
|
+
isConnected: boolean;
|
|
7
|
+
isDisconnecting: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface BleDeviceConstructProps extends BleDeviceProps {
|
|
10
|
+
log?: boolean;
|
|
11
|
+
logger?: EventLogger;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class BleDevice extends BleDeviceClass {
|
|
14
|
+
id: string;
|
|
15
|
+
address: string;
|
|
16
|
+
name: string;
|
|
17
|
+
services: string[];
|
|
18
|
+
ble: BleInterfaceClass;
|
|
19
|
+
peripheral?: BlePeripheral;
|
|
20
|
+
characteristics: BleCharacteristic[];
|
|
21
|
+
state?: string;
|
|
22
|
+
connectState: ConnectState;
|
|
23
|
+
logger?: EventLogger;
|
|
24
|
+
constructor(props?: BleDeviceConstructProps);
|
|
25
|
+
logEvent(event: any): void;
|
|
26
|
+
setInterface(ble: BleInterfaceClass): void;
|
|
27
|
+
private cleanupListeners;
|
|
28
|
+
private onDisconnect;
|
|
29
|
+
connect(props?: ConnectProps): Promise<boolean>;
|
|
30
|
+
disconnect(): Promise<boolean>;
|
|
31
|
+
abstract getProfile(): string;
|
|
32
|
+
abstract onData(characteristic: string, data: Buffer): void;
|
|
33
|
+
abstract write(characteristic: string, data: Buffer): Promise<boolean>;
|
|
34
|
+
abstract read(characteristic: string): Promise<Buffer>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
13
|
+
const ble_1 = require("./ble");
|
|
14
|
+
class BleDevice extends ble_1.BleDeviceClass {
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super();
|
|
17
|
+
this.characteristics = [];
|
|
18
|
+
this.connectState = { isConnecting: false, isConnected: false, isDisconnecting: false };
|
|
19
|
+
this.id = props.id;
|
|
20
|
+
this.address = props.address;
|
|
21
|
+
this.name = props.name;
|
|
22
|
+
this.services = props.services;
|
|
23
|
+
this.ble = props.ble;
|
|
24
|
+
this.characteristics = [];
|
|
25
|
+
if (props.peripheral) {
|
|
26
|
+
const { id, address, advertisement, state } = props.peripheral;
|
|
27
|
+
this.peripheral = props.peripheral;
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.address = address;
|
|
30
|
+
this.name = advertisement.localName;
|
|
31
|
+
this.services = advertisement.serviceUuids;
|
|
32
|
+
this.state = state;
|
|
33
|
+
}
|
|
34
|
+
if (props.logger) {
|
|
35
|
+
this.logger = props.logger;
|
|
36
|
+
}
|
|
37
|
+
else if (props.log) {
|
|
38
|
+
this.logger = new gd_eventlog_1.EventLogger('BleDevice');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
logEvent(event) {
|
|
42
|
+
if (this.logger) {
|
|
43
|
+
this.logger.logEvent(event);
|
|
44
|
+
}
|
|
45
|
+
if (process.env.BLE_DEBUG) {
|
|
46
|
+
console.log(event);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
setInterface(ble) {
|
|
50
|
+
this.ble = ble;
|
|
51
|
+
}
|
|
52
|
+
cleanupListeners() {
|
|
53
|
+
if (this.characteristics === undefined) {
|
|
54
|
+
this.characteristics = [];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.characteristics.forEach(c => {
|
|
58
|
+
c.removeAllListeners('data');
|
|
59
|
+
});
|
|
60
|
+
this.characteristics = [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
onDisconnect() {
|
|
64
|
+
this.state = "disconnected";
|
|
65
|
+
if (!this.connectState.isDisconnecting) {
|
|
66
|
+
this.connect();
|
|
67
|
+
}
|
|
68
|
+
this.emit('disconnected');
|
|
69
|
+
}
|
|
70
|
+
connect(props) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const connectPeripheral = (peripheral) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
this.connectState.isConnecting = true;
|
|
74
|
+
try {
|
|
75
|
+
yield peripheral.connectAsync();
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
this.logEvent({ message: 'cannot connect', error: err.message || err });
|
|
79
|
+
}
|
|
80
|
+
this.connectState.isConnecting = false;
|
|
81
|
+
this.connectState.isConnected = true;
|
|
82
|
+
this.state = "connected";
|
|
83
|
+
this.emit('connected');
|
|
84
|
+
this.cleanupListeners();
|
|
85
|
+
this.ble.addConnectedDevice(this);
|
|
86
|
+
this.peripheral.once('disconnect', () => { this.onDisconnect(); });
|
|
87
|
+
try {
|
|
88
|
+
const { characteristics } = yield peripheral.discoverSomeServicesAndCharacteristicsAsync(this.services || [], []);
|
|
89
|
+
characteristics.forEach(c => {
|
|
90
|
+
if (c.properties.find(p => p === 'notify')) {
|
|
91
|
+
c.on('data', (data, _isNotification) => {
|
|
92
|
+
this.onData(c.uuid, data);
|
|
93
|
+
});
|
|
94
|
+
c.subscribe((err) => {
|
|
95
|
+
if (err)
|
|
96
|
+
this.logEvent({ message: 'cannot subscribe', error: err.message || err });
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
this.logEvent({ message: 'cannot connect', error: err.message || err });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
try {
|
|
106
|
+
if (this.peripheral) {
|
|
107
|
+
const { id, address, advertisement } = this.peripheral;
|
|
108
|
+
const name = advertisement === null || advertisement === void 0 ? void 0 : advertisement.localName;
|
|
109
|
+
this.logEvent({ message: 'connect requested', mode: 'peripheral', device: { id, name, address: address } });
|
|
110
|
+
yield connectPeripheral(this.peripheral);
|
|
111
|
+
this.logEvent({ message: 'connect result: success', mode: 'peripheral', device: { id, name, address } });
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const { id, name, address } = this;
|
|
116
|
+
if (this.address || this.id || this.name) {
|
|
117
|
+
this.connectState.isConnecting = true;
|
|
118
|
+
this.logEvent({ message: 'connect requested', mode: 'device', device: { id, name, address } });
|
|
119
|
+
try {
|
|
120
|
+
if (this.ble.isScanning()) {
|
|
121
|
+
yield this.ble.stopScan();
|
|
122
|
+
}
|
|
123
|
+
const devices = yield this.ble.scan({ device: this });
|
|
124
|
+
if (devices && devices.length > 0) {
|
|
125
|
+
this.peripheral = devices[0].peripheral;
|
|
126
|
+
yield connectPeripheral(this.peripheral);
|
|
127
|
+
this.logEvent({ message: 'connect result: success', mode: 'device', device: { id, name, address } });
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
this.logEvent({ message: 'connect result: failure', mode: 'device', device: { id, name, address } });
|
|
135
|
+
this.connectState.isConnecting = false;
|
|
136
|
+
this.connectState.isConnected = false;
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
this.connectState.isConnecting = false;
|
|
142
|
+
this.connectState.isConnected = false;
|
|
143
|
+
this.logEvent({ message: 'connect result: error', error: err.message });
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
disconnect() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const { id, name, address } = this;
|
|
151
|
+
this.logEvent({ message: 'disconnect requested', device: { id, name, address } });
|
|
152
|
+
this.connectState.isDisconnecting = true;
|
|
153
|
+
if (!this.connectState.isConnecting && !this.connectState.isConnected) {
|
|
154
|
+
this.connectState.isDisconnecting = false;
|
|
155
|
+
this.logEvent({ message: 'disconnect result: success', device: { id, name, address } });
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
if (this.connectState.isConnecting) {
|
|
159
|
+
this.cleanupListeners();
|
|
160
|
+
setTimeout(() => { this.connectState.isDisconnecting = false; }, 1000);
|
|
161
|
+
this.logEvent({ message: 'disconnect result: unclear - connect ongoing', device: { id, name, address } });
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
if (this.connectState.isConnected) {
|
|
165
|
+
this.ble.removeConnectedDevice(this);
|
|
166
|
+
this.cleanupListeners();
|
|
167
|
+
setTimeout(() => { this.connectState.isDisconnecting = false; }, 1000);
|
|
168
|
+
this.logEvent({ message: 'disconnect result: success', device: { id, name, address } });
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.BleDevice = BleDevice;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventLogger } from 'gd-eventlog';
|
|
3
|
+
import { BleInterfaceClass, ConnectProps, ScanProps, BleDeviceClass, BleBinding } from './ble';
|
|
4
|
+
export interface ScanState {
|
|
5
|
+
isScanning: boolean;
|
|
6
|
+
timeout?: NodeJS.Timeout;
|
|
7
|
+
}
|
|
8
|
+
export interface ConnectState {
|
|
9
|
+
isConnecting: boolean;
|
|
10
|
+
isConnected: boolean;
|
|
11
|
+
timeout?: NodeJS.Timeout;
|
|
12
|
+
isOpened: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface BleDeviceInfo {
|
|
15
|
+
device: BleDeviceClass;
|
|
16
|
+
isConnected: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface BleDeviceClassInfo {
|
|
19
|
+
Class: typeof BleDeviceClass;
|
|
20
|
+
type: string;
|
|
21
|
+
services: string[];
|
|
22
|
+
id: string;
|
|
23
|
+
}
|
|
24
|
+
export default class BleInterface extends BleInterfaceClass {
|
|
25
|
+
scanState: ScanState;
|
|
26
|
+
connectState: ConnectState;
|
|
27
|
+
devices: BleDeviceInfo[];
|
|
28
|
+
logger: EventLogger;
|
|
29
|
+
static deviceClasses: BleDeviceClassInfo[];
|
|
30
|
+
static _instance: BleInterface;
|
|
31
|
+
static getInstance(props?: {
|
|
32
|
+
binding?: BleBinding;
|
|
33
|
+
log?: boolean;
|
|
34
|
+
logger?: EventLogger;
|
|
35
|
+
}): BleInterface;
|
|
36
|
+
constructor(props?: {
|
|
37
|
+
binding?: BleBinding;
|
|
38
|
+
log?: boolean;
|
|
39
|
+
logger?: EventLogger;
|
|
40
|
+
});
|
|
41
|
+
static register(id: string, type: string, Class: typeof BleDeviceClass, services: string[]): void;
|
|
42
|
+
logEvent(event: any): void;
|
|
43
|
+
onStateChange(state: any): void;
|
|
44
|
+
onError(err: any): void;
|
|
45
|
+
connect(props?: ConnectProps): Promise<boolean>;
|
|
46
|
+
disconnect(): Promise<boolean>;
|
|
47
|
+
isConnected(): boolean;
|
|
48
|
+
getDevicesFromServices(deviceTypes: (typeof BleDeviceClass)[], services: string | string[]): (typeof BleDeviceClass)[];
|
|
49
|
+
getServicesFromDeviceTypes(deviceTypes: (typeof BleDeviceClass)[]): string[];
|
|
50
|
+
getServicesFromDevice(device: BleDeviceClass): string[];
|
|
51
|
+
connectDevice(requested: BleDeviceClass, timeout?: number): Promise<BleDeviceClass>;
|
|
52
|
+
scan(props: ScanProps): Promise<BleDeviceClass[]>;
|
|
53
|
+
stopScan(): Promise<boolean>;
|
|
54
|
+
isScanning(): boolean;
|
|
55
|
+
addConnectedDevice(device: BleDeviceClass): void;
|
|
56
|
+
removeConnectedDevice(device: BleDeviceClass): void;
|
|
57
|
+
}
|