Exemple #1
0
// static
int vrpn_Mutex_Server::handle_requestMutex(void *userdata, vrpn_HANDLERPARAM p)
{
    vrpn_Mutex_Server *me = (vrpn_Mutex_Server *)userdata;
    const char *b = p.buffer;
    vrpn_int32 remoteId;

    vrpn_unbuffer(&b, &remoteId);

#ifdef VERBOSE
    fprintf(stderr, "vrpn_Mutex_Server::handle_request from %d.\n", remoteId);
#endif

    if (me->d_state == FREE) {
        me->d_state = HELD;

        // BUG BUG BUG - how does the Mutex_Remote recognize that this grant
        // is for it, not for some other?
        me->sendGrantRequest(remoteId);

        return 0;
    }
    else {
        me->sendDenyRequest(remoteId);

        return 0;
    }
}
Exemple #2
0
int vrpn_Dial_Remote::handle_change_message(void *userdata, vrpn_HANDLERPARAM p)
{
    vrpn_Dial_Remote *me = (vrpn_Dial_Remote *)userdata;
    vrpn_DIALCB cp;
    const char *bufptr = p.buffer;

    cp.msg_time = p.msg_time;
    vrpn_unbuffer(&bufptr, &cp.change);
    vrpn_unbuffer(&bufptr, &cp.dial);

    // Go down the list of callbacks that have been registered.
    // Fill in the parameter and call each.
    me->d_callback_list.call_handlers(cp);

    return 0;
}
Exemple #3
0
vrpn_int32 vrpn_Sound::decodeListenerVelocity(const char* buf, vrpn_float64 *velocity) {
	const char *mptr = buf;
	
	for (int i=0;i<4;i++)
	  vrpn_unbuffer(&mptr, &velocity[i]);
	
	return 0;
}
Exemple #4
0
// If the client requests a value for the focus control, then try to set the
// focus to the requested value.
int vrpn_Nikon_Controls::handle_request_message(void *userdata, vrpn_HANDLERPARAM p)
{
    const char	  *bufptr = p.buffer;
    vrpn_int32	  chan_num;
    vrpn_int32	  pad;
    vrpn_float64  value;
    vrpn_Nikon_Controls *me = (vrpn_Nikon_Controls *)userdata;

    // Read the parameters from the buffer
    vrpn_unbuffer(&bufptr, &chan_num);
    vrpn_unbuffer(&bufptr, &pad);
    vrpn_unbuffer(&bufptr, &value);

    // Set the position to the appropriate value, if the channel number is in the
    me->set_channel(chan_num, value);
    return 0;
}
void vrpn_Shared_int32::decodeLamport (const char ** buffer, vrpn_int32 *,
                                vrpn_int32 * newValue, timeval * when,
                                vrpn_LamportTimestamp ** t) const {
  vrpn_uint32 size;
  vrpn_uint32 * array;
  unsigned int i;

  vrpn_unbuffer(buffer, newValue);
  vrpn_unbuffer(buffer, when);
  vrpn_unbuffer(buffer, &size);
  array = new vrpn_uint32 [size];
  for (i = 0; i < size; i++) {
    vrpn_unbuffer(buffer, &array[i]);
  }
  *t = new vrpn_LamportTimestamp(size, array);
  delete array;
}
Exemple #6
0
//Decodes the client sound ID 
vrpn_int32 vrpn_Sound::decodeSoundID(const char* buf, vrpn_SoundID *id)
{
	const char* mptr = buf;

	vrpn_unbuffer(&mptr, id);

	return 0;
}
Exemple #7
0
int vrpn_BaseClassUnique::decode_text_message_from_buffer (char *msg, vrpn_TEXT_SEVERITY *severity,
                         vrpn_uint32 *level, const char *buf)
{
	const char	*bufptr = buf;
	vrpn_uint32	severity_as_uint;

	// Read the type, level and message
	vrpn_unbuffer( &bufptr, &severity_as_uint );
	*severity = (vrpn_TEXT_SEVERITY)(severity_as_uint);
	vrpn_unbuffer( &bufptr, level );
	// Negative length means "unpack until NULL"
	if (vrpn_unbuffer( &bufptr, msg, -(int)(vrpn_MAX_TEXT_LEN)) != 0) {
		return -1;
	}

	return 0;	
}
Exemple #8
0
vrpn_int32 vrpn_Sound::decodeLoadModel_local(const char *buf, char **filename, const int payload) {
	const char *mptr = buf;

	*filename = new char[payload - sizeof(vrpn_SoundID)];
	
	vrpn_unbuffer(&mptr, *filename, payload - sizeof(vrpn_SoundID));
	
	return 0;
}
Exemple #9
0
int vrpn_Poser_Server::handle_change_message(void* userdata,
	    vrpn_HANDLERPARAM p)
{
    vrpn_Poser_Server* me = (vrpn_Poser_Server *)userdata;
    const char* params = (p.buffer);
    int	i;

    vrpn_POSERCB cp;
    // Fill in the parameters to the poser from the message
    if (p.payload_len != (7 * sizeof(vrpn_float64)) ) {
	    fprintf(stderr,"vrpn_Poser_Server: change message payload error\n");
	    fprintf(stderr,"             (got %d, expected %d)\n",
		    p.payload_len, 7 * sizeof(vrpn_float64) );
	    return -1;
    }
    me->p_timestamp = p.msg_time;

    for (i = 0; i < 3; i++) {
	    vrpn_unbuffer(&params, &me->p_pos[i]);
    }
    for (i = 0; i < 4; i++) {
	    vrpn_unbuffer(&params, &me->p_quat[i]);
    }

    // Check the pose against the max and min values of the workspace
    for (i = 0; i < 3; i++) {
        if (me->p_pos[i] < me->p_pos_min[i]) {
            me->p_pos[i] = me->p_pos_min[i];
        }
        else if (me->p_pos[i] > me->p_pos_max[i]) {
            me->p_pos[i] = me->p_pos_max[i];
        }
    }

    ///Now pack the information in a way that user-routine will understand
    cp.msg_time = me->p_timestamp;
    memcpy(cp.pos,me->p_pos, sizeof(cp.pos));
    memcpy(cp.quat,me->p_quat, sizeof(cp.quat));
     // Go down the list of callbacks that have been registered.
    // Fill in the parameter and call each.
     me->d_callback_list.call_handlers(cp);

    return 0;
}
Exemple #10
0
int vrpn_Poser_Server::handle_relative_vel_change_message(void* userdata,
	    vrpn_HANDLERPARAM p)
{
	vrpn_Poser_Server* me = (vrpn_Poser_Server*)userdata;
	const char* params = (p.buffer);
	int	i;

	// Fill in the parameters to the poser from the message
	if (p.payload_len != (8 * sizeof(vrpn_float64)) ) {
		fprintf(stderr,"vrpn_Poser_Server: velocity message payload error\n");
		fprintf(stderr,"             (got %d, expected %d)\n",
			p.payload_len, 8 * sizeof(vrpn_float64) );
		return -1;
	}
	me->p_timestamp = p.msg_time;

	vrpn_float64 dv[3], dq[4], di;
	for (i = 0; i < 3; i++) {
	 	vrpn_unbuffer( &params, &(dv[i]) );
	}
	for (i = 0; i < 4; i++) {
		vrpn_unbuffer( &params, &(dq[i]) );
	}
    vrpn_unbuffer(&params, &di);
	
	// apply the requested changes
	for( i = 0; i < 2; i++ )
		me->p_vel[i] += dv[i];
	q_mult( me->p_quat, dq, me->p_quat );
	me->p_vel_quat_dt += di;

    // Check the velocity against the max and min values of the workspace
    for (i = 0; i < 3; i++) {
        if (me->p_vel[i] < me->p_vel_min[i]) {
            me->p_vel[i] = me->p_vel_min[i];
        }
        else if (me->p_vel[i] > me->p_vel_max[i]) {
            me->p_vel[i] = me->p_vel_max[i];
        }
    }
    return 0;
}
int vrpn_Tracker_PhaseSpace::handle_update_rate_request(void *userdata, vrpn_HANDLERPARAM p)
{
#ifdef DEBUG
  printf("%s\n", __PRETTY_FUNCTION__);
#endif
  vrpn_Tracker_PhaseSpace* thistracker = (vrpn_Tracker_PhaseSpace*)userdata;
  vrpn_float64 update_rate = 0;
  vrpn_unbuffer(&p.buffer,&update_rate);
  thistracker->setFrequency((float) update_rate);
  return 0;
}
Exemple #12
0
static int VRPN_CALLBACK client_msg_handler(void *userdata, vrpn_HANDLERPARAM p) {
  vrpn_Button_Filter * instance = (vrpn_Button_Filter *) userdata;
  const char *bufptr = p.buffer;
  vrpn_int32 event;
  vrpn_int32 buttonid;

  vrpn_unbuffer(&bufptr, &buttonid);
  vrpn_unbuffer(&bufptr, &event);

  if (event== vrpn_BUTTON_MOMENTARY) {
    if (buttonid == vrpn_ALL_ID)
      instance->set_all_momentary();
    else instance->set_momentary(buttonid);
  }else if (event== vrpn_BUTTON_TOGGLE_OFF || event==vrpn_BUTTON_TOGGLE_ON ){
    if (buttonid == vrpn_ALL_ID)
      instance->set_all_toggle(event);
    else instance->set_toggle(buttonid,event);
  } 
  return 0;
}
Exemple #13
0
int vrpn_Tracker_PhaseSpace::handle_update_rate_request(void *userdata, vrpn_HANDLERPARAM p)
{
  vrpn_Tracker_PhaseSpace* thistracker = (vrpn_Tracker_PhaseSpace*)userdata;
  if(thistracker->debug) {
    printf("[debug] vrpn_Tracker_PhaseSpace::handle_update_rate_request\n");
  }
  vrpn_float64 update_rate = 0;
  vrpn_unbuffer(&p.buffer,&update_rate);
  thistracker->context.frequency((float) update_rate);
  return 0;
}
Exemple #14
0
// Static callback
int VRPN_CALLBACK vrpn_XInputGamepad::handle_request_channels_message(void *selfPtr,
	vrpn_HANDLERPARAM data)
{
	const char *bufptr = data.buffer;
	vrpn_int32 chan_num;
	vrpn_int32 pad;
	vrpn_XInputGamepad *me = (vrpn_XInputGamepad *) selfPtr;
	int i;

	// Read the parameters from the buffer
	vrpn_unbuffer(&bufptr, &chan_num);
	vrpn_unbuffer(&bufptr, &pad);

	if (chan_num > me->o_num_channel) {
		char msg[1024];
		sprintf( msg, "Error:  (handle_request_channels_message):  channels above %d not active; "
			"bad request up to channel %d.  Squelching.", me->o_num_channel, chan_num );
		me->send_text_message( msg, data.msg_time, vrpn_TEXT_ERROR );
		chan_num = me->o_num_channel;
	}
	if (chan_num < 0) {
		char msg[1024];
		sprintf( msg, "Error:  (handle_request_channels_message):  invalid channel %d.  Squelching.", chan_num );
		me->send_text_message( msg, data.msg_time, vrpn_TEXT_ERROR );
		return 0;
	}
	for (i = 0; i < chan_num; i++) {
		vrpn_float64 value;
		vrpn_unbuffer(&bufptr, &value);

		float magnitude = static_cast<float>(value);
		magnitude = (magnitude < 0) ? 0 : (magnitude > 1) ? 1 : magnitude;

		me->_motorSpeed[chan_num] = static_cast<WORD>(magnitude * 65535);
	}

	me->update_vibration();

	return 0;
}
Exemple #15
0
int vrpn_Analog_Remote::handle_change_message(void *userdata,
	vrpn_HANDLERPARAM p)
{
    const char* bufptr = p.buffer;
    vrpn_float64 numchannelD;	//< Number of channels passed in a double (yuck!)
    vrpn_Analog_Remote* me = (vrpn_Analog_Remote* )userdata;
    vrpn_ANALOGCB	cp;

    cp.msg_time = p.msg_time;
    vrpn_unbuffer(&bufptr, &numchannelD);
    cp.num_channel = (long)numchannelD;
    me->num_channel = cp.num_channel;
    for (vrpn_int32 i=0; i< cp.num_channel; i++) {
      vrpn_unbuffer(&bufptr, &cp.channel[i]);
    }

    // Go down the list of callbacks that have been registered.
    // Fill in the parameter and call each.
    me->d_callback_list.call_handlers(cp);

    return 0;
}
Exemple #16
0
/* static */
int vrpn_WiiMote::handle_request_channels_message(void* userdata,
        vrpn_HANDLERPARAM p)
{
    const char* bufptr = p.buffer;
    vrpn_int32 num;
    vrpn_int32 pad;
    vrpn_WiiMote* me = (vrpn_WiiMote*)userdata;

    // Read the values from the buffer
    vrpn_unbuffer(&bufptr, &num);
    vrpn_unbuffer(&bufptr, &pad);
    if (num > me->o_num_channel)
    {
        char msg[1024];
        sprintf( msg, "Error:  (handle_request_channels_message):  channels above %d not active; "
                 "bad request up to channel %d.  Squelching.", me->o_num_channel, num );
        me->send_text_message( msg, p.msg_time, vrpn_TEXT_ERROR );
        num = me->o_num_channel;
    }
    if (num < 0)
    {
        char msg[1024];
        sprintf( msg, "Error:  (handle_request_channels_message):  invalid channel %d.  Squelching.", num );
        me->send_text_message( msg, p.msg_time, vrpn_TEXT_ERROR );
        return 0;
    }

    // Pull only channel 0 from the buffer, no matter how many values we received.
    vrpn_float64 value;
    vrpn_unbuffer(&bufptr, &value);
    if (value >= 0.5) {
        wiiuse_rumble(me->wiimote->device, 1);
    } else {
        wiiuse_rumble(me->wiimote->device, 0);
    }

    return 0;
}
// Handles a throttle request by passing it on down to the non-blocking
// thread to deal with.
int vrpn_Imager_Stream_Buffer::static_handle_throttle_message(
    void *userdata, vrpn_HANDLERPARAM p)
{
    const char *bufptr = p.buffer;
    vrpn_Imager_Stream_Buffer *me =
        static_cast<vrpn_Imager_Stream_Buffer *>(userdata);

    // Get the requested number of frames from the buffer
    vrpn_int32 frames_to_send;
    if (vrpn_unbuffer(&bufptr, &frames_to_send)) {
        return -1;
    }

    me->d_shared_state.set_throttle_request(frames_to_send);
    return 0;
}
Exemple #18
0
vrpn_int32 vrpn_Sound::decodeLoadMaterial(const char* buf, vrpn_MaterialDef * material, vrpn_int32 *id) {
	const char *mptr = buf;

	vrpn_unbuffer(&mptr, id);
	
	vrpn_unbuffer(&mptr, material->material_name, MAX_MATERIAL_NAME_LENGTH);
	vrpn_unbuffer(&mptr, &material->transmittance_gain);
	vrpn_unbuffer(&mptr, &material->transmittance_highfreq);
	vrpn_unbuffer(&mptr, &material->reflectance_gain);
	vrpn_unbuffer(&mptr, &material->reflectance_highfreq);
		
	return 0;
}
Exemple #19
0
/* static */
int vrpn_Analog_Output_Remote::handle_report_num_channels( void *userdata, vrpn_HANDLERPARAM p )
{
    const char* bufptr = p.buffer;
    vrpn_int32 num;
    vrpn_Analog_Output_Remote* me = (vrpn_Analog_Output_Remote*)userdata;

    // Read the parameters from the buffer
    vrpn_unbuffer(&bufptr, &num);

    if( num >=0 && num <= vrpn_CHANNEL_MAX )
    {
         me->o_num_channel = num;
    }
    else
    {
         fprintf( stderr, "vrpn_Analog_Output_Remote::handle_report_num_channels_message:  "
                          "Someone sent us a bogus number of channels:  %d.\n", num );
    }
    return 0;
}
Exemple #20
0
// static
int vrpn_Mutex_Remote::handle_denyRequest(void *userdata, vrpn_HANDLERPARAM p)
{
    vrpn_Mutex_Remote *me = (vrpn_Mutex_Remote *)userdata;
    const char *b = p.buffer;
    vrpn_int32 index;

    vrpn_unbuffer(&b, &index);

#ifdef VERBOSE
    fprintf(stderr, "vrpn_Mutex_Remote::handle_denyRequest for %d.\n", index);
#endif

    if (me->d_myIndex != index) {
        return 0;
    }

    me->d_state = HELD_REMOTELY;
    me->triggerDenyCallbacks();

    return 0;
}
void vrpn_RedundantController_Protocol::decode_set
            (const char ** buf, vrpn_uint32 * num, timeval * interval) {
  vrpn_unbuffer(buf, num);
  vrpn_unbuffer(buf, interval);
}
int vrpn_Poser_Analog::handle_vel_change_message(void* userdata,
	    vrpn_HANDLERPARAM p)
{
      vrpn_Poser_Analog* me = (vrpn_Poser_Analog*)userdata;
      const char* params = (p.buffer);
      int	i;
    bool outside_bounds = false;

    // Fill in the parameters to the poser from the message
    if (p.payload_len != (8 * sizeof(vrpn_float64)) ) {
	    fprintf(stderr,"vrpn_Poser_Server: velocity message payload error\n");
	    fprintf(stderr,"             (got %d, expected %d)\n",
		    p.payload_len, 8 * sizeof(vrpn_float64) );
	    return -1;
    }
    me->p_timestamp = p.msg_time;

    for (i = 0; i < 3; i++) {
	    vrpn_unbuffer(&params, &me->p_vel[i]);
    }
    for (i = 0; i < 4; i++) {
	    vrpn_unbuffer(&params, &me->p_vel_quat[i]);
    }
    vrpn_unbuffer(&params, &me->p_vel_quat_dt);

    // Check the velocity against the max and min values of the workspace
    for (i = 0; i < 3; i++) {
        if (me->p_vel[i] < me->p_vel_min[i]) {
            me->p_vel[i] = me->p_vel_min[i];
            outside_bounds = true;
        }
        else if (me->p_vel[i] > me->p_vel_max[i]) {
            me->p_vel[i] = me->p_vel_max[i];
            outside_bounds = true;
        }
    }

    // XXX Update the values now.

    if (me->d_act_as_tracker) {
      // Tell the client where we actually went (clipped position and orientation).
      // using sensor 0 as the one to use to report.
      me->d_sensor = 0;
      me->vel[0] = me->p_vel[0];
      me->vel[1] = me->p_vel[1];
      me->vel[2] = me->p_vel[2];
      me->vel_quat[0] = me->p_vel_quat[0];
      me->vel_quat[1] = me->p_vel_quat[1];
      me->vel_quat[2] = me->p_vel_quat[2];
      me->vel_quat[3] = me->p_vel_quat[3];
      vrpn_gettimeofday(&me->vrpn_Tracker::timestamp, NULL);
      char	msgbuf[1000];
      vrpn_int32	len;
      len = me->vrpn_Tracker::encode_vel_to(msgbuf);
      if (me->d_connection->pack_message(len, me->vrpn_Tracker::timestamp,
        me->velocity_m_id, me->d_sender_id, msgbuf, vrpn_CONNECTION_LOW_LATENCY)) {
         fprintf(stderr,"vrpn_Poser_Analog::handle_vel_change_message(): can't write message: tossing\n");
         return -1;
      }
    }

    return 0;
}
Exemple #23
0
void vrpn_Tracker_Crossbow::reset() {
	const	char *cmd;
	unsigned char recv_buf[8];
	struct timeval timeout;

	timeout.tv_sec = 1;
	timeout.tv_usec = 0;
	
#if 0 // doesn't help
	// First, take the comm port offline for a second
	vrpn_close_commport(serial_fd);
	vrpn_SleepMsecs(1000);
	serial_fd = vrpn_open_commport(portname, baudrate);
#endif

	vrpn_flush_output_buffer(serial_fd);
	vrpn_flush_input_buffer(serial_fd);

	// Try resetting by toggling the RTS line of the serial port
	vrpn_set_rts(serial_fd);
	vrpn_SleepMsecs(750);
	vrpn_clear_rts(serial_fd);
	vrpn_SleepMsecs(250);
	vrpn_gettimeofday(&timestamp, NULL);

	vrpn_flush_input_buffer(serial_fd);

	cmd = "P";
	vrpn_write_characters(serial_fd, reinterpret_cast<const unsigned char*> (cmd), 1);
	vrpn_SleepMsecs(50); // Sleep long enough to stop receiving data
	vrpn_flush_input_buffer(serial_fd);

	cmd = "RSv";
	vrpn_write_characters(serial_fd, reinterpret_cast<const unsigned char*> (cmd), 3);
	vrpn_drain_output_buffer(serial_fd);
	if (vrpn_read_available_characters(serial_fd, recv_buf, 8, &timeout) != 8) {
		fprintf(stderr, "vrpn_Tracker_Crossbow::reset: Crossbow not responding to stimulus\n");
		status = vrpn_TRACKER_FAIL;
		return;
	}

	if ((recv_buf[0] != 'H') || (recv_buf[1] != 255) || (recv_buf[7] != 255)) {
		fprintf(stderr, "vrpn_Tracker_Crossbow::reset: Crossbow gave unexpected ping response\n");
		status = vrpn_TRACKER_FAIL;
		return;
	}

	if (recv_buf[6] != ((recv_buf[2] + recv_buf[3] + recv_buf[4] + recv_buf[5]) & 0xFF)) {
		fprintf(stderr, "vrpn_Tracker_Crossbow::reset: Crossbow gave invalid serial number checksum\n");
		status = vrpn_TRACKER_FAIL;
		return;
	}

	const char *bufptr = reinterpret_cast<const char *>(&recv_buf[2]);
	vrpn_unbuffer(&bufptr, &device_serial);

	if (0) do {
		if (!vrpn_read_available_characters(serial_fd, recv_buf, 1, &timeout)) {
			fprintf(stderr, "vrpn_Tracker_Crossbow::reset: Crossbow not responding to stimulus\n");
			status = vrpn_TRACKER_FAIL;
			return;
		}
	} while (*recv_buf != 255);

	int curSize = 4, curLen = 0;
	device_version = (char *) realloc(device_version, curSize * sizeof(char));
	if (device_version == NULL) {
		fprintf(stderr, "vrpn_Tracker_Crossbow::reset: Out of memory\n");
		status = vrpn_TRACKER_FAIL;
		return;
	}
	do {
		if (!vrpn_read_available_characters(serial_fd, recv_buf, 1, &timeout)) {
			fprintf(stderr, "vrpn_Tracker_Crossbow::reset: Crossbow not responding to stimulus\n");
			status = vrpn_TRACKER_FAIL;
			return;
		}
		if (*recv_buf != '$')
			device_version[curLen++] = *recv_buf;

		if (curLen == curSize)
			device_version = (char *) realloc(device_version, curSize *= 2);
	} while (*recv_buf != '$');

	// Now null-terminate the version string, expanding it one last time if necessary
	if (curLen == curSize)
		device_version = (char *) realloc(device_version, ++curSize);

	device_version[curLen] = 0;

	//printf("Serial %u\tVersion '%s'\n", device_serial, device_version);

	just_read_something = 0;
	status = vrpn_TRACKER_SYNCING;

}
void vrpn_Shared_int32::decode (const char ** buffer, vrpn_int32 *,
                                vrpn_int32 * newValue, timeval * when) const {
  vrpn_unbuffer(buffer, newValue);
  vrpn_unbuffer(buffer, when);
}
void vrpn_Shared_String::decode (const char ** buffer, vrpn_int32 * len,
                                 char * newValue, timeval * when) const {
  vrpn_unbuffer(buffer, when);
  vrpn_unbuffer(buffer, newValue, *len - sizeof(*when));
  newValue[*len - sizeof(*when)] = 0;
}
Exemple #26
0
// Retrieves a raw_packet from an incoming byte array, and even flips endianness as necessary.
void vrpn_Tracker_Crossbow::unbuffer_packet(raw_packet &dest, unsigned char *buffer) {
	vrpn_unbuffer(&buffer, &dest.header);
	vrpn_unbuffer(&buffer, &dest.roll_angle);
	vrpn_unbuffer(&buffer, &dest.pitch_angle);
	vrpn_unbuffer(&buffer, &dest.yaw_rate);
	vrpn_unbuffer(&buffer, &dest.accel_x);
	vrpn_unbuffer(&buffer, &dest.accel_y);
	vrpn_unbuffer(&buffer, &dest.accel_z);
	vrpn_unbuffer(&buffer, &dest.timer);
	vrpn_unbuffer(&buffer, &dest.temp_voltage);
	vrpn_unbuffer(&buffer, &dest.part_number);
	vrpn_unbuffer(&buffer, &dest.status);
	vrpn_unbuffer(&buffer, &dest.checksum);
}
int VRPN_AciCommand_transport_base::decode_AciCommand_from(
	AciCommand &cmd
	, const char *buf
	, size_t buflen
)
{
  //--------------------------------------------------------------------
  // Get the parameters for the command from the buffer.
  // *** Need to pack/unpack them in an order that will make them
  //     aligned correctly.
  // *** This needs to match the encoding routine.
  const char *bufptr = buf;
  if (buflen < sizeof(cmd.slot)) {
    fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
    return -1;
  }
  if (vrpn_unbuffer(&bufptr, &(cmd.slot))) {
    fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer slot\n");
    return -1;
  }
  if (buflen < sizeof(cmd.code)) {
    fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
    return -1;
  }
  if (vrpn_unbuffer(&bufptr, &(cmd.code))) {
    fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer code\n");
    return -1;
  }
  if (buflen < sizeof(cmd.rc)) {
    fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
    return -1;
  }
  if (vrpn_unbuffer(&bufptr, &(cmd.rc))) {
    fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer rc\n");
    return -1;
  }
  if ( (cmd.code >= MIN_CMD_DIRECTIVE) && (cmd.code <= MAX_CMD_DIRECTIVE) ) {
        // Nothing to do here -- there is no data for this type of command.
  } else if ( (cmd.code >= MIN_CMD_VALUE) && (cmd.code <= MAX_CMD_VALUE) ) {

	if (buflen < sizeof(cmd.data.value)) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
	  return -1;
	}
	if (vrpn_unbuffer(&bufptr, &(cmd.data.value))) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer value\n");
	  return -1;
	}

  } else if ( (cmd.code >= MIN_CMD_KEY) && (cmd.code <= MAX_CMD_KEY) ) {

	if (buflen < sizeof(cmd.data.keyValue.key)) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
	  return -1;
	}
	if (vrpn_unbuffer(&bufptr, &(cmd.data.keyValue.key))) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer key\n");
	  return -1;
	}
	if (buflen < sizeof(cmd.data.keyValue.value)) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
	  return -1;
	}
	if (vrpn_unbuffer(&bufptr, &(cmd.data.keyValue.value))) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer count\n");
	  return -1;
	}

  } else if (cmd.code == CMD_LOCK) {

	if (buflen < sizeof(cmd.data.lock.guid)) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
	  return -1;
	}
	if (vrpn_unbuffer(&bufptr, &(cmd.data.lock.guid))) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer guid\n");
	  return -1;
	}
	if (buflen < sizeof(cmd.data.lock.age)) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Not enough data\n");
	  return -1;
	}
	if (vrpn_unbuffer(&bufptr, &(cmd.data.lock.age))) {
	  fprintf(stderr,"VRPN_AciCommand_transport_base::decode_AciCommand_from(): Can't unbuffer age\n");
	  return -1;
	}

  } else {
	fprintf(stderr,"VRPN_AciCommand_transport_base::handle_request_message(): Unrecognized command (%d)\n", cmd.code);
	return -1;
  }

  // Return the number of bytes read.
  return static_cast<int>(bufptr - buf);
}
void vrpn_RedundantController_Protocol::decode_enable(const char **buf,
                                                      vrpn_bool *on)
{
    vrpn_unbuffer(buf, on);
}
Exemple #29
0
vrpn_int32 vrpn_Sound::decodeSoundDef(const char* buf, vrpn_SoundDef *sound, vrpn_SoundID *id, vrpn_int32 *repeat)
{
	const char *mptr = buf;
	int i;

	vrpn_unbuffer(&mptr, repeat);
	vrpn_unbuffer(&mptr, id);
	
	for(i = 0; i < 3; i++)
		vrpn_unbuffer(&mptr, &(sound->pose.position[i]));

	for(i = 0; i < 4; i++)
		vrpn_unbuffer(&mptr, &(sound->pose.orientation[i]));

	for(i = 0; i < 4; i++)
		vrpn_unbuffer(&mptr, &(sound->velocity[i]));

	vrpn_unbuffer(&mptr, &(sound->volume));

	vrpn_unbuffer(&mptr, &(sound->max_back_dist));
	vrpn_unbuffer(&mptr, &(sound->min_back_dist));
	vrpn_unbuffer(&mptr, &(sound->max_front_dist));
	vrpn_unbuffer(&mptr, &(sound->min_front_dist));

	vrpn_unbuffer(&mptr, &(sound->cone_inner_angle));
	vrpn_unbuffer(&mptr, &(sound->cone_outer_angle));
	vrpn_unbuffer(&mptr, &(sound->cone_gain));
	vrpn_unbuffer(&mptr, &(sound->dopler_scale));
	vrpn_unbuffer(&mptr, &(sound->equalization_val));
	vrpn_unbuffer(&mptr, &(sound->pitch));

	return 0;
}
Exemple #30
0
//Decodes the file and Client Index number
vrpn_int32 vrpn_Sound::decodeSound_local(const char *buf, char **filename, vrpn_SoundID *id, vrpn_SoundDef * sound, const int payload)
{
	const char *mptr = buf;
  int i;

	*filename = new char[payload - sizeof(vrpn_SoundID)- sizeof(vrpn_SoundDef)];
	
	vrpn_unbuffer(&mptr, id);
	
	for(i = 0; i < 3; i++)
		vrpn_unbuffer(&mptr, &(sound->pose.position[i]));

	for(i = 0; i < 4; i++)
		vrpn_unbuffer(&mptr, &(sound->pose.orientation[i]));

	for(i = 0; i < 4; i++)
		vrpn_unbuffer(&mptr, &(sound->velocity[i]));

	vrpn_unbuffer(&mptr, &(sound->volume));

	vrpn_unbuffer(&mptr, &(sound->max_back_dist));
	vrpn_unbuffer(&mptr, &(sound->min_back_dist));
	vrpn_unbuffer(&mptr, &(sound->max_front_dist));
	vrpn_unbuffer(&mptr, &(sound->min_front_dist));

	vrpn_unbuffer(&mptr, &(sound->cone_inner_angle));
	vrpn_unbuffer(&mptr, &(sound->cone_outer_angle));
	vrpn_unbuffer(&mptr, &(sound->cone_gain));
	vrpn_unbuffer(&mptr, &(sound->dopler_scale));
	vrpn_unbuffer(&mptr, &(sound->equalization_val));
	vrpn_unbuffer(&mptr, &(sound->pitch));

	vrpn_unbuffer(&mptr, *filename, payload - sizeof(vrpn_SoundID)- sizeof(vrpn_SoundDef));
	
	return 0;
}