Show misc_nmea.c syntax highlighted
/*
* misc_nmea -- Utils for creating/decoding NMEA sentences
*
* $Id: misc_nmea.c,v 1.1 2004/03/18 17:30:40 jelson Exp $
*/
char misc_nmea_id[] = "$Id: misc_nmea.c,v 1.1 2004/03/18 17:30:40 jelson Exp $";
#include "misc.h"
/*
* Given a string of the format
* $<sentence>....*
* ... add the NMEA checksum to the end of the string.
*/
void nmea_checksum(char *sentence)
{
int sum = 0;
/* go past the $ at the beginning */
while (*sentence == '$')
sentence++;
/* scan for the '*' at the end */
do {
if (*sentence == '\0') {
elog(LOG_ERR, "NMEA string not terminated with '*'!");
return;
}
sum = (sum ^ *sentence) & 0xff;
sentence++;
} while (*sentence != '*');
/* append the computed checksum to the sentence */
sprintf(sentence+1, "%X%X", (sum & 0xf0) >> 4, sum & 0xf);
}
See more files for this project here