From 6fa1bd319f0b72c38ac5edba0ea58121f4a18095 Mon Sep 17 00:00:00 2001 From: lillem4n Date: Sun, 3 May 2015 13:29:15 +0200 Subject: [PATCH] Mostly better logging --- lib/session.js | 4 +++- lib/utils.js | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/session.js b/lib/session.js index 7a100f2..91e8502 100644 --- a/lib/session.js +++ b/lib/session.js @@ -110,7 +110,7 @@ function session(sock) { // Make sure the sequence number is set and is correct pduObj.seqNr = returnObj.ourSeqNr; - log.debug('larvitsmpp: lib/session.js: session() - returnObj.send() - Sending PDU to remote. cmdName: ' + pduObj.cmdName + ' seqNr: ' + pduObj.seqNr); + log.debug('larvitsmpp: lib/session.js: session() - returnObj.send() - Sending PDU to remote. pduObj: ' + JSON.stringify(pduObj)); // If closeAndSend is omitted, put callback in its place if (typeof closeAfterSend === 'function') { @@ -225,6 +225,8 @@ function session(sock) { pduObj.params.registered_delivery = 0x01; } + log.debug('larvitsmpp: lib/session.js: returnObj.sendSms() - pduObj: ' + JSON.stringify(pduObj)); + returnObj.send(pduObj, function(err, retPduObj) { if (typeof callback === 'function') { callback(err, retPduObj.params.message_id, retPduObj); diff --git a/lib/utils.js b/lib/utils.js index 47ce58e..2b3c0e4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -116,6 +116,8 @@ function writeBuffer(obj, cmdLength, callback) { // Write parameter value to buffer using the types method write() paramType.write(obj.params[param], buff, offset); + log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing param "' + param + '" with content "' + obj.params[param] + '"'); + // Increase the offset for the next param offset += paramType.size(obj.params[param]); } @@ -132,7 +134,7 @@ function writeBuffer(obj, cmdLength, callback) { tlvSize = tlvDef.type.size(tlvValue); - log.silly('larvitsmpp: lib/utils.js: objToPdu() - writeBuffer() - Writing TLV "' + tlvName + '" offset: ' + offset + ' value: "' + tlvValue + '"'); + log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing TLV "' + tlvName + '" offset: ' + offset + ' value: "' + tlvValue + '"'); buff.writeUInt16BE(tlvId, offset); buff.writeUInt16BE(tlvSize, offset + 2); @@ -299,6 +301,8 @@ function pduToObj(pdu, callback) { 'tagName': defs.tlvsById[tlvCmdId].tag, 'tagValue': tlvValue }; + + log.silly('larvitsmpp: lib/utils.js: pduToObj() - TLV found: "' + defs.tlvsById[tlvCmdId].tag + '" ID: "' + tlvCmdId + '" value: "' + tlvValue + '"'); } offset = offset + 4 + tlvLength; @@ -307,13 +311,11 @@ function pduToObj(pdu, callback) { // Decode the short message if it is set if (retObj.params.short_message !== undefined) { retObj.params.short_message = decodeMsg(retObj.params.short_message, retObj.params.data_coding); - - callback(null, retObj); - } else { - // We need to do the standard callback in an else statement since - // this always would be called before the above callback if we didn't - callback(null, retObj); } + + log.debug('larvitsmpp: lib/utils.js: pduToObj() - Complete decoded PDU: ' + JSON.stringify(retObj)); + + callback(null, retObj); } /** @@ -357,7 +359,7 @@ function objToPdu(obj, callback) { return; } - // All params are mandatory. Set them if they are not set + // Params must be an object if (obj.params === undefined) { obj.params = {}; } @@ -379,6 +381,8 @@ function objToPdu(obj, callback) { log.silly('larvitsmpp: lib/utils.js: objToPdu() - encoding message "' + shortMsg + '" to "' + obj.params.short_message.toString('hex') + '"'); } + log.debug('larvitsmpp: lib/utils.js: objToPdu() - Complete object to encode: ' + JSON.stringify(obj)); + calcCmdLength(obj, function(err, cmdLength) { if (err) { callback(err);