incyclist-devices 2.3.0-beta.5 → 2.3.0-beta.7
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import IncyclistDevice from "../../base/adpater";
|
|
2
|
-
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties, IBlePeripheral } from "../types";
|
|
2
|
+
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties, IBleInterface, IBlePeripheral } from "../types";
|
|
3
3
|
import { IAdapter, IncyclistBikeData, IncyclistAdapterData, DeviceProperties } from "../../types";
|
|
4
4
|
import { BleDeviceData } from "./types";
|
|
5
5
|
import { LegacyProfile } from "../../antv2/types";
|
|
@@ -51,6 +51,7 @@ export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice exten
|
|
|
51
51
|
stop(): Promise<boolean>;
|
|
52
52
|
pause(): Promise<boolean>;
|
|
53
53
|
resume(): Promise<boolean>;
|
|
54
|
+
protected getBle(): IBleInterface<any>;
|
|
54
55
|
update(): void;
|
|
55
56
|
setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
|
|
56
57
|
}
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -38,20 +38,20 @@ class BleAdapter extends adpater_1.default {
|
|
|
38
38
|
}
|
|
39
39
|
connect() {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const
|
|
42
|
-
return yield
|
|
41
|
+
const ble = this.getBle();
|
|
42
|
+
return yield ble.connect();
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
getPeripheral() {
|
|
46
|
-
const
|
|
47
|
-
const p =
|
|
46
|
+
const ble = this.getBle();
|
|
47
|
+
const p = ble === null || ble === void 0 ? void 0 : ble.createPeripheralFromSettings(this.settings);
|
|
48
48
|
return p;
|
|
49
49
|
}
|
|
50
50
|
waitForPeripheral() {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
52
|
this.logEvent({ message: 'waiting for sensor ...', device: this.getName(), interface: this.getInterface() });
|
|
53
|
-
const
|
|
54
|
-
const peripheral = yield
|
|
53
|
+
const ble = this.getBle();
|
|
54
|
+
const peripheral = yield ble.waitForPeripheral(this.settings);
|
|
55
55
|
this.updateSensor(peripheral);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -256,7 +256,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
256
256
|
startAdapter(startProps) {
|
|
257
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
258
258
|
const props = this.getStartProps(startProps);
|
|
259
|
-
const { timeout = this.getDefaultStartupTimeout() } = startProps;
|
|
259
|
+
const { timeout = this.getDefaultStartupTimeout() } = startProps !== null && startProps !== void 0 ? startProps : {};
|
|
260
260
|
const wasPaused = this.paused;
|
|
261
261
|
const preCheckResult = yield this.startPreChecks(props);
|
|
262
262
|
if (preCheckResult === 'done') {
|
|
@@ -349,8 +349,8 @@ class BleAdapter extends adpater_1.default {
|
|
|
349
349
|
});
|
|
350
350
|
return __awaiter(this, void 0, void 0, function* () {
|
|
351
351
|
const res = yield _super.pause.call(this);
|
|
352
|
-
const
|
|
353
|
-
|
|
352
|
+
const ble = this.getBle();
|
|
353
|
+
ble.pauseLogging();
|
|
354
354
|
return res;
|
|
355
355
|
});
|
|
356
356
|
}
|
|
@@ -359,12 +359,15 @@ class BleAdapter extends adpater_1.default {
|
|
|
359
359
|
resume: { get: () => super.resume }
|
|
360
360
|
});
|
|
361
361
|
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
-
const
|
|
363
|
-
|
|
362
|
+
const ble = this.getBle();
|
|
363
|
+
ble.resumeLogging();
|
|
364
364
|
const res = yield _super.resume.call(this);
|
|
365
365
|
return res;
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
|
+
getBle() {
|
|
369
|
+
return interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
370
|
+
}
|
|
368
371
|
update() {
|
|
369
372
|
}
|
|
370
373
|
setCyclingMode(mode, settings, sendInitCommands) {
|
|
@@ -27,7 +27,7 @@ export declare class DirectConnectPeripheral implements IBlePeripheral {
|
|
|
27
27
|
onDisconnect(callback: () => void): void;
|
|
28
28
|
discoverServices(): Promise<string[]>;
|
|
29
29
|
discoverCharacteristics(serviceUUID: string): Promise<BleCharacteristic[]>;
|
|
30
|
-
subscribe(characteristicUUID: string, callback
|
|
30
|
+
subscribe(characteristicUUID: string, callback?: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
31
31
|
unsubscribe(characteristicUUID: string): Promise<boolean>;
|
|
32
32
|
subscribeAll(callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
33
33
|
subscribeSelected(characteristics: string[], callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
@@ -133,6 +133,10 @@ class DirectConnectPeripheral {
|
|
|
133
133
|
subscribe(characteristicUUID, callback) {
|
|
134
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
135
|
var _a, _b;
|
|
136
|
+
const uuid = (0, utils_1.parseUUID)(characteristicUUID);
|
|
137
|
+
if (this.subscribed.includes(uuid)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
136
140
|
const seqNo = this.getNextSeqNo();
|
|
137
141
|
const message = new messages_1.EnableCharacteristicNotificationsMessage();
|
|
138
142
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), enable: true });
|
|
@@ -149,10 +153,12 @@ class DirectConnectPeripheral {
|
|
|
149
153
|
this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
|
|
150
154
|
const confirmed = res.body.characteristicUUID;
|
|
151
155
|
if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
|
|
152
|
-
this.subscribed.push(characteristicUUID);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
this.subscribed.push((0, utils_1.parseUUID)(characteristicUUID));
|
|
157
|
+
if (callback) {
|
|
158
|
+
this.eventEmitter.on((0, utils_1.parseUUID)(characteristicUUID), (data) => {
|
|
159
|
+
callback(characteristicUUID, data);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
156
162
|
return true;
|
|
157
163
|
}
|
|
158
164
|
return false;
|
|
@@ -183,7 +189,7 @@ class DirectConnectPeripheral {
|
|
|
183
189
|
this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
|
|
184
190
|
const confirmed = res.body.characteristicUUID;
|
|
185
191
|
if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
|
|
186
|
-
this.subscribed.splice(this.subscribed.indexOf(characteristicUUID), 1);
|
|
192
|
+
this.subscribed.splice(this.subscribed.indexOf((0, utils_1.parseUUID)(characteristicUUID)), 1);
|
|
187
193
|
this.eventEmitter.removeAllListeners((0, utils_1.parseUUID)(characteristicUUID));
|
|
188
194
|
return true;
|
|
189
195
|
}
|
|
@@ -282,7 +288,7 @@ class DirectConnectPeripheral {
|
|
|
282
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
283
289
|
const promises = [];
|
|
284
290
|
this.subscribed.forEach(characteristicUUID => {
|
|
285
|
-
promises.push(this.unsubscribe(characteristicUUID));
|
|
291
|
+
promises.push(this.unsubscribe((0, utils_1.parseUUID)(characteristicUUID)));
|
|
286
292
|
});
|
|
287
293
|
yield Promise.allSettled(promises);
|
|
288
294
|
return true;
|
|
@@ -318,17 +324,18 @@ class DirectConnectPeripheral {
|
|
|
318
324
|
write(characteristicUUID, data, options) {
|
|
319
325
|
return __awaiter(this, void 0, void 0, function* () {
|
|
320
326
|
return new Promise(resolve => {
|
|
327
|
+
const seqNo = this.getNextSeqNo();
|
|
328
|
+
const message = new messages_1.WriteCharacteristicMessage();
|
|
329
|
+
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), characteristicData: data });
|
|
330
|
+
let response;
|
|
331
|
+
let characteristic = characteristicUUID;
|
|
321
332
|
if (!(options === null || options === void 0 ? void 0 : options.withoutResponse)) {
|
|
333
|
+
this.subscribe(characteristicUUID);
|
|
322
334
|
const uuid = (0, utils_1.parseUUID)(characteristicUUID);
|
|
323
335
|
this.eventEmitter.once(uuid, (data) => {
|
|
324
336
|
resolve(data);
|
|
325
337
|
});
|
|
326
338
|
}
|
|
327
|
-
const seqNo = this.getNextSeqNo();
|
|
328
|
-
const message = new messages_1.WriteCharacteristicMessage();
|
|
329
|
-
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), characteristicData: data });
|
|
330
|
-
let response;
|
|
331
|
-
let characteristic = characteristicUUID;
|
|
332
339
|
this.logEvent({ message: 'WriteCharacteristic request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID),
|
|
333
340
|
data: data.toString('hex'),
|
|
334
341
|
raw: request.toString('hex') });
|
|
@@ -488,10 +495,11 @@ class DirectConnectPeripheral {
|
|
|
488
495
|
this.msgSeqNo = notification.header.seqNum;
|
|
489
496
|
const uuid = (0, utils_1.parseUUID)(notification.body.characteristicUUID);
|
|
490
497
|
this.logEvent({ message: 'Characteristic notification', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(notification.body.characteristicUUID),
|
|
491
|
-
data: Buffer.from(notification.body.characteristicData).toString('hex') });
|
|
498
|
+
data: Buffer.from(notification.body.characteristicData).toString('hex'), raw: incoming.toString('hex') });
|
|
492
499
|
this.eventEmitter.emit(uuid, notification.body.characteristicData);
|
|
493
500
|
}
|
|
494
501
|
else {
|
|
502
|
+
this.logEvent({ message: 'incoming message', path: this.getPath(), raw: incoming.toString('hex'), header });
|
|
495
503
|
this.eventEmitter.emit(`response-${header.seqNum}`, incoming);
|
|
496
504
|
}
|
|
497
505
|
}
|