您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ vrpn_gettimeofday函数代码示例

51自学网 2021-06-03 09:48:58
  C++
这篇教程C++ vrpn_gettimeofday函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中vrpn_gettimeofday函数的典型用法代码示例。如果您正苦于以下问题:C++ vrpn_gettimeofday函数的具体用法?C++ vrpn_gettimeofday怎么用?C++ vrpn_gettimeofday使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了vrpn_gettimeofday函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: sizeof

vrpn_int32 vrpn_Sound_Client::setSoundPose(const vrpn_SoundID id, vrpn_float64 position[3], vrpn_float64 orientation[4]){	char buf[sizeof(vrpn_PoseDef) + sizeof(vrpn_SoundID)];	vrpn_int32 len;	vrpn_PoseDef tempdef;        int i;	for (i=0; i<4; i++) {	  tempdef.orientation[i] = orientation[i];	}	for (i=0; i<3; i++) {	  tempdef.position[i] = position[i];	}	len = encodeSoundPose(tempdef, id, buf);	vrpn_gettimeofday(&timestamp, NULL);	if (vrpn_Sound::d_connection->pack_message(len, timestamp, set_sound_pose, d_sender_id, buf, vrpn_CONNECTION_RELIABLE)) {	    fprintf(stderr,"vrpn_Sound_Client: cannot write message change status: tossing/n");	}		return 0;}
开发者ID:BlueBrain,项目名称:vrpn,代码行数:23,


示例2: vrpn_gettimeofday

