uyvli

Dependents:   theRobot3

Fork of PololuQik2 by Thomas Ashworth

Committer:
Fairy_Paolina
Date:
Sat Apr 12 20:25:58 2014 +0000
Revision:
4:33ca85c52dc0
Parent:
0:511d65ef1276
modified;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
srsmitherman 0:511d65ef1276 1 /**
srsmitherman 0:511d65ef1276 2 * @file CRC7.h
srsmitherman 0:511d65ef1276 3 * @author Edward Wilson (edwilson1989@gmail.com)
srsmitherman 0:511d65ef1276 4 * @date Dec 16, 2010
srsmitherman 0:511d65ef1276 5 * @brief Cyclic Redundancy Check Class. This class computes a CRC7 of the provided data.
srsmitherman 0:511d65ef1276 6 *
srsmitherman 0:511d65ef1276 7 *
srsmitherman 0:511d65ef1276 8 */
srsmitherman 0:511d65ef1276 9
srsmitherman 0:511d65ef1276 10 #ifndef CRC7_H_
srsmitherman 0:511d65ef1276 11 #define CRC7_H_
srsmitherman 0:511d65ef1276 12
srsmitherman 0:511d65ef1276 13 #define CRC7_POLY 0x91 /**< The Chosen Polynomial for CRC7. This is a standard value */
srsmitherman 0:511d65ef1276 14
srsmitherman 0:511d65ef1276 15
srsmitherman 0:511d65ef1276 16 /**
srsmitherman 0:511d65ef1276 17 * This is a CRC7 implementation for checking validity of messages. It will compute
srsmitherman 0:511d65ef1276 18 * a checksum which can be used to determine if a message has been recieved unaltered.
srsmitherman 0:511d65ef1276 19 * This is used particularly over wireless tranmission or noisy serial lines.
srsmitherman 0:511d65ef1276 20 *
srsmitherman 0:511d65ef1276 21 * This implements a stored CRC table. This will taken up 256 bytes of RAM when the object
srsmitherman 0:511d65ef1276 22 * is instantiated. The reason for using a stored CRC table is speed. This is a compromise
srsmitherman 0:511d65ef1276 23 * between speed and storage spaces.
srsmitherman 0:511d65ef1276 24 *
srsmitherman 0:511d65ef1276 25 * This could possibly be static object.
srsmitherman 0:511d65ef1276 26 */
srsmitherman 0:511d65ef1276 27 class CRC7
srsmitherman 0:511d65ef1276 28 {
srsmitherman 0:511d65ef1276 29 public:
srsmitherman 0:511d65ef1276 30 /**
srsmitherman 0:511d65ef1276 31 * Default constructor. This method sets up the CRC table with pre-hashed values.
srsmitherman 0:511d65ef1276 32 */
srsmitherman 0:511d65ef1276 33 CRC7();
srsmitherman 0:511d65ef1276 34 /**
srsmitherman 0:511d65ef1276 35 * this method will generate the CRC7 checksum for the supplied message. It will be returned
srsmitherman 0:511d65ef1276 36 * from this method.
srsmitherman 0:511d65ef1276 37 *
srsmitherman 0:511d65ef1276 38 * @param message[] the message to be hashed.
srsmitherman 0:511d65ef1276 39 * @param length the length of the message to be hashed in characters.
srsmitherman 0:511d65ef1276 40 * @return the checksum computed.
srsmitherman 0:511d65ef1276 41 */
srsmitherman 0:511d65ef1276 42 unsigned char CRC(unsigned char message[], unsigned int length);
srsmitherman 0:511d65ef1276 43
srsmitherman 0:511d65ef1276 44 private:
srsmitherman 0:511d65ef1276 45 /**
srsmitherman 0:511d65ef1276 46 * Used to retrieve the value from the CRCTable.
srsmitherman 0:511d65ef1276 47 *
srsmitherman 0:511d65ef1276 48 * @see GenerateCRCTable()
srsmitherman 0:511d65ef1276 49 * @param val the character which the hash is required for.
srsmitherman 0:511d65ef1276 50 * @return the precomputed hash.
srsmitherman 0:511d65ef1276 51 */
srsmitherman 0:511d65ef1276 52 unsigned char GetCRC(unsigned char val);
srsmitherman 0:511d65ef1276 53 /**
srsmitherman 0:511d65ef1276 54 * Generates the CRC table which is used for lookups during operation.
srsmitherman 0:511d65ef1276 55 * This method is faster than having to compute the hash code each time
srsmitherman 0:511d65ef1276 56 * however it comes at a cost of using up valuable RAM.
srsmitherman 0:511d65ef1276 57 */
srsmitherman 0:511d65ef1276 58 void GenerateCRCTable();
srsmitherman 0:511d65ef1276 59
srsmitherman 0:511d65ef1276 60 /**
srsmitherman 0:511d65ef1276 61 * The array of characters which stores the precomputed hash codes.
srsmitherman 0:511d65ef1276 62 */
srsmitherman 0:511d65ef1276 63 unsigned char CRCTable[256];
srsmitherman 0:511d65ef1276 64 };
srsmitherman 0:511d65ef1276 65
srsmitherman 0:511d65ef1276 66 #endif /* CRC7_H_ */