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; }
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)); }
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; }
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; }
void PVStructureArray::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); StructureConstPtr structure = structureArray->getStructure(); 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] = pvDataCreate->createPVStructure(structure); } data[i]->deserialize(pbuffer, pcontrol); } } replace(freeze(data)); // calls postPut() }
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(); } }
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 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; }
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; }
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); }
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(); } }
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)); }
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(); }
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()); } }
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; }
size_t PVStructureArray::append(size_t number) { checkLength(value.size()+number); svector data(reuse()); data.resize(data.size()+number); StructureConstPtr structure = structureArray->getStructure(); PVDataCreatePtr pvDataCreate = getPVDataCreate(); for(svector::reverse_iterator it = data.rbegin(); number; ++it, --number) *it = pvDataCreate->createPVStructure(structure); size_t newLength = data.size(); const_svector cdata(freeze(data)); swap(cdata); return newLength; }
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)); }
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; }
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; }
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()); }
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); }
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()); } }
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"); }