Exemple #1
0
/**
 * Fix for systems that don't have pthread_mutex_timedlock
 *
 * @param mutex  The mutex we're waiting on
 * @param abs_timeout
 *               The time timeout value
 *
 * @return zero or an error code.
 */
int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout)
{
    int pthread_rc;

    long waitInterval;

    // we might already be timed out
    if (checkTimeOut(abs_timeout, waitInterval))
    {
        return ETIMEDOUT;
    }

    while ((pthread_rc = pthread_mutex_trylock(mutex)) == EBUSY)
    {
        struct timespec ts;
        ts.tv_sec = 0;
        ts.tv_nsec = waitInterval;

        struct timespec slept;
        nanosleep(&ts, &slept);

        // check for a timeout immediately, this also gives us our
        // next wait interval
        if (checkTimeOut(abs_timeout, waitInterval))
        {
            return ETIMEDOUT;
        }
    }

    return pthread_rc;
}
Exemple #2
0
void CMD_SetLPFAlpha(){
           byte alpha, device;
             
           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }    
           
           digitalWrite(SERIALPIN, LOW);
           device = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
           
           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }    
           
           digitalWrite(SERIALPIN, LOW);
           alpha = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
           
           if( alpha<0 || alpha>100 ) return;
           
           switch( device ){
               
               case 0: setDegLPFAlpha( (double) alpha/100 ); break;
               case 1: setAccelLPFAlpha( (double) alpha/100 ); break;
               case 2: setGyroLPFAlpha( (double) alpha/100 ); break;
           }
           
           pendAlphaTM();
}
Exemple #3
0
void parseArguments(int argc, char *argv[], std::string & filePath, bool & unitTest, bool & dirTest, int & timeOut)
{
	filePath	= "";
	unitTest	= false,
	dirTest		= false;

	if (argc > 1)
	{
		std::string argFirst = argv[1];

		if (argFirst[0] != '-')
		{
			const std::string	jaspExtension	= ".jasp",
								unitTestArg		= "--unitTest";

					filePath	= argFirst;
			bool	isJaspFile	= filePath.size() >= jaspExtension.size()  &&  filePath.substr(filePath.size() - jaspExtension.size()) == jaspExtension;
					unitTest	= isJaspFile && argc > 2 && argv[2] == unitTestArg;

			checkTimeOut(argc, argv, 3, timeOut);

		}
		else
		{
			if(argFirst == "--unitTestRecursive")
			{
				std::string argFolder = argv[2];

				QDir folder(QString::fromStdString(argFolder));

				if(!folder.exists())
				{
					std::cerr << "Folder for dir unittest " << argFolder << " does not exist!" << std::endl;
					exit(1);
				}

				dirTest		= true;
				filePath	= argFolder;

				checkTimeOut(argc, argv, 3, timeOut);
			}
			else if(argFirst.find("--remote-debugging-port=")	== std::string::npos &&
					argFirst.find("-qmljsdebugger")				== std::string::npos) //only other excepted argument
			{
				std::cout	<< "JASP can be started without arguments, or the following: filename {--unitTest {--timeOut=10}} | --unitTestRecursive folder {--timeOut=10}\n"
							<< "If a filename is supplied JASP will try to load it. If --unitTest is specified JASP will refresh all analyses in the JASP file and see if the output remains the same and will then exit with an errorcode indicating succes or failure.\n"
							<< "If --unitTestRecursive is specified JASP will go through specified \"folder\" and perform a --unitTest on each JASP file. After it has done this it will exit with an errorcode indication succes or failure.\n"
							<< "For both testing arguments there is the optional --timeout argument, which specifies how many minutes JASP will wait for the analyses-refresh to take. Default is 10 minutes."
							<< std::endl;
				exit(1);
			}
		}
	}
}
void CWizDocumentStatusChecker::onTimeOut()
{
    qDebug() << "CWizDocumentStatusChecker time out";
    m_timeOutTimer->stop();
    m_stop = true;
    emit checkTimeOut(m_strCurGUID);
}
/// \brief New connexion
void ServerCatchcopy::newConnection()
{
	while(server.hasPendingConnections())
	{
		QLocalSocket *clientSocket = server.nextPendingConnection();
		if(clientSocket!=NULL)
		{
			do
			{
				idNextClient++;
				if(idNextClient>2000000000)
					idNextClient=0;
			} while(clientIdFound(idNextClient));
			Client newClient;
			newClient.id			= idNextClient;
			newClient.socket		= clientSocket;
			newClient.haveData		= false;
			newClient.firstProtocolReplied	= false;
			newClient.detectTimeOut		= new QTimer(this);
			newClient.detectTimeOut->setSingleShot(true);
			newClient.detectTimeOut->setInterval(CATCHCOPY_COMMUNICATION_TIMEOUT);
			connect(newClient.socket,	SIGNAL(error(QLocalSocket::LocalSocketError)),	this, SLOT(connectionError(QLocalSocket::LocalSocketError)));
			connect(newClient.socket,	SIGNAL(readyRead()),				this, SLOT(readyRead()));
			connect(newClient.socket,	SIGNAL(disconnected()),				this, SLOT(disconnected()));
			connect(newClient.detectTimeOut,SIGNAL(timeout()),				this, SLOT(checkTimeOut()));
			ClientList << newClient;
			emit connectedClient(newClient.id);
		}
	}
}
Exemple #6
0
void CMD_PIDValues(){
            byte pid, roll;
            int value;
        
            while(!Serial.available()){
                if( checkTimeOut() ) return;
            }
            
            digitalWrite(SERIALPIN, LOW);
            roll = Serial.read();
            digitalWrite(SERIALPIN, HIGH);
            
            while(!Serial.available()){
                if( checkTimeOut() ) return;
            }
            
            digitalWrite(SERIALPIN, LOW);
            pid = Serial.read();
            digitalWrite(SERIALPIN, HIGH);
            
            while(!Serial.available()){
                if( checkTimeOut() ) return;
            }
            
            digitalWrite(SERIALPIN, LOW);
            value = Serial.read() << 8;
            digitalWrite(SERIALPIN, HIGH);
            
            while(!Serial.available()){
                if( checkTimeOut() ) return;
            }
            
            digitalWrite(SERIALPIN, LOW);
            value += Serial.read();
            digitalWrite(SERIALPIN, HIGH);
            
            if( roll==0xFF && pid==0xFF && value==0xFF ){
                setPIDValues(0, 0, double(DEFAULT_PVALUE_ANGLES)/10000);
                setPIDValues(0, 1, double(DEFAULT_IVALUE_ANGLES)/10000);
                setPIDValues(0, 2, double(DEFAULT_DVALUE_ANGLES)/10000);
                setPIDValues(1, 0, double(DEFAULT_PVALUE_GYRO)/10000);
                setPIDValues(1, 1, double(DEFAULT_IVALUE_GYRO)/10000);
                setPIDValues(1, 2, double(DEFAULT_DVALUE_GYRO)/10000);
            } else setPIDValues( roll, pid, double(value)/10000 );
            pendPIDTM();
}
Exemple #7
0
void CMD_SetOffsets(){
           byte dev, axis;
           int val;
           
           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }
           
           digitalWrite(SERIALPIN, LOW);
           dev = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
           
           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }
           
           digitalWrite(SERIALPIN, LOW);
           axis = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
           
           if( axis != 0xFF ){
           
               while(!Serial.available()){
                    if( checkTimeOut() ) return;
                }
                
               digitalWrite(SERIALPIN, LOW);
               val = Serial.read();
               digitalWrite(SERIALPIN, HIGH);
               
               while(!Serial.available()){
                    if( checkTimeOut() ) return;
                }
                
               digitalWrite(SERIALPIN, LOW);
               val = (val << 8) + Serial.read();
               digitalWrite(SERIALPIN, HIGH);
           }
           
           setOffsets(dev, axis, val);
           
           pendAccelOffTM();
           pendGyroOffTM();
}
Exemple #8
0
void CMD_SetMotorOffset(){
           byte mot, sp;
           
           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }
           digitalWrite(SERIALPIN, LOW);
           mot = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
          

           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }
           digitalWrite(SERIALPIN, LOW);
           sp = Serial.read();
           digitalWrite(SERIALPIN, HIGH);

           setMotorOffset( mot, sp );
           pendMotorOffsetsTM();  
}
Exemple #9
0
void WizDocumentStatusChecker::startCheck()
{
//    qDebug() << "----------    CWizDocumentStatusChecker::startCheck start";
    m_networkError = false;
    peekDocumentGUID(m_strCurKbGUID, m_strCurGUID);

    // start timer
    m_timeOutTimer->start(5000);

    bool isGroup = false;
    bool changed = checkDocumentChangedOnServer(m_strCurKbGUID, m_strCurGUID, isGroup);
    if (m_stop)
    {
        emit checkEditStatusFinished(m_strCurGUID, false);
        return;
    }
    emit checkDocumentChangedFinished(m_strCurGUID, changed);

    if (changed)
    {
        emit checkEditStatusFinished(m_strCurGUID, false);
        m_timeOutTimer->stop();
        return;
    }

    bool editingByOthers = false;
    if (isGroup)
    {
        editingByOthers = checkDocumentEditStatus(m_strCurKbGUID, m_strCurGUID);
    }
    //
    if (m_stop)
    {
        emit checkEditStatusFinished(m_strCurGUID, false);
        return;
    }


    m_timeOutTimer->stop();


//    qDebug() << "------------   CWizDocumentStatusChecker::startCheck  finished";

    if (m_networkError)
    {
        //NOTE: 网络错误时不一定会导致超时,此处发送超时消息进行离线编辑的提示
        emit checkTimeOut(m_strCurGUID);
    }
    else
    {
        emit checkEditStatusFinished(m_strCurGUID, !editingByOthers);
    }
}
Exemple #10
0
void CMD_MotorsSwitch(){
           boolean pow;
           int m;
           while(!Serial.available()){
                if( checkTimeOut() ) return;
            }
          
           digitalWrite(SERIALPIN, LOW);
           m = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
          
           pow = !getMotorPower(m);
           setMotorPower( m, pow );
           pendMotorsPowerTM();  
}
Exemple #11
0
void CMD_TestMotors(){
           byte motor;
           unsigned long time;
         
           setTotalSpeed(0);
           
           while(!Serial.available()){
                if( checkTimeOut() ) return;
           }   
           
           digitalWrite(SERIALPIN, LOW); 
           motor = Serial.read();
           digitalWrite(SERIALPIN, HIGH);
           
           setMotorSpeed(motor, 80);
           time = millis();
           
           while( millis() - time < 1000 );
           
           setTotalSpeed(0);
}
void CWizDocumentStatusCheckThread::onTimeOut()
{
    qDebug() << "document check thread time out " << m_strCurGUID;
    emit checkTimeOut(m_strCurGUID);
}
void KEpollSelector::select() {
	epoll_event events[MAXEVENT];
	for (;;) {
#ifdef MALLOCDEBUG
		if (closeFlag) {
			delete this;
			return;
		}
#endif
		checkTimeOut();
		int ret = epoll_wait(kdpfd, events, MAXEVENT,tmo_msec);
		if (utm) {
			updateTime();
		}
		for (int n = 0; n < ret; ++n) {
			KSelectable *st = ((KSelectable *) events[n].data.ptr);
#ifndef NDEBUG
			klog(KLOG_DEBUG,"select st=%p,st_flags=%d,events=%d at %p\n",st,st->st_flags,events[n].events,pthread_self());
			assert(TEST(st->st_flags,STF_READ|STF_WRITE)>0);
			kgl_event *ev = NULL;
#endif
			st->stack_level = 0;
			assert(TEST(st->st_flags,STF_EV));
			if (TEST(events[n].events,EPOLLOUT)) {
#ifndef NDEBUG
				ev = &st->e[OP_WRITE];
#endif
				assert(TEST(st->st_flags,STF_WRITE));
#ifdef ENABLE_ONESHOT_MODEL
				if (likely(TEST(st->st_flags,STF_ONE_SHOT)))
					CLR(st->st_flags,STF_WRITE);
#endif
				assert(st->e[OP_WRITE].result);
				st->eventWrite(st->e[OP_WRITE].arg,st->e[OP_WRITE].result,st->e[OP_WRITE].buffer);
			} else if (TEST(events[n].events,EPOLLIN)) {
#ifndef NDEBUG
				ev = &st->e[OP_READ];
#endif
			
				assert(TEST(st->st_flags,STF_READ));
#ifdef ENABLE_ONESHOT_MODEL
				if (likely(TEST(st->st_flags,STF_ONE_SHOT)))
					CLR(st->st_flags,STF_READ);
#endif
				assert(st->e[OP_READ].result);
				st->eventRead(st->e[OP_READ].arg,st->e[OP_READ].result,st->e[OP_READ].buffer);
			} else {
				if (TEST(st->st_flags,STF_WRITE)) {
#ifndef NDEBUG
					ev = &st->e[OP_WRITE];
#endif
#ifdef ENABLE_ONESHOT_MODEL
					if (likely(TEST(st->st_flags,STF_ONE_SHOT)))
						CLR(st->st_flags,STF_WRITE);
#endif
					st->e[OP_WRITE].result(st->e[OP_WRITE].arg,-1);
				} else {
#ifndef NDEBUG
					ev = &st->e[OP_READ];
#endif
					assert(TEST(st->st_flags,STF_READ));
#ifdef ENABLE_ONESHOT_MODEL
					if (likely(TEST(st->st_flags,STF_ONE_SHOT)))
						CLR(st->st_flags,STF_READ);
#endif
					st->e[OP_READ].result(st->e[OP_READ].arg,-1);
				}
			}
		}
	}

}