Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore static AIS data for self if configured in sk #1833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 !== '' &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this supposed to work considering that n2k-signalk outputs deltas using the empty path trick? https://github.com/SignalK/n2k-signalk/blob/3b0401af0738c3fd8097ac661e060cdf4b9296cc/test/129794_ais_class_a_static_data.js#L59-L77

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently just ignoring that data for self.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The baseDeltas check does nothing if (did not check..) all the static data from AIS has path: ''. Or am I missing something?

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