Example #1
0
static int do_voodoo(int fd) {
    int i;
    char recv_buf[256];

    static struct {
        char buf[64];
        size_t len;
    } reports[] = {
        {{18, 0x01}, 2},
        {{18, 0x05}, 2},
        {{23, 0x05}, 2},
        {{23, 0x01}, 2},
        {{23, 0x11}, 2},
        {{40, 0x00, 0x02}, 3},
        {{40, 0x10, 0x00}, 3},
        {{0x22, 0x14, 0x01, 0x00, 0x06, 0x00, 0x00, 0x03, 0xe8, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 27},
        {{0x24, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x5e, 0x04, 0x73, 0x07, 0xf0, 0xe0, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 32},
    };

    for (i=0; i < sizeof(reports)/sizeof(reports[0]); i++) {
        send_report(fd, reports[i].buf, reports[i].len);
        get_report(fd, reports[i].buf[0], recv_buf, reports[i].len);
    }

    return 0;
}
Example #2
0
void	vrpn_Nikon_Controls::mainloop()
{
  char errmsg[256];

  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 so long as there are more

	    struct timeval current_time;
	    vrpn_gettimeofday(&current_time, NULL);
	    if ( vrpn_TimevalDuration(current_time,timestamp) > POLL_INTERVAL) {
	      static struct timeval last_poll = {0, 0};

	      if (vrpn_TimevalDuration(current_time, last_poll) > TIMEOUT_TIME_INTERVAL) {
		// Ask the unit for its current focus location, which will cause it to respond.
		char  msg[256];
		sprintf(msg, "rSPR\r");
		if (vrpn_write_characters(serial_fd, (unsigned char *)msg, strlen(msg)) != (int)strlen(msg)) {
		  fprintf(stderr, "vrpn_Nikon_Controls::mainloop(): Can't write focus request command\n");
		  status = STATUS_RESETTING;
		  return;
		}
	        vrpn_gettimeofday(&last_poll, NULL);
	      } else {
		return;
	      }
	    }

	    if ( vrpn_TimevalDuration(current_time,timestamp) > TIMEOUT_TIME_INTERVAL) {
		    sprintf(errmsg,"Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",
					current_time.tv_sec, static_cast<long>(current_time.tv_usec),
					timestamp.tv_sec, static_cast<long>(timestamp.tv_usec));
		    VRPN_MSG_ERROR(errmsg);
		    status = STATUS_RESETTING;
	    }
      }
        break;

    default:
	VRPN_MSG_ERROR("Unknown mode (internal error)");
	break;
  }
}
Example #3
0
void vrpn_Tracker_3DMouse::mainloop()
{
	server_mainloop();

	switch(status)
	{
		case vrpn_TRACKER_AWAITING_STATION:
		case vrpn_TRACKER_PARTIAL:
		case vrpn_TRACKER_SYNCING:
			if (get_report()) send_report();
			break;
		case vrpn_TRACKER_RESETTING:
			reset();
			break;
		case vrpn_TRACKER_FAIL:
			fprintf(stderr, "3DMouse failed, trying to reset (Try power cycle if more than 4 attempts made)\n");
			if (serial_fd >= 0)
			{
				vrpn_close_commport(serial_fd);
				serial_fd = -1;
			}
			if ( (serial_fd=vrpn_open_commport(portname, baudrate)) == -1)
			{
				fprintf(stderr,"vrpn_Tracker_3DMouse::mainloop(): Cannot Open serial port\n");
				status = vrpn_TRACKER_FAIL;
				return;
			}
			status = vrpn_TRACKER_RESETTING;
			break;
		default:
			break;
	}
}
Example #4
0
void vrpn_Tracker_MotionNode::mainloop()
{
  // Call the generic server mainloop, since we are a server
  server_mainloop();

  get_report();
}
Example #5
0
void vrpn_DevInput::mainloop()
{
  get_report();

  server_mainloop();

  report_changes();
}
Example #6
0
// This function should be called each time through the main loop
// of the server code. It polls for data from the OWL server and
// sends them if available.
void vrpn_Tracker_PhaseSpace::mainloop()
{
  get_report();

  // Call the generic server mainloop, since we are a server
  server_mainloop();
  return;
}
Example #7
0
void vrpn_Tracker_ViewPoint::mainloop()
{
    // Call the server mainloop
	server_mainloop();

	// Get data from the DLL
    get_report();
}
Example #8
0
void	vrpn_IDEA::mainloop()
{
  char errmsg[256];

  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 so long as there are more

	    struct timeval current_time;
	    vrpn_gettimeofday(&current_time, NULL);
	    if ( duration(current_time,d_timestamp) > POLL_INTERVAL) {
	      static struct timeval last_poll = {0, 0};

              if (duration(current_time, last_poll) > TIMEOUT_TIME_INTERVAL) {
		// Send another request to the unit, in case we've somehow
                // dropped a request.
                if (!send_command("l")) {
                  IDEA_ERROR("Could not request position");
                  status = STATUS_RESETTING;
                }
	        vrpn_gettimeofday(&last_poll, NULL);
	      } else {
		return;
	      }
	    }

	    if ( duration(current_time,d_timestamp) > TIMEOUT_TIME_INTERVAL) {
		    sprintf(errmsg,"Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",
					current_time.tv_sec, static_cast<long>(current_time.tv_usec),
					d_timestamp.tv_sec, static_cast<long>(d_timestamp.tv_usec));
		    IDEA_ERROR(errmsg);
		    status = STATUS_RESETTING;
	    }
      }
        break;

    default:
	IDEA_ERROR("Unknown mode (internal error)");
	break;
  }
}
Example #9
0
void vrpn_Tracker_NDI_Polaris::mainloop()
{
	get_report();
	
	// Call the generic server mainloop, since we are a server
	server_mainloop();
	
	return;
}
Example #10
0
/******************************************************************************
 * NAME      : vrpn_5dt::mainloop
 * ROLE      :  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 device,
 *              either trying to reset it or trying to get a reading from it.  It will
 *              try to reset the device if no data has come from it for a couple of
 *              seconds
 * ARGUMENTS : 
 * RETURN    : void
 ******************************************************************************/
