Exemple #1
0
    void testWriteAll()
    {
        uint16_t addr;

        getReady();
        // Enable write
        writeOpAddr(EWEN_OPCODE, EWEN_OPCODE_BITS, 0, EWEN_ADDR_BITS);
        standby();
        // Fill all memory
        writeOpAddr(WRAL_OPCODE, WRAL_OPCODE_BITS, 0, WRAL_ADDR_BITS);
        writeData(0xABBA);
        standby();

        if (waitForCompletion()) {
            stop();
            getReady();
            // Write successful -- verify all memory
            for ( addr=0; addr < EEPROM93C46::SIZE; addr++ ) {
                CPPUNIT_ASSERT_EQUAL((uint16_t)0xABBA, readAt(addr));
            }
        }
        else {
            CPPUNIT_FAIL("EEPROM write was not completed");
        }
        stop();
    }
Exemple #2
0
void
AGBusLine::setBusNames() {
    busNbr = 0;
    std::list<AGBus>::iterator it1 = buses.begin(); //iterator on buses in the first direction
    std::list<AGBus>::iterator it2 = revBuses.begin(); //iterator on buses in the second direction

    std::list<std::pair<int, std::string> > drivingBuses1, drivingBuses2; //buses on the road or in the parking of the corresponding end: int: the time of availability

    while (it1 != buses.end() && it2 != revBuses.end()) {
        if (it1->getDeparture() > it2->getDeparture()) {
            if (drivingBuses2.size() == 0) {
                drivingBuses2.push_front(make_pair(it2->getDeparture(), createName()));
            } else if (drivingBuses2.front().first > it2->getDeparture()) {
                drivingBuses2.push_front(make_pair(it2->getDeparture(), createName()));
            }
            //here the first in drivingBuses2 is available for the trip
            it2->setName(drivingBuses2.front().second);
            drivingBuses2.pop_front();
            //the same bus will be available for the main direction after some time (see function getReady):
            drivingBuses1.push_back(make_pair(getReady(it2->getDeparture()), it2->getName()));
            it2++;
        } else {
            if (drivingBuses1.size() == 0) {
                drivingBuses1.push_front(make_pair(it1->getDeparture(), createName()));
            } else if (drivingBuses1.front().first > it1->getDeparture()) {
                drivingBuses1.push_front(make_pair(it1->getDeparture(), createName()));
            }
            //here the first in drivingBuses1 is available for the trip
            it1->setName(drivingBuses1.front().second);
            drivingBuses1.pop_front();
            //the same bus will be available for the return way after some time (see function getReady):
            drivingBuses2.push_back(make_pair(getReady(it1->getDeparture()), it1->getName()));
            it1++;
        }
    }
    if (it1 != buses.end()) {
        if (drivingBuses1.size() == 0) {
            it1->setName(createName());
        } else if (drivingBuses1.front().first > it1->getDeparture()) {
            it1->setName(createName());
        } else {
            it1->setName(drivingBuses1.front().second);
            drivingBuses1.pop_front();
        }
        it1++;
    }
    if (it2 != revBuses.end()) {
        if (drivingBuses2.size() == 0) {
            it2->setName(createName());
        } else if (drivingBuses2.front().first > it2->getDeparture()) {
            it2->setName(createName());
        } else {
            it2->setName(drivingBuses2.front().second);
            drivingBuses2.pop_front();
        }
        it2++;
    }
}
Exemple #3
0
    void testErase()
    {
        int i;
        uint16_t addr = 0x1F;

        getReady();
        // Enable write
        shiftOutBits(EWEN_OPCODE, EWEN_OPCODE_BITS);
        shiftOutBits(0, EWEN_ADDR_BITS);
        standby();

        if (writeTo(addr, addr)) {
            stop();
            getReady();
            // Write successful -- continue
            CPPUNIT_ASSERT_EQUAL(addr, readAt(addr));
            stop();
            getReady();

            shiftOutBits(ERASE_OPCODE, ERASE_OPCODE_BITS);
            shiftOutBits(addr, ERASE_ADDR_BITS);

            standby();

            for (i = 0; i < 200; i++) {
                if (eeprom->read() & DO)
                    break;
                //usec_delay(50);
            }

            if (i == 200) {
                CPPUNIT_FAIL("EEPROM erase was not completed");
                stop();
                return;
            }

            standby();

            shiftOutBits(EWDS_OPCODE, EWDS_OPCODE_BITS);
            shiftOutBits(0, EWDS_ADDR_BITS);

            stop();
            getReady();
            CPPUNIT_ASSERT_EQUAL((uint16_t)0xFFFF, readAt(addr));
        }
        else {
            CPPUNIT_FAIL("EEPROM write was not completed");
        }
        stop();
    }
