Author Topic: Is the @ sign a terminator for the Character String fields?  (Read 383 times)

trmartin

  • Seaman
  • *
  • Posts: 2
    • View Profile
Is the @ sign a terminator for the Character String fields?
« on: 24 March, 2017, 10:32:00 pm »
This is a pretty simple question: in Eric Raymond's AIVDM/AIVDO protocol decoding page just below the six bit ASCII table (Table 3) he makes a statement that the @ sign (0x00) is used to terminate AIS Character String fields. Fair enough, However I cannot verify this action anywhere else.

So I thought someone here might shed some light on this? any input would be helpful...

Cheers,
TR.Martin
« Last Edit: 27 March, 2017, 09:02:07 am by Des »

malcolmh

  • New User
  • *
  • Posts: 7
    • View Profile
Re: Is the @ sign a terminator for the Character String fields?
« Reply #1 on: 27 March, 2017, 09:11:12 am »
From the standard (1):

"Character strings are presented left to right most significant bit first. All unused characters should be
represented by the @ symbol, and they should be placed at the end of the string."

(1) http://www.itu.int/dms_pubrec/itu-r/rec/m/R-REC-M.1371-5-201402-I!!PDF-E.pdf

coecles

  • Seaman
  • *
  • Posts: 3
    • View Profile
Re: Is the @ sign a terminator for the Character String fields?
« Reply #2 on: 28 March, 2017, 03:15:24 am »
The ITU spec (Recommendation ITU-R M.1371-5) doesn't describe using the at-sign (@ representing six-zero-bits) as a terminator in text fields.

Nonetheless, Eric has likely seen devices using the at-sign as such in the wild, so there is field experience speaking in his advice.

I suspect this situation would have been the result of poorly-written C-language code in which character strings were terminated in a byte of zeros.  Commonly this byte would be followed by garbage in the buffer -- whatever was previously present in the larger buffer.  When a C string is copied into a bigger buffer as part of data that will be transmitted then these trailing bytes should have been overlaid with zeros.

The DMA Java AIS library, which I use, indeed treats the at-sign as a terminator:

/**
     * Utility to trim text from AIS message
     *
     * @param text
     * @return
     */
    public static String trimText(String text) {
        if (text == null) {
            return null;
        }
        // Remove @
        int firstAt = text.indexOf("@");
        if (firstAt >= 0) {
            text = text.substring(0, firstAt);
        }
        // Trim leading and trailing spaces
        return text.trim();
    }


So this seems to be a pragmatic de facto standard approach.

Best,
Gary

malcolmh

  • New User
  • *
  • Posts: 7
    • View Profile
Re: Is the @ sign a terminator for the Character String fields?
« Reply #3 on: 28 March, 2017, 09:00:27 am »
The @ character is not terminator, but rather a fill character to pad out fixed-length string fields. Decoding software would treat the first @ as a terminator, but encodng software must fill out fixed-length strings with trailing @ characters
« Last Edit: 28 March, 2017, 09:02:03 am by malcolmh »

trmartin

  • Seaman
  • *
  • Posts: 2
    • View Profile
Re: Is the @ sign a terminator for the Character String fields?
« Reply #4 on: 28 March, 2017, 08:10:50 pm »
Ah good deal.. (I chose wisely)
I implemented the '@' sign as a character string termination in my Java code. (the '@' sign and anything past it is dropped)
I've run a lot of well formed sentences/messages through my code but testing with 'real world' malformed sentences has proven difficult and has me concerned.
I feel a little better now.

Thanks for help
Much appreciated.
TR.Martin