Skip to main content
June 16, 2006
Answered

NMEA checksum or C to CF translation

  • June 16, 2006
  • 1 reply
  • 2150 views
Please help me some math or C gurus,
I am in no way a math or C expert and this has made realy huble.

My system calculates checksums based on the National Marine Electronics Association standard. The standard is supported by most GPS systems. I need to generate a hexadecimal number using the checksum of a string according to this and attached C code as an example.

The format of an NMEA sentence is as follows:
$GPRMC,235947.000,V,0000.0000,N,00000.0000,E,,,041299,,*1D<Carriage return>
The checksum immediately follows the ‘*’ (asterisk) character and is computed by taking the bit-wise exclusive-OR of all characters between the ‘$’ (dollar sign) and the ‘*’ (asterisk). The checksum is represented in hexadecimal and is 1D (decimal 29) for the example sentence above.

The following standard C code demonstrates the checksum calculation.
#include <stdio.h>
unsigned char calc_checksum(const char *s)
{
unsigned char result;
result = 0;
s++; // Skip dollar sign
while ((*s != '*') && (*s != '\0'))
result ^= *s++;
return result;
}
int main()
{
unsigned char checksum;
checksum = calc_checksum ("$GPRMC,235947.000,V,0000.0000,N,00000.0000,E,,,041299,,*");
printf("Checksum = %02X\n", checksum);
return 0;
}
When executed, the program should produce the following output:
Checksum = 1D
Could some one help me translating this into CF, CF script or Javascript?
The rest I can do my self.

Bosse Persson
    This topic has been closed for replies.
    Correct answer
    Use the attached code.

    1 reply

    Correct answer
    June 17, 2006
    Use the attached code.

    June 18, 2006
    Thank you MikerRoo,
    I will try this out tomorrow at the office.
    It looks really neat and I cant wait to try it!!!!
    You have helped me to solve an overwelming problem if it works

    I will be back tomorrow
    Bosse