Exemple #4
0
void mypthread_exit(void *retval) 
{

	allThreads[threadIndex].status = EXITED;
	allThreads[threadIndex].retval = retval;
	free(allThreads[threadIndex].context.uc_stack.ss_sp);

	if(allThreads[threadIndex].retadd)
	{
		*(allThreads[threadIndex].retadd) = retval;
	}

	if (allThreads[threadIndex].beingJoinedOnBy > -1)
	{
		int joiningThreadIndex = allThreads[threadIndex].beingJoinedOnBy;
		allThreads[joiningThreadIndex].status = READY;
	}

	int next = getReady();
	if (next < 0)
	{
		int waiting = getWaiting();
		if (waiting < 0)
		{
			printf("No waiting or exiting threads found. Exiting.\n");
			exit(1);
		}
		next = allThreads[waiting].index;
	}
	threadIndex = next;

	allThreads[threadIndex].status = RUNNING;
	setcontext(&(allThreads[threadIndex].context));
	
}
Exemple #5
0
    void testEraseAll()
    {
        //unused: int i;
        uint16_t addr = 0x1F;

        getReady();
        // Enable write
        writeOpAddr(EWEN_OPCODE, EWEN_OPCODE_BITS, 0, EWEN_ADDR_BITS);
        standby();
        // Fill all memory
        writeOpAddr(WRITE_OPCODE, WRITE_OPCODE_BITS, addr, WRITE_ADDR_BITS);
        writeData(0);
        standby();

        if (waitForCompletion()) {
            stop();
            getReady();
            // Write successful -- verify random location
            CPPUNIT_ASSERT_EQUAL((uint16_t)0, readAt(addr));
            stop();
            getReady();

            writeOpAddr(ERAL_OPCODE, ERAL_OPCODE_BITS, addr, ERAL_ADDR_BITS);
            standby();

            if (!waitForCompletion()) {
                CPPUNIT_FAIL("EEPROM erase was not completed");
                stop();
                return;
            }

            standby();

            writeOpAddr(EWDS_OPCODE, EWDS_OPCODE_BITS, 0, EWDS_ADDR_BITS);
            stop();

            getReady();
            for ( addr=0; addr < EEPROM93C46::SIZE; addr++ ) {
                CPPUNIT_ASSERT_EQUAL((uint16_t)0xFFFF, readAt(addr));
            }
        }
        else {
            CPPUNIT_FAIL("EEPROM write was not completed");
        }
        stop();
    }
Exemple #6
0
    void testWriteDisabled()
    {
        getReady();

        uint16_t addr = 0;
        uint16_t oldValue = readAt(addr);
        stop();
        getReady();
        if (writeTo(addr, ~oldValue)) {
            // Write appears to be successful -- continue
            CPPUNIT_ASSERT_EQUAL(oldValue, readAt(addr));
        }
        else {
            CPPUNIT_FAIL("EEPROM write was not completed");
        }
        stop();
    }
Exemple #7
0
 void testSequentialRead()
 {
     getReady();
     shiftOutBits(READ_OPCODE, READ_OPCODE_BITS);
     shiftOutBits(0, READ_ADDR_BITS);
     for ( int wordAddr=0; wordAddr < EEPROM93C46::SIZE; wordAddr++ ) {
         CPPUNIT_ASSERT_EQUAL( initialContent[wordAddr], shiftInBits(DATA_BITS) );
     }
     stop();
 }
Exemple #8
0
/**
 *  readAt - Read a word at specified address
 *  @addr: address to read
 *
 *  Returns the value of the word specified in 'addr' parameter.
 **/
