more work on examples; documentation is only changed up to exampleServer

This commit is contained in:
Marty Kraimer
2014-02-06 16:46:47 -05:00
parent 94bd84211b
commit 9a798bc05a
81 changed files with 2361 additions and 605 deletions
+3
View File
@@ -3,14 +3,17 @@ TOP=..
include $(TOP)/configure/CONFIG
PROD_HOST += testPVCopy
testPVCopy_SRCS += powerSupply.cpp
testPVCopy_SRCS += testPVCopy.cpp
testPVCopy_LIBS += pvDatabase pvAccess pvData Com
PROD_HOST += testPVRecord
testPVRecord_SRCS += powerSupply.cpp
testPVRecord_SRCS += testPVRecord.cpp
testPVRecord_LIBS += pvDatabase pvAccess pvData Com
PROD_HOST += testExampleRecord
testExampleRecord_SRCS += powerSupply.cpp
testExampleRecord_SRCS += testExampleRecord.cpp
testExampleRecord_LIBS += pvDatabase pvAccess pvData Com
+181
View File
@@ -0,0 +1,181 @@
/* powerSupply.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
* @date 2013.04.02
*/
#include "powerSupply.h"
#include <pv/standardField.h>
#include <pv/standardPVField.h>
namespace epics { namespace pvDatabase {
using namespace epics::pvData;
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));
}
using namespace epics::pvData;
PowerSupplyPtr PowerSupply::create(
String const & recordName,
PVStructurePtr const & pvStructure)
{
PowerSupplyPtr pvRecord(
new PowerSupply(recordName,pvStructure));
if(!pvRecord->init()) pvRecord.reset();
return pvRecord;
}
PowerSupply::PowerSupply(
String const & recordName,
PVStructurePtr const & pvStructure)
: PVRecord(recordName,pvStructure)
{
}
PowerSupply::~PowerSupply()
{
}
void PowerSupply::destroy()
{
PVRecord::destroy();
}
bool PowerSupply::init()
{
initPVRecord();
PVStructurePtr pvStructure = getPVStructure();
PVFieldPtr pvField;
bool result;
pvField = pvStructure->getSubField("timeStamp");
if(pvField.get()==NULL) {
std::cerr << "no timeStamp" << std::endl;
return false;
}
result = pvTimeStamp.attach(pvField);
if(!result) {
std::cerr << "no timeStamp" << std::endl;
return false;
}
pvField = pvStructure->getSubField("alarm");
if(pvField.get()==NULL) {
std::cerr << "no alarm" << std::endl;
return false;
}
result = pvAlarm.attach(pvField);
if(!result) {
std::cerr << "no alarm" << std::endl;
return false;
}
String name;
name = "current.value";
pvField = pvStructure->getSubField(name);
if(pvField.get()==NULL) {
name = "current";
pvField = pvStructure->getSubField(name);
}
if(pvField.get()==NULL) {
std::cerr << "no current" << std::endl;
return false;
}
pvCurrent = pvStructure->getDoubleField(name);
if(pvCurrent.get()==NULL) return false;
name = "voltage.value";
pvField = pvStructure->getSubField(name);
if(pvField.get()==NULL) {
name = "voltage";
pvField = pvStructure->getSubField(name);
}
if(pvField.get()==NULL) {
std::cerr << "no voltage" << std::endl;
return false;
}
pvVoltage = pvStructure->getDoubleField(name);
if(pvVoltage.get()==NULL) return false;
name = "power.value";
pvField = pvStructure->getSubField(name);
if(pvField.get()==NULL) {
name = "power";
pvField = pvStructure->getSubField(name);
}
if(pvField.get()==NULL) {
std::cerr << "no power" << std::endl;
return false;
}
pvPower = pvStructure->getDoubleField(name);
if(pvPower.get()==NULL) return false;
return true;
}
void PowerSupply::process()
{
timeStamp.getCurrent();
pvTimeStamp.set(timeStamp);
double voltage = pvVoltage->get();
double power = pvPower->get();
if(voltage<1e-3 && voltage>-1e-3) {
alarm.setMessage("bad voltage");
alarm.setSeverity(majorAlarm);
pvAlarm.set(alarm);
return;
}
double current = power/voltage;
pvCurrent->put(current);
alarm.setMessage("");
alarm.setSeverity(noAlarm);
pvAlarm.set(alarm);
}
void PowerSupply::put(double power,double voltage)
{
pvPower->put(power);
pvVoltage->put(voltage);
}
double PowerSupply::getPower()
{
return pvPower->get();
}
double PowerSupply::getVoltage()
{
return pvVoltage->get();
}
double PowerSupply::getCurrent()
{
return pvCurrent->get();
}
}}
+58
View File
@@ -0,0 +1,58 @@
/* powerSupply.h */
/**
* 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
* @date 2013.04.02
*/
#ifndef POWERSUPPLY_H
#define POWERSUPPLY_H
#include <pv/pvDatabase.h>
#include <pv/timeStamp.h>
#include <pv/alarm.h>
#include <pv/pvTimeStamp.h>
#include <pv/pvAlarm.h>
namespace epics { namespace pvDatabase {
extern epics::pvData::PVStructurePtr createPowerSupply();
class PowerSupply;
typedef std::tr1::shared_ptr<PowerSupply> PowerSupplyPtr;
class PowerSupply :
public PVRecord
{
public:
POINTER_DEFINITIONS(PowerSupply);
static PowerSupplyPtr create(
epics::pvData::String const & recordName,
epics::pvData::PVStructurePtr const & pvStructure);
virtual ~PowerSupply();
virtual void destroy();
virtual bool init();
virtual void process();
void put(double power,double voltage);
double getPower();
double getVoltage();
double getCurrent();
private:
PowerSupply(epics::pvData::String const & recordName,
epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVDoublePtr pvCurrent;
epics::pvData::PVDoublePtr pvPower;
epics::pvData::PVDoublePtr pvVoltage;
epics::pvData::PVAlarm pvAlarm;
epics::pvData::PVTimeStamp pvTimeStamp;
epics::pvData::Alarm alarm;
epics::pvData::TimeStamp timeStamp;
};
}}
#endif /* POWERSUPPLY_H */
+3 -27
View File
@@ -29,7 +29,7 @@
#include <pv/standardPVField.h>
#include <pv/pvData.h>
#include <pv/pvAccess.h>
#include <pv/powerSupplyRecordTest.h>
#include "powerSupply.h"
using namespace std;
using std::tr1::static_pointer_cast;
@@ -38,30 +38,6 @@ using namespace epics::pvAccess;
using namespace epics::pvDatabase;
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));
}
void test()
@@ -86,9 +62,9 @@ void test()
pvRecord.reset();
recordName = "powerSupplyExample";
pvStructure.reset();
PowerSupplyPtr psr;
pvStructure = createPowerSupply();
PowerSupplyRecordTestPtr psr =
PowerSupplyRecordTest::create(recordName,pvStructure);
psr = PowerSupply::create("powerSupply",pvStructure);
if(psr.get()==NULL) {
cout << "PowerSupplyRecordTest::create failed" << endl;
return;
+4 -29
View File
@@ -26,7 +26,7 @@
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/channelProviderLocal.h>
#include <pv/powerSupplyRecordTest.h>
#include "powerSupply.h"
using namespace std;
@@ -73,32 +73,6 @@ static PVRecordPtr createScalarArray(
return PVRecord::create(recordName,pvStructure);
}
static PowerSupplyRecordTestPtr createPowerSupply(String const & recordName)
{
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 PowerSupplyRecordTest::create(recordName,
pvDataCreate->createPVStructure(
fieldCreate->createStructure(names,powerSupply)));
}
static void testPVScalar(
String const & valueNameRecord,
String const & valueNameCopy,
@@ -370,7 +344,7 @@ static void powerSupplyTest()
{
cout << endl << endl << "****powerSupplyTest****" << endl;
RequesterPtr requester(new MyRequester("exampleTest"));
PowerSupplyRecordTestPtr pvRecord;
PowerSupplyPtr pvRecord;
String request;
PVStructurePtr pvRequest;
PVRecordFieldPtr pvRecordField;
@@ -380,7 +354,8 @@ static void powerSupplyTest()
String valueNameCopy;
CreateRequest::shared_pointer createRequest = CreateRequest::create();
pvRecord = createPowerSupply("powerSupply");
PVStructurePtr pv = createPowerSupply();
pvRecord = PowerSupply::create("powerSupply",pv);
valueNameRecord = request = "power.value";
pvRequest = createRequest->createRequest(request);
builder.clear(); pvRequest->toString(&builder);
+4 -31
View File
@@ -26,15 +26,13 @@
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/pvData.h>
#include <pv/pvAccess.h>
#include <pv/pvCopy.h>
#include <pv/powerSupplyRecordTest.h>
#include "powerSupply.h"
using namespace std;
using std::tr1::static_pointer_cast;
using namespace epics::pvData;
using namespace epics::pvAccess;
using namespace epics::pvDatabase;
static PVRecordPtr createScalar(
@@ -57,32 +55,6 @@ static PVRecordPtr createScalarArray(
return PVRecord::create(recordName,pvStructure);
}
static PowerSupplyRecordTestPtr createPowerSupply(String const & recordName)
{
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 PowerSupplyRecordTest::create(recordName,
pvDataCreate->createPVStructure(
fieldCreate->createStructure(names,powerSupply)));
}
static void scalarTest()
{
cout << endl << endl << "****scalarTest****" << endl;
@@ -102,8 +74,9 @@ static void arrayTest()
static void powerSupplyTest()
{
cout << endl << endl << "****powerSupplyTest****" << endl;
PowerSupplyRecordTestPtr pvRecord;
pvRecord = createPowerSupply("powerSupply");
PVRecordPtr pvRecord;
PVStructurePtr pv = createPowerSupply();
pvRecord = PowerSupply::create("powerSupply",pv);
pvRecord->destroy();
}