/** Sample ALOE component implementation file Specific module code */ /** Include general data type library */ #include "typetools.h" #include "itf_types.h" /** GLOBAL DEFINEs*/ #define L_MAX 50000000 #define MAXNUM_ERRORS 1000 #define BITSPERCHAR 8 /*GLOBAL VARIABLES & BUFFERS*/ int value; unsigned char frase[L_MAX]; int filelength=0; /** USER DEFINED FUCNTIONS*/ /** INITIALIZATION USER ROUTINES*/ void init_my_prog() { filelength=lee_archivo("data/rfc793.txt",frase,L_MAX); /*Read the file*/ printf("gen_SINKr1.init_my_prog(): file rfc793.txt readed\n"); printf("gen_SINKr1.init_my_prog(): filelength=%d \n", filelength); } /** Module function generic format * Returns the output length or -1 if error */ int my_prog(void *pdatain, void *pdataout,\ int processingtypeIN, int processingtypeOUT,\ int inputlength, ControlMODULENAME_h myctrl) { int i; float *input_f, *output_f; char *input_c, *output_c; int *input_i, *output_i; short *input_s, *output_s; int outputlength=0; /**Properly typecast your input data pointer and check the input data type*/ if(processingtypeIN==TYPE_BITSTREAM)input_c=(unsigned char *)pdatain; else { printf("gen_SINKr1.my_prog(): ERROR INPUT DATA TYPE NON VALID\n"); return(-1); } if(processingtypeOUT==TYPE_BITSTREAM)output_f=(char *)pdataout; else { printf("gen_SINKr1.my_prog(): ERROR OUTPUT DATA TYPE NON VALID\n"); return(-1); } //*YOUR CODE*/ if(processingtypeIN==TYPE_BITSTREAM)inputlength=inputlength/BITSPERCHAR; compare_data(input_c, frase, inputlength, filelength); outputlength=0; /** NO DATA MUST BE SENT*/ return(outputlength); } //Compare_data: Compare the received data with the original one. //When length of data received is equal to the file length outputs the BER int compare_data(unsigned char *data_in,\ unsigned char *file,\ int numchars, int file_length){ static int p=0, onlyone=0; static int numbitserror=0; unsigned char byte; int i, n, length; //Read data from file for (i=0; i>1; } } p++; } } if((p>=file_length) || (numbitserror>MAXNUM_ERRORS)){ if(onlyone==0){ printf("gen_SINKr1 bits_sent=%d filelength=%d numbitserror=%d\n",\ p*8, file_length*8, numbitserror); printf("FILE RECEIVED: BER=%f\n",\ (float)numbitserror/(float)(p*8)); p++; onlyone=1; } return(-1); } printf("p=%d,file_length=%d \n",p, file_length); return(1); }