incyclist-devices 2.0.16 → 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/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);
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.0.16",
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",
@@ -28,6 +28,7 @@
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": [