Ejemplo n.º 1
0
static int ExecuteValueCells()
{
    knobData        kData;
    int             Error, i;
    int             devIOF;
    int             listNo;
    int             NumberOfLists;
    int             repeat = 0;
    int             tffunc;
    pioDevices      ProCells[MAX_DEVS];
    pioDevices      PioCells[MAX_DEVS];
    int             rep[MAX_DEVS];
    int             ProNumcell, PioNumcell;
    double          diff;
    struct timeb    time2;
    int             oneCell = 1;


    ProNumcell = 0;
    PioNumcell = 0;
    /* get another array for the block server devices, keep however the same array for all the devices */
    for (i=0; i<NumCells;i++) {
        if(strncmp(ValueCells[i].att, "PROF", 4) == 0) {
            memcpy(&ProCells[ProNumcell], &ValueCells[i], sizeof(pioDevices));
            rep[ProNumcell]= Repetition[i];
            ProNumcell++;
        }
        memcpy(&PioCells[PioNumcell], &ValueCells[i], sizeof(pioDevices));
        PioNumcell++;
    }

    //printf("%d proCells, %d pioCells\n", ProNumcell, PioNumcell);

    if(PioNumcell > 0) {
        tffunc = 1;
        listNo = 1;
        devIOF = 7;
        medmAcquisition(&my_protocol, &devIOF, PioCells, &PioNumcell,
                        &repeat, &listNo, &NumberOfLists, &Error, tffunc);

        if (Error < 1) {
            if(Error != -4) C_postMsgEvent(messageWindow, 1, vaPrintf("acs io-error %d\n", Error));

            // do we have timeouts somewhere ?

            if(Error == -4) {
                for (i=0; i<PioNumcell;i++) {
                    if(PioCells[i].error_code == -4) {
                        int indx = PioCells[i].ident;
                        C_GetMutexKnobData(KnobDataPtr, indx, &kData);
                        kData.edata.connected = False;
                        C_SetMutexKnobDataReceived(KnobDataPtr, &kData);
                    }
                }
            }
        }
    }

    /* if any block server cells, execute them one after the other, we will only acquire every 5 seconds */
    /* we will have to pack them, to avoid too many long buffers (acs gives x and y for a profile and the interface  */
    /* request once for x and once for y */

    if(ProNumcell > 0) {
        char name1[9], name2[9];
        char attr1[5], attr2[5];
        int  execute[MAX_DEVS];
        tffunc = 2;
        devIOF = 1;
        myftime(&time2);
        name1[0] = '\0';
        attr1[0] = '\0';

        // get the profiles to execute
        for (i = ProNumcell-1; i >= 0; i--) {
            extent[i] = -1;
            strncpy(name1, ProCells[i].name, 8); name1[8] = '\0';
            strncpy(attr1, ProCells[i].att, 4); attr1[4] = '\0';

            if((i-1) >= 0) {
                strncpy(name2, ProCells[i-1].name, 8); name2[8] = '\0';
                strncpy(attr2, ProCells[i-1].att, 4); attr2[4] = '\0';
            } else {
                name2[0] = '\0';
                attr2[0] = '\0';
            }

            if (IsInside(name2, name1) && IsInside(attr1, attr2)) {
                execute[i] = False;
            } else {
                execute[i] = True;
                if(i!=ProNumcell-1) extent[ProCells[i].ident] = ProCells[i+1].ident;
            }
        }
        // execute the profiles
        for (i = 0; i < ProNumcell; i++) {
            if(execute[i]) {
                diff = ((double) time2.time + (double) time2.millitm / (double)1000) -
                        ((double) lastTime[i].time + (double) lastTime[i].millitm / (double)1000);
                if(diff >= rep[i] || firstTime[i]) {
                    firstTime[i] = False;
                    myftime(&lastTime[i]);
                    listNo = MAX_LISTS/2 + i;

                    medmAcquisition(&my_protocol, &devIOF, &ProCells[i], &oneCell,
                                    &repeat, &listNo, &NumberOfLists, &Error, tffunc);
                    if (Error < 1) {
                        if(Error != -4) C_postMsgEvent(messageWindow, 1, vaPrintf("acs io-error %d\n", Error));
                    }
                }
            }
        }
    }

    return Error;
}
Ejemplo n.º 2
0
Archivo: nltime.c Proyecto: Andais/dmz
NL_EXP NLboolean NL_APIENTRY nlTime(NLtime *t)
{
#ifdef WINDOWS_APP
    static NLboolean        needinit = NL_TRUE;
    static NLboolean        haspcounter = NL_FALSE;
    static LARGE_INTEGER    freq;
    static LARGE_INTEGER    lastcount;
    static NLtime           currenttime;

    if(t == NULL)
    {
		nlSetError(NL_NULL_POINTER);
		return NL_FALSE;
    }
    if(needinit == NL_TRUE)
    {
        if(QueryPerformanceFrequency(&freq) != 0)
        {
            if(QueryPerformanceCounter(&lastcount) != 0)
            {
                /* get the current time */
                struct mytimeb tb;

                myftime(&tb);
                currenttime.seconds = (NLlong)(tb.time);
                currenttime.useconds = (NLlong)(tb.millitm * 1000);
                haspcounter = NL_TRUE;
            }
        }
        needinit = NL_FALSE;
    }
    if(haspcounter == NL_TRUE)
    {
        LARGE_INTEGER   currentcount;
        LARGE_INTEGER   diffcount;

        (void)QueryPerformanceCounter(&currentcount);
        diffcount.QuadPart = currentcount.QuadPart - lastcount.QuadPart;
        lastcount.QuadPart = currentcount.QuadPart;
        while(diffcount.QuadPart >= freq.QuadPart)
        {
            diffcount.QuadPart -= freq.QuadPart;
            currenttime.seconds++;
        }
        currenttime.useconds += (NLlong)(diffcount.QuadPart * 1000000 / freq.QuadPart);
        if(currenttime.useconds >= 1000000)
        {
            currenttime.useconds -= 1000000;
            currenttime.seconds++;
        }
        t->seconds = currenttime.seconds;
        t->mseconds = currenttime.useconds / 1000;
        t->useconds = currenttime.useconds;
    }
    else
    {
        /* fall back to myftime */
        struct mytimeb tb;

        myftime(&tb);
        t->seconds = (NLlong)(tb.time);
        t->mseconds = (NLlong)(tb.millitm);
        t->useconds = (NLlong)(tb.millitm * 1000);
    }
#else /* !WINDOWS_APP */
    struct timeval tv;

    if(t == NULL)
    {
		nlSetError(NL_NULL_POINTER);
		return NL_FALSE;
    }
    gettimeofday(&tv, NULL);
    t->seconds = (NLlong)(tv.tv_sec);
    t->mseconds = (NLlong)(tv.tv_usec / 1000);
    t->useconds = (NLlong)(tv.tv_usec);
#endif /* !WINDOWS_APP */
    return NL_TRUE;
}