uint16_t EEPROMTest::readAt(uint16_t addr)
{
    getReady();
    shiftOutBits(READ_OPCODE, READ_OPCODE_BITS);
    shiftOutBits(addr, READ_ADDR_BITS);

    uint16_t value = shiftInBits(DATA_BITS);
    stop();

    return value;
}
Exemple #9
0
    void testRead()
    {
        getReady();
        for ( uint32_t wordAddr=0; wordAddr < EEPROM93C46::SIZE; wordAddr++ ) {
            shiftOutBits(READ_OPCODE, READ_OPCODE_BITS);
            shiftOutBits(wordAddr, READ_ADDR_BITS);

            CPPUNIT_ASSERT_EQUAL( initialContent[wordAddr], (uint16_t)wordAddr );
            CPPUNIT_ASSERT_EQUAL( initialContent[wordAddr], shiftInBits(DATA_BITS) );
            standby();
        }
        stop();
    }
Exemple #10
0
    void testWrite()
    {
        //unused: int i;
        uint16_t wordAddr;

        getReady();
        // Enable write
        writeOpAddr(EWEN_OPCODE, EWEN_OPCODE_BITS, 0, EWEN_ADDR_BITS);
        standby();

        for ( wordAddr=0; wordAddr < EEPROM93C46::SIZE; wordAddr++ ) {
            //writeOpAddr(WRITE_OPCODE, WRITE_OPCODE_BITS, (uint16_t)wordAddr, WRITE_ADDR_BITS);
            writeTo(wordAddr, 0x3F00 - (wordAddr<<8));
            standby();

            if (!waitForCompletion()) {
                CPPUNIT_FAIL("EEPROM write was not completed");
                stop();
                return;
            }
            standby();
        }

        // Disable write
        writeOpAddr(EWDS_OPCODE, EWDS_OPCODE_BITS, 0, EWDS_ADDR_BITS);

        stop();

        // Now check the result
        getReady();
        writeOpAddr(READ_OPCODE, READ_OPCODE_BITS, 0, READ_ADDR_BITS);
        for ( wordAddr=0; wordAddr < EEPROM93C46::SIZE; wordAddr++ ) {
            CPPUNIT_ASSERT_EQUAL((uint16_t)(0x3F00 - (wordAddr<<8)), shiftInBits(DATA_BITS) );
        }
        stop();
    }
