crc.h
Go to the documentation of this file.
00001 //======================================================================
00029 //======================================================================
00030 
00031 #ifndef CRC_h_
00032 #define CRC_h_
00033 
00034 #include "sdhlibrary_settings.h"
00035 
00036 //----------------------------------------------------------------------
00037 // System Includes - include with <>
00038 //----------------------------------------------------------------------
00039 
00040 
00041 //----------------------------------------------------------------------
00042 // Project Includes - include with ""
00043 //----------------------------------------------------------------------
00044 
00045 #include "basisdef.h"
00046 
00047 //----------------------------------------------------------------------
00048 // Defines, enums, unions, structs
00049 //----------------------------------------------------------------------
00050 
00051 NAMESPACE_SDH_START
00052 
00053 
00054 typedef UInt16 tCRCValue;   
00055 
00056 //----------------------------------------------------------------------
00057 // Global variables (declarations)
00058 //----------------------------------------------------------------------
00059 
00060 
00061 //----------------------------------------------------------------------
00062 // External functions (function declarations)
00063 //----------------------------------------------------------------------
00064 
00065 
00066 //----------------------------------------------------------------------
00067 // Function prototypes (function declarations)
00068 //----------------------------------------------------------------------
00069 
00070 
00071 //----------------------------------------------------------------------
00072 // Class declarations
00073 //----------------------------------------------------------------------
00074 
00082 class VCC_EXPORT cCRC
00083 {
00084  protected:
00086     tCRCValue current_crc;
00087 
00089     tCRCValue initial_value;
00090 
00092     tCRCValue const* crc_table;
00093 
00094  public:
00096     cCRC( tCRCValue const* _crc_table, tCRCValue _initial_value )
00097     {
00098         crc_table     = _crc_table;
00099         initial_value = _initial_value;
00100         current_crc   = initial_value;
00101     }
00102 
00104     tCRCValue AddByte( unsigned char byte )
00105     {
00106         current_crc = ( (current_crc & 0xFF00) >> 8 ) ^ crc_table[ ( current_crc & 0x00FF ) ^ (byte & 0x00FF)];
00107         return current_crc;
00108     }
00109 
00111     tCRCValue AddBytes( unsigned char* bytes, int nb_bytes )
00112     {
00113         for ( int i=0; i<nb_bytes; i++ )
00114             current_crc = ( (current_crc & 0xFF00) >> 8 ) ^ crc_table[ ( current_crc & 0x00FF ) ^ (bytes[i] & 0x00FF)];
00115         return current_crc;
00116     }
00117 
00119     inline tCRCValue GetCRC()
00120     {
00121         return current_crc;
00122     }
00123 
00125     inline UInt8 GetCRC_LB()
00126     {
00127         return current_crc & 0x00ff;
00128     }
00129 
00131     inline UInt8 GetCRC_HB()
00132     {
00133         return (current_crc >> 8) & 0x00ff;
00134     }
00135 
00137     inline tCRCValue Reset()
00138     {
00139         current_crc = initial_value;
00140         return current_crc;
00141     }
00142 };
00143 //----------------------------------------------------------------------
00144 //----------------------------------------------------------------------
00145 
00147 class VCC_EXPORT cCRC_DSACON32m : public cCRC
00148 {
00149  protected:
00151     static tCRCValue const crc_table_dsacon32m[256];
00152 
00153  public:
00155     inline cCRC_DSACON32m( void )
00156         : cCRC( crc_table_dsacon32m, 0xffff )
00157     {
00158         // nothing more to do
00159     }
00160 };
00161 //----------------------------------------------------------------------
00162 //----------------------------------------------------------------------
00163 
00170 class VCC_EXPORT cCRC_SDH : public cCRC_DSACON32m
00171 {
00172  public:
00174     inline cCRC_SDH( void )
00175         : cCRC_DSACON32m()
00176     {
00177         // nothing more to do
00178     }
00179 };
00180 //----------------------------------------------------------------------
00181 //----------------------------------------------------------------------
00182 
00183 NAMESPACE_SDH_END
00184 
00185 #endif
00186 
00187 
00188 //======================================================================
00189 /*
00190   Here are some settings for the emacs/xemacs editor (and can be safely ignored):
00191   (e.g. to explicitely set C++ mode for *.h header files)
00192 
00193   Local Variables:
00194   mode:C
00195   mode:ELSE
00196   End:
00197 */
00198 //======================================================================}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


schunk_sdh
Author(s): Florian Weisshardt
autogenerated on Tue Mar 5 2013 14:44:11