Esempio n. 1
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;
    }
}
Esempio n. 2
0
void PathMachine::event(const SigParseEvent &sigParseEvent)
{
    if (lastEvent != sigParseEvent.requireValid())
        lastEvent = sigParseEvent;

    lastEvent.requireValid();

    switch (state) {
    case PathState::APPROVED:
        approved(sigParseEvent);
        break;
    case PathState::EXPERIMENTING:
        experimenting(sigParseEvent);
        break;
    case PathState::SYNCING:
        syncing(sigParseEvent);
        break;
    }
}