示例#1
0
int main (int argc, char * argv [])
{
  unsigned controller = 0, sendBody = 0, sendUser = 1;
  sprintf(trackerName, "%s", TRACKER_NAME);

  // The only command line argument is a string for the configuration
  if (argc > 1) {
      // Get the arguments (device_name, controller_index, bodyFrame, userFrame)
      if (sscanf(argv[1], "%511s%u%u%u", trackerName, &controller, &sendBody, &sendUser) != 4) {
        fprintf(stderr, "Bad vrpn_Freespace line: %s\n", argv[1]);
        fprintf(stderr, "Expect: deviceName controllerIndex bodyFrame userFrame\n");
        return -1;
      }
  }

  // Correctly handle command line input
  addControlHandler();

  //---------------------------------------------------------------------
  // explicitly open the connection
  connection = vrpn_create_server_connection(CONNECTION_PORT);

  //---------------------------------------------------------------------
  // create a freespace tracker for the first device.
  printf("Tracker's name is %s.\n", trackerName);
  freespace = vrpn_Freespace::create(trackerName, connection, 0, (sendBody != 0), (sendUser != 0));
  if (!freespace) {
      fprintf(stderr, "Error opening freespace device: %s\n", trackerName);
  	  return 1;
  }
  // the freespace device exposes 3 vrpn interfaces.  Tracker, buttons, 
  // and a Dial (scrollwheel)
  // libfreespace also reports values like a mouse (dx/dy), though the 
  // vrpn messages are not currently sent.  Considering the client side doesn't
  // have a notion of a mouse, but treats it as an analog device, I didn't feel
  // compelled to generate the messages, though the additional code is fairly 
  // straight forward

  create_and_link_tracker_remote(trackerName);
  create_and_link_button_remote(trackerName);
  create_and_link_dial_remote(trackerName);

  while ( !quit ) {

	// Let the servers, clients and connection do their things
  	freespace->mainloop();
  	rtkr->mainloop();
  	connection->mainloop();

  	// Sleep for 1ms each iteration so we don't eat the CPU
  	vrpn_SleepMsecs(1);
  }

  delete freespace;
  delete rtkr;
  delete connection;

  return 0;
}   /* main */
示例#2
0
int main (int argc, char * argv [])
{
bool sendBody = 0, sendUser = 1;
// painfully simple CL options to turn on/off body/user frame reports
  if (argc > 1) {
     sendBody = atoi(argv[1]);
     if (argc > 2) { 
       sendUser = atoi(argv[2]);
    }
  }
  //---------------------------------------------------------------------
  // explicitly open the connection
  connection = vrpn_create_server_connection(CONNECTION_PORT);

  //---------------------------------------------------------------------
  // Open the tracker server, using this connection, 2 sensors, update 1 times/sec
  printf("Tracker's name is %s.\n", TRACKER_NAME);

  // create a freespace tracker for the first device.
  freespace = vrpn_Freespace::create(TRACKER_NAME, connection, 0, sendBody, sendUser);
  if (!freespace) {
  	fprintf(stderr, "Error opening freespace device\n");
  	return 1;
  }
  // the freespace device exposes 3 vrpn interfaces.  Tracker, buttons, 
  // and a Dial (scrollwheel)
  // libfreespace also reports values like a mouse (dx/dy), though the 
  // vrpn messages are not currently sent.  Considering the client side doesn't
  // have a notion of a mouse, but treats it as an analog device, I didn't feel
  // compelled to generate the messages, though the additional code is fairly 
  // straight forward

  create_and_link_tracker_remote();
  create_and_link_button_remote();
  create_and_link_dial_remote();

  /* 



 
   * main interactive loop
   */
  while ( 1 ) {

	// Let the servers, clients and connection do their things
  	freespace->mainloop();
  	rtkr->mainloop();
  	connection->mainloop();

  	// Sleep for 1ms each iteration so we don't eat the CPU
  	vrpn_SleepMsecs(1);
  }
  return 0;
}   /* main */
示例#3
0
int main (int argc, char * argv [])
{
	if (argc != 1) {
		fprintf(stderr, "Usage: %s\n", argv[0]);
		return -1;
	}

    //---------------------------------------------------------------------
    // test the packing and unpacking routines
    if (!vrpn_test_pack_unpack()) {
        fprintf(stderr, "vrpn_test_pack_unpack() failed!\n");
        return -1;
    }

    //---------------------------------------------------------------------
	// test the thread library
	if (!vrpn_test_threads_and_semaphores()) {
		fprintf(stderr, "vrpn_test_threads_and_semaphores() failed!\n");
                fprintf(stderr, "  (This is not often used within VRPN, so it should not be fatal\n");
	} else {
		printf("Thread code passes tests (not using for the following though)\n");
	}

	//---------------------------------------------------------------------
	// explicitly open the connection
	connection = vrpn_create_server_connection("loopback:");

	if (!connection->doing_okay()) {
		fprintf(stderr, "Connection not doing okay (should be impossible)!\n");
		return -1;
	}


	//---------------------------------------------------------------------
	// Open the tracker server, using this connection, 2 sensors, update 1 times/sec
	stkr = new vrpn_Tracker_NULL(TRACKER_NAME, connection, 2, 1.0);
	printf("Tracker's name is %s.\n", TRACKER_NAME);
	create_and_link_tracker_remote();

	//---------------------------------------------------------------------
	// Open the dial server, using this connection, 2 dials, spin 0.5 rev/sec,
	// update 1 times/sec
	sdial = new vrpn_Dial_Example_Server(DIAL_NAME, connection, 2, 0.5, 1.0);
	printf("Dial's name is %s.\n", DIAL_NAME);
	create_and_link_dial_remote();

	//---------------------------------------------------------------------
	// Open the button server, using this connection, defaults
	sbtn = new vrpn_Button_Example_Server(BUTTON_NAME, connection);
	printf("Button's name is %s.\n", BUTTON_NAME);
	create_and_link_button_remote();

	//---------------------------------------------------------------------
	// Open the text sender and receiver.
	stext = new vrpn_Text_Sender(TEXT_NAME, connection);
	printf("Text's name is %s.\n", TEXT_NAME);
	create_and_link_text_remote();

	//---------------------------------------------------------------------
	// Open the analog server, using this connection.
	sana = new vrpn_Analog_Server(ANALOG_NAME, connection);
	sana->setNumChannels(8);
	printf("Analog's name is %s.\n", ANALOG_NAME);
	create_and_link_analog_remote();

	//---------------------------------------------------------------------
	// Open the analog output remote , using this connection.
	ranaout = new vrpn_Analog_Output_Remote(ANALOG_OUTPUT_NAME, connection);
	printf("Analog's name is %s.\n", ANALOG_OUTPUT_NAME);
	create_and_link_analog_output_server();

	//---------------------------------------------------------------------
	// open the poser remote
	rposer = new vrpn_Poser_Remote( POSER_NAME, connection );
	printf( "Poser's name is %s.\n", POSER_NAME );
	create_and_link_poser_server();

	/* 
	 * main interactive loop
	 */
        int repeat_tests = 4;
	while ( repeat_tests > 0 ) {
		static	long	secs = 0;
		struct	timeval	now;

		// Let the servers, clients and connection do their things
		send_analog_output_once_in_a_while();
                ranaout->mainloop(); // The remote is on the server for AnalogOutput
                sanaout->mainloop(); // The server is on the client for AnalogOutput
		send_analog_once_in_a_while();
		sana->mainloop();
		rana->mainloop();
		send_text_once_in_a_while();
		rtext->mainloop();
		sdial->mainloop();
		rdial->mainloop();
		sbtn->mainloop();
		rbtn->mainloop();
		stkr->mainloop();
		rtkr->mainloop();
		send_poser_once_in_a_while();
		rposer->mainloop();
		sposer->mainloop();
		connection->mainloop();

		// Every 2 seconds, delete the old remotes and create new ones
		vrpn_gettimeofday(&now, NULL);
		if (secs == 0) {	// First time through
			secs = now.tv_sec;
		}
		if ( now.tv_sec - secs >= 2 ) {
			secs = now.tv_sec;
			printf("\nDeleting and restarting _Remote objects\n");
			delete rtkr;
			delete rdial;
			delete rbtn;
			delete rtext;
			delete rana;
			delete sanaout;
			delete sposer;
			create_and_link_tracker_remote();
			create_and_link_dial_remote();
			create_and_link_button_remote();
			create_and_link_text_remote();
			create_and_link_analog_remote();
			create_and_link_analog_output_server();
			create_and_link_poser_server();
                        --repeat_tests;
		}

		// Sleep for 1ms each iteration so we don't eat the CPU
		vrpn_SleepMsecs(1);
	}
        if ( (pcount == 0) || (vcount == 0) || (acount == 0) ||
             (dcount == 0) || (tcount == 0) || (ancount == 0) ||
             (aocount == 0) ||
             (bcount == 0) || (pocount == 0) || (prcount == 0) ) {
               fprintf(stderr,"Did not get callbacks from one or more device\n");
               return -1;
        }

        printf("\nDeleting _Remote objects\n");
        delete rtkr;
        delete rdial;
        delete rbtn;
        delete rtext;
        delete rana;
        delete ranaout;
        delete rposer;

        printf("Testing whether two connections to a tracker and to a button each get their own messages.\n");
        vrpn_Tracker_Remote *t1 = new vrpn_Tracker_Remote(TRACKER_NAME, connection);
        t1->register_change_handler(NULL, handle_pos1);
        vrpn_Tracker_Remote *t2 = new vrpn_Tracker_Remote(TRACKER_NAME, connection);
        t2->register_change_handler(NULL, handle_pos2);
        vrpn_Button_Remote *b1 = new vrpn_Button_Remote(BUTTON_NAME, connection);
        b1->register_change_handler(NULL, handle_button1);
        vrpn_Button_Remote *b2 = new vrpn_Button_Remote(BUTTON_NAME, connection);
        b2->register_change_handler(NULL, handle_button2);
        unsigned long secs;
        struct timeval start, now;
        vrpn_gettimeofday(&start, NULL);
        do {
          stkr->mainloop();
          sbtn->mainloop();
          t1->mainloop();
          t2->mainloop();
          b1->mainloop();
          b2->mainloop();
          connection->mainloop();

          vrpn_gettimeofday(&now, NULL);
          secs = now.tv_sec - start.tv_sec;
        } while (secs <= 2);
        if ( (p1count == 0) || (p2count == 0) ) {
               fprintf(stderr,"Did not get callbacks from trackers\n");
               return -1;
        }
        if ( (b1count == 0) || (b2count == 0) ) {
               fprintf(stderr,"Did not get callbacks from buttons\n");
               return -1;
        }

	printf("Deleting extra remote objects\n");
	delete t1;
	delete t2;
	delete b1;
	delete b2;

        printf("Deleting servers and connection\n");
        delete stkr;
        delete sbtn;
        delete sdial;
        delete stext;
        delete sana;
        delete sanaout;
        delete sposer;
        connection->removeReference();

        printf("Success!\n");
	return 0;

}   /* main */