##// END OF EJS Templates
minor updates in tmstatistics.cpp
minor updates in tmstatistics.cpp

File last commit:

r69:d8815b251eb0 default
r73:b66d3d3bbd08 default
Show More
paulcommoncrc.cpp
60 lines | 1.4 KiB | text/x-c | CppLexer
#include "paulcommoncrc.h"
PaulCommonCRC::PaulCommonCRC(QObject *parent) :
QObject(parent)
{
initLookUpTableForCRC();
}
void PaulCommonCRC::initLookUpTableForCRC( void )
{
unsigned int i;
unsigned int tmp;
for (i=0; i<256; i++)
{
tmp = 0;
if((i & 1) != 0) {
tmp = tmp ^ 0x1021;
}
if((i & 2) != 0) {
tmp = tmp ^ 0x2042;
}
if((i & 4) != 0) {
tmp = tmp ^ 0x4084;
}
if((i & 8) != 0) {
tmp = tmp ^ 0x8108;
}
if((i & 16) != 0) {
tmp = tmp ^ 0x1231;
}
if((i & 32) != 0) {
tmp = tmp ^ 0x2462;
}
if((i & 64) != 0) {
tmp = tmp ^ 0x48c4;
}
if((i & 128) != 0) {
tmp = tmp ^ 0x9188;
}
lookUpTableForCRC[i] = tmp;
}
}
void PaulCommonCRC::GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
{
unsigned int Chk;
unsigned int j;
Chk = 0xffff; // reset the syndrom to all ones
for (j=0; j<sizeOfData; j++) {
Chk = Crc_opt(data[j], Chk);
}
crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
}
unsigned int PaulCommonCRC::Crc_opt( unsigned char D, unsigned int Chk)
{
return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
}