Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

LOW_helper_crc.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_helper_crc.cpp  -  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 #include "LOW_helper_crc.h"
00019 
00020 
00021 //=====================================================================================
00022 //
00023 // constants
00024 //
00025 
00026 const uint8_t LOW_helper_CRC::crc8Table[256] = {
00027      0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
00028    157,195, 33,127,252,162, 64, 30, 95,  1,227,189, 62, 96,130,220,
00029     35,125,159,193, 66, 28,254,160,225,191, 93,  3,128,222, 60, 98,
00030    190,224,  2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
00031     70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89,  7,
00032    219,133,103, 57,186,228,  6, 88, 25, 71,165,251,120, 38,196,154,
00033    101, 59,217,135,  4, 90,184,230,167,249, 27, 69,198,152,122, 36,
00034    248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91,  5,231,185,
00035    140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
00036     17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
00037    175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
00038     50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
00039    202,148,118, 40,171,245, 23, 73,  8, 86,180,234,105, 55,213,139,
00040     87,  9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
00041    233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
00042    116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53,
00043 };
00044 
00045 const uint16_t LOW_helper_CRC::crc16Table[256] = {
00046     0x0000,  0xc0c1,  0xc181,  0x0140,  0xc301,  0x03c0,  0x0280,  0xc241,
00047     0xc601,  0x06c0,  0x0780,  0xc741,  0x0500,  0xc5c1,  0xc481,  0x0440,
00048     0xcc01,  0x0cc0,  0x0d80,  0xcd41,  0x0f00,  0xcfc1,  0xce81,  0x0e40,
00049     0x0a00,  0xcac1,  0xcb81,  0x0b40,  0xc901,  0x09c0,  0x0880,  0xc841,
00050     0xd801,  0x18c0,  0x1980,  0xd941,  0x1b00,  0xdbc1,  0xda81,  0x1a40,
00051     0x1e00,  0xdec1,  0xdf81,  0x1f40,  0xdd01,  0x1dc0,  0x1c80,  0xdc41,
00052     0x1400,  0xd4c1,  0xd581,  0x1540,  0xd701,  0x17c0,  0x1680,  0xd641,
00053     0xd201,  0x12c0,  0x1380,  0xd341,  0x1100,  0xd1c1,  0xd081,  0x1040,
00054     0xf001,  0x30c0,  0x3180,  0xf141,  0x3300,  0xf3c1,  0xf281,  0x3240,
00055     0x3600,  0xf6c1,  0xf781,  0x3740,  0xf501,  0x35c0,  0x3480,  0xf441,
00056     0x3c00,  0xfcc1,  0xfd81,  0x3d40,  0xff01,  0x3fc0,  0x3e80,  0xfe41,
00057     0xfa01,  0x3ac0,  0x3b80,  0xfb41,  0x3900,  0xf9c1,  0xf881,  0x3840,
00058     0x2800,  0xe8c1,  0xe981,  0x2940,  0xeb01,  0x2bc0,  0x2a80,  0xea41,
00059     0xee01,  0x2ec0,  0x2f80,  0xef41,  0x2d00,  0xedc1,  0xec81,  0x2c40,
00060     0xe401,  0x24c0,  0x2580,  0xe541,  0x2700,  0xe7c1,  0xe681,  0x2640,
00061     0x2200,  0xe2c1,  0xe381,  0x2340,  0xe101,  0x21c0,  0x2080,  0xe041,
00062     0xa001,  0x60c0,  0x6180,  0xa141,  0x6300,  0xa3c1,  0xa281,  0x6240,
00063     0x6600,  0xa6c1,  0xa781,  0x6740,  0xa501,  0x65c0,  0x6480,  0xa441,
00064     0x6c00,  0xacc1,  0xad81,  0x6d40,  0xaf01,  0x6fc0,  0x6e80,  0xae41,
00065     0xaa01,  0x6ac0,  0x6b80,  0xab41,  0x6900,  0xa9c1,  0xa881,  0x6840,
00066     0x7800,  0xb8c1,  0xb981,  0x7940,  0xbb01,  0x7bc0,  0x7a80,  0xba41,
00067     0xbe01,  0x7ec0,  0x7f80,  0xbf41,  0x7d00,  0xbdc1,  0xbc81,  0x7c40,
00068     0xb401,  0x74c0,  0x7580,  0xb541,  0x7700,  0xb7c1,  0xb681,  0x7640,
00069     0x7200,  0xb2c1,  0xb381,  0x7340,  0xb101,  0x71c0,  0x7080,  0xb041,
00070     0x5000,  0x90c1,  0x9181,  0x5140,  0x9301,  0x53c0,  0x5280,  0x9241,
00071     0x9601,  0x56c0,  0x5780,  0x9741,  0x5500,  0x95c1,  0x9481,  0x5440,
00072     0x9c01,  0x5cc0,  0x5d80,  0x9d41,  0x5f00,  0x9fc1,  0x9e81,  0x5e40,
00073     0x5a00,  0x9ac1,  0x9b81,  0x5b40,  0x9901,  0x59c0,  0x5880,  0x9841,
00074     0x8801,  0x48c0,  0x4980,  0x8941,  0x4b00,  0x8bc1,  0x8a81,  0x4a40,
00075     0x4e00,  0x8ec1,  0x8f81,  0x4f40,  0x8d01,  0x4dc0,  0x4c80,  0x8c41,
00076     0x4400,  0x84c1,  0x8581,  0x4540,  0x8701,  0x47c0,  0x4680,  0x8641,
00077     0x8201,  0x42c0,  0x4380,  0x8341,  0x4100,  0x81c1,  0x8081,  0x4040
00078 };
00079 
00080 
00081 //=====================================================================================
00082 //
00083 // static methods
00084 //
00085 
00086 const uint8_t LOW_helper_CRC::calcCRC8( const uint8_t *inBuf, const unsigned int inLen, const uint8_t inPreloadCRC)
00087 { 
00088   uint8_t crc = inPreloadCRC;
00089    
00090   for( unsigned int a=0; a<inLen; a++)
00091     crc = crc8Table[ crc ^ *inBuf++ ];  
00092     
00093   return crc;
00094 }
00095 
00096 
00097 const uint8_t LOW_helper_CRC::calcCRC8( const byteVec_t &inVec, const uint8_t inPreloadCRC)
00098 {
00099   uint8_t crc = inPreloadCRC;
00100    
00101   for( unsigned int a=0; a<inVec.size(); a++)
00102     crc = crc8Table[ crc ^ inVec[a] ];
00103     
00104   return crc;
00105 }
00106 
00107 
00108 const uint16_t LOW_helper_CRC::calcCRC16( const uint8_t *inBuf, const unsigned int inLen, const uint16_t inPreloadCRC)
00109 {
00110   uint16_t crc = inPreloadCRC;
00111 
00112   for( unsigned int a=0; a<inLen; a++)
00113     crc = crc16Table[ (crc ^ *inBuf++) & 0xff ] ^ (crc>>8);
00114     
00115   return crc;
00116 }
00117 
00118 
00119 const uint16_t LOW_helper_CRC::calcCRC16( const byteVec_t &inVec, const uint16_t inPreloadCRC)
00120 {
00121   uint16_t crc = inPreloadCRC;
00122 
00123   for( unsigned int a=0; a<inVec.size(); a++)
00124     crc = crc16Table[ (crc ^ inVec[a]) & 0xff ] ^ (crc>>8);
00125 
00126   return crc;
00127 }

Generated on Sun Jan 12 21:07:43 2003 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001