incyclist-devices 2.3.32 → 2.3.34
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/antv2/fe/adapter.js +1 -1
- 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/fm/adapter.d.ts +3 -2
- package/lib/ble/fm/adapter.js +22 -7
- package/lib/ble/fm/sensor.js +17 -4
- 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/lib/modes/antble-smarttrainer.d.ts +1 -0
- package/lib/modes/antble-smarttrainer.js +10 -0
- package/lib/modes/power-base.d.ts +1 -1
- package/lib/modes/types.d.ts +2 -0
- package/lib/modes/types.js +3 -0
- package/package.json +1 -1
package/lib/antv2/fe/adapter.js
CHANGED
|
@@ -48,7 +48,7 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
48
48
|
return;
|
|
49
49
|
if (this.promiseStop)
|
|
50
50
|
return;
|
|
51
|
-
if (this.promiseSendUpdate) {
|
|
51
|
+
if (this.promiseSendUpdate !== undefined) {
|
|
52
52
|
this.logEvent({ message: 'send bike update skipped', device: this.getName(), request, reason: 'busy' });
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
@@ -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/fm/adapter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BleFitnessMachineDevice from './sensor';
|
|
2
2
|
import BleAdapter from '../base/adapter';
|
|
3
|
-
import ICyclingMode, { CyclingMode } from '../../modes/types';
|
|
3
|
+
import ICyclingMode, { CyclingMode, UpdateRequest } from '../../modes/types';
|
|
4
4
|
import { IndoorBikeData, IndoorBikeFeatures } from './types';
|
|
5
5
|
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties, IBlePeripheral } from '../types';
|
|
6
6
|
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../../types';
|
|
@@ -10,6 +10,7 @@ export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessM
|
|
|
10
10
|
protected distanceInternal: number;
|
|
11
11
|
protected connectPromise: Promise<boolean>;
|
|
12
12
|
protected requestControlRetryDelay: number;
|
|
13
|
+
protected promiseSendUpdate: Promise<UpdateRequest | void>;
|
|
13
14
|
constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
|
|
14
15
|
updateSensor(peripheral: IBlePeripheral): void;
|
|
15
16
|
isSame(device: IAdapter): boolean;
|
|
@@ -25,6 +26,6 @@ export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessM
|
|
|
25
26
|
protected sendInitialRequest(): Promise<void>;
|
|
26
27
|
protected checkCapabilities(): Promise<void>;
|
|
27
28
|
protected updateCapabilitiesFromFeatures(features: IndoorBikeFeatures): void;
|
|
28
|
-
sendUpdate(request: any, enforced?: boolean): Promise<void>;
|
|
29
|
+
sendUpdate(request: any, enforced?: boolean): Promise<UpdateRequest | void>;
|
|
29
30
|
sendInitCommands(): Promise<boolean>;
|
|
30
31
|
}
|
package/lib/ble/fm/adapter.js
CHANGED
|
@@ -233,6 +233,10 @@ class BleFmAdapter extends adapter_1.default {
|
|
|
233
233
|
sendUpdate(request_1) {
|
|
234
234
|
return __awaiter(this, arguments, void 0, function* (request, enforced = false) {
|
|
235
235
|
var _a;
|
|
236
|
+
if (this.promiseSendUpdate !== undefined) {
|
|
237
|
+
yield this.promiseSendUpdate;
|
|
238
|
+
this.promiseSendUpdate = undefined;
|
|
239
|
+
}
|
|
236
240
|
if (!enforced && (this.paused || !this.device))
|
|
237
241
|
return;
|
|
238
242
|
if (!enforced && (this.stopped && !this.isStarting()))
|
|
@@ -242,16 +246,27 @@ class BleFmAdapter extends adapter_1.default {
|
|
|
242
246
|
this.logEvent({ message: 'send bike update requested', profile: this.getProfile(), mode: (_a = this.getCyclingMode()) === null || _a === void 0 ? void 0 : _a.getName(), update, request });
|
|
243
247
|
const device = this.getSensor();
|
|
244
248
|
if (this.hasCapability(types_1.IncyclistCapability.Control)) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
const send = () => __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
const res = {};
|
|
251
|
+
if (update.slope !== undefined) {
|
|
252
|
+
yield device.setSlope(update.slope);
|
|
253
|
+
res.slope = update.slope;
|
|
254
|
+
}
|
|
255
|
+
if (update.targetPower !== undefined) {
|
|
256
|
+
const tp = update.targetPower > 0 ? update.targetPower : 0;
|
|
257
|
+
yield device.setTargetPower(tp);
|
|
258
|
+
res.targetPower = tp;
|
|
259
|
+
}
|
|
260
|
+
return res;
|
|
261
|
+
});
|
|
262
|
+
this.promiseSendUpdate = send();
|
|
263
|
+
const confirmed = yield this.promiseSendUpdate;
|
|
264
|
+
delete this.promiseSendUpdate;
|
|
265
|
+
return confirmed;
|
|
252
266
|
}
|
|
253
267
|
}
|
|
254
268
|
catch (err) {
|
|
269
|
+
delete this.promiseSendUpdate;
|
|
255
270
|
if (err.message === 'not connected') {
|
|
256
271
|
this.logEvent({ message: 'send bike update failed', reason: 'not connected' });
|
|
257
272
|
}
|
package/lib/ble/fm/sensor.js
CHANGED
|
@@ -13,6 +13,8 @@ const consts_1 = require("../consts");
|
|
|
13
13
|
const sensor_1 = require("../base/sensor");
|
|
14
14
|
const utils_1 = require("../utils");
|
|
15
15
|
const consts_2 = require("./consts");
|
|
16
|
+
const task_1 = require("../../utils/task");
|
|
17
|
+
const BLE_COMMAND_TIMEOUT = 800;
|
|
16
18
|
class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
17
19
|
constructor(peripheral, props) {
|
|
18
20
|
super(peripheral, props);
|
|
@@ -299,14 +301,25 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
|
299
301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
300
302
|
try {
|
|
301
303
|
this.logEvent({ message: 'fmts:write', data: data.toString('hex') });
|
|
302
|
-
|
|
304
|
+
let res;
|
|
305
|
+
let tsStart = Date.now();
|
|
306
|
+
if (props === null || props === void 0 ? void 0 : props.timeout) {
|
|
307
|
+
res = yield new task_1.InteruptableTask(this.write(consts_1.FTMS_CP, data, props), {
|
|
308
|
+
timeout: 800,
|
|
309
|
+
errorOnTimeout: true
|
|
310
|
+
}).run();
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
res = yield this.write(consts_1.FTMS_CP, data, props);
|
|
314
|
+
}
|
|
303
315
|
const responseData = Buffer.from(res);
|
|
304
316
|
const opCode = responseData.readUInt8(0);
|
|
305
317
|
const request = responseData.readUInt8(1);
|
|
306
318
|
const result = responseData.readUInt8(2);
|
|
307
319
|
if (opCode !== 128 || request !== requestedOpCode)
|
|
308
320
|
throw new Error('Illegal response ');
|
|
309
|
-
|
|
321
|
+
const duration = Date.now() - tsStart;
|
|
322
|
+
this.logEvent({ message: 'fmts:write result', res: responseData.toString('hex'), result, duration });
|
|
310
323
|
return result;
|
|
311
324
|
}
|
|
312
325
|
catch (err) {
|
|
@@ -330,7 +343,7 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
|
330
343
|
const data = Buffer.alloc(3);
|
|
331
344
|
data.writeUInt8(3, 0);
|
|
332
345
|
data.writeInt16LE(Math.round(inclination * 10), 1);
|
|
333
|
-
const res = yield this.writeFtmsMessage(3, data);
|
|
346
|
+
const res = yield this.writeFtmsMessage(3, data, { timeout: BLE_COMMAND_TIMEOUT });
|
|
334
347
|
return (res === 1);
|
|
335
348
|
});
|
|
336
349
|
}
|
|
@@ -350,7 +363,7 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
|
350
363
|
data.writeInt16LE(Math.round(gradient * 100), 3);
|
|
351
364
|
data.writeUInt8(Math.round(crr * 10000), 5);
|
|
352
365
|
data.writeUInt8(Math.round(cw * 100), 6);
|
|
353
|
-
const res = yield this.writeFtmsMessage(17, data);
|
|
366
|
+
const res = yield this.writeFtmsMessage(17, data, { timeout: BLE_COMMAND_TIMEOUT });
|
|
354
367
|
if (res === 5) {
|
|
355
368
|
this.hasControl = false;
|
|
356
369
|
}
|
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() {
|
|
@@ -48,6 +48,7 @@ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase i
|
|
|
48
48
|
protected checkEmptyRequest(newRequest: UpdateRequest): void;
|
|
49
49
|
protected getVirtualShiftMode(): VirtshiftMode;
|
|
50
50
|
updateData(bikeData: IncyclistBikeData, log?: boolean): IncyclistBikeData;
|
|
51
|
+
getData(): Partial<IncyclistBikeData>;
|
|
51
52
|
sendBikeUpdate(incoming: UpdateRequest): UpdateRequest;
|
|
52
53
|
protected setInitialGear(data: IncyclistBikeData): void;
|
|
53
54
|
protected getGearString(): string;
|
|
@@ -133,6 +133,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
133
133
|
const m = (_c = (_b = this.adapter) === null || _b === void 0 ? void 0 : _b.getWeight()) !== null && _c !== void 0 ? _c : 85;
|
|
134
134
|
this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = this.simSlope) !== null && _d !== void 0 ? _d : 0);
|
|
135
135
|
this.verifySimPower();
|
|
136
|
+
this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope });
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
newRequest.targetPower = this.simPower;
|
|
@@ -185,6 +186,9 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
185
186
|
const m = (_b = (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.getWeight()) !== null && _b !== void 0 ? _b : 85;
|
|
186
187
|
this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = (_c = this.simSlope) !== null && _c !== void 0 ? _c : this.data.slope) !== null && _d !== void 0 ? _d : 0);
|
|
187
188
|
this.verifySimPower();
|
|
189
|
+
this.logger.logEvent({ message: 'set simulater power', power: this.simPower, gear: this.gear, simSlope: this.simSlope, routeSlope: this.data.slope });
|
|
190
|
+
this.adapter.sendUpdate({ targetPower: this.simPower }).then(() => {
|
|
191
|
+
});
|
|
188
192
|
}
|
|
189
193
|
break;
|
|
190
194
|
case 'Adapter':
|
|
@@ -250,6 +254,11 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
250
254
|
}
|
|
251
255
|
return data;
|
|
252
256
|
}
|
|
257
|
+
getData() {
|
|
258
|
+
const gearStr = this.getGearString();
|
|
259
|
+
const data = super.getData();
|
|
260
|
+
return Object.assign(Object.assign({}, data), { gearStr });
|
|
261
|
+
}
|
|
253
262
|
sendBikeUpdate(incoming) {
|
|
254
263
|
this.logger.logEvent({ message: "processing update request", request: incoming, prev: this.prevRequest, data: this.getData() });
|
|
255
264
|
let newRequest = {};
|
|
@@ -278,6 +287,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
278
287
|
const deltas = requiredPowers.map((p, i) => ({ gear: i + 1, delta: Math.abs(p - data.power) }));
|
|
279
288
|
deltas.sort((a, b) => a.delta - b.delta);
|
|
280
289
|
this.gear = deltas[0].gear;
|
|
290
|
+
this.logger.logEvent({ message: 'set initial gear', gear: this.gear, m, rpm: data.pedalRpm, power: data.power });
|
|
281
291
|
}
|
|
282
292
|
getGearString() {
|
|
283
293
|
const mode = this.getVirtualShiftMode();
|
|
@@ -9,7 +9,7 @@ export default class PowerBasedCyclingModeBase extends CyclingModeBase {
|
|
|
9
9
|
prevRequest: UpdateRequest | undefined;
|
|
10
10
|
protected static config: CyclingModeConfig;
|
|
11
11
|
constructor(adapter: IAdapter, props?: Settings);
|
|
12
|
-
getData(): IncyclistBikeData
|
|
12
|
+
getData(): Partial<IncyclistBikeData>;
|
|
13
13
|
getSlope(): number;
|
|
14
14
|
initLogger(defaultLogName: any): void;
|
|
15
15
|
getWeight(): number;
|
package/lib/modes/types.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export default interface ICyclingMode {
|
|
|
47
47
|
getSettings(): Settings;
|
|
48
48
|
setModeProperty(name: string, value: any): void;
|
|
49
49
|
getModeProperty(name: string): any;
|
|
50
|
+
getData(): Partial<IncyclistBikeData>;
|
|
50
51
|
}
|
|
51
52
|
export type CyclingModeConfig = {
|
|
52
53
|
isERG?: boolean;
|
|
@@ -74,4 +75,5 @@ export declare class CyclingMode implements ICyclingMode {
|
|
|
74
75
|
getConfig(): CyclingModeConfig;
|
|
75
76
|
isERG(): boolean;
|
|
76
77
|
isSIM(): boolean;
|
|
78
|
+
getData(): Partial<IncyclistBikeData>;
|
|
77
79
|
}
|
package/lib/modes/types.js
CHANGED