int main()
{
	char key;
	IplImage *base, *fr, *fr0;
	float dt;
	struct timeval past;
	
	inform();
	preprocessing(windowname, &base, &fr, &fr0);
	
	while(1)
	{
		initialize(&past);
		while(explosr<criticr && !restartflag && !escflag)
		{
			cvCopy(base, fr, NULL);
			easyplot(fr, fr0);
			dt = time_interval(&past);
			pausestate(&past, fr);
			user_update();
			com_update();
			ball_update(dt);
			cvShowImage(windowname, fr);
		}
		// exit
		if(escflag) break;
		// update score
		if(bpc.y<0) score[1]++;
		else score[0]++;
		// restart
		if(restartflag) {
			restartflag = 0;
			score[0] = 0;
			score[1] = 0;
		}
	}
	
	// free memory
	cvDestroyWindow(windowname);
	cvReleaseImage(&base);
	cvReleaseImage(&fr);
	cvReleaseImage(&fr0);
	cvReleaseImage(&scoretext1);
	cvReleaseImage(&scoretext2);
	cvReleaseImage(&pausetext);
	cvReleaseImage(&pausefr);
	return 0;
}
void pausestate(struct timeval *past, IplImage *fr)
{
	// check whether key something or not
	char key;
	key = cvWaitKey(3);
	if(key==27) escflag = 1;
	else if(key=='r' || key=='R') restartflag = 1;
	else if(key==' ') pauseflag = 1;
	// pause loop
	if(pauseflag) {
		cvAddWeighted(fr, 0.5, pausetext, 1.0, 0.0, fr);
		while(pauseflag) {
			cvCopy(fr, pausefr);
			// check whether key something or not
			key = cvWaitKey(10);
			if(key==27) {
				escflag   = 1;
				pauseflag = 0;
			}
			else if(key=='r' || key=='R') {
				restartflag = 1;
				pauseflag = 0;
			}
			else if(key==' ') {
				pauseflag = !pauseflag;
			}
			// check mouse position among buttons
			if(mp.x>rbutton1.x && mp.x<rbutton3.x) {
				if(mp.y>rbutton1.y && mp.y<rbutton3.y) {
					plot_rectangular_button(pausefr, yellow, 1);
				}
				else if(mp.y>ebutton1.y && mp.y<ebutton3.y) {
					plot_rectangular_button(pausefr, yellow, 2);
				}
				else if(mp.y>sbutton1.y && mp.y<sbutton3.y) {
					plot_rectangular_button(pausefr, yellow, 3);
				}
			}
			cvSmooth(pausefr, pausefr, CV_BLUR, 5, 5, 0.0, 0.0);
			cvShowImage(windowname, pausefr);
		}
		time_interval(past);
	}
}
Example #3
0
/*DEBUG*/
uint8_t 
deb_msg_send(void)
{
	if(time_interval(ts_debcan)<300) return 1;
	ts_debcan=timer0_getCounter();
	deb_msg.ID=0x200;
	deb_msg.DLEN=8;
	
	deb_msg.data[0]=MSP[0].count_attempt_reinit;
	deb_msg.data[1]=MSP[1].count_attempt_reinit;
	deb_msg.data[2]=MSP[2].count_attempt_reinit;
	deb_msg.data[3]=UART.current_MSP+1;
	deb_msg.data[4]=UART.current_chanel+1;
	deb_msg.data[5]=MSP[0].status;
	deb_msg.data[6]=MSP[1].status;
	deb_msg.data[7]=MSP[2].status;
	CAN_Msg_Send(CAN_PARAMS,&deb_msg);
	return 0;
}
Example #4
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("NDDS_Timer_Test"));

  RTIClock *timer = RTIHighResolutionClock_new();

  u_int errors = 0;

  u_int iterations = 1;

  ACE_Get_Opt getoptarg (argc, argv, ACE_TEXT ("i:"));
  for (int c; (c = getoptarg ()) != -1; )
    {
      switch (c)
        {
        case 'i':
          iterations = ACE_OS::atoi (getoptarg.opt_arg ());
          break;
        }
    }

  // We don't check for errors if the interval is shorter than this
  // value because the OS has a finite resolution anyway.
  static u_int const TIMER_RESOLUTION = 10000;

  for (u_int i = 0; i < sizeof intervals / sizeof (u_int); ++i)
    {
      for (u_int j = 0; j < iterations; ++j)
        {
          ACE_Time_Value const interval (0, intervals[i]);

          RTINtpTime duration;
          time_interval (timer, interval, duration);

          unsigned long long microseconds, nanoseconds;
          int sec;
          RTINtpTime_unpackToMicrosec (sec, microseconds, duration);
          RTINtpTime_unpackToNanosec (sec, nanoseconds, duration);

          time_t const interval_usec =
            interval.sec () * ACE_ONE_SECOND_IN_USECS + interval.usec ();
          time_t const measured_usec =
            sec * ACE_ONE_SECOND_IN_USECS + microseconds;


          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("interval: %: usec, measured: %: usec %s\n"),
                      interval_usec,
                      measured_usec,
                      (intervals[i] <= TIMER_RESOLUTION
                       ? ACE_TEXT (" (interval and measured may differ)")
                       : ACE_TEXT (""))));

          if (intervals[i] > TIMER_RESOLUTION)
            {
              errors += check (interval.sec () * ACE_ONE_SECOND_IN_USECS
                               + interval.usec (),
                               sec * ACE_ONE_SECOND_IN_USECS + microseconds);
              // Don't check for error for intervals below 10 msec.
            }
          errors += check_micro_nano (microseconds, nanoseconds);
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("NDDS_Timer usec: %Q, nsec: %Q\n"),
                      microseconds,
                      nanoseconds));
        }
    }

  ACE_END_TEST;
  return errors == 0  ?  0  :  1;
}
Example #5
0
int main(int argc, char *argv[])
{
	int ret;
	int i_val = 0;
	long long ll_val = 0;
	struct timeval tvb, tve;
	char tmp_buf[256] = { 0 };

	char *file = NULL;
	f1g_template_t tpl;
	data_set_t ds;
	value_t buf;

	buf.val = (i8_p)sg_buf;
	buf.val_len = 0;
	buf.val_size = 2048;

	if (argc < 2) {
		return 1;
	}
	file = argv[1];

	gettimeofday(&tvb, NULL);
	if (F1G_OK != f1g_template_init(&tpl, 24)) {
		fprintf(stderr, "Init template fail!\n");
		return 1;
	}
	
	if (F1G_OK != f1g_template_parse(&tpl, file)) {
		fprintf(stderr, "Parse file %s fail!\n", file);
		return 1;
	}
	gettimeofday(&tve, NULL);
	fprintf(stdout, "Init Template consumes %d useconds\n", time_interval(&tvb, &tve));
	
	f1g_template_print(&tpl);

	gettimeofday(&tvb, NULL);
	ret = data_set_init(&ds, 10);
	if (F1G_OK != ret) {
		return 1;
	}
	
	i_val = 0x0a000222;
	ll_val = 0x1234567801020304;
	data_set_add_int_var(&ds, "iP", (void*)&i_val, "%08x");
	data_set_add_str_var(&ds, "ADc_ip", "1.1.1.1", 7);
	sprintf(tmp_buf, "%s", "www.google.com.hk/test.html");
	data_set_add_str_var(&ds, "O_URL", tmp_buf, strlen(tmp_buf));
	data_set_add_int_var(&ds, "UMASK", (void*)&ll_val, "%llu");
	i_val = 300;
	data_set_add_int_var(&ds, "INTERVAL", (void*)&i_val, "%d");
	i_val = 0x802040;
	data_set_add_int_var(&ds, "VASK", (void*)&i_val, "%u");
	i_val = 12300123;
	data_set_add_int_var(&ds, "UiD", (void*)&i_val, "%u");
	i_val = 0x00007705;
	data_set_add_int_var(&ds, "ANAME", (void*)&i_val, "%08x");
	i_val = 0;
	data_set_add_int_var(&ds, "IPC_NID", (void*)&i_val, "%1d");
	
	if (f1g_template_exec(&tpl, &buf, &ds) != F1G_OK) {
		f1g_template_print(&tpl);
		return 1;
	}
	gettimeofday(&tve, NULL);
	fprintf(stdout, "Exec Template consumes %d useconds\n", time_interval(&tvb, &tve));

	fprintf(stdout, "\nBuff[%d][%.*s]\n", buf.val_len, buf.val_len, buf.val);

	data_set_destroy(&ds);

	f1g_template_destroy(&tpl);

	return 0;
}
Example #6
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("High_Res_Timer_Test"));

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("The ACE_High_Res_Timer scale factor is %u ")
              ACE_TEXT ("1/microsecond\n"),
              ACE_High_Res_Timer::global_scale_factor ()));

  u_int errors = 0;

  u_int iterations = 1;

  ACE_Get_Opt getoptarg (argc, argv, ACE_TEXT ("i:"));
  for (int c; (c = getoptarg ()) != -1; )
    {
      switch (c)
        {
        case 'i':
          iterations = ACE_OS::atoi (getoptarg.opt_arg ());
          break;
        }
    }

  // We don't check for errors if the interval is shorter than this
  // value because the OS has a finite resolution anyway.
  static u_int const TIMER_RESOLUTION = 10000;

  for (u_int i = 0; i < sizeof intervals / sizeof (u_int); ++i)
    {
      for (u_int j = 0; j < iterations; ++j)
        {
          ACE_Time_Value const interval (0, intervals[i]);
          ACE_hrtime_t nanoseconds;
          ACE_hrtime_t microseconds;
          ACE_Time_Value const measured = time_interval (interval,
                                                         nanoseconds,
                                                         microseconds);
          time_t const interval_usec =
            interval.sec () * ACE_ONE_SECOND_IN_USECS + interval.usec ();
          time_t const measured_usec =
            measured.sec () * ACE_ONE_SECOND_IN_USECS + measured.usec ();

          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("interval: %: usec, measured: %: usec %s\n"),
                      interval_usec,
                      measured_usec,
                      (intervals[i] <= TIMER_RESOLUTION
                       ? ACE_TEXT (" (interval and measured may differ)")
                       : ACE_TEXT (""))));

          if (intervals[i] > TIMER_RESOLUTION)
            {
              errors += check (interval.sec () * ACE_ONE_SECOND_IN_USECS
                               + interval.usec (),
                               measured.sec () * ACE_ONE_SECOND_IN_USECS
                               + measured.usec ());
              // Don't check for error for intervals below 10 msec.
            }
          // Check the ACE_Timer_Value-calculated microseconds against
          // the ACE_High_Res_Timer-calculated nanoseconds.
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("ACE_Time_Value usec: %:, ACE_HR nsec: %Q\n"),
                      measured_usec,
                      nanoseconds));
          // This gives problems -> should be fixed
          errors += check_micro_nano (measured.sec () * ACE_ONE_SECOND_IN_USECS
                                      + measured.usec (),
                                      nanoseconds);
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("ACE_High_Res_Timer usec: %Q, nsec: %Q\n"),
                      microseconds,
                      nanoseconds));
          // Now check the ACE_High_Res_Timer-calculated values against
          // each other.
          errors += check_micro_nano (microseconds, nanoseconds);
        }
    }

  ACE_END_TEST;
  return errors == 0  ?  0  :  1;
}