Created
September 5, 2016 20:06
-
-
Save devendranaga/fce8e166f4335fa777650493cb9246db to your computer and use it in GitHub Desktop.
NMEA checksum calculator in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int nmea0183_checksum(char *nmea_data) | |
{ | |
int crc = 0; | |
int i; | |
// the first $ sign and the last two bytes of original CRC + the * sign | |
for (i = 1; i < strlen(nmea_data) - 3; i ++) { | |
crc ^= nmea_data[i]; | |
} | |
return crc; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may want to hoist strlen(nmea_data) out of the loop.