Ejemplo n.º 1
0
double dumptime() {
	static unsigned prevMicroSec = getMicroseconds();
	unsigned curMicroSec = getMicroseconds();
	double res = (curMicroSec - prevMicroSec)/1000000.0;
	prevMicroSec = curMicroSec;
	return res;
}
Ejemplo n.º 2
0
// workerProcessCron is the cron of worker process, it must be called before
// worker process initialized.
//
// `fake_func` is used by spawnFakeWorker and call it every cron.
void workerProcessCron(void (*fake_func)(void *data), void *data)
{
    static long long max_cron_interval = 0;

    struct timeval nowval;
    long long interval;
    int refresh_seconds;
    void (*worker_cron)();

    refresh_seconds = Server.stat_refresh_seconds;
    worker_cron = WorkerProcess->worker->cron;
    while (WorkerProcess->alive) {
        arrayEach(WorkerProcess->apps, appCronRun);

        if (worker_cron)
            worker_cron();
        if (fake_func)
            fake_func(data);
        processEvents(WorkerProcess->center, WHEATSERVER_CRON_MILLLISECONDS);
        if (WorkerProcess->ppid != getppid()) {
            wheatLog(WHEAT_NOTICE, "parent change, worker shutdown");
            WorkerProcess->alive = 0;
        }
        clientsCron();

        if (Server.cron_time.tv_sec - WorkerProcess->refresh_time > refresh_seconds) {
            sendStatPacket(WorkerProcess);
            WorkerProcess->refresh_time = Server.cron_time.tv_sec;
        }

        // Get the max worker cron interval for statistic info
        gettimeofday(&nowval, NULL);
        interval = getMicroseconds(nowval) - getMicroseconds(Server.cron_time);
        if (interval > max_cron_interval) {
            max_cron_interval = interval;
            getStatValByName("Max worker cron interval") = interval;
        }
        Server.cron_time = nowval;
    }

    // Stop accept new client
    deleteEvent(WorkerProcess->center, Server.ipfd, EVENT_READABLE|EVENT_WRITABLE);
    WorkerProcess->refresh_time = Server.cron_time.tv_sec;
    while (Server.cron_time.tv_sec - WorkerProcess->refresh_time < Server.graceful_timeout) {
        processEvents(WorkerProcess->center, WHEATSERVER_CRON_MILLLISECONDS);
        gettimeofday(&Server.cron_time, NULL);
    }
}
Ejemplo n.º 3
0
	static PyObject *convert( const posix_time::ptime &t )
	{
		if ( t.is_special() )
		{
			PyErr_SetString(PyExc_ValueError, "Cannot convert out-of-range ptime to datetime");
			throw_error_already_set();
		}

		gregorian::date date = t.date();
		posix_time::time_duration dur = t.time_of_day();
		return PyDateTime_FromDateAndTime(
			static_cast<int>( date.year() ),
			static_cast<int>( date.month() ),
			static_cast<int>( date.day() ),
			static_cast<int>( dur.hours() ),
			static_cast<int>( dur.minutes() ),
			static_cast<int>( dur.seconds() ),
			getMicroseconds( dur )
		);
	}
Ejemplo n.º 4
0
 std::uint64_t getUptimeMicroseconds() const
 {
     return getMicroseconds() - started_at_usec_;
 }
Ejemplo n.º 5
0
 MonotonicTimekeeper() :
     started_at_usec_(getMicroseconds())
 { }
Ejemplo n.º 6
0
Archivo: Enc.c Proyecto: klvt/fiwt
void EncUpdate(void) {
    int i;
    int32_t timestamp0, timestamp1, timestamp;
    /* Declare local variables */
    unsigned int EncBit_CNT;
    unsigned int  CurEncPos[ENCNUM];
    bool phase_sync;

    phase_sync = true;
    //trigger for start
    ENC_CLOCK = 0;
    timestamp0 = getMicroseconds();
    timestamp1 = timestamp0+ENC_HALF_PEROID;

    //work
    /* Initialize local variables */
    for (i = 0; i < ENCNUM; ++i) {
        CurEncPos[i] = 0;
    }
    //wait
    timestamp = getMicroseconds();
    if (timestamp>=timestamp1) {
       phase_sync = false;
    }
    while (timestamp<timestamp1) {
        timestamp = getMicroseconds();
    }

    /* Read 13-bit resolution Digital Encoders */
    /* Synchro-Serial Interface reading */
    for (EncBit_CNT = 0; EncBit_CNT < 13; ++EncBit_CNT) {
        // Trigger ENC_CLOCK to a logical high state
        ENC_CLOCK = 1;        
        timestamp1 += ENC_HALF_PEROID;

        //work
        // Read Encoder data
        for (i = 0; i < ENCNUM; ++i) {
                CurEncPos[i] <<= 0b1;
        }
        //wait
        timestamp = getMicroseconds();
        if (timestamp>=timestamp1) {
           phase_sync = false;
        }
        while (timestamp<timestamp1) {
            timestamp = getMicroseconds();
        }

        // Trigger ENC_CLOCK to a logical low state
        ENC_CLOCK = 0;
        timestamp1 += ENC_HALF_PEROID;

        //work
        // Read Encoder data
        for (i = 0; i < ENCNUM; ++i) {
            if (*(enc_data[i].port) & enc_data[i].mask)
                CurEncPos[i] |= 0b1;
        }

        //wait
        timestamp = getMicroseconds();
        if (timestamp>=timestamp1) {
           phase_sync = false;
           break;
        }
        while (timestamp<timestamp1) {
            timestamp = getMicroseconds();
        }
    }

    //End. Set ENC_CLOCK to a logical high state
    ENC_CLOCK = 1;
    if (phase_sync) {
        for (i = 0; i < ENCNUM; ++i) {
                EncPos[i] = CurEncPos[i];
        }
    }
}
	// Performs a spin wait for the specified number of microseconds. Exact microsecond accuracy is not super important here. It is, however, at the very least accurate to the millisecond.
	void busyWait(time_t us){
		us += getMicroseconds();
		while (getMicroseconds() < us);
	}
