incyclist-devices 2.0.15 → 2.0.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.
package/lib/adapters.js CHANGED
@@ -45,5 +45,5 @@ class AdapterFactory {
45
45
  return adapter;
46
46
  }
47
47
  }
48
- exports.default = AdapterFactory;
49
48
  AdapterFactory.adapters = [];
49
+ exports.default = AdapterFactory;
@@ -28,10 +28,10 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData, TData> exten
28
28
  };
29
29
  onDataFn: (data: TData) => void;
30
30
  startupRetryPause: number;
31
- protected ivDataTimeout: NodeJS.Timer;
31
+ protected ivDataTimeout: NodeJS.Timeout;
32
32
  protected lastDataTS: number;
33
33
  protected dataMsgCount: number;
34
- protected ivWaitForData: NodeJS.Timer;
34
+ protected ivWaitForData: NodeJS.Timeout;
35
35
  constructor(settings: AntDeviceSettings, props?: DeviceProperties);
36
36
  createSensor(settings: AntDeviceSettings): ISensor;
37
37
  isEqual(settings: AntDeviceSettings): boolean;
@@ -280,6 +280,6 @@ class AntInterface extends events_1.default {
280
280
  return (this.activeScan === undefined || this.activeScan === null);
281
281
  }
282
282
  }
283
- exports.default = AntInterface;
284
283
  AntInterface._instance = undefined;
285
284
  AntInterface.INTERFACE_NAME = 'ant';
285
+ exports.default = AntInterface;
@@ -352,6 +352,6 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
352
352
  });
353
353
  }
354
354
  }
355
- exports.default = AntFEAdapter;
356
355
  AntFEAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
357
356
  AntFEAdapter.ANT_PROFILE_NAME = 'FE';
357
+ exports.default = AntFEAdapter;
@@ -71,6 +71,6 @@ class AntHrAdapter extends adapter_1.default {
71
71
  return this.deviceData.ComputedHeartRate !== undefined && this.deviceData.ComputedHeartRate !== null;
72
72
  }
73
73
  }
74
- exports.default = AntHrAdapter;
75
74
  AntHrAdapter.INCYCLIST_PROFILE_NAME = 'Heartrate Monitor';
76
75
  AntHrAdapter.ANT_PROFILE_NAME = 'HR';
76
+ exports.default = AntHrAdapter;
@@ -10,5 +10,5 @@ class AntFeERGCyclingMode extends ble_erg_mode_1.default {
10
10
  this.initLogger('AntERGMode');
11
11
  }
12
12
  }
13
- exports.default = AntFeERGCyclingMode;
14
13
  AntFeERGCyclingMode.isERG = true;
14
+ exports.default = AntFeERGCyclingMode;
@@ -136,6 +136,6 @@ class AntPwrAdapter extends adapter_1.ControllableAntAdapter {
136
136
  TimeStamp !== undefined || TimeStamp !== null;
137
137
  }
138
138
  }
139
- exports.default = AntPwrAdapter;
140
139
  AntPwrAdapter.INCYCLIST_PROFILE_NAME = 'Power Meter';
141
140
  AntPwrAdapter.ANT_PROFILE_NAME = 'PWR';
141
+ exports.default = AntPwrAdapter;
@@ -42,7 +42,7 @@ export declare class StaticWriteCharacteristic extends MockCharacteristic {
42
42
  }
43
43
  export declare abstract class StaticNotifyCharacteristic extends MockCharacteristic {
44
44
  cntSubscriptions: number;
45
- iv: NodeJS.Timer;
45
+ iv: NodeJS.Timeout;
46
46
  notifyFrequency: number;
47
47
  constructor(uuid: string, description: string);
48
48
  subscribe(callback: (err: Error | undefined) => void): void;
@@ -118,8 +118,8 @@ class BleCyclingPowerDevice extends comms_1.BleComms {
118
118
  this.prevCrankData = undefined;
119
119
  }
120
120
  }
121
- exports.default = BleCyclingPowerDevice;
122
121
  BleCyclingPowerDevice.protocol = 'cp';
123
122
  BleCyclingPowerDevice.services = [consts_1.CSP];
124
123
  BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
125
124
  BleCyclingPowerDevice.detectionPriority = 1;
