From 58b1c10bef989c70de6924c2055e75e7170399ee Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Mon, 14 Sep 2020 13:26:31 -0400 Subject: [PATCH] feature: make sending nework statistics optional (#130) --- lib/ikonvert.js | 2 +- lib/serial.js | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/ikonvert.js b/lib/ikonvert.js index e08aa0b..2c32a42 100644 --- a/lib/ikonvert.js +++ b/lib/ikonvert.js @@ -173,7 +173,7 @@ iKonvertStream.prototype._transform = function (chunk, encoding, done) { } else if ( line.startsWith('$PDGY,000000,') ) { let parts = line.split(',') - if ( parts[2] && parts[2].length > 0 ) { + if ( this.options.sendNetworkStats && parts[2] && parts[2].length > 0 ) { const pgn = { pgn: 0x40100, prio: 7, diff --git a/lib/serial.js b/lib/serial.js index 9599603..6700937 100644 --- a/lib/serial.js +++ b/lib/serial.js @@ -308,25 +308,27 @@ function processNTGMessage(that, buffer, len) return } - let newbuf = new Buffer.alloc(len + 7 ) - var bs = new BitStream(newbuf) - const pgn = 0x40000 + buffer[2] - bs.writeUint8(0) //prio - bs.writeUint8(pgn) - bs.writeUint8(pgn >> 8) - bs.writeUint8(pgn >> 16) - bs.writeUint8(0) //dst - bs.writeUint8(0) //src - bs.writeUint32(0) //timestamp - bs.writeUint8(len-4) - buffer.copy(bs.view.buffer, bs.byteIndex, 3) - - if ( that.options.plainText ) { - that.push(binToActisense(bs.view.buffer, len+7)) - } else { - that.push(bs.view.buffer, len+7) + if ( this.options.sendNetworkStats ) { + let newbuf = new Buffer.alloc(len + 7 ) + var bs = new BitStream(newbuf) + const pgn = 0x40000 + buffer[2] + bs.writeUint8(0) //prio + bs.writeUint8(pgn) + bs.writeUint8(pgn >> 8) + bs.writeUint8(pgn >> 16) + bs.writeUint8(0) //dst + bs.writeUint8(0) //src + bs.writeUint32(0) //timestamp + bs.writeUint8(len-4) + buffer.copy(bs.view.buffer, bs.byteIndex, 3) + + if ( that.options.plainText ) { + that.push(binToActisense(bs.view.buffer, len+7)) + } else { + that.push(bs.view.buffer, len+7) + } } - + if ( !that.outAvailable ) { const command = buffer[2]