Ejemplo n.º 8
0
double Time::getSeconds()
{
    return getMicroseconds() * 0.000001;
}
Ejemplo n.º 9
0
int64_t getMicrosecondsRealtime() {
  return getMicroseconds(CLOCK_REALTIME);
}
Ejemplo n.º 10
0
int64_t getMicrosecondsMonotonic() {
  return getMicroseconds(CLOCK_MONOTONIC);
}
Ejemplo n.º 11
0
Archivo: main.cpp Proyecto: CCJY/coliru
 int64_t getMilliseconds() const
 {
     return int64_t(0.5 + getMicroseconds() / 1000.0);
 }
void SoundplaneOSCOutput::processSoundplaneMessage(const SoundplaneDataMessage* msg)
{
    static const MLSymbol startFrameSym("start_frame");
    static const MLSymbol touchSym("touch");
    static const MLSymbol onSym("on");
    static const MLSymbol continueSym("continue");
    static const MLSymbol offSym("off");
    static const MLSymbol controllerSym("controller");
    static const MLSymbol xSym("x");
    static const MLSymbol ySym("y");
    static const MLSymbol xySym("xy");
    static const MLSymbol zSym("z");
    static const MLSymbol toggleSym("toggle");
    static const MLSymbol endFrameSym("end_frame");
    static const MLSymbol matrixSym("matrix");
    static const MLSymbol nullSym;
    
	if (!mActive) return;
    MLSymbol type = msg->mType;
    MLSymbol subtype = msg->mSubtype;
    
    int voiceIdx, offset;
	float x, y, z, dz, note, vibrato;
    
    if(type == startFrameSym)
    {
        const uint64_t dataPeriodMicrosecs = 1000*1000 / mDataFreq;
        mCurrFrameStartTime = getMicroseconds();
        if (mCurrFrameStartTime > mLastFrameStartTime + (uint64_t)dataPeriodMicrosecs)
        {
            mLastFrameStartTime = mCurrFrameStartTime;
            mTimeToSendNewFrame = true;
        }
        else
        {
            mTimeToSendNewFrame = false;
        }        
        mGotNoteChangesThisFrame = false;
        mGotMatrixThisFrame = false;
		
		for(int i=0; i < kSoundplaneMaxTouches; ++i)
		{
			mPrevPortOffsetsByTouch[i] = mPortOffsetsByTouch[i];
		}
		
		// update all voice states
		for(int offset=0; offset < kNumUDPPorts; ++offset)
		{
			for(int voiceIdx=0; voiceIdx < kSoundplaneMaxTouches; ++voiceIdx)
			{
				OSCVoice& v = mOSCVoices[offset][voiceIdx];        
				if (v.mState == kVoiceStateOff)
				{
					v.mState = kVoiceStateInactive;
				}
			}
		}
		
    }
    else if(type == touchSym)
    {
        // get incoming touch data from message
        voiceIdx = msg->mData[0];
        x = msg->mData[1];
        y = msg->mData[2];
        z = msg->mData[3];
        dz = msg->mData[4];
		note = msg->mData[5];
		vibrato = msg->mData[6];
		offset = msg->mOffset;
		
		mPortOffsetsByTouch[voiceIdx] = offset;
		
		// update new voice state for incoming touch
        OSCVoice& v = mOSCVoices[offset][voiceIdx];        
        v.x = x;
        v.y = y;
        v.z = z;
        v.note = note + vibrato;
		
        if(subtype == onSym)
        {
            v.startX = x;
            v.startY = y;
			
			// send dz (velocity) as first z value
			v.z = dz;
			
            v.mState = kVoiceStateOn;
            mGotNoteChangesThisFrame = true;
        }
        if(subtype == continueSym)
        {
            v.mState = kVoiceStateActive;
        }
        if(subtype == offSym)
        {
            if((v.mState == kVoiceStateActive) || (v.mState == kVoiceStateOn))
            {
                v.mState = kVoiceStateOff;
                v.z = 0;
                mGotNoteChangesThisFrame = true;
            }
        }
    }
    else if(type == controllerSym)
    {
        // when a controller message comes in, make a local copy of the message and store by zone ID.
        int zoneID = msg->mData[0];
        mMessagesByZone[zoneID] = *msg;
    }
    else if(type == matrixSym)
    {
        // store matrix to send with bundle
        mGotMatrixThisFrame = true;
        mMatrixMessage = *msg;
    }
    else if(type == endFrameSym)
    {
        if(mGotNoteChangesThisFrame || mTimeToSendNewFrame)
        {
			sendFrame();
		}
		
		// format and send matrix in OSC blob if we got one.
		// matrix is always sent to the default port. 
		if(mGotMatrixThisFrame)
		{
			osc::OutboundPacketStream& p = getPacketStreamForOffset(0);					 
			UdpTransmitSocket& socket = getTransmitSocketForOffset(0);
			p << osc::BeginMessage( "/t3d/matrix" );
			p << osc::Blob( &(msg->mMatrix), sizeof(msg->mMatrix) );
			p << osc::EndMessage;
			mGotMatrixThisFrame = false;
			socket.Send( p.Data(), p.Size() );
		}
    }
}
Ejemplo n.º 13
0
int Milliseconds::getTime() const
{
  return (getSeconds()*1000) + (getMicroseconds()/1000);
};