# SVN changeset patch # User imanay # Date 2013-02-27 22:52:27.242162 # Revision 104 Testing frame without semicolon. Index: trunk/absroot/source/absc/Control_Module/ServidorTCP.c =================================================================== diff --git a/trunk/absroot/source/absc/Control_Module/ServidorTCP.c b/trunk/absroot/source/absc/Control_Module/ServidorTCP.c --- a/trunk/absroot/source/absc/Control_Module/ServidorTCP.c (revision 103) +++ b/trunk/absroot/source/absc/Control_Module/ServidorTCP.c (revision 104) @@ -56,6 +56,16 @@ typedef struct control_module_parameters cmp; + +char *header = NULL; +char *TypeOfInstrument = NULL; +char *iDSource = NULL; +char *iDDestino = NULL; +char *len = NULL; +char *cmd = NULL; +char *rx_data = NULL; +char *crc = NULL; + cmp parameters; /* * Zona de declaracion de cabeceras. @@ -68,9 +78,12 @@ void procesa_peticion(char *rx_buffer, char *tx_buffer); int cambia_apuntamiento(char *puntero_char); int carga_experimento(char *nombre_archivo); -int chequeo_sistema(char *filename, char *numero_muestras); +char *chequeo_sistema(char *filename, char *numero_muestras); +int chequeo_sistema2(char *filename, char *numero_muestras); void recibe_experimento(char *data, char filename[]); char* File2buffer(char *filename2, int n); +void SplitFrame(char *frame); +void procesa_peticion2(char *rx_buffer, char *tx_buffer); /* * @@ -85,7 +98,7 @@ char *tx_buffer = (char *) malloc(TAM_BUFFER); /* Inicializa parametros del modulo*/ parameters = inicializa_modulo(parameters); - printf("%s%s%s%s",parameters.ID, parameters.param2, parameters.param3, parameters.param4); + printf("%s\n%s\n%s\n%s\n",parameters.ID, parameters.param2, parameters.param3, parameters.param4); /* Inicializa red*/ servSocket = inicializa_ethernet(); /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ @@ -204,7 +217,7 @@ /* * Esta funcion procesa el mensaje de peticion y genera respuesta */ -void procesa_peticion(char *rx_buffer, char *tx_buffer){ +void procesa_peticion2(char *rx_buffer, char *tx_buffer){ int n = 0; char filename1[50]; char filename2[] = "verificacion.txt"; @@ -237,7 +250,7 @@ } else if(strcmp(cmd,"ANST") == 0){ - n = chequeo_sistema(filename2,rx_data); + n = chequeo_sistema2(filename2,rx_data); printf("%i\n",n); tx_data = File2buffer(filename2, n); } @@ -264,6 +277,120 @@ strcat(tx_buffer,crc); strcat(tx_buffer,":"); strcat(tx_buffer,"quit"); + } +} + +void SplitFrame(char *frame){ + header = malloc(4); + *header = *frame; + *(header + 1) = *(frame + 1); + *(header + 2) = *(frame + 2); + *(header + 3) = '\0'; + TypeOfInstrument = malloc(4); + *TypeOfInstrument = *(frame + 3); + *(TypeOfInstrument + 1) = *(frame + 4); + *(TypeOfInstrument + 2) = *(frame + 5); + *(TypeOfInstrument + 3) = '\0'; + iDSource = malloc(8); + *iDSource = *(frame + 6); + *(iDSource + 1) = *(frame + 7); + *(iDSource + 2) = *(frame + 8); + *(iDSource + 3) = *(frame + 9); + *(iDSource + 4) = *(frame + 10); + *(iDSource + 5) = *(frame + 11); + *(iDSource + 6) = *(frame + 12); + *(iDSource + 7) = '\0'; + iDDestino = malloc(8); + *iDDestino = *(frame + 13); + *(iDDestino + 1) = *(frame + 14); + *(iDDestino + 2) = *(frame + 15); + *(iDDestino + 3) = *(frame + 16); + *(iDDestino + 4) = *(frame + 17); + *(iDDestino + 5) = *(frame + 18); + *(iDDestino + 6) = *(frame + 19); + *(iDDestino + 7) = '\0'; + len = malloc(7); + *len = *(frame + 20); + *(len + 1) = *(frame + 21); + *(len + 2) = *(frame + 22); + *(len + 3) = *(frame + 23); + *(len + 4) = *(frame + 24); + *(len + 5) = *(frame + 25); + *(len + 6) = '\0'; + cmd = malloc(5); + *cmd = *(frame + 26); + *(cmd + 1) = *(frame + 27); + *(cmd + 2) = *(frame + 28); + *(cmd + 3) = *(frame + 29); + *(cmd + 4) = '\0'; + + int l = atoi(len) - 31; //Resto del tamaƱo total de la trama los 31 bytes fijos + rx_data = malloc(l); + int i; + for (i = 30; i < 30 + l; i++) + *(rx_data + (i-30)) = *(frame + i); + *(rx_data + l) = '\0'; + crc = malloc(2); + *crc = *(frame + 30 + l); + *(crc + 1) = '\0'; +} + +void procesa_peticion(char *rx_buffer, char *tx_buffer){ +// int n = 0; + char filename1[50]; + char filename2[] = "verificacion.txt"; + char *tx_data = NULL; + SplitFrame(rx_buffer); + printf("Split\n"); + printf("%s\n",header); + printf("%s\n",TypeOfInstrument); + printf("%s\n",iDSource); + printf("%s\n",iDDestino); + printf("%s\n",len); + printf("%s\n",cmd); + printf("%s\n",rx_data); + printf("%s\n",crc); + printf("Split\n"); + + if ((cmd == NULL) || (rx_data == NULL)){ + ERROR("procesarPeticion: formato de mensaje incorrecto"); + } + else{ + if(strcmp(cmd,"SNDF") == 0){ + recibe_experimento(rx_data,filename1); + carga_experimento(filename1); + cambia_apuntamiento("0"); + tx_data = (char*)malloc(3); + tx_data = "OK"; + } + else if(strcmp(cmd,"CHGB") == 0){ + cambia_apuntamiento(rx_data); + tx_data = (char*)malloc(3); + tx_data = "OK"; + + } + + else if(strcmp(cmd,"ANST") == 0){ + /*n = chequeo_sistema(filename2,rx_data); + printf("%i\n",n); + tx_data = File2buffer(filename2, n);*/ + tx_data = chequeo_sistema(filename2,rx_data); + printf("%s\n",tx_data); + } + else{ + tx_data = (char*)malloc(6); + tx_data = "Error"; + ERROR("procesa_peticion: comando no reconocido"); + } + + strcpy(tx_buffer,header); //3 + strcat(tx_buffer,TypeOfInstrument); //3 + strcat(tx_buffer,parameters.ID); //7 + strcat(tx_buffer,iDSource); //7 + strcat(tx_buffer,"00032"); //5 + strcat(tx_buffer,cmd); //4 + strcat(tx_buffer,tx_data); //2 + strcat(tx_buffer,crc); //1 } @@ -388,7 +515,7 @@ * archivo Verificacion. */ -int chequeo_sistema(char *filename, char *numero_muestras){ +int chequeo_sistema2(char *filename, char *numero_muestras){ char valor[7]; int i,cnt; @@ -396,7 +523,7 @@ FILE *fd; fd=fopen(filename,"w"); fprintf(fd,"%s\n","Verificacion"); - fprintf(fd,"%s",parameters.ID); + fprintf(fd,"%s\n",parameters.ID); fprintf(fd,"%s\n","------------"); cnt=0; do @@ -448,12 +575,68 @@ return tx_data; } +/* + * Esta funcion lee "n" veces el estado del APUNTE actual y reporta + * una cadena de Verificacion. + */ +char* chequeo_sistema(char *filename, char *numero_muestras){ + + int i; + int cnt = 0; + unsigned int entradac= 0; + + char page0[250]; + + strcpy(page0,"Verificacion\n"); + strcat(page0,parameters.ID); + strcat(page0,"\n------------\n"); + + char page1[8]; + + do{ + //Inicializando arreglo + for(i=0;i<6;i++) + page1[i]='0'; + page1[6] = '\n'; + page1[7] = '\0'; + //Lectura de puerto + entradac= pio_in(piob,maskb_in); + //Dandole formato al dato + if (!(entradac & bit_up_2)) + page1[0] = '1'; + if (!(entradac & bit_up_1)) + page1[1] = '1'; + if (!(entradac & bit_up_0)) + page1[2] = '1'; + if (!(entradac & bit_dow_2)) + page1[3] = '1'; + if (!(entradac & bit_dow_1)) + page1[4] = '1'; + if (!(entradac & bit_dow_0)) + page1[5] = '1'; + + strcat(page0, page1); + cnt=cnt+1; + usleep(1*1000*1000); + + }while(cnt < atoi(numero_muestras)); + + page0[strlen(page0)] = '\0'; + + char *all_pages = malloc(strlen(page0)+1); + strcpy(all_pages, page0); + return all_pages; +} cmp inicializa_modulo(cmp p){ FILE *fd = fopen("configuration.txt","r"); fgets(p.ID,20,fd); + p.ID[7]='\0'; fgets(p.param2,20,fd); + p.param2[10]='\0'; fgets(p.param3,20,fd); + p.param3[10]='\0'; fgets(p.param4,20,fd); + p.param4[10]='\0'; fclose(fd); return p; }