//////////////////////////////////////////////////////////////////////////////// // // // Module: wimax_datasource // // // // FUNCTION: Generate data // // // // Description: Data source for Downlink WiMAX IEEE802.16e rel 2005 // // // // // // // //June 2009 // //////////////////////////////////////////////////////////////////////////////// /** ALOE headers */ #include #include #include #include "itf_types.h" #include "inputs.h" #include "outputs.h" #include "stats.h" #include "utils.h" #include "datasource_code.h" #include "CDataSource.h" /*GLOBAL VARIABLES*/ int filefinish=0; //filefinish=1 --> FILE SENT unsigned char frase[L_MAX]; int filelength=0; int Tslot=0; /*PREDEFINED FUNCTIONS*/ /*void Init_Controlfunction();*/ void Init_function(); ////////////////////////////////////////////////////////////////////////////////////////// //SQUELETON CALLED FUNCTIONS////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //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*/ } ////////////////////////////////////////////////////////////////////////////////////////// //OUTPUT////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //NO CONTROL OUTPUT// ////////////////////////////////////////////////////////////////////////////////////////// //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) { process_datainflow(len); return 1; } ////////////////////////////////////////////////////////////////////////////////////////// //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) { generate_dataflow(len); return 1; } int InitCustom() { Init_function(); return 1; } int RunCustom() { //printf("SOURCE:Tslot=%d status=%d\n", Tslot, output_control[0].CEx.status); Tslot++; return 1; } ////////////////////////////////////////////////////////////////////////////////////////// //END SQUELETON CALLED FUNCTIONS////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //######################################################################################// ////////////////////////////////////////////////////////////////////////////////////////// //ESPECIFIC MODULE FUNCTIONS////////////////////////////////////////////////////////////// //CONTROL////////////////////////////////////////////////////////////////////////CONTROL// ////////////////////////////////////////////////////////////////////////////////////////// int control_length() { return(INPUT_MAX_CONTROL); } int process_control_input(int len) { /*Process input control word */ if(len==1){ printf("O---->DATASOURCE (config): TSLOT%d, STATUS=%d\n",\ input_control[0].CExec.timeslot,\ input_control[0].CExec.status); printf("O NumOutputbytes=%d\n",\ input_control[0].CData.numdatabytes); } } ////////////////////////////////////////////////////////////////////////////////////////// //DATA//////////////////////////////////////////////////////////////////////////////DATA// ////////////////////////////////////////////////////////////////////////////////////////// /*data_length(): Define the data flow length in each time-slot*/ int datain_length() { int length; length=DATA_FLOW_LENGTH; return(length); } int process_datainflow(int len) { int i; return(1); } int dataout_length() { int length; // printf("DATASOURCE numdatabytes=%d \n", input_control[0].CData.numdatabytes); // printf("DATASOURCE status=%d \n", input_control[0].CExec.status); if(input_control[0].CExec.status==NONACTIVE)length=0; if(input_control[0].CExec.status==ACTIVE)length=input_control[0].CData.numdatabytes; if(input_control[0].CExec.status==TEST_FLOW)length=input_control[0].CData.numdatabytes; if(input_control[0].CExec.status==TEST_PROCESS)length=input_control[0].CData.numdatabytes; if(numoutputbytes>0)length=numoutputbytes; if(filefinish==1)length=0; //FILE SENT. No more data should be sent /* printf("DATASOURCE dataout length=%d numoutputbytes=%d\n",\ length, input_control[0].CData.numdatabytes); printf("DATASOURCE dataout status=%d\n",\ input_control[0].CExec.status); */ return(length); } int generate_dataflow(int len) { int i; if(len==0)return(1); //printf("SOURCE: len=%d\n", len); if(input_control[0].CExec.status==ACTIVE)get_data(output_data, frase, len); return(1); } void Init_function() { filelength=lee_archivo("data/rfc793.txt",frase,L_MAX); /*Read the file*/ } /*Return 0 i OK; -1 if error*/ int get_data(unsigned char *data_out, unsigned char *data_in, int numchars){ static int p=0, one=0; int i, length; //Read data from file if(p>=filelength){ if(filefinish==0){ printf("FILE SENT: filelength=%d\n", filelength); filefinish=1; } return(1); } for (i=0; i