incyclist-devices 1.5.38 → 2.0.0
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 +238 -0
- package/lib/adapters.d.ts +7 -0
- package/lib/adapters.js +49 -0
- package/lib/antv2/adapter-factory.d.ts +21 -10
- package/lib/antv2/adapter-factory.js +51 -33
- package/lib/antv2/adapter.d.ts +65 -0
- package/lib/antv2/adapter.js +310 -0
- package/lib/antv2/ant-interface.d.ts +17 -11
- package/lib/antv2/ant-interface.js +41 -31
- package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +1 -1
- package/lib/antv2/{ant-binding.js → binding.js} +1 -1
- package/lib/antv2/fe/adapter.d.ts +28 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +106 -90
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +15 -0
- package/lib/antv2/hr/adapter.js +76 -0
- package/lib/antv2/hr/index.d.ts +2 -0
- package/lib/antv2/hr/index.js +7 -0
- package/lib/antv2/index.d.ts +7 -0
- package/lib/antv2/index.js +20 -0
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
- package/lib/antv2/pwr/adapter.d.ts +24 -0
- package/lib/antv2/pwr/adapter.js +141 -0
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +22 -0
- package/lib/antv2/types.js +5 -0
- package/lib/antv2/utils.d.ts +4 -0
- package/lib/antv2/utils.js +192 -0
- package/lib/base/adpater.d.ts +68 -0
- package/lib/base/adpater.js +183 -0
- package/lib/ble/adapter-factory.d.ts +33 -0
- package/lib/ble/adapter-factory.js +105 -0
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/base/adapter.js +290 -0
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-device.d.ts → base/comms.d.ts} +31 -16
- package/lib/ble/{ble-device.js → base/comms.js} +193 -55
- package/lib/ble/bindings/index.d.ts +2 -0
- package/lib/ble/bindings/index.js +8 -0
- package/lib/ble/bindings/linux.d.ts +15 -0
- package/lib/ble/bindings/linux.js +39 -0
- package/lib/ble/bindings/mock.d.ts +9 -0
- package/lib/ble/bindings/mock.js +108 -0
- package/lib/ble/bindings/types.d.ts +57 -0
- package/lib/ble/bindings/types.js +96 -0
- package/lib/ble/ble-interface.d.ts +38 -59
- package/lib/ble/ble-interface.js +254 -462
- package/lib/ble/ble-peripheral.d.ts +7 -5
- package/lib/ble/ble-peripheral.js +52 -21
- package/lib/ble/consts.d.ts +3 -0
- package/lib/ble/consts.js +4 -1
- package/lib/ble/cp/adapter.d.ts +22 -0
- package/lib/ble/cp/adapter.js +111 -0
- package/lib/ble/cp/comm.d.ts +31 -0
- package/lib/ble/cp/comm.js +125 -0
- package/lib/ble/cp/index.d.ts +4 -0
- package/lib/ble/cp/index.js +10 -0
- package/lib/ble/cp/types.d.ts +13 -0
- package/lib/ble/cp/types.js +2 -0
- package/lib/ble/elite/adapter.d.ts +19 -0
- package/lib/ble/elite/adapter.js +120 -0
- package/lib/ble/elite/comms.d.ts +32 -0
- package/lib/ble/elite/comms.js +126 -0
- package/lib/ble/elite/index.d.ts +3 -0
- package/lib/ble/elite/index.js +10 -0
- package/lib/ble/fm/adapter.d.ts +22 -0
- package/lib/ble/fm/adapter.js +249 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +34 -277
- package/lib/ble/fm/consts.d.ts +6 -0
- package/lib/ble/fm/consts.js +9 -0
- package/lib/ble/fm/index.d.ts +5 -0
- package/lib/ble/fm/index.js +13 -0
- package/lib/ble/fm/types.d.ts +30 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +14 -0
- package/lib/ble/hr/adapter.js +45 -0
- package/lib/ble/hr/comm.d.ts +19 -0
- package/lib/ble/hr/comm.js +56 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +9 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +99 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +11 -43
- package/lib/ble/{tacx.js → tacx/comms.js} +23 -155
- package/lib/ble/tacx/index.d.ts +4 -0
- package/lib/ble/tacx/index.js +10 -0
- package/lib/ble/tacx/types.d.ts +25 -0
- package/lib/ble/tacx/types.js +2 -0
- package/lib/ble/types.d.ts +128 -0
- package/lib/ble/types.js +2 -0
- package/lib/ble/utils.d.ts +17 -0
- package/lib/ble/utils.js +54 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +95 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +11 -44
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +29 -129
- package/lib/ble/wahoo/index.d.ts +4 -0
- package/lib/ble/wahoo/index.js +10 -0
- package/lib/ble/wahoo/types.d.ts +19 -0
- package/lib/ble/wahoo/types.js +2 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +34 -0
- package/lib/interfaces.d.ts +7 -0
- package/lib/interfaces.js +27 -0
- package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
- package/lib/{ble → modes}/ble-erg-mode.js +2 -2
- package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
- package/lib/{ble → modes}/ble-st-mode.js +1 -1
- package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +8 -4
- package/lib/modes/power-meter.d.ts +3 -3
- package/lib/modes/simulator.d.ts +2 -2
- package/lib/modes/simulator.js +1 -1
- package/lib/serial/adapter-factory.d.ts +12 -0
- package/lib/serial/adapter-factory.js +30 -0
- package/lib/serial/adapter.d.ts +21 -0
- package/lib/serial/adapter.js +61 -0
- package/lib/serial/bindings/tcp.d.ts +45 -0
- package/lib/serial/bindings/tcp.js +284 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +14 -23
- package/lib/{daum → serial/daum}/DaumAdapter.js +57 -97
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
- package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
- package/lib/serial/daum/classic/adapter.d.ts +29 -0
- package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
- package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
- package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
- package/lib/serial/daum/classic/mock.d.ts +96 -0
- package/lib/serial/daum/classic/mock.js +365 -0
- package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
- package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
- package/lib/serial/daum/premium/adapter.d.ts +25 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +107 -47
- package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
- package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +215 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +289 -0
- package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
- package/lib/serial/daum/premium/types.d.ts +12 -0
- package/lib/serial/daum/premium/types.js +2 -0
- package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
- package/lib/{daum → serial/daum}/premium/utils.js +22 -63
- package/lib/serial/index.d.ts +9 -0
- package/lib/serial/index.js +49 -0
- package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
- package/lib/{kettler → serial/kettler}/comms.js +71 -32
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +14 -28
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +102 -169
- package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
- package/lib/serial/kettler/ergo-racer/mock.js +216 -0
- package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
- package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
- package/lib/serial/serial-interface.d.ts +60 -0
- package/lib/serial/serial-interface.js +309 -0
- package/lib/simulator/Simulator.d.ts +12 -25
- package/lib/simulator/Simulator.js +26 -87
- package/lib/types/adapter.d.ts +39 -0
- package/lib/types/adapter.js +2 -0
- package/lib/types/capabilities.d.ts +8 -0
- package/lib/types/capabilities.js +12 -0
- package/lib/types/data.d.ts +12 -0
- package/lib/types/data.js +2 -0
- package/lib/types/device.d.ts +32 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +18 -0
- package/lib/types/interface.js +2 -0
- package/lib/types/route.d.ts +2 -2
- package/lib/types/user.d.ts +1 -1
- package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
- package/lib/{utils.js → utils/utils.js} +5 -1
- package/package.json +16 -14
- package/lib/DeviceSupport.d.ts +0 -36
- package/lib/DeviceSupport.js +0 -82
- package/lib/ant/AntAdapter.d.ts +0 -50
- package/lib/ant/AntAdapter.js +0 -109
- package/lib/ant/AntScanner.d.ts +0 -60
- package/lib/ant/AntScanner.js +0 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
- package/lib/ant/antfe/AntFEAdapter.js +0 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
- package/lib/ant/antpwr/pwr-adapter.js +0 -251
- package/lib/ant/utils.d.ts +0 -1
- package/lib/ant/utils.js +0 -23
- package/lib/antv2/AntAdapter.d.ts +0 -48
- package/lib/antv2/AntAdapter.js +0 -104
- package/lib/antv2/ant-device.d.ts +0 -59
- package/lib/antv2/ant-device.js +0 -161
- package/lib/antv2/fe.d.ts +0 -32
- package/lib/antv2/hr.d.ts +0 -18
- package/lib/antv2/hr.js +0 -102
- package/lib/antv2/incyclist-protocol.d.ts +0 -37
- package/lib/antv2/incyclist-protocol.js +0 -126
- package/lib/antv2/pwr.d.ts +0 -28
- package/lib/antv2/pwr.js +0 -171
- package/lib/ble/ble.d.ts +0 -129
- package/lib/ble/ble.js +0 -86
- package/lib/ble/elite.d.ts +0 -90
- package/lib/ble/elite.js +0 -322
- package/lib/ble/fm.d.ts +0 -125
- package/lib/ble/hrm.d.ts +0 -48
- package/lib/ble/hrm.js +0 -134
- package/lib/ble/incyclist-protocol.d.ts +0 -31
- package/lib/ble/incyclist-protocol.js +0 -153
- package/lib/ble/pwr.d.ts +0 -89
- package/lib/ble/pwr.js +0 -322
- package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
- package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
- package/lib/daum/classic/DaumClassicProtocol.js +0 -185
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
- package/lib/daum/premium/tcpserial.d.ts +0 -33
- package/lib/daum/premium/tcpserial.js +0 -123
- package/lib/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
- package/lib/kettler/ergo-racer/protocol.js +0 -203
- package/lib/protocol.d.ts +0 -74
- package/lib/protocol.js +0 -41
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -33
- package/lib/serialport/bindings/tcp.d.ts +0 -20
- package/lib/serialport/bindings/tcp.js +0 -33
- package/lib/serialport/index.d.ts +0 -2
- package/lib/serialport/index.js +0 -29
- package/lib/serialport/serialport.d.ts +0 -29
- package/lib/serialport/serialport.js +0 -87
- /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
- /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
- /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
- /package/lib/{daum → serial/daum}/constants.js +0 -0
- /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
- /package/lib/{serialport.js → serial/serialport.js} +0 -0
- /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
- /package/lib/{calculations.js → utils/calculations.js} +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import EventEmitter from "events";
|
|
5
|
+
import { BleCharacteristic } from "../types";
|
|
6
|
+
export type Property = 'read' | 'write' | 'notify' | 'indicate';
|
|
7
|
+
export type Descriptor = {
|
|
8
|
+
uuid: string;
|
|
9
|
+
value: string | Buffer;
|
|
10
|
+
};
|
|
11
|
+
export type Characteristic = {
|
|
12
|
+
uuid: string;
|
|
13
|
+
properties: Property[];
|
|
14
|
+
secure?: boolean;
|
|
15
|
+
value: Buffer;
|
|
16
|
+
descriptors: Descriptor[];
|
|
17
|
+
};
|
|
18
|
+
export declare const RESULT_SUCCESS = 0;
|
|
19
|
+
export declare const RESULT_INVALID_OFFSET = 7;
|
|
20
|
+
export declare const RESULT_ATTR_NOT_LONG = 11;
|
|
21
|
+
export declare const RESULT_INVALID_ATTRIBUTE_LENGTH = 13;
|
|
22
|
+
export declare const RESULT_UNLIKELY_ERROR = 14;
|
|
23
|
+
export declare class MockCharacteristic extends EventEmitter implements BleCharacteristic {
|
|
24
|
+
uuid: string;
|
|
25
|
+
properties: Property[];
|
|
26
|
+
secure?: boolean | undefined;
|
|
27
|
+
value: Buffer;
|
|
28
|
+
descriptors: Descriptor[];
|
|
29
|
+
subscribe(callback: (err: Error | undefined) => void): void;
|
|
30
|
+
unsubscribe(callback: (err: Error | undefined) => void): void;
|
|
31
|
+
read(callback: (err: Error | undefined, data: Buffer) => void): void;
|
|
32
|
+
write(data: Buffer, withoutResponse: boolean, callback?: ((err: Error | undefined) => void) | undefined): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class StaticReadCharacteristic extends MockCharacteristic {
|
|
35
|
+
constructor(uuid: string, description: string, value: any);
|
|
36
|
+
read(callback: (err: Error | undefined, data: Buffer) => void): void;
|
|
37
|
+
}
|
|
38
|
+
export declare class StaticWriteCharacteristic extends MockCharacteristic {
|
|
39
|
+
size: number;
|
|
40
|
+
constructor(uuid: string, description: string, size: number);
|
|
41
|
+
write(data: Buffer, withoutResponse: boolean, callback?: (err?: Error) => void): void;
|
|
42
|
+
}
|
|
43
|
+
export declare abstract class StaticNotifyCharacteristic extends MockCharacteristic {
|
|
44
|
+
cntSubscriptions: number;
|
|
45
|
+
iv: NodeJS.Timer;
|
|
46
|
+
notifyFrequency: number;
|
|
47
|
+
constructor(uuid: string, description: string);
|
|
48
|
+
subscribe(callback: (err: Error | undefined) => void): void;
|
|
49
|
+
unsubscribe(callback: (err: Error | undefined) => void): void;
|
|
50
|
+
abstract notify(): void;
|
|
51
|
+
startNotify(): void;
|
|
52
|
+
stopNotify(): void;
|
|
53
|
+
}
|
|
54
|
+
export type PrimaryService = {
|
|
55
|
+
uuid: string;
|
|
56
|
+
characteristics: Characteristic[];
|
|
57
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StaticNotifyCharacteristic = exports.StaticWriteCharacteristic = exports.StaticReadCharacteristic = exports.MockCharacteristic = exports.RESULT_UNLIKELY_ERROR = exports.RESULT_INVALID_ATTRIBUTE_LENGTH = exports.RESULT_ATTR_NOT_LONG = exports.RESULT_INVALID_OFFSET = exports.RESULT_SUCCESS = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
exports.RESULT_SUCCESS = 0x00;
|
|
9
|
+
exports.RESULT_INVALID_OFFSET = 0x07;
|
|
10
|
+
exports.RESULT_ATTR_NOT_LONG = 0x0b;
|
|
11
|
+
exports.RESULT_INVALID_ATTRIBUTE_LENGTH = 0x0d;
|
|
12
|
+
exports.RESULT_UNLIKELY_ERROR = 0x0e;
|
|
13
|
+
class MockCharacteristic extends events_1.default {
|
|
14
|
+
subscribe(callback) {
|
|
15
|
+
throw new Error("Method not implemented.");
|
|
16
|
+
}
|
|
17
|
+
unsubscribe(callback) {
|
|
18
|
+
throw new Error("Method not implemented.");
|
|
19
|
+
}
|
|
20
|
+
read(callback) {
|
|
21
|
+
throw new Error("Method not implemented.");
|
|
22
|
+
}
|
|
23
|
+
write(data, withoutResponse, callback) {
|
|
24
|
+
throw new Error("Method not implemented.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.MockCharacteristic = MockCharacteristic;
|
|
28
|
+
class StaticReadCharacteristic extends MockCharacteristic {
|
|
29
|
+
constructor(uuid, description, value) {
|
|
30
|
+
super();
|
|
31
|
+
this.uuid = uuid;
|
|
32
|
+
this.properties = ['read'];
|
|
33
|
+
this.value = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
34
|
+
this.descriptors = [{ uuid: '2901', value: description }];
|
|
35
|
+
}
|
|
36
|
+
read(callback) {
|
|
37
|
+
callback(undefined, this.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.StaticReadCharacteristic = StaticReadCharacteristic;
|
|
41
|
+
class StaticWriteCharacteristic extends MockCharacteristic {
|
|
42
|
+
constructor(uuid, description, size) {
|
|
43
|
+
super();
|
|
44
|
+
this.uuid = uuid;
|
|
45
|
+
this.properties = ['write'];
|
|
46
|
+
this.value = Buffer.alloc(2);
|
|
47
|
+
this.descriptors = [{ uuid: '2901', value: description }];
|
|
48
|
+
this.size = size;
|
|
49
|
+
}
|
|
50
|
+
write(data, withoutResponse, callback) {
|
|
51
|
+
this.value = data;
|
|
52
|
+
if (!withoutResponse && callback)
|
|
53
|
+
callback();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.StaticWriteCharacteristic = StaticWriteCharacteristic;
|
|
57
|
+
class StaticNotifyCharacteristic extends MockCharacteristic {
|
|
58
|
+
constructor(uuid, description) {
|
|
59
|
+
super();
|
|
60
|
+
this.uuid = uuid;
|
|
61
|
+
this.properties = ['notify'];
|
|
62
|
+
this.descriptors = [{ uuid: '2901', value: description }];
|
|
63
|
+
this.cntSubscriptions = 0;
|
|
64
|
+
this.notifyFrequency = 500;
|
|
65
|
+
}
|
|
66
|
+
subscribe(callback) {
|
|
67
|
+
this.cntSubscriptions++;
|
|
68
|
+
this.startNotify();
|
|
69
|
+
if (callback)
|
|
70
|
+
callback(undefined);
|
|
71
|
+
}
|
|
72
|
+
unsubscribe(callback) {
|
|
73
|
+
if (this.cntSubscriptions === 0) {
|
|
74
|
+
if (callback)
|
|
75
|
+
callback(new Error('not subscribed'));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.cntSubscriptions--;
|
|
79
|
+
if (this.cntSubscriptions === 0) {
|
|
80
|
+
this.stopNotify();
|
|
81
|
+
}
|
|
82
|
+
if (callback)
|
|
83
|
+
callback(undefined);
|
|
84
|
+
}
|
|
85
|
+
startNotify() {
|
|
86
|
+
if (!this.iv)
|
|
87
|
+
this.iv = setInterval(this.notify.bind(this), this.notifyFrequency);
|
|
88
|
+
}
|
|
89
|
+
stopNotify() {
|
|
90
|
+
if (this.iv) {
|
|
91
|
+
clearInterval(this.iv);
|
|
92
|
+
this.iv = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.StaticNotifyCharacteristic = StaticNotifyCharacteristic;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { EventLogger } from 'gd-eventlog';
|
|
3
|
-
import
|
|
4
|
+
import BleAdapterFactory from './adapter-factory';
|
|
5
|
+
import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic } from './types';
|
|
6
|
+
import { BleComms } from './base/comms';
|
|
7
|
+
import { IncyclistInterface } from '../types/interface';
|
|
8
|
+
import BleAdapter from './base/adapter';
|
|
9
|
+
import { IncyclistScanProps } from '../types/device';
|
|
10
|
+
import BlePeripheralCache from './peripheral-cache';
|
|
11
|
+
import EventEmitter from 'events';
|
|
4
12
|
export interface ScanState {
|
|
5
13
|
isScanning: boolean;
|
|
6
14
|
isConnecting: boolean;
|
|
7
15
|
isBackgroundScan: boolean;
|
|
8
16
|
timeout?: NodeJS.Timeout;
|
|
17
|
+
peripherals?: Map<string, BlePeripheral>;
|
|
9
18
|
}
|
|
10
19
|
export interface ConnectState {
|
|
11
20
|
isConnecting: boolean;
|
|
@@ -13,88 +22,58 @@ export interface ConnectState {
|
|
|
13
22
|
timeout?: NodeJS.Timeout;
|
|
14
23
|
isInitSuccess: boolean;
|
|
15
24
|
}
|
|
16
|
-
export interface PeripheralState {
|
|
17
|
-
isLoading: boolean;
|
|
18
|
-
isConfigured: boolean;
|
|
19
|
-
isInterrupted: boolean;
|
|
20
|
-
}
|
|
21
25
|
export interface BleDeviceInfo {
|
|
22
|
-
device:
|
|
26
|
+
device: BleComms;
|
|
23
27
|
isConnected: boolean;
|
|
24
28
|
}
|
|
25
29
|
export interface BleDeviceClassInfo {
|
|
26
|
-
Class: typeof
|
|
30
|
+
Class: typeof BleComms;
|
|
27
31
|
type: string;
|
|
28
32
|
services: string[];
|
|
29
33
|
id: string;
|
|
30
34
|
}
|
|
31
|
-
export
|
|
32
|
-
address: string;
|
|
33
|
-
ts: number;
|
|
34
|
-
peripheral: BlePeripheral;
|
|
35
|
-
state?: PeripheralState;
|
|
36
|
-
characteristics?: BleCharacteristic[];
|
|
37
|
-
}
|
|
38
|
-
export default class BleInterface extends BleInterfaceClass {
|
|
35
|
+
export default class BleInterface extends EventEmitter implements IncyclistInterface {
|
|
39
36
|
scanState: ScanState;
|
|
40
37
|
connectState: ConnectState;
|
|
41
|
-
|
|
42
|
-
peripheralCache: any[];
|
|
38
|
+
peripheralCache: BlePeripheralCache;
|
|
43
39
|
logger: EventLogger;
|
|
44
|
-
|
|
40
|
+
props: BleInterfaceProps;
|
|
41
|
+
binding: BleBinding;
|
|
42
|
+
connectedDevices: BleAdapter[];
|
|
43
|
+
sensorIsConnecting: boolean;
|
|
45
44
|
static _instance: BleInterface;
|
|
46
45
|
static getInstance(props?: {
|
|
47
46
|
binding?: BleBinding;
|
|
48
47
|
log?: boolean;
|
|
49
48
|
logger?: EventLogger;
|
|
50
49
|
}): BleInterface;
|
|
51
|
-
constructor(props?:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
constructor(props?: BleInterfaceProps);
|
|
51
|
+
getBinding(): BleBinding;
|
|
52
|
+
setBinding(binding: BleBinding): void;
|
|
53
|
+
getName(): string;
|
|
54
|
+
startConnectSensor(): void;
|
|
55
|
+
stopConnectSensor(): void;
|
|
56
|
+
waitForSensorConnectionFinish(): Promise<void>;
|
|
57
|
+
getAdapterFactory(): BleAdapterFactory;
|
|
57
58
|
logEvent(event: any): void;
|
|
58
|
-
onStateChange(state:
|
|
59
|
+
onStateChange(state: BleInterfaceState): void;
|
|
59
60
|
onError(err: any): void;
|
|
60
|
-
connect(
|
|
61
|
+
connect(to?: number): Promise<boolean>;
|
|
61
62
|
disconnect(): Promise<boolean>;
|
|
62
63
|
isConnected(): boolean;
|
|
63
|
-
getDevicesFromServices(deviceTypes: (typeof BleDeviceClass)[], services: string | string[]): (typeof BleDeviceClass)[];
|
|
64
|
-
getAllSupportedServices(): any[];
|
|
65
|
-
getAllSupportedDeviceTypes(): (typeof BleDeviceClass)[];
|
|
66
|
-
getServicesFromDeviceTypes(deviceTypes: (typeof BleDeviceClass)[]): string[];
|
|
67
|
-
getServicesFromDevice(device: BleDeviceClass): string[];
|
|
68
64
|
waitForConnectFinished(timeout: any): Promise<unknown>;
|
|
69
|
-
addPeripheralToCache(peripheral: any, props?: {}): void;
|
|
70
65
|
onDisconnect(peripheral: any): void;
|
|
71
|
-
|
|
72
|
-
findPeripheral(peripheral: BlePeripheral | {
|
|
73
|
-
id?: string;
|
|
74
|
-
address?: string;
|
|
75
|
-
name?: string;
|
|
76
|
-
}): BlePeripheral;
|
|
77
|
-
getCharacteristics(peripheral: any): Promise<any>;
|
|
78
|
-
getDeviceClasses(peripheral: any, props?: {
|
|
79
|
-
deviceTypes?: (typeof BleDeviceClass)[];
|
|
80
|
-
profile?: string;
|
|
81
|
-
services?: string[];
|
|
82
|
-
}): (typeof BleDeviceClass)[];
|
|
83
|
-
createDevice(DeviceClass: (typeof BleDeviceClass), peripheral: BlePeripheral, characteristics?: BleCharacteristic[]): BleDeviceClass;
|
|
84
|
-
connectDevice(requested: BleDeviceClass | BleDeviceDescription, timeout?: number): Promise<BleDeviceClass>;
|
|
66
|
+
getCharacteristics(peripheral: BlePeripheral): Promise<BleCharacteristic[]>;
|
|
85
67
|
waitForScanFinished(timeout: any): Promise<unknown>;
|
|
86
|
-
|
|
87
|
-
|
|
68
|
+
onPeripheralFound(p: BlePeripheral, callback: any, props?: {
|
|
69
|
+
request?: BleDeviceSettings;
|
|
70
|
+
comms?: BleComms;
|
|
71
|
+
protocolFilter?: BleProtocol[] | null;
|
|
72
|
+
}): Promise<any>;
|
|
73
|
+
scanForDevice(comms: BleComms, props: IncyclistScanProps): Promise<BlePeripheral>;
|
|
74
|
+
scan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
|
|
88
75
|
stopScan(): Promise<boolean>;
|
|
89
76
|
isScanning(): boolean;
|
|
90
|
-
addConnectedDevice(device:
|
|
91
|
-
|
|
92
|
-
findConnected(device: BleDeviceClass | BlePeripheral): BleDeviceClass;
|
|
93
|
-
findDeviceInCache(device: {
|
|
94
|
-
id?: string;
|
|
95
|
-
address?: string;
|
|
96
|
-
name?: string;
|
|
97
|
-
profile: string;
|
|
98
|
-
}): BleDeviceClass;
|
|
99
|
-
removeConnectedDevice(device: BleDeviceClass): void;
|
|
77
|
+
addConnectedDevice(device: BleAdapter): void;
|
|
78
|
+
removeConnectedDevice(device: BleAdapter): void;
|
|
100
79
|
}
|