scc_lib_test.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <signal.h>
  5. #include <errno.h>
  6. #include <unistd.h>
  7. #include <time.h>
  8. #include <sys/wait.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <fcntl.h>
  12. #define MS 1000000
  13. #define SIG_TIMER SIGRTMIN
  14. /*void sig_TIMER_handler(int signo, siginfo_t *info, void *context)
  15. {
  16. printf("timer went off and i don't know what to do\n");
  17. }
  18. */
  19. int main(int argc, char *argv[]){
  20. int i;
  21. float f[2],x[2];
  22. f[0] = 0.2;
  23. f[1] = 0.3;
  24. //i = f;
  25. memcpy(&i, &f[0], sizeof(int));
  26. memcpy(&x[0], &i, sizeof(int));
  27. //printf("i = %d if = %0.2f\n",i,i);
  28. //x = i;
  29. memcpy(&i, &f[1], sizeof(int));
  30. memcpy(&x[1], &i, sizeof(int));
  31. printf("x[0] = %0.2f x[1] = %0.2f\n",x[0],x[1]);
  32. /*int fd_r,dummy=0,i,j,res;
  33. char filename[64], command='0';
  34. //strcpy(filename,"/shared/herc/command_file");
  35. strcpy(filename,"/home/billtsou/Desktop/command_file");
  36. fd_r = open(filename, O_RDONLY);// | O_NONBLOCK
  37. if (fd_r < 0) perror("open: ");
  38. else {
  39. while (command != '1') {
  40. dummy=0;
  41. for (i=0; i<1000; i++)
  42. for(j=0; j<1000; j++)
  43. dummy++;
  44. res = read(fd_r, &command, sizeof(char));
  45. if (res < 0) perror("read: ");
  46. if (command != '0') printf("I read %c\n",command);
  47. }
  48. }*/
  49. /*time_t cur_time;
  50. struct tm *cur_t;
  51. struct sigevent sev;
  52. struct itimerspec its;//, chk_timer;
  53. timer_t timerid;
  54. sigset_t sigset;
  55. struct sigaction sa;
  56. sev.sigev_notify = SIGEV_SIGNAL;
  57. sev.sigev_signo = SIG_TIMER;
  58. sev.sigev_value.sival_ptr = &timerid;
  59. if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) printf("timer_create error\n");
  60. sa.sa_flags = SA_RESTART | SA_SIGINFO;
  61. sigemptyset(&sigset);
  62. //sigaddset(&sigset, SIG_TIMER);
  63. sa.sa_mask = sigset;
  64. sa.sa_sigaction = sig_TIMER_handler;
  65. if (sigaction(SIG_TIMER, &sa, NULL) < 0) {
  66. perror("sigaction: SIG_TIMER");
  67. exit(1);
  68. }
  69. sigaddset(&sigset, SIG_TIMER);
  70. if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
  71. perror("signals_enable: sigprocmask");
  72. exit(1);
  73. }
  74. its.it_interval.tv_sec = 0;
  75. its.it_interval.tv_nsec = 0;
  76. its.it_value.tv_sec = 0;
  77. its.it_value.tv_nsec = 10 * MS;
  78. if (timer_settime(timerid, 0, &its, NULL) == -1) perror("timer_settime error9");
  79. pause();
  80. cur_time = time(NULL);
  81. cur_t = localtime(&cur_time);
  82. printf("[%d:%d:%d]: Everything went well\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec);
  83. */
  84. /*FILE *app_input, *log_file;
  85. char app_input_file_name[64], log_file_name[64];
  86. int time_next;
  87. strcpy(app_input_file_name,"/home/herc/app_input.txt");
  88. //strcat(app_input_file_name, argv[1]);
  89. //strcat(app_input_file_name, "/app_input.txt");
  90. //printf("file path = %s\n",app_input_file_name);
  91. if ((app_input = fopen(app_input_file_name, "r")) == NULL){
  92. printf("Cannot open input file with file path = %s ",app_input_file_name);
  93. perror("open app_input");
  94. }
  95. fscanf(app_input,"%d",&time_next);
  96. printf("time next = %d\n",time_next);
  97. //strcpy(log_file_name,"./scenaria/");
  98. //strcat(log_file_name, scen_num);
  99. strcpy(log_file_name,"/home/herc/log_file_test.txt");
  100. if ((log_file = fopen(log_file_name, "w")) == NULL){
  101. //printf("open log my id is %d ",node_id);
  102. perror("open log");
  103. }
  104. fprintf(log_file,"poutanes\n");
  105. fclose(app_input);
  106. fclose(log_file);
  107. */
  108. return 0;
  109. }