diff --git a/lib/candevice.js b/lib/candevice.js index 3abc718..30000f2 100644 --- a/lib/candevice.js +++ b/lib/candevice.js @@ -66,13 +66,10 @@ class CanDevice extends EventEmitter { this.foundConflict = false this.devices = {} - this.transmitPGNs = defaultTransmitPGNs - if ( this.options.transmitPGNs ) { - this.transmitPGNs = _.union(this.transmitPGNs, - this.options.transmitPGNs) - } + this.transmitPGNs = [] options.app.on('N2KAnalyzerOut', this.n2kMessage.bind(this)) + options.app.on('nmea2000PgnList', this.addPgns.bind(this)) } start() { @@ -81,6 +78,14 @@ class CanDevice extends EventEmitter { sendAddressClaim(this) }, 1000) } + + addPgns(pgnList) { + pgnList.forEach(pgn => { + if ( this.transmitPGNs.indexOf(pgn) === -1 ) { + this.transmitPGNs.push(pgn) + } + }) + } n2kMessage(pgn) { if ( pgn.dst == 255 || pgn.dst == this.address ) { @@ -219,7 +224,7 @@ function handleProductInformation(device, n2kMsg) { if ( !device.devices[n2kMsg.src] ) { device.devices[n2kMsg.src] = {} } - debug('got production information %j', n2kMsg) + debug('got product information %j', n2kMsg) device.devices[n2kMsg.src].productInformation = n2kMsg } @@ -291,13 +296,13 @@ function sendNAKAcknowledgement(device, src, requestedPGN) { } function sendPGNList(device, src) { - //FIXME: for now, adding everything that signalk-to-nmea2000 supports - //need a way for plugins, etc. to register the pgns they provide + const pgns = device.transmitPGNs.length === 0 ? defaultTransmitPGNs : device.transmitPGNs + debug('sending 126464 with pgns: %j', pgns) const pgnList = { pgn: 126464, dst: src, "Function Code": 0, - list: device.transmitPGNs + list: pgns } sendPGN(device, pgnList) }