Skip to content

Commit

Permalink
feature: support multiple nmea2000 devices (#1553)
Browse files Browse the repository at this point in the history
We need to be able to configure the outEvents
  • Loading branch information
sbender9 authored May 16, 2023
1 parent 599c62f commit d7870ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/streams/canboatjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function CanboatJs(options) {

this.fromPgn = new FromPgn(options)
const createDebug = options.createDebug || require('debug')
const debug = createDebug('signalk:streams:nmea0183-signalk')
const debug = createDebug('signalk:streams:canboatjs')

this.fromPgn.on('warning', (pgn, warning) => {
debug(`[warning] ${pgn.pgn} ${warning}`)
Expand All @@ -36,6 +36,7 @@ function CanboatJs(options) {
})

this.app = options.app
this.analyzerOutEvent = options.analyzerOutEvent || 'N2KAnalyzerOut'
}

require('util').inherits(CanboatJs, Transform)
Expand All @@ -46,13 +47,13 @@ CanboatJs.prototype._transform = function (chunk, encoding, done) {
if (pgnData) {
pgnData.timestamp = new Date(Number(chunk.timestamp)).toISOString()
this.push(pgnData)
this.app.emit('N2KAnalyzerOut', pgnData)
this.app.emit(this.analyzerOutEvent, pgnData)
}
} else {
const pgnData = this.fromPgn.parse(chunk)
if (pgnData) {
this.push(pgnData)
this.app.emit('N2KAnalyzerOut', pgnData)
this.app.emit(this.analyzerOutEvent, pgnData)
}
}
done()
Expand Down
5 changes: 4 additions & 1 deletion packages/streams/n2kAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function N2KAnalyzer(options) {
Transform.call(this, {
objectMode: true,
})

this.analyzerOutEvent = options.analyzerOutEvent || 'N2KAnalyzerOut'

if (process.platform === 'win32') {
this.analyzerProcess = require('child_process').spawn('cmd', [
'/c',
Expand Down Expand Up @@ -47,7 +50,7 @@ function N2KAnalyzer(options) {
try {
parsed = JSON.parse(data)
that.push(parsed)
options.app.emit('N2KAnalyzerOut', parsed)
options.app.emit(this.analyzerOutEvent, parsed)
} catch (ex) {
console.error(data)
console.error(ex.stack)
Expand Down
1 change: 0 additions & 1 deletion packages/streams/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ function nmea2000input(subOptions, logging) {
return [
new actisenseSerial({
...subOptions,
outEvent: 'nmea2000out',
plainText: logging,
}),
]
Expand Down

0 comments on commit d7870ee

Please sign in to comment.