The sample code is to check the correct gprmc format with the last chars, and try to calculate the checksum of gprmc.
// parameters:
// softuart_revbuf: the whole nmea string with header_char '$' and endchar_char 0x0a
// softuart_revbuf_len: the length of this nmea string
// return:
// TRUE: right format; FALSE: bad string format with error end chars or checksum
bool nmea_checksum(U8* softuart_revbuf, U32 softuart_revbuf_len)
{
U8 checksum = 0;
U8 sum[2], nmea_sum[2];
// "$GPRMC"
if( (softuart_revbuf[3]=='R') && (softuart_revbuf[4]=='M') && (softuart_revbuf[5]=='C') ) {
// check nmea data with length, and '*'<0x0d><0x0a> as endchar
if( (softuart_revbuf_len<10) || (softuart_revbuf[softuart_revbuf_len-2]!=0x0d) || (softuart_revbuf[softuart_revbuf_len-5]!='*') ) {
return FALSE;
}
// checksum
for(U32 i=1; i<(softuart_revbuf_len-5); i++)
checksum ^= softuart_revbuf;
nmea_sum[0] = softuart_revbuf[softuart_revbuf_len-4];
nmea_sum[1] = softuart_revbuf[softuart_revbuf_len-3];
copy_2xchar_1xchar(sum, nmea_sum, 1);
if( checksum != sum[0] ) {
return FALSE;
}
}
return TRUE;
}
Allen Zhan
GV-TECH
2010.05.24
用户1397540 2011-10-28 13:51
用户1553070 2011-10-28 10:52
用户1623087 2011-10-28 09:30
用户1616640 2011-10-28 08:56
用户1277994 2010-5-24 16:45
用户1415052 2010-5-24 15:42