Commit 51c3a6c6 authored by Jean-Luc Pons's avatar Jean-Luc Pons

Added BPIStation and MAX ADC filter

parent 923b88f1
......@@ -164,6 +164,7 @@ if(thread==NULL) { \
// Tilt_Angle | Tango::DevDouble Scalar
// KH | Tango::DevULong Scalar
// KV | Tango::DevULong Scalar
// BPIStation | Tango::DevBoolean Scalar
// SA_Va_History | Tango::DevDouble Spectrum ( max = 2000)
// SA_Vb_History | Tango::DevDouble Spectrum ( max = 2000)
// SA_Vc_History | Tango::DevDouble Spectrum ( max = 2000)
......@@ -318,6 +319,7 @@ void LiberaSparkSRBPM::delete_device()
delete[] attr_Tilt_Angle_read;
delete[] attr_KH_read;
delete[] attr_KV_read;
delete[] attr_BPIStation_read;
delete[] attr_SA_Va_History_read;
delete[] attr_SA_Vb_History_read;
delete[] attr_SA_Vc_History_read;
......@@ -413,6 +415,7 @@ void LiberaSparkSRBPM::init_device()
attr_Tilt_Angle_read = new Tango::DevDouble[1];
attr_KH_read = new Tango::DevULong[1];
attr_KV_read = new Tango::DevULong[1];
attr_BPIStation_read = new Tango::DevBoolean[1];
attr_SA_Va_History_read = new Tango::DevDouble[2000];
attr_SA_Vb_History_read = new Tango::DevDouble[2000];
attr_SA_Vc_History_read = new Tango::DevDouble[2000];
......@@ -547,6 +550,8 @@ void LiberaSparkSRBPM::init_device()
A0Temp = readFromFile("/sys/bus/iio/devices/iio:device0/in_temp0_offset");
A1Temp = readFromFile("/sys/bus/iio/devices/iio:device0/in_temp0_scale");
lastAGCtime = 0;
maxAdcBuff.clear();
attr_BPIStation_read[0] = false;
/*----- PROTECTED REGION END -----*/ // LiberaSparkSRBPM::init_device
}
......@@ -566,7 +571,8 @@ void LiberaSparkSRBPM::get_device_property()
aGCMaxADC = 5000;
kH = 0;
kV = 0;
maxADCAvgLength = 1;
/*----- PROTECTED REGION END -----*/ // LiberaSparkSRBPM::get_device_property_before
......@@ -578,6 +584,7 @@ void LiberaSparkSRBPM::get_device_property()
dev_prop.push_back(Tango::DbDatum("KV"));
dev_prop.push_back(Tango::DbDatum("BPM_Set_List"));
dev_prop.push_back(Tango::DbDatum("BPM_Geometry"));
dev_prop.push_back(Tango::DbDatum("MaxADCAvgLength"));
// is there at least one property to be read ?
if (dev_prop.size()>0)
......@@ -658,6 +665,17 @@ void LiberaSparkSRBPM::get_device_property()
// And try to extract BPM_Geometry value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> bPM_Geometry;
// Try to initialize MaxADCAvgLength from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> maxADCAvgLength;
else {
// Try to initialize MaxADCAvgLength from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> maxADCAvgLength;
}
// And try to extract MaxADCAvgLength value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> maxADCAvgLength;
}
/*----- PROTECTED REGION ID(LiberaSparkSRBPM::get_device_property_after) ENABLED START -----*/
......@@ -2794,6 +2812,24 @@ void LiberaSparkSRBPM::read_KV(Tango::Attribute &attr)
/*----- PROTECTED REGION END -----*/ // LiberaSparkSRBPM::read_KV
}
//--------------------------------------------------------
/**
* Read attribute BPIStation related method
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
//--------------------------------------------------------
void LiberaSparkSRBPM::read_BPIStation(Tango::Attribute &attr)
{
DEBUG_STREAM << "LiberaSparkSRBPM::read_BPIStation(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(LiberaSparkSRBPM::read_BPIStation) ENABLED START -----*/
// Set the attribute value
attr.set_value(attr_BPIStation_read);
/*----- PROTECTED REGION END -----*/ // LiberaSparkSRBPM::read_BPIStation
}
//--------------------------------------------------------
/**
* Read attribute SA_Va_History related method
* Description:
......@@ -3455,45 +3491,60 @@ Tango::DevState LiberaSparkSRBPM::dev_state()
status = "Device is OK\nAGC: On";
}
Tango::DevULong umaxADC;
self->read_attribute("MaxADC") >> umaxADC;
maxAdcBuff.push_back((double)umaxADC);
if( (int)maxAdcBuff.size()>maxADCAvgLength )
maxAdcBuff.erase(maxAdcBuff.begin());
time_t now = get_ticks();
if( now-lastAGCtime > 2900 ) {
// AGC control every 3 sec
double maxADC = NAN;
Tango::DevULong maxADC;
Tango::DevULong att;
for (int i = 0; i < (int) maxAdcBuff.size(); i++)
maxADC += maxAdcBuff[i];
if (maxAdcBuff.size() > 0)
maxADC = maxADC / (double) maxAdcBuff.size();
try {
if (!std::isnan(maxADC)) {
self->read_attribute("MaxADC") >> maxADC;
self->read_attribute("Attenuation") >> att;
Tango::DevULong att;
int newAtt = (int) att;
if (maxADC > (Tango::DevULong) aGCMaxADC)
newAtt = ((newAtt + 3) / 3)*3;
if (maxADC < (Tango::DevULong) aGCMinADC)
newAtt = ((newAtt - 3) / 3)*3;
try {
if (newAtt > 30) {
newAtt = 30;
argout = Tango::ALARM;
status += "\nAGC: Alarm, maximum attenuation reached";
}
self->read_attribute("Attenuation") >> att;
int newAtt = (int) att;
if (maxADC > (Tango::DevULong) aGCMaxADC)
newAtt = ((newAtt + 3) / 3) * 3;
if (maxADC < (Tango::DevULong) aGCMinADC)
newAtt = ((newAtt - 3) / 3) * 3;
if (newAtt > 30) {
newAtt = 30;
argout = Tango::ALARM;
status += "\nAGC: Alarm, maximum attenuation reached";
}
if (newAtt < 0) {
newAtt = 0;
if (newAtt < 0) {
newAtt = 0;
argout = Tango::ALARM;
status += "\nAGC: Alarm, minimum attenuation reached";
}
att = (Tango::DevULong) newAtt;
Tango::DeviceAttribute da("Attenuation", att);
self->write_attribute(da);
} catch (Tango::DevFailed &e) {
argout = Tango::ALARM;
status += "\nAGC: Alarm, minimum attenuation reached";
status += "\nAGC: Error " + string(e.errors[0].desc.in());
}
att = (Tango::DevULong) newAtt;
Tango::DeviceAttribute da("Attenuation", att);
self->write_attribute(da);
} catch (Tango::DevFailed &e) {
argout = Tango::ALARM;
status += "\nAGC: Error " + string(e.errors[0].desc.in());
}
lastAGCtime = now;
......
......@@ -227,6 +227,8 @@ private:
Tango::DevULong64 triggerCounterOffset;
vector<double> maxAdcBuff;
void StartSA();
void StartDD();
void StartIQ();
......@@ -273,6 +275,8 @@ public:
vector<string> bPM_Set_List;
// BPM_Geometry: BPM geometry (Large or Small)
string bPM_Geometry;
// MaxADCAvgLength: Averaginf of MaxADC for AGC control
Tango::DevLong maxADCAvgLength;
// Attribute data members
public:
......@@ -338,6 +342,7 @@ public:
Tango::DevDouble *attr_Tilt_Angle_read;
Tango::DevULong *attr_KH_read;
Tango::DevULong *attr_KV_read;
Tango::DevBoolean *attr_BPIStation_read;
Tango::DevDouble *attr_SA_Va_History_read;
Tango::DevDouble *attr_SA_Vb_History_read;
Tango::DevDouble *attr_SA_Vc_History_read;
......@@ -1036,6 +1041,15 @@ public:
*/
virtual void read_KV(Tango::Attribute &attr);
virtual bool is_KV_allowed(Tango::AttReqType type);
/**
* Attribute BPIStation related methods
* Description:
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
virtual void read_BPIStation(Tango::Attribute &attr);
virtual bool is_BPIStation_allowed(Tango::AttReqType type);
/**
* Attribute SA_Va_History related methods
* Description:
......
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
<classes name="LiberaSparkSRBPM" pogoRevision="9.6">
<classes name="LiberaSparkSRBPM" pogoRevision="9.7">
<description description="A class to Handle LiberaSpark SR BPM" title="LiberaSparkBPM" sourcePath="/mntdirect/_segfs/tango/cppserver/machine/diagnostic/bpm/LiberaSparkSRBPM" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Copyright (C): 2019&#xA; European Synchrotron Radiation Facility&#xA; BP 220, Grenoble 38043&#xA; France" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at esrf.fr - pons" author="pons" emailDomain="esrf.fr" classFamily="BeamDiagnostics" siteSpecific="ESRF" platform="Unix Like" bus="MCI" manufacturer="none" reference=""/>
......@@ -29,6 +29,10 @@
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<deviceProperties name="MaxADCAvgLength" description="Averaginf of MaxADC for AGC control">
<type xsi:type="pogoDsl:IntType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="1000" isDynamic="false">
<argin description="none">
<type xsi:type="pogoDsl:VoidType"/>
......@@ -584,6 +588,14 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="BPIStation" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:BooleanType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="SA_Va_History" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="2000" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:DoubleType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
......
......@@ -353,6 +353,19 @@ void LiberaSparkSRBPMClass::set_default_property()
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "MaxADCAvgLength";
prop_desc = "Averaginf of MaxADC for AGC control";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
}
//--------------------------------------------------------
......@@ -2023,6 +2036,30 @@ void LiberaSparkSRBPMClass::attribute_factory(vector<Tango::Attr *> &att_list)
// Not Memorized
att_list.push_back(kv);
// Attribute : BPIStation
BPIStationAttrib *bpistation = new BPIStationAttrib();
Tango::UserDefaultAttrProp bpistation_prop;
// description not set for BPIStation
// label not set for BPIStation
// unit not set for BPIStation
// standard_unit not set for BPIStation
// display_unit not set for BPIStation
// format not set for BPIStation
// max_value not set for BPIStation
// min_value not set for BPIStation
// max_alarm not set for BPIStation
// min_alarm not set for BPIStation
// max_warning not set for BPIStation
// min_warning not set for BPIStation
// delta_t not set for BPIStation
// delta_val not set for BPIStation
bpistation->set_default_properties(bpistation_prop);
// Not Polled
bpistation->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(bpistation);
// Attribute : SA_Va_History
SA_Va_HistoryAttrib *sa_va_history = new SA_Va_HistoryAttrib();
Tango::UserDefaultAttrProp sa_va_history_prop;
......
......@@ -956,6 +956,19 @@ public:
{return (static_cast<LiberaSparkSRBPM *>(dev))->is_KV_allowed(ty);}
};
// Attribute BPIStation class definition
class BPIStationAttrib: public Tango::Attr
{
public:
BPIStationAttrib():Attr("BPIStation",
Tango::DEV_BOOLEAN, Tango::READ) {};
~BPIStationAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<LiberaSparkSRBPM *>(dev))->read_BPIStation(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<LiberaSparkSRBPM *>(dev))->is_BPIStation_allowed(ty);}
};
// Attribute SA_Va_History class definition
class SA_Va_HistoryAttrib: public Tango::SpectrumAttr
{
......
......@@ -1200,6 +1200,22 @@ bool LiberaSparkSRBPM::is_KV_allowed(TANGO_UNUSED(Tango::AttReqType type))
return true;
}
//--------------------------------------------------------
/**
* Method : LiberaSparkSRBPM::is_BPIStation_allowed()
* Description : Execution allowed for BPIStation attribute
*/
//--------------------------------------------------------
bool LiberaSparkSRBPM::is_BPIStation_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Not any excluded states for BPIStation attribute in read access.
/*----- PROTECTED REGION ID(LiberaSparkSRBPM::BPIStationStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // LiberaSparkSRBPM::BPIStationStateAllowed_READ
return true;
}
//--------------------------------------------------------
/**
* Method : LiberaSparkSRBPM::is_SA_Va_History_allowed()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment