本文整理汇总了C++中TimeStamp::getCurrent方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeStamp::getCurrent方法的具体用法?C++ TimeStamp::getCurrent怎么用?C++ TimeStamp::getCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeStamp
的用法示例。
在下文中一共展示了TimeStamp::getCurrent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitEvent
bool PvaClientMultiMonitorDouble::waitEvent(double waitForEvent)
{
if(poll()) return true;
TimeStamp start;
start.getCurrent();
TimeStamp now;
while(true) {
epicsThreadSleep(.1);
if(poll()) return true;
now.getCurrent();
double diff = TimeStamp::diff(now,start);
if(diff>=waitForEvent) break;
}
return false;
}
示例2: schedulePeriodic
void Timer::schedulePeriodic(
TimerCallbackPtr const &timerCallback,
double delay,
double period)
{
if(isScheduled(timerCallback)) {
throw std::logic_error(string("already queued"));
}
{
Lock xx(mutex);
if(!alive) {
timerCallback->timerStopped();
return;
}
}
TimeStamp timeStamp;
timeStamp.getCurrent();
timeStamp += delay;
timerCallback->timeToRun.getCurrent();
timerCallback->timeToRun += delay;
timerCallback->period = period;
bool isFirst = false;
{
Lock xx(mutex);
addElement(timerCallback);
if(timerCallback.get()==head.get()) isFirst = true;
}
if(isFirst) waitForWork.signal();
}
示例3: run
void VectorPerformanceThread::run()
{
TimeStamp timeStamp;
TimeStamp timeStampLast;
timeStampLast.getCurrent();
int nSinceLastReport = 0;
while(true) {
if(delay>0.0) epicsThreadSleep(delay);
{
Lock lock(mutex);
if(isDestroyed) {
runReturned = true;
return;
}
}
timeStamp.getCurrent();
double diff = TimeStamp::diff(timeStamp,timeStampLast);
if(diff>=1.0) {
cout << "thread" << threadNumber;
cout << " value " << value;
cout << " time " << diff;
double iterations = nSinceLastReport;
iterations /= diff;
cout << " iterations/sec " << iterations;
double elementSize = size;
double elementsPerSecond = elementSize*nSinceLastReport;
elementsPerSecond /= diff;
elementsPerSecond /= 1e6;
cout << " elements/sec " << elementsPerSecond << "million" << endl;
cout.flush();
timeStampLast = timeStamp;
nSinceLastReport = 0;
}
++nSinceLastReport;
++value;
for(size_t i=0; i<size; ++i) vector[i] = value;
}
}
示例4: dump
void Timer::dump(std::ostream& o)
{
Lock xx(mutex);
if(!alive) return;
TimeStamp currentTime;
TimerCallbackPtr nodeToCall(head);
currentTime.getCurrent();
while(true) {
if(nodeToCall.get()==NULL) return;
TimeStamp timeToRun = nodeToCall->timeToRun;
double period = nodeToCall->period;
double diff = TimeStamp::diff(timeToRun,currentTime);
o << "timeToRun " << diff << " period " << period << std::endl;
nodeToCall = nodeToCall->next;
}
}
示例5: run
void Timer::run()
{
TimeStamp currentTime;
while(true) {
double period = 0.0;
TimerCallbackPtr nodeToCall;
{
Lock xx(mutex);
currentTime.getCurrent();
if (!alive) break;
TimerCallbackPtr timerCallback = head;
if(timerCallback.get()!=NULL) {
double diff = TimeStamp::diff(
timerCallback->timeToRun,currentTime);
if(diff<=0.0) {
nodeToCall = timerCallback;
nodeToCall->onList = false;
head = head->next;
period = timerCallback->period;
if(period>0.0) {
timerCallback->timeToRun += period;
addElement(timerCallback);
}
timerCallback = head;
}
}
}
if(nodeToCall.get()!=NULL) {
nodeToCall->callback();
}
{
Lock xx(mutex);
if(!alive) break;
}
if(head.get()==NULL) {
waitForWork.wait();
} else {
double delay = TimeStamp::diff(head->timeToRun,currentTime);
waitForWork.wait(delay);
}
}
waitForDone.signal();
}
示例6: setDataTimeStamp
void NTNDArrayRecord::setDataTimeStamp()
{
// Create PVTimeStamp and TimeStamp objects
// attach the dataTimeStamp field to the PVTimeStamp
// TimeStamp object should get the current time
// Use it to set the dataTimeStamp field
#if 0
PVTimeStamp timeStamp;
timeStamp.attach(pvStructure->getSubField<PVStructure>("dataTimeStamp"));
TimeStamp current;
current.getCurrent();
timeStamp.set(current);
#else
// Alternatively you can use the member objects already created
// for you and do the attaching once.
dataTimeStamp.getCurrent();
pvDataTimeStamp.set(dataTimeStamp);
#endif
}
示例7: test_ntscalar
void test_ntscalar()
{
testDiag("test_ntscalar");
NTScalarBuilderPtr builder = NTScalar::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTScalarPtr ntScalar = builder->
value(pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addDisplay()->
addControl()->
add("valueAlarm",standardField->intAlarm()) ->
create();
testOk1(ntScalar.get() != 0);
testOk1(NTScalar::is_a(ntScalar->getPVStructure()));
testOk1(NTScalar::isCompatible(ntScalar->getPVStructure()));
testOk1(ntScalar->getPVStructure().get() != 0);
testOk1(ntScalar->getValue().get() != 0);
testOk1(ntScalar->getDescriptor().get() != 0);
testOk1(ntScalar->getAlarm().get() != 0);
testOk1(ntScalar->getTimeStamp().get() != 0);
testOk1(ntScalar->getDisplay().get() != 0);
testOk1(ntScalar->getControl().get() != 0);
//
// example how to set a value
//
ntScalar->getValue<PVInt>()->put(12);
//
// example how to get a value
//
int32 value = ntScalar->getValue<PVInt>()->get();
testOk1(value == 12);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntScalar->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntScalar->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// display ops
//
PVDisplay pvDisplay;
if (ntScalar->attachDisplay(pvDisplay))
{
testPass("display attach");
// example how to set an display
Display display;
display.setLow(-15);
display.setHigh(15);
display.setDescription("This is a test scalar");
display.setFormat("%d");
display.setUnits("A");
pvDisplay.set(display);
}
else
testFail("display attach fail");
//
//.........这里部分代码省略.........
示例8: test_ntenum
void test_ntenum()
{
testDiag("test_ntenum");
NTEnumBuilderPtr builder = NTEnum::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTEnumPtr ntEnum = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("valueAlarm",standardField->intAlarm()) ->
create();
testOk1(ntEnum.get() != 0);
testOk1(NTEnum::is_a(ntEnum->getPVStructure()));
testOk1(NTEnum::isCompatible(ntEnum->getPVStructure()));
testOk1(ntEnum->getPVStructure().get() != 0);
testOk1(ntEnum->getValue().get() != 0);
testOk1(ntEnum->getDescriptor().get() != 0);
testOk1(ntEnum->getAlarm().get() != 0);
testOk1(ntEnum->getTimeStamp().get() != 0);
//
// example how to set a value
//
PVStructurePtr pvValue = ntEnum->getValue();
//PVStringArray pvChoices = pvValue->getSubField<PVStringArray>("choices");
PVStringArray::svector choices(2);
choices[0] = "Off";
choices[1] = "On";
pvValue->getSubField<PVStringArray>("choices")->replace(freeze(choices));
pvValue->getSubField<PVInt>("index")->put(1);
//
// example how to get a value
//
int32 value = ntEnum->getValue()->getSubField<PVInt>("index")->get();
testOk1(value == 1);
PVStringArrayPtr pvChoices = ntEnum->getValue()->getSubField<PVStringArray>("choices");
std::string choice0 = pvChoices->view()[0];
std::string choice1 = pvChoices->view()[1];
testOk1(choice0 == "Off");
testOk1(choice1 == "On");
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntEnum->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntEnum->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntEnum->getDescriptor()->put("This is a test NTEnum");
// dump ntEnum
std::cout << *ntEnum->getPVStructure() << std::endl;
}
示例9: test_ntcontinuum
//.........这里部分代码省略.........
//
PVDoubleArray::svector newValue;
newValue.push_back(1.0);
newValue.push_back(2.0);
newValue.push_back(10.0);
newValue.push_back(20.0);
newValue.push_back(100.0);
newValue.push_back(200.0);
PVDoubleArrayPtr pvValueField = ntContinuum->getValue();
pvValueField->replace(freeze(newValue));
//
// example how to get values
//
PVDoubleArray::const_svector value(pvValueField->view());
testOk1(value.size() == 6);
testOk1(value[0] == 1.0);
testOk1(value[1] == 2.0);
testOk1(value[2] == 10.0);
testOk1(value[3] == 20.0);
testOk1(value[4] == 100.0);
testOk1(value[5] == 200.0);
//
// example how to set units
//
PVStringArray::svector newUnits;
newUnits.push_back("s");
newUnits.push_back("ms");
newUnits.push_back("us");
newUnits.push_back("s");
PVStringArrayPtr pvUnitsField = ntContinuum->getUnits();
pvUnitsField->replace(freeze(newUnits));
//
// example how to get units
//
PVStringArray::const_svector units(pvUnitsField->view());
testOk1(units.size() == 4);
testOk1(units[0] == "s");
testOk1(units[1] == "ms");
testOk1(units[2] == "us");
testOk1(units[3] == "s");
//
// test isValid
//
testOk1(ntContinuum->isValid());
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntContinuum->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntContinuum->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntContinuum->getDescriptor()->put("This is a test NTContinuum");
// dump NTContinuum
std::cout << *ntContinuum->getPVStructure() << std::endl;
}
示例10: test_nthistogram
void test_nthistogram()
{
testDiag("test_nthistogram");
NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTHistogramPtr ntHistogram = builder->
value(pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
create();
testOk1(ntHistogram.get() != 0);
testOk1(ntHistogram->getPVStructure().get() != 0);
testOk1(ntHistogram->getDescriptor().get() != 0);
testOk1(ntHistogram->getAlarm().get() != 0);
testOk1(ntHistogram->getTimeStamp().get() != 0);
testOk1(ntHistogram->getRanges().get() != 0);
testOk1(ntHistogram->getValue().get() != 0);
testOk1(ntHistogram->getValue<PVIntArray>().get() != 0);
//
// example how to set ranges
//
PVDoubleArray::svector newRanges;
newRanges.push_back(-100.0);
newRanges.push_back(0.0);
newRanges.push_back(100.0);
PVDoubleArrayPtr pvRangesField = ntHistogram->getRanges();
pvRangesField->replace(freeze(newRanges));
//
// example how to get ranges
//
PVDoubleArray::const_svector ranges(pvRangesField->view());
testOk1(ranges.size() == 3);
testOk1(ranges[0] == -100.0);
testOk1(ranges[1] == 0.0);
testOk1(ranges[2] == 100.0);
//
// example how to set value
//
PVIntArray::svector newValue;
newValue.push_back(1);
newValue.push_back(2);
PVIntArrayPtr pvValueField = ntHistogram->getValue<PVIntArray>();
pvValueField->replace(freeze(newValue));
//
// example how to get values for each bin
//
PVIntArray::const_svector value(pvValueField->view());
testOk1(value.size() == 2);
testOk1(value[0] == 1);
testOk1(value[1] == 2);
//
// test isValid
//
testOk1(ntHistogram->isValid());
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntHistogram->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntHistogram->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
//.........这里部分代码省略.........
示例11: request
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);
}
示例12: testTimeStamp
void testTimeStamp(FILE *fd,FILE *auxfd)
{
assert(nanoSecPerSec==1000000000);
TimeStamp current;
current.getCurrent();
fprintf(auxfd,"current %lli %i milliSec %lli\n",
(long long)current.getSecondsPastEpoch(),
current.getNanoSeconds(),
(long long)current.getMilliseconds());
time_t tt;
current.toTime_t(tt);
struct tm ctm;
memcpy(&ctm,localtime(&tt),sizeof(struct tm));
fprintf(auxfd,
"%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d isDst %s\n",
ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
current.getNanoSeconds(),
(ctm.tm_isdst==0) ? "false" : "true");
tt = time(&tt);
current.fromTime_t(tt);
fprintf(auxfd,"fromTime_t\ncurrent %lli %i milliSec %lli\n",
(long long)current.getSecondsPastEpoch(),
current.getNanoSeconds(),
(long long)current.getMilliseconds());
current.toTime_t(tt);
memcpy(&ctm,localtime(&tt),sizeof(struct tm));
fprintf(auxfd,
"%4.4d.%2.2d.%2.2d %2.2d:%2.2d:%2.2d %d isDst %s\n",
ctm.tm_year+1900,ctm.tm_mon + 1,ctm.tm_mday,
ctm.tm_hour,ctm.tm_min,ctm.tm_sec,
current.getNanoSeconds(),
(ctm.tm_isdst==0) ? "false" : "true");
TimeStamp right;
TimeStamp left;
right.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
double diff;
diff = TimeStamp::diff(left,right);
if(debug) fprintf(fd,"diff %e\n",diff);
assert(diff==0.0);
assert((left==right));
assert(!(left!=right));
assert((left<=right));
assert(!(left<right));
assert((left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch()+1,current.getNanoSeconds());
diff = TimeStamp::diff(left,right);
if(debug) fprintf(fd,"diff %e\n",diff);
assert(diff==1.0);
assert(!(left==right));
assert((left!=right));
assert(!(left<=right));
assert(!(left<right));
assert((left>=right));
assert((left>right));
left.put(current.getSecondsPastEpoch()-1,current.getNanoSeconds());
diff = TimeStamp::diff(left,right);
if(debug) fprintf(fd,"diff %e\n",diff);
assert(diff==-1.0);
assert(!(left==right));
assert((left!=right));
assert((left<=right));
assert((left<right));
assert(!(left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-nanoSecPerSec);
diff = TimeStamp::diff(left,right);
if(debug) fprintf(fd,"diff %e\n",diff);
assert(diff==-1.0);
assert(!(left==right));
assert((left!=right));
assert((left<=right));
assert((left<right));
assert(!(left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-1);
diff = TimeStamp::diff(left,right);
if(debug) fprintf(fd,"diff %e\n",diff);
assert(diff<0.0);
assert(!(left==right));
assert((left!=right));
assert((left<=right));
assert((left<right));
assert(!(left>=right));
assert(!(left>right));
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
left += .1;
diff = TimeStamp::diff(left,right);
if(debug) fprintf(fd,"diff %e\n",diff);
left.put(current.getSecondsPastEpoch(),current.getNanoSeconds());
int64 inc = -1;
left += inc;
diff = TimeStamp::diff(left,right);
assert(diff==-1.0);
fprintf(fd,"PASSED\n");
}
示例13: test_nttable
void test_nttable()
{
testDiag("test_nttable");
NTTableBuilderPtr builder = NTTable::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTTablePtr ntTable = builder->
addColumn("column0", pvDouble)->
addColumn("column1", pvString)->
addColumn("column2", pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
create();
testOk1(ntTable.get() != 0);
testOk1(ntTable->getPVStructure().get() != 0);
testOk1(ntTable->getDescriptor().get() != 0);
testOk1(ntTable->getAlarm().get() != 0);
testOk1(ntTable->getTimeStamp().get() != 0);
testOk1(ntTable->getLabels().get() != 0);
testOk1(ntTable->getColumn<PVDoubleArray>("column0").get() != 0);
testOk1(ntTable->getColumn<PVStringArray>("column1").get() != 0);
testOk1(ntTable->getColumn<PVIntArray>("column2").get() != 0);
testOk1(ntTable->getColumn("invalid").get() == 0);
//
// example how to set column values
//
PVIntArray::svector newValues;
newValues.push_back(1);
newValues.push_back(2);
newValues.push_back(8);
PVIntArrayPtr intColumn = ntTable->getColumn<PVIntArray>("column2");
intColumn->replace(freeze(newValues));
//
// example how to get column values
//
PVIntArray::const_svector values(intColumn->view());
testOk1(values.size() == 3);
testOk1(values[0] == 1);
testOk1(values[1] == 2);
testOk1(values[2] == 8);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntTable->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntTable->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntTable->getDescriptor()->put("This is a test NTTable");
// dump NTTable
std::cout << *ntTable->getPVStructure() << std::endl;
}
示例14: testCopy
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");
}
示例15: test_ntnameValue
void test_ntnameValue()
{
testDiag("test_ntnameValue");
NTNameValueBuilderPtr builder = NTNameValue::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTNameValuePtr ntNameValue = builder->
value(pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
create();
testOk1(ntNameValue.get() != 0);
testOk1(NTNameValue::is_a(ntNameValue->getPVStructure()));
testOk1(NTNameValue::isCompatible(ntNameValue->getPVStructure()));
testOk1(ntNameValue->getPVStructure().get() != 0);
testOk1(ntNameValue->getDescriptor().get() != 0);
testOk1(ntNameValue->getAlarm().get() != 0);
testOk1(ntNameValue->getTimeStamp().get() != 0);
testOk1(ntNameValue->getName().get() != 0);
testOk1(ntNameValue->getValue().get() != 0);
//
// example how to set name
//
PVStringArray::svector newName;
newName.push_back("name1");
newName.push_back("name2");
newName.push_back("name3");
PVStringArrayPtr pvNameField = ntNameValue->getName();
pvNameField->replace(freeze(newName));
//
// example how to get name
//
PVStringArray::const_svector name(pvNameField->view());
testOk1(name.size() == 3);
testOk1(name[0] == "name1");
testOk1(name[1] == "name2");
testOk1(name[2] == "name3");
//
// example how to set value
//
PVIntArray::svector newValue;
newValue.push_back(1);
newValue.push_back(2);
newValue.push_back(8);
PVIntArrayPtr pvValueField = ntNameValue->getValue<PVIntArray>();
pvValueField->replace(freeze(newValue));
//
// example how to get column value
//
PVIntArray::const_svector value(pvValueField->view());
testOk1(value.size() == 3);
testOk1(value[0] == 1);
testOk1(value[1] == 2);
testOk1(value[2] == 8);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntNameValue->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntNameValue->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
//.........这里部分代码省略.........