示例#1
0
int ReflexAgent(int percept1, int percept2){
	//interpret input
	//rulematch
	//return action;
	int rule, action;
	rule = interpretInput (percept1, percept2);
	action = ruleMatch(rule);
	return action;
}
/***************************************************
* CHECK AND SEND
* DESCRIPTION: Checks the input port for the value,
* passes the value onto the next device after interpretation
***************************************************/
void checkAndSend(char andValue, char port)
{
   if ((portVal & andValue) == andValue)
   {
   	  P1OUT |= 0x10;
      output = portVal & andValue;
      output = interpretInput(port, output);
      sendData();
      P1OUT &= 0xef;
   }
}
示例#3
0
bool Lockin2::start(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format)
{
    if (_audioInput != 0) {
        qDebug() << __FUNCTION__ << ": lockin is already running, please stop is before start";
        return false;
    }

    if (!format.isValid()) {
        qDebug() << __FUNCTION__ << ": format not valid";
        return false;
    }

    if (!isFormatSupported(format)) {
        qDebug() << __FUNCTION__ << ": format not supported for lockin2";
        return false;
    }

    if (audioDevice.isFormatSupported(format)) {
        _audioInput = new QAudioInput(audioDevice, format, this);
        _audioInput->setNotifyInterval(_outputPeriod * 1000.0);

        connect(_audioInput, SIGNAL(notify()), this, SLOT(interpretInput()));
        connect(_audioInput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State)));

        // pour être au millieu avec le temps
        _timeValue = -(_integrationTime / 2.0);

        // nombre d'échantillons pour le temps d'integration
        _sampleIntegration = format.sampleRate() * _integrationTime;

        // nombre d'échantillons pour un affichage de vumeter
        _sampleVumeter = _vumeterTime * format.sampleRate();

        // nettoyage des variables
        _fifo->readAll(); // vide le fifo
        _dataXY.clear(); // vide <x,y>

        _format = format;

        _audioInput->start(_fifo);
    } else {
        qDebug() << __FUNCTION__ << ": format not supported, can't start";
        return false;
    }


    return true;
}
void SC_TerminalClient::commandLoop()
{
	bool haveNext = false;
	struct timespec nextAbsTime;

	lockSignal();

	while( shouldBeRunning() )
	{

		while ( mSignals ) {
			int sig = mSignals;

			unlockSignal();

			if (sig & sig_input) {
				//postfl("input\n");
				lockInput();
				interpretInput();
				// clear input signal, as we've processed anything signalled so far.
				lockSignal();
				mSignals &= ~sig_input;
				unlockSignal();
				unlockInput();
			}

			if (sig & sig_sched) {
				//postfl("tick\n");
				double secs;
				lock();
				haveNext = tickLocked( &secs );
				// clear scheduler signal, as we've processed all items scheduled up to this time.
				// and will enter the wait according to schedule.
				lockSignal();
				mSignals &= ~sig_sched;
				unlockSignal();
				unlock();

				flush();

				//postfl("tick -> next time = %f\n", haveNext ? secs : -1);
				ElapsedTimeToTimespec( secs, &nextAbsTime );
			}

			if (sig & sig_stop) {
				stopMain();
				lockSignal();
				mSignals &= ~sig_stop;
				unlockSignal();
			}

			if (sig & sig_recompile) {
				recompileLibrary();
				lockSignal();
				mSignals &= ~sig_recompile;
				unlockSignal();
			}

			lockSignal();
		}

		if( !shouldBeRunning() ) {
			break;
		}
		else if( haveNext ) {
			int result = pthread_cond_timedwait( &mCond, &mSignalMutex, &nextAbsTime );
			if( result == ETIMEDOUT ) mSignals |= sig_sched;
		}
		else {
			pthread_cond_wait( &mCond, &mSignalMutex );
		}
	}

	unlockSignal();
}
void SC_TerminalClient::commandLoop()
{
	bool haveNext = false;
	struct timespec nextAbsTime;

	lockSignal();

	while( shouldBeRunning() )
	{

		while ( mSignals ) {
			int sig = mSignals;
			mSignals = 0;

			unlockSignal();

			if (sig & sig_input) {
				//postfl("input\n");
				lockInput();
				interpretInput();
				unlockInput();
			}

			if (sig & sig_sched) {
				//postfl("tick\n");
				double secs;
				lock();
				haveNext = tickLocked( &secs );
				unlock();

				flush();

				//postfl("tick -> next time = %f\n", haveNext ? secs : -1);
				ElapsedTimeToTimespec( secs, &nextAbsTime );
			}

			if (sig & sig_stop) {
				stopMain();
			}

			if (sig & sig_recompile) {
				recompileLibrary();
			}

			lockSignal();
		}

		if( !shouldBeRunning() ) {
			break;
		}
		else if( haveNext ) {
			int result = pthread_cond_timedwait( &mCond, &mSignalMutex, &nextAbsTime );
			if( result == ETIMEDOUT ) mSignals |= sig_sched;
		}
		else {
			pthread_cond_wait( &mCond, &mSignalMutex );
		}
	}

	unlockSignal();
}
void SC_TerminalClient::commandLoop()
{
	bool haveNext = false;
	mutex_chrono::system_clock::time_point nextAbsTime;

	lockSignal();

	while( shouldBeRunning() ) {

		while ( mSignals ) {
			int sig = mSignals;
			mSignals = 0;

			unlockSignal();

			if (sig & sig_input) {
				//postfl("input\n");
				lockInput();
				interpretInput();
				unlockInput();
			}

			if (sig & sig_sched) {
				//postfl("tick\n");
				double secs;
				lock();
				haveNext = tickLocked( &secs );
				unlock();

				flush();

				//postfl("tick -> next time = %f\n", haveNext ? secs : -1);
				ElapsedTimeToChrono( secs, nextAbsTime );
			}

			if (sig & sig_stop) {
				stopMain();
			}

			if (sig & sig_recompile) {
				recompileLibrary();
			}

			lockSignal();
		}

		if( !shouldBeRunning() ) {
			break;
		}
		else if( haveNext ) {
			unlockSignal();
			{
				unique_lock<SC_Lock> lock(mSignalMutex);

				cv_status status = mCond.wait_until(lock, nextAbsTime);
				if( status == cv_status::timeout )
					mSignals |= sig_sched;
			}
			lockSignal();
		}
		else {
			unlockSignal();
			{
				unique_lock<SC_Lock> lock(mSignalMutex);
				mCond.wait(lock);
			}
			lockSignal();
		}
	}

	unlockSignal();
}