Hi All,
I am trying to run a checksum algorithm found in this forum (probably from the ArduPilot project).
Using the code enclosed I keep getting the wrong checksum 0, the correct checksum is 5B.
However, using the commented out string I get the correct checksum of 68.
What am I doing wrong?
Thanks
//$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E68
//$GPRMC,050000,A,331.57,N,00356.61,E,000.0,269.0,010116,004.0,W5B
int index;
char inchar;
//String tempPos = "$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*";
String tempPos ="$GPRMC,050000,A,331.57,N,00356.61,E,000.0,269.0,010116,004.0,W*";
char pos[80];
byte start_with = 0;
byte end_with = 0;
byte CRC = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
tempPos.toCharArray(pos, 80);
// Serial.print(pos);
for ( index = 0; index < 80; index++) {
inchar = pos[index];
if ( inchar == '$') {
start_with = index;
}
if (inchar == '*') {
end_with = index;
}
for (byte x = start_with + 1; x < end_with; x++) { // XOR every character in between '$' and '*'
CRC = CRC ^ pos[x];
}
}
Serial.println(CRC, HEX);}