Monstrous amount of changes. Bad commit disciplin.

This commit is contained in:
2015-05-10 23:42:11 +02:00
parent 2307800d22
commit 80c0153b57
4 changed files with 292 additions and 107 deletions
+8 -3
View File
@@ -159,11 +159,16 @@ function writeBuffer(obj, cmdLength, callback) {
*
* @param buf buffer
* @param str encoding 'ASCII', 'LATIN1' or 'UCS2' or hex values
* @param int offset - defaults to 0
* @return str in utf8 format
*/
function decodeMsg(buffer, encoding) {
function decodeMsg(buffer, encoding, offset) {
var checkEnc;
if (offset === undefined) {
offset = 0;
}
for (checkEnc in defs.consts.ENCODING) {
if (parseInt(encoding) === defs.consts.ENCODING[checkEnc] || encoding === checkEnc) {
encoding = checkEnc;
@@ -175,7 +180,7 @@ function decodeMsg(buffer, encoding) {
encoding = 'ASCII';
}
return defs.encodings[encoding].decode(buffer);
return defs.encodings[encoding].decode(buffer.slice(offset, buffer.length));
}
function encodeMsg(str) {
@@ -208,7 +213,7 @@ function pduToObj(pdu, stupidNullByte, callback) {
}
// Returns true if this PDU is a response to another PDU
retObj.isResponse = function() {
retObj.isResp = function() {
return ! ! (this.cmdId & 0x80000000);
};