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

Feature request: Allow deeper filter conditions #35

Open
marcus-aa opened this issue Jul 20, 2020 · 8 comments
Open

Feature request: Allow deeper filter conditions #35

marcus-aa opened this issue Jul 20, 2020 · 8 comments

Comments

@marcus-aa
Copy link

Feature request:
Allow deeper filter conditions (looking at the data in the NMEA sentence)

For example, allowing only AIS messages with a valid channel indicator.

!AIVDO,1,1,,,B3j5;000@4DTk6=uVHswh5sP06,053
!AIVDO,1,1,,,B3j5;00004DTkV=uRHCwhUsP06,0
17

These are "dummy" messages where field 5 is null, I want to filter them out (or only allow every 10th message)

!AIVDO,1,1,,A,B3j5;000@4DTk6=uVHswh5sP06,053
!AIVDO,1,1,,B,B3j5;00004DTkV=uRHCwhUsP06,0
17
!AIVDO,1,1,,1,B3j5;000@4DTk6=uVHswh5sP06,053
!AIVDO,1,1,,2,B3j5;00004DTkV=uRHCwhUsP06,0
17

These are transmitted messages (where field 5 is A,B,1 or 2)

Also useful to block certain poorly formatted messages from older equipment, my Autohelm wind system f ex.

@stripydog
Copy link
Owner

Match by regex?

@marcus-aa
Copy link
Author

No expert in regex but it should work I think.

@stripydog
Copy link
Owner

I'm currently working on two things: a significant change allowing user-supplied filter scripts to be inserted in kplex's input and output streams and also a tool to do various filtering chores on AIS. I hope to have an "alpha" version of the former should be ready by the end of next week which would allow the insertion of simple sed script to do what you're asking for

@stripydog
Copy link
Owner

stripydog commented Aug 27, 2020

Sorry it's been more than a week but I have the basic outline in the "xfilter" branch. It's a bit rough and ready at the moment but should be good for alpha testing within the week

@stripydog
Copy link
Owner

If you're happy to try out a very "alpha" idea which may have all kinds of race conditions but seems to basically work...

  • checkout the "xfilter" branch and compile it
  • create a program which does the filtering you want with the following constraints:
  • It should read standard input and write its output to standard output
  • Output should be at most line buffered. Output from this program won't be to a terminal and note that shell scripts will by default be block buffered in those situations so flush standard out after every line, use stdbuf on linux etc.
  • It should be killable with SIGTERM
  • It should not require any arguments

For example...create /tmp/foo which looks something like this:

#!/usr/bin/python3
import sys

for line in sys.stdin:
    fields=line.split(",")
    if fields[0][1:5] == 'AIVD' and (len(fields) < 5 or not fields[4]):
        continue
    sys.stdout.write(line)
    sys.stdout.flush()

(python is not my strong point but you get the general idea....)
...and make it executable.
Then if you want to filter sentences on input add the following to the stanza declaring the input interface you receive AIS on:
xifilter=/tmp/foo

...or if you want to filter on output, add the following to the stanza for the interface you want to output AIS on:
xofilter=/tmp/foo

Let me know how you get on and appologies in advance if it hangs: still a work in progress :-)

@stripydog
Copy link
Owner

Have you had a chance to check this out yet? The latest code update to the xfilter branch allows specification of arguments but the whole command line needs to be quoted in a config file. Quotes inside that string can be escaped so quotes can be used to delimit arguments containing whitespace. Comments/feedback appreciated.

@stripydog
Copy link
Owner

Any feedback? If not I'll close this in 5 days if I hear nothing

@marcus-aa
Copy link
Author

Have a test setup running, seems to work.
Real test will be when boat is back in the water.

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants