Main Site Documentation

GPS and validation of the NEMA sentence


#1

Im working on a GPS driven autonomous boat and started using this driver http://www.tinyclr.com/downloads/Extension/FEZ_Extensions_GPS.cs but as far as I can see there is no validation of the checksum.
Can someone confirm this or is there a better driver somewhere?


#2

I think I remember someone talking about truncation losing accuracy in the initially published driver.

http://www.tinyclr.com/forum/8/699/ is a recent update that has some improved accuracy plus some additional functions.


#3

I’ve found the Checksum calulation algorythm for NMEA senteces in the Netduino Forum.

Here it is. It should work with the FEZ Domino:


       public static bool HasValidChecksum(string sentence)
        {
            //For assumption purposes "$[at least one character]*XX"
            if (sentence.Length < 5)
                return false;

            //$ = String, but Dollar looks more descriptive
            int DollarLoc = sentence.IndexOf('$');
            int StarLoc = sentence.LastIndexOf('*');

            //make sure this string doesn't have extraneous characters
            if (DollarLoc != 0 || StarLoc != sentence.Length - 3 )
                return false;

            string checksumFromSentence = sentence.Substring(StarLoc + 1, 2);


            String valToCheck = sentence.Substring(DollarLoc+1, StarLoc-1);
            
            //the checksum is calculated by xor-ing all the characters between $ and *
            char c = valToCheck[0];
            for(int i = 1;i<valToCheck.Length;i++)
            {
                c ^= valToCheck[i];
            }

            return Convert.ToInt32(checksumFromSentence,16) == (int)c;
        }



#4

Great, thank’s