Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreePilot PinDetect mbed-src
Fork of FreePilot_V2-2 by
Diff: checksum.h
- 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
