/** Sample ALOE component implementation file */ /** Include SW API header and SW API utils (skeleton) */ #include #include /** Include general data type library */ #include "typetools.h" /** include input/output interfaces and stats. * itf_types.h must be included 'before' input.h if it defines e.g. control * interface packet structure */ #include "itf_types.h" #include "inputs.h" #include "outputs.h" #include "stats.h" #include "my_prog.h" /*GLOBAL DEFINITIONS*/ #define BITSPERCHAR 8 #define ERROR -1 #define READY 1 #define NONREADY 0 /*GLOBAL VARIABLES & BUFFERS*/ int configured=0; int dataprocessedready=READY; int input_temp[INPUT_MAX_DATA*8], output_temp[OUTPUT_MAX_DATA*8]; char pinput[INPUT_MAX_DATA*8], poutput[INPUT_MAX_DATA*8]; /* PREDEFINED FUNCTIONS*/ void print_array(char *Pin, int Dtype, int Dlength, int Dcolums, \ int print, int numTS, int printingTS, int nprintTS); int datainflow_bypass(int len,int numTS,int print,\ int numcols,int dattype, int outdattype); void check_config(); /*----------------------- SQUELETON CALLED FUNCTIONS ------------------------*/ /** INPUT INTERFACE 1: CONTROL //////////////////////////////////////////CONTROL * controlin_length() Returns the maximum length (in control type words) of the * expected control flow at each time-slot * Funtion activated if control flow has been received */ int controlin_length() { int length=INPUT_MAX_CONTROL; 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 * This is the processing function for the control interface. Here, we simply * have to validate the parameters and update our internal state variables. */ int process_inputcontrol(int len) { if(len<=0)return(1); configured=1; //CAPTURE MODULE CONFIG //memcpy(&ctrl,&ctrlpkt,sizeof(ControlMODULENAME_h)); memcpy(&ctrl,&ctrlpkt,sizeof(ctrl)); //PRINT CONFIG VALUES xprintf("O---->gen_SOURCEr1 (config): CONFIG BY CONTROL ITF\n"); xprintf("O---->gen_SOURCEr1 (config): TSLOT%d, STATUS=%d\n",\ ctrl.time_slot,\ ctrl.status); xprintf("O NumInputdata=%d, NumOutputdata=%d\n",\ ctrl.inputdatalength,\ ctrl.outputdatalength); xprintf("O transporttypeIN=%d, transporttypeOUT=%d\n",\ ctrl.transporttypeIN,\ ctrl.transporttypeOUT); xprintf("O-----------------------------------------0\n"); if(ctrl.inputdatalength>INPUT_MAX_DATA) { printf("ERROR: gen_SOURCEr1.PROCESS_INPUTCONTROL(): \n"); printf("ERROR: ctrl.inputdatalength=%d>INPUT_MAX_DATA=%d\n",\ ctrl.inputdatalength, INPUT_MAX_DATA); return(0); } /*return 1 if OK; return 0 if error*/ return(1); } /** END INPUT INTERFACE 1: CONTROL /////////////////////////////////////CONTROL /** INPUT INTERFACE 2: DATA ///////////////////////////////////////////////DATA * datain_length() Returns the maximum length (in data type words) of the * expected data flow at each time-slot * Funtion activated if data flow has been received */ int datain_length() { int length=0; length=typeSizeArray(ctrl.transporttypeIN, ctrl.inputdatalength); if(length > INPUT_MAX_DATA){ printf("gen_SOURCEr1.datain_length(): ERROR length too long\n"); printf("length=%d INPUT_MAX_DATA=%d\n", ctrl.inputdatalength, INPUT_MAX_DATA); } return(length); } /** Process the received data flow according to the length returned by * datain_length(). Run function. return 1 if ok, 0 if error. * "len" indicates the number of data bytes (input buffer defined as char) * to be processed * This is the main processing function. It will be called every time * data is available for process. Here you will place your signal processing * code. */ int process_inputdata(int lengthbytes) { int i, lengthdata; printf("lengthbytes=%dXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n", lengthbytes); /*Check if configured*/ if (!configured)return(1); /*CHECK DATA INPUT LENGTH*/ /** In general, we want to make sure we have received the expected * amount of data. * The function typeSizeArray() returns the expected bytes as a function * of a general datatype and expected number of elements. For example, if * blockLength=128 and datatype is INTEGER, it returns 128*4=512. * If for example the datatype is BITSTREAM the function will * return 128/8=16 */ if (lengthbytes 0)dataprocessedready=READY; if(PROCESSINGTYPEOUT==TYPE_BITSTREAM){ lengthdata=lengthOUT; /** LAST DATA IN THE OUTPUT BUFFER MUST BE SENT*/ if(lengthdata==0)if(lastTX==0){ lengthdata=lengthbytes; lastTX=1; } } // printf("gen_SOURCEr1.GENERATE_OUTPUTDATA(): dataprocessedready=%d, ctrl.time_slot=%d \n",\ dataprocessedready, ctrl.time_slot); // printf("gen_SOURCEr1.GENERATE_OUTPUTDATA(): lengthdata=%d, ctrl.time_slot=%d \n",\ lengthdata, ctrl.time_slot); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// /**CONVERT TYPE PROCESSED TO TYPE TO BE SENT*/ lengthdata=type2type(poutput, output_data,\ PROCESSINGTYPEOUT, ctrl.transporttypeOUT,\ lengthdata, 1.0); if(lengthdata==ERROR){ printf("ERROR: gen_SOURCEr1.PROCESS_INPUTDATA(): OUTPUT DATA CONVERSION\n"); return(0); } /** PRINT OUTPUT IN CASE*/ if(printting==PRINT) if((NUM_TS<=ctrl.time_slot)&&((NUM_TS+NUM_TS_PRINTS)>ctrl.time_slot)){ if(ctrl.transporttypeOUT==TYPE_BITSTREAM) lengthdata=lengthdata*BITSPERCHAR; else lengthdata=lengthdata/typeSize(ctrl.transporttypeOUT); printf("gen_SOURCEr1.PROCESS_INPUTDATA(): OUTPUT lengthdata=%d,ctrl.outputdatalength=%d \n",\ lengthdata, ctrl.outputdatalength); } print_array(output_data, ctrl.transporttypeOUT, lengthdata,\ NUMCOLS, printting, ctrl.time_slot, numTS2print, NUM_TS_PRINTS); } return 1; } /** This function is called after all interface processing functions have been * called. You can place other state-update code here. */ int RunCustom() { ctrl.time_slot++; //check_config(); return 1; } /** This function is called after all interfaces have been initialized. * You can place other custom initialization code here. */ int InitCustom() { check_config(); init_my_prog(); return 1; } /** This function is called after initializing parameters and before * creating interfaces. It is useful when the number of interfaces or buffers * is a function of an initialization parameter. */ void ConfigInterfaces() { } /*----------------------- SQUELETON CALLED FUNCTIONS END -------------------*/ /** Perfom a bypass input output without any data modification * Parameters * int len Data lenght (number of received bytes) * int numTS Time slot when print * int print print (1) or no print (0) * int numcols Number of printing columns * int indattype Intput Data type to print * int outdattype Output Data type to print */ int datainflow_bypass(int len,int numTS,int print,int numcols,\ int indattype, int outdattype) { int i, lengthprint; /** Print output in case*/ if(indattype == TYPE_BITSTREAM)lengthprint=len*BITSPERCHAR; else lengthprint=len/typeSize(indattype); if(print==printting)if(ctrl.time_slot==numTS)printf("gen_SOURCEr1 BYPASS INPUTDATA\n"); print_array(input_data, indattype, lengthprint, numcols, print, ctrl.time_slot, numTS, 1); /**BYPASS DATA TYPE RECEIVED TO DATA TYPE TO BE SEND*/ len=type2type(input_data, output_data,\ ctrl.transporttypeIN, ctrl.transporttypeOUT, len, 1.0); /** Print output in case*/ if(outdattype == TYPE_BITSTREAM)lengthprint=len*BITSPERCHAR; else lengthprint=len/typeSize(outdattype); if(print==printting)if(ctrl.time_slot==numTS)printf("gen_SOURCEr1 BYPASS OUTPUTDATA\n"); print_array(output_data, outdattype, lengthprint, numcols, print, ctrl.time_slot, numTS, 1); /**CALCULATE THE NUMBER OF DATA TO BE SENT*/ if(outdattype == TYPE_BITSTREAM)len=len*BITSPERCHAR; ctrl.outputdatalength=typeSizeArray(outdattype,len); if(print==printting)if(ctrl.time_slot==numTS) printf("gen_SOURCEr1 BYPASS dataOUTPUTlength=%d\n", ctrl.outputdatalength); return(1); } /** Checks the current module status and capture the configuration defined at * stats.h */ void check_config() { if(configSTATS==FALSE)return; configSTATS=FALSE; configured=1; /*PRINT CONFIG VALUE*/ xprintf("O---->gen_SOURCEr1 (config): CONFIG BY STATS.h\n"); if(ctrl.status==NONACTIVE) xprintf("O---->gen_SOURCEr1 (config): STATUS=NONACTIVE\n"); if(ctrl.status==ACTIVE){ xprintf("O---->gen_SOURCEr1 (config): TSLOT%d, STATUS=ACTIVE\n",\ ctrl.time_slot); } if(ctrl.status==TEST_FLOW){ xprintf("O---->gen_SOURCEr1 (config): TSLOT%d, STATUS=TEST_FLOW\n",\ ctrl.time_slot); } if(ctrl.status==TEST_PROCESS){ ctrl.transporttypeOUT=0; xprintf("O---->gen_SOURCEr1 (config): TSLOT%d, STATUS=TEST_PROCESS\n",\ ctrl.time_slot); } xprintf("O inputdatalength=%d, outputdatalength=%d\n",\ ctrl.inputdatalength,\ ctrl.outputdatalength); xprintf("O transporttypeIN=%d, transporttypeOUT=%d\n",\ ctrl.transporttypeIN,ctrl.transporttypeOUT); xprintf("O---------------------------------------"); xprintf("----------------------------------------0\n"); } /** print_array(): Prints an array according their type at selected Time-Slot * and between Time-Slot printingTS and Time-Slot printingTS+nprintTS. * print parameter allow to desactivate printing. * * char *Pin :Input data pointers * int Dtype :Data type * int Dlength :Number of data * int Dcolums :Printed columns * int print :Print command * int numTS :number of Time-slot * int printingTS :Initial Printing Time-slot * int nprintTS :Number of printing Time-slots */ void print_array(char *Pin, int Dtype, int Dlength, int Dcolums, \ int print, int numTS, int printingTS, int nprintTS) { int i; float *input_f; char *input_c; int *input_i; short *input_s; if(Dtype==TYPE_BITSTREAM)input_c=(unsigned char *)Pin; if(Dtype==TYPE_BIT8)input_c=(unsigned char *)Pin; if(Dtype==TYPE_CHAR)input_c=(unsigned char *)Pin; if(Dtype==TYPE_SHORT)input_s=(short *)Pin; if(Dtype==TYPE_INT)input_i=(int *)Pin; if(Dtype==TYPE_FLOAT)input_f=(float *)Pin; if(print!=PRINT)return; if((printingTS<=numTS)&&((printingTS+nprintTS)>numTS)){ if(Dtype==TYPE_BITSTREAM)Dlength=Dlength/8; printf("000) "); for(i=1; i<=Dlength; i++){ if(Dtype==TYPE_BITSTREAM)printf("%03d ", (unsigned char) *(input_c+i-1)); if(Dtype==TYPE_BIT8)printf("%03d ", (unsigned char )input_c[i-1]); if(Dtype==TYPE_CHAR)printf("%03d ", (unsigned char)input_c[i-1]); if(Dtype==TYPE_SHORT)printf("%d ", (short )input_s[i-1]); if(Dtype==TYPE_INT)printf("%d ", (int)input_i[i-1]); if(Dtype==TYPE_FLOAT)printf("%4.2f ", (float)input_f[i-1]); if(i