00001
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include "sportident.h"
00027 #define POLYNOM 0x8005
00028
00037 unsigned int SiCrc (unsigned int len, const unsigned char * data)
00038 {
00039 short int i,j;
00040 unsigned short int crc,crc_helper,temp;
00041
00042 if (len < 2) return(0);
00043
00044 crc = *data++;
00045 crc = (crc<<8) + *data++;
00046
00047 if (len == 2) return(crc);
00048 for (i=(int)(len>>1);i>0;i--){
00049
00050 if (i>1){
00051 crc_helper = *data++;
00052 crc_helper= (crc_helper<<8) + *data++;
00053 }else{
00054 if (len&1){
00055 crc_helper = *data;
00056 crc_helper= (crc_helper<<8);
00057 } else {
00058 crc_helper=0;
00059 }
00060 }
00061
00062 for (j=0;j<16;j++){
00063 temp=(crc &0x8000)?POLYNOM:0x0;
00064 crc <<= 1;
00065 if (crc_helper & 0x8000)crc++;
00066 crc ^= temp;
00067
00068 crc_helper <<= 1;
00069 }
00070 }
00071 return(crc);
00072 }