incyclist-devices 2.0.0-beta.1 → 2.0.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 +238 -0
- package/lib/adapters.d.ts +1 -0
- package/lib/adapters.js +19 -0
- package/lib/antv2/adapter-factory.d.ts +8 -7
- package/lib/antv2/adapter-factory.js +4 -2
- package/lib/antv2/adapter.d.ts +3 -2
- package/lib/antv2/adapter.js +15 -4
- package/lib/antv2/ant-interface.d.ts +6 -2
- package/lib/antv2/ant-interface.js +27 -21
- package/lib/antv2/binding.d.ts +1 -1
- package/lib/antv2/binding.js +1 -1
- package/lib/antv2/fe/adapter.d.ts +12 -9
- package/lib/antv2/fe/adapter.js +67 -27
- package/lib/antv2/hr/adapter.d.ts +6 -5
- package/lib/antv2/hr/adapter.js +19 -16
- package/lib/antv2/index.d.ts +2 -2
- package/lib/antv2/pwr/adapter.d.ts +6 -4
- package/lib/antv2/pwr/adapter.js +24 -16
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +5 -2
- package/lib/antv2/types.js +3 -0
- package/lib/antv2/utils.d.ts +3 -0
- package/lib/antv2/utils.js +12 -1
- package/lib/base/adpater.d.ts +14 -2
- package/lib/base/adpater.js +43 -4
- package/lib/ble/adapter-factory.d.ts +18 -16
- package/lib/ble/adapter-factory.js +54 -45
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/{adapter.js → base/adapter.js} +111 -9
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-comms.d.ts → base/comms.d.ts} +27 -17
- package/lib/ble/{ble-comms.js → base/comms.js} +179 -53
- 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 +34 -46
- package/lib/ble/ble-interface.js +242 -345
- package/lib/ble/ble-peripheral.d.ts +4 -2
- package/lib/ble/ble-peripheral.js +39 -8
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/cp/adapter.d.ts +1 -2
- package/lib/ble/cp/adapter.js +2 -15
- package/lib/ble/cp/comm.d.ts +8 -5
- package/lib/ble/cp/comm.js +12 -27
- package/lib/ble/elite/adapter.d.ts +1 -2
- package/lib/ble/elite/adapter.js +12 -19
- package/lib/ble/elite/comms.d.ts +8 -4
- package/lib/ble/elite/comms.js +12 -25
- package/lib/ble/fm/adapter.d.ts +3 -2
- package/lib/ble/fm/adapter.js +129 -70
- package/lib/ble/fm/comms.d.ts +8 -8
- package/lib/ble/fm/comms.js +33 -55
- package/lib/ble/fm/types.d.ts +5 -0
- package/lib/ble/hr/adapter.d.ts +1 -4
- package/lib/ble/hr/adapter.js +1 -18
- package/lib/ble/hr/comm.d.ts +6 -2
- package/lib/ble/hr/comm.js +6 -2
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/index.d.ts +2 -1
- package/lib/ble/index.js +5 -5
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +1 -1
- package/lib/ble/tacx/adapter.js +20 -14
- package/lib/ble/tacx/comms.d.ts +6 -6
- package/lib/ble/tacx/comms.js +10 -43
- package/lib/ble/types.d.ts +54 -27
- package/lib/ble/types.js +0 -17
- package/lib/ble/utils.d.ts +15 -5
- package/lib/ble/utils.js +25 -66
- package/lib/ble/wahoo/adapter.d.ts +1 -1
- package/lib/ble/wahoo/adapter.js +12 -10
- package/lib/ble/wahoo/comms.d.ts +7 -6
- package/lib/ble/wahoo/comms.js +15 -17
- package/lib/index.d.ts +10 -7
- package/lib/index.js +21 -25
- package/lib/interfaces.d.ts +2 -1
- package/lib/interfaces.js +4 -0
- package/lib/modes/power-base.js +4 -0
- package/lib/serial/adapter.d.ts +5 -0
- package/lib/serial/adapter.js +19 -0
- package/lib/serial/bindings/tcp.d.ts +2 -1
- package/lib/serial/bindings/tcp.js +19 -5
- package/lib/serial/daum/DaumAdapter.d.ts +1 -1
- package/lib/serial/daum/DaumAdapter.js +16 -10
- package/lib/serial/daum/premium/adapter.d.ts +1 -0
- package/lib/serial/daum/premium/adapter.js +9 -2
- package/lib/serial/daum/premium/comms.js +10 -3
- package/lib/serial/daum/premium/mock.js +0 -1
- package/lib/serial/index.d.ts +3 -3
- package/lib/serial/index.js +2 -2
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +1 -4
- package/lib/serial/kettler/ergo-racer/adapter.js +15 -39
- package/lib/serial/serial-interface.d.ts +3 -1
- package/lib/serial/serial-interface.js +43 -17
- package/lib/simulator/Simulator.d.ts +2 -0
- package/lib/simulator/Simulator.js +8 -5
- package/lib/types/adapter.d.ts +10 -3
- package/lib/types/device.d.ts +3 -0
- package/lib/types/interface.d.ts +7 -3
- package/package.json +3 -5
- package/lib/ble/adapter.d.ts +0 -41
- package/lib/ble/ble.d.ts +0 -57
- package/lib/ble/ble.js +0 -48
- package/lib/device.d.ts +0 -0
- package/lib/device.js +0 -0
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const comms_utils_1 = require("./base/comms-utils");
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
-
function mapLegacyProfile(profile) {
|
|
6
|
-
switch (profile) {
|
|
7
|
-
case 'Smart Trainer': return { profile: 'Smart Trainer', protocol: 'fm' };
|
|
8
|
-
case 'Elite Smart Trainer': return { profile: 'Smart Trainer', protocol: 'elite' };
|
|
9
|
-
case 'Heartrate Monitor': return { profile: 'Heartrate Monitor', protocol: 'hr' };
|
|
10
|
-
case 'Power Meter': return { profile: 'Power Meter', protocol: 'cp' };
|
|
11
|
-
case 'Tacx Smart Trainer': return { profile: 'Smart Trainer', protocol: 'tacx' };
|
|
12
|
-
case 'Wahoo Smart Trainer': return { profile: 'Smart Trainer', protocol: 'wahoo' };
|
|
13
|
-
}
|
|
14
|
-
return { profile, protocol: 'Ble' };
|
|
15
|
-
}
|
|
16
|
-
exports.mapLegacyProfile = mapLegacyProfile;
|
|
17
5
|
class BleAdapterFactory {
|
|
18
6
|
static getInstance() {
|
|
19
7
|
if (!BleAdapterFactory._instance)
|
|
@@ -21,44 +9,70 @@ class BleAdapterFactory {
|
|
|
21
9
|
return BleAdapterFactory._instance;
|
|
22
10
|
}
|
|
23
11
|
constructor() {
|
|
24
|
-
this.
|
|
12
|
+
this.implementations = [];
|
|
13
|
+
this.instances = [];
|
|
25
14
|
}
|
|
26
|
-
|
|
27
|
-
return this.
|
|
15
|
+
getAdapterInfo(protocol) {
|
|
16
|
+
return this.implementations.find(a => a.protocol === protocol);
|
|
28
17
|
}
|
|
29
|
-
|
|
30
|
-
return this.
|
|
18
|
+
getAll() {
|
|
19
|
+
return this.implementations;
|
|
31
20
|
}
|
|
32
21
|
createInstance(settings, props) {
|
|
33
22
|
let { profile, protocol } = settings;
|
|
34
23
|
const adapterSettings = Object.assign({}, settings);
|
|
35
|
-
if (
|
|
36
|
-
const mapping = mapLegacyProfile(profile);
|
|
37
|
-
protocol = mapping.protocol;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
if (profile) {
|
|
25
|
+
const mapping = (0, utils_1.mapLegacyProfile)(profile);
|
|
26
|
+
protocol = adapterSettings.protocol = mapping.protocol;
|
|
27
|
+
delete adapterSettings.profile;
|
|
28
|
+
}
|
|
29
|
+
const existing = this.find(adapterSettings);
|
|
30
|
+
if (existing) {
|
|
31
|
+
existing.setProperties(props);
|
|
32
|
+
return existing;
|
|
41
33
|
}
|
|
42
|
-
const info = this.
|
|
34
|
+
const info = this.getAdapterInfo(protocol);
|
|
43
35
|
if (!info || !info.Adapter)
|
|
44
36
|
return;
|
|
45
37
|
const adapter = new info.Adapter(adapterSettings, props);
|
|
38
|
+
this.instances.push(adapter);
|
|
46
39
|
return adapter;
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
removeInstance(query) {
|
|
42
|
+
let idx = -1;
|
|
43
|
+
if (query.settings) {
|
|
44
|
+
idx = this.instances.findIndex(a => a.isEqual(query.settings));
|
|
45
|
+
}
|
|
46
|
+
else if (query.adapter) {
|
|
47
|
+
idx = this.instances.findIndex(a => a.isEqual(query.adapter.getSettings()));
|
|
48
|
+
}
|
|
49
|
+
if (idx !== -1)
|
|
50
|
+
this.instances.splice(idx);
|
|
51
|
+
}
|
|
52
|
+
find(settings) {
|
|
53
|
+
return this.instances.find(a => a.isEqual(settings));
|
|
54
|
+
}
|
|
55
|
+
register(protocol, Adapter, Comm) {
|
|
56
|
+
const info = Object.assign({}, { protocol, Adapter, Comm });
|
|
57
|
+
const existing = this.implementations.findIndex(a => a.protocol === protocol);
|
|
58
|
+
if (existing !== -1)
|
|
59
|
+
this.implementations[existing] = info;
|
|
53
60
|
else
|
|
54
|
-
this.
|
|
61
|
+
this.implementations.push(info);
|
|
62
|
+
}
|
|
63
|
+
getAllInstances() {
|
|
64
|
+
return this.instances;
|
|
55
65
|
}
|
|
56
|
-
|
|
57
|
-
const supported = BleAdapterFactory.getInstance().
|
|
66
|
+
getAllSupportedComms() {
|
|
67
|
+
const supported = BleAdapterFactory.getInstance().getAll();
|
|
58
68
|
return supported.map(info => info.Comm);
|
|
59
69
|
}
|
|
70
|
+
getAllSupportedAdapters() {
|
|
71
|
+
const supported = BleAdapterFactory.getInstance().getAll();
|
|
72
|
+
return supported.map(info => info.Adapter);
|
|
73
|
+
}
|
|
60
74
|
getAllSupportedServices() {
|
|
61
|
-
const supported = BleAdapterFactory.getInstance().
|
|
75
|
+
const supported = BleAdapterFactory.getInstance().getAll();
|
|
62
76
|
const res = [];
|
|
63
77
|
if (supported && supported.length > 0) {
|
|
64
78
|
supported.forEach(info => {
|
|
@@ -74,18 +88,13 @@ class BleAdapterFactory {
|
|
|
74
88
|
}
|
|
75
89
|
getDeviceClasses(peripheral, props = {}) {
|
|
76
90
|
let DeviceClasses;
|
|
77
|
-
const {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
else {
|
|
83
|
-
DeviceClasses = (0, utils_1.getDevicesFromServices)(deviceTypes, services);
|
|
84
|
-
}
|
|
85
|
-
if (profile && DeviceClasses && DeviceClasses.length > 0) {
|
|
86
|
-
DeviceClasses = DeviceClasses.filter(C => {
|
|
91
|
+
const { protocol, services = peripheral.advertisement.serviceUuids } = props;
|
|
92
|
+
const classes = this.getAllSupportedComms();
|
|
93
|
+
DeviceClasses = (0, comms_utils_1.getDevicesFromServices)(classes, services);
|
|
94
|
+
if (protocol && DeviceClasses && DeviceClasses.length > 0) {
|
|
95
|
+
DeviceClasses = DeviceClasses.filter((C) => {
|
|
87
96
|
const device = new C({ peripheral });
|
|
88
|
-
if (device.
|
|
97
|
+
if (device.getProtocol() !== protocol)
|
|
89
98
|
return false;
|
|
90
99
|
return true;
|
|
91
100
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import IncyclistDevice from "../../base/adpater";
|
|
2
|
+
import CyclingMode, { IncyclistBikeData } from "../../modes/cycling-mode";
|
|
3
|
+
import { Bike } from "../../types/adapter";
|
|
4
|
+
import { DeviceData } from "../../types/data";
|
|
5
|
+
import { DeviceProperties } from "../../types/device";
|
|
6
|
+
import { User } from "../../types/user";
|
|
7
|
+
import { BleComms } from "./comms";
|
|
8
|
+
import BleInterface from "../ble-interface";
|
|
9
|
+
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from "../types";
|
|
10
|
+
export default class BleAdapter extends IncyclistDevice {
|
|
11
|
+
ble: BleInterface;
|
|
12
|
+
deviceData: any;
|
|
13
|
+
data: DeviceData;
|
|
14
|
+
dataMsgCount: number;
|
|
15
|
+
lastDataTS: number;
|
|
16
|
+
device: BleComms;
|
|
17
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
18
|
+
getUniqueName(): string;
|
|
19
|
+
connect(): Promise<boolean>;
|
|
20
|
+
close(): Promise<boolean>;
|
|
21
|
+
getComms(): BleComms;
|
|
22
|
+
isEqual(settings: BleDeviceSettings): boolean;
|
|
23
|
+
isSame(adapter: BleAdapter): boolean;
|
|
24
|
+
isConnected(): boolean;
|
|
25
|
+
resetData(): void;
|
|
26
|
+
getInterface(): string;
|
|
27
|
+
getProtocolName(): string;
|
|
28
|
+
getID(): string;
|
|
29
|
+
getName(): string;
|
|
30
|
+
onDeviceData(deviceData: any): void;
|
|
31
|
+
mapData(deviceData: any): DeviceData | IncyclistBikeData;
|
|
32
|
+
transformData(data: IncyclistBikeData): DeviceData;
|
|
33
|
+
getSettings(): BleDeviceSettings;
|
|
34
|
+
setProperties(props: BleDeviceProperties): void;
|
|
35
|
+
check(): Promise<boolean>;
|
|
36
|
+
start(props?: BleStartProperties): Promise<any>;
|
|
37
|
+
stop(): Promise<boolean>;
|
|
38
|
+
pause(): Promise<boolean>;
|
|
39
|
+
resume(): Promise<boolean>;
|
|
40
|
+
}
|
|
41
|
+
export declare class BleControllableAdapter extends BleAdapter implements Bike {
|
|
42
|
+
cyclingMode: CyclingMode;
|
|
43
|
+
user?: User;
|
|
44
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
45
|
+
setUser(user: User): void;
|
|
46
|
+
isControllable(): boolean;
|
|
47
|
+
setBikeProps(props: DeviceProperties): void;
|
|
48
|
+
getWeight(): number;
|
|
49
|
+
getSupportedCyclingModes(): any[];
|
|
50
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
51
|
+
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
52
|
+
getCyclingMode(): CyclingMode;
|
|
53
|
+
}
|
|
@@ -36,8 +36,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.BleControllableAdapter = void 0;
|
|
39
|
-
const adpater_1 = __importStar(require("
|
|
40
|
-
const ble_interface_1 = __importDefault(require("
|
|
39
|
+
const adpater_1 = __importStar(require("../../base/adpater"));
|
|
40
|
+
const ble_interface_1 = __importDefault(require("../ble-interface"));
|
|
41
41
|
const INTERFACE_NAME = 'ble';
|
|
42
42
|
class BleAdapter extends adpater_1.default {
|
|
43
43
|
constructor(settings, props) {
|
|
@@ -50,17 +50,65 @@ class BleAdapter extends adpater_1.default {
|
|
|
50
50
|
this.updateFrequency = 1000;
|
|
51
51
|
this.ble = ble_interface_1.default.getInstance();
|
|
52
52
|
}
|
|
53
|
+
getUniqueName() {
|
|
54
|
+
const settings = this.settings;
|
|
55
|
+
if (settings.name.match(/[0-9]/g) || settings.address === undefined)
|
|
56
|
+
return this.settings.name;
|
|
57
|
+
else {
|
|
58
|
+
const addressHash = settings.address.substring(0, 2) + settings.address.slice(-2);
|
|
59
|
+
return `${this.getName()} ${addressHash}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
connect() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
if (!this.device) {
|
|
65
|
+
throw new Error('No Comms');
|
|
66
|
+
}
|
|
67
|
+
if (this.isConnected())
|
|
68
|
+
return true;
|
|
69
|
+
let connected = false;
|
|
70
|
+
try {
|
|
71
|
+
connected = yield this.device.connect();
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
this.logEvent({ message: 'error', fn: 'connect()', error: err.message, stack: err.stack });
|
|
75
|
+
}
|
|
76
|
+
return connected;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
close() {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!this.device || !this.isConnected())
|
|
82
|
+
return true;
|
|
83
|
+
if (this.device) {
|
|
84
|
+
yield this.device.disconnect();
|
|
85
|
+
this.ble.removeConnectedDevice(this);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getComms() {
|
|
91
|
+
return this.device;
|
|
92
|
+
}
|
|
53
93
|
isEqual(settings) {
|
|
54
94
|
const as = this.settings;
|
|
55
95
|
if (as.interface !== settings.interface)
|
|
56
96
|
return false;
|
|
57
|
-
if (as.
|
|
97
|
+
if (as.profile || settings.profile) {
|
|
58
98
|
return (as.protocol === settings.protocol && as.profile === settings.profile && as.name === settings.name);
|
|
59
99
|
}
|
|
60
100
|
else {
|
|
61
|
-
return (as.protocol === settings.protocol && (as.name
|
|
101
|
+
return (as.protocol === settings.protocol && ((as.name && settings.name && as.name === settings.name) ||
|
|
102
|
+
(as.address && settings.address && as.address === settings.address) ||
|
|
103
|
+
(as.id && settings.id && as.id === settings.id)));
|
|
62
104
|
}
|
|
63
105
|
}
|
|
106
|
+
isSame(adapter) {
|
|
107
|
+
return this.isEqual(adapter.getSettings());
|
|
108
|
+
}
|
|
109
|
+
isConnected() {
|
|
110
|
+
return this.device && this.device.isConnected();
|
|
111
|
+
}
|
|
64
112
|
resetData() {
|
|
65
113
|
this.dataMsgCount = 0;
|
|
66
114
|
this.deviceData = {};
|
|
@@ -86,17 +134,46 @@ class BleAdapter extends adpater_1.default {
|
|
|
86
134
|
this.dataMsgCount++;
|
|
87
135
|
this.lastDataTS = Date.now();
|
|
88
136
|
this.deviceData = Object.assign({}, deviceData);
|
|
137
|
+
if (!this.started || !this.canSendUpdate())
|
|
138
|
+
return;
|
|
139
|
+
this.logEvent({ message: 'onDeviceData', data: deviceData, isControllable: (this instanceof BleControllableAdapter) });
|
|
140
|
+
if (this instanceof BleControllableAdapter) {
|
|
141
|
+
const mappedData = this.mapData(deviceData);
|
|
142
|
+
const incyclistData = this.getCyclingMode().updateData(mappedData);
|
|
143
|
+
this.data = this.transformData(incyclistData);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.data = this.mapData(this.deviceData);
|
|
147
|
+
}
|
|
148
|
+
this.emitData(this.data);
|
|
149
|
+
}
|
|
150
|
+
mapData(deviceData) {
|
|
151
|
+
throw new Error('message not implemented');
|
|
152
|
+
}
|
|
153
|
+
transformData(data) {
|
|
154
|
+
throw new Error('message not implemented');
|
|
155
|
+
}
|
|
156
|
+
getSettings() {
|
|
157
|
+
return this.settings;
|
|
158
|
+
}
|
|
159
|
+
setProperties(props) {
|
|
160
|
+
this.props = props;
|
|
161
|
+
}
|
|
162
|
+
check() {
|
|
163
|
+
return this.start({ scanOnly: true });
|
|
89
164
|
}
|
|
90
165
|
start(props = {}) {
|
|
91
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
167
|
if (this.started)
|
|
93
168
|
return true;
|
|
169
|
+
const connected = yield this.connect();
|
|
170
|
+
if (!connected)
|
|
171
|
+
throw new Error(`could not start device, reason:could not connect`);
|
|
94
172
|
this.logger.logEvent({ message: 'start requested', protocol: this.getProtocolName(), props });
|
|
95
173
|
try {
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
bleDevice.on('data', (data) => {
|
|
174
|
+
const comms = this.device;
|
|
175
|
+
if (comms) {
|
|
176
|
+
comms.on('data', (data) => {
|
|
100
177
|
this.onDeviceData(data);
|
|
101
178
|
});
|
|
102
179
|
this.resetData();
|
|
@@ -126,6 +203,28 @@ class BleAdapter extends adpater_1.default {
|
|
|
126
203
|
return false;
|
|
127
204
|
});
|
|
128
205
|
}
|
|
206
|
+
pause() {
|
|
207
|
+
const _super = Object.create(null, {
|
|
208
|
+
pause: { get: () => super.pause }
|
|
209
|
+
});
|
|
210
|
+
var _a;
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
const res = yield _super.pause.call(this);
|
|
213
|
+
(_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.pause();
|
|
214
|
+
return res;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
resume() {
|
|
218
|
+
const _super = Object.create(null, {
|
|
219
|
+
resume: { get: () => super.resume }
|
|
220
|
+
});
|
|
221
|
+
var _a;
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const res = yield _super.resume.call(this);
|
|
224
|
+
(_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.resume();
|
|
225
|
+
return res;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
129
228
|
}
|
|
130
229
|
exports.default = BleAdapter;
|
|
131
230
|
class BleControllableAdapter extends BleAdapter {
|
|
@@ -139,8 +238,11 @@ class BleControllableAdapter extends BleAdapter {
|
|
|
139
238
|
if (!user.weight)
|
|
140
239
|
this.user.weight = adpater_1.DEFAULT_USER_WEIGHT;
|
|
141
240
|
}
|
|
241
|
+
isControllable() {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
142
244
|
setBikeProps(props) {
|
|
143
|
-
const { user, userWeight
|
|
245
|
+
const { user, userWeight } = props || {};
|
|
144
246
|
if (user)
|
|
145
247
|
this.setUser(user);
|
|
146
248
|
if (userWeight)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BleProtocol } from "../types";
|
|
2
|
+
import { BleComms } from "./comms";
|
|
3
|
+
export declare function getBestDeviceMatch(DeviceClasses: (typeof BleComms)[]): typeof BleComms;
|
|
4
|
+
export declare function getDevicesFromServices(deviceTypes: (typeof BleComms)[], services: string | string[]): (typeof BleComms)[];
|
|
5
|
+
export declare function getServicesFromDeviceTypes(deviceTypes: (typeof BleComms)[]): string[];
|
|
6
|
+
export declare function getServicesFromProtocols(protocols: BleProtocol[]): string[];
|
|
7
|
+
export declare function getServicesFromDevice(device: BleComms): string[];
|
|
@@ -0,0 +1,91 @@
|
|
|
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.getServicesFromDevice = exports.getServicesFromProtocols = exports.getServicesFromDeviceTypes = exports.getDevicesFromServices = exports.getBestDeviceMatch = void 0;
|
|
7
|
+
const adapter_factory_1 = __importDefault(require("../adapter-factory"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
function getBestDeviceMatch(DeviceClasses) {
|
|
10
|
+
if (!DeviceClasses || DeviceClasses.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
const details = DeviceClasses.map(c => ({ name: c.prototype.constructor.name, priority: c.detectionPriority || 0, class: c }));
|
|
13
|
+
details.sort((a, b) => b.priority - a.priority);
|
|
14
|
+
return details[0].class;
|
|
15
|
+
}
|
|
16
|
+
exports.getBestDeviceMatch = getBestDeviceMatch;
|
|
17
|
+
function getDevicesFromServices(deviceTypes, services) {
|
|
18
|
+
if (!deviceTypes || !Array.isArray(deviceTypes) || deviceTypes.length === 0) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const get = (deviceTypes, fnCompare) => {
|
|
22
|
+
const types = deviceTypes.filter(DeviceType => {
|
|
23
|
+
const C = DeviceType;
|
|
24
|
+
let found = false;
|
|
25
|
+
if (C.services)
|
|
26
|
+
found = C.services.find((s) => fnCompare(s));
|
|
27
|
+
return found;
|
|
28
|
+
});
|
|
29
|
+
return types;
|
|
30
|
+
};
|
|
31
|
+
if (typeof services === 'string') {
|
|
32
|
+
return get(deviceTypes, (s) => (0, utils_1.matches)(s, services));
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(services)) {
|
|
35
|
+
const sids = services.map(utils_1.uuid);
|
|
36
|
+
return get(deviceTypes, s => {
|
|
37
|
+
const res = sids.find((service) => (0, utils_1.matches)(s, service));
|
|
38
|
+
return res !== undefined;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
exports.getDevicesFromServices = getDevicesFromServices;
|
|
44
|
+
function getServicesFromDeviceTypes(deviceTypes) {
|
|
45
|
+
let services = [];
|
|
46
|
+
try {
|
|
47
|
+
if (!deviceTypes || !Array.isArray(deviceTypes) || deviceTypes.length === 0) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
deviceTypes.forEach(DeviceType => {
|
|
51
|
+
if (DeviceType.services) {
|
|
52
|
+
const dtServices = DeviceType.services;
|
|
53
|
+
dtServices.forEach(s => {
|
|
54
|
+
if (!services.find(s2 => s2 === s))
|
|
55
|
+
services.push(s);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
console.log(err);
|
|
62
|
+
}
|
|
63
|
+
return services;
|
|
64
|
+
}
|
|
65
|
+
exports.getServicesFromDeviceTypes = getServicesFromDeviceTypes;
|
|
66
|
+
function getServicesFromProtocols(protocols) {
|
|
67
|
+
const services = [];
|
|
68
|
+
const comms = adapter_factory_1.default.getInstance().getAllSupportedComms();
|
|
69
|
+
comms
|
|
70
|
+
.filter((C) => protocols.find(p => p === C.protocol) !== undefined)
|
|
71
|
+
.forEach((C) => {
|
|
72
|
+
C.services.forEach(s => {
|
|
73
|
+
if (!services.find(s2 => s2 === s))
|
|
74
|
+
services.push(s);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return services;
|
|
78
|
+
}
|
|
79
|
+
exports.getServicesFromProtocols = getServicesFromProtocols;
|
|
80
|
+
function getServicesFromDevice(device) {
|
|
81
|
+
if (!device)
|
|
82
|
+
return [];
|
|
83
|
+
const services = [];
|
|
84
|
+
const dServices = device.getServiceUUids();
|
|
85
|
+
dServices.forEach(s => {
|
|
86
|
+
if (!services.find(s2 => s2 === s))
|
|
87
|
+
services.push(s);
|
|
88
|
+
});
|
|
89
|
+
return services;
|
|
90
|
+
}
|
|
91
|
+
exports.getServicesFromDevice = getServicesFromDevice;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import EventEmitter from "events";
|
|
3
5
|
import { EventLogger } from "gd-eventlog";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
log?: boolean;
|
|
9
|
-
logger?: EventLogger;
|
|
10
|
-
peripheral?: BlePeripheral;
|
|
11
|
-
}
|
|
6
|
+
import { LegacyProfile } from "../../antv2/types";
|
|
7
|
+
import BleInterface from "../ble-interface";
|
|
8
|
+
import BlePeripheralConnector from "../ble-peripheral";
|
|
9
|
+
import { BleCharacteristic, BleCommsConnectProps, BleDeviceConstructProps, BleDeviceInfo, BleDeviceSettings, BlePeripheral, BleProtocol, BleWriteProps, ConnectState, IBlePeripheralConnector } from "../types";
|
|
12
10
|
type CommandQueueItem = {
|
|
13
11
|
uuid: string;
|
|
14
12
|
data: Buffer;
|
|
@@ -21,14 +19,17 @@ export interface MessageLog {
|
|
|
21
19
|
timestamp: any;
|
|
22
20
|
data: string;
|
|
23
21
|
}
|
|
24
|
-
export declare class BleComms extends
|
|
22
|
+
export declare class BleComms extends EventEmitter {
|
|
23
|
+
static services: string[];
|
|
24
|
+
static protocol: BleProtocol;
|
|
25
25
|
id: string;
|
|
26
|
+
paused: boolean;
|
|
26
27
|
address: string;
|
|
27
28
|
name: string;
|
|
28
29
|
services: string[];
|
|
29
|
-
ble:
|
|
30
|
+
ble: BleInterface;
|
|
30
31
|
peripheral?: BlePeripheral;
|
|
31
|
-
characteristics:
|
|
32
|
+
characteristics: BleCharacteristic[];
|
|
32
33
|
state?: string;
|
|
33
34
|
logger?: EventLogger;
|
|
34
35
|
deviceInfo: BleDeviceInfo;
|
|
@@ -37,24 +38,33 @@ export declare class BleComms extends BleDeviceCommsClass {
|
|
|
37
38
|
writeQueue: CommandQueueItem[];
|
|
38
39
|
workerIv: NodeJS.Timeout;
|
|
39
40
|
prevMessages: MessageLog[];
|
|
41
|
+
connectState: ConnectState;
|
|
40
42
|
constructor(props?: BleDeviceConstructProps);
|
|
43
|
+
getConnectState(): ConnectState;
|
|
44
|
+
isConnected(): boolean;
|
|
45
|
+
pause(): void;
|
|
46
|
+
resume(): void;
|
|
41
47
|
getServiceUUids(): string[];
|
|
42
|
-
getProfile():
|
|
48
|
+
getProfile(): LegacyProfile;
|
|
49
|
+
getProtocol(): BleProtocol;
|
|
50
|
+
getSettings(): BleDeviceSettings;
|
|
43
51
|
getServices(): string[];
|
|
44
52
|
logEvent(event: any): void;
|
|
45
53
|
setLogger(logger: EventLogger): void;
|
|
46
|
-
setInterface(ble:
|
|
47
|
-
isMatching(characteristics: string[]): boolean;
|
|
54
|
+
setInterface(ble: BleInterface): void;
|
|
55
|
+
static isMatching(characteristics: string[]): boolean;
|
|
48
56
|
reset(): void;
|
|
49
57
|
cleanupListeners(): void;
|
|
50
|
-
onDisconnect(): void
|
|
58
|
+
onDisconnect(): Promise<void>;
|
|
51
59
|
waitForConnectFinished(timeout: any): Promise<unknown>;
|
|
52
60
|
hasService(serviceUuid: any): boolean;
|
|
53
61
|
init(): Promise<boolean>;
|
|
54
62
|
initDevice(): Promise<boolean>;
|
|
55
|
-
connectPeripheral(peripheral: BlePeripheral): Promise<
|
|
63
|
+
connectPeripheral(peripheral: BlePeripheral): Promise<boolean>;
|
|
64
|
+
subscribeMultiple(characteristics: string[], conn?: IBlePeripheralConnector): Promise<void>;
|
|
56
65
|
subscribeAll(conn?: BlePeripheralConnector): Promise<void>;
|
|
57
|
-
|
|
66
|
+
unsubscribeAll(conn?: BlePeripheralConnector): void;
|
|
67
|
+
connect(props?: BleCommsConnectProps): Promise<boolean>;
|
|
58
68
|
disconnect(): Promise<boolean>;
|
|
59
69
|
checkForDuplicate(characteristic: string, data: Buffer): boolean;
|
|
60
70
|
onData(characteristic: string, _data: Buffer): boolean;
|