incyclist-devices 2.3.33 → 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.
@@ -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
  }
@@ -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
  }
@@ -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
- if (update.slope !== undefined) {
246
- yield device.setSlope(update.slope);
247
- }
248
- if (update.targetPower !== undefined) {
249
- const tp = update.targetPower > 0 ? update.targetPower : 0;
250
- yield device.setTargetPower(tp);
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
  }
@@ -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
- const res = yield this.write(consts_1.FTMS_CP, data, props);
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
- this.logEvent({ message: 'fmts:write result', res, result });
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
  }
@@ -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;
@@ -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
  }
@@ -61,5 +61,8 @@ class CyclingMode {
61
61
  isSIM() {
62
62
  return this.getConfig().isSIM;
63
63
  }
64
+ getData() {
65
+ return {};
66
+ }
64
67
  }
65
68
  exports.CyclingMode = CyclingMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.33",
3
+ "version": "2.3.34",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",