Exemplo n.º 1
0
size_t fromString(PVStructureArrayPtr const &pv, StringArray const & from, size_t fromStartIndex = 0)
{
	int processed = 0;
	size_t fromValueCount = from.size();

	// first get count
	if (fromStartIndex >= fromValueCount)
		throw std::runtime_error("not enough of values");

	size_t numberOfStructures;
	istringstream iss(from[fromStartIndex]);
	iss >> numberOfStructures;
	// not fail and entire value is parsed (e.g. to detect 1.2 parsing to 1)
	if (iss.fail() || !iss.eof())
    	throw runtime_error("failed to parse element count value (uint) of field '" + pv->getFieldName() + "' from string value '" + from[fromStartIndex] + "'");
	fromStartIndex++;
	processed++;

    PVStructureArray::svector pvStructures;
    pvStructures.reserve(numberOfStructures);

    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    for (size_t i = 0; i < numberOfStructures; ++i)
    {
        PVStructurePtr pvStructure = pvDataCreate->createPVStructure(pv->getStructureArray()->getStructure());
        size_t count = fromString(pvStructure, from, fromStartIndex);
        processed += count;
        fromStartIndex += count;
        pvStructures.push_back(pvStructure);
    }

    pv->replace(freeze(pvStructures));

    return processed;
}
Exemplo n.º 2
0
void pvaDriver::monitorConnect (Status const & status,
        MonitorPtr const & monitor, StructureConstPtr const & structure)
{
    const char *functionName = "monitorConnect";

    asynPrint(pasynUserSelf, ASYN_TRACE_FLOW,
            "%s::%s monitor connects [type=%s]\n",
            driverName, functionName, Status::StatusTypeName[status.getType()]);

    if (status.isSuccess())
    {
        PVDataCreatePtr PVDC = getPVDataCreate();

        if(!NTNDArray::isCompatible(PVDC->createPVStructure(structure)))
        {
            asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                    "%s::%s incompatible PVStructure. Not starting monitor\n",
                    driverName, functionName);
            return;
        }

        asynPrint(pasynUserSelf, ASYN_TRACE_FLOW,
                "%s::%s starting monitor\n",
                driverName, functionName);
        monitor->start();
    }
}
Exemplo n.º 3
0
void PVUnionArray::deserialize(ByteBuffer *pbuffer,
        DeserializableControl *pcontrol) {
    svector data(reuse());

    size_t size = this->getArray()->getArraySizeType() == Array::fixed ?
                this->getArray()->getMaximumCapacity() :
                SerializeHelper::readSize(pbuffer, pcontrol);

    data.resize(size);

    UnionConstPtr punion = unionArray->getUnion();

    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    for(size_t i = 0; i<size; i++) {
        pcontrol->ensureData(1);
        size_t temp = pbuffer->getByte();
        if(temp==0) {
            data[i].reset();
        }
        else {
            if(data[i].get()==NULL || !data[i].unique()) {
                data[i] = pvDataCreate->createPVUnion(punion);
            }
            data[i]->deserialize(pbuffer, pcontrol);
        }
    }
    replace(freeze(data)); // calls postPut()
}
Exemplo n.º 4
0
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));
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
// TODO not thread-safe (local static initializers)
// TODO replace with non-locking singleton pattern
PVDataCreatePtr PVDataCreate::getPVDataCreate()
{
    static PVDataCreatePtr pvDataCreate;
    static Mutex mutex;
    Lock xx(mutex);

    if(pvDataCreate.get()==0) pvDataCreate = PVDataCreatePtr(new PVDataCreate());
    return pvDataCreate;
}
static void setValue(PVUnionPtr const &pvUnion, double value)
{
    UnionConstPtr u = pvUnion->getUnion();
    FieldConstPtr field = u->getField(0);
    Type type = field->getType();
    if(type==scalar) {
         ScalarConstPtr scalar = static_pointer_cast<const Scalar>(field);
         ScalarType scalarType = scalar->getScalarType();
         if(scalarType==pvDouble) {
              PVDoublePtr pvValue = static_pointer_cast<PVDouble>(
                   pvDataCreate->createPVScalar(pvDouble));
              pvValue->put(value);
              pvUnion->set(0,pvValue);
              return;
         }
         if(scalarType==pvString) {
              PVStringPtr pvValue = static_pointer_cast<PVString>(
                   pvDataCreate->createPVScalar(pvString));
              stringstream ss;
              ss << "value" << value;
              pvValue->put(ss.str());
              pvUnion->set(0,pvValue);
              return;
         }
         throw std::runtime_error("only pvDouble and pvString are supported");
    }
    if(type==scalarArray) {
         ScalarArrayConstPtr scalarArray = static_pointer_cast<const ScalarArray>(field);
         ScalarType scalarType = scalarArray->getElementType();
         if(scalarType==pvDouble) {
              size_t num = 5;
              PVDoubleArrayPtr pvValue = static_pointer_cast<PVDoubleArray>(
                   pvDataCreate->createPVScalarArray(pvDouble));
              shared_vector<double> data(num);
              for(size_t i=0; i<num; ++i) data[i] = value +i;
              pvValue->replace(freeze(data));
              pvUnion->set(0,pvValue);
              return;
         }
         if(scalarType==pvString) {
              size_t num = 5;
              PVStringArrayPtr pvValue = static_pointer_cast<PVStringArray>(
                   pvDataCreate->createPVScalarArray(pvString));
              shared_vector<string> data(num);
              for(size_t i=0; i<num; ++i) {
                  stringstream ss;
                  ss << "value" << value << i;
                  data[i] = ss.str();
              }
              pvValue->replace(freeze(data));
              pvUnion->set(0,pvValue);
              return;
         }
         throw std::runtime_error("only pvDouble and pvString are supported");
    }
    throw std::runtime_error("only scalar and scalarArray fields are supported");
}
Exemplo n.º 8
0
RPCService::shared_pointer  ExampleHelloRPC::create()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
        add("value",pvString)->
        createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
    ExampleHelloRPCPtr hello(
        new ExampleHelloRPC(pvStructure));
    return hello;
}
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;
}
Exemplo n.º 10
0
void oleaClient::monitorConnect (Status const & status,
        MonitorPtr const & monitor, StructureConstPtr const & structure)
{
    if (status.isSuccess())
    {
        PVDataCreatePtr PVDC = getPVDataCreate();

        if(!NTTable::isCompatible(PVDC->createPVStructure(structure)))
        {
            cout << "No NTTable support" << endl;
            return;
        }

        monitor->start();
    }
}
Exemplo n.º 11
0
static void testCreatePVStructureWithInvalidName()
{
    testDiag("testCreatePVStructureWithInvalidName");
    StringArray fieldNames;
    fieldNames.push_back("ok");
    fieldNames.push_back("this.is-wrong");
    PVFieldPtrArray pvFields;
    pvFields.push_back(pvDataCreate->createPVScalar(pvString));
    pvFields.push_back(pvDataCreate->createPVScalar(pvInt));
    try{
        PVStructurePtr pvParent = pvDataCreate->createPVStructure(
            fieldNames,pvFields);
        testFail("Creation of invalid field name '%s' was allowed", fieldNames[1].c_str());
    } catch(std::invalid_argument& e) {
        testDiag("Exception: \"%s\"", e.what());
        testPass("Creation of invalid field name '%s' fails as expected", fieldNames[1].c_str());
    }
}
Exemplo n.º 12
0
static void testCreatePVStructure()
{
    PVStructurePtr pv0 = standardPVField->scalar(
         pvDouble,alarmTimeStampValueAlarm);
    PVScalarPtr pv1 = pvDataCreate->createPVScalar(pvString);
    PVFieldPtrArray pvFields;
    StringArray fieldNames;
    pvFields.reserve(2);
    fieldNames.reserve(2);
    fieldNames.push_back("value");
    fieldNames.push_back("extra");
    pvFields.push_back(pv0);
    pvFields.push_back(pv1);
    PVStructurePtr pvParent = pvDataCreate->createPVStructure(
        fieldNames,pvFields);
        
    std::cout << "testCreatePVStructure PASSED" << std::endl;
}
Exemplo n.º 13
0
PVStructure::PVStructure(StructureConstPtr const & structurePtr)
: PVField(structurePtr),
  structurePtr(structurePtr),
  extendsStructureName("")
{
    size_t numberFields = structurePtr->getNumberFields();
    FieldConstPtrArray fields = structurePtr->getFields();
    StringArray fieldNames = structurePtr->getFieldNames();
//    PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields);
    pvFields.reserve(numberFields);
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    for(size_t i=0; i<numberFields; i++) {
    	pvFields.push_back(pvDataCreate->createPVField(fields[i]));
    }
    for(size_t i=0; i<numberFields; i++) {
    	pvFields[i]->setParentAndName(this,fieldNames[i]);
    }
}
Exemplo n.º 14
0
static void testPVScalarCommon(string /*fieldName*/,ScalarType stype)
{
    PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype);
    if(stype==pvBoolean) {
        convert->fromString(pvScalar,string("true"));
    } else {
        convert->fromString(pvScalar,string("10"));
    }
}
Exemplo n.º 15
0
size_t PVUnionArray::append(size_t number)
{
    checkLength(value.size()+number);

    svector data(reuse());
    data.resize(data.size()+number);

    UnionConstPtr punion = unionArray->getUnion();

    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    for(svector::reverse_iterator it = data.rbegin(); number; ++it, --number)
        *it = pvDataCreate->createPVUnion(punion);

    size_t newLength = data.size();

    const_svector cdata(freeze(data));
    swap(cdata);

    return newLength;
}
Exemplo n.º 16
0
static void createVariantUnionRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
    StructureConstPtr top = fieldCreate->createFieldBuilder()->
         add("value",fieldCreate->createVariantUnion())->
         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;
}
Exemplo n.º 17
0
RecordListRecordPtr RecordListRecord::create(
    std::string const & recordName)
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
        addNestedStructure("argument")->
            add("database",pvString)->
            add("regularExpression",pvString)->
            endNested()->
        addNestedStructure("result") ->
            add("status",pvString) ->
            addArray("names",pvString) ->
            endNested()->
        createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
    RecordListRecordPtr pvRecord(
        new RecordListRecord(recordName,pvStructure));
    if(!pvRecord->init()) pvRecord.reset();
    return pvRecord;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
