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