incyclist-services 1.0.28 → 1.0.30

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { IncyclistDeviceAdapter } from "incyclist-devices";
2
+ import { IncyclistCapability, IncyclistDeviceAdapter } from "incyclist-devices";
3
3
  import { AdapterInfo, DeviceConfigurationInfo, DeviceConfigurationSettings, DeviceModeInfo, ExtendedIncyclistCapability, IncyclistDeviceSettings, InterfaceSetting, LegacySettings } from "./model";
4
4
  import EventEmitter from "events";
5
5
  import { EventLogger } from "gd-eventlog";
@@ -56,6 +56,10 @@ export declare class DeviceConfigurationService extends EventEmitter {
56
56
  getSelected(capability: ExtendedIncyclistCapability): IncyclistDeviceAdapter | undefined;
57
57
  protected isDisabled(capability: ExtendedIncyclistCapability): boolean;
58
58
  protected getCapabilityInfo(capability: ExtendedIncyclistCapability): CapabilityListDetails;
59
+ getSelectedDevices(capability?: IncyclistCapability): Array<{
60
+ capability: IncyclistCapability;
61
+ selected?: string;
62
+ }>;
59
63
  getInterfaceSettings(ifName: string): InterfaceSetting;
60
64
  isInterfaceEnabled(ifName: string): boolean;
61
65
  enableInterface(ifName: string): void;
@@ -675,6 +675,17 @@ class DeviceConfigurationService extends events_1.default {
675
675
  });
676
676
  return { adapters, selectedIdx, disabled };
677
677
  }
678
+ getSelectedDevices(capability) {
679
+ var _a, _b;
680
+ let capabilites = (_a = this.settings) === null || _a === void 0 ? void 0 : _a.capabilities;
681
+ if (capability) {
682
+ capabilites = (_b = this.settings) === null || _b === void 0 ? void 0 : _b.capabilities.filter(c => c.capability === capability);
683
+ }
684
+ return capabilites.filter(c => c.capability !== 'bike' && !(c.disabled === true)).map(c => {
685
+ const { capability, selected } = c;
686
+ return { capability: capability, selected };
687
+ });
688
+ }
678
689
  getInterfaceSettings(ifName) {
679
690
  if (!this.settings)
680
691
  this.settings = { interfaces: [] };
@@ -30,6 +30,7 @@ export declare class DeviceRideService extends EventEmitter {
30
30
  name: string;
31
31
  isControl: boolean;
32
32
  capabilities: import("../configuration").ExtendedIncyclistCapability[];
33
+ isStarted: boolean;
33
34
  };
34
35
  protected getAdapterList(onlySelected?: boolean): AdapterRideInfo[];
35
36
  prepareEppRoute(props: RideServiceDeviceProperties): PreparedRoute;
@@ -39,6 +40,7 @@ export declare class DeviceRideService extends EventEmitter {
39
40
  setSerialPortInUse(adapter: IncyclistDeviceAdapter): void;
40
41
  protected startAdapters(adapters: AdapterRideInfo[], startType: 'start' | 'check', props?: RideServiceDeviceProperties): Promise<boolean>;
41
42
  start(props: RideServiceDeviceProperties): Promise<boolean>;
43
+ startRetry(props: RideServiceDeviceProperties): Promise<boolean>;
42
44
  cancelStart(): Promise<boolean>;
43
45
  startRide(_props: any): void;
44
46
  stop(udid?: string): Promise<boolean>;
@@ -74,7 +74,8 @@ class DeviceRideService extends events_1.default {
74
74
  const { udid, adapter, capabilities } = adapterInfo;
75
75
  const name = adapter.getUniqueName();
76
76
  const isControl = adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control);
77
- return { udid, name, isControl, capabilities };
77
+ const isStarted = adapter.isStarted();
78
+ return { udid, name, isControl, capabilities, isStarted };
78
79
  }
79
80
  getAdapterList(onlySelected = true) {
80
81
  var _a;
@@ -388,26 +389,30 @@ class DeviceRideService extends events_1.default {
388
389
  .then((success) => __awaiter(this, void 0, void 0, function* () {
389
390
  if (success) {
390
391
  this.emit(`${startType}-success`, this.getAdapterStateInfo(ai));
392
+ this.logEvent(Object.assign({ message: `${startType} ${sType} request finished` }, logProps));
393
+ if (startType === 'check')
394
+ yield ai.adapter.pause().catch(console.log);
395
+ if (ai.adapter.isControllable())
396
+ this.setSerialPortInUse(ai.adapter);
391
397
  }
392
- ai.isStarted = true;
393
- this.logEvent(Object.assign({ message: `${startType} ${sType} request finished` }, logProps));
394
- if (startType === 'check') {
395
- yield ai.adapter.pause().catch(console.log);
396
- ai.adapter.off('data', this.deviceDataHandler);
398
+ else {
399
+ this.emit(`${startType}-error`, this.getAdapterStateInfo(ai));
400
+ this.logEvent(Object.assign({ message: `${startType} ${sType} request failed` }, logProps));
401
+ if (startType === 'check')
402
+ yield ai.adapter.stop().catch(console.log);
397
403
  }
398
- if (ai.adapter.isControllable())
399
- this.setSerialPortInUse(ai.adapter);
404
+ ai.isStarted = success;
400
405
  return success;
401
406
  }))
402
- .catch(err => {
407
+ .catch((err) => __awaiter(this, void 0, void 0, function* () {
403
408
  ai.isStarted = false;
404
409
  this.logEvent(Object.assign(Object.assign({ message: `${startType} ${sType} request failed` }, logProps), { reason: err.message }));
405
410
  this.emit(`${startType}-error`, this.getAdapterStateInfo(ai), err);
406
411
  if (startType === 'check') {
407
- ai.adapter.off('data', this.deviceDataHandler);
412
+ yield ai.adapter.stop().catch(console.log);
408
413
  }
409
414
  return false;
410
- });
415
+ }));
411
416
  }));
412
417
  if (!this.startPromises)
413
418
  return true;
@@ -432,6 +437,18 @@ class DeviceRideService extends events_1.default {
432
437
  return this.startAdapters(adapters, 'start', props);
433
438
  });
