/** ALOE headers */ #include #include #include #include "itf_types.h" #include "inputs.h" #include "outputs.h" #include "stats.h" /*GLOBAL DEFINES*/ #define L_MAX 50000000 #define DATA_FLOW_LENGTH 0 #define NUMBITSPERCHAR 8 /*GLOBAL VARIABLES*/ unsigned char frase[L_MAX]; int filelength=0; int timeSLOT=0; /*PREDEFINED FUNCTIONS*/ int compare_data(unsigned char *data_in, unsigned char *file, int numchars, int file_length); void Init_Controlfunction(); void Init_function(); ////////////////////////////////////////////////////////////////////////////////////////// //SQUELETON CALLED FUNCTIONS////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //CONTROL ////////////////////////////////////////////////////////////////////////CONTROL/ ////////////////////////////////////////////////////////////////////////////////////////// //CONTROL:INPUT/////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /*Returns the length(in control in type words) of the expected control flow at each time-slot*/ //Funtion activated if control flow has been received*/ /*Check INPUT_MAX_CONTROL*/ int get_controlin_length() { int length=1; length=control_length(); return(length); } /*Process the received control flow according to the length returned by get_controlin_length()*/ /*"len" indicates the number of control words to be processed*/ int process_inputcontrol(int len) { process_control_input(len); return(1); /*return 1 if OK; return 0 if error*/ } ////////////////////////////////////////////////////////////////////////////////////////// //CONTROL:OUTPUT////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /*Returns the length (in control out type words) of the generated control flow at each time-slot*/ /*Check OUTPUT_MAX_CONTROL*/ int get_controlout_length() { int length=1; length=0; //NO ADDITIONAL MODULES BEYOND bitLdatasink return(length); } /*Generate the control word to be send according the length provided by get_controlout_length()*/ /*"len" indicates the number of control words to be generated*/ int generate_outputcontrol(int len) { /*return 1 if OK; return 0 if error*/ return(1); } ////////////////////////////////////////////////////////////////////////////////////////// //DATA/////////////////////////////////////////////////////////////////////////////DATA/// ////////////////////////////////////////////////////////////////////////////////////////// //DATA:INPUT////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /*Returns the length(in data in type words) of the expected data flow at each time-slot*/ //Funtion activated only if data flow has been received*/ /*Check INPUT_MAX_DATA*/ int get_datain_length() { int length=1; length=datain_length(); return(length); } /*Process the received data flow according to the length returned by get_datain_length()*/ /** Run function. return 1 if ok, 0 if error*/ /*"len" indicates the number of data words to be processed*/ int process_inputdata(int len) { int ret=1; ret=process_datainflow(len); if(ret==-1)printf("ret=0\n"); return(ret); } ////////////////////////////////////////////////////////////////////////////////////////// //DATA/////////////////////////////////////////////////////////////////////////////DATA/// ////////////////////////////////////////////////////////////////////////////////////////// //DATA: OUTPUT//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /*Returns the length (in data out type words) of the generated data flow at each time-slot*/ int get_dataout_length() { int length=1; length=dataout_length(); return(length); } /*Generate the control word to be send according the length provided by get_controlout_length()*/ /** Run function. return 1 if ok, 0 if error*/ /*"len" indicates the number of data words to be generated*/ int generate_outputdata(int len) { return 1; } int InitCustom() { Init_Controlfunction(); Init_function(); timeSLOT=0; return 1; } int RunCustom() { timeSLOT++; return 1; } ////////////////////////////////////////////////////////////////////////////////////////// //END SQUELETON CALLED FUNCTIONS////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //######################################################################################// ////////////////////////////////////////////////////////////////////////////////////////// //ESPECIFIC MODULE FUNCTIONS////////////////////////////////////////////////////////////// //CONTROL////////////////////////////////////////////////////////////////////////CONTROL// ////////////////////////////////////////////////////////////////////////////////////////// /*Initializes control variables*/ void Init_Controlfunction() { C_datasink[0].CExec.status=NONACTIVE; C_datasink[0].CData.numdatabytes=0; } int control_length() { return(INPUT_MAX_CONTROL); } int process_control_input(int len) { static int done=0; if(done==0){ if(C_datasink[0].CExec.status==ACTIVE){ //printf("SINK: TSLOT%d, timeSLOT%d STATUS=%d\n",\ C_datasink[0].CExec.timeslot,\ timeSLOT,\ C_datasink[0].CExec.status); //done=1; } } if(len==1){ printf("O---->DATASINK (config): TSLOT%d, STATUS=%d\n",\ C_datasink[0].CExec.timeslot,\ C_datasink[0].CExec.status); printf("O NumInputbytes=%d,\n",\ C_datasink[0].CData.numdatabytes); } } ////////////////////////////////////////////////////////////////////////////////////////// //DATA//////////////////////////////////////////////////////////////////////////////DATA// ////////////////////////////////////////////////////////////////////////////////////////// #define DATA_FLOW_LENGTH 0 void Init_function() { filelength=lee_archivo("data/rfc793.txt",frase,L_MAX); /*Read the file*/ printf("SINK filelength=%d \n", filelength); //filelength=1024; } /*data_length(): Define the data flow length in each time-slot*/ int datain_length() { int length; if(C_datasink[0].CExec.status==NONACTIVE)length=0; if(C_datasink[0].CExec.status==ACTIVE)length=C_datasink[0].CData.numdatabytes; if(C_datasink[0].CExec.status==TEST_FLOW)length=C_datasink[0].CData.numdatabytes; if(C_datasink[0].CExec.status==TEST_PROCESS)length=C_datasink[0].CData.numdatabytes; //printf("SINK datain_length: numdatabytes=%d \n", C_datasink[0].CData.numdatabytes); //printf("SINK datain_length: status=%d \n", C_datasink[0].CExec.status); if(numinputbytes>0)length=numinputbytes; //printf("SINK datain_length: length=%d \n", length); return(length); } int process_datainflow(int len) { int i; if(C_datasink[0].CExec.status==ACTIVE) return(compare_data(input_data, frase, len, filelength)); //return(1); } int dataout_length() { int length; length=DATA_FLOW_LENGTH; return(length); } //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; static int numbitserror=0; static int one=0, one2; unsigned char byte; int i, n, length; //printf("SINK:compare_data; status=%d \n", C_datasink[0].CExec.status); if(C_datasink[0].CExec.status==NONACTIVE)return(1); //Read data from file if((p==file_length) || (numbitserror>200)){ if(one==0){ printf("SINK 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++; one=1; return(-1); } } for (i=0; i>1; } } p++; } } /* length=numchars; one2++; if(one2==1){ printf("DATASINK process_datainflow() INPUT length=%d\n", length); for(i=1; i<=(length); i++){ printf("% d", (unsigned char)data_in[i-1]); if(i%16 == 0)printf("\n"); } printf("\n"); } */ return(1); } ////////////////////////////////////////////////////////////////////////////////////////// //END OF ESPECIFIC MODULE FUNCTIONS/////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// void ConfigInterfaces() {}