incyclist-devices 2.3.32 → 2.3.33
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/ble/base/adapter.d.ts +1 -0
- package/lib/ble/base/adapter.js +16 -2
- package/lib/ble/base/interface.d.ts +2 -2
- package/lib/ble/base/interface.js +3 -3
- package/lib/ble/base/peripheral.d.ts +2 -1
- package/lib/ble/base/peripheral.js +8 -0
- package/lib/ble/base/types.d.ts +7 -1
- package/lib/ble/types.d.ts +6 -0
- package/lib/ble/zwift/play/adapter.d.ts +1 -2
- package/lib/ble/zwift/play/adapter.js +0 -3
- package/lib/ble/zwift/play/sensor.d.ts +1 -1
- package/lib/ble/zwift/play/sensor.js +8 -5
- package/lib/direct-connect/base/peripheral.d.ts +2 -1
- package/lib/direct-connect/base/peripheral.js +10 -1
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice exten
|
|
|
19
19
|
connect(): Promise<boolean>;
|
|
20
20
|
getPeripheral(): IBlePeripheral;
|
|
21
21
|
waitForPeripheral(): Promise<void>;
|
|
22
|
+
protected updateSettings(peripheral: IBlePeripheral): void;
|
|
22
23
|
updateSensor(peripheral: IBlePeripheral): void;
|
|
23
24
|
close(): Promise<boolean>;
|
|
24
25
|
getSensor(): TDevice;
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -27,12 +27,12 @@ class BleAdapter extends adpater_1.default {
|
|
|
27
27
|
this.updateFrequency = 1000;
|
|
28
28
|
}
|
|
29
29
|
getUniqueName() {
|
|
30
|
-
var _a;
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
31
31
|
const settings = this.settings;
|
|
32
32
|
if (((_a = settings.name) === null || _a === void 0 ? void 0 : _a.match(/\d/g)) || settings.address === undefined)
|
|
33
33
|
return this.getName();
|
|
34
34
|
else {
|
|
35
|
-
const addressHash = settings.address.substring(0, 2) + settings.address.slice(-2);
|
|
35
|
+
const addressHash = (_d = (_c = (_b = settings.id) === null || _b === void 0 ? void 0 : _b.slice(-4)) === null || _c === void 0 ? void 0 : _c.toUpperCase()) !== null && _d !== void 0 ? _d : ((_f = (_e = settings.address) === null || _e === void 0 ? void 0 : _e.substring(0, 2)) !== null && _f !== void 0 ? _f : '') + ((_h = (_g = settings.address) === null || _g === void 0 ? void 0 : _g.slice(-2)) !== null && _h !== void 0 ? _h : '');
|
|
36
36
|
return `${this.getName()} ${addressHash}`;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -53,8 +53,21 @@ class BleAdapter extends adpater_1.default {
|
|
|
53
53
|
const ble = this.getBle();
|
|
54
54
|
const peripheral = yield ble.waitForPeripheral(this.settings);
|
|
55
55
|
this.updateSensor(peripheral);
|
|
56
|
+
this.updateSettings(peripheral);
|
|
56
57
|
});
|
|
57
58
|
}
|
|
59
|
+
updateSettings(peripheral) {
|
|
60
|
+
var _a, _b, _c;
|
|
61
|
+
try {
|
|
62
|
+
const info = peripheral.getInfo();
|
|
63
|
+
const settings = Object.assign({}, this.settings);
|
|
64
|
+
settings.id = (_a = settings.id) !== null && _a !== void 0 ? _a : info.id;
|
|
65
|
+
settings.address = (_b = settings.address) !== null && _b !== void 0 ? _b : info.address;
|
|
66
|
+
settings.name = (_c = settings.name) !== null && _c !== void 0 ? _c : info.name;
|
|
67
|
+
this.settings = settings;
|
|
68
|
+
}
|
|
69
|
+
catch (_d) { }
|
|
70
|
+
}
|
|
58
71
|
updateSensor(peripheral) {
|
|
59
72
|
throw new Error('method not implemented');
|
|
60
73
|
}
|
|
@@ -285,6 +298,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
285
298
|
this.stopped = false;
|
|
286
299
|
const connected = yield this.startSensor();
|
|
287
300
|
if (connected) {
|
|
301
|
+
this.updateSettings(this.getPeripheral());
|
|
288
302
|
this.logEvent({ message: 'peripheral connected', device: this.getName(), interface: this.getInterface() });
|
|
289
303
|
}
|
|
290
304
|
else {
|
|
@@ -62,8 +62,8 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
|
|
|
62
62
|
resumeLogging(): void;
|
|
63
63
|
isLoggingPaused(): boolean;
|
|
64
64
|
createPeripheral(announcement: BlePeripheralAnnouncement): IBlePeripheral;
|
|
65
|
-
createPeripheralFromSettings(settings:
|
|
66
|
-
waitForPeripheral(settings:
|
|
65
|
+
createPeripheralFromSettings(settings: BleDeviceSettings): IBlePeripheral;
|
|
66
|
+
waitForPeripheral(settings: BleDeviceSettings): Promise<IBlePeripheral>;
|
|
67
67
|
createDeviceSetting(service: BlePeripheralAnnouncement): BleDeviceSettings;
|
|
68
68
|
protected reconnect(): Promise<void>;
|
|
69
69
|
protected startPeripheralScan(retry?: boolean): Promise<void>;
|
|
@@ -248,7 +248,7 @@ class BleInterface extends events_1.default {
|
|
|
248
248
|
return new peripheral_1.BlePeripheral(announcement);
|
|
249
249
|
}
|
|
250
250
|
createPeripheralFromSettings(settings) {
|
|
251
|
-
const info = this.getAll().find(a => a.service.name === settings.name);
|
|
251
|
+
const info = this.getAll().find(a => { var _a, _b, _c; return ((_a = a.service) === null || _a === void 0 ? void 0 : _a.name) === settings.name || ((_c = (_b = a.service) === null || _b === void 0 ? void 0 : _b.peripheral) === null || _c === void 0 ? void 0 : _c.address) === settings.address; });
|
|
252
252
|
if (!(info === null || info === void 0 ? void 0 : info.service))
|
|
253
253
|
return null;
|
|
254
254
|
return this.createPeripheral(info.service);
|
|
@@ -262,8 +262,8 @@ class BleInterface extends events_1.default {
|
|
|
262
262
|
if (!wasDiscovering)
|
|
263
263
|
this.startPeripheralScan();
|
|
264
264
|
const onDevice = (device) => {
|
|
265
|
-
if (device.name === settings.name) {
|
|
266
|
-
const peripheral = this.createPeripheralFromSettings(
|
|
265
|
+
if (device.name === settings.name || device.address === settings.address) {
|
|
266
|
+
const peripheral = this.createPeripheralFromSettings(device);
|
|
267
267
|
if (peripheral) {
|
|
268
268
|
this.off('device', onDevice);
|
|
269
269
|
if (!wasDiscovering)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BleCharacteristic, BlePeripheralAnnouncement, BleRawCharacteristic, BleRawPeripheral, BleService, BleWriteProps, IBlePeripheral } from "../types";
|
|
1
|
+
import { BleCharacteristic, BleDeviceIdentifier, BlePeripheralAnnouncement, BleRawCharacteristic, BleRawPeripheral, BleService, BleWriteProps, IBlePeripheral } from "../types";
|
|
2
2
|
import { BleInterface } from "./interface";
|
|
3
3
|
export declare class BlePeripheral implements IBlePeripheral {
|
|
4
4
|
protected announcement: BlePeripheralAnnouncement;
|
|
@@ -17,6 +17,7 @@ export declare class BlePeripheral implements IBlePeripheral {
|
|
|
17
17
|
constructor(announcement: BlePeripheralAnnouncement);
|
|
18
18
|
get services(): BleService[];
|
|
19
19
|
getPeripheral(): BleRawPeripheral;
|
|
20
|
+
getInfo(): BleDeviceIdentifier;
|
|
20
21
|
connect(): Promise<boolean>;
|
|
21
22
|
disconnect(connectionLost?: boolean): Promise<boolean>;
|
|
22
23
|
isConnected(): boolean;
|
|
@@ -29,6 +29,14 @@ class BlePeripheral {
|
|
|
29
29
|
getPeripheral() {
|
|
30
30
|
return this.announcement.peripheral;
|
|
31
31
|
}
|
|
32
|
+
getInfo() {
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
34
|
+
return {
|
|
35
|
+
id: (_b = (_a = this.announcement) === null || _a === void 0 ? void 0 : _a.peripheral) === null || _b === void 0 ? void 0 : _b.id,
|
|
36
|
+
address: (_d = (_c = this.announcement) === null || _c === void 0 ? void 0 : _c.peripheral) === null || _d === void 0 ? void 0 : _d.address,
|
|
37
|
+
name: (_g = (_f = (_e = this.announcement) === null || _e === void 0 ? void 0 : _e.advertisement) === null || _f === void 0 ? void 0 : _f.localName) !== null && _g !== void 0 ? _g : (_j = (_h = this.announcement) === null || _h === void 0 ? void 0 : _h.peripheral) === null || _j === void 0 ? void 0 : _j.id,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
32
40
|
connect() {
|
|
33
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
42
|
if (this.isConnected())
|
package/lib/ble/base/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceSettings } from "../../types";
|
|
2
|
+
import { BleProtocol, IBleInterface } from "../types";
|
|
2
3
|
export interface BleDeviceData {
|
|
3
4
|
}
|
|
4
5
|
export interface IInterfaceFactory {
|
|
@@ -7,3 +8,8 @@ export interface IInterfaceFactory {
|
|
|
7
8
|
export declare class InterfaceFactory implements IInterfaceFactory {
|
|
8
9
|
getInterface(): IBleInterface<any>;
|
|
9
10
|
}
|
|
11
|
+
export interface BleDeviceSettings extends DeviceSettings {
|
|
12
|
+
id?: string;
|
|
13
|
+
protocol?: BleProtocol;
|
|
14
|
+
address?: string;
|
|
15
|
+
}
|
package/lib/ble/types.d.ts
CHANGED
|
@@ -61,6 +61,11 @@ export interface BleDeviceConstructProps extends BlePeripheralAnnouncement {
|
|
|
61
61
|
log?: boolean;
|
|
62
62
|
logger?: EventLogger;
|
|
63
63
|
}
|
|
64
|
+
export interface BleDeviceIdentifier {
|
|
65
|
+
id?: string;
|
|
66
|
+
address?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
}
|
|
64
69
|
export interface BleDeviceSettings extends DeviceSettings {
|
|
65
70
|
id?: string;
|
|
66
71
|
protocol: BleProtocol;
|
|
@@ -154,6 +159,7 @@ export interface IBlePeripheral {
|
|
|
154
159
|
read(characteristicUUID: string): Promise<Buffer>;
|
|
155
160
|
write(characteristicUUID: string, data: Buffer, options?: BleWriteProps): Promise<Buffer>;
|
|
156
161
|
getManufacturerData?(): Buffer;
|
|
162
|
+
getInfo(): BleDeviceIdentifier;
|
|
157
163
|
}
|
|
158
164
|
export interface IBleSensor extends EventEmitter {
|
|
159
165
|
startSensor(): Promise<boolean>;
|
|
@@ -3,13 +3,12 @@ import { LegacyProfile } from '../../../antv2/types';
|
|
|
3
3
|
import BleAdapter from '../../base/adapter';
|
|
4
4
|
import { BleZwiftPlaySensor } from './sensor';
|
|
5
5
|
import { DeviceProperties, IAdapter, IncyclistAdapterData, IncyclistCapability } from '../../../types';
|
|
6
|
-
import { BleDeviceSettings,
|
|
6
|
+
import { BleDeviceSettings, IBlePeripheral } from '../../types';
|
|
7
7
|
export declare class ZwiftPlayAdapter extends BleAdapter<BleDeviceData, BleZwiftPlaySensor> {
|
|
8
8
|
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
9
9
|
protected static CAPABILITIES: IncyclistCapability[];
|
|
10
10
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
11
11
|
protected checkCapabilities(): Promise<void>;
|
|
12
|
-
start(startProps?: BleStartProperties): Promise<boolean>;
|
|
13
12
|
startSensor(): Promise<boolean>;
|
|
14
13
|
isSame(adapter: IAdapter): boolean;
|
|
15
14
|
updateSensor(peripheral: IBlePeripheral): void;
|
|
@@ -35,7 +35,7 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
|
|
|
35
35
|
read(characteristic: string, ignoreErrors?: boolean): Promise<Buffer | null>;
|
|
36
36
|
pair(): Promise<boolean>;
|
|
37
37
|
reset(): void;
|
|
38
|
-
protected
|
|
38
|
+
protected encryptedSupported(): boolean;
|
|
39
39
|
protected createKeyPair(): import("crypto").KeyPairSyncResult<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
|
|
40
40
|
protected setInitialState(): void;
|
|
41
41
|
protected getManufacturerData(): string;
|
|
@@ -172,13 +172,15 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
172
172
|
pair() {
|
|
173
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
174
|
var _a, _b;
|
|
175
|
+
let manufacturerData;
|
|
175
176
|
try {
|
|
176
177
|
if (this.peripheral.getManufacturerData) {
|
|
177
|
-
|
|
178
|
+
manufacturerData = this.getManufacturerData();
|
|
178
179
|
if (manufacturerData === null || manufacturerData === void 0 ? void 0 : manufacturerData.startsWith('4a09')) {
|
|
179
180
|
const typeVal = Number('0x' + manufacturerData.substring(2, 4));
|
|
180
181
|
if (typeVal === 9) {
|
|
181
182
|
this.deviceType = 'click';
|
|
183
|
+
this.encrypted = false;
|
|
182
184
|
}
|
|
183
185
|
else if (typeVal === 2) {
|
|
184
186
|
this.deviceType = 'right';
|
|
@@ -188,13 +190,14 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
|
-
|
|
193
|
+
if (!this.encryptedSupported()) {
|
|
192
194
|
this.deviceType = 'click';
|
|
195
|
+
this.encrypted = false;
|
|
193
196
|
}
|
|
197
|
+
this.logEvent({ message: 'Play protocol pairing info', deviceType: this.deviceType, encrypted: this.encrypted, manufacturerData });
|
|
194
198
|
let message;
|
|
195
|
-
if (this.
|
|
199
|
+
if (!this.encrypted) {
|
|
196
200
|
message = Buffer.from('RideOn');
|
|
197
|
-
this.encrypted = false;
|
|
198
201
|
}
|
|
199
202
|
else {
|
|
200
203
|
const { publicKey, privateKey } = this.createKeyPair();
|
|
@@ -213,7 +216,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
213
216
|
}
|
|
214
217
|
reset() {
|
|
215
218
|
}
|
|
216
|
-
|
|
219
|
+
encryptedSupported() {
|
|
217
220
|
return crypto_1.generateKeyPairSync !== undefined && typeof (crypto_1.generateKeyPairSync) === 'function';
|
|
218
221
|
}
|
|
219
222
|
createKeyPair() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BleCharacteristic, BleService, BleWriteProps, IBlePeripheral } from "../../ble/types";
|
|
1
|
+
import { BleCharacteristic, BleDeviceIdentifier, BleService, BleWriteProps, IBlePeripheral } from "../../ble/types";
|
|
2
2
|
import { DirectConnectBinding, MulticastDnsAnnouncement, Socket } from "../bindings";
|
|
3
3
|
import { InteruptableTask, TaskState } from "../../utils/task";
|
|
4
4
|
import DirectConnectInterface from "./interface";
|
|
@@ -19,6 +19,7 @@ export declare class DirectConnectPeripheral implements IBlePeripheral {
|
|
|
19
19
|
protected subscribed: Array<string>;
|
|
20
20
|
protected onDisconnectHandler: () => void;
|
|
21
21
|
constructor(announcement: MulticastDnsAnnouncement);
|
|
22
|
+
getInfo(): BleDeviceIdentifier;
|
|
22
23
|
get services(): BleService[];
|
|
23
24
|
connect(): Promise<boolean>;
|
|
24
25
|
disconnect(connectionLost?: boolean): Promise<boolean>;
|
|
@@ -38,8 +38,17 @@ class DirectConnectPeripheral {
|
|
|
38
38
|
this.eventEmitter = new events_1.default();
|
|
39
39
|
this.subscribed = [];
|
|
40
40
|
}
|
|
41
|
+
getInfo() {
|
|
42
|
+
var _a, _b, _c, _d;
|
|
43
|
+
return {
|
|
44
|
+
id: (_b = (_a = this.announcement) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.replace(/:/g, ''),
|
|
45
|
+
address: (_c = this.announcement) === null || _c === void 0 ? void 0 : _c.address,
|
|
46
|
+
name: (_d = this.announcement) === null || _d === void 0 ? void 0 : _d.name
|
|
47
|
+
};
|
|
48
|
+
}
|
|
41
49
|
get services() {
|
|
42
|
-
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const services = (_b = (_a = this.announcement) === null || _a === void 0 ? void 0 : _a.serviceUUIDs) !== null && _b !== void 0 ? _b : [];
|
|
43
52
|
return services.map(s => ({ uuid: s }));
|
|
44
53
|
}
|
|
45
54
|
connect() {
|