incyclist-devices 2.3.31 → 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.
@@ -61,7 +61,8 @@ class AntFEAdapter extends adapter_1.default {
61
61
  this.promiseSendUpdate = fe.sendTrackResistance(update.slope);
62
62
  }
63
63
  if (update.targetPower !== undefined) {
64
- this.promiseSendUpdate = fe.sendTargetPower(update.targetPower);
64
+ const tp = update.targetPower > 0 ? update.targetPower : 0;
65
+ this.promiseSendUpdate = fe.sendTargetPower(tp);
65
66
  }
66
67
  yield this.promiseSendUpdate;
67
68
  delete this.promiseSendUpdate;
@@ -112,6 +113,7 @@ class AntFEAdapter extends adapter_1.default {
112
113
  power: adapterData.power,
113
114
  speed: adapterData.speed,
114
115
  cadence: adapterData.pedalRpm,
116
+ gearStr: adapterData.gearStr,
115
117
  timestamp: Date.now()
116
118
  });
117
119
  if (adapterData.distanceInternal !== undefined) {
@@ -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;
@@ -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: DeviceSettings): IBlePeripheral;
66
- waitForPeripheral(settings: DeviceSettings): Promise<IBlePeripheral>;
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(settings);
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())
@@ -1,4 +1,5 @@
1
- import { IBleInterface } from "../types";
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
+ }
@@ -246,7 +246,8 @@ class BleFmAdapter extends adapter_1.default {
246
246
  yield device.setSlope(update.slope);
247
247
  }
248
248
  if (update.targetPower !== undefined) {
249
- yield device.setTargetPower(update.targetPower);
249
+ const tp = update.targetPower > 0 ? update.targetPower : 0;
250
+ yield device.setTargetPower(tp);
250
251
  }
251
252
  }
252
253
  }
@@ -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, BleStartProperties, IBlePeripheral } from '../../types';
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;
@@ -29,9 +29,6 @@ class ZwiftPlayAdapter extends adapter_1.default {
29
29
  return;
30
30
  });
31
31
  }
32
- start(startProps) {
33
- return super.start(startProps);
34
- }
35
32
  startSensor() {
36
33
  const _super = Object.create(null, {
37
34
  startSensor: { get: () => super.startSensor }
@@ -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 encrpytedSupported(): boolean;
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
- const manufacturerData = this.getManufacturerData();
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
- else if (!this.encrpytedSupported()) {
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.deviceType === 'click') {
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
- encrpytedSupported() {
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
- const services = this.announcement.serviceUUIDs;
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() {
@@ -44,6 +44,7 @@ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase i
44
44
  protected checkSlopeWithSimulatedShifting(request: UpdateRequest, newRequest?: UpdateRequest): void;
45
45
  checkSlope(request: UpdateRequest, newRequest?: UpdateRequest): void;
46
46
  checkGearChange(request: UpdateRequest, newRequest?: UpdateRequest): void;
47
+ protected verifySimPower(): void;
47
48
  protected checkEmptyRequest(newRequest: UpdateRequest): void;
48
49
  protected getVirtualShiftMode(): VirtshiftMode;
49
50
  updateData(bikeData: IncyclistBikeData, log?: boolean): IncyclistBikeData;
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  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
+ const MIN_POWER = 25;
42
43
  class SmartTrainerCyclingMode extends power_base_1.default {
43
44
  constructor(adapter, props) {
44
45
  super(adapter, props);
@@ -111,7 +112,8 @@ class SmartTrainerCyclingMode extends power_base_1.default {
111
112
  checkSlopeWithSimulatedShifting(request, newRequest = {}) {
112
113
  var _a, _b, _c, _d;
113
114
  if (this.gear === undefined) {
114
- return this.checkSlopeNoShiftig(request, newRequest);
115
+ this.checkSlopeNoShiftig(request, newRequest);
116
+ return;
115
117
  }
116
118
  if (request.slope !== undefined) {
117
119
  const prev = (_a = this.data.slope) !== null && _a !== void 0 ? _a : 0;
@@ -126,22 +128,14 @@ class SmartTrainerCyclingMode extends power_base_1.default {
126
128
  }
127
129
  catch (_e) {
128
130
  }
129
- if (this.data.slope === prev) {
130
- newRequest.targetPower = this.simPower;
131
- return;
132
- }
133
- else {
131
+ if (this.data.slope !== prev) {
134
132
  const virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(this.data.pedalRpm, this.gearRatios[this.gear - 1]);
135
133
  const m = (_c = (_b = this.adapter) === null || _b === void 0 ? void 0 : _b.getWeight()) !== null && _c !== void 0 ? _c : 85;
136
134
  this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = this.simSlope) !== null && _d !== void 0 ? _d : 0);
137
- newRequest.targetPower = this.simPower;
135
+ this.verifySimPower();
138
136
  }
139
- if (this.simPower < 0)
140
- this.simPower = 0;
141
- }
142
- else {
143
- newRequest.targetPower = this.simPower;
144
137
  }
138
+ newRequest.targetPower = this.simPower;
145
139
  }
146
140
  checkSlope(request, newRequest = {}) {
147
141
  const virtshiftMode = this.getVirtualShiftMode();
@@ -190,6 +184,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
190
184
  const virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(this.data.pedalRpm, this.gearRatios[this.gear - 1]);
191
185
  const m = (_b = (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.getWeight()) !== null && _b !== void 0 ? _b : 85;
192
186
  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
+ this.verifySimPower();
193
188
  }
194
189
  break;
195
190
  case 'Adapter':
@@ -198,6 +193,14 @@ class SmartTrainerCyclingMode extends power_base_1.default {
198
193
  break;
199
194
  }
200
195
  }
196
+ verifySimPower() {
197
+ if (this.simPower < 0) {
198
+ this.simPower = 0;
199
+ }
200
+ if (this.data.pedalRpm > 0 && this.simPower < MIN_POWER) {
201
+ this.simPower = MIN_POWER;
202
+ }
203
+ }
201
204
  checkEmptyRequest(newRequest) {
202
205
  if (Object.keys(newRequest).length === 0) {
203
206
  if (this.prevRequest) {
@@ -242,6 +245,7 @@ class SmartTrainerCyclingMode extends power_base_1.default {
242
245
  virtualSpeed = (0, calculations_1.calculateVirtualSpeed)(data.pedalRpm, this.gearRatios[this.gear - 1]);
243
246
  const m = (_b = (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.getWeight()) !== null && _b !== void 0 ? _b : 85;
244
247
  this.simPower = calculations_1.default.calculatePower(m, virtualSpeed, (_d = (_c = this.simSlope) !== null && _c !== void 0 ? _c : data.slope) !== null && _d !== void 0 ? _d : 0);
248
+ this.verifySimPower();
245
249
  }
246
250
  }
247
251
  return data;
@@ -279,10 +283,10 @@ class SmartTrainerCyclingMode extends power_base_1.default {
279
283
  const mode = this.getVirtualShiftMode();
280
284
  if (mode === "Disabled")
281
285
  return undefined;
282
- if (this.gear === undefined || this.gear === null)
286
+ if (mode === 'Simulated' && (this.gear === undefined || this.gear === null))
283
287
  return '';
284
288
  if (mode === "SlopeDelta")
285
- return this.gear > 0 ? `+${this.gear}` : `${this.gear}`;
289
+ return this.gearDelta > 0 ? `+${this.gearDelta}` : `${this.gearDelta}`;
286
290
  return this.gear.toString();
287
291
  }
288
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.31",
3
+ "version": "2.3.33",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",