12 #include <pv/pvData.h> 13 #include <pv/pvTimeStamp.h> 14 #include <pv/rpcService.h> 15 #include <pv/convert.h> 16 #include <pv/standardField.h> 17 #define epicsExportSharedSymbols 23 using std::tr1::static_pointer_cast;
28 namespace epics {
namespace pvDatabase {
30 ControlSupport::~ControlSupport()
35 epics::pvData::StructureConstPtr ControlSupport::controlField(ScalarType scalarType)
37 return FieldBuilder::begin()
39 ->add(
"limitLow", pvDouble)
40 ->add(
"limitHigh", pvDouble)
41 ->add(
"minStep", pvDouble)
42 ->add(
"outputValue", scalarType)
49 cerr <<
"ControlSupport IS DEPRECATED\n";
54 ControlSupport::ControlSupport(
PVRecordPtr const & pvRecord)
58 bool ControlSupport::init(PVFieldPtr
const & pv,PVFieldPtr
const & pvsup)
61 if(pv->getField()->getType()==epics::pvData::scalar) {
62 ScalarConstPtr s = static_pointer_cast<
const Scalar>(pv->getField());
63 if(ScalarTypeFunc::isNumeric(s->getScalarType())) {
64 pvValue = static_pointer_cast<PVScalar>(pv);
69 cout <<
"ControlSupport for record " << pvRecord->getRecordName()
70 <<
" failed because not numeric scalar\n";
73 pvControl = static_pointer_cast<PVStructure>(pvsup);
75 pvLimitLow = pvControl->getSubField<PVDouble>(
"limitLow");
76 pvLimitHigh = pvControl->getSubField<PVDouble>(
"limitHigh");
77 pvMinStep = pvControl->getSubField<PVDouble>(
"minStep");
78 pvOutputValue = pvControl->getSubField<PVScalar>(
"outputValue");
80 if(!pvControl || !pvLimitLow || !pvLimitHigh || !pvMinStep || !pvOutputValue) {
81 cout <<
"ControlSupport for record " << pvRecord->getRecordName()
82 <<
" failed because pvSupport not a valid control structure\n";
85 ConvertPtr convert = getConvert();
86 currentValue = convert->toDouble(pvValue);
91 bool ControlSupport::process()
93 ConvertPtr convert = getConvert();
94 double value = convert->toDouble(pvValue);
95 if(!isMinStep && value==currentValue)
return false;
96 double limitLow = pvLimitLow->get();
97 double limitHigh = pvLimitHigh->get();
98 double minStep = pvMinStep->get();
99 bool setValue =
false;
100 if(limitHigh>limitLow) {
101 if(value>limitHigh) {value = limitHigh;setValue=
true;}
102 if(value<limitLow) {value = limitLow;setValue=
true;}
104 if(setValue) convert->fromDouble(pvValue,value);
105 double diff = value - currentValue;
106 double outputValue = value;
109 outputValue = currentValue - minStep;
110 if(limitHigh>limitLow && outputValue<=limitLow) outputValue = limitLow;
112 if(outputValue<value) {
117 outputValue = currentValue + minStep;
118 if(limitHigh>limitLow && outputValue>=limitHigh) outputValue = limitHigh;
120 if(outputValue>value) {
126 if(outputValue==currentValue)
return false;
127 currentValue = outputValue;
128 convert->fromDouble(pvOutputValue,outputValue);
132 void ControlSupport::reset()
std::tr1::shared_ptr< PVRecord > PVRecordPtr
Base interface for a ControlSupport.
std::tr1::shared_ptr< ControlSupport > ControlSupportPtr