125
+ exports.default = BleCyclingPowerDevice;
@@ -119,8 +119,8 @@ class BleEliteDevice extends comms_1.BleComms {
119
119
  this.prevCrankData = undefined;
120
120
  }
121
121
  }
122
- exports.default = BleEliteDevice;
123
122
  BleEliteDevice.protocol = 'elite';
124
123
  BleEliteDevice.services = [consts_1.ELITE_TRAINER_SVC];
125
124
  BleEliteDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
126
125
  BleEliteDevice.detectionPriority = 10;
126
+ exports.default = BleEliteDevice;
@@ -496,8 +496,8 @@ class BleFitnessMachineDevice extends comms_1.BleComms {
496
496
  this.data = {};
497
497
  }
498
498
  }
499
- exports.default = BleFitnessMachineDevice;
500
499
  BleFitnessMachineDevice.protocol = 'fm';
501
500
  BleFitnessMachineDevice.services = [consts_1.FTMS];
502
501
  BleFitnessMachineDevice.characteristics = ['2acc', consts_1.INDOOR_BIKE_DATA, '2ad6', '2ad8', consts_1.FTMS_CP, consts_1.FTMS_STATUS];
503
502
  BleFitnessMachineDevice.detectionPriority = 100;
503
+ exports.default = BleFitnessMachineDevice;
@@ -49,8 +49,8 @@ class BleHrmDevice extends comms_1.BleComms {
49
49
  return true;
50
50
  }
51
51
  }
52
- exports.default = BleHrmDevice;
53
52
  BleHrmDevice.protocol = 'hr';
54
53
  BleHrmDevice.services = ['180d'];
55
54
  BleHrmDevice.characteristics = ['2a37', '2a38', '2a39', '2a3c'];
56
55
  BleHrmDevice.detectionPriority = 1;
56
+ exports.default = BleHrmDevice;
@@ -625,9 +625,9 @@ class TacxAdvancedFitnessMachineDevice extends comms_1.default {
625
625
  this.data = {};
626
626
  }
627
627
  }
628
- exports.default = TacxAdvancedFitnessMachineDevice;
629
628
  TacxAdvancedFitnessMachineDevice.protocol = 'tacx';
630
629
  TacxAdvancedFitnessMachineDevice.services = [consts_1.TACX_FE_C_BLE];
631
630
  TacxAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', consts_1.TACX_FE_C_RX, consts_1.TACX_FE_C_TX];
632
631
  TacxAdvancedFitnessMachineDevice.PROFILE = PROFILE_ID;
633
632
  TacxAdvancedFitnessMachineDevice.detectionPriority = 10;
633
+ exports.default = TacxAdvancedFitnessMachineDevice;
@@ -391,8 +391,8 @@ class BleWahooDevice extends comms_1.default {
391
391
  this.simModeSettings = undefined;
392
392
  }
393
393
  }
394
- exports.default = BleWahooDevice;
395
394
  BleWahooDevice.protocol = 'wahoo';
396
395
  BleWahooDevice.services = [consts_1.CSP];
397
396
  BleWahooDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', consts_1.WAHOO_ADVANCED_TRAINER_CP];
398
397
  BleWahooDevice.detectionPriority = 5;
398
+ exports.default = BleWahooDevice;
package/lib/index.d.ts CHANGED
@@ -8,8 +8,9 @@ import { IncyclistCapability } from './types/capabilities';
8
8
  import { DeviceData } from './types/data';
9
9
  import { DeviceSettings } from './types/device';
10
10
  import CyclingMode from './modes/cycling-mode';
11
+ import calc from './utils/calculations';
11
12
  export * from './modes/cycling-mode';
12
13
  export * from './serial';
13
14
  export * from './ble';
14
15
  export * from './antv2';
