예제 #1
0
void vrpn_Imager_Stream_Buffer::handle_got_first_connection(void)
{
    // There should be no thread in existence when this call is made.
    // If there is, kill it and complain.
    if (d_logging_thread->running()) {
        struct timeval now;
        vrpn_gettimeofday(&now, NULL);
        send_text_message(
            "handle_got_first_connection: Thread running when it should not be",
            now, vrpn_TEXT_ERROR);
        d_logging_thread->kill();
        return;
    }

    // Reset the shared state before starting the thread running.
    d_shared_state.init();

    // Create a thread whose userdata points at the object that
    // created it.  Then call the start function on that thread and wait
    // for its vrpn_Imager_Remote to receive the info from the remote server
    // it has connected to.  We time out after a few seconds if we don't
    // get the response, leaving us with a presumably broken connection
    // to the server.
    if (!d_logging_thread->go()) {
        struct timeval now;
        vrpn_gettimeofday(&now, NULL);
        send_text_message(
            "handle_got_first_connection: Failed to start logging thread", now,
            vrpn_TEXT_ERROR);
        delete d_logging_thread;
        d_logging_thread = NULL;
        return;
    }
    struct timeval start, now;
    vrpn_gettimeofday(&start, NULL);
    do {
        const char *channelBuffer = NULL;
        if (d_shared_state.get_imager_description(
                d_nRows, d_nCols, d_nDepth, d_nChannels, &channelBuffer)) {
            int i;
            const char *bufptr = channelBuffer;
            for (i = 0; i < d_nChannels; i++) {
                d_channels[i].unbuffer(&bufptr);
            }
            delete[] const_cast<char *>(channelBuffer);
            return;
        }

        vrpn_SleepMsecs(1);
        vrpn_gettimeofday(&now, NULL);
    } while (vrpn_TimevalDiff(now, start).tv_sec < 3);

    // Timed out, so we won't be hearing from the server!
    vrpn_gettimeofday(&now, NULL);
    send_text_message("handle_got_first_connection: Didn't hear from server.",
                      now, vrpn_TEXT_WARNING);
}
예제 #2
0
void	vrpn_BaseClassUnique::client_mainloop(void)
{
    struct  timeval now;
    struct  timeval diff;

    // The first time through, set up a callback handler for the pong message so that we
    // know when we are getting them.  Also set up a handler for the system dropped-connection
    // message so that we can initiate a ping cycle when that happens.  Also, we'll initiate
    // the ping cycle here.

    if (d_first_mainloop && (d_connection != NULL)) {

	// Set up handlers for the pong message and for the system connection-drop message
	register_autodeleted_handler(d_pong_message_id, handle_pong, this, d_sender_id);
	register_autodeleted_handler(d_connection->register_message_type(vrpn_dropped_connection),
	    handle_connection_dropped, this);

	// Initiate a ping cycle;
	initiate_ping_cycle();

	// No longer first time through mainloop.
	d_first_mainloop = 0;
    }

    // If we are in the middle of a ping cycle...
    // Check if we've heard, if it has been long enough since we gave a warning or error (>= 1 sec).
    // If it has been three seconds or more since we sent our first ping,
    // start giving warnings.  If it has been ten seconds or more since we got one,
    // switch to errors.  New ping requests go out each second.

    if (d_unanswered_ping) {
    
        vrpn_gettimeofday(&now, NULL);
        diff = vrpn_TimevalDiff(now, d_time_last_warned);
        vrpn_TimevalNormalize(diff);
        
        if (diff.tv_sec >= 1) {
            
            // Send a new ping, since it has been a second since the last one
            d_connection->pack_message(0, now, d_ping_message_id, d_sender_id,
                                       NULL, vrpn_CONNECTION_RELIABLE);
            
            // Send another warning or error, and say if we're flatlined (10+ seconds)
            d_time_last_warned = now;
            if (!shutup) {
                diff = vrpn_TimevalDiff(now, d_time_first_ping);
                vrpn_TimevalNormalize(diff);	    
                if (diff.tv_sec >= 10) {
                    send_text_message("No response from server for >= 10 seconds", now, vrpn_TEXT_ERROR, diff.tv_sec);
                    d_flatline = 1;
                } else if (diff.tv_sec >= 3) {
                    send_text_message("No response from server for >= 3 seconds", now, vrpn_TEXT_WARNING, diff.tv_sec);
                }
            }
        }
    }
}
예제 #3
0
// This routine is called each time through the server's main loop. It will
// take a course of action depending on the current status of the Orb,
// either trying to reset it or trying to get a reading from it.
void	vrpn_GlobalHapticsOrb::mainloop()
{
  struct  timeval last_poll_sent = {0,0};

  // Call the generic server mainloop, since we are a server
  server_mainloop();

  switch(d_status) {
    case STATUS_RESETTING:
      reset();
      break;

    case STATUS_SYNCING:
      {
	// It turns out to be important to get the report before checking
	// to see if it has been too long since the last report.  This is
	// because there is the possibility that some other device running
	// in the same server may have taken a long time on its last pass
	// through mainloop().  Trackers that are resetting do this.  When
	// this happens, you can get an infinite loop -- where one tracker
	// resets and causes the other to timeout, and then it returns the
	// favor.  By checking for the report here, we reset the timestamp
	// if there is a report ready (ie, if THIS device is still operating).
	while (get_report()) {};    // Keep getting reports as long as they come
	struct timeval current_time;
	vrpn_gettimeofday(&current_time, NULL);

	// If we haven't heard in a while (this can be normal), send a reset
	// request to the device -- this will cause a response of 0xfc, which
	// will be ignored when it arrives.  Reset the poll interval when a
	// poll is sent.
	if ( duration(current_time, d_timestamp) > POLL_INTERVAL ) {
	  last_poll_sent = current_time;
	  vrpn_write_characters(serial_fd, &reset_char, 1);
	}

	// If we still haven't heard from the device after a longer time,
	// fail and go into reset mode.
	if ( duration(current_time, d_timestamp) > TIMEOUT_INTERVAL ) {
	  send_text_message("Too long since last report, resetting", current_time, vrpn_TEXT_ERROR);
	  d_status = STATUS_RESETTING;
	}
      }
      break;

    default:
      send_text_message("vrpn_GlobalHapticsOrb: Unknown mode (internal error), resetting", d_timestamp, vrpn_TEXT_ERROR);
      d_status = STATUS_RESETTING;
      break;
  }
}
예제 #4
0
Rozmowa::Rozmowa(QWidget *parent, const QModelIndex& index, Model* mod ) :
    QDialog(parent),
    ui(new Ui::Rozmowa)
{
    ui->setupUi(this);
    message = this->findChild<QPlainTextEdit*>("wiadomosc");//message qplaintext wyslanie
    message->insertPlainText("");
    message->clear();
    QPushButton* send = this->findChild<QPushButton*>("send");
    model = mod;

    QModelIndex ind = model->index( index.row(), 0, QModelIndex() );
    //((MainWindow*)this->parent())->logged_user.numer;
    QVariant value = model->data( ind, Qt::DisplayRole).toString();
    QString title = value.toString();
    ind = model->index( index.row(), 2 );
    char numer[9];
    itoa(((MainWindow*)this->parent())->logged_user.numer,numer,10);
    title += " - (";
    //title += ind.data().toString();
    title += " moj numer: ";
    title += numer;
    title += ")";

    setWindowTitle(title);

    QListView* rozmowa = this->findChild<QListView*>("rozmowa");
    rozmowa->setModel(model);
    rozmowa->setRootIndex(index);

    connect(send, SIGNAL(clicked()), ((MainWindow*)this->parent())->socket, SLOT(send_text_message()));
    connect(this->model, SIGNAL(syg_rozm(int)),this,SLOT(syg_rozm_slot(int)));
}
예제 #5
0
파일: pilot.c 프로젝트: Comanche93/eech
void send_pilot_joined_message (entity *en)
{
	int
		player_count;

	char
		text [200];

	//
	// Client now joined in..... send system message to other players
	//

	player_count = get_session_pilot_count ();

	if (player_count == 1)
	{
		sprintf (text, "%s %s - 1 %s",
							get_local_entity_string (en, STRING_TYPE_PILOTS_NAME),
							get_trans ("joined"),
							get_trans ("player connected"));
	}
	else
	{
		sprintf (text, "%s %s - %d %s",
							get_local_entity_string (en, STRING_TYPE_PILOTS_NAME),
							get_trans ("joined"),
							player_count,
							get_trans ("players connected"));
	}

	send_text_message (en, NULL, MESSAGE_TEXT_SYSTEM_NEW_PILOT, text);
	
	server_log (text); // Jabberwock Server log
}
예제 #6
0
파일: ca_chat.c 프로젝트: Comanche93/eech
static void chat_input_function (ui_object *obj, void *arg)
{
	entity 	// Jabberwock 040213 Chat send after Enter
		*target;
		
	const char
		*text;
		
	text = get_ui_object_text (chat_input);

	if (text)
	{
		if (strlen (text) > 0)
		{
			set_ui_object_text (chat_current_text, get_ui_object_text (chat_input));

			// Jabberwock 040213 Chat send after Enter
			target = get_local_entity_safe_ptr (get_ui_object_item_number (chat_send_button));
		
			if (target)
			{
				send_text_message (get_pilot_entity (), target, MESSAGE_TEXT_PILOT_STRING, text);
			}
			// Jabberwock 040202 ends
		}
	}

	set_ui_object_drawable (chat_current_text, TRUE);

	set_ui_object_drawable (chat_input, FALSE);
}
예제 #7
0
int vrpn_Nikon_Controls::set_channel(unsigned chan_num, vrpn_float64 value)
{
  // Ask to change the focus if this was channel 0.  Also, store away where we
  // asked the focus to go to so that we can know where we are when we get there
  // (the response from the microscope just says "we got here!).
  if ( (int)chan_num >= o_num_channel ) {
    char msg[1024];
    sprintf(msg,"vrpn_Nikon_Controls::set_channel(): Index out of bounds (%d of %d), value %lg\n",
      chan_num, o_num_channel, value);
    vrpn_gettimeofday(&o_timestamp, NULL);
    send_text_message(msg, o_timestamp, vrpn_TEXT_ERROR);
  }

  char  msg[256];
  sprintf(msg, "fSMV%ld\r", (long)value);
#ifdef	VERBOSE
  printf("Nikon Control: Asking to move to %ld with command %s\n", (long)value, msg);
#endif
  if (vrpn_write_characters(serial_fd, (unsigned char *)msg, strlen(msg)) != (int)strlen(msg)) {
    fprintf(stderr, "vrpn_Nikon_Controls::set_channel(): Can't write command\n");
    return -1;
  }
  if (vrpn_drain_output_buffer(serial_fd)) {
    fprintf(stderr, "vrpn_Nikon_Controls::set_channel(): Can't drain command\n");
    return -1;
  }
  _requested_focus = value;

  return 0;
}
예제 #8
0
파일: ca_chat.c 프로젝트: Comanche93/eech
static void notify_send_message (ui_object *obj, void *arg)
{
	entity
		*target;
		
	const char
		*text;
		
	target = get_local_entity_safe_ptr (get_ui_object_item_number (chat_send_button));

	if (target)
	{
		text = get_ui_object_text (chat_current_text);

		if (text)
		{
			if (strlen (text) > 0)
			{
				send_text_message (get_pilot_entity (), target, MESSAGE_TEXT_PILOT_STRING, text);

				return;
			}
		}
	}
}
예제 #9
0
int	vrpn_GlobalHapticsOrb::reset(void)
{
	struct	timeval	timeout;
	unsigned char	inbuf[1];	      // Response from the Orb
	int	ret;

	//-----------------------------------------------------------------------
	// Set the values back to zero for all buttons, analogs and encoders
	clear_values();

	//-----------------------------------------------------------------------
	// Clear the input buffer to make sure we're starting with a clean slate.
	// Send the "reset" command to the box, then wait for a response and
	// make sure it matches what we expect.
	vrpn_flush_input_buffer(serial_fd);
	vrpn_write_characters(serial_fd, &reset_char, 1);
	timeout.tv_sec = 2;
	timeout.tv_usec = 0;
	ret = vrpn_read_available_characters(serial_fd, inbuf, 1, &timeout);
	if (ret < 0) {
	  perror("vrpn_GlobalHapticsOrb::reset(): Error reading from Orb\n");
	  return -1;
	}
	if (ret == 0) {
	  send_text_message("vrpn_GlobalHapticsOrb::reset(): No response from Orb", d_timestamp, vrpn_TEXT_ERROR);
	  return -1;
	}
	if (inbuf[0] != 0xfc) {
	  char	message[1024];
	  sprintf(message, "vrpn_GlobalHapticsOrb::reset(): Bad response from Orb (%02X)", inbuf[0]);
	  send_text_message(message, d_timestamp, vrpn_TEXT_ERROR);
	  return -1;
	}

	//-----------------------------------------------------------------------
	// Figure out how many characters to expect in each report from the device,
	// which is just 1 for the Orb.
	d_expected_chars = 1;

	vrpn_gettimeofday(&d_timestamp, NULL);	// Set watchdog now

	send_text_message("vrpn_GlobalHapticsOrb::reset(): Reset complete (this is good)", d_timestamp, vrpn_TEXT_ERROR);

	// Set the mode to synchronizing
	d_status = STATUS_SYNCING;
	return 0;
}
예제 #10
0
void vrpn_Button::set_momentary(vrpn_int32 which_button) {
  if (which_button >= num_buttons) {
      char msg[200];
       sprintf(msg, "vrpn_Button::set_momentary() buttons id %d is greater than the number of buttons(%d)\n", which_button, num_buttons);
       send_text_message(msg, timestamp, vrpn_TEXT_ERROR);
    return;
  }
  PACK_ADMIN_MESSAGE(which_button,vrpn_BUTTON_MOMENTARY);
}
예제 #11
0
void vrpn_Button_Filter::set_momentary(vrpn_int32 which_button) {
  if (which_button >= num_buttons) {
      char msg[200];
       sprintf(msg, "vrpn_Button::set_momentary() buttons id %d is greater than the number of buttons(%d)\n", which_button, num_buttons);
       send_text_message(msg, timestamp, vrpn_TEXT_ERROR);
    return;
  }
  buttonstate[which_button] = vrpn_BUTTON_MOMENTARY;
  if(send_alerts)PACK_ALERT_MESSAGE(which_button,vrpn_BUTTON_TOGGLE_OFF);
}
예제 #12
0
/**
 * Parse a text update mesage.
 *
 * If the message can be parsed the message data is sent.
 *
 * @param root the JSON message
 * @returns false if any error, true otherwise.
 */
