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)); }
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; }
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 void testPostPut() { testDiag("== testPostPut =="); StructureConstPtr structure = fieldCreate->createFieldBuilder()-> add("alarm",standardField->alarm()) -> add("timeStamp",standardField->timeStamp()) -> addNestedStructure("power") -> add("value",pvDouble) -> add("alarm",standardField->alarm()) -> endNested()-> addNestedStructure("voltage") -> add("value",pvDouble) -> add("alarm",standardField->alarm()) -> endNested()-> addNestedStructure("current") -> add("value",pvDouble) -> add("alarm",standardField->alarm()) -> endNested()-> createStructure(); PvaClientPutDataPtr pvaData = PvaClientPutData::create(structure); PVStructurePtr pvStructure = pvaData->getPVStructure(); BitSetPtr change = pvaData->getChangedBitSet(); PVDoublePtr powerValue = pvStructure->getSubField<PVDouble>("power.value"); PVDoublePtr voltageValue = pvStructure->getSubField<PVDouble>("voltage.value"); PVDoublePtr currentValue = pvStructure->getSubField<PVDouble>("current.value"); size_t powerOffset = powerValue->getFieldOffset(); size_t voltageOffset = voltageValue->getFieldOffset(); size_t currentOffset = currentValue->getFieldOffset(); change->clear(); powerValue->put(1.0); voltageValue->put(2.0); currentValue->put(.5); testOk(change->cardinality()==3,"3 fields changed"); testOk(change->get(powerOffset),"power changed"); testOk(change->get(voltageOffset),"voltage changed"); testOk(change->get(currentOffset),"current changed"); }
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()); }
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"); }
StructureConstPtr NTMultiChannelBuilder::createStructure() { StandardFieldPtr standardField = getStandardField(); size_t nfields = 3; size_t extraCount = extraFieldNames.size(); nfields += extraCount; if(descriptor) ++nfields; if(alarm) ++nfields; if(timeStamp) ++nfields; if(severity) ++nfields; if(status) ++nfields; if(message) ++nfields; if(secondsPastEpoch) ++nfields; if(nanoseconds) ++nfields; if(userTag) ++nfields; FieldConstPtrArray fields(nfields); StringArray names(nfields); size_t ind = 0; names[ind] = "value"; if(valueType) { fields[ind++] = fieldCreate->createUnionArray(valueType); } else { fields[ind++] = fieldCreate->createVariantUnionArray(); } names[ind] = "channelName"; fields[ind++] = fieldCreate->createScalarArray(pvString); names[ind] = "isConnected"; fields[ind++] = fieldCreate->createScalarArray(pvBoolean); if(timeStamp) { names[ind] = "timeStamp"; fields[ind++] = standardField->timeStamp(); } if(alarm) { names[ind] = "alarm"; fields[ind++] = standardField->alarm(); } if(descriptor) { names[ind] = "descriptor"; fields[ind++] = fieldCreate->createScalar(pvString); } if(severity) { names[ind] = "severity"; fields[ind++] = fieldCreate->createScalarArray(pvInt); } if(status) { names[ind] = "status"; fields[ind++] = fieldCreate->createScalarArray(pvInt); } if(message) { names[ind] = "message"; fields[ind++] = fieldCreate->createScalarArray(pvString); } if(secondsPastEpoch) { names[ind] = "secondsPastEpoch"; fields[ind++] = fieldCreate->createScalarArray(pvLong); } if(nanoseconds) { names[ind] = "nanoseconds"; fields[ind++] = fieldCreate->createScalarArray(pvInt); } if(userTag) { names[ind] = "userTag"; fields[ind++] = fieldCreate->createScalarArray(pvInt); } for (size_t i = 0; i< extraCount; i++) { names[ind] = extraFieldNames[i]; fields[ind++] = extraFields[i]; } StructureConstPtr st = fieldCreate->createStructure(NTMultiChannel::URI,names,fields); reset(); return st; }
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"); }
StructureConstPtr NTNDArrayBuilder::createStructure() { enum { DISCRIPTOR_INDEX, TIMESTAMP_INDEX, ALARM_INDEX, DISPLAY_INDEX }; const size_t NUMBER_OF_INDICES = DISPLAY_INDEX+1; const size_t NUMBER_OF_STRUCTURES = 1 << NUMBER_OF_INDICES; Lock xx(mutex); static StructureConstPtr ntndarrayStruc[NUMBER_OF_STRUCTURES]; static UnionConstPtr valueType; static StructureConstPtr codecStruc; static StructureConstPtr dimensionStruc; static StructureConstPtr attributeStruc; StructureConstPtr returnedStruc; size_t index = 0; if (descriptor) index |= 1 << DISCRIPTOR_INDEX; if (timeStamp) index |= 1 << TIMESTAMP_INDEX; if (alarm) index |= 1 << ALARM_INDEX; if (display) index |= 1 << DISPLAY_INDEX; bool isExtended = !extraFieldNames.empty(); if (isExtended || !ntndarrayStruc[index]) { StandardFieldPtr standardField = getStandardField(); FieldBuilderPtr fb = fieldCreate->createFieldBuilder(); if (!valueType) { for (int i = pvBoolean; i < pvString; ++i) { ScalarType st = static_cast<ScalarType>(i); fb->addArray(std::string(ScalarTypeFunc::name(st)) + "Value", st); } valueType = fb->createUnion(); } if (!codecStruc) { codecStruc = fb->setId("codec_t")-> add("name", pvString)-> add("parameters", fieldCreate->createVariantUnion())-> createStructure(); } if (!dimensionStruc) { dimensionStruc = fb->setId("dimension_t")-> add("size", pvInt)-> add("offset", pvInt)-> add("fullSize", pvInt)-> add("binning", pvInt)-> add("reverse", pvBoolean)-> createStructure(); } if (!attributeStruc) { attributeStruc = NTNDArrayAttribute::createBuilder()->createStructure(); } fb->setId(NTNDArray::URI)-> add("value", valueType)-> add("codec", codecStruc)-> add("compressedSize", pvLong)-> add("uncompressedSize", pvLong)-> addArray("dimension", dimensionStruc)-> add("uniqueId", pvInt)-> add("dataTimeStamp", standardField->timeStamp())-> addArray("attribute", attributeStruc); if (descriptor) fb->add("descriptor", pvString); if (alarm) fb->add("alarm", standardField->alarm()); if (timeStamp) fb->add("timeStamp", standardField->timeStamp()); if (display) fb->add("display", standardField->display()); size_t extraCount = extraFieldNames.size(); for (size_t i = 0; i< extraCount; i++) fb->add(extraFieldNames[i], extraFields[i]); returnedStruc = fb->createStructure(); if (!isExtended) ntndarrayStruc[index] = returnedStruc; } else { return ntndarrayStruc[index]; } return returnedStruc; }
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 testDouble() { testDiag("== testDouble =="); StructureConstPtr structure = fieldCreate->createFieldBuilder() -> add("alarm",standardField->alarm()) -> add("timeStamp",standardField->timeStamp()) -> add("value",pvDouble) -> createStructure(); PvaClientPutDataPtr pvaData = PvaClientPutData::create(structure); PVDoublePtr pvDouble = pvaData->getPVStructure() -> getSubField<PVDouble>("value"); pvDouble->put(5.0); BitSetPtr change = pvaData->getChangedBitSet(); size_t valueOffset = pvDouble->getFieldOffset(); testOk(change->cardinality()==1,"1 field changed"); testOk(change->get(valueOffset),"value changed"); testOk(pvaData->hasValue(),"hasValue"); testOk(pvaData->isValueScalar(),"isValueScalar"); testOk(!pvaData->isValueScalarArray(),"!isValueScalarArray"); try { testOk(!!pvaData->getValue(), "getValue"); } catch (std::runtime_error e) { testFail("getValue exception '%s'", e.what()); } try { testOk(!!pvaData->getScalarValue(), "getScalarValue"); } catch (std::runtime_error e) { testFail("getScalarValue exception '%s'", e.what()); } try { testOk(!pvaData->getArrayValue(), "!getArrayValue"); } catch (std::runtime_error e) { testPass("getArrayValue exception '%s'", e.what()); } try { testOk(!pvaData->getScalarArrayValue(), "!getScalarArrayValue"); } catch (std::runtime_error e) { testPass("getScalarArrayValue exception '%s'", e.what()); } try { testOk(pvaData->getDouble() == 5.0, "getDouble value"); } catch (std::runtime_error e) { testFail("getDouble exception '%s'", e.what()); } try { testOk(pvaData->getString() == "5", "getString value"); } catch (std::runtime_error e) { testFail("getString exception '%s'", e.what()); } try { shared_vector<const double> value = pvaData->getDoubleArray(); testFail("getDoubleArray"); } catch (std::runtime_error e) { testPass("getDoubleArray exception '%s'", e.what()); } try { shared_vector<const string> value = pvaData->getStringArray(); testFail("getStringArray"); } catch (std::runtime_error e) { testPass("getStringArray exception '%s'", e.what()); } try { pvaData->putDouble(5.0); testPass("putDouble"); } catch (std::runtime_error e) { testFail("putDouble exception '%s'", e.what()); } try { pvaData->putString("1e5"); testPass("putString"); } catch (std::runtime_error e) { testFail("putString exception '%s'", e.what()); } try { size_t len = 2; shared_vector<double> val(len); for (size_t i=0; i<len; ++i) val[i] = (i+1) * 10.0; pvaData->putDoubleArray(freeze(val)); testFail("putDoubleArray"); } catch (std::runtime_error e) { testPass("putDoubleArray exception '%s'", e.what()); } try { size_t len = 2; shared_vector<string> val(len); val[0] = "one"; val[1] = "two"; pvaData->putStringArray(freeze(val)); testFail("putStringArray"); } catch (std::runtime_error e) { testPass("putStringArray exception '%s'", e.what()); } }