##// END OF EJS Templates
Get file function implemented.
imanay -
r215:216
parent child
Show More
@@ -116,7 +116,9
116 116 int cambia_apuntamiento(char *puntero_char);
117 117 int carga_experimento(char *nombre_archivo);
118 118 char *chequeo_sistema(char *filename, char *numero_muestras);
119 void recibe_experimento(char *data, char filename[]);
119 void escribe_experimento(char *data, char filename[]);
120 char *Lee_experimento(char *filename);
121 void consigue_nombre_experimento(char *rx_data, char filename[]);
120 122 void SplitFrame(char *frame);
121 123 void intToStr( int number, char* str );
122 124
@@ -381,11 +383,16
381 383 }
382 384 else{
383 385 if(strcmp(cmd,"SNDF") == 0){
384 recibe_experimento(rx_data,filename1);
386 escribe_experimento(rx_data,filename1);
385 387 carga_experimento(filename1);
386 cambia_apuntamiento("0");
388 //cambia_apuntamiento("0");
387 389 tx_data = (char*)malloc(3);
388 390 tx_data = "OK";
391 }
392 else if(strcmp(cmd,"GETF") == 0){
393 consigue_nombre_experimento(rx_data,filename1); //get a filename from frame
394 tx_data = Lee_experimento(filename1); //return a pointer to the content of the filename
395 printf("%s\n",tx_data);
389 396 }
390 397 else if(strcmp(cmd,"CHGB") == 0){
391 398 cambia_apuntamiento(rx_data);
@@ -435,10 +442,22
435 442
436 443 }
437 444
445
446 char* Lee_experimento(char filename[]){
447 char *buffer = NULL;
448 FILE * fd = fopen(filename,"r");
449 fseek(fd, 0, SEEK_END);
450 size_t sz = ftell(fd);
451 fseek(fd, 0, SEEK_SET);
452 buffer = malloc(sz);
453 fread(buffer,sizeof(char),sz,fd);
454 fclose(fd);
455 return buffer;
456 }
438 457 /*
439 458 * Esta función genera el archivo de experimento a partir de la trama TCP recibida
440 459 */
441 void recibe_experimento(char *p_data, char filename[]){
460 void escribe_experimento(char *p_data, char filename[]){
442 461 FILE *fd;
443 462 int i = 0;
444 463
@@ -452,6 +471,18
452 471 fd = fopen(filename,"w");
453 472 fprintf(fd, p_data);
454 473 fclose(fd);
474 }
475
476 void consigue_nombre_experimento(char *p_data, char filename[]){
477
478 int i = 0;
479
480 while (*p_data != '\n'){
481 filename[i] = *p_data;
482 i++;
483 p_data++;
484 }
485 filename[i] = '\0';
455 486 }
456 487
457 488 /*
@@ -844,7 +875,8
844 875 strcpy(page0,parameters.ID);
845 876 strcat(page0,"\n-------\n");
846 877
847 sprintf(page1,"UP:%1.2f DW:%1.2f\n",phase1, phase2);
878 //sprintf(page1,"UP:%1.2f DW:%1.2f\n",phase1, phase2);
879 sprintf(page1,"%1.2f %1.2f\n",phase1, phase2);
848 880 strcat(page0,page1);
849 881 char *all_pages = malloc(strlen(page0)+1);
850 882 strcpy(all_pages, page0);
@@ -1,4 +1,4
1 S01
1 CnMod01
2 2 parameter2
3 3 parameter3
4 4 parameter4 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now