Main Page | Class List | File List | Class Members | File Members

crc.c File Reference

#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define UCHAR   unsigned char

Functions

void fwdccitthware (UCHAR data, UCHAR *accum)
void MakeCRCBytes (unsigned char *in, int info_dim, int CRC_dim)
int CheckCRC (UCHAR *out_byte, int info_dim, int CRC_dim)


Define Documentation

#define UCHAR   unsigned char
 

Definition at line 1 of file crc.c.

Referenced by CheckCRC(), fwdccitthware(), and MakeCRCBytes().


Function Documentation

int CheckCRC UCHAR *  out_byte,
int  info_dim,
int  CRC_dim
 

Definition at line 58 of file crc.c.

References fwdccitthware(), and UCHAR.

00062 {
00063 
00064   int i, sum=0;
00065   UCHAR *crcbit;  
00066 
00067   crcbit = (UCHAR *) calloc(17, sizeof(UCHAR));
00068   if (crcbit == NULL) 
00069     printf("warning: CheckCRC calloc failed\n");
00070 
00071   for(i = 0; i <(info_dim+CRC_dim); i++)
00072     fwdccitthware(out_byte[i],crcbit);
00073   for(i = 0; i < 16; i++)
00074     sum += crcbit[i];
00075   
00076   
00077   /* printf("\n"); */
00078 
00079   free(crcbit);
00080   
00081   if(sum == 0) 
00082     return 1;
00083   else 
00084     return 0;
00085 }

void fwdccitthware UCHAR  data,
UCHAR *  accum
 

Definition at line 6 of file crc.c.

References data, and UCHAR.

Referenced by CheckCRC(), and MakeCRCBytes().

00009 {
00010   UCHAR i,j,tmp1,tmp2,tmp3;
00011   
00012   for(i=0;i<8;i++) {
00013     tmp1=((data<<i)&(0x80))/0x80;
00014     for(j=16;j>0;j--)
00015       accum[j]=accum[j-1];
00016     if ((tmp2=accum[16]^tmp1)==1)
00017       {
00018         accum[0]=tmp2;
00019         accum[5]=accum[5]^1;
00020         accum[12]=accum[12]^1;}
00021     else accum[0]=tmp2;
00022   }
00023 }

void MakeCRCBytes unsigned char *  in,
int  info_dim,
int  CRC_dim
 

Definition at line 25 of file crc.c.

References fwdccitthware(), and UCHAR.

00029 {
00030 
00031   int i;
00032   UCHAR *crcbit;  
00033 
00034   crcbit = (UCHAR *) calloc(17, sizeof(UCHAR));
00035   if (crcbit == NULL) 
00036     printf("warning: CheckCRC calloc failed\n");
00037 
00038   for(i = 0; i <info_dim; i++)
00039     fwdccitthware(in[i],crcbit);
00040   
00041 /*  for(i = 15; i >=0 ; i--)
00042     printf("%d", crcbit[i]);
00043   printf("\n");  */
00044 
00045   in[info_dim] = 0;
00046   in[info_dim+1] = 0;
00047   for(i = 7; i >= 0; i--){
00048     in[info_dim] = (in[info_dim] << 1) + crcbit[i+8];
00049     in[info_dim+1] = (in[info_dim+1] << 1) + crcbit[i];
00050   } 
00051   
00052   free(crcbit);
00053 
00054 /*  printf("%d %d\n", in[info_dim], in[info_dim+1]); */
00055 }


Generated on Sun Jul 16 16:27:45 2006 by  doxygen 1.3.9.1