incyclist-devices 3.0.50 → 3.0.52

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.
@@ -152,6 +152,7 @@ class AntInterface extends node_events_1.EventEmitter {
152
152
  this.connectPromise = null;
153
153
  this.scanPromise = null;
154
154
  this.connected = false;
155
+ this.channelsInUse = [];
155
156
  return closed;
156
157
  }
157
158
  async terminate() {
@@ -350,23 +351,32 @@ class AntInterface extends node_events_1.EventEmitter {
350
351
  try {
351
352
  const started = await channel.startSensor(sensor);
352
353
  if (!started) {
353
- this.logEvent({ message: 'could not start sensor' });
354
+ this.logEvent({ message: 'could not start sensor', channelNo: channel.getChannelNo(), profile: sensor.getProfile(), deviceID: sensor.getDeviceID() });
354
355
  channel.off('data', onData);
356
+ await this.releaseChannel(sensor, channel);
357
+ return false;
355
358
  }
356
359
  this.logEvent({ message: 'sensor started', channelNo: sensor.getChannel()?.getChannelNo(), profile: sensor.getProfile(), deviceID: sensor.getDeviceID() });
357
- return started;
360
+ return true;
358
361
  }
359
362
  catch (err) {
360
363
  this.logEvent({ message: 'could not start sensor', error: err.message, stack: err.stack });
361
364
  channel.off('data', onData);
362
- try {
363
- await channel.stopSensor(sensor);
364
- }
365
- catch { }
366
- this.unblockChannel(channel);
365
+ await this.releaseChannel(sensor, channel);
367
366
  return false;
368
367
  }
369
368
  }
369
+ async releaseChannel(sensor, channel) {
370
+ try {
371
+ channel.flush?.();
372
+ await (0, utils_js_1.waitWithTimeout)(channel.stopSensor(sensor), 2000, () => {
373
+ this.logEvent({ message: 'stopping sensor timed out', channelNo: channel.getChannelNo(), deviceID: sensor.getDeviceID() });
374
+ });
375
+ }
376
+ catch {
377
+ }
378
+ this.unblockChannel(channel);
379
+ }
370
380
  blockChannel(channel, usage) {
371
381
  this.channelsInUse.push({ channel: channel, usage });
372
382
  }
@@ -283,6 +283,7 @@ class KettlerRacerAdapter extends adapter_js_1.SerialIncyclistDevice {
283
283
  return info.data;
284
284
  }
285
285
  catch (err) {
286
+ this.started = false;
286
287
  try {
287
288
  await this.reset();
288
289
  }
@@ -293,6 +294,7 @@ class KettlerRacerAdapter extends adapter_js_1.SerialIncyclistDevice {
293
294
  }
294
295
  }, 5, 1000)
295
296
  .then((data) => {
297
+ this.started = true;
296
298
  this.startUpdatePull();
297
299
  return true;
298
300
  });
@@ -318,6 +320,7 @@ class KettlerRacerAdapter extends adapter_js_1.SerialIncyclistDevice {
318
320
  }
319
321
  stop() {
320
322
  this.logEvent({ message: 'stop request' });
323
+ this.started = false;
321
324
  return new Promise(async (resolve, reject) => {
322
325
  try {
323
326
  if (this.iv) {
@@ -147,6 +147,7 @@ export default class AntInterface extends EventEmitter {
147
147
  this.connectPromise = null;
148
148
  this.scanPromise = null;
149
149
  this.connected = false;
150
+ this.channelsInUse = [];
150
151
  return closed;
151
152
  }
152
153
  async terminate() {
@@ -345,23 +346,32 @@ export default class AntInterface extends EventEmitter {
345
346
  try {
346
347
  const started = await channel.startSensor(sensor);
347
348
  if (!started) {
348
- this.logEvent({ message: 'could not start sensor' });
349
+ this.logEvent({ message: 'could not start sensor', channelNo: channel.getChannelNo(), profile: sensor.getProfile(), deviceID: sensor.getDeviceID() });
349
350
  channel.off('data', onData);
351
+ await this.releaseChannel(sensor, channel);
352
+ return false;
350
353
  }
351
354
  this.logEvent({ message: 'sensor started', channelNo: sensor.getChannel()?.getChannelNo(), profile: sensor.getProfile(), deviceID: sensor.getDeviceID() });
352
- return started;
355
+ return true;
353
356
  }
354
357
  catch (err) {
355
358
  this.logEvent({ message: 'could not start sensor', error: err.message, stack: err.stack });
356
359
  channel.off('data', onData);
357
- try {
358
- await channel.stopSensor(sensor);
359
- }
360
- catch { }
361
- this.unblockChannel(channel);
360
+ await this.releaseChannel(sensor, channel);
362
361
  return false;
363
362
  }
364
363
  }
364
+ async releaseChannel(sensor, channel) {
365
+ try {
366
+ channel.flush?.();
367
+ await waitWithTimeout(channel.stopSensor(sensor), 2000, () => {
368
+ this.logEvent({ message: 'stopping sensor timed out', channelNo: channel.getChannelNo(), deviceID: sensor.getDeviceID() });
369
+ });
370
+ }
371
+ catch {
372
+ }
373
+ this.unblockChannel(channel);
374
+ }
365
375
  blockChannel(channel, usage) {
366
376
  this.channelsInUse.push({ channel: channel, usage });
367
377
  }
@@ -278,6 +278,7 @@ export default class KettlerRacerAdapter extends SerialIncyclistDevice {
278
278
  return info.data;
279
279
  }
280
280
  catch (err) {
281
+ this.started = false;
281
282
  try {
282
283
  await this.reset();
283
284
  }
@@ -288,6 +289,7 @@ export default class KettlerRacerAdapter extends SerialIncyclistDevice {
288
289
  }
289
290
  }, 5, 1000)
290
291
  .then((data) => {
292
+ this.started = true;
291
293
  this.startUpdatePull();
292
294
  return true;
293
295
  });
@@ -313,6 +315,7 @@ export default class KettlerRacerAdapter extends SerialIncyclistDevice {
313
315
  }
314
316
  stop() {
315
317
  this.logEvent({ message: 'stop request' });
318
+ this.started = false;
316
319
  return new Promise(async (resolve, reject) => {
317
320
  try {
318
321
  if (this.iv) {
@@ -53,6 +53,7 @@ export default class AntInterface extends EventEmitter implements IncyclistInter
53
53
  protected stopDevices(detected: AntDeviceSettings[]): Promise<void>;
54
54
  stopScan(): Promise<boolean>;
55
55
  startSensor(sensor: ISensor, onDeviceData: (data: any) => void): Promise<boolean>;
56
+ private releaseChannel;
56
57
  private blockChannel;
57
58
  private unblockChannel;
58
59
  stopSensor(sensor: ISensor): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.50",
3
+ "version": "3.0.52",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",