bool vrpn_Tracker_JsonNet::_parse_text(const Json::Value& root)
{
	const Json::Value& valueTextStatus = root[MSG_KEY_TEXT_DATA];
	if (!valueTextStatus.empty() && valueTextStatus.isConvertibleTo(Json::stringValue)) {
		send_text_message(vrpn_TEXT_NORMAL) << valueTextStatus.asString();
		return true;
	}
	fprintf(stderr, "vrpn_Tracker_JsonNet::_parse_text parse error : missing text");
	return false;
}
예제 #13
0
void vrpn_3DConnexion::mainloop()
{
#if defined(VRPN_USE_HID)
	// Full reports are 7 bytes long.
	// XXX If we get a 2-byte report mixed in, then something is going to get
	// truncated.
	update();
#elif defined(linux) && !defined(VRPN_USE_HID)
    struct timeval zerotime;
    fd_set fdset;
    struct input_event ev;
    int i;

    zerotime.tv_sec = 0;
    zerotime.tv_usec = 0;

    FD_ZERO(&fdset);                      /* clear fdset              */
    FD_SET(fd, &fdset);                   /* include fd in fdset      */
    int moreData = 0;
    do {
        vrpn_noint_select(fd + 1, &fdset, NULL, NULL, &zerotime);
        moreData = 0;
        if (FD_ISSET(fd, &fdset)) {
            moreData = 1;
            if (vrpn_noint_block_read(fd, reinterpret_cast<char*>(&ev), sizeof(struct input_event)) != sizeof(struct input_event)) {
                send_text_message("Error reading from vrpn_3DConnexion", vrpn_Analog::timestamp, vrpn_TEXT_ERROR);
                if (d_connection) { d_connection->send_pending_reports(); }
                return;
            }
            switch (ev.type) {
                case EV_KEY:    // button movement
                    vrpn_gettimeofday((timeval *)&this->vrpn_Button::timestamp, NULL);
                    buttons[ev.code & 0x0ff] = ev.value;
                    break;
 
                case EV_REL:    // axis movement
                case EV_ABS:    // new kernels send more logical _ABS instead of _REL
                    vrpn_gettimeofday((timeval *)&this->vrpn_Analog::timestamp, NULL);
                    // Convert from short to int to avoid a short/double conversion
                    // bug in GCC 3.2.
                    i = ev.value;
                    channel[ev.code] = static_cast<double>(i)/400.0;           
                    break;
 
                default:
                    break;
            }
        }
        report_changes();
    } while (moreData == 1);
#endif

    server_mainloop();
    vrpn_gettimeofday(&_timestamp, NULL);
}
예제 #14
0
파일: vrpn_Joylin.C 프로젝트: ajmontag/vrpn
void vrpn_Joylin::mainloop(void) {
  struct timeval zerotime;
  fd_set fdset;
  struct js_event js;
  int i;

  zerotime.tv_sec = 0;
  zerotime.tv_usec = 0;
  
  // Since we are a server, call the generic server mainloop()
  server_mainloop();
 

  FD_ZERO(&fdset);                      /* clear fdset              */
  FD_SET(fd, &fdset);                   /* include fd in fdset      */ 
  select(fd+1, &fdset, NULL, NULL, &zerotime);
    if (FD_ISSET(fd, &fdset)){            
      if (read(fd, &js, sizeof(struct js_event)) != sizeof(struct js_event)) {
		  send_text_message("Error reading from joystick", vrpn_Analog::timestamp, vrpn_TEXT_ERROR);
		  if (d_connection) { d_connection->send_pending_reports(); }
		  return;
      }
      switch(js.type & ~JS_EVENT_INIT) {
      case JS_EVENT_BUTTON:
                  vrpn_gettimeofday((timeval *)&this->vrpn_Button::timestamp, NULL);
		  buttons[js.number] = js.value;
		  break;
      case JS_EVENT_AXIS:
		  vrpn_gettimeofday((timeval *)&this->vrpn_Analog::timestamp, NULL);
		  channel[js.number] = js.value / 32767.0;           /* FIX LATER */
		  break;
      }

#ifdef DEBUG
    if (num_channel) {
	printf("Axes: ");
	 for (i = 0; i < num_channel; i++) {
	  printf("%2d:%.3f ", i, channel[i]);
	 }
    }
    if (num_buttons) {
	 printf("Buttons: ");
	 for (i = 0; i < num_buttons; i++) {
	  printf("%2d:%s ", i, buttons[i] ? "on " : "off");
	 }
    }
    printf("\n");
    fflush(stdout);
#endif	
      
      vrpn_Analog::report_changes(); // report any analog event;
      vrpn_Button::report_changes(); // report any button event;
    }
}
예제 #15
0
void vrpn_Tracker_OSVRHackerDevKit::mainloop()
{
    vrpn_gettimeofday(&_timestamp, NULL);

    update();

    if (connected() && !_wasConnected) {
        send_text_message(vrpn_TEXT_NORMAL)
            << "Successfully connected to OSVR Hacker Dev Kit HMD, receiving "
               "version "
            << int(_reportVersion) << " reports.";

        if (!_knownVersion) {

            send_text_message(vrpn_TEXT_WARNING)
                << "Connected to OSVR Hacker Dev Kit HMD, receiving "
                   "version "
                << int(_reportVersion)
                << " reports, newer than what is specifically recognized. You "
                   "may want to update your server to best make use of this "
                   "new report format.";
        }
    }
    if (!connected()) {
        channel[0] = 0;
        channel[1] = STATUS_UNKNOWN;
        vrpn_Analog::report_changes();
    }

    _wasConnected = connected();

    if (!_wasConnected) {
        m_acceptor->reset();
        reconnect();
    }

    server_mainloop();
}
예제 #16
0
void vrpn_Button::set_toggle(vrpn_int32 which_button, vrpn_int32 current_state) {
  if (which_button >= num_buttons) {
    char msg[200];
    sprintf(msg, "vrpn_Button::set_toggle() buttons id %d is greater then the number of buttons(%d)\n", which_button, num_buttons);
    send_text_message(msg, timestamp, vrpn_TEXT_ERROR);
    return;
  }
  if (current_state==vrpn_BUTTON_TOGGLE_ON) {
    PACK_ADMIN_MESSAGE(which_button,vrpn_BUTTON_TOGGLE_ON);
  }
  else{
    PACK_ADMIN_MESSAGE(which_button,vrpn_BUTTON_TOGGLE_OFF);
  }
}
예제 #17
0
void vrpn_Analog_5dtUSB::mainloop() {
	vrpn_gettimeofday(&_timestamp, NULL);

	update();

	if (connected() && !_wasConnected) {
		std::ostringstream ss;
		ss << "Successfully connected to 5DT glove, " << get_description();
        send_text_message(ss.str().c_str(), _timestamp, vrpn_TEXT_NORMAL);
	}
	_wasConnected = connected();

	server_mainloop();
}
   // ----------------------------------------------------------------------
   void
   ExampleTestbedServiceProcessor::
   process_text_message( TextMessage& message )
      throw()
   {
      std::cout << "ExampleTestbedServiceProcessor::process_text" << std::endl;
      std::cout << "   me  : " << owner().label() << std::endl;
      std::cout << "   from: " << message.source << std::endl;
      std::cout << "   at  : " << message.timestamp << std::endl;
      std::cout << "   msg : " << message.message << std::endl;
      std::cout << "   lev : " << message.level << std::endl;

      std::string reply("my reply!");
      send_text_message( reply, MESSAGE_LEVEL_DEBUG );
   }
