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
checksum.h@34:c2bc9f9be7ff, 2015-02-13 (annotated)
- Committer:
- maximbolduc
- Date:
- Fri Feb 13 17:22:53 2015 +0000
- Revision:
- 34:c2bc9f9be7ff
working version
Who changed what in which revision?
| User | Revision | Line number | New 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 | 34:c2bc9f9be7ff | 8 | for (XOR = 0, i = 0; i < strlen(string); i++) |
| maximbolduc | 34:c2bc9f9be7ff | 9 | { |
| maximbolduc | 34:c2bc9f9be7ff | 10 | c = (unsigned char)string[i]; |
| maximbolduc | 34:c2bc9f9be7ff | 11 | if ( c == '$' )started = true; |
| maximbolduc | 34:c2bc9f9be7ff | 12 | |
| maximbolduc | 34:c2bc9f9be7ff | 13 | if ( started == true ) |
| maximbolduc | 34:c2bc9f9be7ff | 14 | { |
| maximbolduc | 34:c2bc9f9be7ff | 15 | if (c == '*') |
| maximbolduc | 34:c2bc9f9be7ff | 16 | { |
| maximbolduc | 34:c2bc9f9be7ff | 17 | break; |
| maximbolduc | 34:c2bc9f9be7ff | 18 | } |
| maximbolduc | 34:c2bc9f9be7ff | 19 | if (c != '$') XOR ^= c; |
| maximbolduc | 34:c2bc9f9be7ff | 20 | } |
| maximbolduc | 34:c2bc9f9be7ff | 21 | } |
| maximbolduc | 34:c2bc9f9be7ff | 22 | return XOR; |
| maximbolduc | 34:c2bc9f9be7ff | 23 | } |
| maximbolduc | 34:c2bc9f9be7ff | 24 | |
| maximbolduc | 34:c2bc9f9be7ff | 25 | bool validate_checksum(char* validating) |
| maximbolduc | 34:c2bc9f9be7ff | 26 | { |
| maximbolduc | 34:c2bc9f9be7ff | 27 | bool valid = false; |
| maximbolduc | 34:c2bc9f9be7ff | 28 | int tempo = getCheckSum(validating); |
| maximbolduc | 34:c2bc9f9be7ff | 29 | string token, mystring(validating); |
| maximbolduc | 34:c2bc9f9be7ff | 30 | while(token != mystring) |
| maximbolduc | 34:c2bc9f9be7ff | 31 | { |
| maximbolduc | 34:c2bc9f9be7ff | 32 | token = mystring.substr(0,mystring.find_first_of("*")); |
| maximbolduc | 34:c2bc9f9be7ff | 33 | mystring = mystring.substr(mystring.find_first_of("*") + 1,2); |
| maximbolduc | 34:c2bc9f9be7ff | 34 | } |
| maximbolduc | 34:c2bc9f9be7ff | 35 | int checksumm = atoh <uint16_t>(token.c_str()); |
| maximbolduc | 34:c2bc9f9be7ff | 36 | if (tempo == checksumm) |
| maximbolduc | 34:c2bc9f9be7ff | 37 | { |
| maximbolduc | 34:c2bc9f9be7ff | 38 | valid = true; |
| maximbolduc | 34:c2bc9f9be7ff | 39 | } |
| maximbolduc | 34:c2bc9f9be7ff | 40 | return valid; |
| maximbolduc | 34:c2bc9f9be7ff | 41 | } |
