incyclist-devices 1.4.18 → 1.4.19
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/kettler/comms.js
CHANGED
|
@@ -16,7 +16,7 @@ const gd_eventlog_1 = require("gd-eventlog");
|
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
17
|
const events_1 = __importDefault(require("events"));
|
|
18
18
|
const DEFAULT_RCV_TIMEOUT = 1500;
|
|
19
|
-
const DEFAULT_OPEN_TIMEOUT =
|
|
19
|
+
const DEFAULT_OPEN_TIMEOUT = 3000;
|
|
20
20
|
const DEBUG_LOGGER = {
|
|
21
21
|
log: (e, ...args) => console.log(e, ...args),
|
|
22
22
|
logEvent: (event) => console.log(JSON.stringify(event))
|
|
@@ -200,6 +200,7 @@ class KettlerSerialComms extends events_1.default {
|
|
|
200
200
|
cmd.onError(err);
|
|
201
201
|
this.sendState = SendState.Idle;
|
|
202
202
|
this.currentCmd = undefined;
|
|
203
|
+
this.stopCurrentTimeoutCheck();
|
|
203
204
|
};
|
|
204
205
|
try {
|
|
205
206
|
this.logger.logEvent({ message: "sendCommand:sending:", cmd: logStr, msg, port: this.getPort() });
|
|
@@ -208,16 +209,17 @@ class KettlerSerialComms extends events_1.default {
|
|
|
208
209
|
this.sp.write(msg + CRLF, (err) => {
|
|
209
210
|
this.sendState = SendState.Receiving;
|
|
210
211
|
this.currentCmd = cmd;
|
|
211
|
-
if (timeout) {
|
|
212
|
-
this.currentTimeout = setTimeout(() => {
|
|
213
|
-
if (this.sendState === SendState.Receiving) {
|
|
214
|
-
onError(new Error("response timeout"));
|
|
215
|
-
}
|
|
216
|
-
}, timeout);
|
|
217
|
-
}
|
|
218
212
|
if (err)
|
|
219
213
|
onError(err);
|
|
220
214
|
});
|
|
215
|
+
this.currentTimeout = setTimeout(() => {
|
|
216
|
+
if (this.sendState === SendState.Sending) {
|
|
217
|
+
onError(new Error("send timeout"));
|
|
218
|
+
}
|
|
219
|
+
if (this.sendState === SendState.Receiving) {
|
|
220
|
+
onError(new Error("response timeout"));
|
|
221
|
+
}
|
|
222
|
+
}, timeout);
|
|
221
223
|
}
|
|
222
224
|
catch (err) {
|
|
223
225
|
onError(err);
|
|
@@ -232,7 +234,7 @@ class KettlerSerialComms extends events_1.default {
|
|
|
232
234
|
this.write(cmd);
|
|
233
235
|
}
|
|
234
236
|
send(cmd) {
|
|
235
|
-
this.logger.logEvent({ message: '
|
|
237
|
+
this.logger.logEvent({ message: 'add command to queue', cmd: cmd.logStr, msg: cmd.message, port: this.getPort(), queueSize: this.queue.size() });
|
|
236
238
|
this.queue.enqueue(cmd);
|
|
237
239
|
}
|
|
238
240
|
}
|