Skip to content
Snippets Groups Projects
Commit f2fbf59c authored by Claudio Scafuri's avatar Claudio Scafuri :speech_balloon:
Browse files

events and current ripple

parent 44bd4532
No related branches found
No related tags found
1 merge request!1start in OFF state
.nse_depinfo .nse_depinfo*
bin bin
obj obj
......
...@@ -151,7 +151,9 @@ void SimulatedE2PS::init_device() ...@@ -151,7 +151,9 @@ void SimulatedE2PS::init_device()
/* clang-format off */ /* clang-format off */
/*----- PROTECTED REGION END -----*/ // SimulatedE2PS::init_device_before /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::init_device_before
// No device property to be read from database
// Get the device properties from database
get_device_property();
/*----- PROTECTED REGION ID(SimulatedE2PS::init_device) ENABLED START -----*/ /*----- PROTECTED REGION ID(SimulatedE2PS::init_device) ENABLED START -----*/
/* clang-format on */ /* clang-format on */
...@@ -175,6 +177,57 @@ void SimulatedE2PS::init_device() ...@@ -175,6 +177,57 @@ void SimulatedE2PS::init_device()
/*----- PROTECTED REGION END -----*/ // SimulatedE2PS::init_device /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::init_device
} }
//--------------------------------------------------------
/**
* Method : SimulatedE2PS::get_device_property()
* Description: Read database to initialize property data members.
*/
//--------------------------------------------------------
void SimulatedE2PS::get_device_property()
{
/*----- PROTECTED REGION ID(SimulatedE2PS::get_device_property_before) ENABLED START -----*/
/* clang-format on */
// Initialize property data members
/* clang-format off */
/*----- PROTECTED REGION END -----*/ // SimulatedE2PS::get_device_property_before
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("CurrentRipple"));
// is there at least one property to be read ?
if (dev_prop.size()>0)
{
// Call database and extract values
if (Tango::Util::instance()->_UseDb==true)
get_db_device()->get_property(dev_prop);
// get instance on SimulatedE2PSClass to get class property
Tango::DbDatum def_prop, cl_prop;
SimulatedE2PSClass *ds_class =
(static_cast<SimulatedE2PSClass *>(get_device_class()));
int i = -1;
// Try to initialize CurrentRipple from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> currentRipple;
else {
// Try to initialize CurrentRipple from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> currentRipple;
}
// And try to extract CurrentRipple value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> currentRipple;
}
/*----- PROTECTED REGION ID(SimulatedE2PS::get_device_property_after) ENABLED START -----*/
/* clang-format on */
// Check device property data members init
/* clang-format off */
/*----- PROTECTED REGION END -----*/ // SimulatedE2PS::get_device_property_after
}
//-------------------------------------------------------- //--------------------------------------------------------
/** /**
...@@ -238,14 +291,13 @@ void SimulatedE2PS::read_current(Tango::Attribute &attr) ...@@ -238,14 +291,13 @@ void SimulatedE2PS::read_current(Tango::Attribute &attr)
/*----- PROTECTED REGION ID(SimulatedE2PS::read_current) ENABLED START -----*/ /*----- PROTECTED REGION ID(SimulatedE2PS::read_current) ENABLED START -----*/
/* clang-format on */ /* clang-format on */
// Set the attribute value // Set the attribute value
double delta=rand_r(&rand_r_seed)/RAND_MAX; double delta=drand48()-0.5;
if(get_state() == Tango::OFF){ if(get_state() == Tango::OFF){
delta +=0.5; _current_read = delta * currentRipple;
_current_read = delta *0.0001;
} }
else{ else{
delta -=0.5; _current_read = _current +( delta * currentRipple );
_current_read = _current +( delta *0.0001 );
} }
attr.set_value(&_current_read); attr.set_value(&_current_read);
/* clang-format off */ /* clang-format off */
...@@ -264,9 +316,8 @@ void SimulatedE2PS::write_current(Tango::WAttribute &attr) ...@@ -264,9 +316,8 @@ void SimulatedE2PS::write_current(Tango::WAttribute &attr)
{ {
DEBUG_STREAM << "SimulatedE2PS::write_current(Tango::WAttribute &attr) entering... " << std::endl; DEBUG_STREAM << "SimulatedE2PS::write_current(Tango::WAttribute &attr) entering... " << std::endl;
// Retrieve write value // Retrieve write value
attr.get_write_value(_current_read); Tango::DevDouble w_val;
attr.get_write_value(_current); attr.get_write_value(w_val);
_voltage = _current * _ohm;
/*----- PROTECTED REGION ID(SimulatedE2PS::write_current) ENABLED START -----*/ /*----- PROTECTED REGION ID(SimulatedE2PS::write_current) ENABLED START -----*/
/* clang-format on */ /* clang-format on */
// Add your own code // Add your own code
...@@ -342,6 +393,8 @@ void SimulatedE2PS::on() ...@@ -342,6 +393,8 @@ void SimulatedE2PS::on()
/* clang-format on */ /* clang-format on */
// Add your own code // Add your own code
set_state(Tango::ON);
push_change_event("State");
/* clang-format off */ /* clang-format off */
/*----- PROTECTED REGION END -----*/ // SimulatedE2PS::on /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::on
...@@ -358,7 +411,15 @@ void SimulatedE2PS::off() ...@@ -358,7 +411,15 @@ void SimulatedE2PS::off()
DEBUG_STREAM << "SimulatedE2PS::Off() - " << device_name << std::endl; DEBUG_STREAM << "SimulatedE2PS::Off() - " << device_name << std::endl;
/*----- PROTECTED REGION ID(SimulatedE2PS::off) ENABLED START -----*/ /*----- PROTECTED REGION ID(SimulatedE2PS::off) ENABLED START -----*/
/* clang-format on */ /* clang-format on */
_current_read = 0.0;
_current = 0.0;
_voltage = 0.0;
attr_current->set_write_value(_current);
push_change_event("current",&_current_read);
push_change_event("currentSet",&_current);
set_state(Tango::OFF);
push_change_event("State");
;
// Add your own code // Add your own code
/* clang-format off */ /* clang-format off */
......
...@@ -86,6 +86,12 @@ class SimulatedE2PS : public TANGO_BASE_CLASS ...@@ -86,6 +86,12 @@ class SimulatedE2PS : public TANGO_BASE_CLASS
/* clang-format off */ /* clang-format off */
/*----- PROTECTED REGION END -----*/ // SimulatedE2PS::Data Members /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::Data Members
// Device property data members
public:
// CurrentRipple: Residual current oscillation [A]
//
// The simulator adds noise of CurrenRipple amplitude to the reading
Tango::DevDouble currentRipple;
// Attribute data members // Attribute data members
public: public:
...@@ -133,6 +139,10 @@ public: ...@@ -133,6 +139,10 @@ public:
* Initialize the device * Initialize the device
*/ */
virtual void init_device(); virtual void init_device();
/*
* Read the device properties from database
*/
void get_device_property();
/* /*
* Always executed method before execution command method. * Always executed method before execution command method.
*/ */
......
<?xml version="1.0" encoding="ASCII"?> <?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"> <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="SimulatedE2PS" pogoRevision="9.8"> <classes name="SimulatedE2PS" pogoRevision="9.8">
<description description="Simulated power supply for Elettra 2.0 tests (digiltal twin).&#xA;Tango interface Loosely based on NGPS tango device" title="SimulatedE2PS" sourcePath="/homelocal/claudio/src/gitlab/dt/ds/simulatede2ps/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false"> <description description="Simulated power supply for Elettra 2.0 tests (digiltal twin).&#xA;Tango interface Loosely based on NGPS tango device" title="SimulatedE2PS" sourcePath="/homelocal/claudio/src/gitlab/dt/ds/simulatede2ps/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/> <inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="Simulators" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""> <identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="Simulators" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference="">
<keyWords>Power supply</keyWords> <keyWords>Power supply</keyWords>
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
<keyWords>Digital twin</keyWords> <keyWords>Digital twin</keyWords>
</identification> </identification>
</description> </description>
<deviceProperties name="CurrentRipple" description="Residual current oscillation [A]&#xA;&#xA;The simulator adds noise of CurrenRipple amplitude to the reading">
<type xsi:type="pogoDsl:DoubleType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>0.0025</DefaultPropValue>
</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="0"> <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="0">
<argin description="none"> <argin description="none">
<type xsi:type="pogoDsl:VoidType"/> <type xsi:type="pogoDsl:VoidType"/>
......
...@@ -331,6 +331,20 @@ void SimulatedE2PSClass::set_default_property() ...@@ -331,6 +331,20 @@ void SimulatedE2PSClass::set_default_property()
// Set Default Class Properties // Set Default Class Properties
// Set Default device Properties // Set Default device Properties
prop_name = "CurrentRipple";
prop_desc = "Residual current oscillation [A]\n\nThe simulator adds noise of CurrenRipple amplitude to the reading";
prop_def = "0.0025";
vect_data.clear();
vect_data.push_back("0.0025");
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);
} }
//-------------------------------------------------------- //--------------------------------------------------------
......
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