incyclist-devices 2.4.9 → 2.4.11
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/base/adpater.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
|
|
|
19
19
|
protected static controllers: ControllerConfig;
|
|
20
20
|
protected user: User;
|
|
21
21
|
protected data: IncyclistAdapterData;
|
|
22
|
+
protected debugLogEnabled: boolean;
|
|
22
23
|
constructor(settings: DeviceSettings, props?: P);
|
|
23
24
|
supportsVirtualShifting(): boolean;
|
|
24
25
|
getLogger(): EventLogger;
|
|
@@ -73,5 +74,6 @@ export default class IncyclistDevice<P extends DeviceProperties> extends EventEm
|
|
|
73
74
|
onData(callback: OnDeviceDataCallback): void;
|
|
74
75
|
onScanStart(): void;
|
|
75
76
|
onScanStop(): void;
|
|
77
|
+
protected initDebugLog(): void;
|
|
76
78
|
}
|
|
77
79
|
export type IncyclistDeviceAdapter = IncyclistDevice<DeviceProperties>;
|
package/lib/base/adpater.js
CHANGED
|
@@ -31,6 +31,7 @@ class IncyclistDevice extends events_1.default {
|
|
|
31
31
|
this.user = {};
|
|
32
32
|
this.data = {};
|
|
33
33
|
this.cyclingMode = this.getDefaultCyclingMode();
|
|
34
|
+
this.debugLogEnabled = false;
|
|
34
35
|
}
|
|
35
36
|
supportsVirtualShifting() {
|
|
36
37
|
return false;
|
|
@@ -46,11 +47,9 @@ class IncyclistDevice extends events_1.default {
|
|
|
46
47
|
logEvent(event) {
|
|
47
48
|
if (!this.logger || this.paused)
|
|
48
49
|
return;
|
|
50
|
+
if (this.isDebugEnabled() && !this.debugLogEnabled)
|
|
51
|
+
this.initDebugLog();
|
|
49
52
|
this.logger.logEvent(event);
|
|
50
|
-
if (this.isDebugEnabled()) {
|
|
51
|
-
const logText = `~~~ ${this.getInterface()}: ${this.logger.getName()}`;
|
|
52
|
-
console.log(logText, event);
|
|
53
|
-
}
|
|
54
53
|
}
|
|
55
54
|
getName() {
|
|
56
55
|
return this.settings.name;
|
|
@@ -298,6 +297,26 @@ class IncyclistDevice extends events_1.default {
|
|
|
298
297
|
onScanStop() {
|
|
299
298
|
this.scanning = false;
|
|
300
299
|
}
|
|
300
|
+
initDebugLog() {
|
|
301
|
+
if (this.debugLogEnabled) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (this.isDebugEnabled() && this.logger) {
|
|
305
|
+
const logText = `~~~ ${this.getInterface()}: ${this.logger.getName()}`;
|
|
306
|
+
const logEvent = this.logger.logEvent.bind(this.logger);
|
|
307
|
+
this.logger.logEvent = (event) => {
|
|
308
|
+
try {
|
|
309
|
+
logEvent(event);
|
|
310
|
+
}
|
|
311
|
+
catch (_a) { }
|
|
312
|
+
try {
|
|
313
|
+
console.log(logText, event);
|
|
314
|
+
}
|
|
315
|
+
catch (_b) { }
|
|
316
|
+
};
|
|
317
|
+
this.debugLogEnabled = true;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
301
320
|
}
|
|
302
321
|
IncyclistDevice.controllers = {};
|
|
303
322
|
exports.default = IncyclistDevice;
|
package/lib/ble/fm/adapter.js
CHANGED
|
@@ -145,8 +145,10 @@ class BleFmAdapter extends adapter_1.default {
|
|
|
145
145
|
initVirtualShifting() {
|
|
146
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
147
|
var _a;
|
|
148
|
+
this.logEvent({ message: 'init virtual shifting', hasSensor: this.zwiftPlay !== undefined });
|
|
148
149
|
try {
|
|
149
|
-
this.zwiftPlay = (_a = this.zwiftPlay) !== null && _a !== void 0 ? _a : new play_1.BleZwiftPlaySensor(this.device);
|
|
150
|
+
this.zwiftPlay = (_a = this.zwiftPlay) !== null && _a !== void 0 ? _a : new play_1.BleZwiftPlaySensor(this.device, { logger: this.logger, isTrainer: true });
|
|
151
|
+
this.zwiftPlay.initHubService(false);
|
|
150
152
|
}
|
|
151
153
|
catch (err) {
|
|
152
154
|
this.logEvent({ message: 'could not init virtual shifting', reason: err.message });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventLogger } from "gd-eventlog";
|
|
1
2
|
import { LegacyProfile } from "../../../antv2/types";
|
|
2
3
|
import { HubCommand, HubRequest, SimulationParam } from "../../../proto/zwift_hub";
|
|
3
4
|
import { TBleSensor } from "../../base/sensor";
|
|
@@ -7,7 +8,11 @@ type ButtonState = {
|
|
|
7
8
|
pressed: boolean;
|
|
8
9
|
timestamp: number;
|
|
9
10
|
};
|
|
10
|
-
type
|
|
11
|
+
type BleZwiftPlaySensorProps = {
|
|
12
|
+
logger?: EventLogger;
|
|
13
|
+
isTrainer?: boolean;
|
|
14
|
+
};
|
|
15
|
+
type DeviceType = 'left' | 'right' | 'click' | 'hub';
|
|
11
16
|
export declare class BleZwiftPlaySensor extends TBleSensor {
|
|
12
17
|
static readonly profile: LegacyProfile;
|
|
13
18
|
static readonly protocol: BleProtocol;
|
|
@@ -15,7 +20,7 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
|
|
|
15
20
|
static readonly characteristics: any[];
|
|
16
21
|
static readonly detectionPriority = 1;
|
|
17
22
|
protected emitter: EventEmitter;
|
|
18
|
-
protected
|
|
23
|
+
protected isHubPairConfirmed: boolean;
|
|
19
24
|
protected encrypted: boolean;
|
|
20
25
|
protected deviceKey: Buffer;
|
|
21
26
|
protected prevClickMessage: string;
|
|
@@ -30,7 +35,9 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
|
|
|
30
35
|
protected isHubServicePaired: boolean;
|
|
31
36
|
protected isHubServiceSubscribed: boolean;
|
|
32
37
|
protected initHubServicePromise: Promise<boolean>;
|
|
33
|
-
|
|
38
|
+
protected pairPromise: Promise<boolean>;
|
|
39
|
+
protected subscribePromise: Promise<boolean>;
|
|
40
|
+
constructor(peripheral: IBlePeripheral | TBleSensor, props?: BleZwiftPlaySensorProps);
|
|
34
41
|
reconnectSensor(): Promise<void>;
|
|
35
42
|
stopSensor(): Promise<boolean>;
|
|
36
43
|
protected getRequiredCharacteristics(): Array<string>;
|
|
@@ -17,7 +17,12 @@ const crypto_1 = require("crypto");
|
|
|
17
17
|
const events_1 = require("events");
|
|
18
18
|
class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
19
19
|
constructor(peripheral, props) {
|
|
20
|
-
if (peripheral
|
|
20
|
+
if ((props === null || props === void 0 ? void 0 : props.isTrainer) && peripheral) {
|
|
21
|
+
const sensor = peripheral;
|
|
22
|
+
super(sensor.getPeripheral(), props);
|
|
23
|
+
this.isFM = true;
|
|
24
|
+
}
|
|
25
|
+
else if (peripheral &&
|
|
21
26
|
'startSensor' in peripheral && typeof peripheral.startSensor === 'function' &&
|
|
22
27
|
'getPeripheral' in peripheral && typeof peripheral.getPeripheral === 'function') {
|
|
23
28
|
super(peripheral.getPeripheral(), props);
|
|
@@ -70,28 +75,35 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
70
75
|
setSimulationData(data) {
|
|
71
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
77
|
var _a, _b, _c, _d;
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
try {
|
|
79
|
+
if (!this.isHubServiceActive) {
|
|
80
|
+
yield this.initHubService(false);
|
|
81
|
+
}
|
|
82
|
+
if (!this.isHubServiceActive || !this.isHubPairConfirmed)
|
|
83
|
+
return;
|
|
84
|
+
const crrx100000 = Math.round((_a = data === null || data === void 0 ? void 0 : data.crrx100000) !== null && _a !== void 0 ? _a : 400);
|
|
85
|
+
const cWax10000 = Math.round((_b = data === null || data === void 0 ? void 0 : data.cWax10000) !== null && _b !== void 0 ? _b : 5100);
|
|
86
|
+
const windx100 = Math.round((_c = data === null || data === void 0 ? void 0 : data.windx100) !== null && _c !== void 0 ? _c : 0);
|
|
87
|
+
let inclineX100 = Math.round((_d = data === null || data === void 0 ? void 0 : data.inclineX100) !== null && _d !== void 0 ? _d : 1);
|
|
88
|
+
if (inclineX100 === 0 || Number.isNaN(inclineX100))
|
|
89
|
+
inclineX100 = 1;
|
|
90
|
+
const simulation = { inclineX100, crrx100000, cWax10000, windx100 };
|
|
91
|
+
yield this.sendHubCommand({ simulation });
|
|
92
|
+
yield this.requestDataUpdate(512);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
this.logger.logEvent({ message: "error", fn: 'setSimulationData', data, error: err.message, stack: err.stack });
|
|
75
96
|
}
|
|
76
|
-
const crrx100000 = Math.round((_a = data === null || data === void 0 ? void 0 : data.crrx100000) !== null && _a !== void 0 ? _a : 400);
|
|
77
|
-
const cWax10000 = Math.round((_b = data === null || data === void 0 ? void 0 : data.cWax10000) !== null && _b !== void 0 ? _b : 5100);
|
|
78
|
-
const windx100 = Math.round((_c = data === null || data === void 0 ? void 0 : data.windx100) !== null && _c !== void 0 ? _c : 0);
|
|
79
|
-
let inclineX100 = Math.round((_d = data === null || data === void 0 ? void 0 : data.inclineX100) !== null && _d !== void 0 ? _d : 1);
|
|
80
|
-
if (inclineX100 === 0 || Number.isNaN(inclineX100))
|
|
81
|
-
inclineX100 = 1;
|
|
82
|
-
const simulation = { inclineX100, crrx100000, cWax10000, windx100 };
|
|
83
|
-
console.log('# set simulation data', simulation);
|
|
84
|
-
yield this.sendHubCommand({ simulation });
|
|
85
|
-
yield this.requestDataUpdate(512);
|
|
86
97
|
});
|
|
87
98
|
}
|
|
88
99
|
setGearRatio(gearRatio) {
|
|
89
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
101
|
try {
|
|
91
|
-
console.log('# set gear ratio', gearRatio);
|
|
92
102
|
if (!this.isHubServiceActive) {
|
|
93
103
|
yield this.initHubService();
|
|
94
104
|
}
|
|
105
|
+
if (!this.isHubServiceActive || !this.isHubPairConfirmed)
|
|
106
|
+
return;
|
|
95
107
|
const gearRatioX10000 = Math.round(gearRatio * 10000);
|
|
96
108
|
const bikeWeightx100 = 10 * 100;
|
|
97
109
|
const riderWeightx100 = 75 * 100;
|
|
@@ -102,7 +114,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
102
114
|
yield this.requestDataUpdate(512);
|
|
103
115
|
}
|
|
104
116
|
catch (err) {
|
|
105
|
-
|
|
117
|
+
this.logger.logEvent({ message: "error", fn: 'setGearRatio', gearRatio, error: err.message, stack: err.stack });
|
|
106
118
|
}
|
|
107
119
|
return gearRatio;
|
|
108
120
|
});
|
|
@@ -115,6 +127,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
115
127
|
}
|
|
116
128
|
onMeasurement(d) {
|
|
117
129
|
const data = Buffer.from(d);
|
|
130
|
+
this.logEvent({ message: 'got hub notification', raw: data.toString('hex') });
|
|
118
131
|
if ((data === null || data === void 0 ? void 0 : data.length) < 1) {
|
|
119
132
|
console.log('Invalid click measurement data', data.toString('hex'));
|
|
120
133
|
return false;
|
|
@@ -147,19 +160,39 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
147
160
|
if (!this.isHubServiceActive && this.initHubServicePromise !== undefined) {
|
|
148
161
|
yield this.initHubServicePromise;
|
|
149
162
|
}
|
|
163
|
+
const subscribe = () => __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
var _a;
|
|
165
|
+
if (!this.isHubServiceSubscribed) {
|
|
166
|
+
this.logEvent({ message: 'subscribe to hub service characteristics' });
|
|
167
|
+
this.subscribePromise = (_a = this.subscribePromise) !== null && _a !== void 0 ? _a : this.subscribe();
|
|
168
|
+
const subscribed = yield this.subscribePromise;
|
|
169
|
+
this.subscribePromise = undefined;
|
|
170
|
+
this.isHubServiceSubscribed = subscribed;
|
|
171
|
+
if (!subscribed)
|
|
172
|
+
return false;
|
|
173
|
+
this.logEvent({ message: 'subscribed to hub service characteristics' });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const pair = () => __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
if (!this.isHubServicePaired) {
|
|
178
|
+
this.logEvent({ message: 'pair hub service' });
|
|
179
|
+
this.pairPromise = this.pair();
|
|
180
|
+
const paired = yield this.pairPromise;
|
|
181
|
+
this.pairPromise = undefined;
|
|
182
|
+
if (!paired)
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
150
186
|
if (this.isHubServiceActive)
|
|
151
187
|
return true;
|
|
152
|
-
this.logEvent({ message: 'init hub service', paired: this.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
if (!this.isHubServiceSubscribed) {
|
|
158
|
-
yield this.subscribe();
|
|
159
|
-
this.isHubServiceSubscribed = true;
|
|
160
|
-
}
|
|
188
|
+
this.logEvent({ message: 'init hub service', paired: this.isHubPairConfirmed, subscribed: this.isHubServiceSubscribed });
|
|
189
|
+
yield subscribe();
|
|
190
|
+
yield pair();
|
|
191
|
+
yield subscribe();
|
|
161
192
|
this.initHubServicePromise = new Promise((done) => {
|
|
193
|
+
this.logEvent({ message: 'send hub init message' });
|
|
162
194
|
let timeout = setTimeout(() => {
|
|
195
|
+
this.logEvent({ message: 'could not init hub service', reason: 'timeout' });
|
|
163
196
|
done(false);
|
|
164
197
|
}, 2000);
|
|
165
198
|
this.once('hub-riding-data', () => {
|
|
@@ -168,8 +201,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
168
201
|
timeout = undefined;
|
|
169
202
|
}
|
|
170
203
|
this.isHubServiceActive = true;
|
|
171
|
-
|
|
172
|
-
this.logEvent({ message: 'init hub service done', paired: this.paired, subscribed: this.isHubServiceSubscribed });
|
|
204
|
+
this.logEvent({ message: 'init hub service done', paired: this.isHubServicePaired, confirmed: this.isHubPairConfirmed, subscribed: this.isHubServiceSubscribed });
|
|
173
205
|
if (setSimulation) {
|
|
174
206
|
this.logEvent({ message: 'hub: send initial simulation data' });
|
|
175
207
|
this.setSimulationData().then(() => {
|
|
@@ -189,7 +221,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
189
221
|
clearTimeout(timeout);
|
|
190
222
|
timeout = undefined;
|
|
191
223
|
}
|
|
192
|
-
console.log('# init hub service timeout');
|
|
193
224
|
done(false);
|
|
194
225
|
this.logEvent({ message: 'could not init hub service', reason: err.message });
|
|
195
226
|
});
|
|
@@ -200,7 +231,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
200
231
|
sendHubRequest(request) {
|
|
201
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
202
233
|
const message = Buffer.from(zwift_hub_1.HubRequest.toBinary(request));
|
|
203
|
-
console.log('# sending hub request', request, message);
|
|
204
234
|
this.logEvent({ mesage: 'send zwift hub request', request });
|
|
205
235
|
return yield this.sendPlayCommand(0x00, message);
|
|
206
236
|
});
|
|
@@ -208,7 +238,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
208
238
|
sendHubCommand(command) {
|
|
209
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
240
|
const message = Buffer.from(zwift_hub_1.HubCommand.toBinary(command));
|
|
211
|
-
console.log('# sending hub command', command, message);
|
|
212
241
|
this.logEvent({ mesage: 'send zwift hub command', command });
|
|
213
242
|
return yield this.sendPlayCommand(0x04, message);
|
|
214
243
|
});
|
|
@@ -218,7 +247,6 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
218
247
|
this.tsLastRidingData = Date.now();
|
|
219
248
|
const data = zwift_hub_1.HubRidingData.fromBinary(m);
|
|
220
249
|
this.emit('hub-riding-data', data);
|
|
221
|
-
console.log('#riding data', data);
|
|
222
250
|
this.logEvent({ message: 'riding data received', power: data.power, cadence: data.cadence, Speed: data.speedX100 / 100, heartrate: data.hR, unknown1: data.unknown1, unknown2: data.unknown2 });
|
|
223
251
|
}
|
|
224
252
|
catch (err) {
|
|
@@ -231,13 +259,11 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
231
259
|
const { messageType, payload } = envelope;
|
|
232
260
|
if (messageType < 16) {
|
|
233
261
|
const deviceInfo = zwift_hub_1.DeviceInformationContent.fromBinary(payload);
|
|
234
|
-
console.log('# deviceInfo', deviceInfo);
|
|
235
262
|
this.emit('hub-device-info', deviceInfo);
|
|
236
263
|
this.logEvent({ message: 'hub device info update', deviceInfo });
|
|
237
264
|
}
|
|
238
265
|
else if (messageType >= 512 && messageType < 526) {
|
|
239
266
|
const si = zwift_hub_1.DeviceSettings.fromBinary(payload);
|
|
240
|
-
console.log('# settings', si === null || si === void 0 ? void 0 : si.subContent);
|
|
241
267
|
this.emit('hub-settings', si === null || si === void 0 ? void 0 : si.subContent);
|
|
242
268
|
this.logEvent({ message: 'hub settings update', settings: si === null || si === void 0 ? void 0 : si.subContent });
|
|
243
269
|
}
|
|
@@ -287,11 +313,11 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
287
313
|
}
|
|
288
314
|
onPingMessage(message) {
|
|
289
315
|
const idle = zwift_hub_1.Idle.fromBinary(message);
|
|
290
|
-
|
|
291
|
-
this.emit('data', { deviceType: this.deviceType, paired: this.paired, alive: true, ts: Date.now() });
|
|
316
|
+
this.emit('data', { deviceType: this.deviceType, paired: this.isHubPairConfirmed, alive: true, ts: Date.now() });
|
|
292
317
|
}
|
|
293
318
|
onResponse(d) {
|
|
294
319
|
const data = Buffer.from(d);
|
|
320
|
+
this.logEvent({ message: 'got hub message', raw: data.toString('hex'), str: data.toString() });
|
|
295
321
|
if ((data === null || data === void 0 ? void 0 : data.length) < 1) {
|
|
296
322
|
console.log('Invalid response data', data.toString('hex'));
|
|
297
323
|
return false;
|
|
@@ -303,9 +329,9 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
303
329
|
}
|
|
304
330
|
else {
|
|
305
331
|
const len = data.length;
|
|
306
|
-
if (len
|
|
332
|
+
if (len == 6 && data.toString() === 'RideOn') {
|
|
307
333
|
this.encrypted = false;
|
|
308
|
-
this.
|
|
334
|
+
this.isHubPairConfirmed = true;
|
|
309
335
|
this.emitter.emit('paired');
|
|
310
336
|
try {
|
|
311
337
|
this.emit('data', { deviceType: this.deviceType, paired: true, ts: Date.now() });
|
|
@@ -318,7 +344,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
318
344
|
const message = Buffer.from(data.subarray(6, 2)).toString('hex');
|
|
319
345
|
if (message === '0900') {
|
|
320
346
|
this.encrypted = true;
|
|
321
|
-
this.
|
|
347
|
+
this.isHubPairConfirmed = true;
|
|
322
348
|
this.deviceKey = data.subarray(8);
|
|
323
349
|
this.emitter.emit('paired');
|
|
324
350
|
try {
|
|
@@ -332,6 +358,17 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
332
358
|
this.logEvent({ message: 'Pairing failed! ', reason: 'unknown message', raw: message });
|
|
333
359
|
}
|
|
334
360
|
}
|
|
361
|
+
else if (Buffer.from(data.subarray(0, 6)).toString() === 'RideOn') {
|
|
362
|
+
this.encrypted = false;
|
|
363
|
+
this.isHubPairConfirmed = true;
|
|
364
|
+
this.emitter.emit('paired');
|
|
365
|
+
try {
|
|
366
|
+
this.emit('data', { deviceType: this.deviceType, paired: true, ts: Date.now() });
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
this.logEvent({ message: 'error', fn: 'onPairResponse', error: err.message, stack: err.stack });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
335
372
|
return true;
|
|
336
373
|
}
|
|
337
374
|
}
|
|
@@ -352,12 +389,22 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
352
389
|
}
|
|
353
390
|
pair() {
|
|
354
391
|
return __awaiter(this, void 0, void 0, function* () {
|
|
355
|
-
var _a, _b;
|
|
392
|
+
var _a, _b, _c;
|
|
356
393
|
if (this.isHubServicePaired)
|
|
357
394
|
return true;
|
|
395
|
+
if (this.pairPromise !== undefined) {
|
|
396
|
+
const paired = yield this.pairPromise;
|
|
397
|
+
this.pairPromise = undefined;
|
|
398
|
+
if (paired)
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
358
401
|
let manufacturerData;
|
|
359
402
|
try {
|
|
360
|
-
if (this.
|
|
403
|
+
if (this.isFM) {
|
|
404
|
+
this.deviceType = 'hub';
|
|
405
|
+
this.encrypted = false;
|
|
406
|
+
}
|
|
407
|
+
else if (this.peripheral.getManufacturerData) {
|
|
361
408
|
manufacturerData = this.getManufacturerData();
|
|
362
409
|
if (manufacturerData === null || manufacturerData === void 0 ? void 0 : manufacturerData.startsWith('4a09')) {
|
|
363
410
|
const typeVal = Number('0x' + manufacturerData.substring(2, 4));
|
|
@@ -373,23 +420,29 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
373
420
|
}
|
|
374
421
|
}
|
|
375
422
|
}
|
|
376
|
-
if (!this.encryptedSupported()) {
|
|
423
|
+
if (!this.deviceType && !this.encryptedSupported()) {
|
|
377
424
|
this.deviceType = 'click';
|
|
378
425
|
this.encrypted = false;
|
|
379
426
|
}
|
|
427
|
+
this.deviceType = (_a = this.deviceType) !== null && _a !== void 0 ? _a : 'click';
|
|
380
428
|
this.logEvent({ message: 'Play protocol pairing info', deviceType: this.deviceType, encrypted: this.encrypted, manufacturerData });
|
|
381
429
|
let message;
|
|
382
|
-
if (
|
|
383
|
-
message =
|
|
430
|
+
if (this.isFM) {
|
|
431
|
+
message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x01])]);
|
|
384
432
|
}
|
|
385
|
-
else {
|
|
433
|
+
else if (this.encrypted) {
|
|
386
434
|
const { publicKey, privateKey } = this.createKeyPair();
|
|
387
|
-
this.privateKey = (
|
|
388
|
-
this.publicKey = (
|
|
435
|
+
this.privateKey = (_b = this.privateKey) !== null && _b !== void 0 ? _b : Buffer.from(privateKey);
|
|
436
|
+
this.publicKey = (_c = this.publicKey) !== null && _c !== void 0 ? _c : Buffer.from(publicKey);
|
|
389
437
|
message = Buffer.concat([Buffer.from('RideOn'), Buffer.from([0x02, 0x03]), this.publicKey]);
|
|
390
438
|
}
|
|
439
|
+
else {
|
|
440
|
+
message = Buffer.from('RideOn');
|
|
441
|
+
}
|
|
442
|
+
this.logEvent({ message: `send rideOn` });
|
|
391
443
|
yield this.write((0, utils_1.fullUUID)('00000003-19ca-4651-86e5-fa29dcdd09d1'), message, { withoutResponse: true });
|
|
392
444
|
this.isHubServicePaired = true;
|
|
445
|
+
this.logEvent({ message: 'pairing done', deviceType: this.deviceType, encrypted: this.encrypted, manufacturerData });
|
|
393
446
|
return true;
|
|
394
447
|
}
|
|
395
448
|
catch (err) {
|
|
@@ -412,7 +465,7 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
|
|
|
412
465
|
});
|
|
413
466
|
}
|
|
414
467
|
setInitialState() {
|
|
415
|
-
this.
|
|
468
|
+
this.isHubPairConfirmed = false;
|
|
416
469
|
this.encrypted = false;
|
|
417
470
|
this.deviceKey = null;
|
|
418
471
|
this.isHubServicePaired = false;
|
|
@@ -40,6 +40,7 @@ const types_1 = require("./types");
|
|
|
40
40
|
const power_base_1 = __importDefault(require("./power-base"));
|
|
41
41
|
const calculations_1 = __importStar(require("../utils/calculations"));
|
|
42
42
|
const features_1 = require("../features");
|
|
43
|
+
const utils_1 = require("../utils/utils");
|
|
43
44
|
const MIN_POWER = 25;
|
|
44
45
|
class SmartTrainerCyclingMode extends power_base_1.default {
|
|
45
46
|
constructor(adapter, props) {
|
|
@@ -54,7 +55,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
54
55
|
getBikeInitRequest() {
|
|
55
56
|
const virtshiftMode = this.getVirtualShiftMode();
|
|
56
57
|
if (virtshiftMode === 'Adapter') {
|
|
57
|
-
this.gear = this.getSetting('startGear');
|
|
58
|
+
this.gear = (0, utils_1.intVal)(this.getSetting('startGear'));
|
|
58
59
|
const gearRatio = this.gearRatios[this.gear - 1];
|
|
59
60
|
return { slope: 0, gearRatio };
|
|
60
61
|
}
|
|
@@ -254,6 +255,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
checkGearChange(request, newRequest = {}) {
|
|
258
|
+
var _a, _b;
|
|
257
259
|
const virtshiftMode = this.getVirtualShiftMode();
|
|
258
260
|
switch (virtshiftMode) {
|
|
259
261
|
case 'SlopeDelta':
|
|
@@ -267,11 +269,11 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
267
269
|
if (request.gearDelta !== undefined) {
|
|
268
270
|
const oldGear = this.gear;
|
|
269
271
|
if (this.gear === undefined) {
|
|
270
|
-
const initialGear =
|
|
271
|
-
this.gear = initialGear +
|
|
272
|
+
const initialGear = (0, utils_1.intVal)(this.getSetting('startGear'));
|
|
273
|
+
this.gear = initialGear + ((_a = (0, utils_1.intVal)(request.gearDelta)) !== null && _a !== void 0 ? _a : 0);
|
|
272
274
|
}
|
|
273
275
|
else {
|
|
274
|
-
this.gear +=
|
|
276
|
+
this.gear += ((_b = (0, utils_1.intVal)(request.gearDelta)) !== null && _b !== void 0 ? _b : 0);
|
|
275
277
|
}
|
|
276
278
|
if (this.gear < 1) {
|
|
277
279
|
this.gear = 1;
|
|
@@ -290,6 +292,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
290
292
|
break;
|
|
291
293
|
case 'Adapter':
|
|
292
294
|
if (request.gearRatio !== undefined) {
|
|
295
|
+
const oldGear = this.gear;
|
|
293
296
|
newRequest.gearRatio = request.gearRatio;
|
|
294
297
|
if (this.gear === undefined) {
|
|
295
298
|
const requestedRatio = request.gearRatio;
|
|
@@ -303,11 +306,13 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
303
306
|
}
|
|
304
307
|
}
|
|
305
308
|
this.gear = closestIndex + 1;
|
|
309
|
+
this.logger.logEvent({ message: 'gear changed', gear: this.gear, gearRatio: newRequest.gearRatio, oldGear });
|
|
306
310
|
}
|
|
307
311
|
}
|
|
308
312
|
else if (request.gearDelta !== undefined) {
|
|
313
|
+
const oldGear = this.gear;
|
|
309
314
|
if (this.gear === undefined) {
|
|
310
|
-
const initialGear =
|
|
315
|
+
const initialGear = (0, utils_1.intVal)(this.getSetting('startGear'));
|
|
311
316
|
this.gear = initialGear + request.gearDelta;
|
|
312
317
|
}
|
|
313
318
|
else {
|
|
@@ -321,13 +326,15 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
321
326
|
}
|
|
322
327
|
delete request.gearDelta;
|
|
323
328
|
newRequest.gearRatio = this.gearRatios[this.gear];
|
|
329
|
+
this.logger.logEvent({ message: 'gear changed', gear: this.gear, gearRatio: newRequest.gearRatio, oldGear });
|
|
324
330
|
}
|
|
325
331
|
else {
|
|
326
332
|
if (this.gear === undefined) {
|
|
327
|
-
const initialGear =
|
|
333
|
+
const initialGear = (0, utils_1.intVal)(this.getSetting('startGear'));
|
|
328
334
|
this.gear = initialGear + request.gearDelta;
|
|
329
335
|
}
|
|
330
336
|
newRequest.gearRatio = this.gearRatios[this.gear];
|
|
337
|
+
this.logger.logEvent({ message: 'gear initialized', gear: this.gear, gearRatio: newRequest.gearRatio });
|
|
331
338
|
}
|
|
332
339
|
break;
|
|
333
340
|
case 'Disabled':
|