Skip to content

Commit

Permalink
fix: ignore static AIS data for self if configured in sk
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed Nov 21, 2024
1 parent b857dff commit 6d421ee
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/streams/n2k-signalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.')) {
Expand Down

0 comments on commit 6d421ee

Please sign in to comment.