Loading ...
Sorry, an error occurred while loading the content.
 

How to make calculation with the checksum in the AIS sentence?

Expand Messages
  • jackdost
    Hello, For example we have: !AIVDM,1,1,,A,39NWt
    Message 1 of 8 , Jun 11, 2008
      Hello,

      For example we have:

      !AIVDM,1,1,,A,39NWt<@7kDQGjJ8O;U<;MI<400W0,0*66


      How I can check that sentence which I got from the receiver is correct?

      I am writing a program, which decode these sentences, but now I have
      to know how to check sentences if they are correct.

      Please give me all details what I have to add?

      Thanks for all your help.

      Jacek
    • Dave Houy
      Jacek, AIS uses the CRC-CCITT (0xFFFF) variant, available at http://www.lammertbies.nl/comm/info/crc-calculation.html Dave
      Message 2 of 8 , Jun 11, 2008
        Jacek,

        AIS uses the CRC-CCITT (0xFFFF) variant, available at

        http://www.lammertbies.nl/comm/info/crc-calculation.html

        Dave
      • Dave Houy
        Jacek, Forgot to mention the CRC is calculated on the undecoded data as transmitted, therefore you ll need to re-encode the ASCII string before calculation.
        Message 3 of 8 , Jun 11, 2008
          Jacek,

          Forgot to mention the CRC is calculated on the undecoded data as
          transmitted, therefore you'll need to re-encode the ASCII string
          before calculation.

          Dave
        • Giuseppe Menga
          Please Dave, can you detail better what do you means with the last mail? how is the format of the data before the ascii string, and how do you re-decode the
          Message 4 of 8 , Jun 11, 2008
            Please Dave,
            can you detail better what do you means with the last mail?
            how is the format of the data before the ascii string, and how do you re-decode the ascii string?
            thanks in advance
            Giuseppe
            ----- Original Message -----
            From: Dave Houy
            Sent: Wednesday, June 11, 2008 6:59 PM
            Subject: [aismon] Re: How to make calculation with the checksum in the AIS sentence?

            Jacek,

            Forgot to mention the CRC is calculated on the undecoded data as
            transmitted, therefore you'll need to re-encode the ASCII string
            before calculation.

            Dave

          • Dave Houy
            Giuseppe, See the AIS specification at: http://www.tdcom.fr/support/index.php?dir=Sailor%2FAIS-1%2FDocuments%2FITU+doc%2F Dave
            Message 5 of 8 , Jun 11, 2008
            • siirati
              The checksum is checksum of NMEA sentence. Take a second(A) character from string and XOR with next and next to the * character, but not that * . Now you
              Message 6 of 8 , Jun 11, 2008
                The checksum is checksum of NMEA sentence.
                Take a second(A) character from string and XOR with next and next
                to the '*' character, but not that '*'. Now you have
                the checksum in 8 bits. The checksum you get after '*' is
                ASCII-format. Convert they to the same format and compare.

                my solution

                Public Function tarkistussumma(jono As String) As Boolean
                Dim summa As Integer
                Dim tsumma As Integer
                Dim tsummastr As String * 2
                summa = 0
                tsumma = 0
                summa = Asc(Mid$(jono, 2, 1))
                For i = 3 To Len(jono) - 3
                summa = summa Xor Asc(Mid$(jono, i, 1))
                Next i
                If summa < 16 Then
                tsummastr = "0" & Hex$(summa)
                Else
                tsummastr = Hex$(summa)
                End If
                If tsummastr = Mid$(jono, i + 1, 2) Then
                tarkistussumma = True
                Else
                tarkistussumma = False
                End If
                End Function

                t Timppa

                --- In aismon@yahoogroups.com, "jackdost" <jackdost@...> wrote:
                >
                > Hello,
                >
                > For example we have:
                >
                > !AIVDM,1,1,,A,39NWt<@7kDQGjJ8O;U<;MI<400W0,0*66
                >
                >
                > How I can check that sentence which I got from the receiver is correct?
                >
                > I am writing a program, which decode these sentences, but now I have
                > to know how to check sentences if they are correct.
                >
                > Please give me all details what I have to add?
                >
                > Thanks for all your help.
                >
                > Jacek
                >
              • Dave Houy
                Siirati, You are absolutely correct, the CRC16 is used only during verification of the over-the-air packet data. However, a simpler vb calculation of the
                Message 7 of 8 , Jun 11, 2008
                  Siirati,

                  You are absolutely correct, the CRC16 is used only during verification
                  of the over-the-air packet data.

                  However, a simpler vb calculation of the sentence checksum follows:

                  Public Function GPSFCS(Sentence As String) As String

                  Dim i As Long
                  Dim Checksum As Long

                  ' Loop through appropriate chars to get a checksum
                  For i = 2 To Len(Sentence) - 3
                  ' XOR the checksum with this character's value
                  Checksum = Checksum Xor Asc(Mid(Sentence, i, 1))
                  Next

                  ' Return the checksum formatted as a two-character hexadecimal
                  If Checksum < 16 then
                  GPSFCS = "0" & Hex(Checksum)
                  Else
                  GPSFCS = Hex(Checksum)
                  End If

                  End Function

                  Dave
                • lmukis
                  Hi Just this minute joined. By way of an introduction - This is how I calculate the checksum in C(++) Hope it helps For a given message, say -
                  Message 8 of 8 , Aug 26, 2008
                    Hi

                    Just this minute joined. By way of an introduction -

                    This is how I calculate the checksum in C(++)

                    Hope it helps

                    For a given message, say -

                    "!AIVDM,1,1,,A,13u?etPv2;0n:dDPwUM1U1Cb069D,0*24"

                    Pass the entire message (less the double quotes, naturally) to the
                    following:

                    int iChecksum( char* message )
                    {

                    int sum = 0;

                    for( char* c = message+1; *c!='*'; c++ )
                    {
                    sum^=*c;
                    }

                    return sum;

                    }

                    This will return the integer value for the checksum.

                    Don't forget the value you see in the message (24) is HEX (36 decimal)

                    AJ

                    --- In aismon@yahoogroups.com, "jackdost" <jackdost@...> wrote:
                    >
                    > Hello,
                    >
                    > For example we have:
                    >
                    > !AIVDM,1,1,,A,39NWt<@7kDQGjJ8O;U<;MI<400W0,0*66
                    >
                    >
                    > How I can check that sentence which I got from the receiver is
                    correct?
                    >
                    > I am writing a program, which decode these sentences, but now I have
                    > to know how to check sentences if they are correct.
                    >
                    > Please give me all details what I have to add?
                    >
                    > Thanks for all your help.
                    >
                    > Jacek
                    >
                  Your message has been successfully submitted and would be delivered to recipients shortly.