Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

hyperblkcodec.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include "hyperblkcodec.h"
00010 
00011 #include <gf256.h>
00012 #include <rsff-f9.h>
00013 
00014 const int gfblklen=blklen*sizeof(char)/sizeof(GF256);
00015 
00019 void hyperblockprotect(const char* blks, char* protblks)
00020 {
00021   const GF256* gblks=(const GF256*) blks;
00022   GF256* gprot=(GF256*) protblks;
00023 
00024   GF256 data[249], parity[6];
00025   int i,n;
00026   for (i=0; i<249; ++i) data[i]=0;
00027   for (i=0; i<6; ++i) parity[i]=0;
00028 
00029   for (n=0; n<gfblklen; ++n) { // for each stripe
00030     for (i=0; i<hblen; ++i) data[i] = gblks[n+gfblklen*i];
00031     rs255_249_encode(data,parity);
00032     // if (n==0) P(data);
00033     // if (n==0) P(parity);    
00034     for (i=0; i<hbcorr; ++i) gprot[n+gfblklen*i] = parity[i];
00035   }
00036 }
00037 
00040 template <class T> void setifchanged(T& dst, const T& src)
00041 {
00042   if (src != dst) dst = src;
00043 }
00044 
00049 bool hyperblockcorrect(char* blks, const char* protblks)
00050 {
00051   GF256* gblks=(GF256*) blks;
00052   const GF256* gprot=(const GF256*) protblks;
00053 
00054   GF256 received[255];
00055   int i,n, maxerrcorrected=0;
00056   for (i=0; i<255; ++i) received[i]=0;
00057 
00058   for (n=0; n<gfblklen; ++n) { // for each stripe
00059     for (i=0; i<hblen; ++i) received[i] = gblks[n+gfblklen*i];
00060     for (i=0; i<hbcorr; ++i) received[i+249] = gprot[n+gfblklen*i];
00061     // if (n==0) P(received);
00062     int status = rs255_249_decode(received);
00063     if (RS255_249_E4 == status) return false;
00064     int errcorrected = rs255_249_number_of_errors(status);
00065     if ( 0 < errcorrected ) {
00066       for (i=0; i<hblen; ++i) setifchanged(gblks[n+gfblklen*i],received[i]);
00067       if ( maxerrcorrected < errcorrected ) maxerrcorrected = errcorrected;
00068     }
00069   }
00070   return true;
00071 }
00072 
00074 void checkErrorProtection()
00075 {
00076   char in[hblen*blklen+1]; in[hblen*blklen]=0;
00077   char prot[hbcorr*blklen+1]; prot[hbcorr*blklen]=0;
00078   int i;
00079   for (i=0; i<hblen*blklen; ++i) in[i]='a'+(i%23);
00080   for (i=0; i<hbcorr*blklen; ++i) prot[i]='z';
00081   P(in);
00082   // P(prot);
00083   hyperblockprotect(in,prot);
00084   // P(in);
00085   P(prot);
00086   in[3]='z'; in[22]='y';
00087   P(in);
00088   P(hyperblockcorrect(in,prot));
00089   P(in);
00090   // P(prot);  
00091 }
00092 

Generated on Tue Dec 30 12:07:35 2003 for ErrorProtect by doxygen 1.3.2