UH Robotics / PololuQik2

Dependents:   theRobot3

Fork of PololuQik2 by Thomas Ashworth

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CRC7.h Source File

CRC7.h

Go to the documentation of this file.
00001 /**
00002  *  @file       CRC7.h
00003  *  @author     Edward Wilson (edwilson1989@gmail.com)
00004  *  @date       Dec 16, 2010
00005  *  @brief      Cyclic Redundancy Check Class. This class computes a CRC7 of the provided data.
00006  *
00007  *
00008  */
00009 
00010 #ifndef CRC7_H_
00011 #define CRC7_H_
00012 
00013 #define CRC7_POLY 0x91 /**< The Chosen Polynomial for CRC7. This is a standard value */
00014 
00015 
00016 /**
00017  * This is a CRC7 implementation for checking validity of messages. It will compute
00018  * a checksum which can be used to determine if a message has been recieved unaltered.
00019  * This is used particularly over wireless tranmission or noisy serial lines.
00020  *
00021  * This implements a stored CRC table. This will taken up 256 bytes of RAM when the object
00022  * is instantiated. The reason for using a stored CRC table is speed. This is a compromise
00023  * between speed and storage spaces.
00024  *
00025  * This could possibly be static object.
00026  */
00027 class CRC7
00028 {
00029 public:
00030     /**
00031      * Default constructor. This method sets up the CRC table with pre-hashed values.
00032      */
00033     CRC7();
00034     /**
00035      * this method will generate the CRC7 checksum for the supplied message. It will be returned
00036      * from this method.
00037      *
00038      * @param message[] the message to be hashed.
00039      * @param length the length of the message to be hashed in characters.
00040      * @return the checksum computed.
00041      */
00042     unsigned char CRC(unsigned char message[], unsigned int length);
00043 
00044 private:
00045     /**
00046      * Used to retrieve the value from the CRCTable.
00047      *
00048      * @see GenerateCRCTable()
00049      * @param val the character which the hash is required for.
00050      * @return the precomputed hash.
00051      */
00052     unsigned char GetCRC(unsigned char val);
00053     /**
00054      * Generates the CRC table which is used for lookups during operation.
00055      * This method is faster than having to compute the hash code each time
00056      * however it comes at a cost of using up valuable RAM.
00057      */
00058     void GenerateCRCTable();
00059 
00060     /**
00061      * The array of characters which stores the precomputed hash codes.
00062      */
00063     unsigned char CRCTable[256];
00064 };
00065 
00066 #endif /* CRC7_H_ */