From fc7f186b4325a0776cc2695462992d0c945c8714 Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Thu, 15 Aug 2024 14:03:37 -0400 Subject: [PATCH] feature: report connection write messages for the sk dashboard --- lib/canbus.js | 4 ++++ lib/ikonvert.js | 2 ++ lib/serial.js | 2 ++ lib/w2k01.js | 2 ++ lib/ydgw02.js | 2 ++ 5 files changed, 12 insertions(+) diff --git a/lib/canbus.js b/lib/canbus.js index edaf31b..47d6b1d 100644 --- a/lib/canbus.js +++ b/lib/canbus.js @@ -220,6 +220,10 @@ CanbusStream.prototype.sendPGN = function (msg) { debug('sending %j', msg) + if ( this.options.app ) { + this.options.app.emit('connectionwrite', { providerId: this.options.providerId }) + } + let src = msg.pgn === 59904 || msg.forceSrc ? msg.src : this.candevice.address if ( _.isString(msg) ) { var split = msg.split(',') diff --git a/lib/ikonvert.js b/lib/ikonvert.js index a5d1381..8a3bb29 100644 --- a/lib/ikonvert.js +++ b/lib/ikonvert.js @@ -75,9 +75,11 @@ function iKonvertStream (options) { } else { that.sendPGN(msg) } + options.app.emit('connectionwrite', { providerId: options.providerId }) }) options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => { that.sendPGN(msg) + options.app.emit('connectionwrite', { providerId: options.providerId }) }) this.isSetup = false diff --git a/lib/serial.js b/lib/serial.js index 9855df2..1b3d483 100644 --- a/lib/serial.js +++ b/lib/serial.js @@ -148,6 +148,7 @@ SerialStream.prototype.start = function () { buf = composeMessage(N2K_MSG_SEND, buf, buf.length) debugOut(buf) that.serial.write(buf) + options.app.emit('connectionwrite', { providerId: this.options.providerId }) } function writeObject(msg) { @@ -158,6 +159,7 @@ SerialStream.prototype.start = function () { buf = composeMessage(N2K_MSG_SEND, buf, buf.length) debugOut(buf) that.serial.write(buf) + options.app.emit('connectionwrite', { providerId: this.options.providerId }) } this.options.app.on(this.options.outEevent || 'nmea2000out', msg => { diff --git a/lib/w2k01.js b/lib/w2k01.js index 45acf99..4a11575 100644 --- a/lib/w2k01.js +++ b/lib/w2k01.js @@ -49,10 +49,12 @@ function W2K01Stream (options, type, outEvent) { } else { this.sendPGN(msg) } + options.app.emit('connectionwrite', { providerId: options.providerId }) }) options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => { this.sendPGN(msg) + options.app.emit('connectionwrite', { providerId: options.providerId }) }) } } diff --git a/lib/ydgw02.js b/lib/ydgw02.js index e7a9b6a..490f06d 100644 --- a/lib/ydgw02.js +++ b/lib/ydgw02.js @@ -55,10 +55,12 @@ function Ydgw02Stream (options, type) { } else { this.sendPGN(msg) } + options.app.emit('connectionwrite', { providerId: options.providerId }) }) options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => { this.sendPGN(msg) + options.app.emit('connectionwrite', { providerId: options.providerId }) }) //this.sendString('$PDGY,N2NET_OFFLINE')