void vrpn_5dt::mainloop ()
{
  char l_errmsg[256];

  server_mainloop();
  if (_wireless) {
    static bool announced = false;
    if (!announced) {
      _5DT_INFO ("Will connect to a receive-only 'wireless-type' glove - there may be a few warnings before we succeed.");
      announced = true;
    }
  }
  switch (_status)
    {
    case STATUS_RESETTING:
      if (reset()== -1)
	{
	  _5DT_ERROR ("vrpn_Analog_5dt: Cannot reset the glove!");
	}
      break;

    case STATUS_SYNCING:
      syncing ();
      break;

    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).
        get_report();
        struct timeval current_time;
        vrpn_gettimeofday (&current_time, NULL);
        if (duration (current_time, timestamp) > MAX_TIME_INTERVAL) {
          sprintf (l_errmsg, "vrpn_5dt::mainloop: Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",
                   current_time.tv_sec,
                   static_cast<long> (current_time.tv_usec),
                   timestamp.tv_sec,
                   static_cast<long> (timestamp.tv_usec));
          _5DT_ERROR (l_errmsg);
          _status = STATUS_RESETTING;
        }
      }
      break;

    default:
      _5DT_ERROR ("vrpn_5dt::mainloop: Unknown mode (internal error)");
      break;
    }
}
Example #11
0
int print_midpoint_entry( FILE *stream, NUM planet, MIDPT *ptr,
		 BITS mode, int file, char *name, int table, int global )
{
 const char *rpm;
 COUNT x;
 ASPEC *as;
 if ( ptr->total_minutes == -1 )
    return( 1 );
 rpm = get_report( table, global, CH__MID_PLANET );
 if ( rpm == NULL )
    return( 1 );
 if ( output_midpoint_sign( stream, planet, ptr, name, (char *)rpm ) )
    return( 1 );
 if ( file != -1 ) /* show the text */
    get_transfer_text_asp( planet, ptr->second_planet, ptr->sign, file, stream );
 if ( mode & HOUSES ) {
    rpm = get_report( table, global, CH__MID_HOUSE );
    if ( rpm == NULL )
       return( 1 );
    if ( output_midpoint_house( stream, planet, ptr, name, (char *)rpm ) )
       return( 1 );
    }
 else
    fputc( '\n', stream );
 if ( ptr->no_aspect > 0 ) {
    rpm = get_report( table, global, CH__MID_ASPT );
    if ( rpm == NULL )
       return( 1 );
    if ( output_title( stream, name, "", "", (char *)rpm ) )
       return( 1 );
    if ( ptr->no_aspect ) {
       rpm = get_report( table, global, CH__MID_ASPE );
       if ( rpm == NULL )
	  return( 1 );
       for ( x = 1, as = ptr->aspectr; x <= ptr->no_aspect; ++x, ++as ) {
	   if ( print_aspect_entry( stream, planet, as, -1, name, (char *)rpm ) )
	      return( 1 );
	   }
       }
    fputc( '\n', stream );
    }
return( 1 );
}
Example #12
0
bool init_report() {
  if(!get_report()) {
    return true;
  }
  fout = fopen(get_report_file().c_str(), "w");
  if(!fout) {
    return false;
  }
  if(get_json()) {
    fprintf(fout, "[\n");
  }
  return true;
}
Example #13
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;
  }
}
Example #14
0
static int do_simple_voodoo(int fd) {
    char buffer[27];

    get_report(fd, 0x22, buffer, sizeof(buffer));
    if (buffer[0] != 0x22 || buffer[1] != 0x14)
        return 1;

    buffer[2] = 1;
    if (!buffer[3] && buffer[4] != 0x6) {
        buffer[4] = 0x6;
        send_report(fd, buffer, sizeof(buffer));
    }

    return 0;
}
Example #15
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;
  }
}
Example #16
0
void	vrpn_BiosciencesTools::mainloop()
{
  char errmsg[256];

  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 so long as there are more

	    struct timeval current_time;
	    vrpn_gettimeofday(&current_time, NULL);
	    if ( vrpn_TimevalDuration(current_time,timestamp) > TIMEOUT_TIME_INTERVAL) {
		    sprintf(errmsg,"Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",
					current_time.tv_sec, static_cast<long>(current_time.tv_usec),
					timestamp.tv_sec, static_cast<long>(timestamp.tv_usec));
		    DO_ERROR(errmsg);
		    status = STATUS_RESETTING;
	    }
      }
        break;

    default:
	DO_ERROR("Unknown mode (internal error)");
	break;
  }
}
Example #17
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 Magellan,
// either trying to reset it or trying to get a reading from it.
void	vrpn_Magellan::mainloop()
{
  server_mainloop();

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

    case STATUS_SYNCING:
    case STATUS_READING:
	// Keep getting reports until all full reports are read.
	while (get_report()) {};
        break;

    default:
	fprintf(stderr,"vrpn_Magellan: Unknown mode (internal error)\n");
	break;
  }
}
Example #18
0
void vrpn_Tracker_NovintFalcon::mainloop()
{
    struct timeval current_time;
    server_mainloop();

    // no need to report more often than we can poll the device
    vrpn_gettimeofday(&current_time, NULL);
    if ( timediff(current_time, m_timestamp) >= 1000000.0/m_update_rate) {

        // Update the time
        m_timestamp.tv_sec = current_time.tv_sec;
        m_timestamp.tv_usec = current_time.tv_usec;
        switch(status)
        {
        case vrpn_TRACKER_AWAITING_STATION:
        case vrpn_TRACKER_PARTIAL:
        case vrpn_TRACKER_SYNCING:
            if (get_report()) {
                send_report();
                vrpn_Button::report_changes();
                handle_forces();
            }
            break;
        case vrpn_TRACKER_RESETTING:
            reset();
            break;

        case vrpn_TRACKER_FAIL:
            fprintf(stderr, "NovintFalcon #%d failed, trying to reset (Try power cycle if more than 4 attempts made)\n",
                    vrpn_NovintFalcon_Device::MASK_DEVICEIDX & m_devflags);
            status = vrpn_TRACKER_RESETTING;
            break;

        default:
            fprintf(stderr, "NovintFalcon #%d , unknown status message: %d)\n",
                    vrpn_NovintFalcon_Device::MASK_DEVICEIDX & m_devflags, status);
            break;
        }
    }
}
Example #19
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 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;
  }
}
Example #20
0
void vrpn_Tracker_InterSense::mainloop()
{
  // Call the generic server mainloop, since we are a server
  server_mainloop();

  switch (status) {
    case vrpn_TRACKER_SYNCING:
    case vrpn_TRACKER_AWAITING_STATION:
    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).
	    
	  get_report();

	  // Ready for another report
	  status = vrpn_TRACKER_SYNCING;		
      }
      break; 

    case vrpn_TRACKER_RESETTING:
      reset();
      break;

    case vrpn_TRACKER_FAIL:
      VRPN_MSG_WARNING("Tracking failed, trying to reset (try power cycle if more than 4 attempts made)");
      status = vrpn_TRACKER_RESETTING;
      break;
  }
}
Example #21
0
void vrpn_Mouse::mainloop()
{
    get_report();
    server_mainloop();
}
Example #22
0
    bool load_from_file(const char* dwi_file_name)
    {
        file_name = dwi_file_name;
        if (!mat_reader.load_from_file(dwi_file_name))
        {
            error_msg = "Cannot open file";
            return false;
        }
        unsigned int row,col;

        const unsigned short* dim_ptr = 0;
        if (!mat_reader.read("dimension",row,col,dim_ptr))
        {
            error_msg = "Cannot find dimension matrix";
            return false;
        }
        const float* voxel_size = 0;
        if (!mat_reader.read("voxel_size",row,col,voxel_size))
        {
            //error_msg = "Cannot find voxel size matrix";
            //return false;
            std::fill(voxel.vs.begin(),voxel.vs.end(),3.0);
        }
        else
            std::copy(voxel_size,voxel_size+3,voxel.vs.begin());

        if (dim_ptr[0]*dim_ptr[1]*dim_ptr[2] <= 0)
        {
            error_msg = "Invalid dimension setting";
            return false;
        }
        voxel.dim[0] = dim_ptr[0];
        voxel.dim[1] = dim_ptr[1];
        voxel.dim[2] = dim_ptr[2];

        const float* table;
        if (!mat_reader.read("b_table",row,col,table))
        {
            error_msg = "Cannot find b_table matrix";
            return false;
        }
        voxel.bvalues.resize(col);
        voxel.bvectors.resize(col);
        for (unsigned int index = 0;index < col;++index)
        {
            voxel.bvalues[index] = table[0];
            voxel.bvectors[index][0] = table[1];
            voxel.bvectors[index][1] = table[2];
            voxel.bvectors[index][2] = table[3];
            voxel.bvectors[index].normalize();
            table += 4;
        }

        const char* report_buf = 0;
        if(mat_reader.read("report",row,col,report_buf))
            voxel.report = std::string(report_buf,report_buf+row*col);
        else
            get_report(voxel.bvalues,voxel.vs,voxel.report);

        dwi_data.resize(voxel.bvalues.size());
        for (unsigned int index = 0;index < voxel.bvalues.size();++index)
        {
            std::ostringstream out;
            out << "image" << index;
            mat_reader.read(out.str().c_str(),row,col,dwi_data[index]);
            if (!dwi_data[index])
            {
                error_msg = "Cannot find image matrix";
                return false;
            }
        }


        {
            // this grad_dev matrix is rotated
            const float* grad_dev = 0;
            if(mat_reader.read("grad_dev",row,col,grad_dev) && row*col == voxel.dim.size()*9)
            {
                for(unsigned int index = 0;index < 9;index++)
                    voxel.grad_dev.push_back(image::make_image(voxel.dim,grad_dev+index*voxel.dim.size()));
            }
        }

        // create mask;
        calculate_dwi_sum();

        const unsigned char* mask_ptr = 0;
        if(mat_reader.read("mask",row,col,mask_ptr))
        {
            mask.resize(voxel.dim);
            if(row*col == voxel.dim.size())
                std::copy(mask_ptr,mask_ptr+row*col,mask.begin());
        }
        else
            calculate_mask();

        return true;
    }
