Skip to content

Commit

Permalink
feature: support nmea2000out in actisense format
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed Oct 22, 2018
1 parent 1d67ca8 commit 5bac00d
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/ikonvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const debug = require('debug')('canboatjs:canbus')
const debug = require('debug')('canboatjs:ikonvert')
const Transform = require('stream').Transform
const isArray = require('lodash').isArray
const BitStream = require('bit-buffer').BitStream
Expand Down Expand Up @@ -58,12 +58,13 @@ function iKonvertStream (options) {

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


debug('started')
//this.options.app.emit('nmea2000OutAvailable')
}
}
Expand All @@ -74,16 +75,37 @@ iKonvertStream.prototype.start = function () {
}

iKonvertStream.prototype.sendString = function (msg) {
debug('sending %s', msg)
this.options.app.emit('ikonvertOut', msg + '\r\n')
}

iKonvertStream.prototype.sendPGN = function (pgn) {
if ( this.cansend ) {
let msg = toiKonvertSerialFormat(pgn)
let msg = pgnToiKonvertSerialFormat(pgn)
this.sendString(msg)
}
}

iKonvertStream.prototype.sendActisensePGN = function (msg) {
if ( this.cansend ) {
if ( !this.parser ) {
this.parser = new Parser()

let that = this
this.parser.on('error', (pgn, error) => {
console.error(`Error parsing ${pgn.pgn} ${error}`)
console.error(error.stack)
})

this.parser.on('pgn', (pgn) => {
let msg = pgnToiKonvertSerialFormat(pgn)
that.sendString(msg)
})
}
this.parser.parseString(msg)
}
}

iKonvertStream.prototype.setup = function () {
let txPgns = '$PDGY,TX_LIST'
defaultTransmitPGNs.forEach(pgn => {
Expand Down

0 comments on commit 5bac00d

Please sign in to comment.