akiles99
asked on
Checksum(Vb+php)
Hi,
I need a PHP Function returns a NMEA Checksum based on the string given.
its simple XOR formula.
http://www.codepedia.com/1/Calculating+and+Validating+NMEA+Checksums ...
Thanks ,
akiles
I need a PHP Function returns a NMEA Checksum based on the string given.
its simple XOR formula.
http://www.codepedia.com/1/Calculating+and+Validating+NMEA+Checksums ...
Thanks ,
akiles
#define NIBBLE2HEX(c) ((c) > 9 ? (c) + 'A' - 10 : (c) + '0')
// buf is a char[] array which contains the NMEA sentence without trailing checksum.
// E.g. "$FRLIN,,user1,8IVHF" and "*7A" will be added
// buf_inx is an index to the last free position in the buffer
int checksum = 0;
int inx;
for(inx = 1; inx < buf_inx; inx++)
{
checksum ^= buf[inx];
}
buf[buf_inx++] = '*';
buf[buf_inx++] = NIBBLE2HEX((checksum >> 4) & 0xf);
buf[buf_inx++] = NIBBLE2HEX(checksum & 0xf);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
good....
ASKER