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
|
@@ -19,6 +19,7 @@ class BlePeripheral {
|
|
|
19
19
|
this.characteristics = {};
|
|
20
20
|
this.subscribed = [];
|
|
21
21
|
this.disconnecting = false;
|
|
22
|
+
this.onErrorHandler = this.onPeripheralError.bind(this);
|
|
22
23
|
this.ble = interface_1.BleInterface.getInstance();
|
|
23
24
|
}
|
|
24
25
|
get services() {
|
|
@@ -29,31 +30,42 @@ class BlePeripheral {
|
|
|
29
30
|
}
|
|
30
31
|
connect() {
|
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
|
|
33
|
+
if (this.isConnected())
|
|
34
|
+
return true;
|
|
35
|
+
const peripheral = this.getPeripheral();
|
|
36
|
+
yield peripheral.connectAsync();
|
|
33
37
|
this.ble.registerConnected(this);
|
|
38
|
+
peripheral.once('disconnect', () => { this.onPeripheralDisconnect(); });
|
|
39
|
+
peripheral.on('error', this.onErrorHandler);
|
|
34
40
|
this.connected = true;
|
|
35
|
-
return
|
|
41
|
+
return this.connected;
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
44
|
disconnect() {
|
|
39
|
-
return __awaiter(this,
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
40
46
|
this.disconnecting = true;
|
|
41
47
|
if (!this.isConnected())
|
|
42
48
|
return true;
|
|
43
|
-
yield this.unsubscribeAll();
|
|
49
|
+
yield this.unsubscribeAll(connectionLost);
|
|
44
50
|
Object.keys(this.characteristics).forEach(uuid => {
|
|
45
51
|
const c = this.characteristics[uuid];
|
|
46
52
|
c.removeAllListeners();
|
|
47
53
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
const peripheral = this.getPeripheral();
|
|
55
|
+
if (peripheral) {
|
|
56
|
+
if (!connectionLost) {
|
|
57
|
+
if (!peripheral.disconnectAsync) {
|
|
58
|
+
peripheral.disconnectAsync = () => {
|
|
59
|
+
return new Promise((done) => { this.getPeripheral().disconnect(() => { done(); }); });
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
yield this.getPeripheral().disconnectAsync();
|
|
63
|
+
}
|
|
64
|
+
peripheral.removeAllListeners();
|
|
52
65
|
}
|
|
53
|
-
yield this.getPeripheral().disconnectAsync();
|
|
54
66
|
this.connected = false;
|
|
55
67
|
this.disconnecting = false;
|
|
56
|
-
return
|
|
68
|
+
return !this.connected;
|
|
57
69
|
});
|
|
58
70
|
}
|
|
59
71
|
isConnected() {
|
|
@@ -65,13 +77,29 @@ class BlePeripheral {
|
|
|
65
77
|
onDisconnect(callback) {
|
|
66
78
|
this.onDisconnectHandler = callback;
|
|
67
79
|
}
|
|
80
|
+
onPeripheralDisconnect() {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
this.logEvent({ message: 'disconnect' });
|
|
83
|
+
try {
|
|
84
|
+
yield this.disconnect(true);
|
|
85
|
+
}
|
|
86
|
+
catch (_a) { }
|
|
87
|
+
if (this.onDisconnectHandler)
|
|
88
|
+
this.onDisconnectHandler();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
onPeripheralError(err) {
|
|
92
|
+
this.logEvent({ message: 'peripheral error', error: err.message });
|
|
93
|
+
}
|
|
68
94
|
discoverServices() {
|
|
69
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
96
|
if (this.getPeripheral().discoverServicesAsync) {
|
|
97
|
+
this.logEvent({ message: 'discover services' });
|
|
71
98
|
const services = yield this.getPeripheral().discoverServicesAsync([]);
|
|
72
99
|
return services.map(s => s.uuid);
|
|
73
100
|
}
|
|
74
101
|
else {
|
|
102
|
+
this.logEvent({ message: 'discover services and characteristics' });
|
|
75
103
|
const res = yield this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
|
|
76
104
|
return res.services.map(s => s.uuid);
|
|
77
105
|
}
|
|
@@ -92,8 +120,17 @@ class BlePeripheral {
|
|
|
92
120
|
try {
|
|
93
121
|
if (this.disconnecting || !this.connected)
|
|
94
122
|
return false;
|
|
123
|
+
const onData = (data) => {
|
|
124
|
+
try {
|
|
125
|
+
callback(characteristicUUID, data);
|
|
126
|
+
}
|
|
127
|
+
catch (_a) { }
|
|
128
|
+
};
|
|
95
129
|
const subscription = this.subscribed.find(s => s.uuid === characteristicUUID);
|
|
96
130
|
if (subscription) {
|
|
131
|
+
const c = this.getRawCharacteristic(characteristicUUID);
|
|
132
|
+
if (c)
|
|
133
|
+
c.on('data', onData);
|
|
97
134
|
return true;
|
|
98
135
|
}
|
|
99
136
|
const c = this.getRawCharacteristic(characteristicUUID);
|
|
@@ -114,12 +151,6 @@ class BlePeripheral {
|
|
|
114
151
|
}
|
|
115
152
|
else {
|
|
116
153
|
if (callback) {
|
|
117
|
-
const onData = (data) => {
|
|
118
|
-
try {
|
|
119
|
-
callback(characteristicUUID, data);
|
|
120
|
-
}
|
|
121
|
-
catch (_a) { }
|
|
122
|
-
};
|
|
123
154
|
this.subscribed.push({ uuid: characteristicUUID, callback: onData });
|
|
124
155
|
c.on('data', onData);
|
|
125
156
|
}
|
|
@@ -177,16 +208,16 @@ class BlePeripheral {
|
|
|
177
208
|
yield this.discoverAllCharacteristics();
|
|
178
209
|
}
|
|
179
210
|
const retry = [];
|
|
180
|
-
for (
|
|
181
|
-
const c = this.getRawCharacteristic(
|
|
211
|
+
for (const element of characteristics) {
|
|
212
|
+
const c = this.getRawCharacteristic(element);
|
|
182
213
|
if (c === null || c === void 0 ? void 0 : c.properties.includes('notify')) {
|
|
183
214
|
const success = yield this.subscribe(c.uuid, callback);
|
|
184
215
|
if (!success)
|
|
185
216
|
retry.push(c);
|
|
186
217
|
}
|
|
187
218
|
}
|
|
188
|
-
for (
|
|
189
|
-
const c =
|
|
219
|
+
for (const element of retry) {
|
|
220
|
+
const c = element;
|
|
190
221
|
yield this.subscribe(c.uuid, callback);
|
|
191
222
|
}
|
|
192
223
|
return true;
|
|
@@ -214,6 +245,24 @@ class BlePeripheral {
|
|
|
214
245
|
}
|
|
215
246
|
});
|
|
216
247
|
}
|
|
248
|
+
discoverSomeCharacteristics(characteristics) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
try {
|
|
251
|
+
const target = characteristics.map(c => (0, utils_1.fullUUID)(c));
|
|
252
|
+
const res = yield this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], target);
|
|
253
|
+
const found = [];
|
|
254
|
+
res.characteristics.forEach(c => {
|
|
255
|
+
this.characteristics[(0, utils_1.beautifyUUID)(c.uuid)] = c;
|
|
256
|
+
found.push(c.uuid);
|
|
257
|
+
});
|
|
258
|
+
return found;
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
this.logEvent({ message: 'Error', fn: 'discoverAllCharacteristics', error: err.message, stack: err.stack });
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
217
266
|
subscribeAll(callback) {
|
|
218
267
|
return __awaiter(this, void 0, void 0, function* () {
|
|
219
268
|
const characteristics = yield this.discoverAllCharacteristics();
|
|
@@ -222,13 +271,16 @@ class BlePeripheral {
|
|
|
222
271
|
});
|
|
223
272
|
}
|
|
224
273
|
unsubscribeAll() {
|
|
225
|
-
return __awaiter(this,
|
|
274
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
275
|
+
if (connectionLost) {
|
|
276
|
+
this.subscribed = [];
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
226
279
|
const promises = [];
|
|
227
280
|
this.subscribed.forEach(d => {
|
|
228
281
|
promises.push(this.unsubscribe(d.uuid));
|
|
229
282
|
});
|
|
230
283
|
yield Promise.allSettled(promises);
|
|
231
|
-
return true;
|
|
232
284
|
});
|
|
233
285
|
}
|
|
234
286
|
read(characteristicUUID) {
|
|
@@ -280,6 +332,8 @@ class BlePeripheral {
|
|
|
280
332
|
return this.characteristics[(0, utils_1.beautifyUUID)(uuid)];
|
|
281
333
|
}
|
|
282
334
|
logEvent(event) {
|
|
335
|
+
var _a;
|
|
336
|
+
event.peripheral = (_a = this.announcement) === null || _a === void 0 ? void 0 : _a.name;
|
|
283
337
|
this.ble.logEvent(event);
|
|
284
338
|
}
|
|
285
339
|
}
|
package/lib/ble/base/sensor.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class TBleSensor extends EventEmitter implements IBleSensor {
|
|
|
12
12
|
constructor(peripheral: IBlePeripheral, props?: {
|
|
13
13
|
logger?: EventLogger;
|
|
14
14
|
});
|
|
15
|
+
getDetectionPriority(): number;
|
|
15
16
|
getProfile(): LegacyProfile;
|
|
16
17
|
getProtocol(): BleProtocol;
|
|
17
18
|
getServiceUUids(): string[];
|
|
@@ -19,7 +20,7 @@ export declare class TBleSensor extends EventEmitter implements IBleSensor {
|
|
|
19
20
|
hasPeripheral(): boolean;
|
|
20
21
|
startSensor(reconnect?: boolean): Promise<boolean>;
|
|
21
22
|
protected getRequiredCharacteristics(): Array<string>;
|
|
22
|
-
|
|
23
|
+
subscribe(): Promise<boolean>;
|
|
23
24
|
stopSensor(): Promise<boolean>;
|
|
24
25
|
reconnectSensor(): Promise<void>;
|
|
25
26
|
reset(): void;
|
package/lib/ble/base/sensor.js
CHANGED
|
@@ -28,6 +28,11 @@ class TBleSensor extends events_1.default {
|
|
|
28
28
|
this.reset();
|
|
29
29
|
this.onDataHandler = this.onData.bind(this);
|
|
30
30
|
}
|
|
31
|
+
getDetectionPriority() {
|
|
32
|
+
var _a;
|
|
33
|
+
const C = this.constructor;
|
|
34
|
+
return (_a = C['detectionPriority']) !== null && _a !== void 0 ? _a : 0;
|
|
35
|
+
}
|
|
31
36
|
getProfile() {
|
|
32
37
|
const C = this.constructor;
|
|
33
38
|
return C['profile'];
|
|
@@ -69,7 +74,7 @@ class TBleSensor extends events_1.default {
|
|
|
69
74
|
return false;
|
|
70
75
|
if (!reconnect)
|
|
71
76
|
this.peripheral.onDisconnect(this.reconnectSensor.bind(this));
|
|
72
|
-
return
|
|
77
|
+
return true;
|
|
73
78
|
});
|
|
74
79
|
}
|
|
75
80
|
getRequiredCharacteristics() {
|
|
@@ -96,11 +101,19 @@ class TBleSensor extends events_1.default {
|
|
|
96
101
|
}
|
|
97
102
|
reconnectSensor() {
|
|
98
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
let connected = false;
|
|
105
|
+
let subscribed = false;
|
|
99
106
|
let success = false;
|
|
100
107
|
do {
|
|
101
|
-
|
|
108
|
+
if (!connected) {
|
|
109
|
+
connected = yield this.startSensor(true);
|
|
110
|
+
}
|
|
111
|
+
if (connected && !subscribed) {
|
|
112
|
+
subscribed = yield this.subscribe();
|
|
113
|
+
}
|
|
114
|
+
success = connected && subscribed;
|
|
102
115
|
if (!success) {
|
|
103
|
-
yield (0, utils_1.sleep)(
|
|
116
|
+
yield (0, utils_1.sleep)(1000);
|
|
104
117
|
}
|
|
105
118
|
} while (!success || this.stopRequested);
|
|
106
119
|
});
|
|
@@ -114,10 +127,16 @@ class TBleSensor extends events_1.default {
|
|
|
114
127
|
}
|
|
115
128
|
read(characteristicUUID) {
|
|
116
129
|
var _a;
|
|
130
|
+
if (!this.isConnected()) {
|
|
131
|
+
return Promise.reject(new Error('not connected'));
|
|
132
|
+
}
|
|
117
133
|
return (_a = this.peripheral) === null || _a === void 0 ? void 0 : _a.read(characteristicUUID);
|
|
118
134
|
}
|
|
119
135
|
write(characteristicUUID, data, options) {
|
|
120
136
|
var _a;
|
|
137
|
+
if (!this.isConnected()) {
|
|
138
|
+
return Promise.reject(new Error('not connected'));
|
|
139
|
+
}
|
|
121
140
|
return (_a = this.peripheral) === null || _a === void 0 ? void 0 : _a.write(characteristicUUID, data, options);
|
|
122
141
|
}
|
|
123
142
|
onData(characteristic, data) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventLogger } from 'gd-eventlog';
|
|
2
2
|
import BleAdapterFactory from './adapter-factory';
|
|
3
|
-
import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic
|
|
3
|
+
import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic } from './types';
|
|
4
4
|
import { BleComms } from './base/comms';
|
|
5
|
-
import { IncyclistScanProps } from '../types';
|
|
5
|
+
import { IncyclistInterface, IncyclistScanProps } from '../types';
|
|
6
6
|
import BlePeripheralCache from './peripheral-cache';
|
|
7
7
|
import EventEmitter from 'events';
|
|
8
8
|
export interface ScanState {
|
|
@@ -31,7 +31,7 @@ export interface BleDeviceClassInfo {
|
|
|
31
31
|
services: string[];
|
|
32
32
|
id: string;
|
|
33
33
|
}
|
|
34
|
-
export default class BleInterface extends EventEmitter implements
|
|
34
|
+
export default class BleInterface extends EventEmitter implements IncyclistInterface {
|
|
35
35
|
scanState: ScanState;
|
|
36
36
|
connectState: ConnectState;
|
|
37
37
|
peripheralCache: BlePeripheralCache;
|
|
@@ -62,8 +62,7 @@ export default class BleInterface extends EventEmitter implements IBleInterface
|
|
|
62
62
|
pauseLogging(debugOnly?: boolean): void;
|
|
63
63
|
resumeLogging(): void;
|
|
64
64
|
protected isDebugEnabled(): boolean;
|
|
65
|
-
logEvent(event: any): void;
|
|
66
|
-
logError(err: Error, fn: string, args?: any): void;
|
|
65
|
+
protected logEvent(event: any): void;
|
|
67
66
|
protected onStateChange(state: BleInterfaceState): void;
|
|
68
67
|
protected onError(err: any): void;
|
|
69
68
|
connect(to?: number): Promise<boolean>;
|
|
@@ -80,8 +79,6 @@ export default class BleInterface extends EventEmitter implements IBleInterface
|
|
|
80
79
|
}): Promise<any>;
|
|
81
80
|
scanForDevice(comms: BleComms, props: IncyclistScanProps): Promise<BlePeripheral>;
|
|
82
81
|
scan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
|
|
83
|
-
protected legacyScan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
|
|
84
82
|
stopScan(): Promise<boolean>;
|
|
85
83
|
isScanning(): boolean;
|
|
86
|
-
getLogger(): EventLogger;
|
|
87
84
|
}
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -118,10 +118,6 @@ class BleInterface extends events_1.default {
|
|
|
118
118
|
console.log('~~~ BLE', event);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
logError(err, fn, args) {
|
|
122
|
-
const logInfo = args || {};
|
|
123
|
-
this.logEvent(Object.assign(Object.assign({ message: 'Error', fn }, logInfo), { error: err.message, stack: err.stack }));
|
|
124
|
-
}
|
|
125
121
|
onStateChange(state) {
|
|
126
122
|
if (state !== 'poweredOn') {
|
|
127
123
|
this.logEvent({ message: 'Ble disconnected', });
|
|
@@ -146,12 +142,10 @@ class BleInterface extends events_1.default {
|
|
|
146
142
|
this.resumeLogging();
|
|
147
143
|
const timeout = this.props.timeout || to || 2000;
|
|
148
144
|
const connect = new Promise((resolve, reject) => {
|
|
149
|
-
this.logEvent({ message: 'Ble connect request'
|
|
145
|
+
this.logEvent({ message: 'Ble connect request' });
|
|
150
146
|
if (!this.getBinding())
|
|
151
147
|
return reject(new Error('no binding defined'));
|
|
152
|
-
this.connectState.isConnecting = true;
|
|
153
148
|
this.connectState.timeout = setTimeout(() => {
|
|
154
|
-
console.log('connect timeout');
|
|
155
149
|
this.connectState.isConnected = false;
|
|
156
150
|
this.connectState.isConnecting = false;
|
|
157
151
|
this.connectState.timeout = null;
|
|
@@ -500,13 +494,8 @@ class BleInterface extends events_1.default {
|
|
|
500
494
|
}
|
|
501
495
|
scan() {
|
|
502
496
|
return __awaiter(this, arguments, void 0, function* (props = {}) {
|
|
503
|
-
return yield this.legacyScan(props);
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
legacyScan() {
|
|
507
|
-
return __awaiter(this, arguments, void 0, function* (props = {}) {
|
|
508
|
-
this.resumeLogging();
|
|
509
497
|
this.logEvent({ message: 'starting scan ..' });
|
|
498
|
+
this.resumeLogging();
|
|
510
499
|
const { timeout, protocol, protocols } = props;
|
|
511
500
|
const requestedProtocols = protocols || [];
|
|
512
501
|
if (protocol && !requestedProtocols.find(p => p === protocol))
|
|
@@ -629,8 +618,5 @@ class BleInterface extends events_1.default {
|
|
|
629
618
|
isScanning() {
|
|
630
619
|
return this.scanState.isScanning === true;
|
|
631
620
|
}
|
|
632
|
-
getLogger() {
|
|
633
|
-
return this.logger;
|
|
634
|
-
}
|
|
635
621
|
}
|
|
636
622
|
exports.default = BleInterface;
|
|
@@ -18,7 +18,6 @@ export default class BlePeripheralConnector implements IBlePeripheralConnector {
|
|
|
18
18
|
private emitter;
|
|
19
19
|
constructor(peripheral: BlePeripheral);
|
|
20
20
|
logEvent(event: any): void;
|
|
21
|
-
logError(err: Error, fn: string, args?: any): void;
|
|
22
21
|
connect(): Promise<void>;
|
|
23
22
|
reconnect(): Promise<void>;
|
|
24
23
|
onDisconnect(): void;
|
|
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
16
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
15
17
|
const events_1 = __importDefault(require("events"));
|
|
16
18
|
const utils_1 = require("./utils");
|
|
17
|
-
const interface_1 = require("./base/interface");
|
|
18
19
|
class BlePeripheralConnector {
|
|
19
20
|
constructor(peripheral) {
|
|
20
|
-
this.ble =
|
|
21
|
+
this.ble = ble_interface_1.default.getInstance();
|
|
21
22
|
this.peripheral = peripheral;
|
|
22
23
|
this.emitter = new events_1.default();
|
|
23
24
|
if (!this.peripheral || !this.ble)
|
|
@@ -25,13 +26,16 @@ class BlePeripheralConnector {
|
|
|
25
26
|
this.state = { subscribed: [], isConnected: false, isConnecting: false, isInitialized: false, isInitializing: false, isSubscribing: false };
|
|
26
27
|
this.services = [];
|
|
27
28
|
this.characteristics = [];
|
|
28
|
-
this.logger =
|
|
29
|
+
this.logger = new gd_eventlog_1.EventLogger('BLE');
|
|
29
30
|
}
|
|
30
31
|
logEvent(event) {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (this.logger) {
|
|
33
|
+
this.logger.logEvent(event);
|
|
34
|
+
}
|
|
35
|
+
const w = global.window;
|
|
36
|
+
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
|
|
37
|
+
console.log('~~~ BLE', event);
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
connect() {
|
|
37
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CharacteristicParser } from "../types";
|
|
2
|
+
export type BleCSCFeatures = {
|
|
3
|
+
wheelRevolutionData?: boolean;
|
|
4
|
+
crankRevolutionData?: boolean;
|
|
5
|
+
multipleSensorLocations?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare class CscFeatures implements CharacteristicParser<BleCSCFeatures> {
|
|
8
|
+
parse(buffer: Buffer): BleCSCFeatures;
|
|
9
|
+
reset(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CscFeatures = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
class CscFeatures {
|
|
6
|
+
parse(buffer) {
|
|
7
|
+
const data = Buffer.from(buffer);
|
|
8
|
+
const value = data.readUInt8(0);
|
|
9
|
+
const bool = (bitNo) => (value & (0, utils_1.bit)(bitNo)) > 0;
|
|
10
|
+
return {
|
|
11
|
+
wheelRevolutionData: bool(0),
|
|
12
|
+
crankRevolutionData: bool(1),
|
|
13
|
+
multipleSensorLocations: bool(2)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
reset() {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CscFeatures = CscFeatures;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CrankData } from "../../cp";
|
|
2
|
+
import { CharacteristicParser, Feature } from "../types";
|
|
3
|
+
export type CyclingCadenceAndSpeed = {
|
|
4
|
+
cadence?: number;
|
|
5
|
+
speed?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class CscMeasurement implements CharacteristicParser<CyclingCadenceAndSpeed> {
|
|
8
|
+
protected data: CyclingCadenceAndSpeed;
|
|
9
|
+
protected prevCrankData: CrankData;
|
|
10
|
+
protected currentCrankData: CrankData;
|
|
11
|
+
protected prevWheelData: CrankData;
|
|
12
|
+
protected currentWheelData: CrankData;
|
|
13
|
+
protected timeOffset: number;
|
|
14
|
+
protected cw: number;
|
|
15
|
+
constructor(data?: CyclingCadenceAndSpeed);
|
|
16
|
+
setWheelCircumference(wheelCircumference: any): void;
|
|
17
|
+
parse(buffer: Buffer, features?: Feature): CyclingCadenceAndSpeed;
|
|
18
|
+
protected parseCrankData(crankData: any): {
|
|
19
|
+
rpm?: undefined;
|
|
20
|
+
time?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
rpm: number;
|
|
23
|
+
time: any;
|
|
24
|
+
};
|
|
25
|
+
protected parseWheelData(wheelData: any): {
|
|
26
|
+
speed?: undefined;
|
|
27
|
+
time?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
speed: number;
|
|
30
|
+
time: any;
|
|
31
|
+
};
|
|
32
|
+
reset(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CscMeasurement = void 0;
|
|
4
|
+
class CscMeasurement {
|
|
5
|
+
constructor(data = {}) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
this.prevCrankData = undefined;
|
|
8
|
+
this.currentCrankData = undefined;
|
|
9
|
+
this.prevWheelData = undefined;
|
|
10
|
+
this.currentWheelData = undefined;
|
|
11
|
+
this.timeOffset = 0;
|
|
12
|
+
this.cw = 2.1;
|
|
13
|
+
}
|
|
14
|
+
setWheelCircumference(wheelCircumference) {
|
|
15
|
+
this.cw = wheelCircumference;
|
|
16
|
+
}
|
|
17
|
+
parse(buffer, features) {
|
|
18
|
+
const data = Buffer.from(buffer);
|
|
19
|
+
let offset = 0;
|
|
20
|
+
const flags = data.readUInt8(offset);
|
|
21
|
+
offset++;
|
|
22
|
+
if (flags & 0x01) {
|
|
23
|
+
const wheelData = {
|
|
24
|
+
revolutions: data.readUInt32LE(offset),
|
|
25
|
+
time: data.readUInt16LE(offset + 4)
|
|
26
|
+
};
|
|
27
|
+
const { speed } = this.parseWheelData(wheelData);
|
|
28
|
+
this.data.speed = speed;
|
|
29
|
+
offset += 6;
|
|
30
|
+
}
|
|
31
|
+
if (flags & 0x02) {
|
|
32
|
+
const crankData = {
|
|
33
|
+
revolutions: data.readUInt16LE(offset),
|
|
34
|
+
time: data.readUInt16LE(offset + 2)
|
|
35
|
+
};
|
|
36
|
+
const { rpm } = this.parseCrankData(crankData);
|
|
37
|
+
this.data.cadence = rpm;
|
|
38
|
+
}
|
|
39
|
+
return this.data;
|
|
40
|
+
}
|
|
41
|
+
parseCrankData(crankData) {
|
|
42
|
+
if (!this.prevCrankData) {
|
|
43
|
+
this.prevCrankData = Object.assign(Object.assign({}, crankData), { cntUpdateMissing: -1 });
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
const c = this.currentCrankData = crankData;
|
|
47
|
+
const p = this.prevCrankData;
|
|
48
|
+
let rpm = this.data.cadence;
|
|
49
|
+
let hasUpdate = c.time !== p.time;
|
|
50
|
+
if (hasUpdate) {
|
|
51
|
+
let time = c.time - p.time;
|
|
52
|
+
let revs = c.revolutions - p.revolutions;
|
|
53
|
+
if (c.time < p.time) {
|
|
54
|
+
time += 0x10000;
|
|
55
|
+
this.timeOffset += 0x10000;
|
|
56
|
+
}
|
|
57
|
+
if (c.revolutions < p.revolutions)
|
|
58
|
+
revs += 0x10000;
|
|
59
|
+
rpm = 1024 * 60 * revs / time;
|
|
60
|
+
}
|
|
61
|
+
else if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
62
|
+
rpm = 0;
|
|
63
|
+
}
|
|
64
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
65
|
+
this.prevCrankData = this.currentCrankData;
|
|
66
|
+
if (hasUpdate)
|
|
67
|
+
this.prevCrankData.cntUpdateMissing = 0;
|
|
68
|
+
else
|
|
69
|
+
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
70
|
+
return { rpm, time: this.timeOffset + c.time };
|
|
71
|
+
}
|
|
72
|
+
parseWheelData(wheelData) {
|
|
73
|
+
if (!this.prevWheelData) {
|
|
74
|
+
this.prevWheelData = Object.assign(Object.assign({}, wheelData), { cntUpdateMissing: -1 });
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
const c = this.currentWheelData = wheelData;
|
|
78
|
+
const p = this.prevWheelData;
|
|
79
|
+
let speed = this.data.speed;
|
|
80
|
+
let hasUpdate = c.time !== p.time;
|
|
81
|
+
if (hasUpdate) {
|
|
82
|
+
let time = c.time - p.time;
|
|
83
|
+
let revs = c.revolutions - p.revolutions;
|
|
84
|
+
if (c.time < p.time) {
|
|
85
|
+
time += 0x10000;
|
|
86
|
+
this.timeOffset += 0x10000;
|
|
87
|
+
}
|
|
88
|
+
const rps = 1024 * revs / time;
|
|
89
|
+
speed = rps * this.cw;
|
|
90
|
+
}
|
|
91
|
+
else if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
92
|
+
speed = 0;
|
|
93
|
+
}
|
|
94
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
95
|
+
this.prevWheelData = this.currentWheelData;
|
|
96
|
+
if (hasUpdate)
|
|
97
|
+
this.prevWheelData.cntUpdateMissing = 0;
|
|
98
|
+
else
|
|
99
|
+
this.prevWheelData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
100
|
+
return { speed, time: this.timeOffset + c.time };
|
|
101
|
+
}
|
|
102
|
+
reset() {
|
|
103
|
+
this.data = {};
|
|
104
|
+
this.prevCrankData = undefined;
|
|
105
|
+
this.currentCrankData = undefined;
|
|
106
|
+
this.timeOffset = 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.CscMeasurement = CscMeasurement;
|
package/lib/ble/consts.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare const CSP_FEATURE = "2a65";
|
|
|
11
11
|
export declare const HR_MEASUREMENT = "2a37";
|
|
12
12
|
export declare const CSC = "1816";
|
|
13
13
|
export declare const CSC_MEASUREMENT = "2a5b";
|
|
14
|
+
export declare const CSC_FEATURE = "2a5c";
|
|
14
15
|
export declare const ELITE_TRAINER_SVC = "347b0001";
|
package/lib/ble/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ELITE_TRAINER_SVC = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.POWER_RANGE = exports.RES_LEVEL_RANGE = exports.FTMS_FEATURE = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = void 0;
|
|
3
|
+
exports.ELITE_TRAINER_SVC = exports.CSC_FEATURE = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.POWER_RANGE = exports.RES_LEVEL_RANGE = exports.FTMS_FEATURE = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = void 0;
|
|
4
4
|
exports.FTMS = '1826';
|
|
5
5
|
exports.FTMS_CP = '2ad9';
|
|
6
6
|
exports.FTMS_STATUS = '2ada';
|
|
@@ -14,4 +14,5 @@ exports.CSP_FEATURE = '2a65';
|
|
|
14
14
|
exports.HR_MEASUREMENT = '2a37';
|
|
15
15
|
exports.CSC = '1816';
|
|
16
16
|
exports.CSC_MEASUREMENT = '2a5b';
|
|
17
|
+
exports.CSC_FEATURE = '2a5c';
|
|
17
18
|
exports.ELITE_TRAINER_SVC = '347b0001';
|
package/lib/ble/cp/comm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CrankData, PowerData } from './types';
|
|
2
|
-
import { BleComms } from '../base/
|
|
2
|
+
import { BleComms } from '../base/comms';
|
|
3
3
|
import { LegacyProfile } from '../../antv2/types';
|
|
4
4
|
import { BleProtocol, IBlePeripheralConnector } from '../types';
|
|
5
5
|
export default class BleCyclingPowerDevice extends BleComms {
|
package/lib/ble/cp/comm.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const consts_1 = require("../consts");
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const
|
|
6
|
-
class BleCyclingPowerDevice extends
|
|
5
|
+
const comms_1 = require("../base/comms");
|
|
6
|
+
class BleCyclingPowerDevice extends comms_1.BleComms {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this.instantaneousPower = undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import BleAdapter from '../base/adapter';
|
|
2
|
+
import { BleDeviceSettings, IBlePeripheral } from '../types';
|
|
3
|
+
import { DeviceProperties, IncyclistCapability, IAdapter, IncyclistAdapterData } from '../../types';
|
|
4
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
5
|
+
import { BleCyclingSpeedCadenceDevice } from './sensor';
|
|
6
|
+
import { CSCData } from './types';
|
|
7
|
+
export declare class BleCSCAdapter extends BleAdapter<CSCData, BleCyclingSpeedCadenceDevice> {
|
|
8
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
9
|
+
protected static CAPABILITIES: IncyclistCapability[];
|
|
10
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
11
|
+
protected checkCapabilities(): Promise<void>;
|
|
12
|
+
isSame(device: IAdapter): boolean;
|
|
13
|
+
updateSensor(peripheral: IBlePeripheral): void;
|
|
14
|
+
getProfile(): LegacyProfile;
|
|
15
|
+
getDisplayName(): string;
|
|
16
|
+
mapData(deviceData: CSCData): IncyclistAdapterData;
|
|
17
|
+
}
|