示例#1
0
void testGet(bool debug,GatherV3DataPtr gather)
{
    String builder;
    NTTablePtr nttable = gather->getNTTable();
    bool result = gather->get();
    if(!result) printf("get failed\n%s\n",gather->getMessage().c_str());
    if(debug) {
        builder.clear();
        nttable->getPVStructure()->toString(&builder);
        printf("nttable\n%s\n",builder.c_str());
    }
    PVDoubleArrayPtr values = gather->getDoubleValue();
    PVIntArrayPtr severitys = gather->getAlarmSeverity();
    PVBooleanArrayPtr isConnecteds = gather->getIsConnected();
    PVStringArrayPtr channelNames = gather->getChannelName();
    if(debug) {
        builder.clear();
        values->toString(&builder);
        printf("value: %s\n",builder.c_str());
        builder.clear();
        severitys->toString(&builder);
        printf("severity: %s\n",builder.c_str());
        builder.clear();
        isConnecteds->toString(&builder);
        printf("isConnected: %s\n",builder.c_str());
        builder.clear();
        channelNames->toString(&builder);
        printf("channelName: %s\n",builder.c_str());
    }
}
示例#2
0
static PyObject * _create(PyObject *willbenull, PyObject *args)
{
    PyObject *dict = 0;
    if(!PyArg_ParseTuple(args,"O!:nttablePy",
                         &PyDict_Type,&dict))
    {
        PyErr_SetString(PyExc_SyntaxError,
                        "Bad argument. Expected (dictionary)");
        return NULL;
    }
    Py_ssize_t n = PyDict_Size(dict);
    PyObject *pkey, *ptype;
    Py_ssize_t pos = 0;
    NTTableBuilderPtr builder = NTTable::createBuilder();
    for(Py_ssize_t i=0; i< n; i++) {
        PyDict_Next(dict,&pos, &pkey, &ptype);
        char *key = PyString_AS_STRING(pkey);
        char *val = PyString_AS_STRING(ptype);
        string name(key);
        string type(val);
        ScalarType scalarType(pvString);
        if(type.compare("string")==0) {
        } else if(type.compare("string")==0) {
            scalarType = pvString;
        } else if(type.compare("boolean")==0) {
            scalarType = pvBoolean;
        } else if(type.compare("byte")==0) {
            scalarType = pvByte;
        } else if(type.compare("short")==0) {
            scalarType = pvShort;
        } else if(type.compare("int")==0) {
            scalarType = pvInt;
        } else if(type.compare("long")==0) {
            scalarType = pvLong;
        } else if(type.compare("float")==0) {
            scalarType = pvFloat;
        } else if(type.compare("double")==0) {
            scalarType = pvDouble;
        } else {
            PyErr_SetString(PyExc_SyntaxError,
                            "Bad argument. Illegal scalarType");
            return NULL;
        }
        builder->addColumn(name,scalarType);
    }

    NTTablePtr nttable =  builder ->
                          addDescriptor() ->
                          addTimeStamp() ->
                          addAlarm() ->
                          create();
    NTTablePvt *pvt = new NTTablePvt(nttable,nttable->getPVStructure());
    return PyCapsule_New(pvt,"nttablePvt",0);
}
void test_wrap()
{
    testDiag("test_wrap");

    NTTablePtr nullPtr = NTTable::wrap(PVStructurePtr());
    testOk(nullPtr.get() == 0, "nullptr wrap");

    nullPtr = NTTable::wrap(
                getPVDataCreate()->createPVStructure(
                    NTField::get()->createTimeStamp()
                    )
                );
    testOk(nullPtr.get() == 0, "wrong type wrap");


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

    PVStructurePtr pvStructure = builder->
            addColumn("column0", pvDouble)->
            addColumn("column1", pvString)->
            addColumn("column2", pvInt)->
            createPVStructure();
    testOk1(pvStructure.get() != 0);
    if (!pvStructure)
        return;

    NTTablePtr ptr = NTTable::wrap(pvStructure);
    testOk(ptr.get() != 0, "wrap OK");

    ptr = NTTable::wrapUnsafe(pvStructure);
    testOk(ptr.get() != 0, "wrapUnsafe OK");
}
示例#4
0
void test(bool debug, size_t count)
{
    String builder;
    int n = 1000;
    if(debug) n = count;
    StringArray channelName(n);
    char name[40];
    for(int i=0; i<n; i++) {
        sprintf(name,"masarExample%4.4d",i);
        channelName[i] = String(name);
    }

    GatherV3DataPtr gather(new GatherV3Data(channelName,n));
    NTTablePtr nttable = gather->getNTTable();
    if(debug) {
        builder.clear();
        nttable->getPVStructure()->toString(&builder);
        printf("nttable initial\n%s\n",builder.c_str());
    }
    testConnect(debug,gather);
    testConnect(debug,gather);
}
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;

}
示例#6
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());
}