예제 #1
0
/** Sets the app the draw should interact with. */
void D3dDrawManager::setApp(App* _app)
{
   mApp = dynamic_cast<D3dApp*>(_app);

   // We have a new app, so the contexts must be re-initialized
   // so... dirty them all.
   dirtyAllWindows();

   if ( NULL == mApp )
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR:")
         << " [vrj::D3dDrawManager::setApp()] Failed to downcast "
         << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << "application object from vrj::App to vrj::GlApp!" << std::endl
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << "Type of object " << std::hex << _app << std::dec << " is "
         << typeid(_app).name() << std::endl << vprDEBUG_FLUSH;

      throw vrj::DrawMgrException("Object not of type vrj::GlApp",
                                  VPR_LOCATION);
   }
}
예제 #2
0
void ConfigManager::debugDumpPending(int debug_level)
{
   vprASSERT(1 == mPendingLock.test());
   vprDEBUG(vprDBG_ALL,debug_level)
      << clrSetNORM(clrGREEN)
      << "---- Pending list: " << mPendingConfig.size() << " items ----\n"
      << clrRESET << vprDEBUG_FLUSH;
   std::list<ConfigManager::PendingElement>::iterator current, end;
   current = getPendingBegin();
   end = getPendingEnd();

   while ( current != end )
   {
      ConfigElementPtr cur_element = (*current).mElement;

      if ( (*current).mType == PendingElement::ADD )
      {
         vprDEBUG_NEXT(vprDBG_ALL,debug_level) << "   ADD -->" << vprDEBUG_FLUSH;
      }
      else if ( (*current).mType == PendingElement::REMOVE )
      {
         vprDEBUG_NEXT(vprDBG_ALL,debug_level) << "REMOVE -->" << vprDEBUG_FLUSH;
      }

      vprDEBUG_CONT(vprDBG_ALL,debug_level)
         << cur_element->getName() << " type: " << cur_element->getID()
         << std::endl << vprDEBUG_FLUSH;
      current++;
   }
   vprDEBUG_NEXT(vprDBG_ALL,debug_level)
      << "----------------------------------\n" << vprDEBUG_FLUSH;
}
예제 #3
0
void DependencyManager::debugDump()
{
   //vprDEBUG_BEGIN(jcclDBG_RECONFIG, jcclDBG_CONFIG_LVL) << "DependencyManager::debugDump\n" << vprDEBUG_FLUSH;
   vprDEBUG_BEGIN(jcclDBG_RECONFIG, vprDBG_STATE_LVL)
      << "----- Current dependency checkers -----\n" << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_STATE_LVL)
      << "num checkers:" << mDepCheckers.size() << "\n"
      << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_STATE_LVL)
      << "-1: Checker: default   type: default checker  recog: all (this is a fallback)\n"
      << vprDEBUG_FLUSH;

   for(unsigned int cNum=0;cNum<mDepCheckers.size();cNum++)
   {
      DepChecker* checker = mDepCheckers[cNum];
      vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_STATE_LVL)
         << cNum << ": Checker:" << (void*)checker
         << "   type:" << typeid(*checker).name()
         << "   recog:" << checker->getCheckerName().c_str()
         << "\n" << vprDEBUG_FLUSH;
   }

   vprDEBUG_END(jcclDBG_RECONFIG, vprDBG_STATE_LVL)
      << "---------------------\n" << vprDEBUG_FLUSH;
}
예제 #4
0
BaseThread::VPRThreadScope ThreadPosix::posixThreadScopeToVPR(const int scope)
   const
{
   VPRThreadScope vpr_scope;

   switch ( scope )
   {
      case PTHREAD_SCOPE_PROCESS:
         vpr_scope = VPR_LOCAL_THREAD;
         break;
      case PTHREAD_SCOPE_SYSTEM:
         vpr_scope = VPR_GLOBAL_THREAD;
         break;
      default:
         vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
            << clrOutNORM(clrYELLOW, "WARNING:")
            << " Unexpected value " << scope
            << " in vpr::ThreadPosix::posixThreadScopeToVPR()" << std::endl
            << vprDEBUG_FLUSH;
#if VPR_THREAD_SCOPE == PTHREAD_SCOPE_PROCESS
         vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
            << "Defaulting to VPR_LOCAL_THREAD for return value." << std::endl
            << vprDEBUG_FLUSH;
         vpr_scope = VPR_LOCAL_THREAD;
#else
         vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
            << "Defaulting to VPR_GLOBAL_THREAD for return value." << std::endl
            << vprDEBUG_FLUSH;
         vpr_scope = VPR_GLOBAL_THREAD;
#endif
         break;
   };

   return vpr_scope;
}
static void printTrackerInfo(const ISD_TRACKER_INFO_TYPE& info)
{
   vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "InterSense tracker information:" << std::endl << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* InterSense Library version: " << info.LibVersion << std::endl
      << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* Tracker type: " << getTrackerTypeString(info.TrackerType)
      << std::endl << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* Tracker model: " << getTrackerModelString(info.TrackerModel)
      << std::endl << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* Port number: " << info.Port << std::endl << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* Sync frequency: " << info.SyncRate << std::endl << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* Sync phase: " << info.SyncPhase << "%" << std::endl
      << vprDEBUG_FLUSH;

   if ( info.TrackerModel == ISD_IS900 )
   {
      vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "* Ultrasonic timeout: " << info.UltTimeout << std::endl
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "* Ultrasonic speaker volume: " << info.UltVolume << std::endl
         << vprDEBUG_FLUSH;
   }

   vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CONFIG_LVL)
      << "* Firmware revision: " << info.FirmwareRev << std::endl
      << vprDEBUG_FLUSH;
}
예제 #6
0
// Calculates the view frustum needed for the view matrix. This uses a
// method that needs to know the distance in the screen plane from the
// origin (determined by the normal to the plane through the origin) to the
// edges of the screen. This method can be used for any rectangular planar
// screen. By adjusting the wall rotation matrix, this method can be used
// for the general case of a rectangular screen in 3-space.
void SurfaceProjection::calcViewFrustum(const gmtl::Point3f& eyePos,
                                        const float scaleFactor)
{
   const float near_dist = mNearDist;
   const float far_dist = mFarDist;

   // Distance measurements from eye to screen/edges
   // Distance to edges is from the point on the screen plane
   // where a normal line would go through the origin.
   float eye_to_screen, eye_to_right, eye_to_left, eye_to_top, eye_to_bottom;

   // Compute transformed eye position
   // - Converts eye coords into the surface's coord system
   // Xformed position of eyes
   const gmtl::Point3f eye_surface =
      m_surface_M_base * eyePos;

   vprDEBUG(vrjDBG_DISP_MGR, vprDBG_HEX_LVL)
      << "[vrj::SurfaceProjection::calcViewFrustum()] Base eye: "
      << eyePos << std::endl << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_HEX_LVL)
      << "                                            Transformed eye: "
      << eye_surface << std::endl << vprDEBUG_FLUSH;

   // Compute dist from eye to screen/edges
   // Take into account scale since all origin to anythings are in meters
   eye_to_screen = (scaleFactor * mOriginToScreen) + eye_surface[gmtl::Zelt];
   eye_to_right  = (scaleFactor * mOriginToRight) - eye_surface[gmtl::Xelt];
   eye_to_left   = (scaleFactor * mOriginToLeft) + eye_surface[gmtl::Xelt];
   eye_to_top    = (scaleFactor * mOriginToTop) - eye_surface[gmtl::Yelt];
   eye_to_bottom = (scaleFactor * mOriginToBottom) + eye_surface[gmtl::Yelt];

   // Distances in near plane, in near plane from origin.  (Similar to above)
   // Find dists on near plane using similar triangles
   const float near_dist_front = near_dist / eye_to_screen; // constant factor
   const float n_eye_to_left   = eye_to_left * near_dist_front;
   const float n_eye_to_right  = eye_to_right * near_dist_front;
   const float n_eye_to_top    = eye_to_top * near_dist_front;
   const float n_eye_to_bottom = eye_to_bottom * near_dist_front;

   // Set frustum and calculate the matrix.
   mFrustum.set(-n_eye_to_left, n_eye_to_right, -n_eye_to_bottom,
                n_eye_to_top, near_dist, far_dist);

   mFocusPlaneDist = eye_to_screen;    // Needed for drawing

   vprDEBUG(vrjDBG_DISP_MGR, vprDBG_HEX_LVL)
      << "[vrj::SurfaceProjection::calcViewFrustum()]" << std::endl
      << vprDEBUG_FLUSH;
   vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_HEX_LVL)
      << "\tFrustum: " << mFrustum << std::endl << vprDEBUG_FLUSH;
}
예제 #7
0
bool Flock::config(jccl::ConfigElementPtr e)
{
    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
            << "Flock::Flock(jccl::ConfigElementPtr)\n" << vprDEBUG_FLUSH;

    // read in Position's config stuff,
    // --> this will be the port and baud fields
    if(! (Input::config(e) && Position::config(e)))
    {
        return false;
    }

    // Keep this up to date with the version of the element definition we're
    // expecting to handle.
    const unsigned int cur_version(2);
    bool status(true);

    // If the element version is less than cur_version, we will not try to
    // proceed.  Instead, we'll print an error message and return false so
    // that the Config Manager knows this element wasn't consumed.
    if ( e->getVersion() < cur_version )
    {
        vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                << clrOutBOLD(clrRED, "ERROR") << " [Flock] Element named '"
                << e->getName() << "'" << std::endl << vprDEBUG_FLUSH;
        vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                << "is version " << e->getVersion()
                << ", but we require at least version " << cur_version << std::endl
                << vprDEBUG_FLUSH;
        vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                << "Ignoring this element and moving on." << std::endl
                << vprDEBUG_FLUSH;
        status = false;
    }
    else
    {
        // keep FlockStandalone's port and baud members in sync with Input's port
        // and baud members.
        mFlockOfBirds.setPort( e->getProperty<std::string>("port") );
        mFlockOfBirds.setBaudRate( e->getProperty<int>("baud") );

        // Set mFlockOfBirds with the config info.
        mFlockOfBirds.setHemisphere( (BIRD_HEMI) e->getProperty<int>("hemisphere") );
        mFlockOfBirds.setMasterAddress( e->getProperty<unsigned>("master_address") );
        mFlockOfBirds.setAddressingMode( (::Flock::AddressingMode) e->getProperty<int>("addressing_mode") );
        mFlockOfBirds.setFilterType( (BIRD_FILT) e->getProperty<int>("filter") ); //
        mFlockOfBirds.setOutputFormat(::Flock::Output::PositionQuaternion);          // Default to pos quaternion
    }

    return status;
}
예제 #8
0
bool DataGlove::startSampling()
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[dataglove] Begin sampling\n"
         << vprDEBUG_FLUSH;

   bool started(false);

   if (mThread == NULL)
   {
      int maxAttempts=0;
      bool result = false;
      while (result == false && maxAttempts < 5)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
               << "[dataglove] Connecting to "
               << mPortName << " at "
               << mBaudRate << "...\n"
               << vprDEBUG_FLUSH;
         result = mGlove->connectToHardware( mPortName , mBaudRate);
         if (result == false)
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << "[dataglove] ERROR: Can't open or it is already opened."
               << vprDEBUG_FLUSH;
            vpr::System::usleep(14500);
            maxAttempts++;
         }
      }

      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[dataglove] Successfully connected, Now sampling dataglove data."
         << vprDEBUG_FLUSH;
      // Create a new thread to handle the control and set exit flag to false
      mExitFlag = false;
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[dataglove] Spawning control thread\n" << vprDEBUG_FLUSH;

      try
      {
         mThread = new vpr::Thread(boost::bind(&DataGlove::controlLoop, this));
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "[dataglove] DataGlove is active " << std::endl
            << vprDEBUG_FLUSH;
         mActive = true;
         started = true;
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for 5DT DataGlove driver!\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;
      }
   }

   return started;
}
예제 #9
0
bool SerialEncoder::startSampling()
{
   mExitFlag = false;

   bool started(false);

   try
   {
      mSampleThread =
         new vpr::Thread(boost::bind(&SerialEncoder::threadedSampleFunction,
                                     this));
      started = true;
   }
   catch (vpr::Exception& ex)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": Failed to spawn thread for Serial Encoder driver!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;
   }

   return started;
}
예제 #10
0
bool InputWindowXWin::startSampling()
{
   if (mThread != NULL)
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR")
         << ": gadget::InputWindowXWin: startSampling called, when already sampling.\n"
         << vprDEBUG_FLUSH;
      vprASSERT(false);
   }

   bool started(false);
   mExitFlag = false;
   
   // Create a new thread to handle the control
   try
   {
      mThread = new vpr::Thread(boost::bind(&InputWindowXWin::controlLoop,
                                            this));
      started = true;
   }
   catch (vpr::Exception& ex)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": Failed to spawn thread for X11 input window driver!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;
   }

   return started;
}
예제 #11
0
bool Vrpn::startSampling()
{
   bool started(false);

   if ( NULL == mThread )
   {
      // Set flags and spawn sample thread
      mExitFlag = false;

      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) 
         << "[VRPN] Spawning control thread." << std::endl  << vprDEBUG_FLUSH;
      
      try
      {
         mThread = new vpr::Thread(boost::bind(&Vrpn::readLoop, this));
         started = true;

         vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
            << "[VRPN] VRPN driver is active." << std::endl
            << vprDEBUG_FLUSH;
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for VRPN driver!\n" << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;
      }
   }

   return started;
}
예제 #12
0
bool ThreeDMouse::startSampling()
{
   bool started(false);

   if ( mThread == NULL )
   {
      openMouse(mPortName);
      void sampleMouse(void*);

      mExitFlag = false;
      try
      {
         mThread =
            new vpr::Thread(boost::bind(&ThreeDMouse::controlLoop, this));
         started = true;
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for Logitech 3D mouse driver!\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;
      }
   }

   return started;
}
예제 #13
0
BaseThread::VPRThreadState ThreadPosix::posixThreadStateToVPR(const int state)
   const
{
   VPRThreadState vpr_state;

   switch ( state )
   {
      case PTHREAD_CREATE_JOINABLE:
         vpr_state = VPR_JOINABLE_THREAD;
         break;
      case PTHREAD_CREATE_DETACHED:
         vpr_state = VPR_UNJOINABLE_THREAD;
         break;
      default:
         vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
            << clrOutNORM(clrYELLOW, "WARNING:")
            << " Unexpected value " << state
            << " in vpr::ThreadPosix::posixThreadStateToVPR()" << std::endl
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
            << "Defaulting to VPR_JOINABLE_THREAD for return value."
            << std::endl << vprDEBUG_FLUSH;
         vpr_state = VPR_JOINABLE_THREAD;
         break;
   };

   return vpr_state;
}
예제 #14
0
bool CyberGlove::startSampling()
{
   bool started(false);

   if (mThread == NULL)
   {
      resetIndexes();
      
      //Reset Exit flag in case of a shutdown and restart of the driver
      mExitFlag = false;
      // Create a new thread to handle the control
      try
      {
         mThread = new vpr::Thread(boost::bind(&CyberGlove::controlLoop,
                                               this));
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "gadget::CyberGlove is active " << std::endl << vprDEBUG_FLUSH;
         mActive = true;
         started = true;
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for CyberGlove driver!\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;
      }
   }

   return started;
}
예제 #15
0
bool X_IST::startSampling()
{
   bool started(false);

   if ( mThread == NULL )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[X-IST] Begin sampling\n" << vprDEBUG_FLUSH;

      bool result = mGlove->connectToHardware(mGloveNumber);

      if ( result == false )
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << "[X-IST] ERROR: Can't open or it is already opened.\n"
            << vprDEBUG_FLUSH;
         return false;
      }

      const unsigned int num_sensors = mGlove->getNumberSensors();
      mAnalogData = std::vector<AnalogData>(num_sensors, 1.0f);
