all EasyChannel methods are implemented except channelArray; EasyMultiChannel not started.
This commit is contained in:
+39
-19
@@ -1,27 +1,47 @@
|
||||
TOP=..
|
||||
# Makefile for the pvAccess tests
|
||||
|
||||
TOP = ..
|
||||
include $(TOP)/configure/CONFIG
|
||||
#----------------------------------------
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
|
||||
TESTPROD_HOST += testEasyPutData
|
||||
testEasyPutData_SRCS = testEasyPutData
|
||||
testHarness_SRCS += testEasyPutData.cpp
|
||||
TESTS += testEasyPutData
|
||||
|
||||
TESTPROD_HOST += testEasyGetData
|
||||
testEasyGetData_SRCS = testEasyGetData
|
||||
testHarness_SRCS += testEasyGetData.cpp
|
||||
TESTS += testEasyGetData
|
||||
|
||||
TESTPROD_HOST += testEasyMonitorData
|
||||
testEasyMonitorData_SRCS = testEasyMonitorData
|
||||
testHarness_SRCS += testEasyMonitorData.cpp
|
||||
TESTS += testEasyMonitorData
|
||||
|
||||
TESTPROD_HOST += testEasyPutGetMonitor
|
||||
testEasyPutGetMonitor_SRCS = testEasyPutGetMonitor
|
||||
testHarness_SRCS += testEasyPutGetMonitor.cpp
|
||||
TESTS += testEasyPutGetMonitor
|
||||
|
||||
TESTPROD_HOST += testEasyPutGet
|
||||
testEasyPutGet_SRCS = testEasyPutGet
|
||||
testHarness_SRCS += testEasyPutGet.cpp
|
||||
TESTS += testEasyPutGet
|
||||
|
||||
|
||||
PROD_HOST += exampleEasyPVStructure
|
||||
exampleEasyPVStructure_SRCS += exampleEasyPVStructure.cpp
|
||||
exampleEasyPVStructure_LIBS += easyPVA
|
||||
exampleEasyPVStructure_LIBS += pvAccess
|
||||
exampleEasyPVStructure_LIBS += pvData
|
||||
exampleEasyPVStructure_LIBS += Com
|
||||
PROD_LIBS += easyPVA pvAccess pvData Com
|
||||
|
||||
PROD_HOST += exampleEasyGet
|
||||
exampleEasyGet_SRCS += exampleEasyGet.cpp
|
||||
exampleEasyGet_LIBS += easyPVA
|
||||
exampleEasyGet_LIBS += pvAccess
|
||||
exampleEasyGet_LIBS += pvData
|
||||
exampleEasyGet_LIBS += Com
|
||||
testHarness_SRCS += easyAllTests.c
|
||||
|
||||
#===========================
|
||||
PROD_vxWorks = vxTestHarness
|
||||
vxTestHarness_SRCS += $(testHarness_SRCS)
|
||||
TESTSPEC_vxWorks = vxTestHarness.$(MUNCH_SUFFIX); easyAllTests
|
||||
|
||||
PROD_RTEMS += rtemsTestHarness
|
||||
rtemsTestHarness_SRCS += rtemsTestHarness.c rtemsConfig.c
|
||||
rtemsTestHarness_SRCS += $(testHarness_SRCS)
|
||||
TESTSPEC_RTEMS = rtemsTestHarness.$(MUNCH_SUFFIX); easyAllTests
|
||||
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Run EasyPVA tests as a batch.
|
||||
*
|
||||
* Do *not* include performance measurements here, they don't help to
|
||||
* prove functionality (which is the point of this convenience routine).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <epicsThread.h>
|
||||
#include <epicsUnitTest.h>
|
||||
|
||||
int testEasyGetData(void);
|
||||
int testEasyPutData(void);
|
||||
int testEasyMonitorData(void);
|
||||
int testEasyPutGetMonitor(void);
|
||||
int testEasyPutGet(void);
|
||||
|
||||
void easyAllTests(void)
|
||||
{
|
||||
testHarness();
|
||||
runTest(testEasyGetData);
|
||||
runTest(testEasyPutData);
|
||||
runTest(testEasyMonitorData);
|
||||
runTest(testEasyPutMonitor);
|
||||
runTest(testEasyPut);
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/*exampleEasyGet.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
|
||||
static void exampleDouble(EasyPVAPtr const &easyPVA)
|
||||
{
|
||||
cout << "example double scalar\n";
|
||||
double value;
|
||||
try {
|
||||
cout << "short way\n";
|
||||
value = easyPVA->channel("exampleDouble")->get()->getDouble();
|
||||
cout << "as double " << value << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "long way\n";
|
||||
EasyChannelPtr easyChannel = easyPVA->createChannel("exampleDouble");
|
||||
easyChannel->connect(2.0);
|
||||
EasyGetPtr easyGet = easyChannel->createGet();
|
||||
value = easyGet->getDouble();
|
||||
cout << "as double " << value << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void exampleDoubleArray(EasyPVAPtr const &easyPVA)
|
||||
{
|
||||
cout << "example double array\n";
|
||||
shared_vector<double> value;
|
||||
try {
|
||||
cout << "short way\n";
|
||||
value = easyPVA->createChannel("exampleDoubleArray")->createGet()->getDoubleArray();
|
||||
cout << "as doubleArray " << value << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "long way\n";
|
||||
EasyChannelPtr easyChannel = easyPVA->createChannel("exampleDoubleArray");
|
||||
easyChannel->connect(2.0);
|
||||
EasyGetPtr easyGet = easyChannel->createGet();
|
||||
value = easyGet->getDoubleArray();
|
||||
cout << "as doubleArray " << value << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void examplePowerSupply(EasyPVAPtr const &easyPVA)
|
||||
{
|
||||
cout << "example powerSupply\n";
|
||||
PVStructurePtr pvStructure;
|
||||
try {
|
||||
cout << "short way\n";
|
||||
pvStructure = easyPVA->createChannel("examplePowerSupply")->createGet("field()")->getPVStructure();
|
||||
cout << pvStructure << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
exampleDouble(easyPVA);
|
||||
exampleDoubleArray(easyPVA);
|
||||
examplePowerSupply(easyPVA);
|
||||
cout << "done\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*exampleEasyPVStructure.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
|
||||
StandardPVFieldPtr standardPVField = getStandardPVField();
|
||||
EasyPVStructurePtr easyStruct = easyPVA->createEasyPVStructure();
|
||||
PVStructurePtr pvStructure = standardPVField->scalar(pvDouble,"alarm,timeStamp");
|
||||
easyStruct->setPVStructure(pvStructure);
|
||||
cout << easyStruct->getPVStructure() << endl;
|
||||
cout << "as double " << easyStruct->getDouble() << endl;
|
||||
cout << "as float " << easyStruct->getFloat() << endl;
|
||||
try {
|
||||
cout << "as ubyte " << easyStruct->getUByte() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
pvStructure = standardPVField->scalar(pvInt,"alarm,timeStamp");
|
||||
easyStruct->setPVStructure(pvStructure);
|
||||
cout << easyStruct->getPVStructure() << endl;
|
||||
cout << "as double " << easyStruct->getDouble() << endl;
|
||||
cout << "as float " << easyStruct->getFloat() << endl;
|
||||
cout << "as int " << easyStruct->getInt() << endl;
|
||||
cout << "as uint " << easyStruct->getUInt() << endl;
|
||||
cout << "as long " << easyStruct->getLong() << endl;
|
||||
cout << "as ulong " << easyStruct->getULong() << endl;
|
||||
try {
|
||||
cout << "as byte " << easyStruct->getByte() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "as ubyte " << easyStruct->getUByte() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "as short " << easyStruct->getShort() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "as ushort " << easyStruct->getUShort() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*testEasyGetData.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
static EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
|
||||
|
||||
void testDouble()
|
||||
{
|
||||
cout << "\nstarting testDouble\n";
|
||||
StructureConstPtr structure =
|
||||
fieldCreate->createFieldBuilder()->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
add("value",pvDouble) ->
|
||||
createStructure();
|
||||
|
||||
EasyGetDataPtr easyData = EasyGetData::create(structure);
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(easyData->getStructure());
|
||||
BitSetPtr bitSet = BitSetPtr(new BitSet(pvStructure->getNumberFields()));
|
||||
easyData->setData(pvStructure,bitSet);
|
||||
PVDoublePtr pvDouble = pvStructure->getSubField<PVDouble>("value");
|
||||
size_t valueOffset = pvDouble->getFieldOffset();
|
||||
BitSetPtr change = easyData->getBitSet();
|
||||
pvDouble->put(5.0);
|
||||
change->set(pvDouble->getFieldOffset());
|
||||
testOk(change->cardinality()==1,"num set bits 1");
|
||||
testOk(change->get(valueOffset)==true,"value changed");
|
||||
testOk(easyData->hasValue()==true,"hasValue");
|
||||
testOk(easyData->isValueScalar()==true,"isValueScalar");
|
||||
testOk(easyData->isValueScalarArray()==false,"isValueScalarArray");
|
||||
bool result;
|
||||
result = false;
|
||||
if(easyData->getValue()) result = true;
|
||||
testOk(result==true,"getValue");
|
||||
result = false;
|
||||
if(easyData->getScalarValue()) result = true;
|
||||
testOk(result==true,"getScalarValue");
|
||||
try {
|
||||
easyData->getArrayValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "getArrayValue " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
easyData->getScalarArrayValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getScalarArrayValue " << e.what() << endl;
|
||||
}
|
||||
cout << "as double " << easyData->getDouble() << endl;
|
||||
cout << "as string " << easyData->getString() << endl;
|
||||
try {
|
||||
shared_vector<const double> value = easyData->getDoubleArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getDoubleArray " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
shared_vector<const string> value = easyData->getStringArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getStringArray " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void testDoubleArray()
|
||||
{
|
||||
cout << "\nstarting testDoubleArray\n";
|
||||
StructureConstPtr structure =
|
||||
fieldCreate->createFieldBuilder()->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
addArray("value",pvDouble) ->
|
||||
createStructure();
|
||||
|
||||
EasyGetDataPtr easyData = EasyGetData::create(structure);
|
||||
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(easyData->getStructure());
|
||||
BitSetPtr bitSet = BitSetPtr(new BitSet(pvStructure->getNumberFields()));
|
||||
easyData->setData(pvStructure,bitSet);
|
||||
PVDoubleArrayPtr pvalue = easyData->getPVStructure()->getSubField<PVDoubleArray>("value");
|
||||
BitSetPtr change = easyData->getBitSet();
|
||||
size_t valueOffset = pvalue->getFieldOffset();
|
||||
size_t len = 5;
|
||||
shared_vector<double> value(len);
|
||||
for(size_t i=0; i<len; ++i) value[i] = i*10.0;
|
||||
pvalue->replace(freeze(value));
|
||||
change->set(valueOffset);
|
||||
testOk(change->cardinality()==1,"num set bits 1");
|
||||
testOk(change->get(valueOffset)==true,"value changed");
|
||||
testOk(easyData->hasValue()==true,"hasValue");
|
||||
testOk(easyData->isValueScalar()==false,"isValueScalar");
|
||||
testOk(easyData->isValueScalarArray()==true,"isValueScalarArray");
|
||||
bool result;
|
||||
result = false;
|
||||
if(easyData->getValue()) result = true;
|
||||
testOk(result==true,"getValue");
|
||||
result = false;
|
||||
if(easyData->getArrayValue()) result = true;
|
||||
testOk(result==true,"getArrayValue");
|
||||
result = false;
|
||||
if(easyData->getScalarArrayValue()) result = true;
|
||||
testOk(result==true,"getScalarValue");
|
||||
try {
|
||||
easyData->getScalarValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getScalarValue " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "as double " << easyData->getDouble() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getDouble " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
string val = easyData->getString();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getString " << e.what() << endl;
|
||||
}
|
||||
cout << "as doubleArray " << easyData->getDoubleArray() << endl;
|
||||
try {
|
||||
shared_vector<const string> value = easyData->getStringArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getStringArray " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
MAIN(testEasyGetData)
|
||||
{
|
||||
cout << "\nstarting testEasyGetData\n";
|
||||
testPlan(15);
|
||||
testDouble();
|
||||
testDoubleArray();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*testEasyMonitorData.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
static EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
|
||||
|
||||
void testDouble()
|
||||
{
|
||||
cout << "\nstarting testDouble\n";
|
||||
StructureConstPtr structure =
|
||||
fieldCreate->createFieldBuilder()->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
add("value",pvDouble) ->
|
||||
createStructure();
|
||||
|
||||
EasyMonitorDataPtr easyData = EasyMonitorData::create(structure);
|
||||
MonitorElementPtr monitorElement(new MonitorElement(pvDataCreate->createPVStructure(easyData->getStructure())));
|
||||
easyData->setData(monitorElement);
|
||||
PVDoublePtr pvDouble = easyData->getPVStructure()->getSubField<PVDouble>("value");
|
||||
size_t valueOffset = pvDouble->getFieldOffset();
|
||||
BitSetPtr change = easyData->getChangedBitSet();
|
||||
pvDouble->put(5.0);
|
||||
change->set(pvDouble->getFieldOffset());
|
||||
testOk(change->cardinality()==1,"num set bits 1");
|
||||
testOk(change->get(valueOffset)==true,"value changed");
|
||||
testOk(easyData->hasValue()==true,"hasValue");
|
||||
testOk(easyData->isValueScalar()==true,"isValueScalar");
|
||||
testOk(easyData->isValueScalarArray()==false,"isValueScalarArray");
|
||||
bool result;
|
||||
result = false;
|
||||
if(easyData->getValue()) result = true;
|
||||
testOk(result==true,"getValue");
|
||||
result = false;
|
||||
if(easyData->getScalarValue()) result = true;
|
||||
testOk(result==true,"getScalarValue");
|
||||
try {
|
||||
easyData->getArrayValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "getArrayValue " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
easyData->getScalarArrayValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getScalarArrayValue " << e.what() << endl;
|
||||
}
|
||||
cout << "as double " << easyData->getDouble() << endl;
|
||||
cout << "as string " << easyData->getString() << endl;
|
||||
try {
|
||||
shared_vector<const double> value = easyData->getDoubleArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getDoubleArray " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
shared_vector<const string> value = easyData->getStringArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getStringArray " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void testDoubleArray()
|
||||
{
|
||||
cout << "\nstarting testDoubleArray\n";
|
||||
StructureConstPtr structure =
|
||||
fieldCreate->createFieldBuilder()->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
addArray("value",pvDouble) ->
|
||||
createStructure();
|
||||
|
||||
EasyMonitorDataPtr easyData = EasyMonitorData::create(structure);
|
||||
MonitorElementPtr monitorElement(new MonitorElement(pvDataCreate->createPVStructure(easyData->getStructure())));
|
||||
easyData->setData(monitorElement);
|
||||
PVDoubleArrayPtr pvalue = easyData->getPVStructure()->getSubField<PVDoubleArray>("value");
|
||||
BitSetPtr change = easyData->getChangedBitSet();
|
||||
size_t valueOffset = pvalue->getFieldOffset();
|
||||
size_t len = 5;
|
||||
shared_vector<double> value(len);
|
||||
for(size_t i=0; i<len; ++i) value[i] = i*10.0;
|
||||
pvalue->replace(freeze(value));
|
||||
change->set(valueOffset);
|
||||
testOk(change->cardinality()==1,"num set bits 1");
|
||||
testOk(change->get(valueOffset)==true,"value changed");
|
||||
testOk(easyData->hasValue()==true,"hasValue");
|
||||
testOk(easyData->isValueScalar()==false,"isValueScalar");
|
||||
testOk(easyData->isValueScalarArray()==true,"isValueScalarArray");
|
||||
bool result;
|
||||
result = false;
|
||||
if(easyData->getValue()) result = true;
|
||||
testOk(result==true,"getValue");
|
||||
result = false;
|
||||
if(easyData->getArrayValue()) result = true;
|
||||
testOk(result==true,"getArrayValue");
|
||||
result = false;
|
||||
if(easyData->getScalarArrayValue()) result = true;
|
||||
testOk(result==true,"getScalarValue");
|
||||
try {
|
||||
easyData->getScalarValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getScalarValue " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "as double " << easyData->getDouble() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getDouble " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
string val = easyData->getString();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getString " << e.what() << endl;
|
||||
}
|
||||
cout << "as doubleArray " << easyData->getDoubleArray() << endl;
|
||||
try {
|
||||
shared_vector<const string> value = easyData->getStringArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getStringArray " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
MAIN(testEasyMonitorData)
|
||||
{
|
||||
cout << "\nstarting testEasyMonitorData\n";
|
||||
testPlan(15);
|
||||
testDouble();
|
||||
testDoubleArray();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
/*testEasyData.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/bitSet.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
static EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
|
||||
static void testPostPut()
|
||||
{
|
||||
cout << "\nstarting testPostPut\n";
|
||||
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();
|
||||
|
||||
EasyPutDataPtr easyData = EasyPutData::create(structure);
|
||||
PVStructurePtr pvStructure = easyData->getPVStructure();
|
||||
BitSetPtr change = easyData->getBitSet();
|
||||
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);
|
||||
cout << "changed\n";
|
||||
cout << easyData->showChanged(cout) << endl;
|
||||
testOk(change->cardinality()==3,"num set bits 3");
|
||||
testOk(change->get(powerOffset)==true,"power changed");
|
||||
testOk(change->get(voltageOffset)==true,"voltage changed");
|
||||
testOk(change->get(currentOffset)==true,"current changed");
|
||||
}
|
||||
|
||||
void testDouble()
|
||||
{
|
||||
cout << "\nstarting testDouble\n";
|
||||
StructureConstPtr structure =
|
||||
fieldCreate->createFieldBuilder()->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
add("value",pvDouble) ->
|
||||
createStructure();
|
||||
|
||||
EasyPutDataPtr easyData = EasyPutData::create(structure);
|
||||
PVDoublePtr pvDouble = easyData->getPVStructure()->getSubField<PVDouble>("value");
|
||||
pvDouble->put(5.0);
|
||||
BitSetPtr change = easyData->getBitSet();
|
||||
size_t valueOffset = pvDouble->getFieldOffset();
|
||||
testOk(change->cardinality()==1,"num set bits 1");
|
||||
testOk(change->get(valueOffset)==true,"value changed");
|
||||
testOk(easyData->hasValue()==true,"hasValue");
|
||||
testOk(easyData->isValueScalar()==true,"isValueScalar");
|
||||
testOk(easyData->isValueScalarArray()==false,"isValueScalarArray");
|
||||
bool result;
|
||||
result = false;
|
||||
if(easyData->getValue()) result = true;
|
||||
testOk(result==true,"getValue");
|
||||
result = false;
|
||||
if(easyData->getScalarValue()) result = true;
|
||||
testOk(result==true,"getScalarValue");
|
||||
try {
|
||||
easyData->getArrayValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "getArrayValue " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
easyData->getScalarArrayValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getScalarArrayValue " << e.what() << endl;
|
||||
}
|
||||
cout << "as double " << easyData->getDouble() << endl;
|
||||
cout << "as string " << easyData->getString() << endl;
|
||||
try {
|
||||
shared_vector<const double> value = easyData->getDoubleArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getDoubleArray " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
shared_vector<const string> value = easyData->getStringArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getStringArray " << e.what() << endl;
|
||||
}
|
||||
easyData->putDouble(5.0);
|
||||
easyData->putString("1e5");
|
||||
try {
|
||||
size_t len = 2;
|
||||
shared_vector<double> val(len);
|
||||
for(size_t i=0; i<len; ++i) val[i] = (i+1)*10.0;
|
||||
easyData->putDoubleArray(freeze(val));
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " putDoubleArray " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
size_t len = 2;
|
||||
shared_vector<string> val(len);
|
||||
val[0] = "one"; val[1] = "two";
|
||||
easyData->putStringArray(freeze(val));
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " putStringArray " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void testDoubleArray()
|
||||
{
|
||||
cout << "\nstarting testDoubleArray\n";
|
||||
StructureConstPtr structure =
|
||||
fieldCreate->createFieldBuilder()->
|
||||
add("alarm",standardField->alarm()) ->
|
||||
add("timeStamp",standardField->timeStamp()) ->
|
||||
addArray("value",pvDouble) ->
|
||||
createStructure();
|
||||
|
||||
EasyPutDataPtr easyData = EasyPutData::create(structure);
|
||||
PVDoubleArrayPtr pvalue = easyData->getPVStructure()->getSubField<PVDoubleArray>("value");
|
||||
size_t len = 5;
|
||||
shared_vector<double> value(len);
|
||||
for(size_t i=0; i<len; ++i) value[i] = i*10.0;
|
||||
pvalue->replace(freeze(value));
|
||||
BitSetPtr change = easyData->getBitSet();
|
||||
size_t valueOffset = pvalue->getFieldOffset();
|
||||
testOk(change->cardinality()==1,"num set bits 1");
|
||||
testOk(change->get(valueOffset)==true,"value changed");
|
||||
testOk(easyData->hasValue()==true,"hasValue");
|
||||
testOk(easyData->isValueScalar()==false,"isValueScalar");
|
||||
testOk(easyData->isValueScalarArray()==true,"isValueScalarArray");
|
||||
bool result;
|
||||
result = false;
|
||||
if(easyData->getValue()) result = true;
|
||||
testOk(result==true,"getValue");
|
||||
result = false;
|
||||
if(easyData->getArrayValue()) result = true;
|
||||
testOk(result==true,"getArrayValue");
|
||||
result = false;
|
||||
if(easyData->getScalarArrayValue()) result = true;
|
||||
testOk(result==true,"getScalarValue");
|
||||
try {
|
||||
easyData->getScalarValue();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getScalarValue " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
cout << "as double " << easyData->getDouble() << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getDouble " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
string val = easyData->getString();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getString " << e.what() << endl;
|
||||
}
|
||||
cout << "as doubleArray " << easyData->getDoubleArray() << endl;
|
||||
try {
|
||||
shared_vector<const string> value = easyData->getStringArray();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " getStringArray " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
easyData->putDouble(5.0);
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " putDouble " << e.what() << endl;
|
||||
}
|
||||
try {
|
||||
easyData->putString("1e5");
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " putString " << e.what() << endl;
|
||||
}
|
||||
value = shared_vector<double>(len);
|
||||
for(size_t i=0; i<len; ++i) value[i] = (i+1)* 2;
|
||||
easyData->putDoubleArray(freeze(value));
|
||||
cout << "as doubleArray " << easyData->getDoubleArray() << endl;
|
||||
try {
|
||||
size_t len = 2;
|
||||
shared_vector<string> val(len);
|
||||
val[0] = "one"; val[1] = "two";
|
||||
easyData->putStringArray(freeze(val));
|
||||
cout << "as stringArray " << val << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << " putStringArray " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
MAIN(testEasyPutData)
|
||||
{
|
||||
cout << "\nstarting testEasyPutData\n";
|
||||
testPlan(19);
|
||||
testPostPut();
|
||||
testDouble();
|
||||
testDoubleArray();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*exampleEasyPutGet.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
|
||||
static void example(EasyPVAPtr const &easyPVA)
|
||||
{
|
||||
cout << "\nstarting channelPutGet example\n";
|
||||
try {
|
||||
EasyChannelPtr easyChannel = easyPVA->createChannel("examplePowerSupply");
|
||||
easyChannel->connect(2.0);
|
||||
testOk(true==true,"connected");
|
||||
EasyPutGetPtr putGet = easyChannel->createPutGet(
|
||||
"putField(power.value,voltage.value)getField()");
|
||||
EasyPutDataPtr putData = putGet->getPutData();
|
||||
testOk(true==true,"put connected");
|
||||
PVStructurePtr pvStructure = putData->getPVStructure();
|
||||
PVDoublePtr power = pvStructure->getSubField<PVDouble>("power.value");
|
||||
PVDoublePtr voltage = pvStructure->getSubField<PVDouble>("voltage.value");
|
||||
power->put(5.0);
|
||||
voltage->put(5.0);
|
||||
putGet->putGet();
|
||||
EasyGetDataPtr getData = putGet->getGetData();
|
||||
pvStructure = getData->getPVStructure();
|
||||
BitSetPtr bitSet = getData->getBitSet();
|
||||
cout << "changed " << getData->showChanged(cout) << endl;
|
||||
cout << "bitSet " << *bitSet << endl;
|
||||
power->put(6.0);
|
||||
putGet->putGet();
|
||||
pvStructure = getData->getPVStructure();
|
||||
bitSet = getData->getBitSet();
|
||||
cout << "changed " << getData->showChanged(cout) << endl;
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MAIN(testEasyPutGet)
|
||||
{
|
||||
cout << "\nstarting testEasyPutGet\n";
|
||||
testPlan(2);
|
||||
EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
example(easyPVA);
|
||||
cout << "done\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*exampleEasyPutGetMonitor.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::easyPVA;
|
||||
|
||||
|
||||
class MyMonitor : public EasyMonitorRequester
|
||||
{
|
||||
public:
|
||||
MyMonitor() {}
|
||||
virtual ~MyMonitor() {}
|
||||
virtual void event(EasyMonitorPtr monitor)
|
||||
{
|
||||
while(true) {
|
||||
if(!monitor->poll()) return;
|
||||
EasyMonitorDataPtr easyData = monitor->getData();
|
||||
cout << "changed\n";
|
||||
easyData->showChanged(cout);
|
||||
cout << "overrun\n";
|
||||
easyData->showOverrun(cout);
|
||||
monitor->releaseEvent();
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void exampleDouble(EasyPVAPtr const &easyPVA)
|
||||
{
|
||||
cout << "\nstarting exampleDouble\n";
|
||||
try {
|
||||
cout << "long way\n";
|
||||
EasyChannelPtr easyChannel = easyPVA->createChannel("exampleDouble");
|
||||
easyChannel->connect(2.0);
|
||||
testOk(true==true,"connected");
|
||||
EasyPutPtr put = easyChannel->createPut();
|
||||
EasyPutDataPtr putData = put->getData();
|
||||
testOk(true==true,"put connected");
|
||||
EasyGetPtr get = easyChannel->createGet();
|
||||
EasyGetDataPtr getData = get->getData();
|
||||
testOk(true==true,"get connected");
|
||||
EasyMonitorRequesterPtr requester(new MyMonitor());
|
||||
EasyMonitorPtr monitor = easyChannel->monitor(requester);
|
||||
testOk(true==true,"monitor connected");
|
||||
double out;
|
||||
double in;
|
||||
for(size_t i=0 ; i< 5; ++i) {
|
||||
out = i;
|
||||
putData->putDouble(out);
|
||||
put->put();
|
||||
get->get();
|
||||
in = getData->getDouble();
|
||||
cout << "out " << out << " in " << in << endl;
|
||||
}
|
||||
EasyProcessPtr process = easyChannel->createProcess();
|
||||
process->connect();
|
||||
process->process();
|
||||
} catch (std::runtime_error e) {
|
||||
cout << "exception " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MAIN(testEasyPutGetMonitor)
|
||||
{
|
||||
cout << "\nstarting testEasyPutGetMonitor\n";
|
||||
testPlan(4);
|
||||
EasyPVAPtr easyPVA = EasyPVA::create();
|
||||
exampleDouble(easyPVA);
|
||||
cout << "done\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user