From 8eea39754133aa81f99691aacee24311d7d7f57f Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Thu, 13 Sep 2018 15:54:45 -0400 Subject: [PATCH 1/2] feature: get the list of tranmitted pgns from the server if available --- lib/candevice.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/candevice.js b/lib/candevice.js index 3abc718..84de2be 100644 --- a/lib/candevice.js +++ b/lib/candevice.js @@ -66,11 +66,14 @@ class CanDevice extends EventEmitter { this.foundConflict = false this.devices = {} + this.transmitPGNs = [] + /* this.transmitPGNs = defaultTransmitPGNs if ( this.options.transmitPGNs ) { this.transmitPGNs = _.union(this.transmitPGNs, this.options.transmitPGNs) } + */ options.app.on('N2KAnalyzerOut', this.n2kMessage.bind(this)) } @@ -219,7 +222,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 +294,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 transmitPGNs = !device.options.app.getTransmitPGNs ? defaultTransmitPGNs : device.options.app.getTransmitPGNs() + debug('sending 126464 with pgns: %j', transmitPGNs) const pgnList = { pgn: 126464, dst: src, "Function Code": 0, - list: device.transmitPGNs + list: transmitPGNs } sendPGN(device, pgnList) } From 707fc437e60073e2a7e0ad2a2e6219cd585b09ee Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Tue, 30 Oct 2018 10:30:12 -0400 Subject: [PATCH 2/2] refactor: use events instead of storing the list with the server --- lib/candevice.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/candevice.js b/lib/candevice.js index 84de2be..30000f2 100644 --- a/lib/candevice.js +++ b/lib/candevice.js @@ -67,15 +67,9 @@ class CanDevice extends EventEmitter { this.devices = {} this.transmitPGNs = [] - /* - this.transmitPGNs = defaultTransmitPGNs - if ( this.options.transmitPGNs ) { - this.transmitPGNs = _.union(this.transmitPGNs, - this.options.transmitPGNs) - } - */ options.app.on('N2KAnalyzerOut', this.n2kMessage.bind(this)) + options.app.on('nmea2000PgnList', this.addPgns.bind(this)) } start() { @@ -84,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 ) { @@ -294,13 +296,13 @@ function sendNAKAcknowledgement(device, src, requestedPGN) { } function sendPGNList(device, src) { - const transmitPGNs = !device.options.app.getTransmitPGNs ? defaultTransmitPGNs : device.options.app.getTransmitPGNs() - debug('sending 126464 with pgns: %j', transmitPGNs) + 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: transmitPGNs + list: pgns } sendPGN(device, pgnList) }