/*
      for ( unsigned int i = 0; i < num_sensors; ++i )
      {
         mAnalogData[i] = 1.0f;
      }
*/

      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[X-IST] Successfully connected, Now sampling X-IST data.\n"
         << vprDEBUG_FLUSH;

// Create a new thread to handle the control and set exit flag to false
      mExitFlag = false;
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[X-IST] Spawning control thread.\n" << vprDEBUG_FLUSH;

      try
      {
         mThread = new vpr::Thread(boost::bind(&X_IST::controlLoop, this));
         mActive = true;
         started = true;
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
            << "[X-IST] X_IST is active" << std::endl << vprDEBUG_FLUSH;
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for X-IST driver!\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;
         started = false;
      }
   }

   return started;
}
bool MSFTSpeechRecogDigital::startSampling()
{
   mIsInitializing = true;

   // make sure inertia cubes aren't already started
   if ( this->isActive() )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "gadget::MSFTSpeechRecogDigital was already started." << std::endl
         << vprDEBUG_FLUSH;

      mIsInitializing = false;
      return false;
   }

	// Has the thread actually started already
   if(mThread != NULL)
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CONFIG_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << "gadget::MSFTSpeechRecogDigital: startSampling called, when already sampling.\n"
         << vprDEBUG_FLUSH;
      vprASSERT(false);
   }
   else
   {
      // Create a new thread to handle the sampling control
      try
      {
         mThread =
            new vpr::Thread(boost::bind(&MSFTSpeechRecogDigital::controlLoop,
                                        this));

         mIsActive = true;
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "gadget::MSFTSpeechRecogDigital sampling control thread created."
            << std::endl << vprDEBUG_FLUSH;
         mIsInitializing = false;
         return true;  // Fail
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for MS Digital Speech driver!\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;

         mIsInitializing = false;
         return false;  // Fail
      }
   }
   mIsInitializing = false;

   return false;
}
예제 #17
0
// Look for items in the active list that don't have their dependencies filled
// anymore.
//
// POST: Any elements in active with dependencies not filled are added to the
//       the pending list. (A remove and an add are added to the pending).
// RETURNS: The number of lost dependencies found.
int ConfigManager::scanForLostDependencies()
{
   vprASSERT(0 == mActiveLock.test());
   // We can't hold the lock upon entry

   vpr::DebugOutputGuard og(vprDBG_ALL, vprDBG_CONFIG_LVL,
                            "ConfigManager::scanForLostDependencies()\n",
                            "ConfigManager::scanForLostDependencies() done.\n");

   DependencyManager* dep_mgr = DependencyManager::instance();
   std::vector<ConfigElementPtr> elements;
   int num_lost_deps(0);

   // NOTE: can't hold this lock because the isSatisfied routines make
   // use of the activeLock as well
   // NOTE: Make the copy of the elements so that we can iterate without
   // fear of active changing
   mActiveLock.acquire();
   elements = mActiveConfig.vec();   // Get a copy of the elements
   mActiveLock.release();

   // Now test them
   for ( unsigned int i=0;i<elements.size();i++ )
   {
      if ( !dep_mgr->isSatisfied(elements[i]) )     // We are not satisfied
      {
         vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
            << elements[i]->getName()
            << " type: " << elements[i]->getID()
            << " has lost dependencies.\n" << vprDEBUG_FLUSH;

         num_lost_deps++;              // Keep a count of the number lost deps found

         // Add the pending removal
         PendingElement pending;
         pending.mType = PendingElement::REMOVE;
         pending.mElement = elements[i];
         
         vprASSERT(1 == mPendingLock.test());
         addPending(pending);

         // Add the pending re-addition
//         ConfigElementPtr copy_of_element;          // Need a copy so that the remove can delete the element
//         copy_of_element = new ConfigElement(*elements[i]);
         pending.mType = PendingElement::ADD;
         pending.mElement = elements[i];//copy_of_element;
         
         vprASSERT(1 == mPendingLock.test());
         addPending(pending);                   // Add the add item
      }
   }

   return num_lost_deps;
}
예제 #18
0
bool Flock::startSampling()
{
    // make sure birds aren't already started
    if (this->isActive() == true)
    {
        vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
                << "gadget::Flock was already started." << std::endl << vprDEBUG_FLUSH;
        return false;
    }

    bool started(false);

    if (mThread == NULL)
    {
        vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
                << "    Opening flock....\n" << vprDEBUG_FLUSH;
        mFlockOfBirds.open();
        mFlockOfBirds.configure();
        mFlockOfBirds.startStreaming();

        //sanity check.. make sure birds actually started
        if (mFlockOfBirds.getStatus() == FlockStandalone::CLOSED)
        {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                    << "gadget::Flock failed to start.." << std::endl << vprDEBUG_FLUSH;
            return false;
        }

        vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
                << "gadget::Flock ready to go..\n" << vprDEBUG_FLUSH;

        // Create a new thread to handle the control
        mExitFlag = false;
        try
        {
            mThread = new vpr::Thread(boost::bind(&Flock::controlLoop, this));
            started = true;
        }
        catch (vpr::Exception& ex)
        {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                    << clrOutBOLD(clrRED, "ERROR")
                    << ": Failed to spawn thread for Flock of Birds driver!\n"
                    << vprDEBUG_FLUSH;
            vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                    << ex.what() << std::endl << vprDEBUG_FLUSH;
            started = false;
        }
    }

    return started;
}
예제 #19
0
bool SdlJoystick::startSampling()
{
   //return init();
   if (!init())
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " gadget::SdlJoystick::startSampling() SDL init failed.\n"
         << vprDEBUG_FLUSH;
      return false;
   }

   if(mThread != NULL)
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " gadget::SdlJoystick::startSampling() called, when already "
         << "sampling.\n" << vprDEBUG_FLUSH;
      return false;
   }

   // Set flag that will later allow us to stop the control loop.
   mDone = false;

   bool started(true);

   // Create a new thread to handle the control
   try
   {
      mThread = new vpr::Thread(boost::bind(&SdlJoystick::controlLoop,
                                this));
   }
   catch (vpr::Exception& ex)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": Failed to spawn thread for SDL Joystick driver!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;
      started = false;
   }

   return started;
}
예제 #20
0
void ConfigManager::loadRemoteReconfig()
{
   vprASSERT(NULL == mReconfigIf &&
             "RTRC interface object already instantiated.");

   const std::string jccl_base_dir("JCCL_BASE_DIR");
   const std::string vj_base_dir("VJ_BASE_DIR");
   std::string base_dir;

   if ( ! vpr::System::getenv(jccl_base_dir, base_dir) )
   {
      if ( vpr::System::getenv(vj_base_dir, base_dir) )
      {
         vprDEBUG(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
            << "JCCL_BASE_DIR environment variable not set.\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
            << "Using VJ_BASE_DIR instead.\n" << vprDEBUG_FLUSH;
      }
      else
      {
         base_dir = JCCL_ROOT_DIR;

         vprDEBUG(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
            << "Neither JCCL_BASE_DIR nor VJ_BASE_DIR is set."
            << std::endl << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
            << "Using default " << base_dir << " instead."
            << std::endl << vprDEBUG_FLUSH;
      }
   }

   const std::string no_rtrc_plugin("NO_RTRC_PLUGIN");
   std::string junk;

   // If the user has the environment variable NO_RTRC_PLUGIN set (to any
   // value), do not attempt to load the plug-in.
   if ( vpr::System::getenv(no_rtrc_plugin, junk) )
   {
      vprDEBUG(jcclDBG_RECONFIG, vprDBG_STATE_LVL)
         << "Remote reconfig plug-in loading disabled via NO_RTRC_PLUGIN."
         << std::endl << vprDEBUG_FLUSH;
      return;
   }

#if defined(JCCL_PLUGIN_LIBDIR_NAME)
   const std::string lib_dir_name(JCCL_PLUGIN_LIBDIR_NAME);
#else
   const std::string lib_dir_name("lib");
#endif
   
   const std::string jccl_subdir_base("jccl");
   // If versioning is enabled, then the name of the directory containing the
   // Sonix plug-ins must contain version information.
#if defined(JCCL_USE_VERSIONING)
   std::string jccl_ver_str;
   const std::string jccl_version("JCCL_VERSION");

   // If $JCCL_VERSION is set, use the value of that environment variable
   // as the version component of the plug-in subdirectory name. Otherwise,
   // use the compile-time value provided by JCCL_VERSION_DOT.
   if ( ! vpr::System::getenv(jccl_version, jccl_ver_str) )
   {
      jccl_ver_str = JCCL_VERSION_DOT;
   }

   std::string jccl_subdir(jccl_subdir_base + std::string("-") +
                             jccl_ver_str );

   // If versioning is not enabled, then the directory containing the
   // Jackal plug-ins will not incorporate version information.
#else
   std::string jccl_subdir(jccl_subdir_base);
#endif

   std::vector<fs::path> search_path(1);
   search_path[0] =
#if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION == 3
      fs::path(base_dir)
#else
      fs::path(base_dir, fs::native)
#endif
         / lib_dir_name /
         std::string(jccl_subdir) / std::string("plugins");

#if defined(JCCL_DEBUG)
   // For a debug build, search in plugins/debug first.
   search_path.insert(search_path.begin(),
                      search_path[0] / std::string("debug"));
#endif

   // In the long run, we may not want to hard-code the base name of the
   // plug-in we load.  If we ever reach a point where we have multiple ways
   // of implementing remote run-time reconfiguration, we could have options
   // for which plug-in to load.
   const std::string reconfig_dso("corba_rtrc");
   mRemoteRtrcPlugin = vpr::LibraryLoader::findDSO(reconfig_dso, search_path);

   bool load_done(true);

   if ( mRemoteRtrcPlugin.get() != NULL )
   {
      vprASSERT(! mRemoteRtrcPlugin->isLoaded() &&
                "Plug-in should not already be loaded");
      vprDEBUG(jcclDBG_RECONFIG, vprDBG_CONFIG_STATUS_LVL)
         << "Loading library: " << std::setiosflags(std::ios::right)
         << std::setfill(' ') << std::setw(50) << mRemoteRtrcPlugin->getName()
         << std::resetiosflags(std::ios::right) << "     " << vprDEBUG_FLUSH;

      try
      {
         mRemoteRtrcPlugin->load();

         const std::string init_func_name("initPlugin");
         void* entry_point = mRemoteRtrcPlugin->findSymbol(init_func_name);

         if ( NULL != entry_point )
         {
            vprDEBUG_CONT(jcclDBG_RECONFIG, vprDBG_CONFIG_STATUS_LVL)
               << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]\n"
               << vprDEBUG_FLUSH;

            jccl::RemoteReconfig* (*init_func)(jccl::ConfigManager*);

            // Cast the entry point function to the correct signature so that we
            // can call it.  All dynamically plug-ins must have an entry point
            // function that takes no argument and returns a pointer to an
            // implementation of the jccl::RemoteReconfig interface.
            init_func =
               (jccl::RemoteReconfig* (*)(jccl::ConfigManager*)) entry_point;

            // Call the entry point function.
            jccl::RemoteReconfig* plugin = (*init_func)(this);

            if ( NULL != plugin )
            {
               setRemoteReconfigPlugin(plugin);
            }
            else
            {
               load_done = false;
               vprDEBUG_CONT(jcclDBG_RECONFIG, vprDBG_CONFIG_STATUS_LVL)
                  << "[ " << clrSetNORM(clrRED) << "entry point call FAILED"
                  << clrRESET << " ]\n" << vprDEBUG_FLUSH;
            }
         }
         else
         {
            load_done = false;
            vprDEBUG_CONT(jcclDBG_RECONFIG, vprDBG_CONFIG_STATUS_LVL)
               << "[ " << clrSetNORM(clrRED) << "FAILED lookup" << clrRESET
               << " ]\n" << vprDEBUG_FLUSH;
         }
      }
      catch (vpr::Exception& ex)
      {
         load_done = false;
         vprDEBUG_CONT(jcclDBG_RECONFIG, vprDBG_CONFIG_STATUS_LVL)
            << "[ " << clrSetNORM(clrRED) << "FAILED" << clrRESET << " ]\n"
            << ex.what() << std::endl << vprDEBUG_FLUSH;
      }
   }
   else
   {
      load_done = false;
   }

   if ( ! load_done )
   {
      vprDEBUG(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
         << "Failed to load the remote run-time reconfiguration"
         << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
         << "plug-in. Remote run-time reconfiguration is disabled."
         << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_WARNING_LVL)
         << "(This is not a fatal error.)" << std::endl << vprDEBUG_FLUSH;

      // The plug-in is not usable, so we can unload it.
      if ( mRemoteRtrcPlugin.get() != NULL )
      {
         if ( mRemoteRtrcPlugin->isLoaded() )
         {
            mRemoteRtrcPlugin->unload();
         }

         mRemoteRtrcPlugin.reset();
      }
   }
}
// Read exactly the specified number of bytes from the file handle into the
// given buffer.  This is based on the readn() function given on pages 51-2 of
// _Effective TCP/IP Programming_ by Jon D. Snader.
vpr::Uint32 FileHandleImplUNIX::readn_i(void* buffer,
                                        const vpr::Uint32 buffer_size,
                                        const vpr::Interval& timeout)
{
   if ( vpr::Interval::NoTimeout != timeout )
   {
      vprDEBUG(vprDBG_ALL,vprDBG_WARNING_LVL) << "Timeout not supported\n"
                                              << vprDEBUG_FLUSH;
      //TODO: InvalidArgumentException instead, but this will require
      //      adding it as an acceptable exception to throw.
      throw IOException("Timeout not supported by readn.", VPR_LOCATION);
   }

   vpr::Uint32 bytes_read(0);
   size_t bytes_left = buffer_size;

   while ( bytes_left > 0 )
   {
      vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL)
         << "[vpr::FileHandleImplUNIX::readn_i()] Reading " << bytes_left
         << " bytes from file handle " << mFdesc << std::endl
         << vprDEBUG_FLUSH;

      const ssize_t bytes = ::read(mFdesc, buffer, bytes_left);

      vprDEBUG_NEXT(vprDBG_ALL, vprDBG_HVERB_LVL)
         << "Read " << bytes << " bytes from file handle " << mFdesc
         << std::endl << vprDEBUG_FLUSH;

      // Read error.
      if ( bytes < 0 )
      {
         // Restart the read process if we were interrupted by the OS.
         if ( EINTR == errno )
         {
            continue;
         }
         // Restart the read process if socket is non-blocking and no
         // data was immediately available.
         else if ( EAGAIN == errno )
         {
            continue;
         }
         // Otherwise, we have an error situation, so return failure status.
         else
         {
            std::ostringstream msg_stream;
            msg_stream << "Error reading from " << mName << ": "
                       << strerror(errno);
            throw IOException(msg_stream.str(), VPR_LOCATION);
         }
      }
      // We have read EOF, so there is nothing more to read.  At this point,
      // bytes_read contains an accurate count of the bytes read so far
      // (posisbly less than buffer_size).
      else if ( bytes == 0 )
      {
         vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL)
            << "[vpr::FileHandleImplUNIX::readn_i()] Read EOF with "
            << bytes_left << " bytes left to read from file handle "
            << mFdesc << " and " << bytes_read << " bytes read in total."
            << std::endl << vprDEBUG_FLUSH;

         std::ostringstream ss;
         ss << "Read EOF with " << bytes_left
            << " bytes left to read from file handle " << mFdesc << " and "
            << bytes_read << " bytes read in total.";
         throw EOFException(ss.str(), VPR_LOCATION);
      }
      else
      {
         buffer = (void*) ((char*) buffer + bytes);
         bytes_left -= bytes;
         bytes_read += bytes;
      }
   }

   return bytes_read;
}
예제 #22
0
bool SurfaceViewport::config(jccl::ConfigElementPtr element)
{
   vprASSERT(element.get() != NULL);
   vprASSERT(element->getID() == "surface_viewport");

   // Call base class config
   if ( ! Viewport::config(element) )
   {
      return false;
   }

   bool result(true);

   mType = SURFACE;

   // Read in the corners
   mLLCorner.set(element->getProperty<float>("lower_left_corner", 0),
                 element->getProperty<float>("lower_left_corner", 1),
                 element->getProperty<float>("lower_left_corner", 2));
   mLRCorner.set(element->getProperty<float>("lower_right_corner", 0),
                 element->getProperty<float>("lower_right_corner", 1),
                 element->getProperty<float>("lower_right_corner", 2));
   mURCorner.set(element->getProperty<float>("upper_right_corner", 0),
                 element->getProperty<float>("upper_right_corner", 1),
                 element->getProperty<float>("upper_right_corner", 2));
   mULCorner.set(element->getProperty<float>("upper_left_corner", 0),
                 element->getProperty<float>("upper_left_corner", 1),
                 element->getProperty<float>("upper_left_corner", 2));
   
   mCornerUpdateMode = static_cast<CornerUpdateMode>(element->getProperty<int>("auto_corner_update", 0));

   // Calculate the rotation and the pts
//   calculateSurfaceRotation();
//   calculateCornersInBaseFrame();

   // Get info about being tracked
   mTracked = element->getProperty<bool>("tracked");
   if(mTracked)
   {
      mTrackerProxyName = element->getProperty<std::string>("tracker_proxy");
   }

   // Create Projection objects
   // NOTE: The -'s are because we are measuring distance to
   //  the left(bottom) which is opposite the normal axis direction
   //vjMatrix rot_inv;
   //rot_inv.invert(mSurfaceRotation);
   SurfaceProjectionPtr left_proj;
   SurfaceProjectionPtr right_proj;

   if(!mTracked)
   {
      left_proj = SurfaceProjection::create(mLLCorner, mLRCorner, mURCorner,
                                            mULCorner);
      right_proj = SurfaceProjection::create(mLLCorner, mLRCorner, mURCorner,
                                             mULCorner);
   }
   else
   {
      left_proj = TrackedSurfaceProjection::create(mLLCorner, mLRCorner,
                                                   mURCorner, mULCorner,
                                                   mTrackerProxyName);
      right_proj = TrackedSurfaceProjection::create(mLLCorner, mLRCorner,
                                                    mURCorner, mULCorner,
                                                    mTrackerProxyName);
   }

   try
   {
      left_proj->validateCorners();
      right_proj->validateCorners();

      // NOTE: Even if the corner validation above failed, we still proceed with
      // setting up mLeftProj and mRightProj. This is because other code is not
      // written to handle the case of a viewport having no projections. This
      // could definitely be improved.
      mLeftProj  = left_proj;
      mRightProj = right_proj;

      // Configure the projections
      mLeftProj->config(element);
      mLeftProj->setEye(Projection::LEFT);
      mLeftProj->setViewport(shared_from_this());

      mRightProj->config(element);
      mRightProj->setEye(Projection::RIGHT);
      mRightProj->setViewport(shared_from_this());
   }
   catch (InvalidSurfaceException& ex)
   {
      vprDEBUG(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": The surface defined by the viewport named\n" << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
         << "       '" << element->getName() << "' is invalid!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vrjDBG_DISP_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;

      result = false;
   }

   return result;
}
예제 #23
0
void ClusterDepChecker::debugOutDependencies(jccl::ConfigElementPtr element,
                                             const int dbg_lvl)
{
   vprDEBUG_NEXT_BEGIN( vprDBG_ALL, dbg_lvl )
      << "---- Dependencies for " << element->getName()
      << " (type: " << element->getID() << ") ----\n" << vprDEBUG_FLUSH;

   if (element->getID() == ClusterNetwork::getClusterNodeElementType())
   {
      // Machine Specific element should have no dependencies since we are
      // simply inserting the child elements into the pending list.
      vprDEBUG_NEXT( vprDBG_ALL, dbg_lvl ) << "0: "
          << "Host node's ConfigElement"
          << " ==> " << vprDEBUG_FLUSH;
      
      vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "none.\n"
         << vprDEBUG_FLUSH;
   }
   /*
   else if (cluster::ClusterManager::instance()->recognizeRemoteDeviceConfig( element ))
   {
      std::string device_host = element->getProperty<std::string>( "device_host");
      gadget::NodePtr node = cluster::ClusterManager::instance()->getNetwork()->getNodeByName( device_host );

      vprDEBUG_NEXT( vprDBG_ALL, dbg_lvl ) << "1: "
          << "Device node's ConfigElement"
          << " ==> " << vprDEBUG_FLUSH;

      jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance();

      if (!cfg_mgr->isElementInActiveList( device_host ) || NULL == node)
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "not in active list.\n"
            << vprDEBUG_FLUSH;
      }
      else
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "in active list.\n"
            << vprDEBUG_FLUSH;
      }

      vprDEBUG_NEXT( vprDBG_ALL, dbg_lvl ) << "2: "
          << "Device host connection status"
          << " ==> " << vprDEBUG_FLUSH;
      
      if (gadget::Node::DISCONNECTED == node->getStatus())
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "disconnected.\n"
            << vprDEBUG_FLUSH;
      }
      else if (gadget::Node::PENDING == node->getStatus())
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "pending.\n"
            << vprDEBUG_FLUSH;
      }
      else if (gadget::Node::NEWCONNECTION == node->getStatus())
      {
         vprDEBUG_CONT( vprDBG_ALL, dbg_lvl ) << "new connection.\n"
            << vprDEBUG_FLUSH;
      }
   }
   */
   vprDEBUG_CONT_END( vprDBG_ALL, dbg_lvl ) << std::endl << vprDEBUG_FLUSH;
}
예제 #24
0
DTrackStandalone::DTrackStandalone(
	int udpport, const char* remote_host, int remote_port,
	int udpbufsize, int udptimeout_us
)
{
	vpr::InetAddr addr;

	d_udpsock = NULL;
	d_udpbuf = NULL;
	set_noerror();

	// creat UDP socket:

	if(udpport <= 0 || udpport > 65535){
		return;
	}

	addr = vpr::InetAddr::AnyAddr;
	addr.setPort((unsigned short )udpport);

	d_udpsock = new vpr::SocketDatagram(addr, vpr::InetAddr::AnyAddr);

	try
	{
		d_udpsock->open();
		d_udpsock->bind();
		d_udptimeout.set(udptimeout_us, vpr::Interval::Usec);

		// create UDP buffer:

		d_udpbufsize = udpbufsize;

		d_udpbuf = (char *)malloc(udpbufsize);

		if(!d_udpbuf){
			d_udpsock->close();
			delete d_udpsock;
			d_udpsock = NULL;
			return;
		}

		// DTrack remote control parameters:
	
		d_use_remote = false;
	
		if(remote_host != NULL && remote_port > 0 && remote_port <= 65535){
			try
			{
				d_remote.setAddress(remote_host, remote_port);
				d_use_remote = true;
			}
			catch (vpr::UnknownHostException& ex)
			{
				vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
					<< "[DTrackStandalone] invalid remote address "
					<< remote_host << ":" << remote_port
					<< std::endl << vprDEBUG_FLUSH;
				vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CRITICAL_LVL)
					<< ex.what() << std::endl;
				free(d_udpbuf);
				d_udpsock->close();
				delete d_udpsock;
				d_udpsock = NULL;
				return;
			}
		}

		d_remote_cameras = false;
		d_remote_tracking = true;
		d_remote_sending = true;

		// reset actual DTrack data:

		act_framecounter = 0;
		act_timestamp = -1;

		act_num_body = act_num_flystick = act_num_meatool = act_num_hand = 0;
		act_num_marker = 0;
	}
	catch (vpr::Exception& ex)
	{
		vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
			<< "[DTrackStandalone] cannot open UDP socket, port "
			<< udpport << std::endl << vprDEBUG_FLUSH;
		vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CRITICAL_LVL)
			<< ex.what() << std::endl;
		delete d_udpsock;
		d_udpsock = NULL;
	}
}
예제 #25
0
bool IntersenseAPI::startSampling()
{
   // Ensure that we have not already started sampling.
   if (this->isActive() == true)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
         << "IntersenseAPI driver was already started." << std::endl
         << vprDEBUG_FLUSH;
      return false;
   }

   // Ensure that the thread has not already started.
   if(mThread != NULL)
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " gadget::IntersenseAPI::startSampling() called, when already "
         << "sampling.\n" << vprDEBUG_FLUSH;
      return false;
   }

   // Open the connection to the tracker
   mTracker.open(mISenseDriverLocation);
   if (this->isActive() == false)
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " [gadget::IntersenseAPI::startSampling()] mTracker.open() "
         << "failed to connect to tracker.\n" << vprDEBUG_FLUSH;
      return false;
   }

   // Configure the stations used by the configuration
   for( unsigned int i = 0; i < mStations.size(); ++i )
   {
      int station_index = mStations[i].stationIndex;
      // Reset any boresight being used by trackd or ICIDO
      // This makes a call to the tracker and is not simply setting
      // state on a var to configure the tracker with as done below.
      mTracker.resetStationBoresight(station_index);
      // Load the config state from the physical tracker
      mTracker.loadConfigState(station_index);
      mTracker.setState(station_index, mStations[i].enabled);
      mTracker.setInputs(station_index,
                         mStations[i].useDigital || mStations[i].useAnalog);
      mTracker.setTimeStamped( station_index, false );
      mTracker.setDefaultCoordFrame( station_index );

      // Save the config state to the physical tracker.
      if ( ! mTracker.saveConfigState(station_index) )
      {
         vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
            << clrOutNORM(clrRED,"ERROR:")
            << " [gadget::IntersenseAPI::startSampling()] mTracker.saveConfigState() "
            << "failed to save config state to station " << i << ".\n"
            << vprDEBUG_FLUSH;

         mTracker.close();
         return false;
      }

      //Try to get output in quat form otherwise fallback on euler angles
      mTracker.setAngleFormat(station_index, ISD_QUATERNION);
      if ( ! mTracker.saveConfigState(station_index) )
      {
         // Failed to set quaternion format which means it is set for euler
         mTracker.setAngleFormat(station_index, ISD_EULER);
      }
   }

   // Set flag that will later allow us to stop the control loop.
   mDone = false;

   bool started(true);

   // Create a new thread to handle the control
   try
   {
      mThread = new vpr::Thread(boost::bind(&IntersenseAPI::controlLoop,
                                this));
   }
   catch (vpr::Exception& ex)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": Failed to spawn thread for InterSense API driver!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;
      started = false;
   }

   return started;
}
예제 #26
0
// Configure the MotionStar with the given config element.
bool MotionStar::config(jccl::ConfigElementPtr e)
{
   bool retval(false);

   if ( Input::config(e) &&  Position::config(e) )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "MotionStar::config(jccl::ConfigElementPtr)\n"
         << vprDEBUG_FLUSH;

      const unsigned int cur_version(2);

      if ( e->getVersion() < cur_version )
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << " [gadget::MotionStar::config()] Element named '"
            << e->getName() << "'" << std::endl << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << "is version " << e->getVersion()
            << ", but we require at least version " << cur_version
            << std::endl << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << "Ignoring this element and moving on." << std::endl
            << vprDEBUG_FLUSH;
         retval = false;
      }
      else
      {
         // Configure mMotionStar with the config info.
         const unsigned num_filters = e->getNum("position_filters");

         // Sanity check.  There has to be at least one position filter
         // configured.
         if ( num_filters == 0 )
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << clrOutBOLD(clrRED, "ERROR")
               << ": [MotionStar::config(jccl::ConfigElementPtr)] No position "
               << "filters configured in " << e->getName() << std::endl
               << vprDEBUG_FLUSH;
            retval = false;
         }
         else
         {
            BIRDNET::units expected_units;

            // Find the first position_transform_filter instance and get its
            // device_units property value.  This will tell us what units we're
            // expecting from the hardware.
            const std::string filter_type("position_transform_filter");
            for ( unsigned i = 0; i < num_filters; ++i )
            {
               jccl::ConfigElementPtr pos_elt =
                  e->getProperty<jccl::ConfigElementPtr>("position_filters", i);

               if ( pos_elt->getID() == filter_type )
               {
                  const float unit_conv =
                     pos_elt->getProperty<float>("device_units");

                  vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_VERB_LVL)
                     << "[gadget::MotionStar::config()] Read " << unit_conv
                     << " as the conversion from device units to meters.\n"
                     << vprDEBUG_FLUSH;

                  // Inches.  This is the most likely configuration as of this
                  // writing.
                  if ( unit_conv == 0.0254f )
                  {
                     expected_units = BIRDNET::INCHES;
                  }
                  // Feet.
                  else if ( unit_conv == 0.3048f )
                  {
                     expected_units = BIRDNET::FEET;
                  }
                  // Meters.
                  else if ( unit_conv == 1.0f )
                  {
                     expected_units = BIRDNET::METERS;
                  }
                  // Unexpected value.
                  else
                  {
                     vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << "[MotionStar::config(jccl::ConfigElementPtr)] "
                        << clrOutBOLD(clrRED, "ERROR")
                        << ": Unsupported device unit value " << unit_conv
                        << " in " << pos_elt->getFullName() << std::endl
                        << vprDEBUG_FLUSH;
                     vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                        << "Check your configuration for errors.\n"
                        << vprDEBUG_FLUSH;

                     // Break out of this method early because the
                     // configuration element we were given is bad.
                     return false;
                  }

                  // We're done checking for unit conversion values.
                  break;
               }
            }

            mMotionStar.setExpectedUnits(expected_units);

            setAddressName(e->getProperty<std::string>("address").c_str());
            setServerPort((unsigned short) e->getProperty<int>("server_port"));
            setMasterStatus(e->getProperty<bool>("is_master"));
            setHemisphere((unsigned char) e->getProperty<int>("hemisphere"));
            setBirdFormat((unsigned int) e->getProperty<int>("data_format"));
            setRunMode((unsigned int) e->getProperty<int>("mode"));
            setReportRate((unsigned char) e->getProperty<int>("report_rate"));
            setMeasurementRate(e->getProperty<float>("measurement_rate"));
            retval = true;
         }
      }
   }

   return retval;
}
예제 #27
0
bool InputWindowXWin::config(jccl::ConfigElementPtr e)
{
   unsigned required_definition_ver(1);

   if (e->getVersion() < required_definition_ver)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": [gadget::InputWindowXWin::config()] Element named '"
         << e->getName() << "'" << std::endl << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << "is version " << e->getVersion()
         << ", but we require at least version " << required_definition_ver
         << ". Ignoring.\n" << vprDEBUG_FLUSH;
      return false;
   }

   if ( ! ( InputArea::config(e) && Input::config(e) ) )
   {
      return false;
   }

   const char neg_one_STRING[] = "-1";

   // Get size and position
   mWidth  = e->getProperty<int>("size", 0);
   mHeight = e->getProperty<int>("size", 1);

   // Sanity checks.
   if (mWidth == 0)
   {
      mWidth = 400;
   }
   if (mHeight == 0)
   {
      mHeight = 400;
   }

   mX = e->getProperty<int>("origin", 0);
   mY = e->getProperty<int>("origin", 1);

   // Get the X display string
   int x_disp_num = e->getProperty<int>("display_number");
   jccl::ConfigElementPtr disp_sys_elt =
      gadget::InputManager::instance()->getDisplaySystemElement();

   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
      << "gadget::InputWindowXWin: display_number: " << x_disp_num
      << std::endl << vprDEBUG_FLUSH;

   if (NULL == disp_sys_elt.get())
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CONFIG_LVL)
         << clrOutNORM(clrRED, "ERROR")
         << ": [gadget::InputWindowXWin::config()] display_system element "
         << "is NULL.\n" << vprDEBUG_FLUSH;
      return false;
   }

   if ( x_disp_num >= 0 && disp_sys_elt.get() != NULL )
   {
      if ( disp_sys_elt->getVersion() < 3 )
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << clrOutBOLD(clrYELLOW, "WARNING") << ": Display system element '"
            << disp_sys_elt->getName() << "'" << std::endl;
         vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << "         is out of date.\n";
         vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << "         Expected version 3 but found version "
            << disp_sys_elt->getVersion() << ".  Pipe\n";
         vprDEBUG_NEXTnl(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
            << "         configurations will not work.\n" << vprDEBUG_FLUSH;
      }

      mXDisplayString = disp_sys_elt->getProperty<std::string>("pipes",
                                                               x_disp_num);
      
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[gadget::InputWindowXWin::config()] Display: " << mXDisplayString
         << std::endl << vprDEBUG_FLUSH;
   }
   else
   {
      mXDisplayString = std::string("-1");
   }

   if ((mXDisplayString.empty()) || (strcmp(mXDisplayString.c_str(), neg_one_STRING) == 0))    // Use display env
   {
      const std::string DISPLAY_str("DISPLAY");
      vpr::System::getenv(DISPLAY_str, mXDisplayString);
   }
   return true;
}
예제 #28
0
// Begin sampling.
bool MotionStar::startSampling()
{
   bool retval(false);     // Initialize to error status

   // Make sure the device isn't already started.
   if ( isActive() )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_WARNING_LVL)
         << "gadget::MotionStar was already started.\n" << vprDEBUG_FLUSH;
      retval = true;
   }
   else
   {
      if ( NULL == mMyThread )
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "    Getting MotionStar ready ...\n" << vprDEBUG_FLUSH;

         try
         {
            mMotionStar.start();

            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
               << "gadget::MotionStar ready to go.\n" << vprDEBUG_FLUSH;

            // Set exit flag to not exit and start sample thread
            mExitFlag = false;

            try
            {
               mMyThread =
                  new vpr::Thread(boost::bind(&MotionStar::controlLoop, this));
               retval = true;   // success
            }
            catch (vpr::Exception& ex)
            {
               vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                  << clrOutBOLD(clrRED, "ERROR")
                  << ": Failed to spawn thread for MotionStar driver!\n"
                  << vprDEBUG_FLUSH;
               vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
                  << ex.what() << std::endl << vprDEBUG_FLUSH;
               retval = false;
            }
         }
         // Connection to server failed.  MotionStarStandalone prints out
         // the system error message about why.
         catch(mstar::ConnectException& ex)
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << "gadget::MotionStar failed to connect to server: "
               << ex.what() << std::endl << vprDEBUG_FLUSH;
         }
         // Some network error occurred when trying to start the device.
         catch(mstar::NetworkException&)
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << "gadget::MotionStar could not create a socket\n"
               << vprDEBUG_FLUSH;
         }
         // Unkonwn exception from MotionStarStandalone::start().
         catch(mstar::MotionStarException& ex)
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << "Abnormal return from MotionStarStandalone::start(): "
               << ex.what() << std::endl << vprDEBUG_FLUSH;
         }
      }
      // The thread has been started, so we are already sampling.
      else
      {
         retval = true;
      }
   }

   return retval;
}
예제 #29
0
bool DirectXJoystick::startSampling()
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
      << "Initializing Direct Input joystick device" << std::endl
      << vprDEBUG_FLUSH;

   try
   {
      mInputDrv.init();
      mActive = true;
   }
   catch(DirectXJoystickException& ex)
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR:")
         << " [gadget::DirectXJoystick::startSampling()] "
         << "Failed to initialize Direct Input joystick:" << std::endl
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;
      return false;
   }

   // Output joystick description
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
      << std::endl
      << "  joystick label: " << mJsLabel << std::endl
      << "   joystick name: " << mInputDrv.getProductName() << std::endl
      << "            axes: " << mInputDrv.getNumAxes() << std::endl
      << "         buttons: " << mInputDrv.getNumButtons() << std::endl
      << "    firmware rev: " << mInputDrv.getFirmwareRev() << std::endl
      << "    hardware rev: " << mInputDrv.getHardwareRev() << std::endl
      << "    axis buttons: ";

   for ( unsigned int i = 0; i < mAxisButtonIndices.size(); ++i )
   { 
      vprDEBUG_CONTnl(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << mAxisButtonIndices[i] << " ";
   }
   vprDEBUG_CONTnl(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
      << std::endl << vprDEBUG_FLUSH;

   // Allocate initial device data.  By default this will clear them out.
   const DWORD num_axes(mInputDrv.getNumAxes()),
               num_buttons(mInputDrv.getNumButtons());
   mCurAxes.resize(num_axes);
   mCurAxesRanges.resize(num_axes,
                         axis_range_t((float) DirectXJoystickStandalone::getAxisMin(),
                                      (float) DirectXJoystickStandalone::getAxisMax()));
   // We use double the number of axis button indices because each axis has
   // to map to two buttons (high and low).
   mCurButtons.resize(num_buttons + mAxisButtonIndices.size() * 2);

   // Set up axis-as-button stuff.
   // Default to -1, meaning no axis button.
   mAxisToButtonIndexLookup.clear();
   mAxisToButtonIndexLookup.resize(num_axes, -1);

   for ( unsigned int i = 0; i < mAxisButtonIndices.size(); ++i )
   {
      // Define the index of the virtual button from the axis. Each axis
      // provides two virtual buttons: one for its low value and one for its
      // high value. These virtual buttons are paired up in the digital
      // sample buffers as [low0, high0, low1, high1, ..., lowN, highN] for
      // axes 0 through N.
      const unsigned int virtual_btn_index = num_buttons + i * 2;
      vprASSERT(virtual_btn_index < mCurButtons.size() &&
                "Virtual button index out of range");
      // Index of the axis we are mapping.
      unsigned int axis_index = mAxisButtonIndices[i];
      // Set up the mapping.
      mAxisToButtonIndexLookup[axis_index] = int(virtual_btn_index);
   }

   return true;
}
예제 #30
0
/**
 * This routine counts the number of pending elements each time it is called.
 * if it goes pending_repeat_limit calls without changing size, then it returns
 * false until mLastPendingSize changes.
 *
 * CONCURRENCY: concurrent
 */
bool ConfigManager::shouldCheckPending()
{
   // - Lock PendingCountMutex
   // - If the size of the pending list has changed
   //   - Reset the pending check count to allow reconfig
   //   - Record the new size to check against next time
   //   - Set return value to true
   // - Else if the pending check count is less the limit
   //   - Increment the pendling check count (decrease the
   //     number of remaining iterations)
   //   - Set the return value to true
   // - Else if the pending check count equals the limit
   //   - Increment the pendling check count (needed to 
   //     push count over limit)
   //   - Print the list of stale configuration elements
   //   - Set the return value to false
   // - Else
   //   - Set the return value to false
   // - Unlock PendingCountMutex
   
   std::list<PendingElement>::size_type cur_pending_size(0);
   bool ret_val = false;

   mPendingCountMutex.acquire();

   cur_pending_size = mPendingConfig.size();
   if ( cur_pending_size != mLastPendingSize )
   {
      ret_val = true;                           // Flag it for a check
      mPendingCheckCount = 0;                   // Reset the counter
      mLastPendingSize = cur_pending_size;      // Keep track of size
   }
   else if ( mPendingCheckCount < pending_repeat_limit )
   {
      mPendingCheckCount++;
      ret_val = true;
   }
   else if( mPendingCheckCount == pending_repeat_limit )
   {
      mPendingCheckCount++;
      
      vprDEBUG(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
         << "Pending list is now "
         << clrOutNORM(clrGREEN, "STALE") << ":\n" << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
         << cur_pending_size << " items are still in the pending list\n"
         << vprDEBUG_FLUSH;

      if ( cur_pending_size > 0 )
      {
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
            << "NOTE: These items have been specified in the\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
            << "      configuration but have not been loaded.\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
            << "      This may be a problem in the configuration OR\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
            << "      it may be waiting for more configuration\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(jcclDBG_RECONFIG, vprDBG_CRITICAL_LVL)
            << "      information.\n" << vprDEBUG_FLUSH;
      }

      lockPending();
      debugDumpPending(vprDBG_CRITICAL_LVL); // Output the stale pending list
      unlockPending();

      ret_val = false;
   }
   else
   {
      ret_val = false;
   }

   mPendingCountMutex.release();

   return ret_val;
}