Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Revision:
34:c2bc9f9be7ff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/checksum.h	Fri Feb 13 17:22:53 2015 +0000
@@ -0,0 +1,41 @@
+char* checksum2;
+int getCheckSum(char *string)
+{
+    int i;
+    int XOR;
+    int c;
+    bool started = false;
+    for (XOR = 0, i = 0; i < strlen(string); i++) 
+    {
+        c = (unsigned char)string[i];
+        if ( c == '$' )started = true;
+        
+        if ( started == true )
+        {
+        if (c == '*')
+        {
+            break;
+        }
+        if (c != '$') XOR ^= c;
+        }
+    }
+    return XOR;
+}
+
+bool validate_checksum(char* validating)
+{
+    bool valid = false;
+    int tempo = getCheckSum(validating);
+    string token, mystring(validating);
+    while(token != mystring) 
+    {
+        token = mystring.substr(0,mystring.find_first_of("*"));
+        mystring = mystring.substr(mystring.find_first_of("*") + 1,2);
+    }
+    int checksumm = atoh <uint16_t>(token.c_str());
+    if (tempo == checksumm) 
+    {
+        valid = true;
+    }
+    return valid;
+}
\ No newline at end of file