incyclist-devices 1.5.0 → 1.5.1

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/antv2/fe.d.ts CHANGED
@@ -8,6 +8,7 @@ export default class AntFEAdapter extends AntAdapter {
8
8
  protected logger: EventLogger;
9
9
  protected cyclingMode: CyclingMode;
10
10
  protected distanceInternal?: number;
11
+ protected msgCount: number;
11
12
  constructor(sensor: ISensor, protocol: AntProtocol);
12
13
  isBike(): boolean;
13
14
  isHrm(): boolean;
package/lib/antv2/fe.js CHANGED
@@ -28,6 +28,7 @@ class AntFEAdapter extends ant_device_1.default {
28
28
  this.deviceData = {
29
29
  DeviceID: sensor.getDeviceID()
30
30
  };
31
+ this.msgCount = 0;
31
32
  this.logger = new gd_eventlog_1.EventLogger('Ant+FE');
32
33
  }
33
34
  isBike() { return true; }
@@ -112,10 +113,10 @@ class AntFEAdapter extends ant_device_1.default {
112
113
  return;
113
114
  this.deviceData = deviceData;
114
115
  try {
116
+ const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
117
+ this.logger.logEvent({ message: 'onDeviceData', data: logData });
115
118
  if (this.onDataFn && !(this.ignoreHrm && this.ignoreBike && this.ignorePower) && !this.paused) {
116
119
  if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
117
- const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
118
- this.logger.logEvent({ message: 'onDeviceData', data: logData });
119
120
  let incyclistData = this.mapData(deviceData);
120
121
  incyclistData = this.getCyclingMode().updateData(incyclistData);
121
122
  const data = this.transformData(incyclistData);
@@ -125,6 +126,7 @@ class AntFEAdapter extends ant_device_1.default {
125
126
  }
126
127
  }
127
128
  catch (err) {
129
+ this.logger.logEvent({ message: 'error', fn: 'onDeviceData()', error: err.message || err, stack: err.stack });
128
130
  }
129
131
  }
130
132
  mapData(deviceData) {
@@ -171,7 +173,7 @@ class AntFEAdapter extends ant_device_1.default {
171
173
  if (this.ignoreBike) {
172
174
  data = { heartrate: data.heartrate };
173
175
  }
174
- if (this.ignoreHrm)
176
+ if (this.ignoreHrm || !this.isHrm())
175
177
  delete data.heartrate;
176
178
  return data;
177
179
  }
@@ -181,21 +183,38 @@ class AntFEAdapter extends ant_device_1.default {
181
183
  });
182
184
  return __awaiter(this, void 0, void 0, function* () {
183
185
  _super.start.call(this, props);
186
+ this.logger.logEvent({ message: 'start', props });
187
+ this.msgCount = 0;
184
188
  const opts = props || {};
185
189
  const { args = {}, user = {} } = opts;
186
190
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
187
- const { timeout } = props || {};
188
- let to;
191
+ const { timeout = 20000 } = props || {};
192
+ let start = Date.now();
193
+ let startTimeout = start + timeout;
194
+ const status = { userSent: false, slopeSent: false };
195
+ let iv;
196
+ const stopInterval = () => {
197
+ if (iv)
198
+ clearInterval(iv);
199
+ iv = undefined;
200
+ };
189
201
  if (timeout) {
190
- to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
191
- yield this.stop();
192
- reject(new Error(`could not start device, reason:timeout`));
193
- }), timeout);
202
+ iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
203
+ if (Date.now() > startTimeout) {
204
+ stopInterval();
205
+ yield this.stop();
206
+ reject(new Error(`could not start device, reason:timeout`));
207
+ }
208
+ if (this.started && this.msgCount > 1 && status.userSent) {
209
+ this.logger.logEvent({ message: 'start success' });
210
+ stopInterval();
211
+ }
212
+ }), 100);
194
213
  }
195
214
  this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
196
- if (to)
197
- clearTimeout(to);
198
215
  if (!this.started) {
216
+ stopInterval();
217
+ this.stop();
199
218
  return reject(new Error(`could not start device`));
200
219
  }
201
220
  try {
@@ -205,15 +224,19 @@ class AntFEAdapter extends ant_device_1.default {
205
224
  const defaultBikeWeight = bikeType === 'mountain' ? DEFAULT_BIKE_WEIGHT_MOUNTAIN : DEFAULT_BIKE_WEIGHT;
206
225
  const userWeight = args.userWeight || user.weight || DEFAULT_USER_WEIGHT;
207
226
  const bikeWeight = args.bikeWeight || defaultBikeWeight;
208
- const status = { userSent: false, slopeSent: false };
209
227
  let i = 0;
210
228
  while (i < 3 && !status.userSent && !status.slopeSent) {
211
229
  status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
212
230
  status.slopeSent = status.slopeSent || (yield fe.sendTrackResistance(0.0));
213
231
  i++;
214
232
  }
215
- if (status.userSent)
233
+ stopInterval();
234
+ if (status.userSent) {
235
+ this.logger.logEvent({ message: 'start success' });
216
236
  return resolve(true);
237
+ }
238
+ this.logger.logEvent({ message: 'start failure' });
239
+ this.stop();
217
240
  return reject(new Error(`could not start device, reason: could not send commands`));
218
241
  }
219
242
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",