void vrpn_SharedObject::becomeSerializer (void) {  timeval now;  // Make sure only one request is outstanding  if (d_isNegotiatingSerializer) {    return;  }  d_isNegotiatingSerializer = vrpn_TRUE;  // send requestSerializer  if (d_connection) {    vrpn_gettimeofday(&now, NULL);    d_connection->pack_message(0, d_lastUpdate,                               d_requestSerializer_type, d_myId,                               NULL, vrpn_CONNECTION_RELIABLE);  }//fprintf(stderr, "sent requestSerializer/n");}
开发者ID:jeraldamo,项目名称:vrpn_ovr,代码行数:23,


示例3: decode_objectOrientation

int vrpn_ForceDeviceServer::handle_setObjectOrientation_message(    void *userdata, vrpn_HANDLERPARAM p){    vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;    vrpn_int32 objNum;    vrpn_float32 axis[3];    vrpn_float32 angle;    decode_objectOrientation(p.buffer, p.payload_len, &objNum, axis, &angle);#ifdef VRPN_USE_HDAPI    struct timeval now;    vrpn_gettimeofday(&now, NULL);    me->send_text_message("Trimesh not supported under HDAPI", now,                          vrpn_TEXT_ERROR);    return 0;#else    me->setObjectOrientation(objNum, axis, angle);    return 0;#endif}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:23,


示例4: vrpn_Analog

vrpn_Analog_5dtUSB::vrpn_Analog_5dtUSB(vrpn_HidAcceptor *filter,                                       int num_sensors,                                       bool isLeftHand,                                       const char *name,                                       vrpn_Connection *c) :	vrpn_Analog(name, c),	vrpn_HidInterface(filter),	_isLeftHand(isLeftHand),	_wasConnected(false) {	if (num_sensors != 5 && num_sensors != 14) {		throw std::logic_error("The vrpn_Analog_5dtUSB driver only supports 5 or 14 sensors, and a different number was passed!");	}	vrpn_Analog::num_channel = num_sensors;	// Initialize the state of all the analogs	memset(channel, 0, sizeof(channel));	memset(last, 0, sizeof(last));	// Set the timestamp	vrpn_gettimeofday(&_timestamp, NULL);}
开发者ID:vrpn,项目名称:vrpn,代码行数:23,


示例5: send_poser_once_in_a_while

void	send_poser_once_in_a_while( void ){	static long secs = 0;	struct timeval	now;	static vrpn_float64 p[3] = { 0, 0, 0 };	static vrpn_float64 dp[3] = {0, 0, 0 };	static vrpn_float64 q[4] = { 1, 1, 1, 1 };	static int count = 0;	static bool doRelative = true;	vrpn_gettimeofday( &now, NULL );	if( secs == 0 )	{	// First time through		secs = now.tv_sec;	}	if( now.tv_sec - secs >= 1 ) 	{		if( !doRelative )		{			// do a pose request			p[count%3] += 1;			if( p[count%3] > 1 ) p[count%3] = -1;			rposer->request_pose( now, p, q );			count++;			doRelative = true;		}		else		{	// do a relative pose request			dp[count%3] = 0.25;			dp[(count+1)%3] = 0;			dp[(count+2)%3] = 0;			rposer->request_pose_relative( now, dp, q );			doRelative = false;		}		secs = now.tv_sec;	}}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:37,


示例6: vrpn_Button_Filter

// (RDK) serial mouse wired up as button devicevrpn_Button_SerialMouse::vrpn_Button_SerialMouse(const char *name,vrpn_Connection *c,						 const char *port, int baud, vrpn_MOUSETYPE type)    : vrpn_Button_Filter(name, c){    status = BUTTON_FAIL;    printed_error = false;    // Find out the port name and baud rate;    if (port == NULL) {		fprintf(stderr,"vrpn_Button_SerialMouse: NULL port name/n");		return;    } else {		strncpy(portname, port, sizeof(portname));		portname[sizeof(portname)-1] = '/0';    }    num_buttons = 3;    baudrate = baud;        // Open the serial port we are going to use    if ( (serial_fd=vrpn_open_commport(portname, baudrate)) == -1) {		fprintf(stderr,"vrpn_Button_SerialMouse: Cannot open serial port/n");		return;    }        for (vrpn_int32 i = 0; i < num_buttons; i++) {		buttons[i] = lastbuttons[i] = 0;		buttonstate[i] = vrpn_BUTTON_MOMENTARY;    }    mousetype = type;    lastL = lastR = 0;    // first time in read(), this will get set to 0    lastM = (mousetype == THREEBUTTON_EMULATION)?1:0;      // Say we are ready and find out what time it is    status = BUTTON_READY;    vrpn_gettimeofday(&timestamp, NULL);      }
开发者ID:ASPePeX,项目名称:vrpn,代码行数:38,


示例7: vrpn_gettimeofday

void vrpn_Analog_5dtUSB::on_data_received(size_t bytes, vrpn_uint8 *buffer) {	if (bytes != 64) {		std::ostringstream ss;		ss << "Received a too-short report: " << bytes;		struct timeval ts;		vrpn_gettimeofday(&ts, NULL);		send_text_message(ss.str().c_str(), ts, vrpn_TEXT_WARNING);		return;	}	// Decode all full reports.	const float scale = 1.0f / 4096.0f;	vrpn_uint8 * bufptr = buffer;	for (size_t i = 0; i < 16; i++) {		_rawVals[i] = vrpn_unbuffer<vrpn_int16>(bufptr) * scale;	}	switch (vrpn_Analog::num_channel) {		case 5:			for (size_t i = 0; i < 5; ++i) {				channel[i] = _rawVals[i * 3];				// Report this event before parsing the next.				report_changes();			}			break;		case 14:			for (size_t i = 0; i < 14; ++i) {				channel[i] = _rawVals[i];				// Report this event before parsing the next.				report_changes();			}			break;		default:			std::cerr << "Internal error - should not happen: Unrecognized number of channels!" << std::endl;	}}
开发者ID:vrpn,项目名称:vrpn,代码行数:37,


示例8: sizeof

void vrpn_Mutex_Remote::requestIndex(void){    timeval now;    vrpn_int32 buflen = sizeof(vrpn_int32) + sizeof(vrpn_uint32);    char *buf = new char[buflen];    char *bufptr = buf;    vrpn_int32 len = buflen;    vrpn_uint32 ip_addr = getmyIP();#ifdef _WIN32    vrpn_int32 pid = _getpid();#else    vrpn_int32 pid = getpid();#endif    vrpn_buffer(&bufptr, &len, ip_addr);    vrpn_buffer(&bufptr, &len, pid);#ifdef VERBOSE    printf("requesting index for %lu, %d/n", ip_addr, pid);#endif    vrpn_gettimeofday(&now, NULL);    d_connection->pack_message(buflen, now, d_requestIndex_type, d_myId, buf,                               vrpn_CONNECTION_RELIABLE);    delete[] buf;    return;}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:24,


示例9: vrpn_gettimeofday

int	vrpn_IMU_Magnetometer::setup_vector(vrpn_IMU_Vector *vector){  // Set a default time of now.  struct timeval now;  vrpn_gettimeofday(&now, NULL);  vector->time = now;	// If the name is empty, we're done.	if (vector->params.name.size() == 0) { return 0; }	// Open the analog device and point the remote at it.	// If the name starts with the '*' character, use the server  // connection rather than making a new one.	if (vector->params.name[0] == '*') {		vector->ana = new vrpn_Analog_Remote(vector->params.name.c_str()+1,                      d_connection);#ifdef	VERBOSE		printf("vrpn_IMU_Magnetometer: Adding local analog %s/n",      vector->params.name.c_str()+1);#endif	} else {    vector->ana = new vrpn_Analog_Remote(vector->params.name.c_str());#ifdef	VERBOSE		printf("vrpn_IMU_Magnetometer: Adding remote analog %s/n",      vector->params.name.c_str());#endif	}	if (vector->ana == NULL) {		fprintf(stderr,"vrpn_IMU_Magnetometer: "      "Can't open Analog %s/n", vector->params.name.c_str());		return -1;	}	// Set up the callback handler for the channel	return vector->ana->register_change_handler(vector, handle_analog_update);}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:36,


示例10: decode_updateTrimeshChanges

int vrpn_ForceDeviceServer::handle_updateTrimeshChanges_message(    void *userdata, vrpn_HANDLERPARAM p){    vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;    float SurfaceKspring, SurfaceKdamping, SurfaceFdynamic, SurfaceFstatic;    vrpn_int32 objNum;    decode_updateTrimeshChanges(p.buffer, p.payload_len, &objNum,                                &SurfaceKspring, &SurfaceKdamping,                                &SurfaceFdynamic, &SurfaceFstatic);#ifdef VRPN_USE_HDAPI    struct timeval now;    vrpn_gettimeofday(&now, NULL);    me->send_text_message("Trimesh not supported under HDAPI", now,                          vrpn_TEXT_ERROR);    return 0;#else    me->updateTrimeshChanges(objNum, SurfaceKspring, SurfaceFstatic,                             SurfaceFdynamic, SurfaceKdamping);    return 0;#endif}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:24,


示例11: decode_triangle

int vrpn_ForceDeviceServer::handle_setTriangle_message(void *userdata,                                                       vrpn_HANDLERPARAM p){    vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;    vrpn_int32 triNum, v0, v1, v2, n0, n1, n2;    vrpn_int32 objNum;    decode_triangle(p.buffer, p.payload_len, &objNum, &triNum, &v0, &v1, &v2,                    &n0, &n1, &n2);#ifdef VRPN_USE_HDAPI    struct timeval now;    vrpn_gettimeofday(&now, NULL);    me->send_text_message("Trimesh not supported under HDAPI", now,                          vrpn_TEXT_ERROR);    return 0;#else    if (me->setTriangle(objNum, triNum, v0, v1, v2, n0, n1, n2))        return 0;    else {        fprintf(stderr, "vrpn_Phantom: error in trimesh::setTriangle/n");        return -1;    }#endif}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:24,


示例12: decode_addObjectExScene

int vrpn_ForceDeviceServer::handle_addObjectExScene_message(void *userdata,                                                            vrpn_HANDLERPARAM p){    vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;    vrpn_int32 objNum;    decode_addObjectExScene(p.buffer, p.payload_len, &objNum);#ifdef VRPN_USE_HDAPI    struct timeval now;    vrpn_gettimeofday(&now, NULL);    me->send_text_message("Trimesh not supported under HDAPI", now,                          vrpn_TEXT_ERROR);    return 0;#else    if (me->addObjectExScene(objNum)) {        return 0;    }    else {        fprintf(stderr, "vrpn_Phantom: error in trimesh::addObjectExScene/n");        return -1;    }#endif}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:24,


示例13: vrpn_gettimeofday

void DeviceThread::AddReport(  std::vector<double> values  , struct timeval sampleTime){  // The arrival time is always now.  struct timeval arrivalTime;  vrpn_gettimeofday(&arrivalTime, NULL);  // If the sampleTime is NOW, then replace it with the arrival time.  if ( (sampleTime.tv_sec == NOW.tv_sec) && (sampleTime.tv_usec == NOW.tv_usec)) {    sampleTime = arrivalTime;  }  // This is called in the sub-thread to add a report to the list of available  // reports.  We yank the report-vector semaphore while we're adding it to  // avoid races.  DeviceThreadReport r;  r.arrivalTime = arrivalTime;  r.sampleTime = sampleTime;  r.values = values;  m_reportSemaphore.p();  m_reports.push_back(r);  m_reportSemaphore.v();}
开发者ID:ReliaSolve,项目名称:Latent,代码行数:24,


示例14: server_mainloop

void vrpn_Tracker_WiimoteHead::mainloop() {	struct timeval now;	// Call generic server mainloop, since we are a server	server_mainloop();	// Mainloop() the wiimote to get fresh values	if (d_ana != NULL) {		d_ana->mainloop();	}	// See if we have new data, or if it has been too long since our last	// report.  Send a new report in either case.	vrpn_gettimeofday(&now, NULL);	double interval = vrpn_TimevalDurationSeconds(now, d_prevtime);	if (_should_report(interval)) {		// Figure out the new matrix based on the current values and		// the length of the interval since the last report		update_pose();		report();	}}
开发者ID:godbyk,项目名称:vrpn,代码行数:24,


示例15: server_mainloop

void vrpn_Dial_Example_Server::mainloop(){    struct timeval current_time;    int i;    // Call the generic server mainloop, since we are a server    server_mainloop();    // See if its time to generate a new report    // IN A REAL SERVER, this check would not be done; although the    // time of the report would be updated to the current time so    // that the correct timestamp would be issued on the report.    vrpn_gettimeofday(&current_time, NULL);    if (vrpn_TimevalDuration(current_time, timestamp) >=        1000000.0 / _update_rate) {        // Update the time        timestamp.tv_sec = current_time.tv_sec;        timestamp.tv_usec = current_time.tv_usec;        // Update the values for the dials, to say that each one has        // moved the appropriate rotation (spin rate is revolutions per        // second, update rate is report/second, the quotient is the number        // of revolutions since the last report). When the changes are        // reported, these values are set back to zero.        // THIS CODE WILL BE REPLACED by the user code that tells how        // many revolutions each dial has changed since the last report.        for (i = 0; i < num_dials; i++) {            dials[i] = _spin_rate / _update_rate;        }        // Send reports. Stays the same in a real server.        report_changes();    }}
开发者ID:ASPePeX,项目名称:vrpn,代码行数:36,


示例16: update

void vrpn_Griffin_PowerMate::mainloop(void){	update();	server_mainloop();	struct timeval current_time;	vrpn_gettimeofday(&current_time, NULL);	if (vrpn_TimevalDuration(current_time, _timestamp) > POLL_INTERVAL ) {		_timestamp = current_time;		report_changes();		if (vrpn_Analog::num_channel > 0)		{			vrpn_Analog::server_mainloop();		}		if (vrpn_Button::num_buttons > 0)		{			vrpn_Button::server_mainloop();		}		if (vrpn_Dial::num_dials > 0)		{			vrpn_Dial::server_mainloop();		}	}}
开发者ID:BenjaminRothschild,项目名称:vrpn,代码行数:24,


示例17: tracking

//.........这里部分代码省略.........	reset[resetLen++] = 'Y'; // Put tracker into tracking (not point) mode   }   if (numResets > 3) {	// Get a little more aggressive   	if (numResets > 4) { // Even more aggressive      	reset[resetLen++] = 't'; // Toggle extended mode (in case it is on)   }   reset[resetLen++] = 'W'; // Reset to factory defaults   reset[resetLen++] = (char) (11); // Ctrl + k --> Burn settings into EPROM   }   reset[resetLen++] = (char) (25); // Ctrl + Y -> reset the tracker   send_text_message("Resetting", timestamp, vrpn_TEXT_ERROR, numResets);   for (i = 0; i < resetLen; i++) {	if (vrpn_write_characters(serial_fd, &reset[i], 1) == 1) {		sleep(2);  // Wait 2 seconds each character   	} else {		send_text_message("Failed writing to tracker", timestamp, vrpn_TEXT_ERROR, numResets);		perror("3Space: Failed writing to tracker");		status = vrpn_TRACKER_FAIL;		return;	}   }   sleep(10);	// Sleep to let the reset happen   // Get rid of the characters left over from before the reset   vrpn_flush_input_buffer(serial_fd);   // Make sure that the tracker has stopped sending characters   sleep(2);   unsigned char scrap[80];   if ( (ret = vrpn_read_available_characters(serial_fd, scrap, 80)) != 0) {     fprintf(stderr,"  3Space warning: got >=%d characters after reset:/n",ret);     for (i = 0; i < ret; i++) {      	if (isprint(scrap[i])) {         	fprintf(stderr,"%c",scrap[i]);         } else {         	fprintf(stderr,"[0x%02X]",scrap[i]);         }     }     fprintf(stderr, "/n");     vrpn_flush_input_buffer(serial_fd);		// Flush what's left   }   // Asking for tracker status   if (vrpn_write_characters(serial_fd, (const unsigned char *) "S", 1) == 1) {      sleep(1); // Sleep for a second to let it respond   } else {	perror("  3Space write failed");	status = vrpn_TRACKER_FAIL;	return;   }   // Read Status   unsigned char statusmsg[56];   if ( (ret = vrpn_read_available_characters(serial_fd, statusmsg, 55)) != 55){  	fprintf(stderr, "  Got %d of 55 characters for status/n",ret);   }   if ( (statusmsg[0]!='2') || (statusmsg[54]!=(char)(10)) ) {     int i;     statusmsg[55] = '/0';	// Null-terminate the string     fprintf(stderr, "  Tracker: status is (");     for (i = 0; i < 55; i++) {      	if (isprint(statusmsg[i])) {         	fprintf(stderr,"%c",statusmsg[i]);         } else {         	fprintf(stderr,"[0x%02X]",statusmsg[i]);         }     }     fprintf(stderr, ")/n  Bad status report from tracker, retrying reset/n");     return;   } else {     send_text_message("Got status (tracker back up)!", timestamp, vrpn_TEXT_ERROR, 0);     numResets = 0; 	// Success, use simple reset next time   }   // Set output format to be position,quaternion   // These are a capitol 'o' followed by comma-separated values that   // indicate data sets according to appendix F of the 3Space manual,   // then followed by character 13 (octal 15).   if (vrpn_write_characters(serial_fd, (const unsigned char *)"O2,11/015", 6) == 6) {	sleep(1); // Sleep for a second to let it respond   } else {	perror("  3Space write failed");	status = vrpn_TRACKER_FAIL;	return;   }   // Set data format to BINARY mode   vrpn_write_characters(serial_fd, (const unsigned char *)"f", 1);   // Set tracker to continuous mode   if (vrpn_write_characters(serial_fd,(const unsigned char *) "C", 1) != 1)   	perror("  3Space write failed");   else {   	fprintf(stderr, "  3Space set to continuous mode/n");   }   fprintf(stderr, "  (at the end of 3Space reset routine)/n");   vrpn_gettimeofday(&timestamp, NULL);	// Set watchdog now   status = vrpn_TRACKER_SYNCING;	// We're trying for a new reading}
开发者ID:Lab411-HUST,项目名称:Github,代码行数:101,


示例18: send_text_message

int vrpn_Tracker_3Space::get_report(void){   int ret;   // The reports are each 20 characters long, and each start with a   // byte that has the high bit set and no other bytes have the high   // bit set.  If we're synching, read a byte at a time until we find   // one with the high bit set.   if (status == vrpn_TRACKER_SYNCING) {      // Try to get a character.  If none, just return.      if (vrpn_read_available_characters(serial_fd, buffer, 1) != 1) {      	return 0;      }      // If the high bit isn't set, we don't want it we      // need to look at the next one, so just return      if ( (buffer[0] & 0x80) == 0) {      	send_text_message("Syncing (high bit not set)", timestamp, vrpn_TEXT_WARNING);      	return 0;      }      // Got the first character of a report -- go into PARTIAL mode      // and say that we got one character at this time.      bufcount = 1;      vrpn_gettimeofday(&timestamp, NULL);      status = vrpn_TRACKER_PARTIAL;   }   // Read as many bytes of this 20 as we can, storing them   // in the buffer.  We keep track of how many have been read so far   // and only try to read the rest.  The routine that calls this one   // makes sure we get a full reading often enough (ie, it is responsible   // for doing the watchdog timing to make sure the tracker hasn't simply   // stopped sending characters).   ret = vrpn_read_available_characters(serial_fd, &buffer[bufcount],		20-bufcount);   if (ret == -1) {	send_text_message("Error reading, resetting", timestamp, vrpn_TEXT_ERROR);	status = vrpn_TRACKER_FAIL;	return 0;   }   bufcount += ret;   if (bufcount < 20) {	// Not done -- go back for more	return 0;   }   { // Decode the report	unsigned char decode[17];	int i;	static unsigned char mask[8] = {0x01, 0x02, 0x04, 0x08,					0x10, 0x20, 0x40, 0x80 };	// Clear the MSB in the first byte	buffer[0] &= 0x7F;	// Decode the 3Space binary representation into standard	// 8-bit bytes.  This is done according to page 4-4 of the	// 3Space user's manual, which says that the high-order bits	// of each group of 7 bytes is packed into the 8th byte of the	// group.  Decoding involves setting those bits in the bytes	// iff their encoded counterpart is set and then skipping the	// byte that holds the encoded bits.	// We decode from buffer[] into decode[] (which is 3 bytes	// shorter due to the removal of the bit-encoding bytes).	// decoding from buffer[0-6] into decode[0-6]	for (i=0; i<7; i++) {		decode[i] = buffer[i];		if ( (buffer[7] & mask[i]) != 0) {			decode[i] |= (unsigned char)(0x80);		}	}	// decoding from buffer[8-14] into decode[7-13]	for (i=7; i<14; i++) {		decode[i] = buffer[i+1];		if ( (buffer[15] & mask[i-7]) != 0) {			decode[i] |= (unsigned char)(0x80);		}	}	// decoding from buffer[16-18] into decode[14-16]	for (i=14; i<17; i++) {		decode[i] = buffer[i+2];		if ( (buffer[19] & mask[i-14]) != 0) {			decode[i] |= (unsigned char)(0x80);		}	}	// Parse out sensor number, which is the second byte and is	// stored as the ASCII number of the sensor, with numbers	// starting from '1'.  We turn it into a zero-based unit number.	d_sensor = decode[1] - '1';	// Position	for (i=0; i<3; i++) {		pos[i] = (* (short*)(&decode[3+2*i])) * T_3_BINARY_TO_METERS;	}	// Quarternion orientation.  The 3Space gives quaternions//.........这里部分代码省略.........
开发者ID:Lab411-HUST,项目名称:Github,代码行数:101,


示例19: vrpn_read_available_characters

//.........这里部分代码省略.........   ) {     if (VRPN_LIBERTY_DEBUGA)	fprintf(stderr,"[DEBUG]: Don't have LY or PA or 'LU' at beginning");	   status = vrpn_TRACKER_SYNCING;	   VRPN_MSG_INFO("Not 'LY' or 'PA' or 'LU' in record, re-syncing");	   vrpn_flush_input_buffer(serial_fd);	   return 0;   }   if (buffer[bufcount-1] != ' ') {	   status = vrpn_TRACKER_SYNCING;	   VRPN_MSG_INFO("No space character at end of report, re-syncing/n");	   vrpn_flush_input_buffer(serial_fd);	   if (VRPN_LIBERTY_DEBUGA) fprintf(stderr,"[DEBUG]: Don't have space at end of report, got (%c) sensor %i/n",buffer[bufcount-1], d_sensor);	   return 0;   }   //Decode the error status and output a debug message   if (buffer[4] != ' ') {     // An error has been flagged     if (VRPN_LIBERTY_DEBUGA) fprintf(stderr,"[DEBUG]:Error Flag %i/n",buffer[4]);   }   //--------------------------------------------------------------------   // Decode the X,Y,Z of the position and the W,X,Y,Z of the quaternion   // (keeping in mind that we store quaternions as X,Y,Z, W).   //--------------------------------------------------------------------   // The reports coming from the Liberty are in little-endian order,   // which is the opposite of the network-standard byte order that is   // used by VRPN. Here we swap the order to big-endian so that the   // routines below can pull out the values in the correct order.   // This is slightly inefficient on machines that have little-endian   // order to start with, since it means swapping the values twice, but   // that is more than outweighed by the cleanliness gained by keeping   // all architecture-dependent code in the vrpn_Shared.C file.   //--------------------------------------------------------------------   // Point at the first value in the buffer (position of the X value)   bufptr = &buffer[8];   // When copying the positions, convert from inches to meters, since the   // Liberty reports in inches and VRPN reports in meters.   pos[0] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr) * INCHES_TO_METERS;   pos[1] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr) * INCHES_TO_METERS;   pos[2] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr) * INCHES_TO_METERS;   // Change the order of the quaternion fields to match quatlib order   d_quat[Q_W] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);   d_quat[Q_X] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);   d_quat[Q_Y] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);   d_quat[Q_Z] = vrpn_unbuffer_from_little_endian<vrpn_float32>(bufptr);   //--------------------------------------------------------------------   // Decode the time from the Liberty system (unsigned 32bit int), add it to the   // time we zeroed the tracker, and update the report time.  Remember   // to convert the MILLIseconds from the report into MICROseconds and   // seconds.   //--------------------------------------------------------------------       struct timeval delta_time;   // Time since the clock was reset       // Read the integer value of the time from the record.       vrpn_uint32 read_time = vrpn_unbuffer_from_little_endian<vrpn_uint32>(bufptr);       // Convert from the float in MILLIseconds to the struct timeval       delta_time.tv_sec = (long)(read_time / 1000);	// Integer trunction to seconds       vrpn_uint32 read_time_milliseconds = read_time - delta_time.tv_sec * 1000;	// Subtract out what we just counted       delta_time.tv_usec = (long)(read_time_milliseconds * 1000);	// Convert remainder to MICROseconds       // The time that the report was generated       timestamp = vrpn_TimevalSum(liberty_zerotime, delta_time);       vrpn_gettimeofday(&watchdog_timestamp, NULL);	// Set watchdog now           //--------------------------------------------------------------------   // If this sensor has button on it, decode the button values   // into the button device and mainloop the button device so that   // it will report any changes.   //--------------------------------------------------------------------   if (stylus_buttons[d_sensor]) {	   // Read the integer value of the bytton status from the record.	   vrpn_uint32 button_status = vrpn_unbuffer_from_little_endian<vrpn_uint32>(bufptr);	   	   stylus_buttons[d_sensor]->set_button(0, button_status);	   stylus_buttons[d_sensor]->mainloop();   }   //--------------------------------------------------------------------   // Done with the decoding, set the report to ready   //--------------------------------------------------------------------   status = vrpn_TRACKER_SYNCING;   bufcount = 0;#ifdef VERBOSE2      print_latest_report();#endif   return 1;}
开发者ID:vrpn,项目名称:vrpn,代码行数:101,


示例20: fprintf

//.........这里部分代码省略.........	vrpn_SleepMsecs(1000.0*1); // Sleep for a second to let it respond     } else {	perror("  Liberty write orientation filter failed");	status = vrpn_TRACKER_FAIL;	return;     }   }   // Send the additional reset commands, if any, to the tracker.   // These commands come in lines, with character /015 ending each   // line. If a line start with an asterisk (*), treat it as a pause   // command, with the number of seconds to wait coming right after   // the asterisk. Otherwise, the line is sent directly to the tracker.   // Wait a while for them to take effect, then clear the input   // buffer.   if (strlen(add_reset_cmd) > 0) {	char	*next_line;	char	add_cmd_copy[sizeof(add_reset_cmd)];	char	string_to_send[sizeof(add_reset_cmd)];	int	seconds_to_wait;	printf("  Liberty writing extended reset commands.../n");	// Make a copy of the additional reset string, since it is consumed        vrpn_strcpy(add_cmd_copy, add_reset_cmd);	// Pass through the string, testing each line to see if it is	// a sleep command or a line to send to the tracker. Continue until	// there are no more line delimiters ('/015'). Be sure to write the	// /015 to the end of the string sent to the tracker.	// Note that strok() puts a NULL character in place of the delimiter.	next_line = strtok(add_cmd_copy, "/015");	while (next_line != NULL) {		if (next_line[0] == '*') {	// This is a "sleep" line, see how long			seconds_to_wait = atoi(&next_line[1]);			fprintf(stderr,"   ...sleeping %d seconds/n",seconds_to_wait);			vrpn_SleepMsecs(1000.0*seconds_to_wait);		} else {	// This is a command line, send it			sprintf(string_to_send, "%s/015", next_line);			fprintf(stderr, "   ...sending command: %s/n", string_to_send);			vrpn_write_characters(serial_fd,				(const unsigned char *)string_to_send,strlen(string_to_send));		}		next_line = strtok(next_line+strlen(next_line)+1, "/015");	}	// Sleep a little while to let this finish, then clear the input buffer	vrpn_SleepMsecs(1000.0*2);	vrpn_flush_input_buffer(serial_fd);   }      // Set data format to BINARY mode   sprintf(outstring1, "F1/r");   if (vrpn_write_characters(serial_fd, (const unsigned char *)outstring1,			    strlen(outstring1)) == (int)strlen(outstring1)) {      fprintf(stderr, "  Liberty set to binary mode/n");   }   // Set tracker to continuous mode   sprintf(outstring3, "C/r");   if (vrpn_write_characters(serial_fd, (const unsigned char *)outstring3,                                strlen(outstring3)) != (int)strlen(outstring3)) { 	perror("  Liberty write failed");	status = vrpn_TRACKER_FAIL;	return;   } else {   	fprintf(stderr, "  Liberty set to continuous mode/n");   }   // If we are using the Liberty timestamps, clear the timer on the device and   // store the time when we cleared it.  First, drain any characters in the output   // buffer to ensure we're sending right away.  Then, send the reset command and   // store the time that we sent it, plus the estimated time for the characters to   // get across the serial line to the device at the current baud rate.   // Set time units to milliseconds (MT) and reset the time (MZ).	char	clear_timestamp_cmd[] = "Q0/r";	vrpn_drain_output_buffer(serial_fd);	if (vrpn_write_characters(serial_fd, (const unsigned char *)clear_timestamp_cmd,	        strlen(clear_timestamp_cmd)) != (int)strlen(clear_timestamp_cmd)) {	    VRPN_MSG_ERROR("Cannot send command to clear timestamp");	    status = vrpn_TRACKER_FAIL;	    return;	}	// Drain the output buffer again, then record the time as the base time from	// the tracker.	vrpn_drain_output_buffer(serial_fd);	vrpn_gettimeofday(&liberty_zerotime, NULL);   // Done with reset.   vrpn_gettimeofday(&watchdog_timestamp, NULL);	// Set watchdog now   VRPN_MSG_WARNING("Reset Completed (this is good)");   status = vrpn_TRACKER_SYNCING;	// We're trying for a new reading}
开发者ID:vrpn,项目名称:vrpn,代码行数:101,


示例21: open_new_log_connection

bool vrpn_Imager_Stream_Buffer::make_new_logging_connection(    const char *local_in_logfile_name, const char *local_out_logfile_name,    const char *remote_in_logfile_name, const char *remote_out_logfile_name){    // Open a new connection to do logging on before deleting the old one so    // that we keep at least one connection open to the server at all time.    // This will prevent it from doing its "dropped last connection" things    // which will include resetting the imager server.    vrpn_Connection *new_log_connection = open_new_log_connection(        local_in_logfile_name, local_out_logfile_name, remote_in_logfile_name,        remote_out_logfile_name);    if (new_log_connection == NULL) {        fprintf(stderr, "vrpn_Imager_Stream_Buffer::make_new_logging_"                        "connection(): Cannot open connection/n");        return false;    }    // Unhook the callbacks from the existing logging connection so that    // we don't end up with two callbacks for each message.    if (!teardown_handlers_for_logging_connection(d_log_connection)) {        fprintf(stderr, "vrpn_Imager_Stream_Buffer::make_new_logging_"                        "connection(): Cannot teardown connection/n");        return false;    }    // Hook the callbacks up to the new connection so that we will get reports    // from the server.    if (!setup_handlers_for_logging_connection(new_log_connection)) {        fprintf(stderr, "vrpn_Imager_Stream_Buffer::make_new_logging_"                        "connection(): Cannot setup connection/n");        return false;    }    // Mainloop the new connection object until it becomes connected or we    // time out.  If we time out, then put things back on the old connection    // and tell the thread it is time to self-destruct.  The way we check    // for connected cannot be just that the connection's connected() method    // returns true (because our end can be marked connected before the other    // end decides it has complete the connection.  Rather, we check to see    // that we've got a new description report from the server -- indicating    // that it has seen the new report.  This also lets us know that the old    // log file will have accumulated all images up to the new report, so we    // can shut it off without losing any images in the switch to the new    // log file (there may be duplicates, but not losses).    struct timeval start, now;    vrpn_gettimeofday(&start, NULL);    now = start;    d_ready_to_drop_old_connection = false;    while (!d_ready_to_drop_old_connection &&           (vrpn_TimevalDiff(now, start).tv_sec < 3)) {        new_log_connection->mainloop(); // Enable connection set-up to occur        new_log_connection->save_log_so_far();        d_log_connection->mainloop(); // Eat up (and log) any incoming messages        d_log_connection->save_log_so_far();        vrpn_gettimeofday(&now, NULL);        vrpn_SleepMsecs(1);    };    if (!d_ready_to_drop_old_connection) {        fprintf(stderr, "vrpn_Imager_Stream_Buffer::make_new_logging_"                        "connection(): Could not connect new logging "                        "connection/n");        teardown_handlers_for_logging_connection(new_log_connection);        setup_handlers_for_logging_connection(d_log_connection);        new_log_connection->removeReference();        d_shared_state.time_to_exit(true);        return false;    }    // Delete the old connection object by reducing its reference count.    d_log_connection->removeReference();    // Set up to use the new connection    d_log_connection = new_log_connection;    return true;}
开发者ID:godbyk,项目名称:vrpn,代码行数:75,


示例22: main

int main (int, char **) {  vrpn_Connection * connection;  connection = vrpn_create_server_connection(4999);  int myID = connection->register_sender("rpc_Test");  rpc_Test * enc_out = new rpc_Test(connection);  connection->mainloop();  struct timeval now;  char * buf = NULL;  vrpn_int32 len = 0;  vrpn_gettimeofday(&now, NULL);  printf("Expect Empty/n");  connection->pack_message(len, now, enc_out->d_Empty_type, myID,                           (char *) buf, vrpn_CONNECTION_RELIABLE);  connection->mainloop();  buf = enc_out->encode_Simple(&len, 2, 1.85f, 3.23f);  vrpn_gettimeofday(&now, NULL);  printf("Expect Simple, 2, 1.85, 3.23/n");  connection->pack_message(len, now, enc_out->d_Simple_type, myID,                           (char *) buf, vrpn_CONNECTION_RELIABLE);  delete [] buf; buf = NULL;  connection->mainloop();  const vrpn_int32 cnt = 3;  char nm[NAME_LENGTH] = "Jones";  char nm2[cnt]= "nM";  char doublenm[4][NAME_LENGTH] = {"one", "two", "three", "four"};  int i;//    char *p_to_char[4]= {"one", "two", "three", "four"};//    char (*arr_of_p)[4] ;//    printf ("size %d %d/n", sizeof(p_to_char), sizeof(arr_of_p));  char **triplenm[4]; //char **(*p_t)[4] = &triplenm;  for (i =0; i<4; i++) {      triplenm[i] = new char *[cnt];      for (int j=0; j< cnt; j++) {          triplenm[i][j] = new char[cnt];          sprintf (triplenm[i][j], "%c%c", (char)((int)'a' + i),                   (char)((int)'j' + j));       }  }//    char triplenm[4][cnt][cnt] =   { {"aa", "ab", "ac" } ,//                                     {"ba", "bb", "bc" } ,//                                     {"ca", "cb", "cc" } ,//                                     {"da", "db", "dc" } };  buf = enc_out->encode_CharArray(&len, cnt, nm, nm2,                                   doublenm, triplenm);  vrpn_gettimeofday(&now, NULL);  printf("Expect CharArray .../n");  connection->pack_message(len, now, enc_out->d_CharArray_type, myID,                           (char *) buf, vrpn_CONNECTION_RELIABLE);  delete [] buf; buf = NULL;  connection->mainloop();  //  vrpn_int32 cnt;  vrpn_int32 shortstuff[] = {1,2,3};  vrpn_int32 constdouble[6][4];  vrpn_int32 *triple[4][NAME_LENGTH];  for ( i =0; i<6; i++) {      for (int j=0; j< 4; j++) {          constdouble[i][j] = i+j;      }  }  for ( i =0; i<4; i++) {      for (int j=0; j< NAME_LENGTH; j++) {          triple[i][j] = new vrpn_int32[cnt];          for (int k=0; k< cnt; k++) {              triple[i][j][k] = i+j+k;          }      }  }  buf = enc_out->encode_IntArray(&len, cnt, &(shortstuff[0]),                                  constdouble, triple);  vrpn_gettimeofday(&now, NULL);  printf("Expect IntArray .../n");  connection->pack_message(len, now, enc_out->d_IntArray_type, myID,                           (char *) buf, vrpn_CONNECTION_RELIABLE);  delete [] buf; buf = NULL;  connection->mainloop();    vrpn_int32 count = 3;  char name[64] = "Z Piezo";  char units[64]= "nm";  vrpn_float32 offset = 1.3f;  vrpn_float32 scale = 0.025f;  char * mptr; int mlen;  buf = enc_out->encode_ReportScanDatasets_header ( &len, &mptr, &mlen, count );  for (int lv_1 = 0; lv_1 < count; lv_1++) {   enc_out->encode_ReportScanDatasets_body ( &len, buf, &mptr, &mlen,                                              name, units, offset, scale );//.........这里部分代码省略.........
开发者ID:ASPePeX,项目名称:vrpn,代码行数:101,


示例23: vrpn_test_threads_and_semaphores

bool vrpn_test_threads_and_semaphores(void){  //------------------------------------------------------------  // Make a semaphore to test in single-threaded mode.  First run its count all the way  // down to zero, then bring it back to the full complement and then bring it down  // again.  Check that all of the semaphores are available and also that there are no  // more than expected available.  const unsigned sem_count = 5;  vrpn_Semaphore s(sem_count);  unsigned i;  for (i = 0; i < sem_count; i++) {    if (s.condP() != 1) {      fprintf(stderr, "vrpn_test_threads_and_semaphores(): Semaphore ran out of counts/n");      return false;    }  }  if (s.condP() != 0) {    fprintf(stderr, "vrpn_test_threads_and_semaphores(): Semaphore had too many counts/n");    return false;  }  for (i = 0; i < sem_count; i++) {    if (s.v() != 0) {      fprintf(stderr, "vrpn_test_threads_and_semaphores(): Could not release Semaphore/n");      return false;    }  }  for (i = 0; i < sem_count; i++) {    if (s.condP() != 1) {      fprintf(stderr, "vrpn_test_threads_and_semaphores(): Semaphore ran out of counts, round 2/n");      return false;    }  }  if (s.condP() != 0) {    fprintf(stderr, "vrpn_test_threads_and_semaphores(): Semaphore had too many counts, round 2/n");    return false;  }  //------------------------------------------------------------  // Get a semaphore and use it to construct a thread data structure and then  // a thread.  Use that thread to test whether threading is enabled (if not, then  // this completes our testing) and to find out how many processors there are.  vrpn_ThreadData	td;  td.pvUD = NULL;  vrpn_Thread	t(vrpn_test_thread_body, td);  // If threading is not enabled, then we're done.  if (!t.available()) {    return true;  }  // Find out how many processors we have.  unsigned num_procs = t.number_of_processors();  if (num_procs == 0) {    fprintf(stderr, "vrpn_test_threads_and_semaphores(): vrpn_Thread::number_of_processors() returned zero/n");    return false;  }  //------------------------------------------------------------  // Now make sure that we can actually run a thread.  Do this by  // creating a semaphore with one entry and calling p() on it.  // Then make sure we can't p() it again and then run a thread  // that will call v() on it when it runs.  vrpn_Semaphore	sem;  if (sem.p() != 1) {    fprintf(stderr, "vrpn_test_threads_and_semaphores(): thread-test Semaphore had no count/n");    return false;  }  if (sem.condP() != 0) {    fprintf(stderr, "vrpn_test_threads_and_semaphores(): thread-test Semaphore had too many counts/n");    return false;  }  t.userData(&sem);  if (!t.go()) {    fprintf(stderr, "vrpn_test_threads_and_semaphores(): Could not start thread/n");    return false;  }  struct timeval start;  struct timeval now;  vrpn_gettimeofday(&start, NULL);  while (true) {    if (sem.condP() == 1) {      // The thread must have run; we got the semaphore!      break;    }    // Time out after three seconds if we haven't had the thread run to reset    // the semaphore.    vrpn_gettimeofday(&now, NULL);    struct timeval diff = vrpn_TimevalDiff( now, start );    if (diff.tv_sec >= 3) {      fprintf(stderr, "vrpn_test_threads_and_semaphores(): Thread didn't run/n");      return false;    }    vrpn_SleepMsecs(1);  }  return true;}
开发者ID:lpberg,项目名称:vrpn,代码行数:99,


示例24: vrpn_gettimeofday

int vrpn_gettimeofday(timeval *tp, void *voidp){    static int fFirst=1;    static int fHasPerfCounter=1;    static struct _timeb tbInit;    static LARGE_INTEGER liInit;    static LARGE_INTEGER liNow;    static LARGE_INTEGER liDiff;    timeval tvDiff;#ifndef _STRUCT_TIMEZONE  #define _STRUCT_TIMEZONE  /* from HP-UX */  struct timezone {      int     tz_minuteswest; /* minutes west of Greenwich */      int     tz_dsttime;     /* type of dst correction */  };#endif  struct timezone *tzp = (struct timezone *)voidp;    if (!fHasPerfCounter) {        _ftime(&tbInit);        tp->tv_sec  = tbInit.time;        tp->tv_usec = tbInit.millitm*1000;        return 0;    }    if (fFirst) {        LARGE_INTEGER liTemp;        // establish a time base        fFirst=0;	// Check to see if we are on a Windows NT machine (as opposed to a	// Windows 95/98 machine).  If we are not, then use the _ftime code	// because the hi-perf clock does not work under Windows 98SE on my	// laptop, although the query for one seems to indicate that it is	// available.	{   OSVERSIONINFO osvi;	    memset(&osvi, 0, sizeof(OSVERSIONINFO));	    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);	    GetVersionEx(&osvi);	    if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) {                fprintf(stderr, "/nvrpn_gettimeofday: disabling hi performance clock on non-NT system. "	             "Defaulting to _ftime (~6 ms resolution) .../n");		fHasPerfCounter=0;	        vrpn_gettimeofday( tp, tzp );		return 0;	    }	}        // check that hi-perf clock is available        if ( !(fHasPerfCounter = QueryPerformanceFrequency( &liTemp )) ) {            fprintf(stderr, "/nvrpn_gettimeofday: no hi performance clock available. "                 "Defaulting to _ftime (~6 ms resolution) .../n");            fHasPerfCounter=0;            vrpn_gettimeofday( tp, tzp );            return 0;        }        if (vrpn_AdjustFrequency()<0) {            fprintf(stderr, "/nvrpn_gettimeofday: can't verify clock frequency. "                 "Defaulting to _ftime (~6 ms resolution) .../n");            fHasPerfCounter=0;            vrpn_gettimeofday( tp, tzp );            return 0;        }        // get current time        // We assume this machine has a time stamp counter register --        // I don't know of an easy way to check for this        rdtsc( liInit );        _ftime(&tbInit);        // we now consider it to be exactly the time _ftime returned        // (beyond the resolution of _ftime, down to the perfCounter res)    }    // now do the regular get time call to get the current time    rdtsc( liNow );    // find offset from initial value    liDiff.QuadPart = liNow.QuadPart - liInit.QuadPart;    tvDiff.tv_sec = (long) ( liDiff.QuadPart / VRPN_CLOCK_FREQ );    tvDiff.tv_usec = (long)(1e6*((liDiff.QuadPart-VRPN_CLOCK_FREQ                                  *tvDiff.tv_sec)                                 / (double) VRPN_CLOCK_FREQ) );    // pack the value and clean it up    tp->tv_sec  = tbInit.time + tvDiff.tv_sec;    tp->tv_usec = tbInit.millitm*1000 + tvDiff.tv_usec;    while (tp->tv_usec >= 1000000) {        tp->tv_sec++;        tp->tv_usec -= 1000000;    }    return 0;}
开发者ID:lpberg,项目名称:vrpn,代码行数:100,


示例25: GetTimeZoneInformation

  if (tzp != NULL) {    TIME_ZONE_INFORMATION tz;    GetTimeZoneInformation(&tz);    tzp->tz_minuteswest = tz.Bias ;    tzp->tz_dsttime = (tz.StandardBias != tz.Bias);  }  return 0;}#endif //defined(VRPN_WINDOWS_CLOCK_V2)#endif //defined(_WIN32)// do the calibration before the program ever starts upstatic timeval __tv;static int __iTrash = vrpn_gettimeofday(&__tv, (struct timezone *)NULL);#endif // VRPN_UNSAFE_WINDOWS_CLOCK#include <stdio.h>                      // for fprintf, stderr, perror, etc#include <string.h>                     // for memcpy, strlen, strcpy, etc#ifndef _WIN32#include <errno.h>                      // for EAGAIN, errno#include <signal.h>                     // for pthread_kill, SIGKILL#endif#define ALL_ASSERT(exp, msg) if(!(exp)){ fprintf(stderr, "/nAssertion failed! /n %s (%s, %s)/n", msg, __FILE__, __LINE__); }// init all fields in init()vrpn_Semaphore::vrpn_Semaphore( int cNumResources ) :
开发者ID:lpberg,项目名称:vrpn,代码行数:31,


示例26: vrpn_gettimeofday

// plays at most one entry which comes before end_filetime// returns//   -1 on error (including EOF, call eof() to test)//    0 for normal result (played one entry)//    1 if we hit end_filetimeint vrpn_File_Connection::playone_to_filetime( timeval end_filetime ){    vrpn_Endpoint * endpoint = d_endpoints[0];    timeval now;    int retval;    // If we don't have a currentLogEntry, then we've gone past the end of the    // file.    if (!d_currentLogEntry) {      return 1;    }    vrpn_HANDLERPARAM & header = d_currentLogEntry->data;    if (vrpn_TimevalGreater(header.msg_time, end_filetime)) {        // there are no entries to play after the current        // but before end_filetime        return 1;    }    // TCH July 2001    // XXX A big design decision:  do we re-log messages exactly,    // or do we mark them with the time they were played back?    // Maybe this should be switchable, but the latter is what    // I need yesterday.    vrpn_gettimeofday(&now, NULL);    retval = endpoint->d_inLog->logIncomingMessage                    (header.payload_len, now, header.type,                     header.sender, header.buffer);    if (retval) {      fprintf(stderr, "Couldn't log /"incoming/" message during replay!/n");      return -1;    }    // advance current file position    d_time = header.msg_time;  // Handle this log entry    if (header.type >= 0) {#ifdef	VERBOSE	printf("vrpn_FC: Msg Sender (%s), Type (%s), at (%ld:%ld)/n",		endpoint->other_senders[header.sender].name,		endpoint->other_types[header.type].name,		header.msg_time.tv_sec, header.msg_time.tv_usec);#endif        if (endpoint->local_type_id(header.type) >= 0) {            if (do_callbacks_for(endpoint->local_type_id(header.type),                                 endpoint->local_sender_id(header.sender),                                 header.msg_time, header.payload_len,                                 header.buffer)) {                return -1;            }        }                } else {  // system handler                    if (header.type != vrpn_CONNECTION_UDP_DESCRIPTION) {            if (doSystemCallbacksFor(header, endpoint)) {                fprintf(stderr, "vrpn_File_Connection::playone_to_filename:  "                        "Nonzero system return./n");                return -1;            }        }    }                return advance_currentLogEntry();}
开发者ID:BlueBrain,项目名称:vrpn,代码行数:72,


示例27: fprintf

// virtualint vrpn_File_Connection::read_entry (void){    vrpn_LOGLIST * newEntry;    int retval;    newEntry = new vrpn_LOGLIST;    if (!newEntry) {        fprintf(stderr, "vrpn_File_Connection::read_entry: Out of memory./n");        return -1;    }    // Only print this message every second or so    if (!d_file) {      static struct timeval last_told = {0,0};      static struct timeval now;      vrpn_gettimeofday(&now, NULL);      if (now.tv_sec != last_told.tv_sec) {        fprintf(stderr, "vrpn_File_Connection::read_entry: no open file/n");        memcpy(&last_told, &now, sizeof(last_told));      }      delete newEntry;      return -1;    }    // Get the header of the next message.  This was done as a horrible    // hack in the past, where we read the sizeof a struct from the file,    // including a pointer.  This of course changed on 64-bit architectures.    // The pointer value was not needed.  We now read it as an array of    // 32-bit values and then stuff these into the structure.  Unfortunately,    // we now need to both send and read the bogus pointer value if we want    // to be compatible with old versions of log files.    vrpn_HANDLERPARAM & header = newEntry->data;    vrpn_int32  values[6];    retval = fread(values, sizeof(vrpn_int32), 6, d_file);    // return 1 if nothing to read OR end-of-file;    // the latter isn't an error state    if (retval <= 0) {        // Don't close the file because we might get a reset message...        delete newEntry;        return 1;    }    header.type = ntohl(values[0]);    header.sender = ntohl(values[1]);    header.msg_time.tv_sec = ntohl(values[2]);    header.msg_time.tv_usec = ntohl(values[3]);    header.payload_len = ntohl(values[4]);    header.buffer = NULL; // values[5] is ignored -- it used to hold the bogus pointer.    // get the body of the next message    if (header.payload_len > 0) {      header.buffer = new char [header.payload_len];      if (!header.buffer) {        fprintf(stderr, "vrpn_File_Connection::read_entry:  "                "Out of memory./n");        return -1;      }      retval = fread((char *) header.buffer, 1, header.payload_len, d_file);    }    // return 1 if nothing to read OR end-of-file;    // the latter isn't an error state    if (retval <= 0) {        // Don't close the file because we might get a reset message...        return 1;    }    // If we are accumulating messages, keep the list of them up to    // date.  If we are not, toss the old to make way for the new.    // Whenever this function returns 0, we need to have set the    // Head and Tail to something non-NULL.    if (d_accumulate) {      // doubly-linked list maintenance, putting this one at the tail.      newEntry->next = NULL;      newEntry->prev = d_logTail;      if (d_logTail) {	  d_logTail->next = newEntry;      }      d_logTail = newEntry;      // If we've not gotten any messages yet, this one is also the      // head.      if (!d_logHead) {	  d_logHead = d_logTail;      }    } else { // Don't keep old list entries.      // If we had a message before, get rid of it and its data now.  We      // could use either Head or Tail here because they will point      // to the same message.      if (d_logTail) {        if (d_logTail->data.buffer) {//.........这里部分代码省略.........
开发者ID:BlueBrain,项目名称:vrpn,代码行数:101,


示例28: vrpn_gettimeofday

// sync the baud rate on the ibox.// seconds determines how long the process is permitted to continueint vrpn_ImmersionBox::syncBaudrate (double seconds) {    struct timeval miniDelay;    miniDelay.tv_sec = 0;    miniDelay.tv_usec = 50000;    unsigned long maxDelay = 1000000L * (long) seconds;    struct timeval start_time;    vrpn_gettimeofday(&start_time, NULL);    int loggedOn = 0;    unsigned char responseString[8];    const unsigned char * matchString = (unsigned char *) S_INITIALIZE ;  // IMMC    int index, numRead;    if (serial_fd < 0)	return 0;    vrpn_flush_input_buffer(serial_fd);    vrpn_write_characters(serial_fd, (const unsigned char *)"E", 1);    pause (0.01);    while (!loggedOn) {	struct timeval current_time;	vrpn_gettimeofday(&current_time, NULL);	if (vrpn_TimevalDuration(current_time, start_time) > maxDelay ) {	    // if we've timed out, go back unhappy	    fprintf(stderr,"vrpn_ImmersionBox::syncBaudrate timeout expired: %lf secs /n", seconds);	    break;  // out of while loop	}			// send "IMMC"	if (4 != vrpn_write_characters(serial_fd, matchString, 4)) {	    fprintf(stderr,"vrpn_ImmersionBox::syncBaudrate could not write to serial port/n");	    break;  // out of while loop	}	pause (0.015);	// wait for 4 characters	numRead = vrpn_read_available_characters(serial_fd, responseString, 4, &miniDelay);	if (numRead <= 0) 	    continue;	// get 4 characters, hopefully "IMMC"	for (index = 0; index < 4; index++) {	    // get a character, check for failure	    if (responseString[index] != matchString[index]) 		break;	}	// if we got all four, we're done	if (4 == index)	    loggedOn = 1;    }     if (!loggedOn)	return 0;    // now begin the session && ensure that its an ibox we're talking to    matchString = (const unsigned char *) "IBOX";    vrpn_write_characters(serial_fd, (const unsigned char *)"BEGIN", 5);    numRead = vrpn_read_available_characters(serial_fd, responseString, 4, &miniDelay);    if (numRead <= 0) 	return 0;    // check 4 characters, hopefully "IBOX"    for (index = 0; index < 4; index++) {	// get a character, check for failure	if (responseString[index] != matchString[index]) 	    return 0;    }    vrpn_flush_input_buffer(serial_fd);    return 1;}
开发者ID:godbyk,项目名称:vrpn,代码行数:78,



注:本文中的vrpn_gettimeofday函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ vrtc_cmos_read函数代码示例
C++ vrele函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。