예제 #19
0
파일: vrpn_Text.C 프로젝트: BlueBrain/vrpn
int vrpn_Text_Sender::send_message(const char *msg, 				  
                            vrpn_TEXT_SEVERITY type,
                            vrpn_uint32 level,
			    const struct timeval time)
{
  struct timeval now;
  
  // Replace the time value with the current time if the user passed in the
  // constant time referring to "now".
  if ( (time.tv_sec == vrpn_TEXT_NOW.tv_sec) && (time.tv_usec == vrpn_TEXT_NOW.tv_usec) ) {
    vrpn_gettimeofday(&now, NULL);
  } else {
    now = time;
  }  
  // send message, time, type and level
  return send_text_message(msg, now, type, level);
}
예제 #20
0
void vrpn_XInputGamepad::mainloop() {
	XINPUT_STATE state;
	DWORD rv;

	server_mainloop();
	if ((rv = XInputGetState(_controllerIndex, &state)) != ERROR_SUCCESS) {
		char errMsg[256];
		struct timeval now;

		if (rv == ERROR_DEVICE_NOT_CONNECTED)
			sprintf(errMsg, "XInput device %u not connected", _controllerIndex);
		else
			sprintf(errMsg, "XInput device %u returned Windows error code %u",
				_controllerIndex, rv);

		vrpn_gettimeofday(&now, NULL);
		send_text_message(errMsg, now, vrpn_TEXT_ERROR);
		return;
	}

	// Set device state in VRPN_Analog
	channel[0] = normalize_axis(state.Gamepad.sThumbLX, XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
	channel[1] = normalize_axis(state.Gamepad.sThumbLY, XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
	channel[2] = normalize_axis(state.Gamepad.sThumbRX, XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
	channel[3] = normalize_axis(state.Gamepad.sThumbRY, XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
	channel[4] = normalize_dpad(state.Gamepad.wButtons);
	channel[5] = normalize_trigger(state.Gamepad.bLeftTrigger);
	channel[6] = normalize_trigger(state.Gamepad.bRightTrigger);

	// Set device state in VRPN_Button
	// Buttons are listed in DirectInput ordering
	buttons[0] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0;
	buttons[1] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0;
	buttons[2] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0;
	buttons[3] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0;
	buttons[4] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) != 0;
	buttons[5] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) != 0;
	buttons[6] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) != 0;
	buttons[7] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) != 0;
	buttons[8] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0;
	buttons[9] = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0;

	vrpn_gettimeofday(&_timestamp, NULL);
	report_changes();
}
예제 #21
0
int
server_logic(client_t *c, proto_msg_t *msg)
{
    TRACE_MSG(msg);

    switch (proto_msg_type(msg)) {
        case MSG_HELLO:
            return (handle_hello(c, msg));
        case MSG_OP:
            return (handle_op(c, msg));
        case MSG_TEXT:
            return (handle_text(c, msg));
        case MSG_NUM:
            return (handle_num(c, msg));
        default:
            return (send_text_message(c, "thank you!"));
    }
}
예제 #22
0
void vrpn_Tracker_Flock_Parallel_Slave::mainloop()
{
  // We don't call the generic server mainloop code, because the master unit
  // will have done that for us.

  switch (status) {
  case vrpn_TRACKER_SYNCING:
  case vrpn_TRACKER_PARTIAL:
    {
	// It turns out to be important to get the report before checking
	// to see if it has been too long since the last report.  This is
	// because there is the possibility that some other device running
	// in the same server may have taken a long time on its last pass
	// through mainloop().  Trackers that are resetting do this.  When
	// this happens, you can get an infinite loop -- where one tracker
	// resets and causes the other to timeout, and then it returns the
	// favor.  By checking for the report here, we reset the timestamp
	// if there is a report ready (ie, if THIS device is still operating).
	while (get_report()) {
	    send_report();
	}
	struct timeval current_time;
	vrpn_gettimeofday(&current_time, NULL);
	if ( duration(current_time,timestamp) > MAX_TIME_INTERVAL) {
		fprintf(stderr,"Tracker failed to read... current_time=%ld:%ld, timestamp=%ld:%ld\n",
				current_time.tv_sec, static_cast<long>(current_time.tv_usec),
				timestamp.tv_sec, static_cast<long>(timestamp.tv_usec));
		send_text_message("Too long since last report, resetting", current_time, vrpn_TEXT_ERROR);
		status = vrpn_TRACKER_FAIL;
	}
    }
  break;
  // master resets us
  case vrpn_TRACKER_RESETTING:
    break;
  case vrpn_TRACKER_FAIL:
    // here we just fail and let the master figure out that we have
    // failed and need to be reset
    fprintf(stderr, "\nvrpn_Tracker_Flock_Parallel_Slave %d: tracker "
	    "failed, trying to reset ...", d_sensor);
    break;
  }
}
예제 #23
0
void vrpn_Tracker_OSVRHackerDevKit::mainloop()
{
    vrpn_gettimeofday(&_timestamp, NULL);

    update();

    if (connected() && !_wasConnected) {
        send_text_message("Successfully connected to OSVR Hacker Dev Kit HMD.",
                          _timestamp, vrpn_TEXT_NORMAL);
    }
    _wasConnected = connected();

    if (!_wasConnected) {
        m_acceptor->reset();
        reconnect();
    }

    server_mainloop();
}
예제 #24
0
void ContactView::sendChatMessage()
{
  auto msg = ui->chat_input->toPlainText();
  if (msg.size() != 0)
  {
    auto                               app = bts::application::instance();
    auto                               profile = app->get_profile();
    auto                               idents = profile->identities();
    bts::bitchat::private_text_message text_msg(msg.toUtf8().constData() );
    if (idents.size() )
    {
      fc::ecc::private_key my_priv_key = profile->get_keychain().get_identity_key(idents[0].dac_id_string);
      app->send_text_message(text_msg, _current_contact.public_key, my_priv_key);
      appendChatMessage("me", msg);
    }

    ui->chat_input->setPlainText(QString());
  }
}
예제 #25
0
파일: vrpn_Mouse.C 프로젝트: ASPePeX/vrpn
void vrpn_Button_SerialMouse::mainloop()
{
	// Call the generic server mainloop, since we are a server
	server_mainloop();
 
    switch (status) {
	case BUTTON_READY:
	    read();
	    report_changes();
	    break;
	case BUTTON_FAIL:
      	{	
	    if (printed_error)	break;
	    printed_error = true;
	    send_text_message("vrpn_Button_SerialMouse failure!", timestamp, vrpn_TEXT_ERROR);
        }
      	break;
    }
}
예제 #26
0
void vrpn_Freespace::mainloop(void) 
{
	server_mainloop();
    struct freespace_message s;

    /*
     * Send configuration information to the device repeatedly to force the
     * device into the correct mode.  This method ensures the correct mode 
     * even if the Freespace device was asleep during initialization or if
     * the tracker resets.
     */
    struct timeval timestamp;
    vrpn_gettimeofday(&timestamp, NULL);
    if (_timestamp.tv_sec != timestamp.tv_sec) {
        _timestamp.tv_sec = timestamp.tv_sec;
        deviceConfigure();
    }

	// Do not block, read as many messages as 
    while (FREESPACE_SUCCESS == freespace_readMessage(_freespaceDevice, &s, 0)) {
	    switch(s.messageType) {
		    case FREESPACE_MESSAGE_LINKSTATUS:
			    handleLinkStatus(s.linkStatus);
			    break;
		    case FREESPACE_MESSAGE_BODYFRAME:
			    handleBodyFrame(s.bodyFrame);
			    break;
		    case FREESPACE_MESSAGE_USERFRAME:
			    handleUserFrame(s.userFrame);
			    break;
            case FREESPACE_MESSAGE_ALWAYSONRESPONSE:
                break;
            case FREESPACE_MESSAGE_DATAMODERESPONSE:
                break;
		    default:
                send_text_message("Received an unhandled message from freespace device", timestamp, vrpn_TEXT_WARNING);
			    break;
	    }
    }
}
예제 #27
0
파일: pilot.c 프로젝트: Comanche93/eech
void send_pilot_quit_message (entity *en)
{
	int
		player_count;

	char
		text [200];

	//
	// Client now joined in..... send system message to other players
	//

	player_count = get_session_pilot_count () - 1;

	if (player_count == 1)
	{
		sprintf (text, "%s %s - 1 %s",
							get_local_entity_string (en, STRING_TYPE_PILOTS_NAME),
							get_trans ("quit"),
							get_trans ("player connected"));
	}
	else
	{
		sprintf (text, "%s %s - %d %s",
							get_local_entity_string (en, STRING_TYPE_PILOTS_NAME),
							get_trans ("quit"),
							player_count,
							get_trans ("players connected"));
	}

	send_text_message (en, NULL, MESSAGE_TEXT_SYSTEM_NEW_PILOT, text);
	
	server_log (text); // Jabberwock Server log
	
	if ((command_line_pause_server) && (player_count <= 1)) // 040220 Jabberwock Pause server, changed to <=1 by Werewolf
	{
		force_pause_acceleration();
		server_log ("Server paused");
	}
}	
예제 #28
0
파일: vrpn_CerealBox.C 프로젝트: bilke/vrpn
// This routine is called each time through the server's main loop. It will
// take a course of action depending on the current status of the cerealbox,
// either trying to reset it or trying to get a reading from it.
void	vrpn_CerealBox::mainloop()
{
  // Call the generic server mainloop, since we are a server
  server_mainloop();

  switch(status) {
    case STATUS_RESETTING:
	reset();
	break;

    case STATUS_SYNCING:
    case STATUS_READING:
      {
		// It turns out to be important to get the report before checking
		// to see if it has been too long since the last report.  This is
		// because there is the possibility that some other device running
		// in the same server may have taken a long time on its last pass
		// through mainloop().  Trackers that are resetting do this.  When
		// this happens, you can get an infinite loop -- where one tracker
		// resets and causes the other to timeout, and then it returns the
		// favor.  By checking for the report here, we reset the timestamp
		// if there is a report ready (ie, if THIS device is still operating).
		while (get_report()) {};    // Keep getting reports as long as they come
		struct timeval current_time;
		vrpn_gettimeofday(&current_time, NULL);
		if ( duration(current_time,timestamp) > MAX_TIME_INTERVAL) {
			fprintf(stderr,"CerealBox failed to read... current_time=%ld:%ld, timestamp=%ld:%ld\n",
					current_time.tv_sec, static_cast<long>(current_time.tv_usec),
					timestamp.tv_sec, static_cast<long>(timestamp.tv_usec));
			send_text_message("Too long since last report, resetting", current_time, vrpn_TEXT_ERROR);
			status = STATUS_RESETTING;
		}
      }
      break;

    default:
	fprintf(stderr,"vrpn_CerealBox: Unknown mode (internal error)\n");
	break;
  }
}
예제 #29
0
void vrpn_XInputGamepad::update_vibration() {
	XINPUT_VIBRATION vibration;

	vibration.wLeftMotorSpeed = _motorSpeed[0];
	vibration.wRightMotorSpeed = _motorSpeed[1];

	DWORD rv = XInputSetState(_controllerIndex, &vibration);
	if (rv != ERROR_SUCCESS) {
		char errMsg[256];
		struct timeval now;

		if (rv == ERROR_DEVICE_NOT_CONNECTED)
			sprintf(errMsg, "XInput device %u not connected", _controllerIndex);
		else
			sprintf(errMsg, "XInput device %u returned Windows error code %u",
				_controllerIndex, rv);

		vrpn_gettimeofday(&now, NULL);
		send_text_message(errMsg, now, vrpn_TEXT_ERROR);
		return;
	}
}
void vrpn_Tracker_OSVRHackerDevKit::on_data_received(std::size_t bytes,
                                                     vrpn_uint8 *buffer)
{
    if (bytes != 32) {
        send_text_message(vrpn_TEXT_WARNING)
            << "Received a report " << bytes
            << " in length, but expected it to be 32 bytes. Discarding.";
        return;
    }

    vrpn_uint8 version = vrpn_unbuffer_from_little_endian<vrpn_uint8>(buffer);
    /// @todo Verify that version is what we expect.
    vrpn_uint8 msg_seq = vrpn_unbuffer_from_little_endian<vrpn_uint8>(buffer);

    // Signed, 16-bit, fixed-point numbers in Q1.14 format.
    typedef vrpn::FixedPoint<1, 14> FixedPointValue;
    d_quat[Q_X] =
        FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
            .get<vrpn_float64>();
    d_quat[Q_Y] =
        FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
            .get<vrpn_float64>();
    d_quat[Q_Z] =
        FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
            .get<vrpn_float64>();
    d_quat[Q_W] =
        FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
            .get<vrpn_float64>();

    vrpn_Tracker::timestamp = _timestamp;
    char msgbuf[512];
    int len = vrpn_Tracker::encode_to(msgbuf);
    if (d_connection->pack_message(len, _timestamp, position_m_id, d_sender_id,
                                   msgbuf, vrpn_CONNECTION_LOW_LATENCY)) {
        fprintf(
            stderr,
            "vrpn_Tracker_OSVRHackerDevKit: cannot write message: tossing\n");
    }
}