Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Committer:
maximbolduc
Date:
Fri Mar 06 16:31:19 2015 +0000
Revision:
40:a68cc1a1a1e7
Parent:
35:f9caeb8ca31e
Child:
45:ecd8c2e27948
farmerGPS autosteer routine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maximbolduc 34:c2bc9f9be7ff 1 char* checksum2;
maximbolduc 34:c2bc9f9be7ff 2 int getCheckSum(char *string)
maximbolduc 34:c2bc9f9be7ff 3 {
maximbolduc 34:c2bc9f9be7ff 4 int i;
maximbolduc 34:c2bc9f9be7ff 5 int XOR;
maximbolduc 34:c2bc9f9be7ff 6 int c;
maximbolduc 34:c2bc9f9be7ff 7 bool started = false;
maximbolduc 40:a68cc1a1a1e7 8 for (XOR = 0, i = 0; i < strlen(string); i++) {
maximbolduc 34:c2bc9f9be7ff 9 c = (unsigned char)string[i];
maximbolduc 34:c2bc9f9be7ff 10 if ( c == '$' )started = true;
maximbolduc 40:a68cc1a1a1e7 11
maximbolduc 40:a68cc1a1a1e7 12 if ( started == true ) {
maximbolduc 40:a68cc1a1a1e7 13 if (c == '*') {
maximbolduc 40:a68cc1a1a1e7 14 break;
maximbolduc 40:a68cc1a1a1e7 15 }
maximbolduc 40:a68cc1a1a1e7 16 if (c != '$') XOR ^= c;
maximbolduc 34:c2bc9f9be7ff 17 }
maximbolduc 34:c2bc9f9be7ff 18 }
maximbolduc 34:c2bc9f9be7ff 19 return XOR;
maximbolduc 34:c2bc9f9be7ff 20 }
maximbolduc 34:c2bc9f9be7ff 21
maximbolduc 34:c2bc9f9be7ff 22 bool validate_checksum(char* validating)
maximbolduc 34:c2bc9f9be7ff 23 {
maximbolduc 34:c2bc9f9be7ff 24 bool valid = false;
maximbolduc 34:c2bc9f9be7ff 25 int tempo = getCheckSum(validating);
maximbolduc 34:c2bc9f9be7ff 26 string token, mystring(validating);
maximbolduc 40:a68cc1a1a1e7 27 while(token != mystring) {
maximbolduc 34:c2bc9f9be7ff 28 token = mystring.substr(0,mystring.find_first_of("*"));
maximbolduc 34:c2bc9f9be7ff 29 mystring = mystring.substr(mystring.find_first_of("*") + 1,2);
maximbolduc 34:c2bc9f9be7ff 30 }
maximbolduc 34:c2bc9f9be7ff 31 int checksumm = atoh <uint16_t>(token.c_str());
maximbolduc 40:a68cc1a1a1e7 32 if (tempo == checksumm) {
maximbolduc 34:c2bc9f9be7ff 33 valid = true;
maximbolduc 34:c2bc9f9be7ff 34 }
maximbolduc 34:c2bc9f9be7ff 35 return valid;
maximbolduc 34:c2bc9f9be7ff 36 }