コード例 #1
0
void test()
{
    String builder;
    int n = 9;
    StringArray channelName(n);
    channelName[0] = "masarExample0000";
    channelName[1] = "masarExample0001";
    channelName[2] = "masarExample0002";
    channelName[3] = "masarExample0003";
    channelName[4] = "masarExample0004";
    channelName[5] = "masarExampleCharArray";
    channelName[6] = "masarExampleStringArray";
    channelName[7] = "masarExampleLongArray";
    channelName[8] = "masarExampleDoubleArray";
    GatherV3DataPtr gather(new GatherV3Data(channelName,n));
    bool result = gather->connect(5.0);
    if(!result) {
        printf("connect failed\n%s\n",gather->getMessage().c_str());
        printf("This test requires iocBoot/iocAll ");
        printf("It must be started before running this test\n");
        exit(1);
    }
    NTTablePtr nttable = gather->getNTTable();
    BooleanArrayData booldata;
    PVBooleanArrayPtr pvIsArray = static_pointer_cast<PVBooleanArray>
            (nttable->getPVStructure()->getScalarArrayField("isArray",pvBoolean));
    pvIsArray->get(0,n,booldata);
    BooleanArray & isArray = booldata.data;
    DoubleArrayData ddata;
    gather->getDoubleValue()->get(0,n,ddata);
    DoubleArray & dvalue = ddata.data;
    StringArrayData sdata;
    gather->getStringValue()->get(0,n,sdata);
    StringArray & svalue = sdata.data;
    LongArrayData ldata;
    gather->getLongValue()->get(0,n,ldata);
    LongArray & lvalue = ldata.data;
    IntArrayData idata;
    StructureArrayData structdata;
    gather->getArrayValue()->get(0,n,structdata);
    PVStructurePtrArray & structvalue = structdata.data;
    gather->getDBRType()->get(0,n,idata);
    IntArray & dbrType = idata.data;
    for(int i=0; i<n; i++) {
        if(isArray[i]) {
            PVStructurePtr pvStructure = structvalue[i];
            switch(dbrType[i]) {
            case DBF_STRING: {
                PVStringArrayPtr pvValue = static_pointer_cast<PVStringArray>(
                    pvStructure->getScalarArrayField("stringValue",pvString));
                int num = 4;
                String value[4];
                value[0] = "aaa";
                value[1] = "bbb";
                value[2] = "ccc";
                value[3] = "ddd";
                pvValue->put(0,num,value,0);
                break;
            }
            case DBF_CHAR:
            case DBF_INT:
            case DBF_LONG: {
                PVIntArrayPtr pvValue = static_pointer_cast<PVIntArray>(
                    pvStructure->getScalarArrayField("intValue",pvInt));
                int num = 4;
                int32 value[4] = {1,2,3,4};
                pvValue->put(0,num,value,0);
                 break;
            }
            case DBF_FLOAT:
            case DBF_DOUBLE: {
                PVDoubleArrayPtr pvValue = static_pointer_cast<PVDoubleArray>(
                    pvStructure->getScalarArrayField("doubleValue",pvDouble));
                int num = 4;
                double value[4] = {1e1,1e2,1e3,1e4};
                pvValue->put(0,num,value,0);
                 break;
            }
            default:
                printf("got an unexpected DBF type. Logic error\n");
                exit(1);
            }
            continue;
        }
        switch(dbrType[i]) {
        case DBF_STRING:
             svalue[i] = String("this is set by gatherV3DataPut"); break;
        case DBF_ENUM:
             svalue[i] = String("one"); break;
        case DBF_CHAR:
        case DBF_INT:
        case DBF_LONG:
             lvalue[i] = i; break;
        case DBF_FLOAT:
        case DBF_DOUBLE:
             dvalue[i] = i; break;
        default:
            printf("got an unexpected DBF type. Logic error\n");
            exit(1);
        }
    }
    result = gather->put();
    if(!result) {printf("put failed\n%s\n",gather->getMessage().c_str()); exit(1);}
    result = gather->get();
    if(!result) {printf("get failed\n%s\n",gather->getMessage().c_str()); exit(1);}
    builder.clear();
    nttable->getPVStructure()->toString(&builder);
    printf("nttable\n%s\n",builder.c_str());
}
コード例 #2
0
static void test()
{
    NTMultiChannelBuilderPtr builder = NTMultiChannel::createBuilder();
    testOk(builder.get() != 0, "Got builder");

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

    PVStructurePtr pvStructure = multiChannel->getPVStructure();
    testOk1(pvStructure.get()!=NULL);
    testOk1(NTMultiChannel::is_a(pvStructure->getStructure()));
    size_t nchan = 3;
    shared_vector<string> names(nchan);
    names[0] = "channel 0";
    names[1] = "channel 1";
    names[2] = "channel 2";
    shared_vector<const string> channelNames(freeze(names));
    PVStringArrayPtr pvChannelName = multiChannel->getChannelName();
    pvChannelName->replace(channelNames);
    if(debug) {cout << *pvStructure << endl;}
    UnionConstPtr unionPtr =
       fieldCreate->createFieldBuilder()->
           add("doubleValue", pvDouble)->
           add("intValue", pvInt)->
           createUnion();
    multiChannel = builder->
            value(unionPtr) ->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            addIsConnected() ->
            create();
    testOk1(multiChannel.get() != 0);
    pvStructure = multiChannel->getPVStructure();
    if(debug) {cout << *pvStructure << endl;}
    pvChannelName = multiChannel->getChannelName();
    pvChannelName->replace(channelNames);
    PVUnionArrayPtr pvValue = multiChannel->getValue();
    shared_vector<PVUnionPtr> unions(nchan);
    unions[0] = pvDataCreate->createPVUnion(unionPtr);
    unions[1] = pvDataCreate->createPVUnion(unionPtr);
    unions[2] = pvDataCreate->createPVUnion(unionPtr);
    unions[0]->select("doubleValue");
    unions[1]->select("intValue");
    unions[2]->select("intValue");
    PVDoublePtr pvDouble = unions[0]->get<PVDouble>();
    pvDouble->put(1.235);
    PVIntPtr pvInt = unions[1]->get<PVInt>();
    pvInt->put(5);
    pvInt = unions[2]->get<PVInt>();
    pvInt->put(7);
    pvValue->replace(freeze(unions));
    shared_vector<int32> severities(nchan);
    severities[0] = 0;
    severities[1] = 1;
    severities[2] = 2;
    PVIntArrayPtr pvSeverity = multiChannel->getSeverity();
    pvSeverity->replace(freeze(severities));
    if(debug) {cout << *pvStructure << endl;}
    PVBooleanArrayPtr pvIsConnected = multiChannel->getIsConnected();
    shared_vector<const epics::pvData::boolean> isConnected = pvIsConnected->view();
    multiChannel = builder->
            value(unionPtr) ->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            addStatus() ->
            addMessage() ->
            addSecondsPastEpoch() ->
            addNanoseconds() ->
            addUserTag() ->
            addIsConnected() ->
            create();
    testOk1(multiChannel.get() != 0);
    pvStructure = multiChannel->getPVStructure();
    if(debug) {cout << *pvStructure << endl;}
    testOk1(NTMultiChannel::isCompatible(pvStructure)==true);
    PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp();
    testOk1(pvTimeStamp.get() !=0);
    PVStructurePtr pvAlarm = multiChannel->getAlarm();
    testOk1(pvAlarm.get() !=0);
    pvValue = multiChannel->getValue();
    testOk1(pvValue.get() !=0);
    pvChannelName = multiChannel->getChannelName();
    testOk1(pvChannelName.get() !=0);
    pvIsConnected = multiChannel->getIsConnected();
    testOk1(pvIsConnected.get() !=0);
    pvSeverity = multiChannel->getSeverity();
    testOk1(pvSeverity.get() !=0);
    PVIntArrayPtr pvStatus = multiChannel->getStatus();
    testOk1(pvStatus.get() !=0);
    PVStringArrayPtr pvMessage = multiChannel->getMessage();
    testOk1(pvMessage.get() !=0);
    PVLongArrayPtr pvSecondsPastEpoch = multiChannel->getSecondsPastEpoch();
    testOk1(pvSecondsPastEpoch.get() !=0);
    PVIntArrayPtr pvNanoseconds = multiChannel->getNanoseconds();
    testOk1(pvNanoseconds.get() !=0);
    PVIntArrayPtr pvUserTag = multiChannel->getUserTag();
    testOk1(pvUserTag.get() !=0);
    PVStringPtr pvDescriptor = multiChannel->getDescriptor();
    testOk1(pvDescriptor.get() !=0);
}
コード例 #3
0
static void test()
{
    NTScalarMultiChannelBuilderPtr builder = NTScalarMultiChannel::createBuilder();
    testOk(builder.get() != 0, "Got builder");

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

    PVStructurePtr pvStructure = multiChannel->getPVStructure();
    testOk1(pvStructure.get()!=NULL);
    testOk1(NTScalarMultiChannel::is_a(pvStructure->getStructure()));
    size_t nchan = 3;
    shared_vector<string> names(nchan);
    names[0] = "channel 0";
    names[1] = "channel 1";
    names[2] = "channel 2";
    shared_vector<const string> channelNames(freeze(names));
    PVStringArrayPtr pvChannelName = multiChannel->getChannelName();
    pvChannelName->replace(channelNames);
    if(debug) {cout << *pvStructure << endl;}
    multiChannel = builder->
            value(pvDouble) ->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            addIsConnected() ->
            create();
    testOk1(multiChannel.get() != 0);
    pvStructure = multiChannel->getPVStructure();
    if(debug) {cout << *pvStructure << endl;}
    pvChannelName = multiChannel->getChannelName();
    pvChannelName->replace(channelNames);
    PVDoubleArrayPtr pvValue = multiChannel->getValue<PVDoubleArray>();
    PVDoubleArray::svector doubles(nchan);
    doubles.resize(nchan);
    doubles[0] = 3.14159;
    doubles[1] = 2.71828;
    doubles[2] = 137.036;
    pvValue->replace(freeze(doubles));
    shared_vector<int32> severities(nchan);
    severities[0] = 0;
    severities[1] = 1;
    severities[2] = 2;
    PVIntArrayPtr pvSeverity = multiChannel->getSeverity();
    pvSeverity->replace(freeze(severities));
    if(debug) {cout << *pvStructure << endl;}
    PVBooleanArrayPtr pvIsConnected = multiChannel->getIsConnected();
    shared_vector<const epics::pvData::boolean> isConnected = pvIsConnected->view();
    multiChannel = builder->
            value(pvDouble) ->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            addStatus() ->
            addMessage() ->
            addSecondsPastEpoch() ->
            addNanoseconds() ->
            addUserTag() ->
            addIsConnected() ->
            create();
    testOk1(multiChannel.get() != 0);
    pvStructure = multiChannel->getPVStructure();
    if(debug) {cout << *pvStructure << endl;}
    testOk1(NTScalarMultiChannel::isCompatible(pvStructure)==true);
    PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp();
    testOk1(pvTimeStamp.get() !=0);
    PVStructurePtr pvAlarm = multiChannel->getAlarm();
    testOk1(pvAlarm.get() !=0);
    pvValue = multiChannel->getValue<PVDoubleArray>();
    testOk1(pvValue.get() !=0);
    pvChannelName = multiChannel->getChannelName();
    testOk1(pvChannelName.get() !=0);
    pvIsConnected = multiChannel->getIsConnected();
    testOk1(pvIsConnected.get() !=0);
    pvSeverity = multiChannel->getSeverity();
    testOk1(pvSeverity.get() !=0);
    PVIntArrayPtr pvStatus = multiChannel->getStatus();
    testOk1(pvStatus.get() !=0);
    PVStringArrayPtr pvMessage = multiChannel->getMessage();
    testOk1(pvMessage.get() !=0);
    PVLongArrayPtr pvSecondsPastEpoch = multiChannel->getSecondsPastEpoch();
    testOk1(pvSecondsPastEpoch.get() !=0);
    PVIntArrayPtr pvNanoseconds = multiChannel->getNanoseconds();
    testOk1(pvNanoseconds.get() !=0);
    PVIntArrayPtr pvUserTag = multiChannel->getUserTag();
    testOk1(pvUserTag.get() !=0);
    PVStringPtr pvDescriptor = multiChannel->getDescriptor();
    testOk1(pvDescriptor.get() !=0);
}