incyclist-devices 3.0.51 → 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
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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>;
|