Skip to content

Commit

Permalink
feature: make sending nework statistics optional (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Sep 14, 2020
1 parent e45ca32 commit 58b1c10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/ikonvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 20 additions & 18 deletions lib/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 58b1c10

Please sign in to comment.