incyclist-devices 3.0.17 → 3.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/ble/base/adapter.js +1 -1
- package/lib/cjs/ble/base/peripheral.js +19 -4
- package/lib/cjs/ble/base/sensor.js +7 -6
- package/lib/cjs/ble/fm/sensor.js +5 -0
- package/lib/esm/ble/base/adapter.js +1 -1
- package/lib/esm/ble/base/peripheral.js +19 -4
- package/lib/esm/ble/base/sensor.js +7 -6
- package/lib/esm/ble/fm/sensor.js +5 -0
- package/lib/types/ble/base/sensor.d.ts +2 -2
- package/lib/types/ble/fm/sensor.d.ts +1 -0
- package/package.json +1 -1
|
@@ -359,7 +359,7 @@ class BleAdapter extends adpater_js_1.default {
|
|
|
359
359
|
sensor.off('data', this.onDeviceDataHandler);
|
|
360
360
|
let connected = false;
|
|
361
361
|
if (sensor.isReconnectBusy()) {
|
|
362
|
-
connected = await sensor.reconnectSensor();
|
|
362
|
+
connected = await sensor.reconnectSensor(false);
|
|
363
363
|
}
|
|
364
364
|
if (connected) {
|
|
365
365
|
sensor.on('data', this.onDeviceDataHandler);
|
|
@@ -50,6 +50,7 @@ class BlePeripheral {
|
|
|
50
50
|
if (this.connectPromise !== undefined) {
|
|
51
51
|
return this.connectPromise.then(() => this.connected);
|
|
52
52
|
}
|
|
53
|
+
let address;
|
|
53
54
|
this.connectPromise = new Promise((done) => {
|
|
54
55
|
const peripheral = this.getPeripheral();
|
|
55
56
|
this.connected = false;
|
|
@@ -60,7 +61,8 @@ class BlePeripheral {
|
|
|
60
61
|
if (!this.ble.isConnected()) {
|
|
61
62
|
return done();
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
address = peripheral.address;
|
|
65
|
+
this.logEvent({ message: 'connect peripheral', address });
|
|
64
66
|
peripheral.connectAsync().then(() => {
|
|
65
67
|
this.ble.registerConnected(this, peripheralId);
|
|
66
68
|
peripheral.once('disconnect', () => { this.onPeripheralDisconnect(); });
|
|
@@ -75,11 +77,12 @@ class BlePeripheral {
|
|
|
75
77
|
});
|
|
76
78
|
await this.connectPromise;
|
|
77
79
|
delete this.connectPromise;
|
|
80
|
+
this.logEvent({ message: 'connect peripheral result', address, connected: this.connected });
|
|
78
81
|
return this.connected;
|
|
79
82
|
}
|
|
80
83
|
async disconnect(connectionLost = false) {
|
|
81
84
|
this.disconnecting = true;
|
|
82
|
-
if (this.isConnected()) {
|
|
85
|
+
if (this.isConnected() || connectionLost) {
|
|
83
86
|
await this.unsubscribeAll(connectionLost);
|
|
84
87
|
}
|
|
85
88
|
Object.keys(this.characteristics).forEach(uuid => {
|
|
@@ -101,13 +104,14 @@ class BlePeripheral {
|
|
|
101
104
|
.catch(() => { });
|
|
102
105
|
}
|
|
103
106
|
peripheral.removeAllListeners();
|
|
107
|
+
this.ble.unregisterConnected(peripheral.id);
|
|
104
108
|
}
|
|
105
109
|
else {
|
|
106
110
|
delete this.onDisconnectHandler;
|
|
107
111
|
}
|
|
108
|
-
this.ble.unregisterConnected(peripheral.id);
|
|
109
112
|
this.connected = false;
|
|
110
113
|
this.disconnecting = false;
|
|
114
|
+
this.logEvent({ message: 'peripheral disconnect completed', address: peripheral.address });
|
|
111
115
|
return !this.connected;
|
|
112
116
|
}
|
|
113
117
|
isConnected() {
|
|
@@ -200,8 +204,12 @@ class BlePeripheral {
|
|
|
200
204
|
}
|
|
201
205
|
async subscribe(characteristicUUID, callback) {
|
|
202
206
|
try {
|
|
203
|
-
if (this.disconnecting || !this.connected)
|
|
207
|
+
if (this.disconnecting || !this.connected) {
|
|
208
|
+
this.logEvent({ message: 'peripheral subscribe failed', uuid: characteristicUUID, reason: 'not connected',
|
|
209
|
+
disconnecting: this.disconnecting, connected: this.connected
|
|
210
|
+
});
|
|
204
211
|
return false;
|
|
212
|
+
}
|
|
205
213
|
const uuid = (0, utils_js_2.beautifyUUID)(characteristicUUID);
|
|
206
214
|
const onData = (data, isNotify) => {
|
|
207
215
|
try {
|
|
@@ -211,6 +219,7 @@ class BlePeripheral {
|
|
|
211
219
|
};
|
|
212
220
|
const subscription = this.subscribed.find(s => s.uuid === uuid);
|
|
213
221
|
if (subscription) {
|
|
222
|
+
this.logEvent({ message: 'peripheral subscribe skipped', uuid: characteristicUUID, reason: 'already subscribed' });
|
|
214
223
|
const c = this.getRawCharacteristic(characteristicUUID);
|
|
215
224
|
if (c) {
|
|
216
225
|
c.off('data', onData);
|
|
@@ -220,11 +229,13 @@ class BlePeripheral {
|
|
|
220
229
|
}
|
|
221
230
|
let c = await this.queryRawCharacteristic(characteristicUUID).catch(() => null);
|
|
222
231
|
if (!c) {
|
|
232
|
+
this.logEvent({ message: 'peripheral subscribe failed', uuid: characteristicUUID, reason: 'not found' });
|
|
223
233
|
return false;
|
|
224
234
|
}
|
|
225
235
|
return new Promise((resolve, reject) => {
|
|
226
236
|
const info = this.subscribed.find(s => s.uuid === characteristicUUID);
|
|
227
237
|
if (info) {
|
|
238
|
+
this.logEvent({ message: 'peripheral subscribe skipped', uuid: characteristicUUID, reason: 'already subscribed' });
|
|
228
239
|
return Promise.resolve(true);
|
|
229
240
|
}
|
|
230
241
|
this.logEvent({ message: 'subscribe request', address: this.getPeripheral().address, characteristic: uuid, success: true });
|
|
@@ -287,6 +298,8 @@ class BlePeripheral {
|
|
|
287
298
|
}
|
|
288
299
|
}
|
|
289
300
|
async subscribeSelected(characteristics, callback) {
|
|
301
|
+
const uuids = characteristics != null ? characteristics.map(c => (0, utils_js_2.beautifyUUID)(c)).join('|') : 'none';
|
|
302
|
+
this.logEvent({ message: 'peripheral subscribe selected', uuids });
|
|
290
303
|
if (!this.discoveredServiceUUIds) {
|
|
291
304
|
try {
|
|
292
305
|
await this.discoverServices();
|
|
@@ -349,6 +362,7 @@ class BlePeripheral {
|
|
|
349
362
|
}
|
|
350
363
|
}
|
|
351
364
|
async subscribeAll(callback) {
|
|
365
|
+
this.logEvent({ message: 'peripheral subscribe all' });
|
|
352
366
|
if (!this.discoveredServiceUUIds) {
|
|
353
367
|
try {
|
|
354
368
|
await this.discoverServices();
|
|
@@ -360,6 +374,7 @@ class BlePeripheral {
|
|
|
360
374
|
return success;
|
|
361
375
|
}
|
|
362
376
|
async unsubscribeAll(connectionLost = false) {
|
|
377
|
+
this.logEvent({ message: 'peripheral unsubscribe all', connectionLost });
|
|
363
378
|
if (connectionLost) {
|
|
364
379
|
this.subscribed = [];
|
|
365
380
|
return;
|
|
@@ -112,18 +112,19 @@ class TBleSensor extends node_events_1.EventEmitter {
|
|
|
112
112
|
isReconnectBusy() {
|
|
113
113
|
return (this.reconnectPromise !== undefined);
|
|
114
114
|
}
|
|
115
|
-
async reconnectSensor() {
|
|
115
|
+
async reconnectSensor(connectionLost = true) {
|
|
116
116
|
if (this.reconnectPromise !== undefined) {
|
|
117
117
|
return await this.reconnectPromise;
|
|
118
118
|
}
|
|
119
|
-
this.reconnectPromise = this.doReconnectSensor();
|
|
119
|
+
this.reconnectPromise = this.doReconnectSensor(connectionLost);
|
|
120
120
|
const res = await this.reconnectPromise;
|
|
121
121
|
delete this.reconnectPromise;
|
|
122
122
|
return res;
|
|
123
123
|
}
|
|
124
|
-
async doReconnectSensor() {
|
|
124
|
+
async doReconnectSensor(connectionLost = true) {
|
|
125
125
|
this.onDisconnect();
|
|
126
|
-
this.
|
|
126
|
+
const { name, address } = this.peripheral?.getInfo() ?? {};
|
|
127
|
+
this.logEvent({ message: 'reconnect sensor', name, address, connectionLost });
|
|
127
128
|
let connected = false;
|
|
128
129
|
let subscribed = false;
|
|
129
130
|
let success = false;
|
|
@@ -143,8 +144,8 @@ class TBleSensor extends node_events_1.EventEmitter {
|
|
|
143
144
|
if (!success) {
|
|
144
145
|
await (0, utils_js_1.sleep)(1000);
|
|
145
146
|
}
|
|
146
|
-
if (!this.stopRequested)
|
|
147
|
-
this.logEvent({ message: 'reconnect sensor retry' });
|
|
147
|
+
if (!this.stopRequested && !success)
|
|
148
|
+
this.logEvent({ message: 'reconnect sensor retry', name, address });
|
|
148
149
|
} while (!success || this.stopRequested);
|
|
149
150
|
this.logEvent({ message: 'reconnect sensor completed', success, stopRequested: this.stopRequested });
|
|
150
151
|
return success;
|
package/lib/cjs/ble/fm/sensor.js
CHANGED
|
@@ -22,6 +22,7 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
|
|
|
22
22
|
windSpeed = 0;
|
|
23
23
|
wheelSize = 2100;
|
|
24
24
|
ftmsServiceData;
|
|
25
|
+
ftmsServiceDataAttempts = 0;
|
|
25
26
|
rowerDataTS;
|
|
26
27
|
rowerMaxPower;
|
|
27
28
|
constructor(peripheral, props) {
|
|
@@ -102,6 +103,7 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
|
|
|
102
103
|
}
|
|
103
104
|
onDisconnect() {
|
|
104
105
|
this.hasControl = false;
|
|
106
|
+
this.ftmsServiceDataAttempts = 0;
|
|
105
107
|
}
|
|
106
108
|
async requestControl() {
|
|
107
109
|
if (this.hasControl) {
|
|
@@ -472,11 +474,14 @@ class BleFitnessMachineDevice extends sensor_js_1.TBleSensor {
|
|
|
472
474
|
parseServiceData() {
|
|
473
475
|
if (this.ftmsServiceData)
|
|
474
476
|
return this.ftmsServiceData;
|
|
477
|
+
if (this.ftmsServiceDataAttempts > 3)
|
|
478
|
+
return this.ftmsServiceData;
|
|
475
479
|
try {
|
|
476
480
|
const peripheral = this.peripheral;
|
|
477
481
|
if (peripheral?.getServiceData === undefined)
|
|
478
482
|
return;
|
|
479
483
|
const bitSet = (value, bitNo) => (value & (0, utils_js_1.bit)(bitNo)) > 0;
|
|
484
|
+
this.ftmsServiceDataAttempts++;
|
|
480
485
|
const data = peripheral.getServiceData(consts_js_1.FTMS);
|
|
481
486
|
const dataLength = data?.length ?? 0;
|
|
482
487
|
if (dataLength >= 2) {
|
|
@@ -354,7 +354,7 @@ export default class BleAdapter extends IncyclistDevice {
|
|
|
354
354
|
sensor.off('data', this.onDeviceDataHandler);
|
|
355
355
|
let connected = false;
|
|
356
356
|
if (sensor.isReconnectBusy()) {
|
|
357
|
-
connected = await sensor.reconnectSensor();
|
|
357
|
+
connected = await sensor.reconnectSensor(false);
|
|
358
358
|
}
|
|
359
359
|
if (connected) {
|
|
360
360
|
sensor.on('data', this.onDeviceDataHandler);
|
|
@@ -47,6 +47,7 @@ export class BlePeripheral {
|
|
|
47
47
|
if (this.connectPromise !== undefined) {
|
|
48
48
|
return this.connectPromise.then(() => this.connected);
|
|
49
49
|
}
|
|
50
|
+
let address;
|
|
50
51
|
this.connectPromise = new Promise((done) => {
|
|
51
52
|
const peripheral = this.getPeripheral();
|
|
52
53
|
this.connected = false;
|
|
@@ -57,7 +58,8 @@ export class BlePeripheral {
|
|
|
57
58
|
if (!this.ble.isConnected()) {
|
|
58
59
|
return done();
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
address = peripheral.address;
|
|
62
|
+
this.logEvent({ message: 'connect peripheral', address });
|
|
61
63
|
peripheral.connectAsync().then(() => {
|
|
62
64
|
this.ble.registerConnected(this, peripheralId);
|
|
63
65
|
peripheral.once('disconnect', () => { this.onPeripheralDisconnect(); });
|
|
@@ -72,11 +74,12 @@ export class BlePeripheral {
|
|
|
72
74
|
});
|
|
73
75
|
await this.connectPromise;
|
|
74
76
|
delete this.connectPromise;
|
|
77
|
+
this.logEvent({ message: 'connect peripheral result', address, connected: this.connected });
|
|
75
78
|
return this.connected;
|
|
76
79
|
}
|
|
77
80
|
async disconnect(connectionLost = false) {
|
|
78
81
|
this.disconnecting = true;
|
|
79
|
-
if (this.isConnected()) {
|
|
82
|
+
if (this.isConnected() || connectionLost) {
|
|
80
83
|
await this.unsubscribeAll(connectionLost);
|
|
81
84
|
}
|
|
82
85
|
Object.keys(this.characteristics).forEach(uuid => {
|
|
@@ -98,13 +101,14 @@ export class BlePeripheral {
|
|
|
98
101
|
.catch(() => { });
|
|
99
102
|
}
|
|
100
103
|
peripheral.removeAllListeners();
|
|
104
|
+
this.ble.unregisterConnected(peripheral.id);
|
|
101
105
|
}
|
|
102
106
|
else {
|
|
103
107
|
delete this.onDisconnectHandler;
|
|
104
108
|
}
|
|
105
|
-
this.ble.unregisterConnected(peripheral.id);
|
|
106
109
|
this.connected = false;
|
|
107
110
|
this.disconnecting = false;
|
|
111
|
+
this.logEvent({ message: 'peripheral disconnect completed', address: peripheral.address });
|
|
108
112
|
return !this.connected;
|
|
109
113
|
}
|
|
110
114
|
isConnected() {
|
|
@@ -197,8 +201,12 @@ export class BlePeripheral {
|
|
|
197
201
|
}
|
|
198
202
|
async subscribe(characteristicUUID, callback) {
|
|
199
203
|
try {
|
|
200
|
-
if (this.disconnecting || !this.connected)
|
|
204
|
+
if (this.disconnecting || !this.connected) {
|
|
205
|
+
this.logEvent({ message: 'peripheral subscribe failed', uuid: characteristicUUID, reason: 'not connected',
|
|
206
|
+
disconnecting: this.disconnecting, connected: this.connected
|
|
207
|
+
});
|
|
201
208
|
return false;
|
|
209
|
+
}
|
|
202
210
|
const uuid = beautifyUUID(characteristicUUID);
|
|
203
211
|
const onData = (data, isNotify) => {
|
|
204
212
|
try {
|
|
@@ -208,6 +216,7 @@ export class BlePeripheral {
|
|
|
208
216
|
};
|
|
209
217
|
const subscription = this.subscribed.find(s => s.uuid === uuid);
|
|
210
218
|
if (subscription) {
|
|
219
|
+
this.logEvent({ message: 'peripheral subscribe skipped', uuid: characteristicUUID, reason: 'already subscribed' });
|
|
211
220
|
const c = this.getRawCharacteristic(characteristicUUID);
|
|
212
221
|
if (c) {
|
|
213
222
|
c.off('data', onData);
|
|
@@ -217,11 +226,13 @@ export class BlePeripheral {
|
|
|
217
226
|
}
|
|
218
227
|
let c = await this.queryRawCharacteristic(characteristicUUID).catch(() => null);
|
|
219
228
|
if (!c) {
|
|
229
|
+
this.logEvent({ message: 'peripheral subscribe failed', uuid: characteristicUUID, reason: 'not found' });
|
|
220
230
|
return false;
|
|
221
231
|
}
|
|
222
232
|
return new Promise((resolve, reject) => {
|
|
223
233
|
const info = this.subscribed.find(s => s.uuid === characteristicUUID);
|
|
224
234
|
if (info) {
|
|
235
|
+
this.logEvent({ message: 'peripheral subscribe skipped', uuid: characteristicUUID, reason: 'already subscribed' });
|
|
225
236
|
return Promise.resolve(true);
|
|
226
237
|
}
|
|
227
238
|
this.logEvent({ message: 'subscribe request', address: this.getPeripheral().address, characteristic: uuid, success: true });
|
|
@@ -284,6 +295,8 @@ export class BlePeripheral {
|
|
|
284
295
|
}
|
|
285
296
|
}
|
|
286
297
|
async subscribeSelected(characteristics, callback) {
|
|
298
|
+
const uuids = characteristics != null ? characteristics.map(c => beautifyUUID(c)).join('|') : 'none';
|
|
299
|
+
this.logEvent({ message: 'peripheral subscribe selected', uuids });
|
|
287
300
|
if (!this.discoveredServiceUUIds) {
|
|
288
301
|
try {
|
|
289
302
|
await this.discoverServices();
|
|
@@ -346,6 +359,7 @@ export class BlePeripheral {
|
|
|
346
359
|
}
|
|
347
360
|
}
|
|
348
361
|
async subscribeAll(callback) {
|
|
362
|
+
this.logEvent({ message: 'peripheral subscribe all' });
|
|
349
363
|
if (!this.discoveredServiceUUIds) {
|
|
350
364
|
try {
|
|
351
365
|
await this.discoverServices();
|
|
@@ -357,6 +371,7 @@ export class BlePeripheral {
|
|
|
357
371
|
return success;
|
|
358
372
|
}
|
|
359
373
|
async unsubscribeAll(connectionLost = false) {
|
|
374
|
+
this.logEvent({ message: 'peripheral unsubscribe all', connectionLost });
|
|
360
375
|
if (connectionLost) {
|
|
361
376
|
this.subscribed = [];
|
|
362
377
|
return;
|
|
@@ -109,18 +109,19 @@ export class TBleSensor extends EventEmitter {
|
|
|
109
109
|
isReconnectBusy() {
|
|
110
110
|
return (this.reconnectPromise !== undefined);
|
|
111
111
|
}
|
|
112
|
-
async reconnectSensor() {
|
|
112
|
+
async reconnectSensor(connectionLost = true) {
|
|
113
113
|
if (this.reconnectPromise !== undefined) {
|
|
114
114
|
return await this.reconnectPromise;
|
|
115
115
|
}
|
|
116
|
-
this.reconnectPromise = this.doReconnectSensor();
|
|
116
|
+
this.reconnectPromise = this.doReconnectSensor(connectionLost);
|
|
117
117
|
const res = await this.reconnectPromise;
|
|
118
118
|
delete this.reconnectPromise;
|
|
119
119
|
return res;
|
|
120
120
|
}
|
|
121
|
-
async doReconnectSensor() {
|
|
121
|
+
async doReconnectSensor(connectionLost = true) {
|
|
122
122
|
this.onDisconnect();
|
|
123
|
-
this.
|
|
123
|
+
const { name, address } = this.peripheral?.getInfo() ?? {};
|
|
124
|
+
this.logEvent({ message: 'reconnect sensor', name, address, connectionLost });
|
|
124
125
|
let connected = false;
|
|
125
126
|
let subscribed = false;
|
|
126
127
|
let success = false;
|
|
@@ -140,8 +141,8 @@ export class TBleSensor extends EventEmitter {
|
|
|
140
141
|
if (!success) {
|
|
141
142
|
await sleep(1000);
|
|
142
143
|
}
|
|
143
|
-
if (!this.stopRequested)
|
|
144
|
-
this.logEvent({ message: 'reconnect sensor retry' });
|
|
144
|
+
if (!this.stopRequested && !success)
|
|
145
|
+
this.logEvent({ message: 'reconnect sensor retry', name, address });
|
|
145
146
|
} while (!success || this.stopRequested);
|
|
146
147
|
this.logEvent({ message: 'reconnect sensor completed', success, stopRequested: this.stopRequested });
|
|
147
148
|
return success;
|
package/lib/esm/ble/fm/sensor.js
CHANGED
|
@@ -20,6 +20,7 @@ export default class BleFitnessMachineDevice extends TBleSensor {
|
|
|
20
20
|
windSpeed = 0;
|
|
21
21
|
wheelSize = 2100;
|
|
22
22
|
ftmsServiceData;
|
|
23
|
+
ftmsServiceDataAttempts = 0;
|
|
23
24
|
rowerDataTS;
|
|
24
25
|
rowerMaxPower;
|
|
25
26
|
constructor(peripheral, props) {
|
|
@@ -100,6 +101,7 @@ export default class BleFitnessMachineDevice extends TBleSensor {
|
|
|
100
101
|
}
|
|
101
102
|
onDisconnect() {
|
|
102
103
|
this.hasControl = false;
|
|
104
|
+
this.ftmsServiceDataAttempts = 0;
|
|
103
105
|
}
|
|
104
106
|
async requestControl() {
|
|
105
107
|
if (this.hasControl) {
|
|
@@ -470,11 +472,14 @@ export default class BleFitnessMachineDevice extends TBleSensor {
|
|
|
470
472
|
parseServiceData() {
|
|
471
473
|
if (this.ftmsServiceData)
|
|
472
474
|
return this.ftmsServiceData;
|
|
475
|
+
if (this.ftmsServiceDataAttempts > 3)
|
|
476
|
+
return this.ftmsServiceData;
|
|
473
477
|
try {
|
|
474
478
|
const peripheral = this.peripheral;
|
|
475
479
|
if (peripheral?.getServiceData === undefined)
|
|
476
480
|
return;
|
|
477
481
|
const bitSet = (value, bitNo) => (value & bit(bitNo)) > 0;
|
|
482
|
+
this.ftmsServiceDataAttempts++;
|
|
478
483
|
const data = peripheral.getServiceData(FTMS);
|
|
479
484
|
const dataLength = data?.length ?? 0;
|
|
480
485
|
if (dataLength >= 2) {
|
|
@@ -28,8 +28,8 @@ export declare class TBleSensor extends EventEmitter implements IBleSensor {
|
|
|
28
28
|
subscribe(): Promise<boolean>;
|
|
29
29
|
stopSensor(): Promise<boolean>;
|
|
30
30
|
isReconnectBusy(): boolean;
|
|
31
|
-
reconnectSensor(): Promise<boolean>;
|
|
32
|
-
doReconnectSensor(): Promise<boolean>;
|
|
31
|
+
reconnectSensor(connectionLost?: boolean): Promise<boolean>;
|
|
32
|
+
doReconnectSensor(connectionLost?: boolean): Promise<boolean>;
|
|
33
33
|
reset(): void;
|
|
34
34
|
isConnected(): boolean;
|
|
35
35
|
isSubscribed(): boolean;
|
|
@@ -19,6 +19,7 @@ export default class BleFitnessMachineDevice extends TBleSensor {
|
|
|
19
19
|
protected windSpeed: number;
|
|
20
20
|
protected wheelSize: number;
|
|
21
21
|
protected ftmsServiceData: FtmsServiceData;
|
|
22
|
+
protected ftmsServiceDataAttempts: number;
|
|
22
23
|
protected rowerDataTS: number | undefined;
|
|
23
24
|
protected rowerMaxPower: number | undefined;
|
|
24
25
|
constructor(peripheral: IBlePeripheral, props?: any);
|