Exemple #11
0
int mypthread_yield(void) 
{
	if (!mainSetup)
	{
		int unused = getUnused();
		if (getcontext(&(allThreads[unused].context)) != 0)
		{
			printf("Error getting context.\n");
			exit(0);
		}

		allThreads[unused].context.uc_stack.ss_sp = malloc(STACKSIZE);
		allThreads[unused].context.uc_stack.ss_size = STACKSIZE;
		allThreads[unused].status = READY;
		allThreads[threadIndex].status = RUNNING;

		mainSetup = 1;

		swapcontext(&(allThreads[unused].context), &(allThreads[threadIndex].context));
		return 0;
	}
	allThreads[threadIndex].status = READY;

	int next = getReady();

	if (next < 0)
	{
		int waiting = getWaiting();
		
		if (waiting < 0)
		{
			printf("No waiting threads found.\n");
			exit(0);
		}
		
		next = allThreads[waiting].index;
	}

	int old = threadIndex;

	threadIndex = next;

	allThreads[threadIndex].status = RUNNING;

	swapcontext(&(allThreads[old].context), &(allThreads[threadIndex].context));
	
	return 0;
}
Exemple #12
0
void Ship::pushPosition() {
    visual -> setPosition((int)properties.posX, (int)properties.posY);
    visual -> setDirection(
            cos(properties.shipDirection), sin(properties.shipDirection));
    visual -> setCannonDirection(
            cos(properties.cannonDirection), sin(properties.cannonDirection));
    visual -> setViewDirection(
            cos(properties.radarDirection), sin(properties.radarDirection));

    turnData.x = (unsigned short)properties.posX;
    turnData.y = (unsigned short)properties.posY;
    turnData.energy = energy;
    rubyShip.updateTurnData();

    getReady();
}
Exemple #13
0
int mypthread_join(mypthread_t thread, void **retval) 
{
	if (!mainSetup)
	{
		int unused = getUnused();
		if (getcontext(&(allThreads[unused].context)) != 0)
		{
			printf("Error getting context.\n");
			exit(0);
		}
		allThreads[unused].context.uc_stack.ss_sp = malloc(STACKSIZE);
		allThreads[unused].context.uc_stack.ss_size = STACKSIZE;

		allThreads[thread.index].beingJoinedOnBy = allThreads[unused].index;

		threadIndex = thread.index;

		allThreads[threadIndex].status = RUNNING;
		allThreads[unused].status = WAITING;

		if (retval)
		{	
			printf("retval detected in join call, setting return address in thread struct\n");
			allThreads[threadIndex].retadd = retval;
			printf("retadd set to %p\n", allThreads[threadIndex].retadd);
		}

		mainSetup = 1;

		swapcontext(&(allThreads[unused].context), &(allThreads[threadIndex].context));

		return 0;
	}
	if (threadIndex == thread.index)
	{
		printf("A thread cannot join on itself.\n");
		return -1;
	}
	if (allThreads[thread.index].beingJoinedOnBy > -1)
	{
		printf("Thread is already being joined on.\n");
		return -1;
	}
	if (retval)
		{	
			printf("retval detected in join call (not in main setup), setting return address in thread struct\n");
			allThreads[thread.index].retadd = retval;
			printf("retadd set to %p\n", allThreads[threadIndex].retadd);
		}
	if (allThreads[threadIndex].status == EXITED)
	{
		allThreads[threadIndex].status = UNUSED;
		free(allThreads[threadIndex].context.uc_stack.ss_sp);
		allThreads[threadIndex].beingJoinedOnBy = -1;
		count--;
		return 0;
	}

	allThreads[threadIndex].status = WAITING;
	allThreads[thread.index].beingJoinedOnBy = threadIndex;

	int next = getReady();

	if (next < 0)
	{
		int waiting = getWaiting();
		
		if (waiting < 0)
		{
			printf("No waiting threads found.\n");
			exit(0);
		}	
		next = allThreads[waiting].index;
	}

	int old = threadIndex;
	threadIndex = next;
	allThreads[threadIndex].status = RUNNING;
	swapcontext(&(allThreads[old].context), &(allThreads[threadIndex].context));
	return 0;
}
Exemple #14
0
  /** Run the VMC algorithm.
   * \param nblocks number of blocks
   * \param nsteps number of steps
   * \param tau the timestep
   *
   * Advance the walkers nblocks*nsteps timesteps. 
   * For each timestep:
   * <ul>
   * <li> Move all the particles of a walker.
   * <li> Calculate the properties for the new walker configuration.
   * <li> Accept/reject the new configuration.
   * <li> Accumulate the estimators.
   * </ul>
   * For each block:
   * <ul>
   * <li> Flush the estimators and print to file.
   * <li> (Optional) Print the ensemble of walker configurations.
   * </ul>
   *
   * Default mode: Print the ensemble of walker configurations 
   * at the end of the run.
   */
  bool VMC::run() { 
    
#ifdef MOVE_ONE
    DistanceTable::create(1);
#else
    DistanceTable::create(W.getActiveWalkers());
    Psi.resizeByWalkers(W.getActiveWalkers());
#endif

    if(put(qmc_node)){
      
      //set the data members to start a new run
      getReady();
      
      //probably unnecessary
      for(MCWalkerConfiguration::iterator it = W.begin(); 
	  it != W.end(); ++it) {
	(*it)->Properties(Weight) = 1.0;
      }
      
      Estimators.reset();

      //create an output engine
      HDFWalkerOutput WO(RootName);
      
      IndexType block = 0;
      
      Pooma::Clock timer;
      
      double wh=0.0;
      IndexType accstep=0;
      IndexType nAcceptTot = 0;
      IndexType nRejectTot = 0;
      do {
	IndexType step = 0;
	timer.start();
	nAccept = 0; nReject=0;
	do {
#ifdef MOVE_ONE
	  advanceWalkerByWalker();
#else
	  advanceAllWalkers();
#endif
	  step++;accstep++;
	  Estimators.accumulate(W);
	} while(step<nSteps);
	
	timer.stop();
	nAcceptTot += nAccept;
	nRejectTot += nReject;
	
	Estimators.flush();
	Estimators.setColumn(AcceptIndex,
			     static_cast<double>(nAccept)/static_cast<double>(nAccept+nReject));
	Estimators.report(accstep);
	
	LogOut->getStream() << "Block " << block << " " << timer.cpu_time() << endl;
	if(pStride) WO.get(W);
	nAccept = 0; nReject = 0;
	block++;
      } while(block<nBlocks);
      
      LogOut->getStream() 
	<< "Ratio = " 
	<< static_cast<double>(nAcceptTot)/static_cast<double>(nAcceptTot+nRejectTot)
	<< endl;
      
      if(!pStride) WO.get(W);
      
      Estimators.finalize();
      
      return true;
    } else {
      ERRORMSG("Error with Input")
      return false;
    }
  }
