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: base/checksum.h
- Revision:
- 45:ecd8c2e27948
- Parent:
- 40:a68cc1a1a1e7
- Child:
- 50:07dfcda65732
--- a/base/checksum.h Mon Mar 09 17:36:36 2015 +0000
+++ b/base/checksum.h Tue Mar 10 23:14:18 2015 +0000
@@ -1,4 +1,4 @@
-char* checksum2;
+/*char* checksum2;
int getCheckSum(char *string)
{
int i;
@@ -33,4 +33,54 @@
valid = true;
}
return valid;
+}*/
+
+
+
+
+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, char* &returning)
+{
+ bool valid = false;
+ if (string(validating).find("*") != std::string::npos) {
+
+ int tempo = getCheckSum(validating);
+ string token = "";
+ string 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;
+ returning = (char*)(string(validating).substr(0,string(validating).find('*'))+"\r\n").c_str();
+ } else {
+ returning = (char*)(string(validating).substr(0,string(validating).find('*'))+"\r\n").c_str();
+ }
+ } else {
+ returning = validating;
+ valid = true;
+ }
+ return valid;
}
\ No newline at end of file