434
439
  }
440
+ startRetry(props) {
441
+ return __awaiter(this, void 0, void 0, function* () {
442
+ yield this.lazyInit();
443
+ const allAdapters = this.getAdapterList();
444
+ this.emit('start-request', allAdapters === null || allAdapters === void 0 ? void 0 : allAdapters.map(this.getAdapterStateInfo));
445
+ const adapters = this.getAdapterList().filter(ai => !ai.adapter.isStarted());
446
+ const goodToGo = yield this.waitForPreviousStartToFinish();
447
+ if (!goodToGo)
448
+ return;
449
+ return this.startAdapters(adapters, 'start', props);
450
+ });
451
+ }
435
452
  cancelStart() {
436
453
  return __awaiter(this, void 0, void 0, function* () {
437
454
  const adapters = this.getAdapterList();
@@ -485,18 +502,23 @@ class DeviceRideService extends events_1.default {
485
502
  }
486
503
  onData(deviceSettings, data) {
487
504
  const adapters = this.getAdapterList();
488
- const hasControl = (adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.capabilities.includes(incyclist_devices_1.IncyclistCapability.Control))) !== undefined;
489
- const hasPower = (adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.capabilities.includes(incyclist_devices_1.IncyclistCapability.Power))) !== undefined;
490
505
  const adapterInfo = adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.adapter.isEqual(deviceSettings));
491
506
  if (!adapterInfo)
492
507
  return;
493
- adapterInfo.capabilities.forEach(capability => {
508
+ adapters === null || adapters === void 0 ? void 0 : adapters.forEach(ai => ai.capabilities = ai.adapter.getCapabilities());
509
+ const selectedDevices = this.configurationService.getSelectedDevices();
510
+ const enabledCapabilities = selectedDevices.filter(sd => sd.selected === adapterInfo.udid).map(c => c.capability);
511
+ const hasControl = (adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.capabilities.includes(incyclist_devices_1.IncyclistCapability.Control))) !== undefined;
512
+ const hasPower = (adapters === null || adapters === void 0 ? void 0 : adapters.find(ai => ai.capabilities.includes(incyclist_devices_1.IncyclistCapability.Power))) !== undefined;
513
+ enabledCapabilities.forEach(capability => {
494
514
  switch (capability) {
495
515
  case incyclist_devices_1.IncyclistCapability.HeartRate:
496
516
  this.data.heartrate = data.heartrate;
497
517
  break;
498
518
  case incyclist_devices_1.IncyclistCapability.Power:
499
519
  this.data.power = data.power;
520
+ break;
521
+ case incyclist_devices_1.IncyclistCapability.Speed:
500
522
  this.data.speed = data.speed;
501
523
  break;
502
524
  case incyclist_devices_1.IncyclistCapability.Cadence:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.24"
6
6
  },
@@ -37,7 +37,7 @@
37
37
  "lib": "./src"
38
38
  },
39
39
  "dependencies": {
40
- "incyclist-devices": "^2.1.2",
40
+ "incyclist-devices": "^2.1.5",
41
41
  "uuid": "^9.0.0"
42
42
  }
43
43
  }