Exemple #15
0
MainWindow::MainWindow()
{
    setupUi(this);
    if (tr("LTR") == "RTL") {
        qApp->setLayoutDirection(Qt::RightToLeft);
    }

#ifndef Q_OS_WIN32
    testPageSplitter->setPalette(this->palette());
#endif

    remainingTimeLcdNumber->setVisible(false);
    remainingTimeProgressBar->setVisible(false);
    label_minutes->setVisible(false);
    questionTextSvgSplitter->setCollapsible(0, false);
    questionTextSvgSplitter->setCollapsible(1, true);
    tcpSocket = new QTcpSocket(this);
    progress_dialog = NULL;
    current_test_use_groups = false;
    current_connection_local = false;

    QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateTime()));
    QObject::connect(tbtnQuit, SIGNAL(released()), this, SLOT(close()));
    QObject::connect(tbtnAbout, SIGNAL(released()), this, SLOT(about()));
    QObject::connect(tbtnGetReady, SIGNAL(released()), this, SLOT(getReady()));
    QObject::connect(tbtnStart, SIGNAL(released()), this, SLOT(start()));
    QObject::connect(tbtnBrowse_DBPath, SIGNAL(released()), this, SLOT(browse_i()));
    QObject::connect(tbtnBrowse_savePath, SIGNAL(released()), this, SLOT(browse_o()));
    QObject::connect(tbtnLoad, SIGNAL(released()), this, SLOT(loadFile()));
    QObject::connect(useDefaultOutputCheckBox, SIGNAL(toggled(bool)), savePathLineEdit, SLOT(setDisabled(bool)));
    QObject::connect(useDefaultOutputCheckBox, SIGNAL(toggled(bool)), tbtnBrowse_savePath, SLOT(setDisabled(bool)));
    QObject::connect(serverNameLineEdit, SIGNAL(textChanged(const QString &)),
                     this, SLOT(enableConnectButton()));
    QObject::connect(serverPortLineEdit, SIGNAL(textChanged(const QString &)),
                     this, SLOT(enableConnectButton()));
    QObject::connect(DBPathLineEdit, SIGNAL(textChanged(const QString &)),
                     this, SLOT(enableLoadButton()));
    QObject::connect(tbtnConnect, SIGNAL(released()), this, SLOT(connectSocket()));
    QObject::connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readIncomingData()));
    QObject::connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
                     this, SLOT(displayError(QAbstractSocket::SocketError)));
    QObject::connect(LQListWidget, SIGNAL(currentTextChanged(QString)),
                     this, SLOT(setCurrentQuestion()));
    QObject::connect(svgDisplayWidget, SIGNAL(titleClicked(const QString &)), this, SLOT(previewSvg(const QString &)));
    QObject::connect(btnNext, SIGNAL(released()), this, SLOT(nextQuestion()));
    QObject::connect(btnLast, SIGNAL(released()), this, SLOT(lastQuestion()));
    QObject::connect(btnFinish, SIGNAL(released()), this, SLOT(finish()));
    QObject::connect(btnNewTest, SIGNAL(released()), this, SLOT(newTest()));
    QObject::connect(btnQuit, SIGNAL(released()), this, SLOT(close()));

    rbtngrpInputType = new QButtonGroup (this);
    rbtngrpInputType->addButton(rbtnNetwork);
    rbtngrpInputType->addButton(rbtnFromFile);
    QObject::connect(rbtngrpInputType, SIGNAL(buttonReleased(QAbstractButton *)), this, SLOT(toggleInputType(QAbstractButton *)));

    QObject::connect(answersView, SIGNAL(buttonReleased(Question::Answers)), this, SLOT(setQuestionAnswered(Question::Answers)));

    for (int i = 0; i < 8; ++i) {
        infoTableWidget->setItem(i, 0, new QTableWidgetItem);
    }
    ITW_test_name = infoTableWidget->item(0, 0);
    ITW_test_date = infoTableWidget->item(1, 0);
    ITW_test_timestamp = infoTableWidget->item(2, 0);
    ITW_test_time = infoTableWidget->item(3, 0);
    ITW_test_qnum = infoTableWidget->item(4, 0);
    ITW_test_fnum = infoTableWidget->item(5, 0);
    ITW_test_categories = infoTableWidget->item(6, 0);
    ITW_test_passmark = infoTableWidget->item(7, 0);
    ITW_test_comments = new QTextBrowser (infoTableWidget);
    infoTableWidget->setCellWidget(8, 0, ITW_test_comments);
    infoTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    infoTableWidget->verticalHeader()->setSectionResizeMode(8, QHeaderView::Stretch);
    resultsTableWidget->setColumnCount(1);
    resultsTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    resultsTableWidget->horizontalHeader()->hide();
    
    loadSettings();
    
    // Check app args ----------------------------------------------------------
    if (qApp->arguments().count() > 2) {
        if (qApp->arguments().at(1) == "-port") {
            serverNameLineEdit->setText("Localhost");
            serverPortLineEdit->setText(qApp->arguments().at(2));
            connectSocket();
        }
    } else if (qApp->arguments().count() > 1) {
        openFile(qApp->arguments().at(1));
    }
}
/**
 * This tutorial demonstrates simple sending of messages over the ROS system.
 */
