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.
Fork of PololuQik2 by
CRC7.cpp
00001 /** 00002 * @file CRC7.cpp 00003 * @author Edward Wilson (edwilson1989@gmail.com) 00004 * @date Dec 16, 2010 00005 * @brief The CRC7 checksum code. 00006 * 00007 * 00008 */ 00009 00010 #include "CRC7.h" 00011 00012 CRC7::CRC7() 00013 { 00014 GenerateCRCTable(); 00015 00016 } 00017 00018 unsigned char CRC7::GetCRC(unsigned char val) 00019 { 00020 int j; 00021 for (j = 0; j < 8; j++) { 00022 if (val & 1) 00023 val ^= CRC7_POLY; 00024 val >>= 1; 00025 } 00026 return val; 00027 } 00028 00029 unsigned char CRC7::CRC(unsigned char message[], unsigned int length) 00030 { 00031 unsigned char i, crc = 0; 00032 00033 for (i = 0; i < length; i++) 00034 crc = CRCTable[crc ^ message[i]]; 00035 return crc; 00036 } 00037 00038 void CRC7::GenerateCRCTable() 00039 { 00040 int i; 00041 // generate a table value for all 256 possible byte values 00042 for (i = 0; i < 256; i++) { 00043 CRCTable[i] = GetCRC(i); 00044 } 00045 } 00046
Generated on Fri Jul 15 2022 23:53:36 by