15
- export { IncyclistInterface, INTERFACE, InterfaceFactory, InterfaceProps, DeviceSettings, CyclingMode, AdapterFactory, IncyclistDeviceAdapter, Controllable, ControllableDeviceAdapter, DeviceData, IncyclistCapability, };
16
+ export { IncyclistInterface, INTERFACE, InterfaceFactory, InterfaceProps, DeviceSettings, CyclingMode, AdapterFactory, IncyclistDeviceAdapter, Controllable, ControllableDeviceAdapter, DeviceData, IncyclistCapability, calc, };
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.IncyclistCapability = exports.ControllableDeviceAdapter = exports.AdapterFactory = exports.InterfaceFactory = exports.INTERFACE = void 0;
20
+ exports.calc = exports.IncyclistCapability = exports.ControllableDeviceAdapter = exports.AdapterFactory = exports.InterfaceFactory = exports.INTERFACE = void 0;
21
21
  const device_1 = require("./types/device");
22
22
  Object.defineProperty(exports, "INTERFACE", { enumerable: true, get: function () { return device_1.INTERFACE; } });
23
23
  const interfaces_1 = __importDefault(require("./interfaces"));
@@ -28,6 +28,8 @@ const adpater_1 = require("./base/adpater");
28
28
  Object.defineProperty(exports, "ControllableDeviceAdapter", { enumerable: true, get: function () { return adpater_1.ControllableDevice; } });
29
29
  const capabilities_1 = require("./types/capabilities");
30
30
  Object.defineProperty(exports, "IncyclistCapability", { enumerable: true, get: function () { return capabilities_1.IncyclistCapability; } });
31
+ const calculations_1 = __importDefault(require("./utils/calculations"));
32
+ exports.calc = calculations_1.default;
31
33
  __exportStar(require("./modes/cycling-mode"), exports);
32
34
  __exportStar(require("./serial"), exports);
33
35
  __exportStar(require("./ble"), exports);
@@ -144,5 +144,5 @@ class BleERGCyclingMode extends power_base_1.default {
144
144
  return data;
145
145
  }
146
146
  }
147
- exports.default = BleERGCyclingMode;
148
147
  BleERGCyclingMode.isERG = true;
148
+ exports.default = BleERGCyclingMode;
@@ -9,7 +9,7 @@ var CyclingModeProperyType;
9
9
  CyclingModeProperyType["String"] = "String";
10
10
  CyclingModeProperyType["SingleSelect"] = "SingleSelect";
11
11
  CyclingModeProperyType["MultiSelect"] = "MultiSelect";
12
- })(CyclingModeProperyType = exports.CyclingModeProperyType || (exports.CyclingModeProperyType = {}));
12
+ })(CyclingModeProperyType || (exports.CyclingModeProperyType = CyclingModeProperyType = {}));
13
13
  class CyclingModeBase {
14
14
  constructor(adapter, props) {
15
15
  this.settings = {};
@@ -136,5 +136,5 @@ class SimulatorCyclingMode extends power_base_1.default {
136
136
  return data;
137
137
  }
138
138
  }
139
- exports.default = SimulatorCyclingMode;
140
139
  SimulatorCyclingMode.isERG = true;
140
+ exports.default = SimulatorCyclingMode;
@@ -16,6 +16,7 @@ exports.TCPPortBinding = exports.TCPBinding = exports.getSubnets = exports.scanS
16
16
  const gd_eventlog_1 = require("gd-eventlog");
17
17
  const os_1 = require("os");
18
18
  const net_1 = __importDefault(require("net"));
19
+ const DEFAULT_TIMEOUT = 3000;
19
20
  function resolveNextTick() {
20
21
  return new Promise(resolve => process.nextTick(() => resolve()));
21
22
  }
@@ -123,8 +124,7 @@ exports.TCPBinding = {
123
124
  return reject(new TypeError('"path" is not valid'));
124
125
  }
125
126
  const socket = new net_1.default.Socket();
126
- if (options.timeout)
127
- socket.setTimeout(options.timeout);
127
+ socket.setTimeout(options.timeout || DEFAULT_TIMEOUT);
128
128
  socket.once('timeout', () => { reject(new Error('timeout')); });
129
129
  socket.once('error', (err) => { reject(err); });
130
130
  socket.once('connect', () => { resolve(socket); });
@@ -145,6 +145,7 @@ class TCPPortBinding {
145
145
  this.pendingRead = null;
146
146
  this.writeOperation = null;
147
147
  this.data = null;
148
+ this.socket.removeAllListeners();
148
149
  this.socket.on('data', this.onData.bind(this));
149
150
  this.socket.on('error', this.onError.bind(this));
150
151
  this.socket.on('close', () => { this.close(); });
@@ -175,14 +176,20 @@ class TCPPortBinding {
175
176
  if (!this.isOpen)
176
177
  return;
177
178
  this.data = Buffer.alloc(0);
178
- const socket = this.socket;
179
- socket.removeAllListeners();
180
- socket.destroy();
181
- socket.on('error', () => { });
182
- setTimeout(() => { socket.removeAllListeners(); }, 500);
183
- this.socket = null;
184
- if (this.pendingRead) {
185
- this.pendingRead(new CanceledError('port is closed'));
179
+ const close = () => __awaiter(this, void 0, void 0, function* () {
180
+ return new Promise(done => {
181
+ const socket = this.socket;
182
+ socket.on('error', () => { done(false); });
183
+ socket.on('close', () => { socket.removeAllListeners(); done(true); });
184
+ socket.destroy();
185
+ });
186
+ });
187
+ const closed = yield close();
188
+ if (closed) {
189
+ this.socket = null;
190
+ if (this.pendingRead) {
191
+ this.pendingRead(new CanceledError('port is closed'));
192
+ }
186
193
  }
187
194
  });
188
195
  }
@@ -206,5 +206,5 @@ class ERGCyclingMode extends power_base_1.default {
206
206
  return target;
207
207
  }
208
208
  }
