bool PvaClientMultiMonitorDouble::waitEvent(double waitForEvent)
{
    if(poll()) return true;
    TimeStamp start;
    start.getCurrent();
    TimeStamp now;
    while(true) {
          epicsThreadSleep(.1);
          if(poll()) return true;
          now.getCurrent();
          double diff = TimeStamp::diff(now,start);
          if(diff>=waitForEvent) break;
    }
    return false;
}
示例#2
0
文件: timer.cpp 项目: ukaea/epics
void Timer::schedulePeriodic(
    TimerCallbackPtr const &timerCallback,
    double delay,
    double period)
{
    if(isScheduled(timerCallback)) {
        throw std::logic_error(string("already queued"));
    }
    {
        Lock xx(mutex);
        if(!alive) {
            timerCallback->timerStopped();
            return;
        }
    }
    TimeStamp timeStamp;
    timeStamp.getCurrent();
    timeStamp += delay;
    timerCallback->timeToRun.getCurrent();
    timerCallback->timeToRun += delay;
    timerCallback->period = period;
    bool isFirst = false;
    {
        Lock xx(mutex);
        addElement(timerCallback);
        if(timerCallback.get()==head.get()) isFirst = true;
    }
    if(isFirst) waitForWork.signal();
}
void VectorPerformanceThread::run()
{
    TimeStamp timeStamp;
    TimeStamp timeStampLast;
    timeStampLast.getCurrent();
    int nSinceLastReport = 0;
    while(true) {
        if(delay>0.0) epicsThreadSleep(delay);
        {
            Lock lock(mutex);
            if(isDestroyed) {
                runReturned = true;
                return;
            }
        }
        timeStamp.getCurrent();
        double diff = TimeStamp::diff(timeStamp,timeStampLast);
        if(diff>=1.0) {
            cout << "thread" << threadNumber;
            cout << " value " << value;
            cout << " time " << diff;
            double iterations = nSinceLastReport;
            iterations /= diff;
            cout << " iterations/sec " << iterations;
            double elementSize = size;
            double elementsPerSecond = elementSize*nSinceLastReport;
            elementsPerSecond /= diff;
            elementsPerSecond /= 1e6;
            cout << " elements/sec " << elementsPerSecond << "million" << endl;
            cout.flush();
            timeStampLast = timeStamp;
            nSinceLastReport = 0;
        }
        ++nSinceLastReport;
        ++value;
        for(size_t i=0; i<size; ++i) vector[i] = value;
    }
}
示例#4
0
文件: timer.cpp 项目: ukaea/epics
void Timer::dump(std::ostream& o)
{
    Lock xx(mutex);
    if(!alive) return;
    TimeStamp currentTime;
    TimerCallbackPtr nodeToCall(head);
    currentTime.getCurrent();
    while(true) {
        if(nodeToCall.get()==NULL) return;
        TimeStamp timeToRun = nodeToCall->timeToRun;
        double period = nodeToCall->period;
        double diff = TimeStamp::diff(timeToRun,currentTime);
        o << "timeToRun " << diff << " period " << period << std::endl;
        nodeToCall = nodeToCall->next;
    }
}
示例#5
0
文件: timer.cpp 项目: ukaea/epics
void Timer::run()
{
    TimeStamp currentTime;
    while(true) {
        double period = 0.0;
        TimerCallbackPtr nodeToCall;
        {
            Lock xx(mutex);
            currentTime.getCurrent();
            if (!alive) break;
            TimerCallbackPtr timerCallback = head;
            if(timerCallback.get()!=NULL) {
                double diff = TimeStamp::diff(
                                  timerCallback->timeToRun,currentTime);
                if(diff<=0.0) {
                    nodeToCall = timerCallback;
                    nodeToCall->onList = false;
                    head = head->next;
                    period = timerCallback->period;
                    if(period>0.0) {
                        timerCallback->timeToRun += period;
                        addElement(timerCallback);
                    }
                    timerCallback = head;
                }
            }
        }
        if(nodeToCall.get()!=NULL) {
            nodeToCall->callback();
        }
        {
            Lock xx(mutex);
            if(!alive) break;
        }
        if(head.get()==NULL) {
            waitForWork.wait();
        } else {
            double delay = TimeStamp::diff(head->timeToRun,currentTime);
            waitForWork.wait(delay);
        }
    }
    waitForDone.signal();
}
示例#6
0
void NTNDArrayRecord::setDataTimeStamp()
{
    // Create PVTimeStamp and TimeStamp objects
    // attach the dataTimeStamp field to the PVTimeStamp
    // TimeStamp object should get the current time
    // Use it to set the dataTimeStamp field
#if 0
    PVTimeStamp timeStamp;
    timeStamp.attach(pvStructure->getSubField<PVStructure>("dataTimeStamp"));
    TimeStamp current;
    current.getCurrent();
    timeStamp.set(current);
#else
    // Alternatively you can use the member objects already created
    // for you and do the attaching once.
    dataTimeStamp.getCurrent();
    pvDataTimeStamp.set(dataTimeStamp);
#endif
}
示例#7
0
void test_ntscalar()
{
    testDiag("test_ntscalar");

    NTScalarBuilderPtr builder = NTScalar::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTScalarPtr ntScalar = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addDisplay()->
            addControl()->
            add("valueAlarm",standardField->intAlarm()) ->
            create();
    testOk1(ntScalar.get() != 0);

    testOk1(NTScalar::is_a(ntScalar->getPVStructure()));
    testOk1(NTScalar::isCompatible(ntScalar->getPVStructure()));

    testOk1(ntScalar->getPVStructure().get() != 0);
    testOk1(ntScalar->getValue().get() != 0);
    testOk1(ntScalar->getDescriptor().get() != 0);
    testOk1(ntScalar->getAlarm().get() != 0);
    testOk1(ntScalar->getTimeStamp().get() != 0);
    testOk1(ntScalar->getDisplay().get() != 0);
    testOk1(ntScalar->getControl().get() != 0);

    //
    // example how to set a value
    //
    ntScalar->getValue<PVInt>()->put(12);

    //
    // example how to get a value
    //
    int32 value = ntScalar->getValue<PVInt>()->get();
    testOk1(value == 12);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntScalar->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntScalar->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // display ops
    //
    PVDisplay pvDisplay;
    if (ntScalar->attachDisplay(pvDisplay))
    {
        testPass("display attach");

        // example how to set an display
        Display display;
        display.setLow(-15);
        display.setHigh(15);
        display.setDescription("This is a test scalar");
        display.setFormat("%d");
        display.setUnits("A");
        pvDisplay.set(display);
    }
    else
        testFail("display attach fail");

    //
    // control ops
    //
    PVControl pvControl;
    if (ntScalar->attachControl(pvControl))
    {
        testPass("control attach");

        // example how to set an control
        Control control;
        control.setLow(-10);
        control.setHigh(10);
        control.setMinStep(1);
        pvControl.set(control);
    }
    else
        testFail("control attach fail");

    //
    // set descriptor
    //
    ntScalar->getDescriptor()->put("This is a test NTScalar");

    // dump ntScalar
    std::cout << *ntScalar->getPVStructure() << std::endl;

}
示例#8
0
void test_ntenum()
{
    testDiag("test_ntenum");

    NTEnumBuilderPtr builder = NTEnum::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTEnumPtr ntEnum = builder->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("valueAlarm",standardField->intAlarm()) ->
            create();
    testOk1(ntEnum.get() != 0);

    testOk1(NTEnum::is_a(ntEnum->getPVStructure()));
    testOk1(NTEnum::isCompatible(ntEnum->getPVStructure()));

    testOk1(ntEnum->getPVStructure().get() != 0);
    testOk1(ntEnum->getValue().get() != 0);
    testOk1(ntEnum->getDescriptor().get() != 0);
    testOk1(ntEnum->getAlarm().get() != 0);
    testOk1(ntEnum->getTimeStamp().get() != 0);

    //
    // example how to set a value
    //
    PVStructurePtr pvValue = ntEnum->getValue();
    //PVStringArray pvChoices = pvValue->getSubField<PVStringArray>("choices");
    PVStringArray::svector choices(2);
    choices[0] = "Off";
    choices[1] = "On";
    pvValue->getSubField<PVStringArray>("choices")->replace(freeze(choices));
    pvValue->getSubField<PVInt>("index")->put(1);
    
    //
    // example how to get a value
    //
    int32 value = ntEnum->getValue()->getSubField<PVInt>("index")->get();
    testOk1(value == 1);

    PVStringArrayPtr pvChoices = ntEnum->getValue()->getSubField<PVStringArray>("choices");
    std::string choice0 = pvChoices->view()[0];
    std::string choice1 = pvChoices->view()[1];
    testOk1(choice0 == "Off");
    testOk1(choice1 == "On");

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntEnum->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntEnum->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntEnum->getDescriptor()->put("This is a test NTEnum");

    // dump ntEnum
    std::cout << *ntEnum->getPVStructure() << std::endl;

}
void test_ntcontinuum()
{
    testDiag("test_ntcontinuum");

    NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTContinuumPtr ntContinuum = builder->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("extra1",fieldCreate->createScalar(pvString)) ->
            add("extra2",fieldCreate->createScalarArray(pvString)) ->
            create();
    testOk1(ntContinuum.get() != 0);

    testOk1(ntContinuum->getPVStructure().get() != 0);
    testOk1(ntContinuum->getDescriptor().get() != 0);
    testOk1(ntContinuum->getAlarm().get() != 0);
    testOk1(ntContinuum->getTimeStamp().get() != 0);
    testOk1(ntContinuum->getBase().get() != 0);
    testOk1(ntContinuum->getValue().get() != 0);
    //
    // example how to set base
    //
    PVDoubleArray::svector newBase;
    newBase.push_back(1.0);
    newBase.push_back(2.0);

    PVDoubleArrayPtr pvBaseField = ntContinuum->getBase();
    pvBaseField->replace(freeze(newBase));

    //
    // example how to get bases
    //
    PVDoubleArray::const_svector base(pvBaseField->view());

    testOk1(base.size() == 2);
    testOk1(base[0] == 1.0);
    testOk1(base[1] == 2.0);

    //
    // example how to set values
    //
    PVDoubleArray::svector newValue;
    newValue.push_back(1.0);
    newValue.push_back(2.0);
    newValue.push_back(10.0);
    newValue.push_back(20.0);
    newValue.push_back(100.0);
    newValue.push_back(200.0);

    PVDoubleArrayPtr pvValueField = ntContinuum->getValue();
    pvValueField->replace(freeze(newValue));

    //
    // example how to get values
    //
    PVDoubleArray::const_svector value(pvValueField->view());

    testOk1(value.size() == 6);
    testOk1(value[0] == 1.0);
    testOk1(value[1] == 2.0);
    testOk1(value[2] == 10.0);
    testOk1(value[3] == 20.0);
    testOk1(value[4] == 100.0);
    testOk1(value[5] == 200.0);

    //
    // example how to set units
    //
    PVStringArray::svector newUnits;
    newUnits.push_back("s");
    newUnits.push_back("ms");
    newUnits.push_back("us");
    newUnits.push_back("s");

    PVStringArrayPtr pvUnitsField = ntContinuum->getUnits();
    pvUnitsField->replace(freeze(newUnits));

    //
    // example how to get units
    //
    PVStringArray::const_svector units(pvUnitsField->view());

    testOk1(units.size() == 4);
    testOk1(units[0] == "s");
    testOk1(units[1] == "ms");
    testOk1(units[2] == "us");
    testOk1(units[3] == "s");

    //
    // test isValid
    //
    testOk1(ntContinuum->isValid());
    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntContinuum->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntContinuum->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntContinuum->getDescriptor()->put("This is a test NTContinuum");

    // dump NTContinuum
    std::cout << *ntContinuum->getPVStructure() << std::endl;

}
void test_nthistogram()
{
    testDiag("test_nthistogram");

    NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTHistogramPtr ntHistogram = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("extra1",fieldCreate->createScalar(pvString)) ->
            add("extra2",fieldCreate->createScalarArray(pvString)) ->
            create();
    testOk1(ntHistogram.get() != 0);

    testOk1(ntHistogram->getPVStructure().get() != 0);
    testOk1(ntHistogram->getDescriptor().get() != 0);
    testOk1(ntHistogram->getAlarm().get() != 0);
    testOk1(ntHistogram->getTimeStamp().get() != 0);
    testOk1(ntHistogram->getRanges().get() != 0);
    testOk1(ntHistogram->getValue().get() != 0);
    testOk1(ntHistogram->getValue<PVIntArray>().get() != 0);
    //
    // example how to set ranges
    //
    PVDoubleArray::svector newRanges;
    newRanges.push_back(-100.0);
    newRanges.push_back(0.0);
    newRanges.push_back(100.0);

    PVDoubleArrayPtr pvRangesField = ntHistogram->getRanges();
    pvRangesField->replace(freeze(newRanges));

    //
    // example how to get ranges
    //
    PVDoubleArray::const_svector ranges(pvRangesField->view());

    testOk1(ranges.size() == 3);
    testOk1(ranges[0] == -100.0);
    testOk1(ranges[1] == 0.0);
    testOk1(ranges[2] == 100.0);

    //
    // example how to set value
    //
    PVIntArray::svector newValue;
    newValue.push_back(1);
    newValue.push_back(2);

    PVIntArrayPtr pvValueField = ntHistogram->getValue<PVIntArray>();
    pvValueField->replace(freeze(newValue));

    //
    // example how to get values for each bin
    //
    PVIntArray::const_svector value(pvValueField->view());

    testOk1(value.size() == 2);
    testOk1(value[0] == 1);
    testOk1(value[1] == 2);

    //
    // test isValid
    //
    testOk1(ntHistogram->isValid());
    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntHistogram->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntHistogram->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntHistogram->getDescriptor()->put("This is a test NTHistogram");

    // dump NTHistogram
    std::cout << *ntHistogram->getPVStructure() << std::endl;

}
示例#11
0
void ExampleServiceRPC::request(
    ChannelRPCRequester::shared_pointer const & channelRPCRequester,
    epics::pvData::PVStructure::shared_pointer const & pvArgument)
{
    String buffer;
    PVStringPtr pvfunction = pvArgument->getStringField("function");
    PVStringArrayPtr pvnames = static_pointer_cast<PVStringArray>
        (pvArgument->getScalarArrayField("names",pvString));
    PVStringArrayPtr pvvalues = static_pointer_cast<PVStringArray>
        (pvArgument->getScalarArrayField("values",pvString));
    buffer += "pvArgument ";
    bool is = true;
    if(pvfunction==0) is = false;
    if(pvnames==0) is = false;
    if(pvvalues==0) is = false;
    if(is) {
        buffer += "is a NTNameValue\n";
    } else {
        buffer += "is not a NTNameValue\n ";
    }
    pvArgument->toString(&buffer);
    printf("%s\n",buffer.c_str());
    StandardFieldPtr standardField = getStandardField();
    StandardPVFieldPtr standardPVField = getStandardPVField();
    FieldCreatePtr  fieldCreate = getFieldCreate();
    PVDataCreatePtr  pvDataCreate = getPVDataCreate();
    size_t n = 5;
    FieldConstPtrArray fields;
    StringArray names;
    fields.reserve(n);
    names.reserve(n);
    names.push_back("alarm");
    names.push_back("timeStamp");
    names.push_back("label");
    names.push_back("position");
    names.push_back("alarms");
StructureConstPtr xxx = standardField->alarm();
printf("xxx %p\n",xxx.get());
    fields.push_back(standardField->alarm());
    fields.push_back(standardField->timeStamp());
    fields.push_back(fieldCreate->createScalarArray(pvString));
    fields.push_back(fieldCreate->createScalarArray(pvDouble));
    fields.push_back(fieldCreate->createStructureArray(standardField->alarm()));
    StructureConstPtr structure = fieldCreate->createStructure(names,fields);
printf("structure %p\n",structure.get());
buffer.clear();
structure->toString(&buffer);
printf("structure\n%s\n",buffer.c_str());
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(structure);
    PVTimeStamp pvTimeStamp;
    TimeStamp timeStamp;
    pvTimeStamp.attach(pvStructure->getStructureField("timeStamp"));
    timeStamp.getCurrent();
    pvTimeStamp.set(timeStamp);
    StringArray label;
    label.reserve(2);
    for(int i=0; i<2; i++) {
        label.push_back(names[i+3]);
    }
    PVStringArrayPtr pvLabel = static_pointer_cast<PVStringArray>
        (pvStructure->getScalarArrayField("label",pvString));
    pvLabel->put(0,2,label,0);
    PVDoubleArrayPtr pvPositions = static_pointer_cast<PVDoubleArray>
        (pvStructure->getScalarArrayField("position",pvDouble));
    double positions[2];
    positions[0] = 1.0;
    positions[1] = 2.0;
    pvPositions->put(0,2,positions,0);
    PVStructureArrayPtr pvAlarms = static_pointer_cast<PVStructureArray>
        (pvStructure->getStructureArrayField("alarms"));
    PVAlarm pvAlarm;
    Alarm alarm;
    PVStructurePtrArray palarms;
    size_t na=2;
    palarms.reserve(na);
    for(size_t i=0; i<na; i++) {
        palarms.push_back(pvDataCreate->createPVStructure(standardField->alarm()));
    }
    for(size_t i=0; i<na; i++) {
        pvAlarm.attach(palarms[i]);
        alarm.setMessage("test");
        alarm.setSeverity(majorAlarm);
        alarm.setStatus(clientStatus);
        pvAlarm.set(alarm);
    }
    pvAlarms->put(0,2,palarms,0);
    String labels[2];
    labels[0] = pvPositions->getFieldName();
    labels[1] = pvAlarms->getFieldName();
    pvLabel->put(0,2,labels,0);
    buffer.erase();
    pvStructure->toString(&buffer);
    printf("%s\n",buffer.c_str());
    channelRPCRequester->requestDone(Status::Ok,pvStructure);
}
示例#12
0
void testTimeStamp(FILE *fd,FILE *auxfd)
{
    assert(nanoSecPerSec==1000000000);
    TimeStamp current;
    current.getCurrent();
    fprintf(auxfd,"current %lli %i milliSec %lli\n",
        (long long)current.getSecondsPastEpoch(),
        current.getNanoSeconds(),
        (long long)current.getMilliseconds());
    time_t tt;
    current.toTime_t(tt);
    struct tm ctm;
    memcpy(&ctm,localtime(&tt),sizeof(struct tm));
    fprintf(auxfd,
        "%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d isDst %s\n",
        ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
        ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
        current.getNanoSeconds(),
        (ctm.tm_isdst==0) ? "false" : "true");
    tt = time(&tt);
    current.fromTime_t(tt);
    fprintf(auxfd,"fromTime_t\ncurrent %lli %i milliSec %lli\n",
        (long long)current.getSecondsPastEpoch(),
        current.getNanoSeconds(),
        (long long)current.getMilliseconds());
    current.toTime_t(tt);
    memcpy(&ctm,localtime(&tt),sizeof(struct tm));
    fprintf(auxfd,
        "%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d isDst %s\n",
        ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
        ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
        current.getNanoSeconds(),
        (ctm.tm_isdst==0) ? "false" : "true");
    TimeStamp right;
    TimeStamp left;
    right.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
    left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
    double diff;
    diff = TimeStamp::diff(left,right);
    if(debug) fprintf(fd,"diff %e\n",diff);
    assert(diff==0.0);
    assert((left==right));
    assert(!(left!=right));
    assert((left<=right));
    assert(!(left<right));
    assert((left>=right));
    assert(!(left>right));
    left.put(current.getSecondsPastEpoch()+1,current.getNanoSeconds());
    diff = TimeStamp::diff(left,right);
    if(debug) fprintf(fd,"diff %e\n",diff);
    assert(diff==1.0);
    assert(!(left==right));
    assert((left!=right));
    assert(!(left<=right));
    assert(!(left<right));
    assert((left>=right));
    assert((left>right));
    left.put(current.getSecondsPastEpoch()-1,current.getNanoSeconds());
    diff = TimeStamp::diff(left,right);
    if(debug) fprintf(fd,"diff %e\n",diff);
    assert(diff==-1.0);
    assert(!(left==right));
    assert((left!=right));
    assert((left<=right));
    assert((left<right));
    assert(!(left>=right));
    assert(!(left>right));
    left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-nanoSecPerSec);
    diff = TimeStamp::diff(left,right);
    if(debug) fprintf(fd,"diff %e\n",diff);
    assert(diff==-1.0);
    assert(!(left==right));
    assert((left!=right));
    assert((left<=right));
    assert((left<right));
    assert(!(left>=right));
    assert(!(left>right));
    left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-1);
    diff = TimeStamp::diff(left,right);
    if(debug) fprintf(fd,"diff %e\n",diff);
    assert(diff<0.0);
    assert(!(left==right));
    assert((left!=right));
    assert((left<=right));
    assert((left<right));
    assert(!(left>=right));
    assert(!(left>right));
    left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
    left += .1;
    diff = TimeStamp::diff(left,right);
    if(debug) fprintf(fd,"diff %e\n",diff);
    left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
    int64 inc = -1;
    left += inc;
    diff = TimeStamp::diff(left,right);
    assert(diff==-1.0);
    fprintf(fd,"PASSED\n");
}
void test_nttable()
{
    testDiag("test_nttable");

    NTTableBuilderPtr builder = NTTable::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTTablePtr ntTable = builder->
            addColumn("column0", pvDouble)->
            addColumn("column1", pvString)->
            addColumn("column2", pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            create();
    testOk1(ntTable.get() != 0);

    testOk1(ntTable->getPVStructure().get() != 0);
    testOk1(ntTable->getDescriptor().get() != 0);
    testOk1(ntTable->getAlarm().get() != 0);
    testOk1(ntTable->getTimeStamp().get() != 0);
    testOk1(ntTable->getLabels().get() != 0);

    testOk1(ntTable->getColumn<PVDoubleArray>("column0").get() != 0);
    testOk1(ntTable->getColumn<PVStringArray>("column1").get() != 0);
    testOk1(ntTable->getColumn<PVIntArray>("column2").get() != 0);

    testOk1(ntTable->getColumn("invalid").get() == 0);

    //
    // example how to set column values
    //
    PVIntArray::svector newValues;
    newValues.push_back(1);
    newValues.push_back(2);
    newValues.push_back(8);

    PVIntArrayPtr intColumn = ntTable->getColumn<PVIntArray>("column2");
    intColumn->replace(freeze(newValues));

    //
    // example how to get column values
    //
    PVIntArray::const_svector values(intColumn->view());

    testOk1(values.size() == 3);
    testOk1(values[0] == 1);
    testOk1(values[1] == 2);
    testOk1(values[2] == 8);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntTable->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntTable->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntTable->getDescriptor()->put("This is a test NTTable");

    // dump NTTable
    std::cout << *ntTable->getPVStructure() << std::endl;

}
示例#14
0
static void testCopy()
{
    TEST_COPY(PVBoolean, 1);
    TEST_COPY(PVByte, 12);
    TEST_COPY(PVShort, 128);
    TEST_COPY(PVInt, 128000);
    TEST_COPY(PVLong, 128000000);
    TEST_COPY(PVUByte, 12);
    TEST_COPY(PVUShort, 128);
    TEST_COPY(PVUInt, 128000);
    TEST_COPY(PVULong, 128000000);
    TEST_COPY(PVFloat, 12.8);
    TEST_COPY(PVDouble, 8.12);
    TEST_COPY(PVString, "jikes");

    int32 testValue = 128;

    // PVStructure test
    PVStructurePtr pvStructure =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructure->getSubField<PVInt>("value")->put(testValue);

    PVTimeStamp timeStamp;
    timeStamp.attach(pvStructure->getSubField<PVStructure>("timeStamp"));
    TimeStamp current;
    current.getCurrent();
    timeStamp.set(current);

    PVStructurePtr pvStructureCopy =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy->copy(*pvStructure);
    testOk(*pvStructure == *pvStructureCopy, "PVStructure copy");


    PVStructurePtr pvStructureCopy2 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy2->copyUnchecked(*pvStructure);
    testOk(*pvStructure == *pvStructureCopy2, "PVStructure copyUnchecked");

    BitSet mask(pvStructure->getNumberFields());
    PVStructurePtr pvStructureCopy3 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    PVStructurePtr pvStructureCopy4 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy3->copyUnchecked(*pvStructure, mask);
    testOk(*pvStructureCopy3 == *pvStructureCopy4, "PVStructure copyUnchecked w/ cleared mask");

    mask.set(pvStructure->getSubField<PVInt>("value")->getFieldOffset());
    pvStructureCopy3->copyUnchecked(*pvStructure, mask);
    pvStructureCopy4->getSubField<PVInt>("value")->put(testValue);
    testOk(*pvStructureCopy3 == *pvStructureCopy4, "PVStructure copyUnchecked w/ value mask only");

    mask.set(pvStructure->getSubField<PVStructure>("timeStamp")->getFieldOffset());
    PVStructurePtr pvStructureCopy5 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy5->copyUnchecked(*pvStructure, mask);
    testOk(*pvStructure == *pvStructureCopy5, "PVStructure copyUnchecked w/ value+timeStamp mask");


    UnionConstPtr _union = fieldCreate->createFieldBuilder()->
        add("doubleValue", pvDouble)->
        add("intValue", pvInt)->
        add("timeStamp",standardField->timeStamp())->
        createUnion();

    PVUnionPtr pvUnion = pvDataCreate->createPVUnion(_union);
    PVUnionPtr pvUnion2 = pvDataCreate->createPVUnion(_union);
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "null PVUnion copy");

    pvUnion->select<PVInt>("intValue")->put(123);
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "PVUnion scalar copy, to null PVUnion");

    pvUnion->select("doubleValue");
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "PVUnion scalar copy, to different type PVUnion");

    pvUnion->select<PVStructure>("timeStamp")->copy(
        *pvStructure->getSubField<PVStructure>("timeStamp")
    );
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "PVUnion PVStructure copy, to different type PVUnion");
}
示例#15
0
void test_ntnameValue()
{
    testDiag("test_ntnameValue");

    NTNameValueBuilderPtr builder = NTNameValue::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTNameValuePtr ntNameValue = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("extra1",fieldCreate->createScalar(pvString)) ->
            add("extra2",fieldCreate->createScalarArray(pvString)) ->
            create();
    testOk1(ntNameValue.get() != 0);

    testOk1(NTNameValue::is_a(ntNameValue->getPVStructure()));
    testOk1(NTNameValue::isCompatible(ntNameValue->getPVStructure()));

    testOk1(ntNameValue->getPVStructure().get() != 0);
    testOk1(ntNameValue->getDescriptor().get() != 0);
    testOk1(ntNameValue->getAlarm().get() != 0);
    testOk1(ntNameValue->getTimeStamp().get() != 0);
    testOk1(ntNameValue->getName().get() != 0);
    testOk1(ntNameValue->getValue().get() != 0);

    //
    // example how to set name
    //
    PVStringArray::svector newName;
    newName.push_back("name1");
    newName.push_back("name2");
    newName.push_back("name3");

    PVStringArrayPtr pvNameField = ntNameValue->getName();
    pvNameField->replace(freeze(newName));

    //
    // example how to get name
    //
    PVStringArray::const_svector name(pvNameField->view());

    testOk1(name.size() == 3);
    testOk1(name[0] == "name1");
    testOk1(name[1] == "name2");
    testOk1(name[2] == "name3");

    //
    // example how to set value
    //
    PVIntArray::svector newValue;
    newValue.push_back(1);
    newValue.push_back(2);
    newValue.push_back(8);

    PVIntArrayPtr pvValueField = ntNameValue->getValue<PVIntArray>();
    pvValueField->replace(freeze(newValue));

    //
    // example how to get column value
    //
    PVIntArray::const_svector value(pvValueField->view());

    testOk1(value.size() == 3);
    testOk1(value[0] == 1);
    testOk1(value[1] == 2);
    testOk1(value[2] == 8);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntNameValue->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntNameValue->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntNameValue->getDescriptor()->put("This is a test NTNameValue");

    // dump NTNameValue
    std::cout << *ntNameValue->getPVStructure() << std::endl;

}
示例#16
0
void ArrayPerformance::run()
{
    PVStructurePtr pvStructure = PVRecord::getPVRecordStructure()->getPVStructure();
    PVLongArrayPtr pvValue= pvStructure->getSubField<PVLongArray>("value");
    TimeStamp timeStamp;
    TimeStamp timeStampLast;
    timeStampLast.getCurrent();
    int nSinceLastReport = 0;
    int64 value = 0;
    while(true) {
        if(runStop.tryWait()) {
             runReturn.signal();
             return;
        }    
        if(delay>0.0) epicsThreadSleep(delay);
        timeStamp.getCurrent();
        double diff = TimeStamp::diff(timeStamp,timeStampLast);
        if(diff>=1.0) {
            ostringstream out;
            out << "arrayPerformance value " << value;
            out << " time " << diff ;
            double iterations = nSinceLastReport;
            iterations /= diff;
            if(iterations>10.0e9) {
                 iterations /= 1e9;
                 out << " gigaIterations/sec " << iterations;
            } else if(iterations>10.0e6) {
                 iterations /= 1e6;
                 out << " megaIterations/sec " << iterations;
            } else if(iterations>10.0e3) {
                 iterations /= 1e3;
                 out << " kiloIterations/sec " << iterations;
            } else  {
                 out << " Iterations/sec " << iterations;
            }
            double elementSize = size;
            double elementsPerSecond = elementSize*nSinceLastReport;
            elementsPerSecond /= diff;
            if(elementsPerSecond>10.0e9) {
                 elementsPerSecond /= 1e9;
                 out << " gigaElements/sec " << elementsPerSecond;
            } else if(elementsPerSecond>10.0e6) {
                 elementsPerSecond /= 1e6;
                 out << " megaElements/sec " << elementsPerSecond;
            } else if(elementsPerSecond>10.0e3) {
                 elementsPerSecond /= 1e3;
                 out << " kiloElements/sec " << elementsPerSecond;
            } else  {
                 out << " Elements/sec " << elementsPerSecond;
            }
            cout << out.str() << endl;
            timeStampLast = timeStamp;
            nSinceLastReport = 0;
        }
        ++nSinceLastReport;
        lock();
        try {
            if(getTraceLevel()>1) {
                 cout << "arrayPerformance size " << size;
                 cout << " value " << value +1 << endl;
            }
            shared_vector<int64> xxx(size,value++);
            shared_vector<const int64> data(freeze(xxx));
            beginGroupPut();
            pvValue->replace(data);
            process();
            endGroupPut();
        } catch(...) {
           unlock();
           throw;
        }
        unlock();
    }
}
void test_ntndarrayAttribute()
{
    testDiag("test_ntndarrayAttribute");

    NTNDArrayAttributeBuilderPtr builder = NTNDArrayAttribute::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTNDArrayAttributePtr ntNDArrayAttribute = builder->
            addTags()->
            addAlarm()->
            addTimeStamp()->
            create();
    testOk1(ntNDArrayAttribute.get() != 0);

    testOk1(ntNDArrayAttribute->getPVStructure().get() != 0);
    testOk1(ntNDArrayAttribute->getName().get() != 0);
    testOk1(ntNDArrayAttribute->getValue().get() != 0);
    testOk1(ntNDArrayAttribute->getTags().get() != 0);
    testOk1(ntNDArrayAttribute->getDescriptor().get() != 0);
    testOk1(ntNDArrayAttribute->getAlarm().get() != 0);
    testOk1(ntNDArrayAttribute->getTimeStamp().get() != 0);
    testOk1(ntNDArrayAttribute->getSourceType().get() != 0);
    testOk1(ntNDArrayAttribute->getSource().get() != 0);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntNDArrayAttribute->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntNDArrayAttribute->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntNDArrayAttribute->getDescriptor()->put("This is a test NTNDArrayAttribute");

    // dump ntNDArrayAttribute
    std::cout << *ntNDArrayAttribute->getPVStructure() << std::endl;

}
示例#18
0
void LongArrayMonitor::run()
{
    PvaClientPtr pva(PvaClient::get("pva"));
    string  request("record[queueSize=");
    char buff[20];
    sprintf(buff,"%d",queueSize);
    request += buff;
    request += "]field(value,timeStamp,alarm)";
    PvaClientMonitorPtr monitor = pva->channel(channelName,providerName,2.0)->monitor(request);
    TimeStamp timeStamp;
    TimeStamp timeStampLast;
    timeStampLast.getCurrent();
    long nElements = 0;
    long nSinceLastReport = 0;
    int64 first = 0;
    int64 last = 0;
    while(true) {   
        if(runStop.tryWait()) {
             runReturn.signal();
             return;
        }    
        if(!monitor->waitEvent(0.0)) {
	    cout << "waitEvent returned false. Why???" << endl;
            continue;
        }
        PvaClientMonitorDataPtr pvaData = monitor->getData();
    	PVStructurePtr pvStructure = pvaData->getPVStructure();
    	PVLongArrayPtr pvValue = pvStructure->getSubField<PVLongArray>("value");
        size_t len = pvValue->getLength();
        if(len>0) {
            shared_vector<const int64> data = pvValue->view();
            first = data[0];
            last = data[len-1];
            if(first!=last) cout << "error first=" << first << " last=" << last << endl;
       } else {
            cout << "len is 0" << endl;
       }
       nElements += len;
       timeStamp.getCurrent();
       double diff = TimeStamp::diff(timeStamp,timeStampLast);
       if(diff>=1.0) {
            ostringstream out;
            out << " monitors/sec " << nSinceLastReport << " ";
            if(len>0) out << "first " << first << " last " << last ;
            out << " changed " << *pvaData->getChangedBitSet();
            out << " overrun " << *pvaData->getOverrunBitSet();
            double elementsPerSec = nElements;
            elementsPerSec /= diff;
            if(elementsPerSec>10.0e9) {
                 elementsPerSec /= 1e9;
                 out << " gigaElements/sec " << elementsPerSec;
            } else if(elementsPerSec>10.0e6) {
                 elementsPerSec /= 1e6;
                 out << " megaElements/sec " << elementsPerSec;
            } else if(elementsPerSec>10.0e3) {
                 elementsPerSec /= 1e3;
                 out << " kiloElements/sec " << elementsPerSec;
            } else  {
                 out << " Elements/sec " << elementsPerSec;
            }
            cout << out.str() << endl;
            timeStampLast = timeStamp;
            nSinceLastReport = 0;
            nElements = 0;
        }
        ++nSinceLastReport;
        monitor->releaseEvent();
    }
}
void test_ntscalarArray()
{
    testDiag("test_ntscalarArray");

    NTScalarArrayBuilderPtr builder = NTScalarArray::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTScalarArrayPtr ntScalarArray = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addDisplay()->
            addControl()->
            create();
    testOk1(ntScalarArray.get() != 0);

    testOk1(ntScalarArray->getPVStructure().get() != 0);
    testOk1(ntScalarArray->getValue().get() != 0);
    testOk1(ntScalarArray->getDescriptor().get() != 0);
    testOk1(ntScalarArray->getAlarm().get() != 0);
    testOk1(ntScalarArray->getTimeStamp().get() != 0);
    testOk1(ntScalarArray->getDisplay().get() != 0);
    testOk1(ntScalarArray->getControl().get() != 0);

    //
    // example how to set values
    //
    PVIntArray::svector newValues;
    newValues.push_back(1);
    newValues.push_back(2);
    newValues.push_back(8);

    PVIntArrayPtr pvValueField = ntScalarArray->getValue<PVIntArray>();
    pvValueField->replace(freeze(newValues));

    //
    // example how to get values
    //
    PVIntArray::const_svector values(pvValueField->view());

    testOk1(values.size() == 3);
    testOk1(values[0] == 1);
    testOk1(values[1] == 2);
    testOk1(values[2] == 8);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntScalarArray->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntScalarArray->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // display ops
    //
    PVDisplay pvDisplay;
    if (ntScalarArray->attachDisplay(pvDisplay))
    {
        testPass("display attach");

        // example how to set an display
        Display display;
        display.setLow(-15);
        display.setHigh(15);
        display.setDescription("This is a test scalar array");
        display.setFormat("%d");
        display.setUnits("A");
        pvDisplay.set(display);
    }
    else
        testFail("display attach fail");

    //
    // control ops
    //
    PVControl pvControl;
    if (ntScalarArray->attachControl(pvControl))
    {
        testPass("control attach");

        // example how to set an control
        Control control;
        control.setLow(-10);
        control.setHigh(10);
        control.setMinStep(1);
        pvControl.set(control);
    }
    else
        testFail("control attach fail");

    //
    // set descriptor
    //
    ntScalarArray->getDescriptor()->put("This is a test NTScalarArray");

    // dump ntScalarArray
    std::cout << *ntScalarArray->getPVStructure() << std::endl;

}
void test_ntunion()
{
    testDiag("test_ntunion");

    NTUnionBuilderPtr builder = NTUnion::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTUnionPtr ntUnion = builder->
                         addDescriptor()->
                         addAlarm()->
                         addTimeStamp()->
                         create();
    testOk1(ntUnion.get() != 0);

    testOk1(ntUnion->getPVStructure().get() != 0);
    testOk1(ntUnion->getValue().get() != 0);
    testOk1(ntUnion->getDescriptor().get() != 0);
    testOk1(ntUnion->getAlarm().get() != 0);
    testOk1(ntUnion->getTimeStamp().get() != 0);

    // TODO
    // 1. Variant union example.
    // 2. set the union value.

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntUnion->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntUnion->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntUnion->getDescriptor()->put("This is a test NTUnion");

    // dump ntUnion
    std::cout << *ntUnion->getPVStructure() << std::endl;

}