node-open-protocol
Advanced tools
Comparing version 1.0.1 to 1.0.2
--- | ||
#### 1.0.2 | ||
- Update test | ||
- Emit error on fail parser | ||
- New control of callback on case Disable Link Layer | ||
--- | ||
#### 1.0.1 | ||
@@ -9,2 +16,3 @@ | ||
- Fix issues #1 and #2 | ||
--- | ||
@@ -14,2 +22,3 @@ #### 1.0.0 | ||
- First release published to npm | ||
--- |
{ | ||
"name": "node-open-protocol", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Node of Open Protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -91,2 +91,5 @@ /* | ||
this.opSerializer.on("error", (err) => this._onErrorSerializer(err)); | ||
//TODO | ||
//Verificar outra tratativa | ||
this.opParser.on("error", (err) => this._onErrorParser(err)); | ||
@@ -130,5 +133,3 @@ this.midParser.on("error", (err) => this._onErrorParser(err)); | ||
_onErrorParser(err) { | ||
// TODO | ||
// this.emit("error", err); | ||
this.emit("errorParser", err); | ||
this.emit("error", err); | ||
return; | ||
@@ -139,6 +140,5 @@ } | ||
if (this.linkLayerActive) { | ||
if (data.mid !== NEGATIVE_ACK && data.mid !== POSITIVE_ACK) { | ||
this.timer = setTimeout(() => this._resendMid(), this.timeOut); | ||
} | ||
if (data.mid !== NEGATIVE_ACK && data.mid !== POSITIVE_ACK) { | ||
clearTimeout(this.timer); | ||
this.timer = setTimeout(() => this._resendMid(), this.timeOut); | ||
} | ||
@@ -192,22 +192,6 @@ | ||
_onDataOpSerializer(data) { | ||
this.stream.write(data, () => { | ||
if (!this.linkLayerActive) { | ||
if (this.callbackWrite) { | ||
function doCallback(cb) { | ||
process.nextTick(() => cb()); | ||
} | ||
doCallback(this.callbackWrite); | ||
this.callbackWrite = undefined; | ||
} | ||
} | ||
}); | ||
this.stream.write(data); | ||
} | ||
_onDataStream(data) { | ||
if (this.rawData) { | ||
@@ -333,7 +317,7 @@ this.dataRaw = Buffer.from(data); | ||
if (this.linkLayerActive) { | ||
if (data.mid === POSITIVE_ACK || data.mid === NEGATIVE_ACK) { | ||
this._receiverLinkLayer(data); | ||
return; | ||
} | ||
clearTimeout(this.timer); | ||
if (data.mid === POSITIVE_ACK || data.mid === NEGATIVE_ACK) { | ||
this._receiverLinkLayer(data); | ||
return; | ||
} | ||
@@ -369,7 +353,5 @@ | ||
_read(size) { | ||
if (this.stream.isPaused()) { | ||
this.stream.resume(); | ||
} | ||
} | ||
@@ -385,2 +367,10 @@ | ||
finishCycle(err) { | ||
if (this.callbackWrite) { | ||
this.callbackWrite(err); | ||
this.callbackWrite = undefined; | ||
} | ||
} | ||
/** | ||
@@ -471,4 +461,2 @@ * Enable LinkLayer | ||
let err = new Error(`[LinkLayer] timeout send MID[${this.message.mid}]`); | ||
clearTimeout(this.timer); | ||
@@ -483,2 +471,6 @@ | ||
let err = new Error(`[LinkLayer] timeout send MID[${this.message.mid}]`); | ||
this.resentTimes = 0; | ||
if (this.callbackWrite) { | ||
@@ -485,0 +477,0 @@ |
@@ -43,3 +43,5 @@ /* | ||
function promisify(ref, method, mid, opts) { | ||
return new Promise(function (resolve, reject) { | ||
return ref[method](mid, opts, (err, data) => { | ||
@@ -56,2 +58,3 @@ if (err) { | ||
function maybePromisify(ref, method, mid, opts, cb) { | ||
if (cb === undefined) { | ||
@@ -65,2 +68,3 @@ if (typeof opts === "function") { | ||
} | ||
return ref[method](mid, opts, cb); | ||
@@ -212,3 +216,3 @@ } | ||
this.keepAliveTimer = undefined; | ||
this.receiverKeepAliveTimer = undefined; | ||
// this.receiverKeepAliveTimer = undefined; | ||
@@ -303,3 +307,5 @@ this.onClose = false; | ||
if (data.payload.midNumber !== 1) { | ||
this.emit("error", new Error(`[Session Control Client] [Connect] invalid acknowledge, expect MID[1], received MID[${data.payload.midNumber}]`)); | ||
let e = new Error(`[Session Control Client] [Connect] invalid acknowledge, expect MID[1], received MID[${data.payload.midNumber}]`); | ||
this.emit("error", e); | ||
this.ll.finishCycle(e); | ||
return; | ||
@@ -314,6 +320,12 @@ } | ||
this.ll.finishCycle(); | ||
sendMidOne(); | ||
} else { | ||
let errorCode = helpers.padLeft(data.payload.errorCode, 2); | ||
this.emit("error", new Error(`[Session Control Client] [Connect] negative acknowledge, MID[${data.payload.midNumber}], Error [${constants.ERROR[errorCode]}]`)); | ||
let e = new Error(`[Session Control Client] [Connect] negative acknowledge, MID[${data.payload.midNumber}], Error [${constants.ERROR[errorCode]}]`); | ||
this.ll.finishCycle(e); | ||
this.emit("error", e); | ||
} | ||
@@ -348,7 +360,7 @@ | ||
this.ll.finishCycle(); | ||
this.statusConnection = CONN_CONNECTED; | ||
this.controllerData = data; | ||
process.nextTick(() => this.emit("connect", data)); | ||
this.ll.on("data", (data) => this._onDataLinkLayer(data)); | ||
@@ -359,12 +371,15 @@ this.ll.on("error", (err) => this._onErrorLinkLayer(err)); | ||
process.nextTick(() => { | ||
this.emit("connect", data); | ||
}); | ||
if (this.useLinkLayer === undefined) { | ||
if (data.payload.sequenceNumberSupport === 1) { | ||
this.ll.activateLinkLayer(); | ||
this.useLinkLayer = true; | ||
} else { | ||
this.ll.deactivateLinkLayer(); | ||
this.useLinkLayer = false; | ||
} | ||
} else if (this.useLinkLayer) { | ||
@@ -375,3 +390,2 @@ if (data.payload.sequenceNumberSupport !== 1 || data.payload.linkingHandlingSupport !== 1) { | ||
} | ||
this.ll.activateLinkLayer(); | ||
@@ -384,4 +398,2 @@ | ||
clearTimeout(this.keepAliveTimer); | ||
clearTimeout(this.receiverKeepAliveTimer); | ||
this.keepAliveTimer = setTimeout(() => this._sendKeepAlive(), this.keepAlive); | ||
@@ -391,2 +403,3 @@ | ||
this.inOperation = false; | ||
this._sendingProcess(); | ||
@@ -420,4 +433,7 @@ } | ||
if (this.onClose) { | ||
return; | ||
} | ||
clearTimeout(this.keepAliveTimer); | ||
clearTimeout(this.receiverKeepAliveTimer); | ||
@@ -434,5 +450,2 @@ this.onClose = true; | ||
this.ll.destroy(); | ||
this.stream.end(); | ||
this.midInProcess = null; | ||
@@ -443,2 +456,5 @@ this.midQueue = []; | ||
this.ll.destroy(); | ||
this.stream.end(); | ||
this.emit("close", err); | ||
@@ -836,3 +852,2 @@ } | ||
clearTimeout(this.keepAliveTimer); | ||
clearTimeout(this.receiverKeepAliveTimer); | ||
@@ -906,3 +921,2 @@ this.keepAliveTimer = setTimeout(() => this._sendKeepAlive(), this.keepAlive); | ||
return revision || 0; | ||
} | ||
@@ -957,21 +971,18 @@ | ||
if (this.onClose) { | ||
clearTimeout(this.keepAliveTimer); | ||
return; | ||
} | ||
clearTimeout(this.keepAliveTimer); | ||
this.keepAliveTimer = setTimeout(() => this._sendKeepAlive(), this.keepAlive); | ||
if (!this.receiverKeepAliveTimer || this.receiverKeepAliveTimer._idleTimeout === -1) { | ||
this.receiverKeepAliveTimer = setTimeout(() => this._failKeepAlive(), this.keepAlive); | ||
} | ||
this.request("keepAlive", (err) => { | ||
clearTimeout(this.receiverKeepAliveTimer); | ||
if (err) { | ||
clearTimeout(this.keepAliveTimer); | ||
this.close(); | ||
} | ||
}); | ||
} | ||
_failKeepAlive() { | ||
clearTimeout(this.receiverKeepAliveTimer); | ||
clearTimeout(this.keepAliveTimer); | ||
this.close(); | ||
} | ||
/** | ||
@@ -987,7 +998,12 @@ * @private | ||
if (!this.midInProcess) { | ||
return; | ||
} | ||
let midNumber = data.payload.midNumber; | ||
if (midNumber !== this.midInProcess.midNumber) { | ||
if (!this.midInProcess || midNumber !== this.midInProcess.midNumber) { | ||
let err = new Error(`[Session Control Client] invalid acknowledge, expect MID[${this.midInProcess.midNumber}], received MID[${midNumber}]`); | ||
this.midInProcess.doCallback(err); | ||
this.ll.finishCycle(err); | ||
this.inOperation = false; | ||
@@ -1007,2 +1023,3 @@ this._sendingProcess(); | ||
this.changeRevisionGeneric = true; | ||
this.ll.finishCycle(); | ||
this._transmitMid(); | ||
@@ -1016,2 +1033,3 @@ return; | ||
this.changeRevision = true; | ||
this.ll.finishCycle(); | ||
this._transmitMid(); | ||
@@ -1025,2 +1043,3 @@ return; | ||
this.midInProcess.doCallback(err); | ||
this.ll.finishCycle(err); | ||
this.inOperation = false; | ||
@@ -1032,2 +1051,3 @@ this._sendingProcess(); | ||
//Positive acknowledge | ||
this.ll.finishCycle(); | ||
this.midInProcess.doCallback(null, data); | ||
@@ -1054,2 +1074,4 @@ this.inOperation = false; | ||
this.ll.finishCycle(); | ||
if (!this.useLinkLayer) { | ||
@@ -1068,5 +1090,7 @@ | ||
if (replyGroup === this.midInProcess.group) { | ||
this.ll.finishCycle(); | ||
this.midInProcess.doCallback(null, data); | ||
} else { | ||
let err = new Error(`[Session Control Client] invalid reply, expect MID[${midReply}], received [${data.mid}]`); | ||
let err = new Error(`[Session Control Client] invalid reply, expect MID[${JSON.stringify(midReply)}], received [${data.mid}]`); | ||
this.ll.finishCycle(err); | ||
this.midInProcess.doCallback(err); | ||
@@ -1094,4 +1118,8 @@ } | ||
_onErrorSerializer(err) { | ||
if (this.midInProcess) { | ||
this.midInProcess.doCallback(err); | ||
} | ||
this._sendKeepAlive(); | ||
this.midInProcess.doCallback(err); | ||
this.inOperation = false; | ||
@@ -1101,12 +1129,2 @@ this._sendingProcess(); | ||
/** | ||
* @private | ||
* @param {*} err | ||
*/ | ||
_onErrorParser(err) { | ||
this.midInProcess.doCallback(err); | ||
this.inOperation = false; | ||
this._sendingProcess(); | ||
} | ||
} | ||
@@ -1153,2 +1171,3 @@ | ||
doCallback(err, data) { | ||
if (this._callback !== undefined) { | ||
@@ -1155,0 +1174,0 @@ this._callback(err, data); |
@@ -112,3 +112,3 @@ /* | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00" | ||
@@ -169,3 +169,3 @@ } | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00", | ||
@@ -230,3 +230,3 @@ torqueValuesUnit: 2, | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00", | ||
@@ -294,3 +294,3 @@ torqueValuesUnit: 2, | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00", | ||
@@ -359,3 +359,3 @@ torqueValuesUnit: 2, | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00", | ||
@@ -427,3 +427,3 @@ torqueValuesUnit: 2, | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00", | ||
@@ -573,3 +573,3 @@ torqueValuesUnit: 2, | ||
syncTighteningID: 25463, | ||
toolSerialNumber: 95623145874512, | ||
toolSerialNumber: "95623145874512", | ||
timeStamp: "2018-06-06:12:20:00", | ||
@@ -576,0 +576,0 @@ torqueValuesUnit: 2, |
@@ -46,9 +46,9 @@ /* | ||
let step = 0; | ||
let sessionControlClient; | ||
let stream = createStreamHelper((data) => { | ||
//console.log("Receiver", data.toString()); | ||
switch (step) { | ||
case 0: | ||
stream.push(Buffer.from("00260004001000000000000197\u0000")); | ||
step++; | ||
break; | ||
@@ -58,3 +58,2 @@ | ||
stream.push(Buffer.from("00260004001000000000000197\u0000")); | ||
step++; | ||
break; | ||
@@ -64,3 +63,2 @@ | ||
stream.push(Buffer.from("00260004001000000000000197\u0000")); | ||
step++; | ||
break; | ||
@@ -70,3 +68,2 @@ | ||
stream.push(Buffer.from("00260004001000000000000197\u0000")); | ||
step++; | ||
break; | ||
@@ -76,3 +73,2 @@ | ||
stream.push(Buffer.from("00260004001000000000000197\u0000")); | ||
step++; | ||
break; | ||
@@ -82,8 +78,10 @@ | ||
stream.push(Buffer.from("00570002001000000000010001020103Airbag1 \u0000")); | ||
step++; | ||
break; | ||
} | ||
step++; | ||
}); | ||
let sessionControlClient = new SessionControlClient({ | ||
sessionControlClient = new SessionControlClient({ | ||
stream: stream | ||
@@ -108,10 +106,5 @@ }); | ||
let sessionControlClient = new SessionControlClient({ | ||
stream: stream, | ||
defaultRevisions: {} | ||
stream: stream | ||
}); | ||
sessionControlClient.on("data", data => { | ||
//console.log("SCC - Data:", data); | ||
}); | ||
sessionControlClient.on("error", err => { | ||
@@ -128,2 +121,3 @@ console.log("SCC - Error:", err); | ||
sessionControlClient.connect(); | ||
}); | ||
@@ -137,2 +131,3 @@ | ||
let stream = createStreamHelper((data) => { | ||
switch (step) { | ||
@@ -155,6 +150,2 @@ case 0: | ||
sessionControlClient.on("data", data => { | ||
//console.log("SCC - Data:", data); | ||
}); | ||
sessionControlClient.on("error", err => { | ||
@@ -165,3 +156,5 @@ console.log("SCC - Error:", err); | ||
sessionControlClient.on("connect", () => { | ||
sessionControlClient.subscribe("lastTightening", null, (err) => { | ||
sessionControlClient.subscribe("lastTightening", null, (err, data) => { | ||
expect(err).to.be.null; | ||
@@ -588,3 +581,3 @@ sessionControlClient.close(); | ||
step++; | ||
stream.push(Buffer.from("0022003900100000000055\u0000")); | ||
stream.push(Buffer.from("0022003900100000000055\u0000")); | ||
} | ||
@@ -750,3 +743,3 @@ }); | ||
sessionControlClient.on("connect", () => { | ||
sessionControlClient.subscribe("psetSelected", {}, (err, data) =>{ | ||
@@ -767,3 +760,3 @@ | ||
}; | ||
expect(data).to.be.deep.equal(mid); | ||
@@ -810,3 +803,3 @@ sessionControlClient.close(); | ||
sessionControlClient.unsubscribe("psetSelected", (err, data) => { | ||
let mid = { | ||
@@ -825,3 +818,3 @@ mid: 5, | ||
}; | ||
expect(data).to.be.deep.equal(mid); | ||
@@ -926,3 +919,3 @@ sessionControlClient.close(); | ||
expect(str).to.be.deep.equal(data.toString("ascii")); | ||
sessionControlClient.close(); | ||
sessionControlClient.close(); | ||
done(); | ||
@@ -950,2 +943,33 @@ | ||
it("Should close connection, fail send keepAlive by retry and timeout - Based Test 30/08/2018", (done) => { | ||
let sessionControlClient; | ||
let step = 0; | ||
let stream = createStreamHelper((data) => { | ||
switch (step) { | ||
case 0: | ||
stream.push(Buffer.from("01790002006 0000010000020003PA160LDA2 04ACT052.2 0610.15.6 07 08Silver (Ag) 09D240003 1000111001121130\u0000")); | ||
step += 1; | ||
break; | ||
} | ||
}); | ||
sessionControlClient = new SessionControlClient({ | ||
stream: stream, | ||
genericMode: false, | ||
keepAlive: 1000, | ||
timeOut: 300 | ||
}); | ||
sessionControlClient.on('close', (err) => { | ||
if (err) { | ||
sessionControlClient.close(); | ||
done(); | ||
} | ||
}); | ||
sessionControlClient.connect(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5330302
17558
2