NMEA 0183 - C Implementation of Checksum Generation

C Implementation of Checksum Generation

Persons looking to implement NMEA 0183 are often stumped by the checksum part. The following C code generates a checksum for the string entered as "mystring" and prints it to the output stream. In the example a sentence for the sample file is used.

#include #include int main { char *mystring= "GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A"; int lengthofstring = strlen(mystring); int checksum=0, i; for( i=0; i
Which can be simplified to function form as follows:

#include #include int checksum(char *s) { int c = 0; while(*s) c ^= *s++; return c; } int main { char mystring = "GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A"; printf("String: %s\nChecksum: 0x%02X\n", mystring, checksum(mystring)); return 0; }

Read more about this topic:  NMEA 0183

Famous quotes containing the word generation:

    The world is never the same as it was.... And that’s as it should be. Every generation has the obligation to make the preceding generation irrelevant. It happens in little ways: no longer knowing the names of bands or even recognizing their sounds of music; no longer implicitly understanding life’s rules: wearing plaid Bermuda shorts to the grocery and not giving it another thought.
    Jim Shahin (20th century)