incyclist-devices 1.5.16 → 1.5.18

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,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Device } from '../protocol';
2
3
  import { IChannel, ISensor } from 'incyclist-ant-plus';
3
4
  import AntProtocol from './incyclist-protocol';
@@ -28,6 +29,8 @@ export default class AntAdapter extends IncyclistDevice implements Device {
28
29
  selected: boolean;
29
30
  settings: any;
30
31
  onDataFn: OnDeviceDataCallback;
32
+ protected ivDataTimeout: NodeJS.Timer;
33
+ protected lastDataTS: number;
31
34
  constructor(sensor: ISensor, protocol: AntProtocol, settings?: any);
32
35
  isBike(): boolean;
33
36
  isPower(): boolean;
@@ -45,6 +48,8 @@ export default class AntAdapter extends IncyclistDevice implements Device {
45
48
  setIgnorePower(ignore: any): void;
46
49
  pause(): Promise<boolean>;
47
50
  resume(): Promise<boolean>;
51
+ startDataTimeoutCheck(): void;
52
+ stopDataTimeoutCheck(): void;
48
53
  start(props?: any): Promise<any>;
49
54
  stop(): Promise<boolean>;
50
55
  isStopped(): boolean;
@@ -17,6 +17,7 @@ const incyclist_protocol_1 = require("./incyclist-protocol");
17
17
  const ant_interface_1 = __importDefault(require("./ant-interface"));
18
18
  const device_1 = __importDefault(require("../device"));
19
19
  exports.DEFAULT_UPDATE_FREQUENCY = 1000;
20
+ const NO_DATA_TIMEOUT = 5000;
20
21
  class AntAdapter extends device_1.default {
21
22
  constructor(sensor, protocol, settings) {
22
23
  super(protocol, settings);
@@ -92,6 +93,24 @@ class AntAdapter extends device_1.default {
92
93
  resolve(true);
93
94
  });
94
95
  }
96
+ startDataTimeoutCheck() {
97
+ if (this.ivDataTimeout)
98
+ return;
99
+ this.ivDataTimeout = setInterval(() => {
100
+ console.log('~~~ check', this.lastDataTS);
101
+ if (!this.lastDataTS)
102
+ return;
103
+ if (this.lastDataTS + NO_DATA_TIMEOUT < Date.now()) {
104
+ this.emit('disconnected', Date.now() - this.lastDataTS);
105
+ }
106
+ }, 1000);
107
+ }
108
+ stopDataTimeoutCheck() {
109
+ if (!this.ivDataTimeout)
110
+ return;
111
+ clearInterval(this.ivDataTimeout);
112
+ this.ivDataTimeout = undefined;
113
+ }
95
114
  start(props) {
96
115
  return __awaiter(this, void 0, void 0, function* () {
97
116
  if (props && props.user)
@@ -104,6 +123,7 @@ class AntAdapter extends device_1.default {
104
123
  }
105
124
  stop() {
106
125
  return __awaiter(this, void 0, void 0, function* () {
126
+ this.stopDataTimeoutCheck();
107
127
  this.stopped = true;
108
128
  return true;
109
129
  });
package/lib/antv2/fe.js CHANGED
@@ -112,6 +112,9 @@ class AntFEAdapter extends ant_device_1.default {
112
112
  if (!this.started || this.isStopped())
113
113
  return;
114
114
  this.deviceData = deviceData;
115
+ this.lastDataTS = Date.now();
116
+ if (!this.ivDataTimeout)
117
+ this.startDataTimeoutCheck();
115
118
  try {
116
119
  const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
117
120
  this.logger.logEvent({ message: 'onDeviceData', data: logData });
package/lib/antv2/hr.js CHANGED
@@ -40,6 +40,9 @@ class AntHrAdapter extends ant_device_1.default {
40
40
  if (!this.started)
41
41
  return;
42
42
  this.deviceData = deviceData;
43
+ this.lastDataTS = Date.now();
44
+ if (!this.ivDataTimeout)
45
+ this.startDataTimeoutCheck();
43
46
  try {
44
47
  if (this.onDataFn && !this.ignoreHrm && !this.paused) {
45
48
  if (this.lastUpdate === undefined || (Date.now() - this.lastUpdate) > this.updateFrequency) {
package/lib/antv2/pwr.js CHANGED
@@ -58,7 +58,9 @@ class AntPwrAdapter extends ant_device_1.default {
58
58
  if (!this.started)
59
59
  return;
60
60
  this.deviceData = deviceData;
61
- this.deviceData = deviceData;
61
+ this.lastDataTS = Date.now();
62
+ if (!this.ivDataTimeout)
63
+ this.startDataTimeoutCheck();
62
64
  try {
63
65
  if (this.onDataFn && !(this.ignoreBike && this.ignorePower) && !this.paused) {
64
66
  if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
package/lib/ble/fm.js CHANGED
@@ -554,7 +554,7 @@ class FmAdapter extends device_1.default {
554
554
  if (this.device)
555
555
  this.device.setLogger(this.logger);
556
556
  }
557
- isBike() { return this.device.isBike(); }
557
+ isBike() { return this.device.isBike() || this.device.isPower(); }
558
558
  isHrm() { return this.device.isHrm(); }
559
559
  isPower() { return this.device.isPower(); }
560
560
  isSame(device) {
@@ -708,6 +708,7 @@ class FmAdapter extends device_1.default {
708
708
  bleDevice.on('data', (data) => {
709
709
  this.onDeviceData(data);
710
710
  });
711
+ bleDevice.on('disconnected', this.emit);
711
712
  return true;
712
713
  }
713
714
  }
@@ -204,6 +204,8 @@ class DaumAdapterBase extends device_1.default {
204
204
  this.logger.logEvent(event);
205
205
  }
206
206
  stop() {
207
+ if (this.stopped)
208
+ return Promise.resolve(true);
207
209
  this.logEvent({ message: 'stop request' });
208
210
  this.stopped = true;
209
211
  return new Promise((resolve, reject) => {
@@ -241,7 +243,7 @@ class DaumAdapterBase extends device_1.default {
241
243
  }
242
244
  sendUpdate(request) {
243
245
  return __awaiter(this, void 0, void 0, function* () {
244
- if (this.paused)
246
+ if (this.paused || this.stopped)
245
247
  return;
246
248
  this.logEvent({ message: 'sendUpdate', request, waiting: this.requests.length });
247
249
  return yield this.processClientRequest(request);
@@ -253,6 +255,8 @@ class DaumAdapterBase extends device_1.default {
253
255
  }
254
256
  update() {
255
257
  return __awaiter(this, void 0, void 0, function* () {
258
+ if (this.stopped)
259
+ return;
256
260
  this.updateBusy = true;
257
261
  this.getCurrentBikeData()
258
262
  .then(bikeData => {
@@ -271,6 +275,8 @@ class DaumAdapterBase extends device_1.default {
271
275
  }
272
276
  sendRequests() {
273
277
  return __awaiter(this, void 0, void 0, function* () {
278
+ if (this.stopped)
279
+ return;
274
280
  if (this.requests.length > 0) {
275
281
  const processing = [...this.requests];
276
282
  const cnt = processing.length;
@@ -294,7 +300,7 @@ class DaumAdapterBase extends device_1.default {
294
300
  }
295
301
  bikeSync() {
296
302
  return __awaiter(this, void 0, void 0, function* () {
297
- if (this.paused) {
303
+ if (this.paused || this.stopped) {
298
304
  return;
299
305
  }
300
306
  if (this.updateBusy || this.requestBusy) {
@@ -22,6 +22,6 @@ export default class DaumClassicAdapter extends DaumAdapter {
22
22
  user?: any;
23
23
  bikeSettings?: any;
24
24
  gear?: any;
25
- }): Promise<unknown>;
25
+ }, isRelaunch?: boolean): Promise<unknown>;
26
26
  getCurrentBikeData(): any;
27
27
  }
@@ -121,7 +121,8 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
121
121
  if (!isRelaunch) {
122
122
  try {
123
123
  const version = yield this.bike.getVersion();
124
- this.logEvent({ message: 'device info', deviceInfo: version });
124
+ const { serialNo, cockpit } = version || {};
125
+ this.logEvent({ message: 'device info', deviceInfo: { serialNo, cockpit } });
125
126
  }
126
127
  catch (_a) { }
127
128
  }
@@ -136,7 +137,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
136
137
  }
137
138
  });
138
139
  }
139
- performStart(props = {}) {
140
+ performStart(props = {}, isRelaunch = false) {
140
141
  this.stop();
141
142
  const { user, bikeSettings } = props;
142
143
  if (user && user.weight)
@@ -147,7 +148,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
147
148
  let startState = {};
148
149
  return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
149
150
  try {
150
- if (!this.bike.isConnected())
151
+ if (!isRelaunch && !this.bike.isConnected())
151
152
  yield this.bike.saveConnect();
152
153
  yield this.getBike().resetDevice();
153
154
  if (!startState.setProg) {
@@ -76,10 +76,12 @@ class Daum8008 {
76
76
  return 10;
77
77
  }
78
78
  connect() {
79
- this.logEvent({ message: "connect()", port: this.getPort(), sp: (this.sp !== undefined), });
79
+ this.logEvent({ message: "connect()", port: this.getPort(), isConnected: this.connected, sp: (this.sp !== undefined), });
80
80
  if (this.closing || this.opening) {
81
81
  return;
82
82
  }
83
+ if (this.connected)
84
+ return;
83
85
  try {
84
86
  if (this.sp === undefined) {
85
87
  const settings = this.settings.port || {};
package/lib/device.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ /// <reference types="node" />
1
2
  import { DeviceProtocol, Device } from './protocol';
2
3
  import CyclingMode from './cycling-mode';
4
+ import EventEmitter from 'events';
3
5
  export declare const DEFAULT_BIKE_WEIGHT = 10;
4
6
  export declare const DEFAULT_USER_WEIGHT = 75;
5
7
  export declare type DeviceData = {
@@ -50,7 +52,7 @@ export interface DeviceAdapter extends Device {
50
52
  sendUpdate(request: any): void;
51
53
  onData(callback: OnDeviceDataCallback): void;
52
54
  }
53
- export default class IncyclistDevice implements DeviceAdapter {
55
+ export default class IncyclistDevice extends EventEmitter implements DeviceAdapter {
54
56
  protocol: DeviceProtocol;
55
57
  detected: boolean;
56
58
  selected: boolean;
package/lib/device.js CHANGED
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
7
+ const events_1 = __importDefault(require("events"));
4
8
  exports.DEFAULT_BIKE_WEIGHT = 10;
5
9
  exports.DEFAULT_USER_WEIGHT = 75;
6
- class IncyclistDevice {
10
+ class IncyclistDevice extends events_1.default {
7
11
  constructor(proto, settings) {
12
+ super();
8
13
  this.protocol = proto;
9
14
  this.detected = false;
10
15
  this.selected = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.5.16",
3
+ "version": "1.5.18",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",