Example #23
0
int print_entry( FILE *stream, AS_INF *inf, NUM planet, BITS mode,
    int fil, int aspfil, int hsfil, int midfile, AS_INF_EXT *aie,
    char *name, char *comment, int table, int global )
{
 COUNT i, ruler;
 ASPEC *as;
 MIDPT *mid;
 const char *rps;
 static char fmt5[] = { "<%s:>\x80" };

 ruler = sign_rulers[sign(house_cusps[inf->house])];
 if ( output_planet_sign( stream, planet, inf,
			-1, NULL, mode, name, comment, (char *)rppl ) )
    return( 1 );
 if ( mode & TEXT ) {
    if ( inf->cusp == -1 ) {
       get_transfer_text( inf->sign, planet, fil, stream );
       if ( inf->retrograde )
	  get_transfer_text( 12, planet, fil, stream );
       }
    else {
       fprintf( stream, (char *)fmt5, sign_str( inf->sign ) );
       get_transfer_text( inf->sign, planet, fil, stream );
       fprintf( stream, (char *)fmt5, sign_str( inf->cusp ) );
       get_transfer_text( inf->cusp, planet, fil, stream );
       if ( inf->retrograde )
	  get_transfer_text( 12, planet, fil, stream );
       }
    }
 if ( mode & MISCELL ) {
    if ( output_planet_sign( stream, planet, inf,
			   -1, NULL, mode, name, comment, (char *)rpmsc ) )
       return( 1 );
    if ( mode & TEXT )
       get_transfer_text( inf->sign, (inf->misc_code & 3)+29, fil, stream );
    }
 if ( mode & EXT_CALCS ) {
    rps = get_report( table, global, CH__PLAN_EXT );
    if ( rps == NULL )
       return( 1 );
    if ( output_planet_sign_ext( stream, planet, aie, name, (char *)rps ) )
       return( 1 );
    }
 if ( mode & HOUSES && planet != ASCEND && planet != MED_COELI &&
	  planet != IM_COELI ) {
    if ( output_planet_house( stream, planet, inf, name, comment, (char *)rphs ) )
       return( 1 );
    if ( mode & TEXT )
       get_transfer_text( inf->house, planet, hsfil, stream );
	   get_transfer_text( ruler, 13, hsfil, stream );
    }
 if ( mode & ASPECTS ) {
    if ( inf->no_aspects > 0 ) {
       if ( output_title( stream, name, "", "", (char *)rpah ) )
	  return( 1 );
       for ( as = inf->aspectr, i = 1; i <= inf->no_aspects; ++i, ++as )
	   if ( print_aspect_entry( stream, planet, as, ((mode & TEXT)?aspfil:-1), name, (char *)rpas ) )
	      return( 1 );
       }
    }
#ifdef DELUXE
 if ( inf->no_midpt > 0 ) {
    rps = get_report( table, global, CH__MIDPT_HD );
    if ( rps == NULL )
       return( 1 );
    if ( output_title( stream, name, comment, "", (char *)rps ) )
       return( 1 );
    for ( mid = inf->midptr, i = 1; i <= inf->no_midpt; ++i, ++mid )
	print_midpoint_entry( stream, planet, mid, mode, midfile, name, table, global );
    }
#endif
 fputc( '\n', stream );
 return( 1 );
}
Example #24
0
void vrpn_Tracker_Isotrak::reset()
{
    static int numResets = 0;	// How many resets have we tried?
    int i,resetLen,ret;
    unsigned char reset[10];
    char errmsg[512];
    
    //--------------------------------------------------------------------
    // This section deals with resetting the tracker to its default state.
    // Multiple attempts are made to reset, getting more aggressive each
    // time. This section completes when the tracker reports a valid status
    // message after the reset has completed.
    //--------------------------------------------------------------------
    
    // Send the tracker a string that should reset it.  The first time we
    // try this, just do the normal 'c' command to put it into polled mode.
    // After a few tries with this, use a [return] character, and then use the ^Y to reset. 
    
    resetLen = 0;
    numResets++;		  	
    
    // We're trying another reset
    if (numResets > 1) {	        // Try to get it out of a query loop if its in one
            reset[resetLen++] = (unsigned char) (13); // Return key -> get ready
    }
    
    if (numResets > 2) {
        reset[resetLen++] = (unsigned char) (25); // Ctrl + Y -> reset the tracker
    }
    
    reset[resetLen++] = 'c'; // Put it into polled (not continuous) mode
    
    
    sprintf(errmsg, "Resetting the tracker (attempt %d)", numResets);
    VRPN_MSG_WARNING(errmsg);
    
    for (i = 0; i < resetLen; i++) {
            if (vrpn_write_characters(serial_fd, &reset[i], 1) == 1) {
                    fprintf(stderr,".");
                    vrpn_SleepMsecs(1000.0*2);  // Wait after each character to give it time to respond
            } else {
                    perror("Isotrack: Failed writing to tracker");
                    status = vrpn_TRACKER_FAIL;
                    return;
            }
    }
    //XXX Take out the sleep and make it keep spinning quickly
    if (numResets > 2) {
        vrpn_SleepMsecs(1000.0*20);	// Sleep to let the reset happen, if we're doing ^Y
    }
    
    fprintf(stderr,"\n");
    
    // 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
    vrpn_SleepMsecs(1000.0*2);
    unsigned char scrap[80];
    if ( (ret = vrpn_read_available_characters(serial_fd, scrap, 80)) != 0) {
        sprintf(errmsg,"Got >=%d characters after reset",ret);
        VRPN_MSG_WARNING(errmsg);
        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) {
        vrpn_SleepMsecs(1000.0*1); // Sleep for a second to let it respond
    } else {
            perror("  Isotrack write failed");
            status = vrpn_TRACKER_FAIL;
            return;
    }
    
    // Read Status
    unsigned char statusmsg[22];
    
    // Attempt to read 21 characters.  
    ret = vrpn_read_available_characters(serial_fd, statusmsg, 21);
    
    if ( (ret != 21) ) {
            fprintf(stderr,
            "  Got %d of 21 characters for status\n",ret);
        VRPN_MSG_ERROR("Bad status report from Isotrack, retrying reset");
        return;
    }
    else if ( (statusmsg[0]!='2') ) {
        int i;
        statusmsg[sizeof(statusmsg) - 1] = '\0';	// Null-terminate the string
        fprintf(stderr, "  Isotrack: bad status (");
        for (i = 0; i < ret; i++) {
            if (isprint(statusmsg[i])) {
                    fprintf(stderr,"%c",statusmsg[i]);
            } else {
                    fprintf(stderr,"[0x%02X]",statusmsg[i]);
            }
        }
        fprintf(stderr,")\n");
        VRPN_MSG_ERROR("Bad status report from Isotrack, retrying reset");
        return;
    } else {
        VRPN_MSG_WARNING("Isotrack gives correct status (this is good)");
        numResets = 0; 	// Success, use simple reset next time
    }
    
    //--------------------------------------------------------------------
    // Now that the tracker has given a valid status report, set all of
    // the parameters the way we want them. We rely on power-up setting
    // based on the receiver select switches to turn on the receivers that
    // the user wants.
    //--------------------------------------------------------------------
    
    // Set output format. This is done once for the Isotrak, not per channel.
    if (set_sensor_output_format(0)) {
        return;
    }
    
    // Enable filtering if the constructor parameter said to.
    // Set filtering for both position (x command) and orientation (v command)
    // to the values that are recommended as a "jumping off point" in the
    // Isotrack manual.

    if (do_filter) {
        if (vrpn_write_characters(serial_fd, (const unsigned char *)"x0.2,0.2,0.8,0.8\015", 17) == 17) {
            vrpn_SleepMsecs(1000.0*1); // Sleep for a second to let it respond
        } else {
            perror("  Isotrack write position filter failed");
            status = vrpn_TRACKER_FAIL;
            return;
        }
        if (vrpn_write_characters(serial_fd, (const unsigned char *)"v0.2,0.2,0.8,0.8\015", 17) == 17) {
            vrpn_SleepMsecs(1000.0*1); // Sleep for a second to let it respond
        } else {
            perror("  Isotrack write orientation filter failed");
            status = vrpn_TRACKER_FAIL;
            return;
        }
    }
    
    // RESET Alignment reference frame
    if (vrpn_write_characters(serial_fd, (const unsigned char *) "R1\r", 3) != 3) {
            perror("  Isotrack write failed");
            status = vrpn_TRACKER_FAIL;
            return;
    } else {
            VRPN_MSG_WARNING("Isotrack reset ALIGNMENT reference frame (this is good)");
    }
    
    // reset BORESIGHT
    if (vrpn_write_characters(serial_fd, (const unsigned char *) "b1\r", 3) != 3) {
            perror("  Isotrack write failed");
            status = vrpn_TRACKER_FAIL;
            return;
    } else {
            VRPN_MSG_WARNING("Isotrack reset BORESIGHT (this is good)");
    }
    
    // Set data format to METRIC mode
    if (vrpn_write_characters(serial_fd, (const unsigned char *) "u", 1) != 1) {
            perror("  Isotrack write failed");
            status = vrpn_TRACKER_FAIL;
            return;
    } else {
            VRPN_MSG_WARNING("Isotrack set to metric units (this is good)");
    }



    // 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("  Isotrack writing extended reset commands...\n");

        // Make a copy of the additional reset string, since it is consumed
        strncpy(add_cmd_copy, add_reset_cmd, sizeof(add_cmd_copy));

        // 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
    // F = ASCII, f = binary
    if (vrpn_write_characters(serial_fd, (const unsigned char *) "f", 1) != 1) {
            perror("  Isotrack write failed");
            status = vrpn_TRACKER_FAIL;
            return;
    } else {
            VRPN_MSG_WARNING("Isotrack set to BINARY mode (this is good)");
    }
    
    
    // Set tracker to continuous mode
    if (vrpn_write_characters(serial_fd, (const unsigned char *) "C", 1) != 1) {
            perror("  Isotrack write failed");
            status = vrpn_TRACKER_FAIL;
            return;
    } else {
            VRPN_MSG_WARNING("Isotrack set to continuous mode (this is good)");
    }

    VRPN_MSG_WARNING("Reset Completed.");

    status = vrpn_TRACKER_SYNCING;	// We're trying for a new reading

    // Ok, device is ready, we want to calibrate to sensor 1 current position/orientation
    while(get_report() != 1);

    // Done with reset.
    vrpn_gettimeofday(&timestamp, NULL);	// Set watchdog now
    
    status = vrpn_TRACKER_SYNCING;	// We're trying for a new reading
}
Example #25
0
// This function should be called each time through the main loop
// of the server code. It polls for data from the OWL server and
// sends them if available.
void vrpn_Tracker_PhaseSpace::mainloop()
{
  get_report();
  server_mainloop();
  return;
}
Example #26
0
void print_results( FILE *stream, AS_INF *inf_ptr, BIRTH_DB *data,
       AS_INF_EXT *aie_ptr, BITS mode, NUM house_mode,
       DATA_PACKET *dpk, char *comment )
{
 COUNT i;
 AS_INF *inf;
 AS_INF_EXT *aiep;
 char buf1[60];
 const char *report;
 NUM maxp, file = -1, aspfile = -1, hsfile = -1, midfile = -1;
 int sign, cusp, k, global = -1, table = -1, ruler;
 static char fmt8[] = { "<%s:>\x80" };

 if ( mode & ASTEROID )
	maxp = CHIRON;
 else if ( mode & VERT_EAST )
    maxp = EAST_POINT;
 else
    maxp = PART_FORTU;

 if ( mode & TEXT ) {
    if ( mode & ASPECTS )
       aspfile = open_asp_files( ASPECT_FILE );
    file = open_files( PLANET_FILE );
    if ( mode & HOUSES )
       hsfile = open_files( HOUSE_FILE );
	if ( mode & (BASE_MID|HALF_MID|FULL_MID) )
	   midfile = open_asp_files( MIDPOINT_SIGN );
    }
 if ( mode & NOBIRTHTIM && ( dpk->rdp->rect_system == SOLARCHART ||
		 dpk->rdp->rect_system == FLATCHART ) )
    house_mode = EQUAL;
 table = get_tables( REPORT_NAME, &global );
 if ( table == -1 ) {
    er_close1:
    close_files( file );
    close_files_asp( aspfile );
    close_files( hsfile );
    close_files( midfile );
    return;
    }
 if ( dpk->chart_code & RELOC_CH )
    k = CHH_RELOC;
 else
    k = CHH_TITLE;
 if ( ( report = get_report( table, global, k ) ) == NULL ) {
    goto er_close1;
    }
 else
    output_title( stream, data->name, comment, "", (char *)report );
 if ( output_birth_head_group( stream, mode, data, table, house_mode,
						comment, dpk, global ) ) {
    goto er_close1;
    }
 rppl = get_report( table, global, CH__PLANET );
 rphs = get_report( table, global, CH__PLAN_HOUSE );
 rpah = get_report( table, global, CH__ASPECT_HD );
 rpas = get_report( table, global, CH__ASPECT );
 rpmsc = get_report( table, global, CH__MISC );
 if ( rppl == NULL || rphs == NULL || rpas == NULL || rpah == NULL || rpmsc == NULL ) {
    er_close2:
    close_tables( table, global );
    close_files( file );
    close_files_asp( aspfile );
    close_files( hsfile );
    close_files( midfile );
    return;
    }
 fputs("\n\n", stream );
 if ( ferror( stream ) ) {
    goto er_close2;
    }
 for ( i = 0, aiep = aie_ptr, inf = inf_ptr; i <= maxp; ++i, ++inf, ++aiep ) {
	 if ( !inf->calced )
		 continue;
	 if ( x_kb_check() )
	   break;
     print_entry( stream, inf, i, mode, file, aspfile, hsfile, midfile, aiep,
	       data->name, comment, table, global );
     if ( ferror( stream ) ) {
        goto er_close2;
        }
     }
 if ( mode & TEXT ) {
    close_files( file );
    close_files_asp( aspfile );
    close_files( hsfile );
    close_files( midfile );
    }
 if ( x_kb_check() )
    return;
 if ( mode & HOUSES ) {
    if ( mode & TEXT ) {
       if ( ( hsfile = open_files( SIGN_HOUSE_FILE ) ) == -1 )
	  mode &= ( 0xffff ^ TEXT );
       }
    if ( mode & HOUSES )
       out_do_house_cusps(stream,data->name, comment, "",
					table, global, house_cusps, CH__HOUSE_HEAD );
 if ( ( report = get_report( table, global, CH__HS_SGN_HED ) ) == NULL ) {
    er_close3:
    close_tables( table, global );
    close_files( hsfile );
    return;
    }
 else
    output_title( stream, data->name, comment, "", (char *)report );
 if ( ( report = get_report( table, global, CH__HOUSE_SIGN ) ) == NULL ) {
    goto er_close3;
    }
 if ( ( rphs = strdup( report )) == NULL )
    goto er_close3;
 for ( i = 1; i <= 12; ++i ) {
     if ( x_kb_check() )
	break;
     output_house_sign( stream, i, house_cusps[i], &cusp, &sign,
						     data->name, (char *)rphs );
     ruler = sign_rulers[sign];
	 if ( cusp == -1 ) {
	if ( mode & TEXT )
	   get_transfer_text( sign, i, hsfile, stream );
	   get_transfer_text( ruler, 13, hsfile, stream );
	}
     else {
	if ( mode & TEXT ) {
	   fprintf( stream, (char *)fmt8, sign_str( sign ) );
	   get_transfer_text( sign, i, hsfile, stream );
	   fprintf( stream, (char *)fmt8, sign_str( cusp ) );
	   get_transfer_text( cusp, i, hsfile, stream );
	   get_transfer_text( ruler, 13, hsfile, stream );
	   }
	}
     }
 if ( mode & TEXT )
    close_files( hsfile );
 }
 if ( x_kb_check() ) {
    close_tables( table, global );
    return;
    }
 close_tables( table, global );
 table = get_tables( SUMMARY_NAME, &global );
 if ( table == -1 )
    return;
 if ( mode & SUMMARY )
    print_summary(stream, mode, table, global, data->name, comment );
 close_tables( table, global );
}
Example #27
0
void vrpn_Tracker_GPS::mainloop()
{
  //char temp[256];
	fprintf(stderr,"calling server main\n");
  // Call the generic server mainloop, since we are a server
  server_mainloop();

//-eb adding get report and removing switch statement
	//get_report();

	fprintf(stderr,"status in mainloop is %d\n\n",status);

  switch (status) {
    case vrpn_TRACKER_REPORT_READY:
    {
		printf("tracker report ready\n",status);

        gettimeofday(&timestamp, NULL);	// Set watchdog now
	    
        // Send the message on the connection
    	  if (d_connection) {
		      char	msgbuf[1000];
		      

			//sprintf(temp, "position id = %d, sender id = %d", position_m_id, d_sender_id); 
			//MessageBox(NULL, temp,"GPS Testing",0);

			  // Pack position report
			  int	len = encode_to(msgbuf);
		      if (d_connection->pack_message(len, timestamp,
			      position_m_id, d_sender_id, msgbuf,
			      vrpn_CONNECTION_LOW_LATENCY)) {

				  fprintf(stderr,"Fastrak: cannot write message: tossing\n");
		      }

			  // Pack velocity report
			  
		     //   len = encode_vel_to(msgbuf);
  		     // if (d_connection->pack_message(len, timestamp,
	         //                                velocity_m_id, d_sender_id, msgbuf,
             //                              vrpn_CONNECTION_LOW_LATENCY)){
			//	  fprintf(stderr,"Fastrak: cannot write message: tossing\n");
		    //  }
			  
      	
		  } else {
		      fprintf(stderr,"Tracker Fastrak: No valid connection\n");
	      }

	      // Ready for another report
	      status = vrpn_TRACKER_SYNCING;
    
	}
    break;

    case vrpn_TRACKER_SYNCING:
    case vrpn_TRACKER_AWAITING_STATION:
    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).
		  
		
		  get_report();
		 // 
		 // struct timeval current_time;
		 // gettimeofday(&current_time, NULL);
		 // if ( duration(current_time,timestamp) > MAX_TIME_INTERVAL) {
		//	  sprintf(errmsg,"Timeout... current_time=%ld:%ld, timestamp=%ld:%ld",current_time.tv_sec, current_time.tv_usec, timestamp.tv_sec, timestamp.tv_usec);
		//	  FT_ERROR(errmsg);
		//	  MessageBox(NULL,"Timeout","GPS Testing",0);
		//	  status = vrpn_TRACKER_FAIL;
		//  }
		 // 
		  
    }
    break;

    case vrpn_TRACKER_RESETTING:
		reset();
	break;

    case vrpn_TRACKER_FAIL:
	    FT_WARNING("Tracking failed, trying to reset (try power cycle if more than 4 attempts made)");
	    //vrpn_close_commport(serial_fd);
	    //serial_fd = vrpn_open_commport(portname, baudrate);
	    status = vrpn_TRACKER_RESETTING;
	    break;
  }//switch
	 
}
Example #28
0
// This routine is called each time through the server's main loop. It will
// get a reading and also handle the server_mainloop requirement.
void vrpn_Keyboard::mainloop()
{
    server_mainloop();
    get_report();
}
Example #29
0
void vrpn_SGIBox::mainloop() {
  server_mainloop();
  get_report();
}