209
- exports.default = ERGCyclingMode;
210
209
  ERGCyclingMode.isERG = true;
210
+ exports.default = ERGCyclingMode;
@@ -24,7 +24,7 @@ var direction;
24
24
  (function (direction) {
25
25
  direction["up"] = "up";
26
26
  direction["down"] = "down";
27
- })(direction = exports.direction || (exports.direction = {}));
27
+ })(direction || (exports.direction = direction = {}));
28
28
  class SmartTrainerCyclingMode extends cycling_mode_1.CyclingModeBase {
29
29
  constructor(adapter, props) {
30
30
  super(adapter, props);
@@ -246,5 +246,5 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
246
246
  return this.getBike().runData();
247
247
  }
248
248
  }
249
- exports.default = DaumClassicAdapter;
250
249
  DaumClassicAdapter.NAME = PROTOCOL_NAME;
250
+ exports.default = DaumClassicAdapter;
@@ -243,5 +243,5 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
243
243
  });
244
244
  }
245
245
  }
246
- exports.default = DaumPremiumAdapter;
247
246
  DaumPremiumAdapter.NAME = PROTOCOL_NAME;
247
+ exports.default = DaumPremiumAdapter;
@@ -183,13 +183,13 @@ var ReservedCommands;
183
183
  ReservedCommands[ReservedCommands["RELAX_GET_DATA"] = 15] = "RELAX_GET_DATA";
184
184
  ReservedCommands[ReservedCommands["KEY_PRESSED"] = 16] = "KEY_PRESSED";
185
185
  ReservedCommands[ReservedCommands["PROGRAM_CONTROL"] = 17] = "PROGRAM_CONTROL";
186
- })(ReservedCommands = exports.ReservedCommands || (exports.ReservedCommands = {}));
186
+ })(ReservedCommands || (exports.ReservedCommands = ReservedCommands = {}));
187
187
  var BikeType;
188
188
  (function (BikeType) {
189
189
  BikeType[BikeType["ALLROUND"] = 0] = "ALLROUND";
190
190
  BikeType[BikeType["RACE"] = 1] = "RACE";
191
191
  BikeType[BikeType["MOUNTAIN"] = 2] = "MOUNTAIN";
192
- })(BikeType = exports.BikeType || (exports.BikeType = {}));
192
+ })(BikeType || (exports.BikeType = BikeType = {}));
193
193
  function getBikeType(bikeTypeStr) {
194
194
  if (bikeTypeStr === undefined || bikeTypeStr === null)
195
195
  return BikeType.RACE;
@@ -32,13 +32,13 @@ var SerialCommsState;
32
32
  SerialCommsState[SerialCommsState["Disconnecting"] = 3] = "Disconnecting";
33
33
  SerialCommsState[SerialCommsState["Disconnected"] = 4] = "Disconnected";
34
34
  SerialCommsState[SerialCommsState["Error"] = 5] = "Error";
35
- })(SerialCommsState = exports.SerialCommsState || (exports.SerialCommsState = {}));
35
+ })(SerialCommsState || (exports.SerialCommsState = SerialCommsState = {}));
36
36
  var SendState;
