Skip to content

Commit

Permalink
feature: allow configuration on the nmea2000 output event (#121)
Browse files Browse the repository at this point in the history
This also makes so either string actisense or json formats can be sent to the same event
  • Loading branch information
sbender9 authored Aug 13, 2020
1 parent 685d449 commit 5963dcd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/canbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function CanbusStream (options) {
var that = this

if ( options.app ) {
options.app.on('nmea2000out', (msg) => {
options.app.on(options.outEvent || 'nmea2000out', (msg) => {
that.sendPGN(msg)
})
options.app.on('nmea2000JsonOut', (msg) => {
Expand Down
8 changes: 6 additions & 2 deletions lib/ikonvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ function iKonvertStream (options) {
var that = this

if ( this.options.app ) {
options.app.on('nmea2000out', (msg) => {
that.sendActisensePGN(msg)
options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
if ( typeof msg === 'string' ) {
that.sendActisensePGN(msg)
} else {
that.sendPGN(msg)
}
})
options.app.on('nmea2000JsonOut', (msg) => {
that.sendPGN(msg)
Expand Down
22 changes: 17 additions & 5 deletions lib/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,34 @@ SerialStream.prototype.start = function () {
})

if ( this.options.app ) {
this.options.app.on('nmea2000out', msg => {
function writeString(msg) {
debugOut(`sending ${msg}`)
var buf = parseInput(msg)
buf = composeMessage(N2K_MSG_SEND, buf, buf.length)
that.serial.write(buf)
})

this.options.app.on('nmea2000JsonOut', msg => {
}
function writeObject(msg) {
var data = toPgn(msg)
var actisense = encodeActisense({ pgn: msg.pgn, data, dst: msg.dst})
debugOut(`sending ${actisense}`)
var buf = parseInput(actisense)
buf = composeMessage(N2K_MSG_SEND, buf, buf.length)
that.serial.write(buf)
}

this.options.app.on(this.options.outEevent || 'nmea2000out', msg => {
if ( typeof msg === 'string' ) {
writeString(msg)
} else {
writeObject(msg)
}
})


this.options.app.on('nmea2000JsonOut', msg => {
writeObject(msg)
})

this.options.app.emit('nmea2000OutAvailable')
}

Expand Down
12 changes: 7 additions & 5 deletions lib/ydgw02.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ function Ydgw02Stream (options) {
})


if ( this.options.app ) {
options.app.on('nmea2000out', (msg) => {
this.sendYdgwPGN(msg)
if ( options.app ) {
options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
if ( typeof msg === 'string' ) {
this.sendYdgwPGN(msg)
} else {
this.sendPGN(msg)
}
})

options.app.on('nmea2000JsonOut', (msg) => {
this.sendPGN(msg)
})

//this.sendString('$PDGY,N2NET_OFFLINE')

debug('started')
}

Expand Down

0 comments on commit 5963dcd

Please sign in to comment.