Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feature: get the list of tranmitted pgns from the server if available #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions lib/candevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down