37
37
  (function (SendState) {
38
38
  SendState[SendState["Idle"] = 0] = "Idle";
39
39
  SendState[SendState["Sending"] = 1] = "Sending";
40
40
  SendState[SendState["Receiving"] = 2] = "Receiving";
41
- })(SendState = exports.SendState || (exports.SendState = {}));
41
+ })(SendState || (exports.SendState = SendState = {}));
42
42
  const getBikeProps = (props) => {
43
43
  const { port, interface: ifaceName } = props;
44
44
  let serial;
@@ -140,5 +140,5 @@ class ERGCyclingMode extends power_base_1.default {
140
140
  return data;
141
141
  }
142
142
  }
143
- exports.default = ERGCyclingMode;
144
143
  ERGCyclingMode.isERG = true;
144
+ exports.default = ERGCyclingMode;
@@ -326,5 +326,5 @@ class SerialInterface extends events_1.default {
326
326
  });
327
327
  }
328
328
  }
329
- exports.default = SerialInterface;
330
329
  SerialInterface._instances = [];
330
+ exports.default = SerialInterface;
@@ -9,4 +9,4 @@ var IncyclistCapability;
9
9
  IncyclistCapability["HeartRate"] = "heartrate";
10
10
  IncyclistCapability["Gear"] = "gear";
11
11
  IncyclistCapability["Control"] = "control";
12
- })(IncyclistCapability = exports.IncyclistCapability || (exports.IncyclistCapability = {}));
12
+ })(IncyclistCapability || (exports.IncyclistCapability = IncyclistCapability = {}));
@@ -6,4 +6,4 @@ var RouteType;
6
6
  RouteType["FREE_RIDE"] = "free ride";
7
7
  RouteType["FOLLOW_ROUTE"] = "follow route";
8
8
  RouteType["VIDEO"] = "video";
9
- })(RouteType = exports.RouteType || (exports.RouteType = {}));
9
+ })(RouteType || (exports.RouteType = RouteType = {}));
package/lib/types/user.js CHANGED
@@ -6,4 +6,4 @@ var Gender;
6
6
  Gender["MALE"] = "M";
7
7
  Gender["FEMALE"] = "F";
8
8
  Gender["OTHERS"] = "o";
9
- })(Gender = exports.Gender || (exports.Gender = {}));
9
+ })(Gender || (exports.Gender = Gender = {}));
package/package.json CHANGED
@@ -1,33 +1,34 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",
7
7
  "@serialport/parser-delimiter": "^9.0.1",
8
8
  "@serialport/parser-readline": "^10.5.0",
9
9
  "@serialport/stream": "^10.5.0",
10
- "incyclist-ant-plus": "^0.1.18",
10
+ "incyclist-ant-plus": "^0.2.0",
11
11
  "win32filetime": "^1.0.2"
12
12
  },
13
13
  "peerDependencies": {
14
- "gd-eventlog": "^0.1.22"
14
+ "gd-eventlog": "^0.1.24"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@serialport/binding-mock": "^10.2.2",
18
18
  "@serialport/bindings-cpp": "^10.8.0",
19
- "@types/jest": "^29.2.4",
20
- "@types/node": "^18.11.18",
21
- "eslint": "^8.30.0",
19
+ "@types/jest": "^29.5.3",
20
+ "@types/node": "^20.5.0",
21
+ "eslint": "^8.47.0",
22
22
  "eslint-config-react-app": "^7.0.1",
23
- "jest": "^29.3.1",
24
- "ts-jest": "^29.0.3",
25
- "typescript": "^4.9.4"
23
+ "jest": "^29.6.2",
24
+ "ts-jest": "^29.1.1",
25
+ "typescript": "^5.1.6"
26
26
  },
27
27
  "scripts": {
28
28
  "lint": "eslint . --ext .ts",
29
29
  "build": "tsc",
30
30
  "test": "jest --coverage",
31
+ "test:ci": "jest --coverage --forceExit",
31
32
  "dev": "tsc --watch"
32
33
  },
33
34
  "files": [