int main(int argc, char **argv)
{
  /**
   * The ros::init() function needs to see argc and argv so that it can perform
   * any ROS arguments and name remapping that were provided at the command line. For programmatic
   * remappings you can use a different version of init() which takes remappings
   * directly, but for most command-line programs, passing argc and argv is the easiest
   * way to do it.  The third argument to init() is the name of the node.
   *
   * You must call one of the versions of ros::init() before using any other
   * part of the ROS system.
   */
  ros::init(argc, argv, "talker");

  /**
   * NodeHandle is the main access point to communications with the ROS system.
   * The first NodeHandle constructed will fully initialize this node, and the last
   * NodeHandle destructed will close down the node.
   */
  ros::NodeHandle n;

  /**
   * The advertise() function is how you tell ROS that you want to
   * publish on a given topic name. This invokes a call to the ROS
   * master node, which keeps a registry of who is publishing and who
   * is subscribing. After this advertise() call is made, the master
   * node will notify anyone who is trying to subscribe to this topic name,
   * and they will in turn negotiate a peer-to-peer connection with this
   * node.  advertise() returns a Publisher object which allows you to
   * publish messages on that topic through a call to publish().  Once
   * all copies of the returned Publisher object are destroyed, the topic
   * will be automatically unadvertised.
   *
   * The second parameter to advertise() is the size of the message queue
   * used for publishing messages.  If messages are published more quickly
   * than we can send them, the number here specifies how many messages to
   * buffer up before throwing some away.
   */
  ros::Publisher pose2D_pub = n.advertise<geometry_msgs::Pose2D>("chatter", 1000);

  ros::Rate loop_rate(10);

  /**
   * A count of how many messages we have sent. This is used to create
   * a unique string for each message.
   */
  int count = 0;
  while (ros::ok())
  {
    /**
     * This is a message object. You stuff it with data, and then publish it.
     */
    // float x= 1.0;
    //std_msgs::String msg;
    geometry_msgs::Pose2D msg;

    ReadPoint();
    msg.x = getPositionX();
    msg.y = getPositionY();
    msg.theta = getReady();

    ROS_INFO("%f %f %f", msg.x, msg.y, msg.theta);
 
    /**
     * The publish() function is how you send messages. The parameter
     * is the message object. The type of this object must agree with the type
     * given as a template parameter to the advertise<>() call, as was done
     * in the constructor above.
     */
    pose2D_pub.publish(msg);

    ros::spinOnce();

    loop_rate.sleep();
    ++count;
  }


  return 0;
}