TELECOMMAND MANAGER V1
Dependencies: mbed SLCD mbed-rtos
crc.h
- Committer:
- shreeshas95
- Date:
- 2015-06-06
- Revision:
- 1:df31097c8442
- Parent:
- 0:b5b370873460
- Child:
- 2:994e741028c7
File content as of revision 1:df31097c8442:
#define WIDTH 16 #define TOPBIT (1 << 15) #define POLYNOMIAL 0x1021 namespace CRC{ typedef uint16_t crctype; crctype crcGenerate(const unsigned char message[], int nBytes){ crctype remainder = 0xffff; int byte; char bit; for( byte = 0 ; byte < nBytes ; byte++ ){ /* Bring the data byte by byte each time only one byte is brought 0 xor x = x */ remainder = remainder ^ ( message[byte] << (WIDTH-8) ); for( bit = 8 ; bit > 0 ; bit--){ /* for each bit, xor the remainder with polynomial if the MSB is 1 */ if(remainder & TOPBIT){ remainder = (remainder << 1) ^ POLYNOMIAL; /* each time the remainder is xor-ed with polynomial, the MSB is made zero hence the first digit of the remainder is ignored in the loop */ } else{ remainder = (remainder << 1); } } } return remainder; } };