From 6d421ee0b3f0dab5d1a6a067125d65f2c83b4c3d Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Thu, 21 Nov 2024 12:00:53 -0500 Subject: [PATCH] fix: ignore static AIS data for self if configured in sk --- packages/streams/n2k-signalk.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/streams/n2k-signalk.js b/packages/streams/n2k-signalk.js index 6a209df8e..9e4d89d47 100644 --- a/packages/streams/n2k-signalk.js +++ b/packages/streams/n2k-signalk.js @@ -20,6 +20,8 @@ const N2kMapper = require('@signalk/n2k-signalk').N2kMapper require('util').inherits(ToSignalK, Transform) +const aisPGNs = [129794, 129810, 129040, 130842, 129809] + function ToSignalK(options) { Transform.call(this, { objectMode: true, @@ -108,6 +110,15 @@ ToSignalK.prototype.isFiltered = function (source) { ) } +ToSignalK.prototype.filterSelfAISStatic = function (values) { + return values.filter((kv) => { + return ( + kv.path !== '' && + this.app.config.baseDeltaEditor.getSelfValue(kv.path) === undefined + ) + }) +} + ToSignalK.prototype._transform = function (chunk, encoding, done) { try { const delta = this.n2kMapper.toDelta(chunk) @@ -137,6 +148,16 @@ ToSignalK.prototype._transform = function (chunk, encoding, done) { return } + //filter out static AIS data for self if configured + if ( + delta.context == this.app.selfContext && + aisPGNs.indexOf(chunk.pgn) !== -1 + ) { + delta.updates[0].values = this.filterSelfAISStatic( + delta.updates[0].values + ) + } + delta.updates.forEach((update) => { update.values.forEach((kv) => { if (kv.path && kv.path.startsWith('notifications.')) {