Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
   // default configuration filename
   const char* configFilename = "test1.edl";

   for (int i = 1; i < argc; i++) {
      if (std::strcmp(argv[i],"-f") == 0) {
         configFilename = argv[++i];
      }
   }

   //
   station = builder(configFilename);

   // send a reset event and frame sim once
   station->event(Basic::Component::RESET_EVENT);
   station->tcFrame( static_cast<LCreal>(1.0/static_cast<double>(station->getTimeCriticalRate())) );

   // create time critical thread
   station->createTimeCriticalProcess();
   // short pause to allow os to startup thread
   lcSleep(2000);

   // calculate delta time for background thread
   double dt = 1.0/static_cast<double>(bgRate);

   // system time of day
   double simTime = 0.0;                    // Simulator time reference
   double startTime = getComputerTime();    // Time of day (sec) run started

   //int k = 0;
   std::cout << "Starting background main loop ..." << std::endl;
   for(;;) {

      // update background thread
      station->updateData( static_cast<LCreal>(dt) );

      simTime += dt;                       // time of next frame
      double timeNow = getComputerTime();  // time now

      double elapsedTime = timeNow - startTime;
      double nextFrameStart = simTime - elapsedTime;
      int sleepTime = static_cast<int>(nextFrameStart*1000.0);

      // wait for the next frame
      if (sleepTime > 0)
         lcSleep(sleepTime);

/*
    std::cout << ".";
    k += 1;
    if ( k == 40 ) {
      std::cout << "\n";
      k = 0;
    }
*/

   }
   return 0;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
// run the test
//------------------------------------------------------------------------------
void run(Tester* const tester)
{
   if (tester != 0) {
      Basic::Timer::freeze(true);

      // Time between printing the timer data
      double dt = 1.0 / static_cast<double>(TIMERS_PRINT_RATE);

      // Our main test control timer
      Basic::UpTimer* mainTimer = new Basic::UpTimer();
      mainTimer->setAlarmTime(MAIN_TIMER_VALUE);
      mainTimer->start();

      // ---
      // First pass
      // ---
      std::cout << "#### First Test ####" << std::endl;

      Basic::Timer::freeze(false);
      while ( !mainTimer->alarm()) {
         lcSleep( static_cast<unsigned int>(dt * 1000.0 + 0.5) );
         std::printf("time(%4.1f)\n", mainTimer->getCurrentTime());
         tester->printTimers();
      }

      // ---
      // Restart the timers
      // ---
      Basic::Timer::freeze(true);

      std::cout << std::endl;
      std::cout << "#### Restarting Timers (all active) ####" << std::endl;
      tester->restartAllTimers();
      mainTimer->restart();

      // ---
      // Second pass
      // ---
      std::cout << std::endl;
      std::cout << "#### Second Test ####" << std::endl;

      Basic::Timer::freeze(false);
      while ( !mainTimer->alarm()) {
         lcSleep( static_cast<unsigned int>(dt * 1000.0 + 0.5) );
         std::printf("time(%4.1f)\n", mainTimer->getCurrentTime());
         tester->printTimers();
      }
   }
}
//-----------------------------------------------------------------------------
// GLUT idle time; static callback function
//-----------------------------------------------------------------------------
void GlutDisplay::idleCB()
{
   int id = glutGetWindow();
   double time = getComputerTime();

   // N-1 Time
   static double time0 = time;

   // Compute delta time
   double dt = (time - time0);
   time0 = time;

   // Update displays
   unsigned int sleepFor = DEFAULT_IDLE_SLEEP;
   for (int i = 0; i < numGlutDisplays; i++) {
      if (idList[i] >= 0) {
         glutSetWindow(idList[i]);
         displayList[i]->updateData( static_cast<LCreal>(dt) );
         if (displayList[i]->isMainDisplay()) {
            sleepFor = displayList[i]->getIdleSleepTime();
         }
         displayList[i]->drawIt();
      }
   }
   glutSetWindow(id);

   // Sleep to let other's use the CPU
   lcSleep(sleepFor);
}
Ejemplo n.º 4
0
		//-----------------------------------------------------------------------------
		// Eaagles::Swarms::main() -- Main routine
		//-----------------------------------------------------------------------------
		void exec(int argc, char* argv[])
		{
			// parse arguments
			for (int i = 1; i < argc; i++) {
				if (strcmp(argv[i],"-f") == 0) {
					configFile = argv[++i];
				}
			}
			// build a Station
			builder();

			// Reset the Simulation
			station->event(Basic::Component::RESET_EVENT);
			// Set timer for the background tasks
			station->tcFrame( static_cast<LCreal>(1.0/static_cast<double>(station->getTimeCriticalRate())) );
			
			// Create the Time Critical Thread
			station->createTimeCriticalProcess();
			// short pause to allow os to startup thread
			lcSleep(2000);
			
			// Calc delta time for background thread
			double dt = 1.0/static_cast<double>(bgRate);
			
			// System Time of Day 
			double simTime = 0.0;                 // Simulator time reference
			double startTime = getComputerTime(); // Time of day (sec) run started

			//cout << "Simulation running..." << endl;
			
			while (true) { // runs for 10 minutes
				// Update background thread
				station->updateData(static_cast<LCreal>(dt));
			
				simTime += dt;                      // time of next frame
				double timeNow = getComputerTime(); // time now
			
				double elapsedTime = timeNow - startTime;
				double nextFrameStart = simTime - elapsedTime;
				int sleepTime = static_cast<int>(nextFrameStart*1000.0);

				// wait for the next frame
				if (sleepTime > 0)
					lcSleep(sleepTime);
			}
		}