00001 /*************************************************************************** 00002 LOW_helper_crc.h - description 00003 ------------------- 00004 begin : Sat Jul 6 2002 00005 copyright : (C) 2002 by Harald Roelle, Helmut Reiser 00006 email : roelle@informatik.uni-muenchen.de, reiser@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_HELPER_CRC_H 00019 #define LOW_HELPER_CRC_H 00020 00021 00022 00023 #include "LOW_types.h" 00024 #include "LOW_exception.h" 00025 00026 00027 /** Static functions for CRC calculation. 00028 00029 @author Harald Roelle, Helmut Reiser 00030 */ 00031 class LOW_helper_CRC { 00032 00033 //======================================================================================= 00034 public: 00035 00036 //===================================================================================== 00037 // 00038 // exceptions 00039 // 00040 00041 /** Exception base class to indicate CRC errors. */ 00042 class_DERIVE_FROM_EXCEPTION( crc_error, LOW_exception); 00043 00044 00045 //===================================================================================== 00046 // 00047 // static methods 00048 // 00049 00050 /** Calculate 8 bit CRC from piece of memory. 00051 @param inBuf Pointer to memoty segment. 00052 @param inLen Length of memory segment. 00053 @param inPreloadCRC Initial CRC value. 00054 */ 00055 static const uint8_t calcCRC8( const uint8_t *inBuf, const unsigned int inLen, const uint8_t inPreloadCRC = 0); 00056 00057 /** Calculate 8 bit CRC from byte vector. 00058 @param inVec Reference to byte vector. 00059 @param inPreloadCRC Initial CRC value. 00060 */ 00061 static const uint8_t calcCRC8( const byteVec_t &inVec, const uint8_t inPreloadCRC = 0); 00062 00063 00064 /** Calculate 16 bit CRC from piece of memory. 00065 @param inBuf Pointer to memoty segment. 00066 @param inLen Length of memory segment. 00067 @param inPreloadCRC Initial CRC value. 00068 */ 00069 static const uint16_t calcCRC16( const uint8_t *inBuf, const unsigned int inLen, const uint16_t inPreloadCRC = 0); 00070 00071 /** Calculate 16 bit CRC from byte vector. 00072 @param inVec Reference to byte vector. 00073 @param inPreloadCRC Initial CRC value. 00074 */ 00075 static const uint16_t calcCRC16( const byteVec_t &inVec, const uint16_t inPreloadCRC = 0); 00076 00077 00078 //======================================================================================= 00079 private: 00080 00081 //===================================================================================== 00082 // 00083 // constants 00084 // 00085 00086 static const uint8_t crc8Table[256]; /**< Preinitialize CRC-8 table. */ 00087 static const uint16_t crc16Table[256]; /**< Preinitialize CRC-16 table. */ 00088 00089 }; 00090 00091 #endif