コード例 #1
0
static void createDumbPowerSupplyRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
     StructureConstPtr top = fieldCreate->createFieldBuilder()->
         add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
コード例 #2
0
PowerSupplyRecordPtr PowerSupplyRecord::create(
    string const & recordName)
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    StandardFieldPtr standardField = getStandardField();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               endNested()->
            createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
    PowerSupplyRecordPtr pvRecord(
        new PowerSupplyRecord(recordName,pvStructure));
    if(!pvRecord->init()) pvRecord.reset();
    return pvRecord;
}
コード例 #3
0
StandardFieldPtr StandardField::getStandardField()
{
    static StandardFieldPtr standardFieldCreate;
    static Mutex mutex;
    Lock xx(mutex);

    if(standardFieldCreate.get()==0)
    {
        standardFieldCreate = StandardFieldPtr(new StandardField());
        standardFieldCreate->init();
    }
    return standardFieldCreate;
}
コード例 #4
0
ファイル: ntenumTest.cpp プロジェクト: epicsdeb/epics-nt
void test_builder()
{
    testDiag("test_builder");

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

    StructureConstPtr structure = builder->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("valueAlarm",standardField->doubleAlarm()) ->
            add("extra",fieldCreate->createScalarArray(pvString)) ->
            createStructure();
    testOk1(structure.get() != 0);
    if (!structure)
        return;

    testOk1(NTEnum::is_a(structure));
    testOk1(structure->getID() == NTEnum::URI);
    testOk1(structure->getNumberFields() == 6);
    testOk1(structure->getField("value").get() != 0);
    testOk1(structure->getField("descriptor").get() != 0);
    testOk1(structure->getField("alarm").get() != 0);
    testOk1(structure->getField("timeStamp").get() != 0);

    FieldConstPtr valueField = structure->getField("value");
    testOk(valueField.get() != 0 &&
           ntField->isEnumerated(valueField), "value is enum");

    std::cout << *structure << std::endl;

}
コード例 #5
0
static void testPostPut()
{
    testDiag("== testPostPut ==");
    StructureConstPtr structure =
       fieldCreate->createFieldBuilder()->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure();

    PvaClientPutDataPtr pvaData = PvaClientPutData::create(structure);
    PVStructurePtr pvStructure = pvaData->getPVStructure();

    BitSetPtr change = pvaData->getChangedBitSet();
    PVDoublePtr powerValue = pvStructure->getSubField<PVDouble>("power.value");
    PVDoublePtr voltageValue = pvStructure->getSubField<PVDouble>("voltage.value");
    PVDoublePtr currentValue = pvStructure->getSubField<PVDouble>("current.value");
    size_t powerOffset = powerValue->getFieldOffset();
    size_t voltageOffset = voltageValue->getFieldOffset();
    size_t currentOffset = currentValue->getFieldOffset();

    change->clear();
    powerValue->put(1.0);
    voltageValue->put(2.0);
    currentValue->put(.5);

    testOk(change->cardinality()==3,"3 fields changed");
    testOk(change->get(powerOffset),"power changed");
    testOk(change->get(voltageOffset),"voltage changed");
    testOk(change->get(currentOffset),"current changed");
}
コード例 #6
0
ファイル: caChannel.cpp プロジェクト: ralphlange/pvAccessCPP
static Structure::const_shared_pointer createStructure(CAChannel::shared_pointer const & channel, string const & properties)
{
    StandardFieldPtr standardField = getStandardField();
    Structure::const_shared_pointer structure;

    chtype channelType = channel->getNativeType();
    if (channelType != DBR_ENUM)
    {
        ScalarType st = dbr2ST[channelType];
        structure = (channel->getElementCount() > 1) ?
                     standardField->scalarArray(st, properties) :
                     standardField->scalar(st, properties);
    }
    else
    {
        // NOTE: enum arrays not supported
        structure = standardField->enumerated(properties);
    }

    return structure;
}
コード例 #7
0
ファイル: testPVCopy.cpp プロジェクト: anjohnson/pvDataCPP
static PVStructurePtr createPowerSupply()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    StandardFieldPtr standardField = getStandardField();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    size_t nfields = 5;
    StringArray names;
    names.reserve(nfields);
    FieldConstPtrArray powerSupply;
    powerSupply.reserve(nfields);
    names.push_back("alarm");
    powerSupply.push_back(standardField->alarm());
    names.push_back("timeStamp");
    powerSupply.push_back(standardField->timeStamp());
    string properties("alarm,display");
    names.push_back("voltage");
    powerSupply.push_back(standardField->scalar(pvDouble,properties));
    names.push_back("power");
    powerSupply.push_back(standardField->scalar(pvDouble,properties));
    names.push_back("current");
    powerSupply.push_back(standardField->scalar(pvDouble,properties));
    return pvDataCreate->createPVStructure(
            fieldCreate->createStructure(names,powerSupply));
}
コード例 #8
0
ExampleHelloPtr ExampleHello::create(
    string const & recordName)
{
    StandardFieldPtr standardField = getStandardField();
    FieldCreatePtr fieldCreate = getFieldCreate();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
        addNestedStructure("argument")->
            add("value",pvString)->
            endNested()->
        addNestedStructure("result") ->
            add("value",pvString) ->
            add("timeStamp",standardField->timeStamp()) ->
            endNested()->
        createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);

    ExampleHelloPtr pvRecord(
        new ExampleHello(recordName,pvStructure));
    if(!pvRecord->init()) pvRecord.reset();
    return pvRecord;
}
コード例 #9
0
ファイル: ntscalarTest.cpp プロジェクト: epicsdeb/epics-nt
void test_builder()
{
    testDiag("test_builder");

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

    StructureConstPtr structure = builder->
            value(pvDouble)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addDisplay()->
            addControl()->
            add("valueAlarm",standardField->doubleAlarm()) ->
            add("extra",fieldCreate->createScalarArray(pvString)) ->
            createStructure();
    testOk1(structure.get() != 0);
    if (!structure)
        return;

    testOk1(NTScalar::is_a(structure));
    testOk1(structure->getID() == NTScalar::URI);
    testOk1(structure->getNumberFields() == 8);
    testOk1(structure->getField("value").get() != 0);
    testOk1(structure->getField("descriptor").get() != 0);
    testOk1(structure->getField("alarm").get() != 0);
    testOk1(structure->getField("timeStamp").get() != 0);
    testOk1(structure->getField("display").get() != 0);
    testOk1(structure->getField("control").get() != 0);

    testOk(dynamic_pointer_cast<const Scalar>(structure->getField("value")).get() != 0 &&
            dynamic_pointer_cast<const Scalar>(structure->getField("value"))->getScalarType() == pvDouble, "value type");

    std::cout << *structure << std::endl;

    // no value set
    try
    {
        structure = builder->
                addDescriptor()->
                addAlarm()->
                addTimeStamp()->
                addDisplay()->
                addControl()->
                createStructure();
        testFail("no value type set");
    } catch (std::runtime_error &) {
        testPass("no value type set");
    }
}
コード例 #10
0
ファイル: dbPv.cpp プロジェクト: dhickin/pvaSrv
void DbPv::init()
{
    // this requires valid existance of dbPv::shared_pointer instance
    StandardFieldPtr standardField = getStandardField();
    ScalarType scalarType = pvBoolean;
    switch(dbChannelFinalFieldType(dbChan)) {
        case DBF_CHAR:
            scalarType = pvByte; break;
        case DBF_UCHAR:
            scalarType = pvUByte; break;
        case DBF_SHORT:
            scalarType = pvShort; break;
        case DBF_USHORT:
            scalarType = pvUShort; break;
        case DBF_LONG:
            scalarType = pvInt; break;
        case DBF_ULONG:
            scalarType = pvUInt; break;
        case DBF_FLOAT:
            scalarType = pvFloat; break;
        case DBF_DOUBLE:
            scalarType = pvDouble; break;
        case DBF_STRING:
            scalarType = pvString; break;

        case DBF_ENUM:
        case DBF_MENU:
        case DBF_DEVICE:
            recordField = standardField->enumerated("value,timeStamp,alarm");
            return;
        case DBF_INLINK:
        case DBF_OUTLINK:
        case DBF_FWDLINK:
            scalarType = pvString; break;
        default:
          break;
    }
    bool isArray = (dbChannelFinalElements(dbChan) > 1) ? true : false;
    if(scalarType==pvString) {  
        if(isArray) {
            recordField = standardField->scalarArray(scalarType,
                "value,timeStamp,alarm");
        } else {
            recordField = standardField->scalar(scalarType,
                "value,timeStamp,alarm");
        }
    }
    else if(scalarType!=pvBoolean) {
        if(isArray) {
            recordField = standardField->scalarArray(scalarType,
                "value,timeStamp,alarm,display");
        } else {
            recordField = standardField->scalar(scalarType,
                "value,timeStamp,alarm,display,control,valueAlarm");
        }
    }
}
コード例 #11
0
void testPVNTField()
{
    testDiag("testPVNTField");

    StringArray choices;
    choices.resize(3);
    choices[0] = "one";
    choices[1] = "two";
    choices[2] = "three";
    PVStructurePtr pvStructure = PVStructurePtr(
        pvntField->createEnumerated(choices));
    cout << *pvStructure << endl;
    testOk1(ntField->isEnumerated(pvStructure->getStructure()));

    pvStructure = PVStructurePtr(pvntField->createTimeStamp());
    cout << *pvStructure << endl;
    testOk1(ntField->isTimeStamp(pvStructure->getStructure()));

    pvStructure = PVStructurePtr(pvntField->createAlarm());
    cout << *pvStructure << endl;
    testOk1(ntField->isAlarm(pvStructure->getStructure()));

    pvStructure = PVStructurePtr(pvntField->createDisplay());
    cout << *pvStructure << endl;
    testOk1(ntField->isDisplay(pvStructure->getStructure()));

    pvStructure = PVStructurePtr(pvDataCreate->createPVStructure(standardField->doubleAlarm()));
    cout << *pvStructure << endl;
    testOk1(ntField->isAlarmLimit(pvStructure->getStructure()));

    PVStructureArrayPtr pvStructureArray = PVStructureArrayPtr(
        pvntField->createEnumeratedArray());
    cout << *pvStructure << endl;
    cout << *pvStructureArray->getStructureArray()->getStructure();

    pvStructureArray = PVStructureArrayPtr(
        pvntField->createTimeStampArray());
    cout << *pvStructure << endl;
    cout << *pvStructureArray->getStructureArray()->getStructure();

    pvStructureArray = PVStructureArrayPtr(
        pvntField->createAlarmArray());
    cout << *pvStructure << endl;
    cout << *pvStructureArray->getStructureArray()->getStructure();
}
コード例 #12
0
void testNTField()
{
    testDiag("testNTField");

    StructureConstPtr structureConstPtr = ntField->createEnumerated();
    cout << *structureConstPtr << endl;
    testOk1(ntField->isEnumerated(structureConstPtr));

    structureConstPtr = ntField->createTimeStamp();
    cout << *structureConstPtr << endl;
    testOk1(ntField->isTimeStamp(structureConstPtr));

    structureConstPtr = ntField->createAlarm();
    cout << *structureConstPtr << endl;
    testOk1(ntField->isAlarm(structureConstPtr));

    structureConstPtr = ntField->createDisplay();
    cout << *structureConstPtr << endl;
    testOk1(ntField->isDisplay(structureConstPtr));

    structureConstPtr = standardField->doubleAlarm();
    cout << *structureConstPtr << endl;
    testOk1(ntField->isAlarmLimit(structureConstPtr));

    structureConstPtr = ntField->createControl();
    cout << *structureConstPtr << endl;
    testOk1(ntField->isControl(structureConstPtr));

    StructureArrayConstPtr structureArrayConstPtr
        = ntField->createEnumeratedArray();
    cout << *structureConstPtr << endl;

    structureArrayConstPtr = ntField->createTimeStampArray();
    cout << *structureConstPtr << endl;

    structureArrayConstPtr = ntField->createAlarmArray();
    cout << *structureConstPtr << endl;
}
コード例 #13
0
PVStructurePtr createPowerSupply()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    StandardFieldPtr standardField = getStandardField();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    return pvDataCreate->createPVStructure(
        fieldCreate->createFieldBuilder()->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure());
}
コード例 #14
0
static void test()
{
    std::ostringstream oss;
    
    testDiag("\ntestBitSetUtil\n");
    StringArray fieldNames;
    PVFieldPtrArray pvFields;
    fieldNames.reserve(5);
    pvFields.reserve(5);
    fieldNames.push_back("timeStamp");
    fieldNames.push_back("alarm");
    fieldNames.push_back("voltage");
    fieldNames.push_back("power");
    fieldNames.push_back("current");
    pvFields.push_back(
        pvDataCreate->createPVStructure(standardField->timeStamp()));
    pvFields.push_back(
        pvDataCreate->createPVStructure(standardField->alarm()));
    pvFields.push_back(
        pvDataCreate->createPVStructure(
            standardField->scalar(pvDouble,"alarm")));
    pvFields.push_back(
        pvDataCreate->createPVStructure(
            standardField->scalar(pvDouble,"alarm")));
    pvFields.push_back(
        pvDataCreate->createPVStructure(
            standardField->scalar(pvDouble,"alarm")));
    PVStructurePtr pvs =  pvDataCreate->createPVStructure(
         fieldNames,pvFields);

    int32 nfields = (int32)pvs->getNumberFields();
    BitSetPtr bitSet = BitSet::create(nfields);
    for(int32 i=0; i<nfields; i++) bitSet->set(i);

    BitSetUtil::compress(bitSet,pvs);

    bitSet->clear();
    PVFieldPtr pvField = pvs->getSubField<PVStructure>("timeStamp");
    int32 offsetTimeStamp = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVLong>("timeStamp.secondsPastEpoch");
    int32 offsetSeconds = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVInt>("timeStamp.nanoseconds");
    int32 offsetNano = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVInt>("timeStamp.userTag");
    int32 offsetUserTag = (int32)pvField->getFieldOffset();
    bitSet->set(offsetSeconds);
    BitSetUtil::compress(bitSet,pvs);
    testOk1(bitSet->get(offsetSeconds)==true);
    bitSet->set(offsetNano);
    bitSet->set(offsetUserTag);

    BitSetUtil::compress(bitSet,pvs);
    testOk1(bitSet->get(offsetSeconds)==false);
    testOk1(bitSet->get(offsetTimeStamp)==true);

    bitSet->clear();

    pvField = pvs->getSubField<PVStructure>("current");
    int32 offsetCurrent = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVDouble>("current.value");
    int32 offsetValue = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVStructure>("current.alarm");
    int32 offsetAlarm = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVInt>("current.alarm.severity");
    int32 offsetSeverity = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVInt>("current.alarm.status");
    int32 offsetStatus = (int32)pvField->getFieldOffset();
    pvField = pvs->getSubField<PVString>("current.alarm.message");
    int32 offsetMessage = (int32)pvField->getFieldOffset();
    bitSet->set(offsetValue);
    bitSet->set(offsetSeverity);
    bitSet->set(offsetStatus);
    bitSet->set(offsetMessage);

    BitSetUtil::compress(bitSet,pvs);

    testOk1(bitSet->get(offsetCurrent)==true);
    bitSet->clear();
    bitSet->set(offsetSeverity);
    bitSet->set(offsetStatus);
    bitSet->set(offsetMessage);

    BitSetUtil::compress(bitSet,pvs);

    testOk1(bitSet->get(offsetAlarm)==true);
    bitSet->clear();
    printf("testBitSetUtil PASSED\n");
}
コード例 #15
0
ファイル: ntscalarTest.cpp プロジェクト: epicsdeb/epics-nt
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;

}
コード例 #16
0
ファイル: ntenumTest.cpp プロジェクト: epicsdeb/epics-nt
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;

}
コード例 #17
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);
}
コード例 #18
0
StructureConstPtr NTMultiChannelBuilder::createStructure()
{
    StandardFieldPtr standardField = getStandardField();
    size_t nfields = 3;
    size_t extraCount = extraFieldNames.size();
    nfields += extraCount;
    if(descriptor) ++nfields;
    if(alarm) ++nfields;
    if(timeStamp) ++nfields;
    if(severity) ++nfields;
    if(status) ++nfields;
    if(message) ++nfields;
    if(secondsPastEpoch) ++nfields;
    if(nanoseconds) ++nfields;
    if(userTag) ++nfields;
    FieldConstPtrArray fields(nfields);
    StringArray names(nfields);
    size_t ind = 0;
    names[ind] = "value";
    if(valueType) {
        fields[ind++] =  fieldCreate->createUnionArray(valueType);
    } else {
        fields[ind++] =  fieldCreate->createVariantUnionArray();
    }
    names[ind] = "channelName";
    fields[ind++] =  fieldCreate->createScalarArray(pvString);
    names[ind] = "isConnected";
    fields[ind++] =  fieldCreate->createScalarArray(pvBoolean);
    if(timeStamp) {
        names[ind] = "timeStamp";
        fields[ind++] = standardField->timeStamp();
    }
    if(alarm) {
        names[ind] = "alarm";
        fields[ind++] = standardField->alarm();
    }
    if(descriptor) {
        names[ind] = "descriptor";
        fields[ind++] = fieldCreate->createScalar(pvString);
    }
    if(severity) {
        names[ind] = "severity";
        fields[ind++] = fieldCreate->createScalarArray(pvInt);
    }
    if(status) {
        names[ind] = "status";
        fields[ind++] = fieldCreate->createScalarArray(pvInt);
    }
    if(message) {
        names[ind] = "message";
        fields[ind++] = fieldCreate->createScalarArray(pvString);
    }
    if(secondsPastEpoch) {
        names[ind] = "secondsPastEpoch";
        fields[ind++] = fieldCreate->createScalarArray(pvLong);
    }
    if(nanoseconds) {
        names[ind] = "nanoseconds";
        fields[ind++] = fieldCreate->createScalarArray(pvInt);
    }
    if(userTag) {
        names[ind] = "userTag";
        fields[ind++] = fieldCreate->createScalarArray(pvInt);
    }
    for (size_t i = 0; i< extraCount; i++) {
        names[ind] = extraFieldNames[i];
        fields[ind++] = extraFields[i];
    }

    StructureConstPtr st = fieldCreate->createStructure(NTMultiChannel::URI,names,fields);
    reset();
    return st;
}
コード例 #19
0
static void testDouble()
{
    testDiag("== testDouble ==");
    StructureConstPtr structure =
        fieldCreate->createFieldBuilder() ->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            add("value",pvDouble) ->
            createStructure();

    PvaClientPutDataPtr pvaData = PvaClientPutData::create(structure);
    PVDoublePtr pvDouble = pvaData->getPVStructure() ->
        getSubField<PVDouble>("value");
    pvDouble->put(5.0);

    BitSetPtr change = pvaData->getChangedBitSet();
    size_t valueOffset = pvDouble->getFieldOffset();
    testOk(change->cardinality()==1,"1 field changed");
    testOk(change->get(valueOffset),"value changed");

    testOk(pvaData->hasValue(),"hasValue");
    testOk(pvaData->isValueScalar(),"isValueScalar");
    testOk(!pvaData->isValueScalarArray(),"!isValueScalarArray");

    try {
        testOk(!!pvaData->getValue(), "getValue");
    } catch (std::runtime_error e) {
        testFail("getValue exception '%s'", e.what());
    }

    try {
        testOk(!!pvaData->getScalarValue(), "getScalarValue");
    } catch (std::runtime_error e) {
        testFail("getScalarValue exception '%s'", e.what());
    }
    try {
        testOk(!pvaData->getArrayValue(), "!getArrayValue");
    } catch (std::runtime_error e) {
        testPass("getArrayValue exception '%s'", e.what());
    }
    try {
        testOk(!pvaData->getScalarArrayValue(), "!getScalarArrayValue");
    } catch (std::runtime_error e) {
        testPass("getScalarArrayValue exception '%s'", e.what());
    }

    try {
        testOk(pvaData->getDouble() == 5.0, "getDouble value");
    } catch (std::runtime_error e) {
        testFail("getDouble exception '%s'", e.what());
    }
    try {
        testOk(pvaData->getString() == "5", "getString value");
    } catch (std::runtime_error e) {
        testFail("getString exception '%s'", e.what());
    }

    try {
        shared_vector<const double> value = pvaData->getDoubleArray();
        testFail("getDoubleArray");
    } catch (std::runtime_error e) {
        testPass("getDoubleArray exception '%s'", e.what());
    }
    try {
        shared_vector<const string> value = pvaData->getStringArray();
        testFail("getStringArray");
    } catch (std::runtime_error e) {
        testPass("getStringArray exception '%s'", e.what());
    }

    try {
        pvaData->putDouble(5.0);
        testPass("putDouble");
    } catch (std::runtime_error e) {
        testFail("putDouble exception '%s'", e.what());
    }
    try {
        pvaData->putString("1e5");
        testPass("putString");
    } catch (std::runtime_error e) {
        testFail("putString exception '%s'", e.what());
    }

    try {
        size_t len = 2;
        shared_vector<double> val(len);
        for (size_t i=0; i<len; ++i)
            val[i] = (i+1) * 10.0;
        pvaData->putDoubleArray(freeze(val));
        testFail("putDoubleArray");
    } catch (std::runtime_error e) {
        testPass("putDoubleArray exception '%s'", e.what());
    }
    try {
        size_t len = 2;
        shared_vector<string> val(len);
        val[0] = "one"; val[1] = "two";
        pvaData->putStringArray(freeze(val));
        testFail("putStringArray");
    } catch (std::runtime_error e) {
        testPass("putStringArray exception '%s'", e.what());
    }
}
コード例 #20
0
ファイル: testPVData.cpp プロジェクト: mrkraimer/pvDataCPP
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");
}
コード例 #21
0
StructureConstPtr NTNDArrayBuilder::createStructure()
{
    enum
    {
        DISCRIPTOR_INDEX,
        TIMESTAMP_INDEX,
        ALARM_INDEX,
        DISPLAY_INDEX
    };

    const size_t NUMBER_OF_INDICES = DISPLAY_INDEX+1;
    const size_t NUMBER_OF_STRUCTURES = 1 << NUMBER_OF_INDICES;

    Lock xx(mutex);

    static StructureConstPtr ntndarrayStruc[NUMBER_OF_STRUCTURES];
    static UnionConstPtr valueType;
    static StructureConstPtr codecStruc;
    static StructureConstPtr dimensionStruc;
    static StructureConstPtr attributeStruc;

    StructureConstPtr returnedStruc;

    size_t index = 0;
    if (descriptor) index  |= 1 << DISCRIPTOR_INDEX;
    if (timeStamp)  index  |= 1 << TIMESTAMP_INDEX;
    if (alarm)      index  |= 1 << ALARM_INDEX;
    if (display)    index  |= 1 << DISPLAY_INDEX;

    bool isExtended = !extraFieldNames.empty();

    if (isExtended || !ntndarrayStruc[index])
    {
        StandardFieldPtr standardField = getStandardField();
        FieldBuilderPtr fb = fieldCreate->createFieldBuilder();

        if (!valueType)
        {
            for (int i = pvBoolean; i < pvString; ++i)
            {
                ScalarType st = static_cast<ScalarType>(i);
                fb->addArray(std::string(ScalarTypeFunc::name(st)) + "Value", st);
            }
            valueType = fb->createUnion();                
        }

        if (!codecStruc)
        {
            codecStruc = fb->setId("codec_t")->
                add("name", pvString)->
                add("parameters", fieldCreate->createVariantUnion())->
                createStructure();
        }

        if (!dimensionStruc)
        {
            dimensionStruc = fb->setId("dimension_t")->
                add("size", pvInt)->
                add("offset",  pvInt)->
                add("fullSize",  pvInt)->
                add("binning",  pvInt)->
                add("reverse",  pvBoolean)->
                createStructure();
        }

        if (!attributeStruc)
        {
            attributeStruc = NTNDArrayAttribute::createBuilder()->createStructure();
        }

        fb->setId(NTNDArray::URI)->
            add("value", valueType)->
            add("codec", codecStruc)->
            add("compressedSize", pvLong)->
            add("uncompressedSize", pvLong)->
            addArray("dimension", dimensionStruc)->
            add("uniqueId", pvInt)->
            add("dataTimeStamp", standardField->timeStamp())->
            addArray("attribute", attributeStruc);

        if (descriptor)
            fb->add("descriptor", pvString);

        if (alarm)
            fb->add("alarm", standardField->alarm());

        if (timeStamp)
            fb->add("timeStamp", standardField->timeStamp());

        if (display)
            fb->add("display", standardField->display());

        size_t extraCount = extraFieldNames.size();
        for (size_t i = 0; i< extraCount; i++)
            fb->add(extraFieldNames[i], extraFields[i]);

        returnedStruc = fb->createStructure();

        if (!isExtended)
            ntndarrayStruc[index] = returnedStruc; 
    }
    else
    {
        return ntndarrayStruc[index];
    }

    return returnedStruc;
}