incyclist-devices 2.3.0-beta.19 → 2.3.0-beta.20
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/ble/adapter-factory.d.ts +24 -20
- package/lib/ble/adapter-factory.js +36 -13
- package/lib/ble/base/comms.d.ts +74 -2
- package/lib/ble/base/comms.js +596 -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/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- 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/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/sensor.js +1 -1
- package/lib/ble/types.d.ts +1 -1
- package/lib/ble/utils.d.ts +1 -0
- package/lib/ble/utils.js +5 -1
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -19,6 +19,11 @@ __BLE__
|
|
|
19
19
|
- Wahoo Smart Trainers (Wahoo specific service)
|
|
20
20
|
- Tacx FE-C over BLE
|
|
21
21
|
|
|
22
|
+
__Direct Connect (Wifi)__
|
|
23
|
+
- Smart Trainers (FTMS)
|
|
24
|
+
- Power Meters (CP)
|
|
25
|
+
- Heartrate Monitors (HR)
|
|
26
|
+
|
|
22
27
|
__Serial__
|
|
23
28
|
- Daum Classic Ergo Bikes
|
|
24
29
|
- Daum Premium Ergo Bikes (also over TCP/IP)
|
|
@@ -41,6 +46,7 @@ As this library supports various OS( Linux, Windows, Mac) and Incyclist is based
|
|
|
41
46
|
- Ant: specified by the [incyclist-ant-plus](https://github.com/incyclist/ant-plus) library
|
|
42
47
|
- Serial: specified by the [serialport](https://serialport.io/) library
|
|
43
48
|
- BLE: specified by the [noble](https://github.com/noble/noble) library
|
|
49
|
+
- Wifi: a combination of Multicast DNS as provided by the [Bonjour](https://github.com/onlxltd/bonjour-service) library and createSocket() wich creates a Socket class from NodeJS net module
|
|
44
50
|
|
|
45
51
|
__Ant Example__
|
|
46
52
|
|
|
@@ -76,6 +82,55 @@ const logger = new EventLogger('BLESample')
|
|
|
76
82
|
const ble = InterfaceFactory.create('ble',{logger, log:true, binding:noble})
|
|
77
83
|
```
|
|
78
84
|
|
|
85
|
+
__Direct Connect Example__
|
|
86
|
+
```
|
|
87
|
+
const { Bonjour } = require('bonjour-service')
|
|
88
|
+
const net = require('net');
|
|
89
|
+
|
|
90
|
+
const createBinding = ()=>{
|
|
91
|
+
return {
|
|
92
|
+
mdns: new MDNSBinding(),
|
|
93
|
+
net: {
|
|
94
|
+
createSocket: ()=>new net.Socket()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class MDNSBinding {
|
|
100
|
+
|
|
101
|
+
connect() {
|
|
102
|
+
this.bonjour = new Bonjour()
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
disconnect() {
|
|
107
|
+
if (this.bonjour) {
|
|
108
|
+
this.bonjour.destroy()
|
|
109
|
+
this.bonjour = null
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
find(opts , onUp) {
|
|
114
|
+
this.bonjour.find(opts, (s)=>{
|
|
115
|
+
this.handleAnnouncement(s,onUp)
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
handleAnnouncement(service,callback) {
|
|
120
|
+
const {name,txt,port,referer,protocol} = service
|
|
121
|
+
const announcement = {
|
|
122
|
+
name,address:referer?.address,protocol,port,
|
|
123
|
+
serialNo:txt?.['serial-number'],
|
|
124
|
+
serviceUUIDs:txt?.['ble-service-uuids']?.split(',')
|
|
125
|
+
}
|
|
126
|
+
if (callback)
|
|
127
|
+
callback(announcement)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
|
|
79
134
|
### Check availability of interface
|
|
80
135
|
|
|
81
136
|
For some interfaces (ANT and BLE) it cannot be guaranteed that the underlying hardware supports the interface ( e.g. a USB stick might be required). Therefore this library offers a `connect` method, that allows to check if the interface is availabe
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import BleAdapter from "./base/adapter";
|
|
2
|
-
import { BleDeviceSettings, BleProtocol
|
|
2
|
+
import { BleDeviceSettings, BleProtocol } from "./types";
|
|
3
3
|
import { DeviceProperties } from "../types";
|
|
4
|
+
import { BleComms } from "./base/comms";
|
|
4
5
|
import { BleDeviceData } from "./base/types";
|
|
5
|
-
export interface BleAdapterInfo
|
|
6
|
+
export interface BleAdapterInfo {
|
|
6
7
|
protocol: BleProtocol;
|
|
7
|
-
Adapter: typeof BleAdapter<BleDeviceData,
|
|
8
|
-
Comm: typeof
|
|
8
|
+
Adapter: typeof BleAdapter<BleDeviceData, BleComms>;
|
|
9
|
+
Comm: typeof BleComms;
|
|
9
10
|
}
|
|
10
|
-
export default class BleAdapterFactory
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, T>;
|
|
11
|
+
export default class BleAdapterFactory {
|
|
12
|
+
static _instance: BleAdapterFactory;
|
|
13
|
+
implementations: BleAdapterInfo[];
|
|
14
|
+
instances: Array<BleAdapter<BleDeviceData, BleComms>>;
|
|
15
|
+
static getInstance(): BleAdapterFactory;
|
|
16
|
+
constructor();
|
|
17
|
+
getAdapterInfo(protocol: BleProtocol): BleAdapterInfo;
|
|
18
|
+
getAll(): BleAdapterInfo[];
|
|
19
|
+
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, BleComms>;
|
|
20
20
|
removeInstance(query: {
|
|
21
21
|
settings?: BleDeviceSettings;
|
|
22
|
-
adapter?: BleAdapter<BleDeviceData,
|
|
22
|
+
adapter?: BleAdapter<BleDeviceData, BleComms>;
|
|
23
23
|
}): void;
|
|
24
|
-
find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData,
|
|
25
|
-
register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData,
|
|
26
|
-
getAllInstances(): Array<BleAdapter<BleDeviceData,
|
|
27
|
-
getAllSupportedComms(): (typeof
|
|
28
|
-
getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData,
|
|
24
|
+
find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData, BleComms>;
|
|
25
|
+
register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData, BleComms>, Comm: typeof BleComms): void;
|
|
26
|
+
getAllInstances(): Array<BleAdapter<BleDeviceData, BleComms>>;
|
|
27
|
+
getAllSupportedComms(): (typeof BleComms)[];
|
|
28
|
+
getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData, BleComms>)>;
|
|
29
29
|
getAllSupportedServices(): string[];
|
|
30
|
+
getDeviceClasses(peripheral: any, props?: {
|
|
31
|
+
protocol?: BleProtocol;
|
|
32
|
+
services?: string[];
|
|
33
|
+
}): (typeof BleComms)[];
|
|
30
34
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const comms_utils_1 = require("./base/comms-utils");
|
|
3
4
|
const utils_1 = require("./utils");
|
|
4
5
|
class BleAdapterFactory {
|
|
5
|
-
static getInstance(
|
|
6
|
-
if (!BleAdapterFactory.
|
|
7
|
-
BleAdapterFactory.
|
|
8
|
-
return BleAdapterFactory.
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!BleAdapterFactory._instance)
|
|
8
|
+
BleAdapterFactory._instance = new BleAdapterFactory();
|
|
9
|
+
return BleAdapterFactory._instance;
|
|
9
10
|
}
|
|
10
|
-
constructor(
|
|
11
|
-
this.transport = transport;
|
|
11
|
+
constructor() {
|
|
12
12
|
this.implementations = [];
|
|
13
13
|
this.instances = [];
|
|
14
14
|
}
|
|
@@ -37,8 +37,7 @@ class BleAdapterFactory {
|
|
|
37
37
|
return existing;
|
|
38
38
|
}
|
|
39
39
|
const info = this.getAdapterInfo(protocol);
|
|
40
|
-
|
|
41
|
-
if (!(info === null || info === void 0 ? void 0 : info.Adapter))
|
|
40
|
+
if (!info || !info.Adapter)
|
|
42
41
|
return;
|
|
43
42
|
const adapter = new info.Adapter(adapterSettings, props);
|
|
44
43
|
this.instances.push(adapter);
|
|
@@ -70,18 +69,42 @@ class BleAdapterFactory {
|
|
|
70
69
|
return this.instances;
|
|
71
70
|
}
|
|
72
71
|
getAllSupportedComms() {
|
|
73
|
-
const supported =
|
|
72
|
+
const supported = BleAdapterFactory.getInstance().getAll();
|
|
74
73
|
return supported.map(info => info.Comm);
|
|
75
74
|
}
|
|
76
75
|
getAllSupportedAdapters() {
|
|
77
|
-
const supported =
|
|
76
|
+
const supported = BleAdapterFactory.getInstance().getAll();
|
|
78
77
|
return supported.map(info => info.Adapter);
|
|
79
78
|
}
|
|
80
79
|
getAllSupportedServices() {
|
|
81
|
-
const supported =
|
|
82
|
-
const res = [
|
|
80
|
+
const supported = BleAdapterFactory.getInstance().getAll();
|
|
81
|
+
const res = [];
|
|
82
|
+
if (supported && supported.length > 0) {
|
|
83
|
+
supported.forEach(info => {
|
|
84
|
+
if (info && info.Comm && info.Comm.services) {
|
|
85
|
+
info.Comm.services.forEach(s => {
|
|
86
|
+
if (!res.includes(s))
|
|
87
|
+
res.push(s);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
83
92
|
return res;
|
|
84
93
|
}
|
|
94
|
+
getDeviceClasses(peripheral, props = {}) {
|
|
95
|
+
let DeviceClasses;
|
|
96
|
+
const { protocol, services = peripheral.advertisement.serviceUuids } = props;
|
|
97
|
+
const classes = this.getAllSupportedComms();
|
|
98
|
+
DeviceClasses = (0, comms_utils_1.getDevicesFromServices)(classes, services);
|
|
99
|
+
if (protocol && DeviceClasses && DeviceClasses.length > 0) {
|
|
100
|
+
DeviceClasses = DeviceClasses.filter((C) => {
|
|
101
|
+
const device = new C({ peripheral });
|
|
102
|
+
if (device.getProtocol() !== protocol)
|
|
103
|
+
return false;
|
|
104
|
+
return true;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return DeviceClasses;
|
|
108
|
+
}
|
|
85
109
|
}
|
|
86
|
-
BleAdapterFactory._instances = {};
|
|
87
110
|
exports.default = BleAdapterFactory;
|
package/lib/ble/base/comms.d.ts
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { EventLogger } from "gd-eventlog";
|
|
3
|
+
import { LegacyProfile } from "../../antv2/types";
|
|
4
|
+
import BleInterface from "../ble-interface";
|
|
5
|
+
import BlePeripheralConnector from "../ble-peripheral";
|
|
6
|
+
import { BleCharacteristic, BleCommsConnectProps, BleDeviceConstructProps, BleDeviceInfo, BleDeviceSettings, BlePeripheral, BleProtocol, BleWriteProps, ConnectState, IBlePeripheralConnector } from "../types";
|
|
7
|
+
type CommandQueueItem = {
|
|
8
|
+
uuid: string;
|
|
9
|
+
data: Buffer;
|
|
10
|
+
timeout: number;
|
|
11
|
+
resolve: any;
|
|
12
|
+
reject: any;
|
|
13
|
+
};
|
|
14
|
+
export interface MessageLog {
|
|
15
|
+
uuid: string;
|
|
16
|
+
timestamp: any;
|
|
17
|
+
data: string;
|
|
3
18
|
}
|
|
19
|
+
export declare class BleComms extends EventEmitter {
|
|
20
|
+
static services: string[];
|
|
21
|
+
static protocol: BleProtocol;
|
|
22
|
+
id: string;
|
|
23
|
+
paused: boolean;
|
|
24
|
+
address: string;
|
|
25
|
+
name: string;
|
|
26
|
+
services: string[];
|
|
27
|
+
ble: BleInterface;
|
|
28
|
+
peripheral?: BlePeripheral;
|
|
29
|
+
characteristics: BleCharacteristic[];
|
|
30
|
+
state?: string;
|
|
31
|
+
logger?: EventLogger;
|
|
32
|
+
deviceInfo: BleDeviceInfo;
|
|
33
|
+
isInitialized: boolean;
|
|
34
|
+
subscribedCharacteristics: string[];
|
|
35
|
+
writeQueue: CommandQueueItem[];
|
|
36
|
+
workerIv: NodeJS.Timeout;
|
|
37
|
+
prevMessages: MessageLog[];
|
|
38
|
+
connectState: ConnectState;
|
|
39
|
+
constructor(props?: BleDeviceConstructProps);
|
|
40
|
+
getConnectState(): ConnectState;
|
|
41
|
+
isConnected(): boolean;
|
|
42
|
+
pause(): void;
|
|
43
|
+
resume(): void;
|
|
44
|
+
getServiceUUids(): string[];
|
|
45
|
+
getProfile(): LegacyProfile;
|
|
46
|
+
getProtocol(): BleProtocol;
|
|
47
|
+
getSettings(): BleDeviceSettings;
|
|
48
|
+
getServices(): string[];
|
|
49
|
+
logEvent(event: any): void;
|
|
50
|
+
setLogger(logger: EventLogger): void;
|
|
51
|
+
setInterface(ble: BleInterface): void;
|
|
52
|
+
static isMatching(characteristics: string[]): boolean;
|
|
53
|
+
reset(): void;
|
|
54
|
+
cleanupListeners(): void;
|
|
55
|
+
onDisconnect(): Promise<void>;
|
|
56
|
+
waitForConnectFinished(timeout: any): Promise<unknown>;
|
|
57
|
+
hasService(serviceUuid: any): boolean;
|
|
58
|
+
init(): Promise<boolean>;
|
|
59
|
+
initDevice(): Promise<boolean>;
|
|
60
|
+
connectPeripheral(peripheral: BlePeripheral): Promise<boolean>;
|
|
61
|
+
subscribeMultiple(characteristics: string[], conn?: IBlePeripheralConnector): Promise<void>;
|
|
62
|
+
subscribeAll(conn?: BlePeripheralConnector): Promise<void>;
|
|
63
|
+
unsubscribeAll(conn?: BlePeripheralConnector): void;
|
|
64
|
+
connect(props?: BleCommsConnectProps): Promise<boolean>;
|
|
65
|
+
disconnect(): Promise<boolean>;
|
|
66
|
+
checkForDuplicate(characteristic: string, data: Buffer): boolean;
|
|
67
|
+
onData(characteristic: string, _data: Buffer): boolean;
|
|
68
|
+
timeoutCheck(): void;
|
|
69
|
+
startWorker(): void;
|
|
70
|
+
stopWorker(): void;
|
|
71
|
+
write(characteristicUuid: string, data: Buffer, props?: BleWriteProps): Promise<ArrayBuffer>;
|
|
72
|
+
read(characteristicUuid: string): Promise<Uint8Array>;
|
|
73
|
+
getDeviceInfo(): Promise<BleDeviceInfo>;
|
|
74
|
+
}
|
|
75
|
+
export {};
|