process reports if it changed fields
This commit is contained in:
@ -57,14 +57,18 @@ public:
|
||||
/**
|
||||
* @brief Honors control fields.
|
||||
*
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual void process();
|
||||
virtual bool process();
|
||||
/**
|
||||
* @brief If implementing minSteps it sets isMinStep to false.
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual void reset();
|
||||
static ControlSupportPtr create(PVRecordPtr const & pvRecord);
|
||||
static epics::pvData::StructureConstPtr controlField();
|
||||
private:
|
||||
ControlSupport(PVRecordPtr const & pvRecord);
|
||||
PVRecordPtr pvRecord;
|
||||
@ -73,6 +77,7 @@ private:
|
||||
epics::pvData::PVDoublePtr pvLimitLow;
|
||||
epics::pvData::PVDoublePtr pvLimitHigh;
|
||||
epics::pvData::PVDoublePtr pvMinStep;
|
||||
epics::pvData::PVDoublePtr pvOutputValue;
|
||||
double requestedValue;
|
||||
double currentValue;
|
||||
bool isMinStep;
|
||||
|
@ -69,10 +69,13 @@ public:
|
||||
/**
|
||||
* @brief Virtual method for derived class.
|
||||
*
|
||||
* Called when record is processed.
|
||||
* It is the method that implements support.
|
||||
* It is called each time the record is processed.
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual void process() = 0;
|
||||
virtual bool process() = 0;
|
||||
/**
|
||||
* @brief Optional method for derived class.
|
||||
*
|
||||
|
@ -60,17 +60,18 @@ public:
|
||||
/**
|
||||
* @brief Honors scalarAlarm fields.
|
||||
*
|
||||
*
|
||||
* @return Returns true is any fields were modified; otherwise false.
|
||||
*/
|
||||
virtual void process();
|
||||
virtual bool process();
|
||||
/**
|
||||
* @brief If implementing minSteps it sets isMinStep to false.
|
||||
*
|
||||
*/
|
||||
virtual void reset();
|
||||
static ScalarAlarmSupportPtr create(PVRecordPtr const & pvRecord);
|
||||
static epics::pvData::StructureConstPtr scalarAlarm();
|
||||
static epics::pvData::StructureConstPtr scalarAlarmField();
|
||||
private:
|
||||
static epics::pvData::StructureConstPtr scalarAlarmField;
|
||||
|
||||
ScalarAlarmSupport(PVRecordPtr const & pvRecord);
|
||||
enum {
|
||||
|
@ -29,6 +29,18 @@ ControlSupport::~ControlSupport()
|
||||
cout << "ControlSupport::~ControlSupport()\n";
|
||||
}
|
||||
|
||||
epics::pvData::StructureConstPtr ControlSupport::controlField()
|
||||
{
|
||||
return FieldBuilder::begin()
|
||||
->setId("control_t")
|
||||
->add("limitLow", pvDouble)
|
||||
->add("limitHigh", pvDouble)
|
||||
->add("minStep", pvDouble)
|
||||
->add("outputValue", pvDouble)
|
||||
->createStructure();
|
||||
}
|
||||
|
||||
|
||||
ControlSupportPtr ControlSupport::create(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
ControlSupportPtr support(new ControlSupport(pvRecord));
|
||||
@ -59,8 +71,9 @@ bool ControlSupport::init(PVFieldPtr const & pv,PVFieldPtr const & pvsup)
|
||||
pvLimitLow = pvControl->getSubField<PVDouble>("limitLow");
|
||||
pvLimitHigh = pvControl->getSubField<PVDouble>("limitHigh");
|
||||
pvMinStep = pvControl->getSubField<PVDouble>("minStep");
|
||||
pvOutputValue = pvControl->getSubField<PVDouble>("outputValue");
|
||||
}
|
||||
if(!pvControl || !pvLimitLow || !pvLimitHigh || !pvMinStep) {
|
||||
if(!pvControl || !pvLimitLow || !pvLimitHigh || !pvMinStep || !pvOutputValue) {
|
||||
cout << "ControlSupport for record " << pvRecord->getRecordName()
|
||||
<< " failed because pvSupport not a valid control structure\n";
|
||||
return false;
|
||||
@ -72,47 +85,44 @@ bool ControlSupport::init(PVFieldPtr const & pv,PVFieldPtr const & pvsup)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControlSupport::process()
|
||||
bool ControlSupport::process()
|
||||
{
|
||||
ConvertPtr convert = getConvert();
|
||||
double value = convert->toDouble(pvValue);
|
||||
if(value==requestedValue&&value==currentValue) return;
|
||||
if(value==requestedValue&&value==currentValue) return false;
|
||||
if(!isMinStep) requestedValue = value;
|
||||
double limitLow = pvLimitLow->get();
|
||||
double limitHigh = pvLimitHigh->get();
|
||||
double minStep = pvMinStep->get();
|
||||
if(limitHigh>limitLow) {
|
||||
if(value>limitHigh) value = limitHigh;
|
||||
if(value<limitLow) value = limitLow;
|
||||
if(!isMinStep) {
|
||||
if(requestedValue>limitHigh) requestedValue = limitHigh;
|
||||
if(requestedValue<limitLow) requestedValue = limitLow;
|
||||
}
|
||||
if(requestedValue>limitHigh) requestedValue = limitHigh;
|
||||
if(requestedValue<limitLow) requestedValue = limitLow;
|
||||
}
|
||||
double diff = requestedValue - currentValue;
|
||||
double outputValue = requestedValue;
|
||||
if(minStep>0.0) {
|
||||
double diff = requestedValue - currentValue;
|
||||
if(diff<0.0) {
|
||||
value = currentValue - minStep;
|
||||
outputValue = currentValue - minStep;
|
||||
isMinStep = true;
|
||||
if(value<requestedValue) {
|
||||
value = requestedValue;
|
||||
if(outputValue<requestedValue) {
|
||||
outputValue = requestedValue;
|
||||
isMinStep = false;
|
||||
}
|
||||
} else {
|
||||
value = currentValue + minStep;
|
||||
outputValue = currentValue + minStep;
|
||||
isMinStep = true;
|
||||
if(value>requestedValue) {
|
||||
value = requestedValue;
|
||||
if(outputValue>requestedValue) {
|
||||
outputValue = requestedValue;
|
||||
isMinStep = false;
|
||||
}
|
||||
}
|
||||
cout << "diff " << diff
|
||||
<< " value " << value
|
||||
<< " isMinStep " << (isMinStep ? "true" : "false")
|
||||
<< "\n";
|
||||
}
|
||||
currentValue = value;
|
||||
convert->fromDouble(pvValue,value);
|
||||
currentValue = outputValue;
|
||||
pvOutputValue->put(outputValue);
|
||||
if(!isMinStep && (outputValue!=requestedValue)) {
|
||||
convert->fromDouble(pvValue,requestedValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControlSupport::reset()
|
||||
|
@ -32,8 +32,9 @@ cout << "ScalarAlarmSupport::~ScalarAlarmSupport()\n";
|
||||
}
|
||||
|
||||
|
||||
epics::pvData::StructureConstPtr ScalarAlarmSupport::scalarAlarmField =
|
||||
FieldBuilder::begin()
|
||||
epics::pvData::StructureConstPtr ScalarAlarmSupport::scalarAlarmField()
|
||||
{
|
||||
return FieldBuilder::begin()
|
||||
->setId("scalarAlarm_t")
|
||||
->add("active", pvBoolean)
|
||||
->add("lowAlarmLimit", pvDouble)
|
||||
@ -42,10 +43,6 @@ FieldBuilder::begin()
|
||||
->add("highAlarmLimit", pvDouble)
|
||||
->add("hysteresis", pvDouble)
|
||||
->createStructure();
|
||||
|
||||
epics::pvData::StructureConstPtr ScalarAlarmSupport::scalarAlarm()
|
||||
{
|
||||
return scalarAlarmField;
|
||||
}
|
||||
|
||||
ScalarAlarmSupportPtr ScalarAlarmSupport::create(PVRecordPtr const & pvRecord)
|
||||
@ -104,7 +101,7 @@ bool ScalarAlarmSupport::init(
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScalarAlarmSupport::process()
|
||||
bool ScalarAlarmSupport::process()
|
||||
{
|
||||
ConvertPtr convert = getConvert();
|
||||
double value = convert->toDouble(pvValue);
|
||||
@ -132,9 +129,14 @@ void ScalarAlarmSupport::process()
|
||||
alarmRange = range_Low;
|
||||
}
|
||||
}
|
||||
if(alarmRange!=prevAlarmRange) setAlarm(pvAlarm,alarmRange);
|
||||
bool retValue = false;
|
||||
if(alarmRange!=prevAlarmRange) {
|
||||
setAlarm(pvAlarm,alarmRange);
|
||||
retValue = true;
|
||||
}
|
||||
prevAlarmRange = alarmRange;
|
||||
currentValue = value;
|
||||
return retValue;
|
||||
}
|
||||
|
||||
void ScalarAlarmSupport::reset()
|
||||
|
Reference in New Issue
Block a user