Extend the AIS protocol with a new sentence [!ABVDM ]

Nikolay 2 years ago

Hello,

I need some advice, which is the better approach to add !ABVDM to the AisProtocolDecoder.

To extend the current one or to implement a new protocol, the only difference is the initial sentence - !ABVDM instead of !AIVDM

Anton Tananaev2 years ago

Extending the existing one is what we usually prefer.

Nikolay 2 years ago

Is it possible to switch .text in PatternBuilder?

private static final Pattern PATTERN = new PatternBuilder()
.text("!AIVDM,")
.number("(d+),")
.number("(d+),")
.number("(d+)?,")
.expression(".,")
.expression("([^,]+),")
.any()
.compile();
Anton Tananaev2 years ago

No, you need an expression.

Nikolay 2 years ago

What this expression should look like?

I thought that if I pass to Parser "!ABVDM,|!AIVDM,...." it would work, but it doesn't.

Would it be possible to get some help?

Anton Tananaev2 years ago

I would probably do something like this:

.text("!")
.expression("A[DI]VDM,")
Nikolay 2 years ago
private static final Pattern PATTERN = new PatternBuilder()
            .text("!")
            .expression("A[BI]VDM,")
            .number("(d+),")                     // count
            .number("(d+),")                     // index
            .number("(d+)?,")                    // id
            .expression(".,")                    // radio channel
            .expression("([^,]+),")              // payload
            .any()
            .compile();

It works like a charm.
All tests passed successfully.

Thank you very much