incyclist-devices 2.1.11 → 2.1.12

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.
@@ -37,6 +37,8 @@ export default class SerialPortComms<T extends CommsState, C extends Request, R
37
37
  isConnected(): boolean;
38
38
  pauseLogging(): void;
39
39
  resumeLogging(): void;
40
+ pause(): void;
41
+ resume(): void;
40
42
  logEvent(e: any): void;
41
43
  connect(): Promise<boolean>;
42
44
  onConnected(): void;
@@ -51,6 +51,12 @@ class SerialPortComms {
51
51
  resumeLogging() {
52
52
  this.isLoggingPaused = false;
53
53
  }
54
+ pause() {
55
+ this.pauseLogging();
56
+ }
57
+ resume() {
58
+ this.resumeLogging();
59
+ }
54
60
  logEvent(e) {
55
61
  if (this.isLoggingPaused)
56
62
  return;
@@ -24,10 +24,16 @@ export declare class TCPPortBinding implements BindingPortInterface {
24
24
  writeOperation: null | Promise<any>;
25
25
  data: Buffer;
26
26
  private pendingRead;
27
+ private onDataHandler;
28
+ private onErrorHandler;
29
+ private onTimeoutHandler;
30
+ private onCloseHandler;
27
31
  constructor(socket: net.Socket, options: Required<OpenOptions>);
28
32
  get isOpen(): boolean;
29
33
  onData(data: Buffer): void;
30
34
  onError(err: Error): void;
35
+ onTimeout(): void;
36
+ onClose(): void;
31
37
  close(): Promise<void>;
32
38
  read(buffer: Buffer, offset: number, length: number): Promise<{
33
39
  buffer: Buffer;
@@ -141,6 +141,10 @@ exports.TCPBinding = {
141
141
  };
142
142
  class TCPPortBinding {
143
143
  constructor(socket, options) {
144
+ this.onDataHandler = this.onData.bind(this);
145
+ this.onErrorHandler = this.onError.bind(this);
146
+ this.onTimeoutHandler = this.onTimeout.bind(this);
147
+ this.onCloseHandler = this.onClose.bind(this);
144
148
  this.logger = new gd_eventlog_1.EventLogger('TCPPort');
145
149
  this.socket = socket;
146
150
  this.openOptions = options;
@@ -148,11 +152,11 @@ class TCPPortBinding {
148
152
  this.writeOperation = null;
149
153
  this.data = null;
150
154
  this.socket.removeAllListeners();
151
- this.socket.on('data', this.onData.bind(this));
152
- this.socket.on('error', this.onError.bind(this));
153
- this.socket.on('close', () => { this.close(); });
154
- this.socket.on('end', () => { this.close(); });
155
- this.socket.on('timeout', () => { this.onError(new Error('socket timeout')); });
155
+ this.socket.on('data', this.onDataHandler);
156
+ this.socket.on('error', this.onErrorHandler);
157
+ this.socket.on('close', this.onCloseHandler);
158
+ this.socket.on('end', this.onCloseHandler);
159
+ this.socket.on('timeout', this.onTimeoutHandler);
156
160
  }
157
161
  get isOpen() {
158
162
  return this.socket !== null;
@@ -168,11 +172,21 @@ class TCPPortBinding {
168
172
  }
169
173
  }
170
174
  onError(err) {
175
+ this.logger.logEvent({ message: 'Port Error', error: err.message });
171
176
  if (this.pendingRead) {
172
177
  this.pendingRead(err);
173
178
  this.socket = null;
174
179
  }
175
180
  }
181
+ onTimeout() {
182
+ this.logger.logEvent({ message: 'Port Timeout' });
183
+ if (this.pendingRead) {
184
+ this.pendingRead(new Error('timeout'));
185
+ }
186
+ }
187
+ onClose() {
188
+ this.close();
189
+ }
176
190
  close() {
177
191
  return __awaiter(this, void 0, void 0, function* () {
178
192
  if (!this.isOpen)
@@ -217,6 +231,10 @@ class TCPPortBinding {
217
231
  return new Promise((resolve, reject) => {
218
232
  this.pendingRead = err => {
219
233
  if (err) {
234
+ if (err.message === 'timeout') {
235
+ resolve({ buffer: Buffer.from([]), bytesRead: 0 });
236
+ return;
237
+ }
220
238
  return reject(err);
221
239
  }
222
240
  this.read(buffer, offset, length).then(resolve, reject);
@@ -117,7 +117,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
117
117
  return __awaiter(this, void 0, void 0, function* () {
118
118
  yield this.stopUpdatePull();
119
119
  const paused = yield _super.pause.call(this);
120
- (_a = this.comms) === null || _a === void 0 ? void 0 : _a.pauseLogging();
120
+ (_a = this.comms) === null || _a === void 0 ? void 0 : _a.pause();
121
121
  return paused;
122
122
  });
123
123
  }
@@ -128,7 +128,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
128
128
  var _a;
129
129
  return __awaiter(this, void 0, void 0, function* () {
130
130
  const resumed = yield _super.resume.call(this);
131
- (_a = this.comms) === null || _a === void 0 ? void 0 : _a.resumeLogging();
131
+ (_a = this.comms) === null || _a === void 0 ? void 0 : _a.resume();
132
132
  if (startUpdatePull)
133
133
  yield this.startUpdatePull();
134
134
  return resumed;
@@ -256,9 +256,14 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
256
256
  });
257
257
  }
258
258
  cleanupInterval() {
259
- clearInterval(this.iv.sync);
260
- clearInterval(this.iv.update);
261
- this.iv.emitter.removeAllListeners();
259
+ if (!this.iv)
260
+ return;
261
+ if (this.iv.sync)
262
+ clearInterval(this.iv.sync);
263
+ if (this.iv.sync)
264
+ clearInterval(this.iv.update);
265
+ if (this.iv.emitter)
266
+ this.iv.emitter.removeAllListeners();
262
267
  this.iv = undefined;
263
268
  }
264
269
  stopUpdatePull() {
@@ -5,6 +5,7 @@ import { DaumSerialComms } from "../types";
5
5
  import { OnDeviceStartCallback, DaumPremiumCommsState, DaumPremiumRequest, ResponseObject, Route } from "./types";
6
6
  import SerialPortComms from "../../base/comms";
7
7
  export default class Daum8i extends SerialPortComms<DaumPremiumCommsState, DaumPremiumRequest, ResponseObject> implements DaumSerialComms {
8
+ private onDataHandler;
8
9
  validatePath(path: string): string;
9
10
  getDefaultLoggerName(): string;
10
11
  getAckTimeoutValue(): number;
@@ -43,4 +44,6 @@ export default class Daum8i extends SerialPortComms<DaumPremiumCommsState, DaumP
43
44
  programUploadDone(): Promise<boolean>;
44
45
  startProgram(programId?: number): Promise<boolean>;
45
46
  programUpload(bikeType: string, route: Route, onStatusUpdate?: OnDeviceStartCallback): Promise<boolean>;
47
+ pause(): void;
48
+ resume(): void;
46
49
  }
@@ -20,6 +20,10 @@ const utils_2 = require("../../../utils/utils");
20
20
  const comms_1 = __importDefault(require("../../base/comms"));
21
21
  const consts_1 = require("./consts");
22
22
  class Daum8i extends comms_1.default {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.onDataHandler = this.onData.bind(this);
26
+ }
23
27
  validatePath(path) {
24
28
  return (0, utils_1.validatePath)(path);
25
29
  }
@@ -33,7 +37,7 @@ class Daum8i extends comms_1.default {
33
37
  return consts_1.DEFAULT_TIMEOUT;
34
38
  }
35
39
  onConnected() {
36
- this.sp.on('data', this.onData.bind(this));
40
+ this.sp.on('data', this.onDataHandler);
37
41
  }
38
42
  getInitialCommsState() {
39
43
  const state = super.getInitialCommsState();
@@ -574,5 +578,11 @@ class Daum8i extends comms_1.default {
574
578
  }
575
579
  });
576
580
  }
581
+ pause() {
582
+ super.pause();
583
+ }
584
+ resume() {
585
+ super.resume();
586
+ }
577
587
  }
578
588
  exports.default = Daum8i;
@@ -1,8 +1,8 @@
1
1
  export declare abstract class DaumSerialComms {
2
2
  serial: any;
3
3
  abstract getPort(): string;
4
- abstract pauseLogging(): void;
5
- abstract resumeLogging(): void;
4
+ abstract pause(): void;
5
+ abstract resume(): void;
6
6
  abstract isConnected(): boolean;
7
7
  abstract connect(): Promise<boolean>;
8
8
  abstract close(): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",