From 3ed81cca7c9eac2a4a1265921b8ab12a8dd7d848 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Thu, 21 Nov 2024 17:17:33 +0100 Subject: [PATCH] add possiblity to change current ripple amplitude and switch ripple on/off --- src/SimulatedE2PS.cpp | 159 +++++++++++++++++++----- src/SimulatedE2PS.h | 63 +++++++--- src/SimulatedE2PS.xmi | 24 +++- src/SimulatedE2PSClass.cpp | 198 ++++++++++++++++++------------ src/SimulatedE2PSClass.h | 78 ++++++++---- src/SimulatedE2PSStateMachine.cpp | 80 +++++++++--- 6 files changed, 428 insertions(+), 174 deletions(-) diff --git a/src/SimulatedE2PS.cpp b/src/SimulatedE2PS.cpp index 04397cb..be0aada 100644 --- a/src/SimulatedE2PS.cpp +++ b/src/SimulatedE2PS.cpp @@ -65,9 +65,11 @@ //================================================================ // Attributes managed are: //================================================================ -// current | Tango::DevDouble Scalar -// voltage | Tango::DevDouble Scalar -// currentSet | Tango::DevDouble Scalar +// current | Tango::DevDouble Scalar +// voltage | Tango::DevDouble Scalar +// currentSet | Tango::DevDouble Scalar +// CurrentRipple | Tango::DevDouble Scalar +// AddRipple | Tango::DevBoolean Scalar //================================================================ namespace SimulatedE2PS_ns @@ -80,8 +82,8 @@ namespace SimulatedE2PS_ns //-------------------------------------------------------- /** - * Method : SimulatedE2PS::SimulatedE2PS() - * Description: Constructors for a Tango device + * Method : SimulatedE2PS::SimulatedE2PS() + * Description: Constructors for a Tango device * implementing the classSimulatedE2PS */ //-------------------------------------------------------- @@ -122,8 +124,8 @@ SimulatedE2PS::~SimulatedE2PS() //-------------------------------------------------------- /** - * Method : SimulatedE2PS::delete_device() - * Description: will be called at device destruction or at init command + * Method : SimulatedE2PS::delete_device() + * Description: will be called at device destruction or at init command */ //-------------------------------------------------------- void SimulatedE2PS::delete_device() @@ -138,8 +140,8 @@ void SimulatedE2PS::delete_device() //-------------------------------------------------------- /** - * Method : SimulatedE2PS::init_device() - * Description: will be called at device initialization. + * Method : SimulatedE2PS::init_device() + * Description: will be called at device initialization. */ //-------------------------------------------------------- void SimulatedE2PS::init_device() @@ -162,6 +164,8 @@ void SimulatedE2PS::init_device() _current= 0.0; _current_read= 0.0; _voltage= 0.1; + _current_ripple = currentRipple; + _add_ripple = false; _ohm = 0.2; // load resistance in ohm _busy = false; thread_running=false; @@ -180,8 +184,8 @@ void SimulatedE2PS::init_device() //-------------------------------------------------------- /** - * Method : SimulatedE2PS::get_device_property() - * Description: Read database to initialize property data members. + * Method : SimulatedE2PS::get_device_property() + * Description: Read database to initialize property data members. */ //-------------------------------------------------------- void SimulatedE2PS::get_device_property() @@ -232,8 +236,8 @@ void SimulatedE2PS::get_device_property() //-------------------------------------------------------- /** - * Method : SimulatedE2PS::always_executed_hook() - * Description: method always executed before any command is executed + * Method : SimulatedE2PS::always_executed_hook() + * Description: method always executed before any command is executed */ //-------------------------------------------------------- void SimulatedE2PS::always_executed_hook() @@ -248,8 +252,8 @@ void SimulatedE2PS::always_executed_hook() //-------------------------------------------------------- /** - * Method : SimulatedE2PS::read_attr_hardware() - * Description: Hardware acquisition for attributes + * Method : SimulatedE2PS::read_attr_hardware() + * Description: Hardware acquisition for attributes */ //-------------------------------------------------------- void SimulatedE2PS::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) @@ -263,8 +267,8 @@ void SimulatedE2PS::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list } //-------------------------------------------------------- /** - * Method : SimulatedE2PS::write_attr_hardware() - * Description: Hardware writing for attributes + * Method : SimulatedE2PS::write_attr_hardware() + * Description: Hardware writing for attributes */ //-------------------------------------------------------- void SimulatedE2PS::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) @@ -280,7 +284,7 @@ void SimulatedE2PS::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_lis //-------------------------------------------------------- /** * Read attribute current related method - * Description: The powersupply current setting in amps + * Description: The powersupply current setting in amps * * Data type: Tango::DevDouble * Attr type: Scalar @@ -292,13 +296,18 @@ void SimulatedE2PS::read_current(Tango::Attribute &attr) /*----- PROTECTED REGION ID(SimulatedE2PS::read_current) ENABLED START -----*/ /* clang-format on */ // Set the attribute value - double delta=drand48()-0.5; + + double delta; + if (_add_ripple) + delta = drand48()-0.5; // use anothe random distribution? + else + delta = 0.0; if(get_state() == Tango::OFF){ - _current_read = delta * currentRipple; + _current_read = 0.0; //delta * _current_ripple; } else{ - _current_read = _current +( delta * currentRipple ); + _current_read = _current +( delta * _current_ripple ); } attr.set_value(&_current_read); /* clang-format off */ @@ -307,7 +316,7 @@ void SimulatedE2PS::read_current(Tango::Attribute &attr) //-------------------------------------------------------- /** * Write attribute current related method - * Description: The powersupply current setting in amps + * Description: The powersupply current setting in amps * * Data type: Tango::DevDouble * Attr type: Scalar @@ -329,7 +338,7 @@ void SimulatedE2PS::write_current(Tango::WAttribute &attr) //-------------------------------------------------------- /** * Read attribute voltage related method - * Description: The powersupply voltage in volts. + * Description: The powersupply voltage in volts. * * Data type: Tango::DevDouble * Attr type: Scalar @@ -348,7 +357,7 @@ void SimulatedE2PS::read_voltage(Tango::Attribute &attr) //-------------------------------------------------------- /** * Read attribute currentSet related method - * Description: The current set value as stored in the powersupply. + * Description: The current set value as stored in the powersupply. * * Data type: Tango::DevDouble * Attr type: Scalar @@ -364,11 +373,95 @@ void SimulatedE2PS::read_currentSet(Tango::Attribute &attr) /* clang-format off */ /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::read_currentSet } +//-------------------------------------------------------- +/** + * Read attribute CurrentRipple related method + * Description: Amplitude of current ripple (noise) added to output. + * Initial value from property CurrentRipple + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void SimulatedE2PS::read_CurrentRipple(Tango::Attribute &attr) +{ + DEBUG_STREAM << "SimulatedE2PS::read_CurrentRipple(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(SimulatedE2PS::read_CurrentRipple) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(&_current_ripple); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::read_CurrentRipple +} +//-------------------------------------------------------- +/** + * Write attribute CurrentRipple related method + * Description: Amplitude of current ripple (noise) added to output. + * Initial value from property CurrentRipple + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void SimulatedE2PS::write_CurrentRipple(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "SimulatedE2PS::write_CurrentRipple(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(SimulatedE2PS::write_CurrentRipple) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + _current_ripple = w_val; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::write_CurrentRipple +} +//-------------------------------------------------------- +/** + * Read attribute AddRipple related method + * Description: Switch on/off current ripple. If False the power supply is ideal :no noise. + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void SimulatedE2PS::read_AddRipple(Tango::Attribute &attr) +{ + DEBUG_STREAM << "SimulatedE2PS::read_AddRipple(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(SimulatedE2PS::read_AddRipple) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(&_add_ripple); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::read_AddRipple +} +//-------------------------------------------------------- +/** + * Write attribute AddRipple related method + * Description: Switch on/off current ripple. If False the power supply is ideal :no noise. + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void SimulatedE2PS::write_AddRipple(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "SimulatedE2PS::write_AddRipple(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(SimulatedE2PS::write_AddRipple) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + _add_ripple = w_val; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::write_AddRipple +} //-------------------------------------------------------- /** - * Method : SimulatedE2PS::add_dynamic_attributes() - * Description: Create the dynamic attributes if any + * Method : SimulatedE2PS::add_dynamic_attributes() + * Description: Create the dynamic attributes if any * for specified device. */ //-------------------------------------------------------- @@ -384,7 +477,7 @@ void SimulatedE2PS::add_dynamic_attributes() //-------------------------------------------------------- /** * Command On related method - * Description: Switch powersupply ON. + * Description: Switch powersupply ON. * */ //-------------------------------------------------------- @@ -405,7 +498,7 @@ void SimulatedE2PS::on() //-------------------------------------------------------- /** * Command Off related method - * Description: Switch power supply OFF. + * Description: Switch power supply OFF. * */ //-------------------------------------------------------- @@ -432,7 +525,7 @@ void SimulatedE2PS::off() //-------------------------------------------------------- /** * Command Reset related method - * Description: Reset the powersupply to a well known state. + * Description: Reset the powersupply to a well known state. * */ //-------------------------------------------------------- @@ -473,7 +566,7 @@ void SimulatedE2PS::start_cycling() //-------------------------------------------------------- /** * Command Abort related method - * Description: stop ramp or cycling + * Description: stop ramp or cycling * */ //-------------------------------------------------------- @@ -491,7 +584,7 @@ void SimulatedE2PS::abort() //-------------------------------------------------------- /** * Command Fault related method - * Description: Force a simulated faulty condtion + * Description: Force a simulated faulty condtion * */ //-------------------------------------------------------- @@ -517,8 +610,8 @@ void SimulatedE2PS::fault() } //-------------------------------------------------------- /** - * Method : SimulatedE2PS::add_dynamic_commands() - * Description: Create the dynamic commands if any + * Method : SimulatedE2PS::add_dynamic_commands() + * Description: Create the dynamic commands if any * for specified device. */ //-------------------------------------------------------- diff --git a/src/SimulatedE2PS.h b/src/SimulatedE2PS.h index dcf8853..78de624 100644 --- a/src/SimulatedE2PS.h +++ b/src/SimulatedE2PS.h @@ -74,9 +74,11 @@ class SimulatedE2PS : public TANGO_BASE_CLASS protected : double _current; double _current_read; + double _current_ripple; double _voltage; double _ohm; bool _busy; + bool _add_ripple; unsigned int rand_r_seed; class cyclethread *cycleloop; bool thread_running; @@ -98,6 +100,8 @@ public: Tango::DevDouble *attr_current_read; Tango::DevDouble *attr_voltage_read; Tango::DevDouble *attr_currentSet_read; + Tango::DevDouble *attr_CurrentRipple_read; + Tango::DevBoolean *attr_AddRipple_read; // Constructors and destructors public: @@ -153,24 +157,24 @@ public: public: //-------------------------------------------------------- /* - * Method : SimulatedE2PS::read_attr_hardware() - * Description: Hardware acquisition for attributes. + * Method : SimulatedE2PS::read_attr_hardware() + * Description: Hardware acquisition for attributes. */ //-------------------------------------------------------- virtual void read_attr_hardware(std::vector<long> &attr_list); //-------------------------------------------------------- /* - * Method : SimulatedE2PS::write_attr_hardware() - * Description: Hardware writing for attributes. + * Method : SimulatedE2PS::write_attr_hardware() + * Description: Hardware writing for attributes. */ //-------------------------------------------------------- virtual void write_attr_hardware(std::vector<long> &attr_list); /** * Attribute current related methods - * Description: The powersupply current setting in amps + * Description: The powersupply current setting in amps * - * Data type: Tango::DevDouble + * Data type: Tango::DevDouble * Attr type: Scalar */ virtual void read_current(Tango::Attribute &attr); @@ -178,28 +182,49 @@ public: virtual bool is_current_allowed(Tango::AttReqType type); /** * Attribute voltage related methods - * Description: The powersupply voltage in volts. + * Description: The powersupply voltage in volts. * - * Data type: Tango::DevDouble + * Data type: Tango::DevDouble * Attr type: Scalar */ virtual void read_voltage(Tango::Attribute &attr); virtual bool is_voltage_allowed(Tango::AttReqType type); /** * Attribute currentSet related methods - * Description: The current set value as stored in the powersupply. + * Description: The current set value as stored in the powersupply. * - * Data type: Tango::DevDouble + * Data type: Tango::DevDouble * Attr type: Scalar */ virtual void read_currentSet(Tango::Attribute &attr); virtual bool is_currentSet_allowed(Tango::AttReqType type); +/** + * Attribute CurrentRipple related methods + * Description: Amplitude of current ripple (noise) added to output. + * Initial value from property CurrentRipple + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_CurrentRipple(Tango::Attribute &attr); + virtual void write_CurrentRipple(Tango::WAttribute &attr); + virtual bool is_CurrentRipple_allowed(Tango::AttReqType type); +/** + * Attribute AddRipple related methods + * Description: Switch on/off current ripple. If False the power supply is ideal :no noise. + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_AddRipple(Tango::Attribute &attr); + virtual void write_AddRipple(Tango::WAttribute &attr); + virtual bool is_AddRipple_allowed(Tango::AttReqType type); //-------------------------------------------------------- /** - * Method : SimulatedE2PS::add_dynamic_attributes() - * Description: Add dynamic attributes if any. + * Method : SimulatedE2PS::add_dynamic_attributes() + * Description: Add dynamic attributes if any. */ //-------------------------------------------------------- void add_dynamic_attributes(); @@ -211,21 +236,21 @@ public: public: /** * Command On related method - * Description: Switch powersupply ON. + * Description: Switch powersupply ON. * */ virtual void on(); virtual bool is_On_allowed(const CORBA::Any &any); /** * Command Off related method - * Description: Switch power supply OFF. + * Description: Switch power supply OFF. * */ virtual void off(); virtual bool is_Off_allowed(const CORBA::Any &any); /** * Command Reset related method - * Description: Reset the powersupply to a well known state. + * Description: Reset the powersupply to a well known state. * */ virtual void reset(); @@ -239,14 +264,14 @@ public: virtual bool is_StartCycling_allowed(const CORBA::Any &any); /** * Command Abort related method - * Description: stop ramp or cycling + * Description: stop ramp or cycling * */ virtual void abort(); virtual bool is_Abort_allowed(const CORBA::Any &any); /** * Command Fault related method - * Description: Force a simulated faulty condtion + * Description: Force a simulated faulty condtion * */ virtual void fault(); @@ -255,8 +280,8 @@ public: //-------------------------------------------------------- /** - * Method : SimulatedE2PS::add_dynamic_commands() - * Description: Add dynamic commands if any. + * Method : SimulatedE2PS::add_dynamic_commands() + * Description: Add dynamic commands if any. */ //-------------------------------------------------------- void add_dynamic_commands(); diff --git a/src/SimulatedE2PS.xmi b/src/SimulatedE2PS.xmi index 3b12b35..832f4e2 100644 --- a/src/SimulatedE2PS.xmi +++ b/src/SimulatedE2PS.xmi @@ -1,7 +1,7 @@ <?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="SimulatedE2PS" pogoRevision="9.8"> - <description description="Simulated power supply for Elettra 2.0 tests (digiltal twin).
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"> +<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://tango.org/pogo/PogoDsl"> + <classes name="SimulatedE2PS" pogoRevision="9.9"> + <description description="Simulated power supply for Elettra 2.0 tests (digiltal twin).
Tango interface Loosely based on NGPS tango device" title="SimulatedE2PS" sourcePath="/home/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=""/> <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> @@ -129,6 +129,22 @@ <properties description="The current set value as stored in the powersupply." label="" unit="A" standardUnit="1" displayUnit="A" format="%6.4f" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> <readExcludedStates>UNKNOWN</readExcludedStates> </attributes> + <attributes name="CurrentRipple" attType="Scalar" rwType="READ_WRITE" displayLevel="EXPERT" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <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="Amplitude of current ripple (noise) added to output.
Initial value from property CurrentRipple" label="current ripple (noise)" unit="A" standardUnit="1" displayUnit="A" format="%6.6f" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="AddRipple" attType="Scalar" rwType="READ_WRITE" displayLevel="EXPERT" polledPeriod="0" maxX="" maxY="" allocReadMember="false" 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="Switch on/off current ripple. If False the power supply is ideal :no noise." label="add current ripple" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> <states name="UNKNOWN" description="initialization failed or incomlete"> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </states> @@ -147,6 +163,6 @@ <states name="OFF" description="power supply off , not sourcing current"> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </states> - <preferences docHome="./doc_html" makefileHome="/usr/local/tango-9.3.6/share/pogo/preferences"/> + <preferences docHome="./doc_html" makefileHome="$(TANGO_HOME)"/> </classes> </pogoDsl:PogoSystem> diff --git a/src/SimulatedE2PSClass.cpp b/src/SimulatedE2PSClass.cpp index 26d339e..be7b272 100644 --- a/src/SimulatedE2PSClass.cpp +++ b/src/SimulatedE2PSClass.cpp @@ -143,7 +143,7 @@ SimulatedE2PSClass *SimulatedE2PSClass::instance() { if (_instance == NULL) { - std::cerr << "Class is not initialised !!" << std::endl; + std::cerr << "Class is not initialized !!" << std::endl; exit(-1); } return _instance; @@ -268,8 +268,8 @@ CORBA::Any *FaultClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CO //=================================================================== //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::get_class_property() - * Description: Get the class property for specified name. + * Method : SimulatedE2PSClass::get_class_property() + * Description: Get the class property for specified name. */ //-------------------------------------------------------- Tango::DbDatum SimulatedE2PSClass::get_class_property(std::string &prop_name) @@ -283,8 +283,8 @@ Tango::DbDatum SimulatedE2PSClass::get_class_property(std::string &prop_name) //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::get_default_device_property() - * Description: Return the default value for device property. + * Method : SimulatedE2PSClass::get_default_device_property() + * Description: Return the default value for device property. */ //-------------------------------------------------------- Tango::DbDatum SimulatedE2PSClass::get_default_device_property(std::string &prop_name) @@ -298,8 +298,8 @@ Tango::DbDatum SimulatedE2PSClass::get_default_device_property(std::string &prop //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::get_default_class_property() - * Description: Return the default value for class property. + * Method : SimulatedE2PSClass::get_default_class_property() + * Description: Return the default value for class property. */ //-------------------------------------------------------- Tango::DbDatum SimulatedE2PSClass::get_default_class_property(std::string &prop_name) @@ -314,8 +314,8 @@ Tango::DbDatum SimulatedE2PSClass::get_default_class_property(std::string &prop_ //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::set_default_property() - * Description: Set default property (class and device) for wizard. + * Method : SimulatedE2PSClass::set_default_property() + * Description: Set default property (class and device) for wizard. * For each property, add to wizard property name and description. * If default value has been set, add it to wizard property and * store it in a DbDatum. @@ -349,43 +349,43 @@ void SimulatedE2PSClass::set_default_property() //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::write_class_property() - * Description: Set class description fields as property in database + * Method : SimulatedE2PSClass::write_class_property() + * Description: Set class description fields as property in database */ //-------------------------------------------------------- void SimulatedE2PSClass::write_class_property() { -// First time, check if database used -if (Tango::Util::_UseDb == false) - return; - -Tango::DbData data; -std::string classname = get_name(); -std::string header; - -// Put title -Tango::DbDatum title("ProjectTitle"); -std::string str_title("SimulatedE2PS"); -title << str_title; -data.push_back(title); - -// Put Description -Tango::DbDatum description("Description"); -std::vector<std::string> str_desc; -str_desc.push_back("Simulated power supply for Elettra 2.0 tests (digiltal twin)."); -str_desc.push_back("Tango interface Loosely based on NGPS tango device"); -description << str_desc; -data.push_back(description); - -// Put inheritance -Tango::DbDatum inher_datum("InheritedFrom"); -std::vector<std::string> inheritance; -inheritance.push_back("TANGO_BASE_CLASS"); -inher_datum << inheritance; -data.push_back(inher_datum); - -// Call database and and values -get_db_class()->put_property(data); + // First time, check if database used + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + std::string classname = get_name(); + std::string header; + + // Put title + Tango::DbDatum title("ProjectTitle"); + std::string str_title("SimulatedE2PS"); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + std::vector<std::string> str_desc; + str_desc.push_back("Simulated power supply for Elettra 2.0 tests (digiltal twin)."); + str_desc.push_back("Tango interface Loosely based on NGPS tango device"); + description << str_desc; + data.push_back(description); + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + std::vector<std::string> inheritance; + inheritance.push_back("TANGO_BASE_CLASS"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + get_db_class()->put_property(data); } //=================================================================== @@ -394,44 +394,44 @@ get_db_class()->put_property(data); //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::device_factory() - * Description: Create the device object(s) + * Method : SimulatedE2PSClass::device_factory() + * Description: Create the device object(s) * and store them in the device list */ //-------------------------------------------------------- void SimulatedE2PSClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) { -/*----- PROTECTED REGION ID(SimulatedE2PSClass::device_factory_before) ENABLED START -----*/ + /*----- PROTECTED REGION ID(SimulatedE2PSClass::device_factory_before) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // SimulatedE2PSClass::device_factory_before -// Create devices and add it into the device list -for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) -{ - TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << std::endl; - device_list.push_back(new SimulatedE2PS(this, (*devlist_ptr)[i])); -} - -// Manage dynamic attributes if any -erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << std::endl; + device_list.push_back(new SimulatedE2PS(this, (*devlist_ptr)[i])); + } -// Export devices to the outside world -for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) -{ - // Add dynamic attributes if any - SimulatedE2PS *dev = static_cast<SimulatedE2PS *>(device_list[device_list.size()-i]); - dev->add_dynamic_attributes(); + // Manage dynamic attributes if any + erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); - // Check before if database used. - if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) - export_device(dev); - else - export_device(dev, dev->get_name().c_str()); -} + // Export devices to the outside world + for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) + { + // Add dynamic attributes if any + SimulatedE2PS *dev = static_cast<SimulatedE2PS *>(device_list[device_list.size()-i]); + dev->add_dynamic_attributes(); + + // Check before if database used. + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(dev); + else + export_device(dev, dev->get_name().c_str()); + } -/*----- PROTECTED REGION ID(SimulatedE2PSClass::device_factory_after) ENABLED START -----*/ + /*----- PROTECTED REGION ID(SimulatedE2PSClass::device_factory_after) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ @@ -439,8 +439,8 @@ for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) } //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::attribute_factory() - * Description: Create the attribute object(s) + * Method : SimulatedE2PSClass::attribute_factory() + * Description: Create the attribute object(s) * and store them in the attribute list */ //-------------------------------------------------------- @@ -520,6 +520,52 @@ void SimulatedE2PSClass::attribute_factory(std::vector<Tango::Attr *> &att_list) // Not Memorized att_list.push_back(currentset); + // Attribute : CurrentRipple + CurrentRippleAttrib *currentripple = new CurrentRippleAttrib(); + Tango::UserDefaultAttrProp currentripple_prop; + currentripple_prop.set_description("Amplitude of current ripple (noise) added to output.\nInitial value from property CurrentRipple"); + currentripple_prop.set_label("current ripple (noise)"); + currentripple_prop.set_unit("A"); + currentripple_prop.set_standard_unit("1"); + currentripple_prop.set_display_unit("A"); + currentripple_prop.set_format("%6.6f"); + // max_value not set for CurrentRipple + // min_value not set for CurrentRipple + // max_alarm not set for CurrentRipple + // min_alarm not set for CurrentRipple + // max_warning not set for CurrentRipple + // min_warning not set for CurrentRipple + // delta_t not set for CurrentRipple + // delta_val not set for CurrentRipple + currentripple->set_default_properties(currentripple_prop); + // Not Polled + currentripple->set_disp_level(Tango::EXPERT); + // Not Memorized + att_list.push_back(currentripple); + + // Attribute : AddRipple + AddRippleAttrib *addripple = new AddRippleAttrib(); + Tango::UserDefaultAttrProp addripple_prop; + addripple_prop.set_description("Switch on/off current ripple. If False the power supply is ideal :no noise."); + addripple_prop.set_label("add current ripple"); + // unit not set for AddRipple + // standard_unit not set for AddRipple + // display_unit not set for AddRipple + // format not set for AddRipple + // max_value not set for AddRipple + // min_value not set for AddRipple + // max_alarm not set for AddRipple + // min_alarm not set for AddRipple + // max_warning not set for AddRipple + // min_warning not set for AddRipple + // delta_t not set for AddRipple + // delta_val not set for AddRipple + addripple->set_default_properties(addripple_prop); + // Not Polled + addripple->set_disp_level(Tango::EXPERT); + // Not Memorized + att_list.push_back(addripple); + // Create a list of static attributes create_static_attribute_list(get_class_attr()->get_attr_list()); @@ -531,8 +577,8 @@ void SimulatedE2PSClass::attribute_factory(std::vector<Tango::Attr *> &att_list) } //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::pipe_factory() - * Description: Create the pipe object(s) + * Method : SimulatedE2PSClass::pipe_factory() + * Description: Create the pipe object(s) * and store them in the pipe list */ //-------------------------------------------------------- @@ -551,8 +597,8 @@ void SimulatedE2PSClass::pipe_factory() } //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::command_factory() - * Description: Create the command object(s) + * Method : SimulatedE2PSClass::command_factory() + * Description: Create the command object(s) * and store them in the command list */ //-------------------------------------------------------- @@ -643,7 +689,7 @@ void SimulatedE2PSClass::create_static_attribute_list(std::vector<Tango::Attr *> for (unsigned long i=0 ; i<att_list.size() ; i++) { std::string att_name(att_list[i]->get_name()); - transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + std::transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); defaultAttList.push_back(att_name); } @@ -699,8 +745,8 @@ void SimulatedE2PSClass::erase_dynamic_attributes(const Tango::DevVarStringArray //-------------------------------------------------------- /** - * Method : SimulatedE2PSClass::get_attr_object_by_name() - * Description: returns Tango::Attr * object found by name + * Method : SimulatedE2PSClass::get_attr_object_by_name() + * Description: returns Tango::Attr * object found by name */ //-------------------------------------------------------- Tango::Attr *SimulatedE2PSClass::get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname) diff --git a/src/SimulatedE2PSClass.h b/src/SimulatedE2PSClass.h index c24a21a..1491e0f 100644 --- a/src/SimulatedE2PSClass.h +++ b/src/SimulatedE2PSClass.h @@ -61,8 +61,8 @@ class currentAttrib: public Tango::Attr { public: currentAttrib():Attr("current", - Tango::DEV_DOUBLE, Tango::READ_WRITE) {}; - ~currentAttrib() {}; + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~currentAttrib() {} virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) {(static_cast<SimulatedE2PS *>(dev))->read_current(att);} virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) @@ -76,8 +76,8 @@ class voltageAttrib: public Tango::Attr { public: voltageAttrib():Attr("voltage", - Tango::DEV_DOUBLE, Tango::READ) {}; - ~voltageAttrib() {}; + Tango::DEV_DOUBLE, Tango::READ) {} + ~voltageAttrib() {} virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) {(static_cast<SimulatedE2PS *>(dev))->read_voltage(att);} virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) @@ -89,14 +89,44 @@ class currentSetAttrib: public Tango::Attr { public: currentSetAttrib():Attr("currentSet", - Tango::DEV_DOUBLE, Tango::READ) {}; - ~currentSetAttrib() {}; + Tango::DEV_DOUBLE, Tango::READ) {} + ~currentSetAttrib() {} virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) {(static_cast<SimulatedE2PS *>(dev))->read_currentSet(att);} virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) {return (static_cast<SimulatedE2PS *>(dev))->is_currentSet_allowed(ty);} }; +// Attribute CurrentRipple class definition +class CurrentRippleAttrib: public Tango::Attr +{ +public: + CurrentRippleAttrib():Attr("CurrentRipple", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~CurrentRippleAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<SimulatedE2PS *>(dev))->read_CurrentRipple(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<SimulatedE2PS *>(dev))->write_CurrentRipple(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<SimulatedE2PS *>(dev))->is_CurrentRipple_allowed(ty);} +}; + +// Attribute AddRipple class definition +class AddRippleAttrib: public Tango::Attr +{ +public: + AddRippleAttrib():Attr("AddRipple", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {} + ~AddRippleAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<SimulatedE2PS *>(dev))->read_AddRipple(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<SimulatedE2PS *>(dev))->write_AddRipple(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<SimulatedE2PS *>(dev))->is_AddRipple_allowed(ty);} +}; + //========================================= // Define classes for commands @@ -111,13 +141,13 @@ public: const char *in_desc, const char *out_desc, Tango::DispLevel level) - :Command(cmd_name,in,out,in_desc,out_desc, level) {}; + :Command(cmd_name,in,out,in_desc,out_desc, level) {} OnClass(const char *cmd_name, Tango::CmdArgType in, Tango::CmdArgType out) - :Command(cmd_name,in,out) {}; - ~OnClass() {}; + :Command(cmd_name,in,out) {} + ~OnClass() {} virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) @@ -134,13 +164,13 @@ public: const char *in_desc, const char *out_desc, Tango::DispLevel level) - :Command(cmd_name,in,out,in_desc,out_desc, level) {}; + :Command(cmd_name,in,out,in_desc,out_desc, level) {} OffClass(const char *cmd_name, Tango::CmdArgType in, Tango::CmdArgType out) - :Command(cmd_name,in,out) {}; - ~OffClass() {}; + :Command(cmd_name,in,out) {} + ~OffClass() {} virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) @@ -157,13 +187,13 @@ public: const char *in_desc, const char *out_desc, Tango::DispLevel level) - :Command(cmd_name,in,out,in_desc,out_desc, level) {}; + :Command(cmd_name,in,out,in_desc,out_desc, level) {} ResetClass(const char *cmd_name, Tango::CmdArgType in, Tango::CmdArgType out) - :Command(cmd_name,in,out) {}; - ~ResetClass() {}; + :Command(cmd_name,in,out) {} + ~ResetClass() {} virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) @@ -180,13 +210,13 @@ public: const char *in_desc, const char *out_desc, Tango::DispLevel level) - :Command(cmd_name,in,out,in_desc,out_desc, level) {}; + :Command(cmd_name,in,out,in_desc,out_desc, level) {} StartCyclingClass(const char *cmd_name, Tango::CmdArgType in, Tango::CmdArgType out) - :Command(cmd_name,in,out) {}; - ~StartCyclingClass() {}; + :Command(cmd_name,in,out) {} + ~StartCyclingClass() {} virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) @@ -203,13 +233,13 @@ public: const char *in_desc, const char *out_desc, Tango::DispLevel level) - :Command(cmd_name,in,out,in_desc,out_desc, level) {}; + :Command(cmd_name,in,out,in_desc,out_desc, level) {} AbortClass(const char *cmd_name, Tango::CmdArgType in, Tango::CmdArgType out) - :Command(cmd_name,in,out) {}; - ~AbortClass() {}; + :Command(cmd_name,in,out) {} + ~AbortClass() {} virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) @@ -226,13 +256,13 @@ public: const char *in_desc, const char *out_desc, Tango::DispLevel level) - :Command(cmd_name,in,out,in_desc,out_desc, level) {}; + :Command(cmd_name,in,out,in_desc,out_desc, level) {} FaultClass(const char *cmd_name, Tango::CmdArgType in, Tango::CmdArgType out) - :Command(cmd_name,in,out) {}; - ~FaultClass() {}; + :Command(cmd_name,in,out) {} + ~FaultClass() {} virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) diff --git a/src/SimulatedE2PSStateMachine.cpp b/src/SimulatedE2PSStateMachine.cpp index d2a8df9..9e3de3c 100644 --- a/src/SimulatedE2PSStateMachine.cpp +++ b/src/SimulatedE2PSStateMachine.cpp @@ -54,8 +54,8 @@ namespace SimulatedE2PS_ns //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_current_allowed() - * Description: Execution allowed for current attribute + * Method : SimulatedE2PS::is_current_allowed() + * Description: Execution allowed for current attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_current_allowed(TANGO_UNUSED(Tango::AttReqType type)) @@ -100,8 +100,8 @@ bool SimulatedE2PS::is_current_allowed(TANGO_UNUSED(Tango::AttReqType type)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_voltage_allowed() - * Description: Execution allowed for voltage attribute + * Method : SimulatedE2PS::is_voltage_allowed() + * Description: Execution allowed for voltage attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_voltage_allowed(TANGO_UNUSED(Tango::AttReqType type)) @@ -126,8 +126,8 @@ bool SimulatedE2PS::is_voltage_allowed(TANGO_UNUSED(Tango::AttReqType type)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_currentSet_allowed() - * Description: Execution allowed for currentSet attribute + * Method : SimulatedE2PS::is_currentSet_allowed() + * Description: Execution allowed for currentSet attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_currentSet_allowed(TANGO_UNUSED(Tango::AttReqType type)) @@ -150,6 +150,50 @@ bool SimulatedE2PS::is_currentSet_allowed(TANGO_UNUSED(Tango::AttReqType type)) return true; } +//-------------------------------------------------------- +/** + * Method : SimulatedE2PS::is_CurrentRipple_allowed() + * Description: Execution allowed for CurrentRipple attribute + */ +//-------------------------------------------------------- +bool SimulatedE2PS::is_CurrentRipple_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for CurrentRipple attribute in Write access. + /*----- PROTECTED REGION ID(SimulatedE2PS::CurrentRippleStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::CurrentRippleStateAllowed_WRITE + + // Not any excluded states for CurrentRipple attribute in read access. + /*----- PROTECTED REGION ID(SimulatedE2PS::CurrentRippleStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::CurrentRippleStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : SimulatedE2PS::is_AddRipple_allowed() + * Description: Execution allowed for AddRipple attribute + */ +//-------------------------------------------------------- +bool SimulatedE2PS::is_AddRipple_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for AddRipple attribute in Write access. + /*----- PROTECTED REGION ID(SimulatedE2PS::AddRippleStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::AddRippleStateAllowed_WRITE + + // Not any excluded states for AddRipple attribute in read access. + /*----- PROTECTED REGION ID(SimulatedE2PS::AddRippleStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::AddRippleStateAllowed_READ + return true; +} + //================================================= // Commands Allowed Methods @@ -157,8 +201,8 @@ bool SimulatedE2PS::is_currentSet_allowed(TANGO_UNUSED(Tango::AttReqType type)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_On_allowed() - * Description: Execution allowed for On attribute + * Method : SimulatedE2PS::is_On_allowed() + * Description: Execution allowed for On attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_On_allowed(TANGO_UNUSED(const CORBA::Any &any)) @@ -178,8 +222,8 @@ bool SimulatedE2PS::is_On_allowed(TANGO_UNUSED(const CORBA::Any &any)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_Off_allowed() - * Description: Execution allowed for Off attribute + * Method : SimulatedE2PS::is_Off_allowed() + * Description: Execution allowed for Off attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_Off_allowed(TANGO_UNUSED(const CORBA::Any &any)) @@ -199,8 +243,8 @@ bool SimulatedE2PS::is_Off_allowed(TANGO_UNUSED(const CORBA::Any &any)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_Reset_allowed() - * Description: Execution allowed for Reset attribute + * Method : SimulatedE2PS::is_Reset_allowed() + * Description: Execution allowed for Reset attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_Reset_allowed(TANGO_UNUSED(const CORBA::Any &any)) @@ -219,8 +263,8 @@ bool SimulatedE2PS::is_Reset_allowed(TANGO_UNUSED(const CORBA::Any &any)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_StartCycling_allowed() - * Description: Execution allowed for StartCycling attribute + * Method : SimulatedE2PS::is_StartCycling_allowed() + * Description: Execution allowed for StartCycling attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_StartCycling_allowed(TANGO_UNUSED(const CORBA::Any &any)) @@ -240,8 +284,8 @@ bool SimulatedE2PS::is_StartCycling_allowed(TANGO_UNUSED(const CORBA::Any &any)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_Abort_allowed() - * Description: Execution allowed for Abort attribute + * Method : SimulatedE2PS::is_Abort_allowed() + * Description: Execution allowed for Abort attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_Abort_allowed(TANGO_UNUSED(const CORBA::Any &any)) @@ -261,8 +305,8 @@ bool SimulatedE2PS::is_Abort_allowed(TANGO_UNUSED(const CORBA::Any &any)) //-------------------------------------------------------- /** - * Method : SimulatedE2PS::is_Fault_allowed() - * Description: Execution allowed for Fault attribute + * Method : SimulatedE2PS::is_Fault_allowed() + * Description: Execution allowed for Fault attribute */ //-------------------------------------------------------- bool SimulatedE2PS::is_Fault_allowed(TANGO_UNUSED(const CORBA::Any &any)) -- GitLab