static void createRegularUnionArrayRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
    StructureConstPtr top = fieldCreate->createFieldBuilder()->
         addNestedUnionArray("value")->
             add("string",pvString)->
             addArray("stringArray",pvString)->
             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;
}
Exemplo n.º 20
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());
}
Exemplo n.º 21
0
static void testRequest()
{        
    StringArray nullNames;
    FieldConstPtrArray nullFields;
    StringArray optionNames(1);
    FieldConstPtrArray optionFields(1);
    optionNames[0] = "process";
    optionFields[0] = fieldCreate->createScalar(pvString);
    StringArray recordNames(1);
    FieldConstPtrArray recordFields(1);
    recordNames[0] = "_options";
    recordFields[0] = fieldCreate->createStructure(optionNames,optionFields);
    StringArray fieldNames(2);
    FieldConstPtrArray fieldFields(2);
    fieldNames[0] = "alarm";
    fieldFields[0] = fieldCreate->createStructure(nullNames,nullFields);
    fieldNames[1] = "timeStamp";
    fieldFields[1] = fieldCreate->createStructure(nullNames,nullFields);
    StringArray topNames(2);
    FieldConstPtrArray topFields(2);
    topNames[0] = "record";
    topFields[0] = fieldCreate->createStructure(recordNames,recordFields);
    topNames[1] = "field";
    topFields[1] = fieldCreate->createStructure(fieldNames,fieldFields);
    StructureConstPtr topStructure = fieldCreate->createStructure(
        topNames,topFields);
cout << *topStructure << endl;
    PVStructurePtr pvTop = pvDataCreate->createPVStructure(topStructure);
cout << *pvTop << endl;
cout << *pvTop->getStructure() << endl;
PVStructurePtr xxx = pvTop->getSubField<PVStructure>("record");
cout << *xxx << endl;
xxx = pvTop->getSubField<PVStructure>("field");
cout << *xxx << endl;
PVStringPtr pvString = pvTop->getSubField<PVString>("record._options.process");
pvString->put("true");
cout << *pvTop << endl;

string subName("record._options.process");
PVFieldPtr pvField = pvTop->getSubField<PVString>(subName);
string fieldName = pvField->getFieldName();
string fullName = pvField->getFullName();
cout << "fieldName " << fieldName << " fullName " << fullName << endl;

    testOk1(fieldName.compare("process")==0);
    testOk1(fullName.compare(subName)==0);

}
Exemplo n.º 22
0
void NTNDArrayConverter::fromAttributes (NDArray *src)
{
    PVStructureArrayPtr dest(m_array->getAttribute());
    NDAttributeList *srcList = src->pAttributeList;
    NDAttribute *attr = NULL;
    StructureConstPtr structure(dest->getStructureArray()->getStructure());
    PVStructureArray::svector destVec(dest->reuse());

    destVec.resize(srcList->count());

    size_t i = 0;
    while((attr = srcList->next(attr)))
    {
        if(!destVec[i].get() || !destVec[i].unique())
            destVec[i] = PVDC->createPVStructure(structure);

        PVStructurePtr pvAttr(destVec[i]);

        pvAttr->getSubField<PVString>("name")->put(attr->getName());
        pvAttr->getSubField<PVString>("descriptor")->put(attr->getDescription());
        pvAttr->getSubField<PVString>("source")->put(attr->getSource());

        NDAttrSource_t sourceType;
        attr->getSourceInfo(&sourceType);
        pvAttr->getSubField<PVInt>("sourceType")->put(sourceType);

        switch(attr->getDataType())
        {
        case NDAttrInt8:      fromAttribute <PVByte,   int8_t>  (pvAttr, attr); break;
        case NDAttrUInt8:     fromAttribute <PVUByte,  uint8_t> (pvAttr, attr); break;
        case NDAttrInt16:     fromAttribute <PVShort,  int16_t> (pvAttr, attr); break;
        case NDAttrUInt16:    fromAttribute <PVUShort, uint16_t>(pvAttr, attr); break;
        case NDAttrInt32:     fromAttribute <PVInt,    int32_t> (pvAttr, attr); break;
        case NDAttrUInt32:    fromAttribute <PVUInt,   uint32_t>(pvAttr, attr); break;
        case NDAttrFloat32:   fromAttribute <PVFloat,  float>   (pvAttr, attr); break;
        case NDAttrFloat64:   fromAttribute <PVDouble, double>  (pvAttr, attr); break;
        case NDAttrString:    fromStringAttribute(pvAttr, attr); break;
        case NDAttrUndefined: fromUndefinedAttribute(pvAttr); break;
        default:              throw std::runtime_error("invalid attribute data type");
        }

        ++i;
    }

    dest->replace(freeze(destVec));
}
Exemplo n.º 23
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();
}
Exemplo n.º 24
0
void NTNDArrayConverter::fromDimensions (NDArray *src)
{
    PVStructureArrayPtr dest(m_array->getDimension());
    PVStructureArray::svector destVec(dest->reuse());
    StructureConstPtr dimStructure(dest->getStructureArray()->getStructure());

    destVec.resize(src->ndims);
    for (int i = 0; i < src->ndims; i++)
    {
        if (!destVec[i] || !destVec[i].unique())
            destVec[i] = PVDC->createPVStructure(dimStructure);

        destVec[i]->getSubField<PVInt>("size")->put(src->dims[i].size);
        destVec[i]->getSubField<PVInt>("offset")->put(src->dims[i].offset);
        destVec[i]->getSubField<PVInt>("fullSize")->put(src->dims[i].size);
        destVec[i]->getSubField<PVInt>("binning")->put(src->dims[i].binning);
        destVec[i]->getSubField<PVBoolean>("reverse")->put(src->dims[i].reverse);
    }
    dest->replace(freeze(destVec));
}
Exemplo n.º 25
0
static void testConvertScalarArray(FILE *fd) {
    PVScalarArrayPtr pvBytePtr = pvDataCreate->createPVScalarArray(pvByte);
    PVScalarArrayPtr pvUBytePtr = pvDataCreate->createPVScalarArray(pvUByte);
    PVScalarArrayPtr pvShortPtr = pvDataCreate->createPVScalarArray(pvShort);
    PVScalarArrayPtr pvUShortPtr = pvDataCreate->createPVScalarArray(pvUShort);
    PVScalarArrayPtr pvIntPtr = pvDataCreate->createPVScalarArray(pvInt);
    PVScalarArrayPtr pvUIntPtr = pvDataCreate->createPVScalarArray(pvUInt);
    PVScalarArrayPtr pvLongPtr = pvDataCreate->createPVScalarArray(pvLong);
    PVScalarArrayPtr pvULongPtr = pvDataCreate->createPVScalarArray(pvULong);
    PVScalarArrayPtr pvFloatPtr = pvDataCreate->createPVScalarArray(pvFloat);
    PVScalarArrayPtr pvDoublePtr = pvDataCreate->createPVScalarArray(pvDouble);

    fprintf(fd,"testConvertScalarArray\n");
    if(debug) fprintf(fd,"\nfromByte\n");
    size_t length = 4;
    int8 barray[length];
    int8 bval = 127;
    barray[0] = bval;
    for(size_t i=1; i<length; i++) barray[i] = barray[i-1] + 1;
    convert->fromByteArray(pvBytePtr,0,length,barray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromByteArray(pvUBytePtr,0,length,barray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromByteArray(pvShortPtr,0,length,barray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromByteArray(pvUShortPtr,0,length,barray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromByteArray(pvIntPtr,0,length,barray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromByteArray(pvUIntPtr,0,length,barray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromByteArray(pvLongPtr,0,length,barray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromByteArray(pvULongPtr,0,length,barray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromByteArray(pvFloatPtr,0,length,barray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromByteArray(pvDoublePtr,0,length,barray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvUBytePtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvUBytePtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromByte PASSED\n");

    if(debug) fprintf(fd,"\nfromShort\n");
    int16 sarray[length];
    int16 sval = 0x7fff;
    sarray[0] = sval;
    for(size_t i=1; i<length; i++) sarray[i] = sarray[i-1] + 1;
    convert->fromShortArray(pvBytePtr,0,length,sarray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromShortArray(pvUBytePtr,0,length,sarray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromShortArray(pvShortPtr,0,length,sarray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromShortArray(pvUShortPtr,0,length,sarray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromShortArray(pvIntPtr,0,length,sarray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromShortArray(pvUIntPtr,0,length,sarray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromShortArray(pvLongPtr,0,length,sarray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromShortArray(pvULongPtr,0,length,sarray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromShortArray(pvFloatPtr,0,length,sarray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromShortArray(pvDoublePtr,0,length,sarray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvUShortPtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvUShortPtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromShort PASSED\n");

    if(debug) fprintf(fd,"\nfromInt\n");
    int32 iarray[length];
    int32 ival = 0x7fffffff;
    iarray[0] = ival;
    for(size_t i=1; i<length; i++) iarray[i] = iarray[i-1] + 1;
    convert->fromIntArray(pvBytePtr,0,length,iarray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromIntArray(pvUBytePtr,0,length,iarray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromIntArray(pvShortPtr,0,length,iarray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromIntArray(pvUShortPtr,0,length,iarray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromIntArray(pvIntPtr,0,length,iarray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromIntArray(pvUIntPtr,0,length,iarray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromIntArray(pvLongPtr,0,length,iarray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromIntArray(pvULongPtr,0,length,iarray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromIntArray(pvFloatPtr,0,length,iarray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromIntArray(pvDoublePtr,0,length,iarray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvUIntPtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvUIntPtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromInt PASSED\n");

    if(debug) fprintf(fd,"\nfromLong\n");
    int64 larray[length];
    int64 lval = 0x7fffffffffffffffLL;
    larray[0] = lval;
    for(size_t i=1; i<length; i++) larray[i] = larray[i-1] + 1;
    convert->fromLongArray(pvBytePtr,0,length,larray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromLongArray(pvUBytePtr,0,length,larray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromLongArray(pvShortPtr,0,length,larray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromLongArray(pvUShortPtr,0,length,larray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromLongArray(pvIntPtr,0,length,larray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromLongArray(pvUIntPtr,0,length,larray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromLongArray(pvLongPtr,0,length,larray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromLongArray(pvULongPtr,0,length,larray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromLongArray(pvFloatPtr,0,length,larray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromLongArray(pvDoublePtr,0,length,larray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvULongPtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvULongPtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromLong PASSED\n");

    if(debug) fprintf(fd,"\nfromUByte\n");
    uint8 ubarray[length];
    uint8 ubval = 127;
    ubarray[0] = ubval;
    for(size_t i=1; i<length; i++) ubarray[i] = ubarray[i-1] + 1;
    convert->fromUByteArray(pvBytePtr,0,length,ubarray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromUByteArray(pvUBytePtr,0,length,ubarray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromUByteArray(pvShortPtr,0,length,ubarray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromUByteArray(pvUShortPtr,0,length,ubarray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromUByteArray(pvIntPtr,0,length,ubarray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromUByteArray(pvUIntPtr,0,length,ubarray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromUByteArray(pvLongPtr,0,length,ubarray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromUByteArray(pvULongPtr,0,length,ubarray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromUByteArray(pvFloatPtr,0,length,ubarray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromUByteArray(pvDoublePtr,0,length,ubarray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvUBytePtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvUBytePtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromUByte PASSED\n");

    if(debug) fprintf(fd,"\nfromUShort\n");
    uint16 usarray[length];
    uint16 usval = 0x7fff;
    usarray[0] = usval;
    for(size_t i=1; i<length; i++) usarray[i] = usarray[i-1] + 1;
    convert->fromUShortArray(pvBytePtr,0,length,usarray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromUShortArray(pvUBytePtr,0,length,usarray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromUShortArray(pvShortPtr,0,length,usarray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromUShortArray(pvUShortPtr,0,length,usarray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromUShortArray(pvIntPtr,0,length,usarray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromUShortArray(pvUIntPtr,0,length,usarray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromUShortArray(pvLongPtr,0,length,usarray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromUShortArray(pvULongPtr,0,length,usarray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromUShortArray(pvFloatPtr,0,length,usarray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromUShortArray(pvDoublePtr,0,length,usarray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvUShortPtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvUShortPtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromUShort PASSED\n");

    if(debug) fprintf(fd,"\nfromUInt\n");
    uint32 uiarray[length];
    uint32 uival = 0x7fffffff;
    uiarray[0] = uival;
    for(size_t i=1; i<length; i++) uiarray[i] = uiarray[i-1] + 1;
    convert->fromUIntArray(pvBytePtr,0,length,uiarray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromUIntArray(pvUBytePtr,0,length,uiarray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromUIntArray(pvShortPtr,0,length,uiarray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromUIntArray(pvUShortPtr,0,length,uiarray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromUIntArray(pvIntPtr,0,length,uiarray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromUIntArray(pvUIntPtr,0,length,uiarray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromUIntArray(pvLongPtr,0,length,uiarray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromUIntArray(pvULongPtr,0,length,uiarray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromUIntArray(pvFloatPtr,0,length,uiarray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromUIntArray(pvDoublePtr,0,length,uiarray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvUIntPtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvUIntPtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromUInt PASSED\n");

    if(debug) fprintf(fd,"\nfromULong\n");
    uint64 ularray[length];
    uint64 ulval = 0x7fffffffffffffffLL;
    ularray[0] = ulval;
    for(size_t i=1; i<length; i++) ularray[i] = ularray[i-1] + 1;
    convert->fromULongArray(pvBytePtr,0,length,ularray,0);
    builder.clear(); pvBytePtr->toString(&builder);
    if(debug) fprintf(fd,"byte %s\n",builder.c_str());
    convert->fromULongArray(pvUBytePtr,0,length,ularray,0);
    builder.clear(); pvUBytePtr->toString(&builder);
    if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
    convert->fromULongArray(pvShortPtr,0,length,ularray,0);
    builder.clear(); pvShortPtr->toString(&builder);
    if(debug) fprintf(fd,"short %s\n",builder.c_str());
    convert->fromULongArray(pvUShortPtr,0,length,ularray,0);
    builder.clear(); pvUShortPtr->toString(&builder);
    if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
    convert->fromULongArray(pvIntPtr,0,length,ularray,0);
    builder.clear(); pvIntPtr->toString(&builder);
    if(debug) fprintf(fd,"int %s\n",builder.c_str());
    convert->fromULongArray(pvUIntPtr,0,length,ularray,0);
    builder.clear(); pvUIntPtr->toString(&builder);
    if(debug) fprintf(fd,"uint %s\n",builder.c_str());
    convert->fromULongArray(pvLongPtr,0,length,ularray,0);
    builder.clear(); pvLongPtr->toString(&builder);
    if(debug) fprintf(fd,"long %s\n",builder.c_str());
    convert->fromULongArray(pvULongPtr,0,length,ularray,0);
    builder.clear(); pvULongPtr->toString(&builder);
    if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
    convert->fromULongArray(pvFloatPtr,0,length,ularray,0);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float %s\n",builder.c_str());
    convert->fromULongArray(pvDoublePtr,0,length,ularray,0);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double %s\n",builder.c_str());
    convert->copyScalarArray(pvULongPtr,0, pvFloatPtr,0,length);
    builder.clear(); pvFloatPtr->toString(&builder);
    if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
    convert->copyScalarArray(pvULongPtr,0, pvDoublePtr,0,length);
    builder.clear(); pvDoublePtr->toString(&builder);
    if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
    fprintf(fd,"fromLong PASSED\n");
}
Exemplo n.º 26
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");
}
Exemplo n.º 27
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");
}
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);
}
Exemplo n.º 29
0
static void testFieldAccess()
{
    testDiag("Check methods for accessing structure fields");

    StructureConstPtr tdef = fieldCreate->createFieldBuilder()->
            add("test", pvInt)->
            addNestedStructure("hello")->
              add("world", pvInt)->
            endNested()->
            createStructure();

    PVStructurePtr fld = pvDataCreate->createPVStructure(tdef);

    PVIntPtr a = fld->getSubField<PVInt>("test");
    testOk1(a.get() != NULL);
    if(a.get()) {
        PVIntPtr b = fld->getSubFieldT<PVInt>("test");
        testOk(b.get()==a.get(), "%p == %p", b.get(), a.get());
    } else
        testSkip(1, "test doesn't exist?");

    a = fld->getSubField<PVInt>("hello.world");
    testOk1(a.get() != NULL);
    if(a.get()) {
        PVIntPtr b = fld->getSubFieldT<PVInt>("hello.world");
        testOk(b.get()==a.get(), "%p == %p", b.get(), a.get());
    } else
        testSkip(1, "hello.world doesn't exist?");

    // non-existent
    testOk1(fld->getSubField<PVInt>("invalid").get()==NULL);

    // wrong type
    testOk1(fld->getSubField<PVDouble>("test").get()==NULL);

    // intermediate struct non-existent
    testOk1(fld->getSubField<PVDouble>("helo.world").get()==NULL);

    // empty leaf field name
    testOk1(fld->getSubField<PVDouble>("hello.").get()==NULL);

    // empty field name
    testOk1(fld->getSubField<PVDouble>("hello..world").get()==NULL);
    testOk1(fld->getSubField<PVDouble>(".").get()==NULL);

    // whitespace
    testOk1(fld->getSubField<PVInt>(" test").get()==NULL);

    // intermediate field not structure
    testOk1(fld->getSubField<PVInt>("hello.world.invalid").get()==NULL);

    // null string
    try{
        char * name = NULL;
        fld->getSubFieldT<PVInt>(name);
        testFail("missing required exception");
    }catch(std::invalid_argument& e){
        testPass("caught expected exception: %s", e.what());
    }

    // non-existent
    try{
        fld->getSubFieldT<PVInt>("invalid");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // wrong type
    try{
        fld->getSubFieldT<PVDouble>("test");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // empty leaf field name
    try{
        fld->getSubFieldT<PVDouble>("hello.");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // empty field name
    try{
        fld->getSubFieldT<PVDouble>("hello..world");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }
    try{
        fld->getSubFieldT<PVDouble>(".");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // whitespace
    try{
        fld->getSubFieldT<PVDouble>(" test");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // intermediate field not structure
    try{
        fld->getSubFieldT<PVDouble>("hello.world.invalid");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }
}
Exemplo n.º 30
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);
}