Commit 11d04cb4 authored by Claudio Scafuri's avatar Claudio Scafuri 💬
Browse files

import beam_info rpc server from host specified in BeamInfoRpcHost property

parent 3b0a65cc
......@@ -398,6 +398,10 @@ void BPMID::init_device()
attr_HorPos_read = new Tango::DevDouble[12];
attr_VerAngle_read = new Tango::DevDouble[12];
attr_VerPos_read = new Tango::DevDouble[12];
// No longer if mandatory property not set.
if (mandatoryNotDefined)
return;
/*----- PROTECTED REGION ID(BPMID::init_device) ENABLED START -----*/
// Initialize device
......@@ -511,7 +515,8 @@ void BPMID::init_device()
main_condition=new omni_condition(&cond_mutex);
shared_data.thresholdCurrent=thresholdCurrent;
BEAM_THRESHOLD=thresholdCurrent;
activeThread = new bpmidThread(this, &shared_data, main_mutex, *main_condition, minimumThreadRefreshPeriod, threadRefreshPeriod);
const char* beaminfhost = beamInfoRpcHost.c_str();
activeThread = new bpmidThread(this, &shared_data, main_mutex, *main_condition, minimumThreadRefreshPeriod, threadRefreshPeriod, beaminfhost);
set_state(Tango::INIT);
set_status("BPMID: init ok");
......@@ -533,12 +538,14 @@ void BPMID::get_device_property()
/*----- PROTECTED REGION END -----*/ // BPMID::get_device_property_before
mandatoryNotDefined = false;
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("ThresholdCurrent"));
dev_prop.push_back(Tango::DbDatum("ThreadRefreshPeriod"));
dev_prop.push_back(Tango::DbDatum("MinimumThreadRefreshPeriod"));
dev_prop.push_back(Tango::DbDatum("BeamInfoRpcHost"));
// is there at least one property to be read ?
if (dev_prop.size()>0)
......@@ -586,6 +593,19 @@ void BPMID::get_device_property()
// And try to extract MinimumThreadRefreshPeriod value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> minimumThreadRefreshPeriod;
// Try to initialize BeamInfoRpcHost from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> beamInfoRpcHost;
else {
// Try to initialize BeamInfoRpcHost from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> beamInfoRpcHost;
}
// And try to extract BeamInfoRpcHost value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> beamInfoRpcHost;
// Property StartDsPath is mandatory, check if has been defined in database.
check_mandatory_property(cl_prop, dev_prop[i]);
}
/*----- PROTECTED REGION ID(BPMID::get_device_property_after) ENABLED START -----*/
......@@ -594,6 +614,32 @@ void BPMID::get_device_property()
/*----- PROTECTED REGION END -----*/ // BPMID::get_device_property_after
}
//--------------------------------------------------------
/**
* Method : BPMID::check_mandatory_property()
* Description : For mandatory properties check if defined in database.
*/
//--------------------------------------------------------
void BPMID::check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop)
{
// Check if all properties are empty
if (class_prop.is_empty() && dev_prop.is_empty())
{
TangoSys_OMemStream tms;
tms << endl <<"Property \'" << dev_prop.name;
if (Tango::Util::instance()->_UseDb==true)
tms << "\' is mandatory but not defined in database";
else
tms << "\' is mandatory but cannot be defined without database";
append_status(tms.str());
mandatoryNotDefined = true;
/*----- PROTECTED REGION ID(BPMID::check_mandatory_property) ENABLED START -----*/
cerr << tms.str() << " for " << device_name << endl;
/*----- PROTECTED REGION END -----*/ // BPMID::check_mandatory_property
}
}
//--------------------------------------------------------
/**
......@@ -604,6 +650,13 @@ void BPMID::get_device_property()
void BPMID::always_executed_hook()
{
DEBUG_STREAM << "BPMID::always_executed_hook() " << device_name << endl;
if (mandatoryNotDefined)
{
Tango::Except::throw_exception(
(const char *)"PROPERTY_NOT_SET",
get_status().c_str(),
(const char *)"BPMID::always_executed_hook()");
}
/*----- PROTECTED REGION ID(BPMID::always_executed_hook) ENABLED START -----*/
// code always executed before all requests
......@@ -1974,10 +2027,9 @@ void BPMID::read_Y_B11(Tango::Attribute &attr)
}
else
attr.set_quality(Tango::ATTR_INVALID);
}
/*----- PROTECTED REGION END -----*/ // BPMID::read_Y_B11
/*----- PROTECTED REGION END -----*/ // BPMID::read_Y_B11
}
//--------------------------------------------------------
/**
* Read attribute Y_B6 related method
......@@ -1989,8 +2041,8 @@ void BPMID::read_Y_B11(Tango::Attribute &attr)
//--------------------------------------------------------
void BPMID::read_Y_B6(Tango::Attribute &attr)
{
DEBUG_STREAM << "BPMID::read_Y_B6(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(BPMID::read_Y_B6) ENABLED START -----*/
DEBUG_STREAM << "BPMID::read_Y_B6(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(BPMID::read_Y_B6) ENABLED START -----*/
// Set the attribute value
if(validY){
attr.set_value(attr_Y_B6_read);
......
......@@ -78,6 +78,10 @@ public:
// Acts as a safety limit in case of slow field access.
// Time in milliseconds.
Tango::DevLong minimumThreadRefreshPeriod;
// BeamInfoRpcHost:
string beamInfoRpcHost;
bool mandatoryNotDefined;
// Attribute data members
public:
......@@ -211,6 +215,10 @@ public:
*/
virtual void always_executed_hook();
/*
* Check if mandatory property has been set
*/
void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop);
// Attribute methods
public:
......
<?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="BPMID" pogoRevision="9.6">
<description description="The class BPMID estimates the electron beam positions and angles at the centres of the SR insertion devices.&#xA;Calculations are based on services of the old HLS library and its undelying rpc calls.&#xA;The number and names of the positions are fixed.&#xA;TO DO: position at the bending sources." title="Bpm ID" sourcePath="/home/claudio/devel/elettra/server/bpmid/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<description description="The class BPMID estimates the electron beam positions and angles at the centres of the SR insertion devices.&#xA;Calculations are based on services of the old HLS library and its undelying rpc calls.&#xA;The number and names of the positions are fixed.&#xA;TO DO: position at the bending sources." title="Bpm ID" sourcePath="/home/claudio/src/gitlab/cs/ds/bpmid/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="BeamDiag" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""/>
</description>
......@@ -20,6 +20,10 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>10000</DefaultPropValue>
</deviceProperties>
<deviceProperties name="BeamInfoRpcHost" mandatory="true" description="">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its &lt;i>device_state&lt;/i> data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
<argin description="none.">
<type xsi:type="pogoDsl:VoidType"/>
......
......@@ -261,6 +261,19 @@ void BPMIDClass::set_default_property()
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "BeamInfoRpcHost";
prop_desc = "";
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);
}
//--------------------------------------------------------
......
......@@ -1976,7 +1976,7 @@ int acquire()
/*-----------------------------------------*/
int bpmid_init()
int bpmid_init(const char* infosrv_host)
{
int j, err=0;
int nseconds ;
......@@ -2076,8 +2076,8 @@ int bpmid_init()
/* import new dcct call beamsid= */
if(import_beam_info("tom")<0){
printf ("beaminfo server %s\n",infosrv_host);
if(import_beam_info(infosrv_host)<0){
nc_perror("import_beam()");
return -1;
}
......
......@@ -20,7 +20,7 @@ extern "C" {
extern double **PID; /* position at centre of ID */
extern double **AID; /* angle at centre of ID */
int bpmid_init();
int bpmid_init(const char*);
int bpmid_read_and_update();
void bpmid_print_orbit(int plane);
void Init_field();
......
......@@ -7,14 +7,14 @@
bool bpmidThread::hls_init=false;
bpmidThread::bpmidThread(Tango::Device_4Impl *dev, bpmidShData *dat, omni_mutex &mut,omni_condition &cond, long minreftime,long reftime):omni_thread(),Tango::LogAdapter(dev),flag_update(false),exit_thread(false),shared_data(dat), the_mutex(mut),the_cond(cond), min_period(minreftime),refresh_period(reftime)
bpmidThread::bpmidThread(Tango::Device_4Impl *dev, bpmidShData *dat, omni_mutex &mut,omni_condition &cond, long minreftime,long reftime, const char* beam_info_host):omni_thread(),Tango::LogAdapter(dev),flag_update(false),exit_thread(false),shared_data(dat), the_mutex(mut),the_cond(cond), min_period(minreftime),refresh_period(reftime), beam_info_host_name(beam_info_host)
{
{
omni_mutex_lock lo(the_mutex);
shared_data->last_update.tv_sec=0;
shared_data->last_update.tv_usec=0;
if(!hls_init){
if (bpmid_init() <0){
if (bpmid_init(beam_info_host_name) <0){
ERROR_STREAM << "bpmidThread bpmid_init() failed"<<endl;
shared_data->init_ok=false;
}
......
......@@ -40,7 +40,7 @@ struct bpmidShData{
class bpmidThread : public omni_thread, public Tango::LogAdapter
{
public :
bpmidThread(Tango::Device_4Impl *dev, bpmidShData *dat, omni_mutex &mut, omni_condition &cond, long minreftime=5000,long reftime=15000);
bpmidThread(Tango::Device_4Impl *dev, bpmidShData *dat, omni_mutex &mut, omni_condition &cond, long minreftime=5000,long reftime=15000, const char* beam_info_host="localhost");
void *run_undetached(void *);
bool flag_update; /* thread raises flag - Device lowers : avoidmultiple copise/locking - use locking!*/
......@@ -54,7 +54,9 @@ private :
long refresh_period; //refresh period (ms)
bpmidShData local_data;
void read_and_update();
static bool hls_init;
static bool hls_init;
const char* beam_info_host_name;
/**
* calculate time difference in milliseconds
......
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