incyclist-devices 2.2.7 → 2.2.8

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.
@@ -4,6 +4,7 @@ import IncyclistDevice from '../../base/adpater';
4
4
  import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData, AdapterStartStatus } from '../types';
5
5
  import { IAdapter, IncyclistAdapterData, IncyclistBikeData, IncyclistCapability } from '../../types';
6
6
  import EventEmitter from 'events';
7
+ import ICyclingMode from '../../modes/types';
7
8
  export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
8
9
  sensor: ISensor;
9
10
  data: IncyclistAdapterData;
@@ -42,6 +43,7 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData> extends Incy
42
43
  mapData(deviceData: TDeviceData): IncyclistBikeData;
43
44
  transformData(data: IncyclistBikeData, deviceData: TDeviceData): void;
44
45
  mapToAdapterData(deviceData: any): void;
46
+ refreshDeviceData(): void;
45
47
  onDeviceData(deviceData: TDeviceData): void;
46
48
  isWaitingForData(): boolean;
47
49
  _wait(): Promise<boolean>;
@@ -68,4 +70,5 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData> extends Incy
68
70
  stop(): Promise<boolean>;
69
71
  startSensor(): Promise<boolean>;
70
72
  stopSensor(): Promise<void>;
73
+ setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
71
74
  }
@@ -119,6 +119,21 @@ class AntAdapter extends adpater_1.default {
119
119
  mapToAdapterData(deviceData) {
120
120
  throw new Error('message not implemented');
121
121
  }
122
+ refreshDeviceData() {
123
+ if (this.isStopped() || this.isPaused())
124
+ return;
125
+ const logData = this.getLogData(this.deviceData, ['PairedDevices', 'RawData', '_RawData']);
126
+ this.logEvent({ message: 'refreshDeviceData', data: logData, paused: this.paused, started: this.started, canEmit: this.canEmitData() });
127
+ if (this.isControllable()) {
128
+ let incyclistData = this.mapData(this.deviceData);
129
+ incyclistData = this.getCyclingMode().updateData(incyclistData);
130
+ this.transformData(incyclistData, this.deviceData);
131
+ }
132
+ else {
133
+ this.mapToAdapterData(this.deviceData);
134
+ }
135
+ this.emitData(this.data);
136
+ }
122
137
  onDeviceData(deviceData) {
123
138
  this.dataMsgCount++;
124
139
  this.lastDataTS = Date.now();
@@ -461,5 +476,9 @@ class AntAdapter extends adpater_1.default {
461
476
  catch (_a) { }
462
477
  });
463
478
  }
479
+ setCyclingMode(mode, settings, sendInitCommands) {
480
+ super.setCyclingMode(mode, settings, sendInitCommands);
481
+ this.refreshDeviceData();
482
+ }
464
483
  }
465
484
  exports.default = AntAdapter;
@@ -43,7 +43,14 @@ class AntFEAdapter extends adapter_1.default {
43
43
  if (this.promiseStop)
44
44
  return;
45
45
  if (this.promiseSendUpdate) {
46
- this.logEvent({ message: 'send bike update skipped', device: this.getName(), request, reason: 'busy' });
46
+ let stack;
47
+ try {
48
+ throw new Error();
49
+ }
50
+ catch (err) {
51
+ stack = err.stack;
52
+ }
53
+ this.logEvent({ message: 'send bike update skipped', device: this.getName(), request, reason: 'busy', stack });
47
54
  return;
48
55
  }
49
56
  let isReset = request.reset && Object.keys(request).length === 1;
@@ -5,6 +5,7 @@ import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from "../t
5
5
  import { IAdapter, IncyclistBikeData, IncyclistAdapterData, DeviceProperties } from "../../types";
6
6
  import { BleDeviceData } from "./types";
7
7
  import { LegacyProfile } from "../../antv2/types";
8
+ import ICyclingMode from "../../modes/types";
8
9
  export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice extends BleComms> extends IncyclistDevice<BleDeviceProperties> {
9
10
  protected ble: BleInterface;
10
11
  protected deviceData: TDeviceData;
@@ -27,6 +28,7 @@ export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice exten
27
28
  getProtocolName(): string;
28
29
  getID(): string;
29
30
  getName(): string;
31
+ refreshDeviceData(): void;
30
32
  onDeviceData(deviceData: TDeviceData): void;
31
33
  mapData(deviceData: TDeviceData): IncyclistAdapterData | IncyclistBikeData;
32
34
  transformData(data: IncyclistBikeData): IncyclistAdapterData;
@@ -39,4 +41,5 @@ export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice exten
39
41
  pause(): Promise<boolean>;
40
42
  resume(): Promise<boolean>;
41
43
  update(): void;
44
+ setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
42
45
  }
@@ -108,6 +108,25 @@ class BleAdapter extends adpater_1.default {
108
108
  const settings = this.settings;
109
109
  return settings.name || settings.id || settings.address;
110
110
  }
111
+ refreshDeviceData() {
112
+ if (this.isStopped() || this.isPaused())
113
+ return;
114
+ try {
115
+ this.logEvent({ message: 'refreshDeviceData', data: this.deviceData, isControllable: this.isControllable() });
116
+ if (this.isControllable()) {
117
+ const mappedData = this.mapData(this.deviceData);
118
+ const incyclistData = this.getCyclingMode().updateData(mappedData);
119
+ this.data = this.transformData(incyclistData);
120
+ }
121
+ else {
122
+ this.data = this.mapData(this.deviceData);
123
+ }
124
+ this.emitData(this.data);
125
+ }
126
+ catch (err) {
127
+ this.logEvent({ message: 'error', fn: 'refreshDeviceData', error: err.message, stack: err.stack });
128
+ }
129
+ }
111
130
  onDeviceData(deviceData) {
112
131
  try {
113
132
  this.dataMsgCount++;
@@ -231,5 +250,9 @@ class BleAdapter extends adpater_1.default {
231
250
  }
232
251
  update() {
233
252
  }
253
+ setCyclingMode(mode, settings, sendInitCommands) {
254
+ super.setCyclingMode(mode, settings, sendInitCommands);
255
+ this.refreshDeviceData();
256
+ }
234
257
  }
235
258
  exports.default = BleAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",