incyclist-devices 1.5.16 → 1.5.17

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
  }
@@ -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
  }
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.17",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",