diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0ea3d3f92b974e57fbe8dc1a2f45355c690c9152 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +.pydevproject +.project +.cproject +.settings +obj +bin +core* +*~ +*.pyc +*.so +*.so* +.pylintrc +.metadata +.idea +.cvsignore +.nse_depinfo +software +oldsrc diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..7a5c362a201c5161b81fc3fb0773418d8db9c3dd --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +NAME_SRV = tpg300-srv + +#CXXFLAGS = +#LDFLAGS = + +include ../makefiles/Make-9.3.3.in diff --git a/README.md b/README.md index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..84465ebf8f6ebe772bcebba1f40038338e9c1764 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,34 @@ +# Project Name + +tpg300 + +## Description + +Tango device server for Pfeiffer TPG300 Total Pressure Gauge Controller + + +## Installation + +See your institue guidelines for deploying and configuring a Tango device server. + +## Usage + +The server is designed for controlling remotely a Balzers TPG300 as used in atypical particle accelerator + + + +## History + + +2019-12-09 : project created on gitlab, derived from CVS release_03 + +## Credits + + +Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +Strada Statale 14 - km 163,5 in AREA Science Park +34149 Basovizza, Trieste ITALY + +## License + +GPL 3 diff --git a/docs/TPG_300.pdf b/docs/TPG_300.pdf new file mode 100644 index 0000000000000000000000000000000000000000..7ed897f8081ca7fcb0ef2c5461b2190553f0f9c9 Binary files /dev/null and b/docs/TPG_300.pdf differ diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..273657a29a54e591c73cef184bd25fac1af76851 --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,52 @@ +/*----- PROTECTED REGION ID(Tpg300::ClassFactory.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: ClassFactory.cpp,v 1.4 2012-09-10 08:01:04 mdm Exp $"; +//============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible for the creation of +// all class singleton for a device server. It is called +// at device server startup. +// +// project : Blzer Tpg 300. +// +// $Author: mdm $ +// +// $Revision: 1.4 $ +// $Date: 2012-09-10 08:01:04 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/ClassFactory.cpp,v $ +// $Log: ClassFactory.cpp,v $ +// Revision 1.4 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <tango.h> +#include <Tpg300Class.h> + +// Add class header files if needed + + +/** + * Create Tpg300 Class singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + // Add method class init if needed + + add_class(Tpg300_ns::Tpg300Class::init("Tpg300")); +} + +/*----- PROTECTED REGION END -----*/ diff --git a/src/ThreadGuard.h b/src/ThreadGuard.h new file mode 100644 index 0000000000000000000000000000000000000000..812cc8f026e20c45ef5b5173c4f9387069bb80a6 --- /dev/null +++ b/src/ThreadGuard.h @@ -0,0 +1,29 @@ +/* + * ThreadGuard.h + * + * Created on: Nov 30, 2011 + * Author: mdm + */ + +#ifndef THREADGUARD_H_ +#define THREADGUARD_H_ + +namespace Tpg300_ns +{ + class ThreadGuard + { + public: + ThreadGuard(omni_mutex& m) : mutex(m) + { + mutex.lock(); + } + ~ThreadGuard() + { + mutex.unlock(); + } + private: + omni_mutex& mutex; + }; +} + +#endif /* THREADGUARD_H_ */ diff --git a/src/Tpg300.cpp b/src/Tpg300.cpp new file mode 100644 index 0000000000000000000000000000000000000000..719d1080890bcd889d2a7147e08f84ff206e9cec --- /dev/null +++ b/src/Tpg300.cpp @@ -0,0 +1,1548 @@ +/*----- PROTECTED REGION ID(Tpg300.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: Tpg300.cpp,v 1.8 2016-10-18 15:53:02 claudio Exp $"; +//============================================================================= +// +// file : Tpg300.cpp +// +// description : C++ source for the Tpg300 and its commands. +// The class is derived from Device. It represents the +// CORBA servant object which will be accessed from the +// network. All commands which can be executed on the +// Tpg300 are implemented in this file. +// +// project : Balzer Tpg 300. +// +// $Author: claudio $ +// +// $Revision: 1.8 $ +// $Date: 2016-10-18 15:53:02 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/Tpg300.cpp,v $ +// $Log: Tpg300.cpp,v $ +// Revision 1.8 2016-10-18 15:53:02 claudio +// tango9 +// +// Revision 1.7 2013-06-12 09:57:05 lorenzo +// Added DeviceState and DeviceStatus attributes +// +// Revision 1.6 2013-06-05 14:59:10 lorenzo +// Tango 8.0.5 +// +// Revision 1.5 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <Tpg300.h> +#include <Tpg300Class.h> +#include <Tpg300Proxy.h> +#include <Tpg300Error.h> +#include <Tpg300SPManager.h> +#include <Tpg300Channel.h> +#include <Tpg300Thread.h> +#include <Tpg300Utils.h> + +#include "devicestate.h" + +/*----- PROTECTED REGION END -----*/ + + +/** + * Tpg300 class description: + * Total pressure gauge and controller + */ + +//================================================================ +// +// The following table gives the correspondence +// between command and method names. +// +// Command name | Method name +//---------------------------------------------------------------- +// State | Inherited (no method) +// Status | Inherited (no method) +// SensorOn | sensor_on +// SensorOff | sensor_off +// WriteLowerThreshold | write_lower_threshold +// ReadLowerThreshold | read_lower_threshold +// WriteUpperThreshold | write_upper_threshold +// ReadUpperThreshold | read_upper_threshold +// ReadSensorSource | read_sensor_source +// WriteSensorSource | write_sensor_source +// RegisterName | register_name +// UnregisterName | unregister_name +//================================================================ + +namespace Tpg300_ns +{ + /*----- PROTECTED REGION ID(Tpg300::namespace_starting) ENABLED START -----*/ + + // static initializations + + /*----- PROTECTED REGION END -----*/ // Tpg300::namespace_starting + + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300() + * Description : Constructors for a Tango device + * implementing the class Tpg300 + */ +//-------------------------------------------------------- +Tpg300::Tpg300(Tango::DeviceClass *cl, string &s) + : TANGO_BASE_CLASS(cl, s.c_str()) +{ + /*----- PROTECTED REGION ID(Tpg300::constructor_1) ENABLED START -----*/ + + init_device(); + + /*----- PROTECTED REGION END -----*/ // Tpg300::constructor_1 +} +//-------------------------------------------------------- +Tpg300::Tpg300(Tango::DeviceClass *cl, const char *s) + : TANGO_BASE_CLASS(cl, s) +{ + /*----- PROTECTED REGION ID(Tpg300::constructor_2) ENABLED START -----*/ + + init_device(); + + /*----- PROTECTED REGION END -----*/ // Tpg300::constructor_2 +} +//-------------------------------------------------------- +Tpg300::Tpg300(Tango::DeviceClass *cl, const char *s, const char *d) + : TANGO_BASE_CLASS(cl, s, d) +{ + /*----- PROTECTED REGION ID(Tpg300::constructor_3) ENABLED START -----*/ + + init_device(); + + /*----- PROTECTED REGION END -----*/ // Tpg300::constructor_3 +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::delete_device()() + * Description : will be called at device destruction or at init command + */ +//-------------------------------------------------------- +void Tpg300::delete_device() +{ + /*----- PROTECTED REGION ID(Tpg300::delete_device) ENABLED START -----*/ + + DEBUG_STREAM << "Tpg300::delete_device() delete device " << device_name << endl; + + if(thread) + { + thread->kill_thread(); + + unsigned long sec; + unsigned long nsec; + + unsigned long timeout_sec = timeout/1000; + unsigned long timeout_nsec = (timeout%1000)*1000000; + + omni_thread::get_time(&sec, &nsec, timeout_sec, timeout_nsec); + + stop_condition->timedwait(sec, nsec); + + thread = 0; + } + + if(channel_0) + { + delete channel_0; + channel_0 = 0; + } + if(channel_1) + { + delete channel_1; + channel_1 = 0; + } + if(channel_2) + { + delete channel_2; + channel_2 = 0; + } + if(channel_3) + { + delete channel_3; + channel_3 = 0; + } + + if(sp_manager) + { + delete sp_manager; + sp_manager = 0; + } + + if(error_status) + { + delete error_status; + error_status = 0; + } + + if(proxy) + { + delete proxy; + proxy = 0; + } + + delete stop_condition; + delete stop_mutex; + + + Tpg300Utils::string_free(attr_Status_0_read); + Tpg300Utils::string_free(attr_Status_1_read); + Tpg300Utils::string_free(attr_Status_2_read); + Tpg300Utils::string_free(attr_Status_3_read); + + Tpg300Utils::string_free(attr_Name_0_read); + Tpg300Utils::string_free(attr_Name_1_read); + Tpg300Utils::string_free(attr_Name_2_read); + Tpg300Utils::string_free(attr_Name_3_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::delete_device + delete[] attr_Pressure_0_read; + delete[] attr_Pressure_1_read; + delete[] attr_Pressure_2_read; + delete[] attr_Pressure_3_read; + delete[] attr_State_0_read; + delete[] attr_State_1_read; + delete[] attr_State_2_read; + delete[] attr_State_3_read; + delete[] attr_Status_0_read; + delete[] attr_Status_1_read; + delete[] attr_Status_2_read; + delete[] attr_Status_3_read; + delete[] attr_Name_0_read; + delete[] attr_Name_1_read; + delete[] attr_Name_2_read; + delete[] attr_Name_3_read; + delete[] attr_DeviceState_read; + delete[] attr_DeviceStatus_read; + delete[] attr_SetPointStatus_read; + +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::init_device() + * Description : // will be called at device initialization. + */ +//-------------------------------------------------------- +void Tpg300::init_device() +{ + DEBUG_STREAM << "Tpg300::init_device() create device " << device_name << endl; + + /*----- PROTECTED REGION ID(Tpg300::init_device_before) ENABLED START -----*/ + + set_state(Tango::INIT); + set_status("Device server initialization"); + + proxy = 0; + + error_status = 0; + + sp_manager = 0; + + channel_0 = 0; + channel_1 = 0; + channel_2 = 0; + channel_3 = 0; + + thread = 0; + + init_completed = false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::init_device_before + + // Get the device properties (if any) from database + get_device_property(); + + attr_Pressure_0_read = new Tango::DevDouble[1]; + attr_Pressure_1_read = new Tango::DevDouble[1]; + attr_Pressure_2_read = new Tango::DevDouble[1]; + attr_Pressure_3_read = new Tango::DevDouble[1]; + attr_State_0_read = new Tango::DevState[1]; + attr_State_1_read = new Tango::DevState[1]; + attr_State_2_read = new Tango::DevState[1]; + attr_State_3_read = new Tango::DevState[1]; + attr_Status_0_read = new Tango::DevString[1]; + attr_Status_1_read = new Tango::DevString[1]; + attr_Status_2_read = new Tango::DevString[1]; + attr_Status_3_read = new Tango::DevString[1]; + attr_Name_0_read = new Tango::DevString[1]; + attr_Name_1_read = new Tango::DevString[1]; + attr_Name_2_read = new Tango::DevString[1]; + attr_Name_3_read = new Tango::DevString[1]; + attr_DeviceState_read = new Tango::DevUChar[1]; + attr_DeviceStatus_read = new Tango::DevString[1]; + attr_SetPointStatus_read = new Tango::DevBoolean[6]; + + /*----- PROTECTED REGION ID(Tpg300::init_device) ENABLED START -----*/ + + Tpg300Utils::string_alloc(attr_Status_0_read); + Tpg300Utils::string_alloc(attr_Status_1_read); + Tpg300Utils::string_alloc(attr_Status_2_read); + Tpg300Utils::string_alloc(attr_Status_3_read); + + Tpg300Utils::string_alloc(attr_Name_0_read); + Tpg300Utils::string_alloc(attr_Name_1_read); + Tpg300Utils::string_alloc(attr_Name_2_read); + Tpg300Utils::string_alloc(attr_Name_3_read); + + stop_mutex = new omni_mutex(); + stop_condition = new omni_condition(stop_mutex); + + if(get_state() != Tango::FAULT) + { + try + { + proxy = new Tpg300Proxy(serialDevice, timeout, proxySleep); + + proxy->write_read("UNI,1"); + + vector<Tpg300Task *> task_vector; + + error_status = new Tpg300Error(proxy); + task_vector.push_back(error_status); + + sp_manager = new Tpg300SPManager(proxy); + task_vector.push_back(sp_manager); + + channel_0 = new Tpg300Channel(proxy, Tpg300Channel::CHANNEL_0); + task_vector.push_back(channel_0); + + channel_1 = new Tpg300Channel(proxy, Tpg300Channel::CHANNEL_1); + task_vector.push_back(channel_1); + + channel_2 = new Tpg300Channel(proxy, Tpg300Channel::CHANNEL_2); + task_vector.push_back(channel_2); + + channel_3 = new Tpg300Channel(proxy, Tpg300Channel::CHANNEL_3); + task_vector.push_back(channel_3); + + thread = new Tpg300Thread(task_vector, threadSleep, stop_condition); + + init_completed = true; + } + catch(Tango::DevFailed& ex) + { + set_state( Tango::FAULT ); + set_status( Tpg300Utils::get_trace(ex) ); + } + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::init_device +} + + + +//-------------------------------------------------------- +/** + * Method : Tpg300::get_device_property() + * Description : // Add your own code to initialize + */ +//-------------------------------------------------------- +void Tpg300::get_device_property() +{ + /*----- PROTECTED REGION ID(Tpg300::get_device_property_before) ENABLED START -----*/ + + // Initialize property data members + + /*----- PROTECTED REGION END -----*/ // Tpg300::get_device_property_before + + + // Read device properties from database. + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("SerialDevice")); + dev_prop.push_back(Tango::DbDatum("Timeout")); + dev_prop.push_back(Tango::DbDatum("ThreadSleep")); + dev_prop.push_back(Tango::DbDatum("ProxySleep")); + + // 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 Tpg300Class to get class property + Tango::DbDatum def_prop, cl_prop; + Tpg300Class *ds_class = + (static_cast<Tpg300Class *>(get_device_class())); + int i = -1; + + // Try to initialize SerialDevice from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> serialDevice; + else { + // Try to initialize SerialDevice from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> serialDevice; + } + // And try to extract SerialDevice value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> serialDevice; + + // Try to initialize Timeout from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> timeout; + else { + // Try to initialize Timeout from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> timeout; + } + // And try to extract Timeout value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> timeout; + + // Try to initialize ThreadSleep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> threadSleep; + else { + // Try to initialize ThreadSleep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> threadSleep; + } + // And try to extract ThreadSleep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> threadSleep; + + // Try to initialize ProxySleep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> proxySleep; + else { + // Try to initialize ProxySleep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> proxySleep; + } + // And try to extract ProxySleep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> proxySleep; + + + } + /*----- PROTECTED REGION ID(Tpg300::get_device_property_after) ENABLED START -----*/ + + if(dev_prop[0].is_empty()) + { + set_state(Tango::FAULT); + set_status("SerialDevice property not defined"); + return; + } + + if(serialDevice.empty() || serialDevice.compare("undefined") == 0) + { + set_state(Tango::FAULT); + set_status("SerialDevice property is empty"); + return; + } + + if(dev_prop[1].is_empty()) + { + WARN_STREAM << "Timeout property not defined, default: " << timeout << endl; + } + + if(timeout < 1 || timeout > 10000) + { + set_state(Tango::FAULT); + set_status("Timeout invalid value, valid range [1,10000]"); + return; + } + + if(dev_prop[2].is_empty()) + { + WARN_STREAM << "ThreadSleep property not defined, default: " << threadSleep << endl; + } + + if(threadSleep < 1 || threadSleep > 10000) + { + set_state(Tango::FAULT); + set_status("ThreadSleep invalid value, valid range [1,10000]"); + return; + } + + if(dev_prop[3].is_empty()) + { + WARN_STREAM << "ProxySleep property not defined, default: " << proxySleep << endl; + } + + if(proxySleep < 1 || proxySleep > 10000) + { + set_state(Tango::FAULT); + set_status("ProxySleep invalid value, valid range [1,10000]"); + return; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::get_device_property_after + +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::always_executed_hook() + * Description : method always executed before any command is executed + */ +//-------------------------------------------------------- +void Tpg300::always_executed_hook() +{ + INFO_STREAM << "Tpg300::always_executed_hook() " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::always_executed_hook) ENABLED START -----*/ + + if(init_completed) + { + update_state(); + + update_status(); + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::always_executed_hook +} + + + +//-------------------------------------------------------- +/** + * Method : Tpg300::read_attr_hardware() + * Description : Hardware acquisition for attributes. + */ +//-------------------------------------------------------- +void Tpg300::read_attr_hardware(vector<long> &attr_list) +{ + DEBUG_STREAM << "Tpg300::read_attr_hardware(vector<long> &attr_list) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_attr_hardware) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_attr_hardware + +} + + +//-------------------------------------------------------- +/** + * Read Pressure_0 attribute + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Pressure_0(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Pressure_0(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_0) ENABLED START -----*/ + + *attr_Pressure_0_read = channel_0->get_pressure(); + + attr.set_value(attr_Pressure_0_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_0 +} +//-------------------------------------------------------- +/** + * Read Pressure_1 attribute + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Pressure_1(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Pressure_1(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_1) ENABLED START -----*/ + + *attr_Pressure_1_read = channel_1->get_pressure(); + + attr.set_value(attr_Pressure_1_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_1 +} +//-------------------------------------------------------- +/** + * Read Pressure_2 attribute + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Pressure_2(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Pressure_2(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_2) ENABLED START -----*/ + + *attr_Pressure_2_read = channel_2->get_pressure(); + + attr.set_value(attr_Pressure_2_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_2 +} +//-------------------------------------------------------- +/** + * Read Pressure_3 attribute + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Pressure_3(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Pressure_3(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_3) ENABLED START -----*/ + + *attr_Pressure_3_read = channel_3->get_pressure(); + + attr.set_value(attr_Pressure_3_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_3 +} +//-------------------------------------------------------- +/** + * Read State_0 attribute + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_State_0(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_State_0(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_State_0) ENABLED START -----*/ + + *attr_State_0_read = channel_0->get_state(); + + attr.set_value(attr_State_0_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_0 +} +//-------------------------------------------------------- +/** + * Read State_1 attribute + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_State_1(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_State_1(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_State_1) ENABLED START -----*/ + + *attr_State_1_read = channel_1->get_state(); + + attr.set_value(attr_State_1_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_1 +} +//-------------------------------------------------------- +/** + * Read State_2 attribute + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_State_2(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_State_2(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_State_2) ENABLED START -----*/ + + *attr_State_2_read = channel_2->get_state(); + + attr.set_value(attr_State_2_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_2 +} +//-------------------------------------------------------- +/** + * Read State_3 attribute + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_State_3(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_State_3(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_State_3) ENABLED START -----*/ + + *attr_State_3_read = channel_3->get_state(); + + attr.set_value(attr_State_3_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_3 +} +//-------------------------------------------------------- +/** + * Read Status_0 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Status_0(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Status_0(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Status_0) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Status_0_read, channel_0->get_status()); + + attr.set_value(attr_Status_0_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_0 +} +//-------------------------------------------------------- +/** + * Read Status_1 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Status_1(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Status_1(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Status_1) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Status_1_read, channel_1->get_status()); + + attr.set_value(attr_Status_1_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_1 +} +//-------------------------------------------------------- +/** + * Read Status_2 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Status_2(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Status_2(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Status_2) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Status_2_read, channel_2->get_status()); + + attr.set_value(attr_Status_2_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_2 +} +//-------------------------------------------------------- +/** + * Read Status_3 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Status_3(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Status_3(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Status_3) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Status_3_read, channel_3->get_status()); + + attr.set_value(attr_Status_3_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_3 +} +//-------------------------------------------------------- +/** + * Read Name_0 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Name_0(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Name_0(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Name_0) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Name_0_read, channel_0->get_name()); + + attr.set_value(attr_Name_0_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_0 +} +//-------------------------------------------------------- +/** + * Read Name_1 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Name_1(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Name_1(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Name_1) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Name_1_read, channel_1->get_name()); + + attr.set_value(attr_Name_1_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_1 +} +//-------------------------------------------------------- +/** + * Read Name_2 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Name_2(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Name_2(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Name_2) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Name_2_read, channel_2->get_name()); + + attr.set_value(attr_Name_2_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_2 +} +//-------------------------------------------------------- +/** + * Read Name_3 attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_Name_3(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_Name_3(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_Name_3) ENABLED START -----*/ + + Tpg300Utils::string_copy(attr_Name_3_read, channel_3->get_name()); + + attr.set_value(attr_Name_3_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_3 +} +//-------------------------------------------------------- +/** + * Read DeviceState attribute + * Description: + * + * Data type: Tango::DevUChar + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_DeviceState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_DeviceState(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_DeviceState) ENABLED START -----*/ + + // Set the attribute value + attr.set_value(attr_DeviceState_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_DeviceState +} + +//-------------------------------------------------------- +/** + * Write DeviceState attribute values to hardware. + * + * Data type: Tango::DevUChar + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::write_DeviceState(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "Tpg300::write_DeviceState(Tango::Attribute &attr) entering... " << endl; + + // Retrieve write value + Tango::DevUChar w_val; + attr.get_write_value(w_val); + + /*----- PROTECTED REGION ID(Tpg300::write_DeviceState) ENABLED START -----*/ + + if (w_val >= DEVICESTATE_T_SIZE) { + Tango::Except::throw_exception("", "Value out of range", \ + "MksSrg::write_DeviceState()"); + } + *attr_DeviceState_read = w_val; + + /*----- PROTECTED REGION END -----*/ // Tpg300::write_DeviceState +} + +//-------------------------------------------------------- +/** + * Read DeviceStatus attribute + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void Tpg300::read_DeviceStatus(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_DeviceStatus(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_DeviceStatus) ENABLED START -----*/ + + // Set the attribute value + attr.set_value(attr_DeviceStatus_read); + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_DeviceStatus +} +//-------------------------------------------------------- +/** + * Read SetPointStatus attribute + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 6 + */ +//-------------------------------------------------------- +void Tpg300::read_SetPointStatus(Tango::Attribute &attr) +{ + DEBUG_STREAM << "Tpg300::read_SetPointStatus(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(Tpg300::read_SetPointStatus) ENABLED START -----*/ + + try + { + sp_manager->get_setpoint_value(attr_SetPointStatus_read, 6); + + attr.set_value(attr_SetPointStatus_read, 6); + } + catch(Tango::DevFailed &ex) + { + attr.set_quality(Tango::ATTR_INVALID, false); + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_SetPointStatus +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::add_dynamic_attributes() + * Description : Create the dynamic attributes if any + * for specified device. + */ +//-------------------------------------------------------- +void Tpg300::add_dynamic_attributes() +{ + /*----- PROTECTED REGION ID(Tpg300::Class::add_dynamic_attributes) ENABLED START -----*/ + + // Add your own code to create and add dynamic attributes if any + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::add_dynamic_attributes + +} + + + +//======================================================== +// Command execution methods +//======================================================== + +//-------------------------------------------------------- +/** + * Execute the SensorOn command: + * Description: Start measuring channel n + * + * @param argin Channel + * [0,3] + * @returns + */ +//-------------------------------------------------------- +void Tpg300::sensor_on(Tango::DevShort argin) +{ + DEBUG_STREAM << "Tpg300::SensorOn() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::sensor_on) ENABLED START -----*/ + + switch(argin) + { + case Tpg300Channel::CHANNEL_0: + channel_0->on(); + break; + case Tpg300Channel::CHANNEL_1: + channel_1->on(); + break; + case Tpg300Channel::CHANNEL_2: + channel_2->on(); + break; + case Tpg300Channel::CHANNEL_3: + channel_3->on(); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-3]", "SensorOn"); + break; + } + /*----- PROTECTED REGION END -----*/ // Tpg300::sensor_on + +} + +//-------------------------------------------------------- +/** + * Execute the SensorOff command: + * Description: Stop measuring channel n + * + * @param argin Channel + * [0,3] + * @returns + */ +//-------------------------------------------------------- +void Tpg300::sensor_off(Tango::DevShort argin) +{ + DEBUG_STREAM << "Tpg300::SensorOff() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::sensor_off) ENABLED START -----*/ + + switch(argin) + { + case Tpg300Channel::CHANNEL_0: + channel_0->off(); + break; + case Tpg300Channel::CHANNEL_1: + channel_1->off(); + break; + case Tpg300Channel::CHANNEL_2: + channel_2->off(); + break; + case Tpg300Channel::CHANNEL_3: + channel_3->off(); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-3]", "SensorOff"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::sensor_off + +} + +//-------------------------------------------------------- +/** + * Execute the WriteLowerThreshold command: + * Description: Set setpoint lower threshold + * + * @param argin Setpoint, Pressure + * + * Setpoint + * 0 -> Switching function 1 + * 1 -> Switching function 2 + * 2 -> Switching function 3 + * 3 -> Switching function 4 + * 4 -> Switching function A + * 5 -> Switching function B + * + * Pressure + * [1.0E-11, 9.9E+3] + * @returns + */ +//-------------------------------------------------------- +void Tpg300::write_lower_threshold(const Tango::DevVarDoubleArray *argin) +{ + DEBUG_STREAM << "Tpg300::WriteLowerThreshold() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::write_lower_threshold) ENABLED START -----*/ + + // Add your own code + if(argin->length() != 2) + Tango::Except::throw_exception("", "Invalid argument size, valid 2", "WriteLowerThreahold"); + if((*argin)[1] < 1.0E-11 || (*argin)[1] > 9.9E+3) + Tango::Except::throw_exception("", "Out of range[1.0E-11, 9.9E+3]" , "WriteLowerThreahold"); + switch(int((*argin)[0])) + { + case 0: + sp_manager->set_lower_threshold(Tpg300SPManager::SETPOINT_0, (*argin)[1]); + break; + case 1: + sp_manager->set_lower_threshold(Tpg300SPManager::SETPOINT_1, (*argin)[1]); + break; + case 2: + sp_manager->set_lower_threshold(Tpg300SPManager::SETPOINT_2, (*argin)[1]); + break; + case 3: + sp_manager->set_lower_threshold(Tpg300SPManager::SETPOINT_3, (*argin)[1]); + break; + case 4: + sp_manager->set_lower_threshold(Tpg300SPManager::SETPOINT_A, (*argin)[1]); + break; + case 5: + sp_manager->set_lower_threshold(Tpg300SPManager::SETPOINT_B, (*argin)[1]); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-5]", "WriteLowerThreahold"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::write_lower_threshold + +} + +//-------------------------------------------------------- +/** + * Execute the ReadLowerThreshold command: + * Description: Get setpoint lower threshold + * + * @param argin Setpoint + * 0 -> Switching function 1 + * 1 -> Switching function 2 + * 2 -> Switching function 3 + * 3 -> Switching function 4 + * 4 -> Switching function A + * 5 -> Switching function B + * @returns Pressure + */ +//-------------------------------------------------------- +Tango::DevDouble Tpg300::read_lower_threshold(Tango::DevShort argin) +{ + Tango::DevDouble argout; + DEBUG_STREAM << "Tpg300::ReadLowerThreshold() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::read_lower_threshold) ENABLED START -----*/ + + // Add your own code + switch(argin) + { + case 0: + argout = sp_manager->get_lower_threshold(Tpg300SPManager::SETPOINT_0); + break; + case 1: + argout = sp_manager->get_lower_threshold(Tpg300SPManager::SETPOINT_1); + break; + case 2: + argout = sp_manager->get_lower_threshold(Tpg300SPManager::SETPOINT_2); + break; + case 3: + argout = sp_manager->get_lower_threshold(Tpg300SPManager::SETPOINT_3); + break; + case 4: + argout = sp_manager->get_lower_threshold(Tpg300SPManager::SETPOINT_A); + break; + case 5: + argout = sp_manager->get_lower_threshold(Tpg300SPManager::SETPOINT_B); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-5]", "ReadLowerThreahold"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_lower_threshold + + return argout; +} + +//-------------------------------------------------------- +/** + * Execute the WriteUpperThreshold command: + * Description: Set setpoint upper threshold + * + * @param argin Setpoint, Pressure + * + * Setpoint + * 0 -> Switching function 1 + * 1 -> Switching function 2 + * 2 -> Switching function 3 + * 3 -> Switching function 4 + * 4 -> Switching function A + * 5 -> Switching function B + * + * Pressure + * [1.0E-11, 9.9E+3] + * @returns + */ +//-------------------------------------------------------- +void Tpg300::write_upper_threshold(const Tango::DevVarDoubleArray *argin) +{ + DEBUG_STREAM << "Tpg300::WriteUpperThreshold() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::write_upper_threshold) ENABLED START -----*/ + + // Add your own code + if(argin->length() != 2) + Tango::Except::throw_exception("", "Invalid argument size, valid 2", "WriteUpperThreahold"); + if((*argin)[1] < 1.0E-11 || (*argin)[1] > 9.9E+3) + Tango::Except::throw_exception("", "Out of range[1.0E-11, 9.9E+3]" , "WriteUpperThreahold"); + switch(int((*argin)[0])) + { + case 0: + sp_manager->set_upper_threshold(Tpg300SPManager::SETPOINT_0, (*argin)[1]); + break; + case 1: + sp_manager->set_upper_threshold(Tpg300SPManager::SETPOINT_1, (*argin)[1]); + break; + case 2: + sp_manager->set_upper_threshold(Tpg300SPManager::SETPOINT_2, (*argin)[1]); + break; + case 3: + sp_manager->set_upper_threshold(Tpg300SPManager::SETPOINT_3, (*argin)[1]); + break; + case 4: + sp_manager->set_upper_threshold(Tpg300SPManager::SETPOINT_A, (*argin)[1]); + break; + case 5: + sp_manager->set_upper_threshold(Tpg300SPManager::SETPOINT_B, (*argin)[1]); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-5]", "WriteUpperThreahold"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::write_upper_threshold + +} + +//-------------------------------------------------------- +/** + * Execute the ReadUpperThreshold command: + * Description: Get setpoint upper threshold + * + * @param argin Setpoint + * 0 -> Switching function 1 + * 1 -> Switching function 2 + * 2 -> Switching function 3 + * 3 -> Switching function 4 + * 4 -> Switching function A + * 5 -> Switching function B + * @returns Pressure + */ +//-------------------------------------------------------- +Tango::DevDouble Tpg300::read_upper_threshold(Tango::DevShort argin) +{ + Tango::DevDouble argout; + DEBUG_STREAM << "Tpg300::ReadUpperThreshold() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::read_upper_threshold) ENABLED START -----*/ + + // Add your own code + switch(argin) + { + case 0: + argout = sp_manager->get_upper_threshold(Tpg300SPManager::SETPOINT_0); + break; + case 1: + argout = sp_manager->get_upper_threshold(Tpg300SPManager::SETPOINT_1); + break; + case 2: + argout = sp_manager->get_upper_threshold(Tpg300SPManager::SETPOINT_2); + break; + case 3: + argout = sp_manager->get_upper_threshold(Tpg300SPManager::SETPOINT_3); + break; + case 4: + argout = sp_manager->get_upper_threshold(Tpg300SPManager::SETPOINT_A); + break; + case 5: + argout = sp_manager->get_upper_threshold(Tpg300SPManager::SETPOINT_B); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-5]", "ReadLowerThreahold"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_upper_threshold + + return argout; +} + +//-------------------------------------------------------- +/** + * Execute the ReadSensorSource command: + * Description: Get setpoint source + * + * @param argin Setpoint + * 0 -> Switching function 1 + * 1 -> Switching function 2 + * 2 -> Switching function 3 + * 3 -> Switching function 4 + * 4 -> Switching function A + * 5 -> Switching function B + * @returns Source + * 0 -> No assignment + * 1 -> Measuring circuit A1 + * 2 -> Measuring circuit A2 + * 3 -> Measuring circuit B1 + * 4 -> Measuring circuit B2 + * 5 -> Measuring circuit A1 (for self monitoring) + * 6 -> Measuring circuit A2 (for self monitoring) + * 7 -> Measuring circuit B1 (for self monitoring) + * 8 -> Measuring circuit B2 (for self monitoring) + */ +//-------------------------------------------------------- +Tango::DevShort Tpg300::read_sensor_source(Tango::DevShort argin) +{ + Tango::DevShort argout; + DEBUG_STREAM << "Tpg300::ReadSensorSource() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::read_sensor_source) ENABLED START -----*/ + + switch(argin) + { + case 0: + argout = sp_manager->get_source(Tpg300SPManager::SETPOINT_0); + break; + case 1: + argout = sp_manager->get_source(Tpg300SPManager::SETPOINT_1); + break; + case 2: + argout = sp_manager->get_source(Tpg300SPManager::SETPOINT_2); + break; + case 3: + argout = sp_manager->get_source(Tpg300SPManager::SETPOINT_3); + break; + case 4: + argout = sp_manager->get_source(Tpg300SPManager::SETPOINT_A); + break; + case 5: + argout = sp_manager->get_source(Tpg300SPManager::SETPOINT_B); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-5]", "ReadSensorSource"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_sensor_source + + return argout; +} + +//-------------------------------------------------------- +/** + * Execute the WriteSensorSource command: + * Description: Set setpoint switching function + * + * @param argin Setpoint, Source + * + * Setpoint + * 0 -> Switching function 1 + * 1 -> Switching function 2 + * 2 -> Switching function 3 + * 3 -> Switching function 4 + * 4 -> Switching function A + * 5 -> Switching function B + * + * Source: + * 0 -> No assignment + * 1 -> Measuring circuit A1 + * 2 -> Measuring circuit A2 + * 3 -> Measuring circuit B1 + * 4 -> Measuring circuit B2 + * 5 -> Measuring circuit A1 (for self monitoring) + * 6 -> Measuring circuit A2 (for self monitoring) + * 7 -> Measuring circuit B1 (for self monitoring) + * 8 -> Measuring circuit B2 (for self monitoring) + * @returns + */ +//-------------------------------------------------------- +void Tpg300::write_sensor_source(const Tango::DevVarShortArray *argin) +{ + DEBUG_STREAM << "Tpg300::WriteSensorSource() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::write_sensor_source) ENABLED START -----*/ + + if(argin->length() != 2) + Tango::Except::throw_exception("", "Invalid argument size, valid 2", "WriteSensorSource"); + + if((*argin)[1] < 0 || (*argin)[1] > 8) + Tango::Except::throw_exception("", "Out of range[0, 8]" , "WriteSensorSource"); + + switch(int((*argin)[0])) + { + case 0: + sp_manager->set_source(Tpg300SPManager::SETPOINT_0, (*argin)[1]); + break; + case 1: + sp_manager->set_source(Tpg300SPManager::SETPOINT_1, (*argin)[1]); + break; + case 2: + sp_manager->set_source(Tpg300SPManager::SETPOINT_2, (*argin)[1]); + break; + case 3: + sp_manager->set_source(Tpg300SPManager::SETPOINT_3, (*argin)[1]); + break; + case 4: + sp_manager->set_source(Tpg300SPManager::SETPOINT_A, (*argin)[1]); + break; + case 5: + sp_manager->set_source(Tpg300SPManager::SETPOINT_B, (*argin)[1]); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-5]", "WriteSensorSource"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::write_sensor_source + +} + +//-------------------------------------------------------- +/** + * Execute the RegisterName command: + * Description: Set channel name + * + * @param argin Channel, Name + * + * Channel + * [0,3] + * + * Name + * max 64 characters + * @returns + */ +//-------------------------------------------------------- +void Tpg300::register_name(const Tango::DevVarLongStringArray *argin) +{ + DEBUG_STREAM << "Tpg300::RegisterName() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::register_name) ENABLED START -----*/ + + if(argin->lvalue.length() != 1 || argin->svalue.length() != 1) + Tango::Except::throw_exception("", "Invalid argument size, valid 2", "RegisterName"); + + long channel = argin->lvalue[0]; + string channel_name(argin->svalue[0]); + + if(channel_name.empty() || channel_name.size() > 64) + Tango::Except::throw_exception("", "Invalid name size, min = 1, max = 64", "RegisterName"); + + switch(channel) + { + case Tpg300Channel::CHANNEL_0: + channel_0->set_name(channel_name); + break; + case Tpg300Channel::CHANNEL_1: + channel_1->set_name(channel_name); + break; + case Tpg300Channel::CHANNEL_2: + channel_2->set_name(channel_name); + break; + case Tpg300Channel::CHANNEL_3: + channel_3->set_name(channel_name); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-3]", "RegisterName"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::register_name + +} + +//-------------------------------------------------------- +/** + * Execute the UnregisterName command: + * Description: Unregister channel name + * + * @param argin Channel + * [0,3] + * @returns + */ +//-------------------------------------------------------- +void Tpg300::unregister_name(Tango::DevShort argin) +{ + DEBUG_STREAM << "Tpg300::UnregisterName() - " << device_name << endl; + /*----- PROTECTED REGION ID(Tpg300::unregister_name) ENABLED START -----*/ + + switch(argin) + { + case Tpg300Channel::CHANNEL_0: + channel_0->set_name("Unknown channel name"); + break; + case Tpg300Channel::CHANNEL_1: + channel_1->set_name("Unknown channel name"); + break; + case Tpg300Channel::CHANNEL_2: + channel_2->set_name("Unknown channel name"); + break; + case Tpg300Channel::CHANNEL_3: + channel_3->set_name("Unknown channel name"); + break; + default: + Tango::Except::throw_exception("", "Invalid argument, valid [0-3]", "RegisterName"); + break; + } + + /*----- PROTECTED REGION END -----*/ // Tpg300::unregister_name + +} + + + /*----- PROTECTED REGION ID(Tpg300::namespace_ending) ENABLED START -----*/ + +//======================================================== +// Utilities methods +//======================================================== + +//-------------------------------------------------------- +/** + * Execute the update_state command: + * Description: + */ +//-------------------------------------------------------- +void Tpg300::update_state() +{ + DEBUG_STREAM << "Tpg300::update_state() - " << device_name << endl; + + Tango::DevState tpg_state = Tango::UNKNOWN; + + tpg_state = error_status->get_state(); + + if(channel_0->get_state() == Tango::FAULT || + channel_1->get_state() == Tango::FAULT || + channel_2->get_state() == Tango::FAULT || + channel_3->get_state() == Tango::FAULT) + tpg_state = Tango::FAULT; + + set_state(tpg_state); +} + +//-------------------------------------------------------- +/** + * Execute the update_status command: + * Description: + */ +//-------------------------------------------------------- +void Tpg300::update_status() +{ + DEBUG_STREAM << "Tpg300::update_status() - " << device_name << endl; + + stringstream status_str; + + if(error_status->get_state() == Tango::ALARM || + error_status->get_state() == Tango::FAULT) + status_str << error_status->get_status() << endl; + + if(channel_0->get_state() == Tango::FAULT) + status_str << channel_0->get_status() << endl; + + if(channel_1->get_state() == Tango::FAULT) + status_str << channel_1->get_status() << endl; + + if(channel_2->get_state() == Tango::FAULT) + status_str << channel_2->get_status() << endl; + + if(channel_3->get_state() == Tango::FAULT) + status_str << channel_3->get_status() << endl; + + if(status_str.str().empty()) + status_str << "Connected to " << serialDevice << endl; + + set_status(status_str.str()); +} + + /*----- PROTECTED REGION END -----*/ // Tpg300::namespace_ending +} // namespace diff --git a/src/Tpg300.h b/src/Tpg300.h new file mode 100644 index 0000000000000000000000000000000000000000..9aaa427c1511b9c0c6555574d4157d5f597d884d --- /dev/null +++ b/src/Tpg300.h @@ -0,0 +1,506 @@ +/*----- PROTECTED REGION ID(Tpg300.h) ENABLED START -----*/ +//============================================================================= +// +// file : Tpg300.h +// +// description : Include for the Tpg300 class. +// +// project : Blzer Tpg 300. +// +// $Author: claudio $ +// +// $Revision: 1.7 $ +// $Date: 2016-10-18 15:53:02 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/Tpg300.h,v $ +// $Log: Tpg300.h,v $ +// Revision 1.7 2016-10-18 15:53:02 claudio +// tango9 +// +// Revision 1.6 2013-06-05 14:59:10 lorenzo +// Tango 8.0.5 +// +// Revision 1.5 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef TPG300_H +#define TPG300_H + + +#include <tango.h> + +/*----- PROTECTED REGION END -----*/ + + +/** + * Tpg300 class Description: + * Total pressure gauge and controller + */ + +namespace Tpg300_ns +{ + /*----- PROTECTED REGION ID(Tpg300::Additional Class Declarations) ENABLED START -----*/ + +class Tpg300Proxy; +class Tpg300Channel; +class Tpg300SPManager; +class Tpg300Error; +class Tpg300Thread; + + /*----- PROTECTED REGION END -----*/ // Tpg300::Additional Class Declarations + + +class Tpg300 : public TANGO_BASE_CLASS + +{ + + + /*----- PROTECTED REGION ID(Tpg300::Data Members) ENABLED START -----*/ + + omni_mutex* stop_mutex; + omni_condition* stop_condition; + + Tpg300Proxy* proxy; + + Tpg300Error* error_status; + + Tpg300SPManager* sp_manager; + + Tpg300Channel* channel_0; + Tpg300Channel* channel_1; + Tpg300Channel* channel_2; + Tpg300Channel* channel_3; + + Tpg300Thread* thread; + + bool init_completed; + + /*----- PROTECTED REGION END -----*/ // Tpg300::Data Members + + +// Device property data members +public: // SerialDevice: + string serialDevice; + // Timeout: Milliseconds + Tango::DevULong timeout; + // ThreadSleep: Millisecond + Tango::DevULong threadSleep; + // ProxySleep: Millisecond + Tango::DevULong proxySleep; + + +// Attribute data members +public: + Tango::DevDouble *attr_Pressure_0_read; + Tango::DevDouble *attr_Pressure_1_read; + Tango::DevDouble *attr_Pressure_2_read; + Tango::DevDouble *attr_Pressure_3_read; + Tango::DevState *attr_State_0_read; + Tango::DevState *attr_State_1_read; + Tango::DevState *attr_State_2_read; + Tango::DevState *attr_State_3_read; + Tango::DevString *attr_Status_0_read; + Tango::DevString *attr_Status_1_read; + Tango::DevString *attr_Status_2_read; + Tango::DevString *attr_Status_3_read; + Tango::DevString *attr_Name_0_read; + Tango::DevString *attr_Name_1_read; + Tango::DevString *attr_Name_2_read; + Tango::DevString *attr_Name_3_read; + Tango::DevUChar *attr_DeviceState_read; + Tango::DevString *attr_DeviceStatus_read; + Tango::DevBoolean *attr_SetPointStatus_read; + + + +// Constructors and destructors +public: + /** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + Tpg300(Tango::DeviceClass *cl,string &s); + /** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + Tpg300(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + Tpg300(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The object destructor. + */ + ~Tpg300() {delete_device();}; + + + +// Miscellaneous methods +public: + /** + * will be called at device destruction or at init command. + */ + void delete_device(); + /** + * Initialize the device + */ + virtual void init_device(); + /** + * Read the device properties from database + */ + void get_device_property(); + /** + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + +// Attribute methods +public: + /** + * Method : Tpg300::read_attr_hardware() + * Description : Hardware acquisition for attributes. + */ + virtual void read_attr_hardware(vector<long> &attr_list); + + + /** + * Pressure_0 attribute related methods. + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Pressure_0(Tango::Attribute &attr); + virtual bool is_Pressure_0_allowed(Tango::AttReqType type); + + + + /** + * Pressure_1 attribute related methods. + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Pressure_1(Tango::Attribute &attr); + virtual bool is_Pressure_1_allowed(Tango::AttReqType type); + + + + /** + * Pressure_2 attribute related methods. + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Pressure_2(Tango::Attribute &attr); + virtual bool is_Pressure_2_allowed(Tango::AttReqType type); + + + + /** + * Pressure_3 attribute related methods. + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Pressure_3(Tango::Attribute &attr); + virtual bool is_Pressure_3_allowed(Tango::AttReqType type); + + + + /** + * State_0 attribute related methods. + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ + virtual void read_State_0(Tango::Attribute &attr); + virtual bool is_State_0_allowed(Tango::AttReqType type); + + + + /** + * State_1 attribute related methods. + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ + virtual void read_State_1(Tango::Attribute &attr); + virtual bool is_State_1_allowed(Tango::AttReqType type); + + + + /** + * State_2 attribute related methods. + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ + virtual void read_State_2(Tango::Attribute &attr); + virtual bool is_State_2_allowed(Tango::AttReqType type); + + + + /** + * State_3 attribute related methods. + * Description: + * + * Data type: Tango::DevState + * Attr type: Scalar + */ + virtual void read_State_3(Tango::Attribute &attr); + virtual bool is_State_3_allowed(Tango::AttReqType type); + + + + /** + * Status_0 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Status_0(Tango::Attribute &attr); + virtual bool is_Status_0_allowed(Tango::AttReqType type); + + + + /** + * Status_1 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Status_1(Tango::Attribute &attr); + virtual bool is_Status_1_allowed(Tango::AttReqType type); + + + + /** + * Status_2 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Status_2(Tango::Attribute &attr); + virtual bool is_Status_2_allowed(Tango::AttReqType type); + + + + /** + * Status_3 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Status_3(Tango::Attribute &attr); + virtual bool is_Status_3_allowed(Tango::AttReqType type); + + + + /** + * Name_0 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Name_0(Tango::Attribute &attr); + virtual bool is_Name_0_allowed(Tango::AttReqType type); + + + + /** + * Name_1 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Name_1(Tango::Attribute &attr); + virtual bool is_Name_1_allowed(Tango::AttReqType type); + + + + /** + * Name_2 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Name_2(Tango::Attribute &attr); + virtual bool is_Name_2_allowed(Tango::AttReqType type); + + + + /** + * Name_3 attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Name_3(Tango::Attribute &attr); + virtual bool is_Name_3_allowed(Tango::AttReqType type); + + + + /** + * DeviceState attribute related methods. + * Description: + * + * Data type: Tango::DevUChar + * Attr type: Scalar + */ + virtual void read_DeviceState(Tango::Attribute &attr); + virtual void write_DeviceState(Tango::WAttribute &attr); + virtual bool is_DeviceState_allowed(Tango::AttReqType type); + + + + /** + * DeviceStatus attribute related methods. + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_DeviceStatus(Tango::Attribute &attr); + virtual bool is_DeviceStatus_allowed(Tango::AttReqType type); + + + + /** + * SetPointStatus attribute related methods. + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 6 + */ + virtual void read_SetPointStatus(Tango::Attribute &attr); + virtual bool is_SetPointStatus_allowed(Tango::AttReqType type); + + + + /** + * Method : Tpg300::add_dynamic_attributes() + * Description : Add dynamic attributes if any. + */ + void add_dynamic_attributes(); + +// Command related methods +public: + + + /** + * Command SensorOn related methods. + */ + void sensor_on(Tango::DevShort argin); + virtual bool is_SensorOn_allowed(const CORBA::Any &any); + + /** + * Command SensorOff related methods. + */ + void sensor_off(Tango::DevShort argin); + virtual bool is_SensorOff_allowed(const CORBA::Any &any); + + /** + * Command WriteLowerThreshold related methods. + */ + void write_lower_threshold(const Tango::DevVarDoubleArray *argin); + virtual bool is_WriteLowerThreshold_allowed(const CORBA::Any &any); + + /** + * Command ReadLowerThreshold related methods. + */ + Tango::DevDouble read_lower_threshold(Tango::DevShort argin); + virtual bool is_ReadLowerThreshold_allowed(const CORBA::Any &any); + + /** + * Command WriteUpperThreshold related methods. + */ + void write_upper_threshold(const Tango::DevVarDoubleArray *argin); + virtual bool is_WriteUpperThreshold_allowed(const CORBA::Any &any); + + /** + * Command ReadUpperThreshold related methods. + */ + Tango::DevDouble read_upper_threshold(Tango::DevShort argin); + virtual bool is_ReadUpperThreshold_allowed(const CORBA::Any &any); + + /** + * Command ReadSensorSource related methods. + */ + Tango::DevShort read_sensor_source(Tango::DevShort argin); + virtual bool is_ReadSensorSource_allowed(const CORBA::Any &any); + + /** + * Command WriteSensorSource related methods. + */ + void write_sensor_source(const Tango::DevVarShortArray *argin); + virtual bool is_WriteSensorSource_allowed(const CORBA::Any &any); + + /** + * Command RegisterName related methods. + */ + void register_name(const Tango::DevVarLongStringArray *argin); + virtual bool is_RegisterName_allowed(const CORBA::Any &any); + + /** + * Command UnregisterName related methods. + */ + void unregister_name(Tango::DevShort argin); + virtual bool is_UnregisterName_allowed(const CORBA::Any &any); + + + + /*----- PROTECTED REGION ID(Tpg300::Additional Method prototypes) ENABLED START -----*/ + + void update_state(); + + void update_status(); + + /*----- PROTECTED REGION END -----*/ // Tpg300::Additional Method prototypes + +}; + + /*----- PROTECTED REGION ID(Tpg300::Additional Classes Definitions) ENABLED START -----*/ + + // Additional Classes definitions + + /*----- PROTECTED REGION END -----*/ // Tpg300::Additional Classes Definitions + +} // namespace + +#endif // TPG300_H diff --git a/src/Tpg300.xmi b/src/Tpg300.xmi new file mode 100644 index 0000000000000000000000000000000000000000..dd88085d07c84ccf977ace7475fa09a24af9fb64 --- /dev/null +++ b/src/Tpg300.xmi @@ -0,0 +1,303 @@ +<?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="Tpg300"> + <description description="Total pressure gauge and controller" title="Blzer Tpg 300" sourcePath="/home/lorenzo/src/a/fermi/servers/tpg300/src" language="Cpp" filestogenerate="XMI file,Code files" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_Impl" sourcePath=""/> + <identification contact="at elettra.trieste.it - marco.demarco" author="marco.demarco" emailDomain="elettra.trieste.it" classFamily="Vacuum" siteSpecific="" platform="All Platforms" bus="Serial Line" manufacturer="Blzer" reference="Tpg 300"/> + <comments commandsTable="//================================================================
//
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//----------------------------------------------------------------
// State | Inherited (no method)
// Status | Inherited (no method)
// SensorOn | sensor_on
// SensorOff | sensor_off
// WriteLowerThreshold | write_lower_threshold
// ReadLowerThreshold | read_lower_threshold
// WriteUpperThreshold | write_upper_threshold
// ReadUpperThreshold | read_upper_threshold
// ReadSensorSource | read_sensor_source
// WriteSensorSource | write_sensor_source
// RegisterName | register_name
// UnregisterName | unregister_name
//================================================================"/> + </description> + <deviceProperties name="SerialDevice" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>undefined</DefaultPropValue> + </deviceProperties> + <deviceProperties name="Timeout" description="Milliseconds"> + <type xsi:type="pogoDsl:UIntType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>2500</DefaultPropValue> + </deviceProperties> + <deviceProperties name="ThreadSleep" description="Millisecond"> + <type xsi:type="pogoDsl:UIntType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>1500</DefaultPropValue> + </deviceProperties> + <deviceProperties name="ProxySleep" description="Millisecond"> + <type xsi:type="pogoDsl:UIntType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>1500</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"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device state"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its device_status data member) and returns it to the caller." execMethod="dev_status" displayLevel="OPERATOR"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device status"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="SensorOn" description="Start measuring channel n" execMethod="sensor_on" displayLevel="EXPERT"> + <argin description="Channel
[0,3]"> + <type xsi:type="pogoDsl:ShortType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="SensorOff" description="Stop measuring channel n" execMethod="sensor_off" displayLevel="EXPERT"> + <argin description="Channel
[0,3]"> + <type xsi:type="pogoDsl:ShortType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="WriteLowerThreshold" description="Set setpoint lower threshold" execMethod="write_lower_threshold" displayLevel="EXPERT"> + <argin description="Setpoint, Pressure

Setpoint
0 -> Switching function 1
1 -> Switching function 2
2 -> Switching function 3
3 -> Switching function 4
4 -> Switching function A
5 -> Switching function B

Pressure
[1.0E-11, 9.9E+3]"> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="ReadLowerThreshold" description="Get setpoint lower threshold" execMethod="read_lower_threshold" displayLevel="EXPERT"> + <argin description="Setpoint
0 -> Switching function 1
1 -> Switching function 2
2 -> Switching function 3
3 -> Switching function 4
4 -> Switching function A
5 -> Switching function B"> + <type xsi:type="pogoDsl:ShortType"/> + </argin> + <argout description="Pressure"> + <type xsi:type="pogoDsl:DoubleType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="WriteUpperThreshold" description="Set setpoint upper threshold" execMethod="write_upper_threshold" displayLevel="EXPERT"> + <argin description="Setpoint, Pressure

Setpoint
0 -> Switching function 1
1 -> Switching function 2
2 -> Switching function 3
3 -> Switching function 4
4 -> Switching function A
5 -> Switching function B

Pressure
[1.0E-11, 9.9E+3]"> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="ReadUpperThreshold" description="Get setpoint upper threshold" execMethod="read_upper_threshold" displayLevel="EXPERT"> + <argin description="Setpoint
0 -> Switching function 1
1 -> Switching function 2
2 -> Switching function 3
3 -> Switching function 4
4 -> Switching function A
5 -> Switching function B"> + <type xsi:type="pogoDsl:ShortType"/> + </argin> + <argout description="Pressure"> + <type xsi:type="pogoDsl:DoubleType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="ReadSensorSource" description="Get setpoint source" execMethod="read_sensor_source" displayLevel="EXPERT"> + <argin description="Setpoint
0 -> Switching function 1
1 -> Switching function 2
2 -> Switching function 3
3 -> Switching function 4
4 -> Switching function A
5 -> Switching function B"> + <type xsi:type="pogoDsl:ShortType"/> + </argin> + <argout description="Source
0 -> No assignment
1 -> Measuring circuit A1
2 -> Measuring circuit A2
3 -> Measuring circuit B1
4 -> Measuring circuit B2
5 -> Measuring circuit A1 (for self monitoring)
6 -> Measuring circuit A2 (for self monitoring)
7 -> Measuring circuit B1 (for self monitoring)
8 -> Measuring circuit B2 (for self monitoring)"> + <type xsi:type="pogoDsl:ShortType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="WriteSensorSource" description="Set setpoint switching function" execMethod="write_sensor_source" displayLevel="EXPERT"> + <argin description="Setpoint, Source

Setpoint
0 -> Switching function 1
1 -> Switching function 2
2 -> Switching function 3
3 -> Switching function 4
4 -> Switching function A
5 -> Switching function B

Source:
0 -> No assignment
1 -> Measuring circuit A1
2 -> Measuring circuit A2
3 -> Measuring circuit B1
4 -> Measuring circuit B2
5 -> Measuring circuit A1 (for self monitoring)
6 -> Measuring circuit A2 (for self monitoring)
7 -> Measuring circuit B1 (for self monitoring)
8 -> Measuring circuit B2 (for self monitoring)"> + <type xsi:type="pogoDsl:ShortArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="RegisterName" description="Set channel name" execMethod="register_name" displayLevel="EXPERT"> + <argin description="Channel, Name

Channel
[0,3]

Name
max 64 characters"> + <type xsi:type="pogoDsl:LongStringArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="UnregisterName" description="Unregister channel name" execMethod="unregister_name" displayLevel="EXPERT"> + <argin description="Channel
[0,3]"> + <type xsi:type="pogoDsl:ShortType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <attributes name="Pressure_0" attType="Scalar" rwType="READ" displayLevel="OPERATOR" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="mbar" standardUnit="mbar" displayUnit="mbar" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Pressure_1" attType="Scalar" rwType="READ" displayLevel="OPERATOR" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="mbar" standardUnit="mbar" displayUnit="mbar" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Pressure_2" attType="Scalar" rwType="READ" displayLevel="OPERATOR" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="mbar" standardUnit="mbar" displayUnit="mbar" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Pressure_3" attType="Scalar" rwType="READ" displayLevel="OPERATOR" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="mbar" standardUnit="mbar" displayUnit="mbar" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="State_0" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StateType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="State_1" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StateType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="State_2" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StateType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="State_3" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StateType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Status_0" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Status_1" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Status_2" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Status_3" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Name_0" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Name_1" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Name_2" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="Name_3" attType="Scalar" rwType="READ" displayLevel="EXPERT" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="DeviceState" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" maxX="" maxY="" memorized="true" allocReadMember="true"> + <dataType xsi:type="pogoDsl:UCharType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="DeviceStatus" attType="Scalar" rwType="READ" displayLevel="OPERATOR" maxX="" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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="SetPointStatus" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" maxX="6" maxY="" allocReadMember="true"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="true"/> + <archiveEvent fire="false" libCheckCriteria="true"/> + <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> + <states name="ON" description=""> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="OFF" description=""> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="ALARM" description=""> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="FAULT" description=""> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <preferences docHome="./doc_html" makefileHome="/usr/local/tango-7.2.6/share/pogo/preferences"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/src/Tpg300Channel.cpp b/src/Tpg300Channel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e41551ededf91afbec312955990d9f10238336e3 --- /dev/null +++ b/src/Tpg300Channel.cpp @@ -0,0 +1,262 @@ +/* + * Tpg300Channel.cpp + * + * Created on: Jun 12, 2012 + * Author: mdm + */ + +#include "Tpg300Channel.h" +#include "Tpg300Proxy.h" +#include "Tpg300Utils.h" +#include "ThreadGuard.h" + +namespace Tpg300_ns +{ + +//-------------------------------------------------------- +// Tpg300Channel::Tpg300Channel() +//-------------------------------------------------------- +Tpg300Channel::Tpg300Channel(Tpg300Proxy* p, Channel c) : + proxy(p), channel(c) +{ + pressure = 0; + state = Tango::UNKNOWN; + status = "Unknown status"; + name = "Unknown channel name"; +} + +//-------------------------------------------------------- +// Tpg300Channel::update_channel() +//-------------------------------------------------------- +void Tpg300Channel::update() +{ + string result; + + try + { + switch(channel) + { + case CHANNEL_0: + result = proxy->write_read("PA1"); + break; + case CHANNEL_1: + result = proxy->write_read("PA2"); + break; + case CHANNEL_2: + result = proxy->write_read("PB1"); + break; + case CHANNEL_3: + result = proxy->write_read("PB2"); + break; + } + + ThreadGuard lock(mutex); + + pressure = parse_pressure(result); + state = parse_state(result); + status = parse_status(result); + } + catch(Tango::DevFailed &ex) + { + state = Tango::FAULT; + status = Tpg300Utils::get_trace(ex); + } +} + +//-------------------------------------------------------- +// Tpg300Channel::get_pressure() +//-------------------------------------------------------- +Tango::DevDouble Tpg300Channel::get_pressure() +{ + ThreadGuard lock(mutex); + + return pressure; +} + +//-------------------------------------------------------- +// Tpg300Channel::get_state() +//-------------------------------------------------------- +Tango::DevState Tpg300Channel::get_state() +{ + ThreadGuard lock(mutex); + + return state; +} + +//-------------------------------------------------------- +// Tpg300Channel::get_status() +//-------------------------------------------------------- +string Tpg300Channel::get_status() +{ + ThreadGuard lock(mutex); + + return status; +} + +//-------------------------------------------------------- +// Tpg300Channel::set_name() +//-------------------------------------------------------- +void Tpg300Channel::set_name(string n) +{ + ThreadGuard lock(mutex); + + name = n; +} + +//-------------------------------------------------------- +// Tpg300Channel::get_name() +//-------------------------------------------------------- +string Tpg300Channel::get_name() +{ + ThreadGuard lock(mutex); + + return name; +} + +//-------------------------------------------------------- +// Tpg300Channel::on() +//-------------------------------------------------------- +void Tpg300Channel::on() throw(Tango::DevFailed) +{ + read_write_state(channel, ON); +} + +//-------------------------------------------------------- +// Tpg300Channel::off() +//-------------------------------------------------------- +void Tpg300Channel::off() throw(Tango::DevFailed) +{ + read_write_state(channel, OFF); +} + +//======================================================== +// Utilities methods +//======================================================== + +//-------------------------------------------------------- +// Tpg300Channel::read_write_state() +//-------------------------------------------------------- +void Tpg300Channel::read_write_state(Channel channel, ChannelState new_state) +{ + string result = proxy->write_read("SEN,0,0,0,0"); + + if(result.size() == 7) + { + int channels_states[4] = {0}; + + channels_states[0] = atoi( &result.at(0) ); + channels_states[1] = atoi( &result.at(2) ); + channels_states[2] = atoi( &result.at(4) ); + channels_states[3] = atoi( &result.at(6) ); + + channels_states[channel] = new_state; + + stringstream command_str; + command_str << "SEN," + << channels_states[0] << "," + << channels_states[1] << "," + << channels_states[2] << "," + << channels_states[3]; + + proxy->write_read(command_str.str()); + } + else + Tango::Except::throw_exception("", "Parsing error", "read_write_state"); + +} + +//-------------------------------------------------------- +// Tpg300Channel::parse_pressure() +//-------------------------------------------------------- +Tango::DevDouble Tpg300Channel::parse_pressure(string result) +{ + Tango::DevDouble pressure = 0; + + size_t pos; + if((pos = result.find(POINT)) != string::npos) + { + pressure = strtod(result.substr(pos+1, result.size()).c_str(), 0); + } + else + Tango::Except::throw_exception("", "Parsing error", "parse_pressure"); + + return pressure; +} + +//-------------------------------------------------------- +// Tpg300Channel::parse_state() +//-------------------------------------------------------- +Tango::DevState Tpg300Channel::parse_state(string result) +{ + Tango::DevState state = Tango::FAULT; + + size_t pos; + if( (pos = result.find(POINT)) != string::npos) + { + switch(atoi(result.substr(0, pos).c_str())) + { + case 0: + state = Tango::ON; + break; + case 1: + state = Tango::ALARM; + break; + case 2: + state = Tango::ALARM; + break; + case 3: + state = Tango::ALARM; + break; + case 4: + state = Tango::OFF; + break; + case 5: + state = Tango::DISABLE; + break; + } + } + else + Tango::Except::throw_exception("", "Parsing error", "parse_state"); + + return state; +} + +//-------------------------------------------------------- +// Tpg300Channel::parse_status() +//-------------------------------------------------------- +string Tpg300Channel::parse_status(string result) +{ + string status = "Parsing error"; + + size_t pos; + if( (pos = result.find(POINT)) != string::npos) + { + switch(atoi(result.substr(0, pos).c_str())) + { + case 0: + status = "Measurement data OK"; + break; + case 1: + status = "Under range"; + break; + case 2: + status = "Over range"; + break; + case 3: + status = "Measuring circuit error"; + break; + case 4: + status = "Measuring circuit switched off"; + break; + case 5: + status = "No hardware"; + break; + } + } + else + Tango::Except::throw_exception("", "Parsing error", "parse_status"); + + return status; +} + +} diff --git a/src/Tpg300Channel.h b/src/Tpg300Channel.h new file mode 100644 index 0000000000000000000000000000000000000000..2f8836d976b2c9bacfe838013f840fa2a6775ee8 --- /dev/null +++ b/src/Tpg300Channel.h @@ -0,0 +1,58 @@ +/* + * Tpg300Channel.h + * + * Created on: Jun 12, 2012 + * Author: mdm + */ + +#ifndef TPG300CHANNEL_H_ +#define TPG300CHANNEL_H_ + +#include <tango.h> +#include <Tpg300Task.h> + +namespace Tpg300_ns +{ + +class Tpg300Proxy; + +class Tpg300Channel : public Tpg300Task +{ + +public: + enum Channel{CHANNEL_0 = 0, CHANNEL_1 = 1, CHANNEL_2 = 2, CHANNEL_3 = 3}; + enum ChannelState{OFF = 1, ON = 3}; + +public: + Tpg300Channel(Tpg300Proxy*, Channel); + virtual ~Tpg300Channel() {}; + +public: + virtual void update(); + virtual Tango::DevDouble get_pressure(); + virtual Tango::DevState get_state(); + virtual std::string get_status(); + virtual void set_name(std::string); + virtual std::string get_name(); + virtual void on() throw(Tango::DevFailed); + virtual void off() throw(Tango::DevFailed); + +protected: + virtual void read_write_state(Channel, ChannelState); + virtual Tango::DevDouble parse_pressure(std::string); + virtual Tango::DevState parse_state(std::string); + virtual std::string parse_status(std::string); + +private: + Tango::DevDouble pressure; + Tango::DevState state; + std::string status; + std::string name; + Tpg300Proxy* proxy; + omni_mutex mutex; + const Channel channel; +}; + +} + +#endif /* TPG300CHANNEL_H_ */ diff --git a/src/Tpg300Class.cpp b/src/Tpg300Class.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd2530d884c9dfbd90ecfd38e52daca728c5eacf --- /dev/null +++ b/src/Tpg300Class.cpp @@ -0,0 +1,1422 @@ +/*----- PROTECTED REGION ID(Tpg300Class.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: Tpg300Class.cpp,v 1.6 2013-06-05 14:59:10 lorenzo Exp $"; +static const char *TagName = "$Name: $"; +static const char *CvsPath = "$Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/Tpg300Class.cpp,v $"; +static const char *SvnPath = "$HeadURL: $"; +static const char *HttpServer = "http://www.esrf.eu/computing/cs/tango/tango_doc/ds_doc/"; +//============================================================================= +// +// file : Tpg300Class.cpp +// +// description : C++ source for the Tpg300Class. A singleton +// class derived from DeviceClass. It implements the +// command list and all properties and methods required +// by the «name» once per process. +// +// project : Blzer Tpg 300. +// +// $Author: lorenzo $ +// +// $Revision: 1.6 $ +// $Date: 2013-06-05 14:59:10 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/Tpg300Class.cpp,v $ +// $Log: Tpg300Class.cpp,v $ +// Revision 1.6 2013-06-05 14:59:10 lorenzo +// Tango 8.0.5 +// +// Revision 1.5 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <Tpg300Class.h> + +/*----- PROTECTED REGION END -----*/ + +//------------------------------------------------------------------- +/** + * Create Tpg300Class singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_Tpg300_class(const char *name) { + return Tpg300_ns::Tpg300Class::init(name); + } +} + + +namespace Tpg300_ns +{ + + +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +Tpg300Class *Tpg300Class::_instance = NULL; + +//-------------------------------------------------------- +/** + * method : Tpg300Class::Tpg300Class(string &s) + * description : constructor for the Tpg300Class + * + * @param s The class name + */ +//-------------------------------------------------------- +Tpg300Class::Tpg300Class(string &s):DeviceClass(s) +{ + cout2 << "Entering Tpg300Class constructor" << endl; + set_default_property(); + get_class_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(Tpg300::Class::constructor) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::constructor + + cout2 << "Leaving Tpg300Class constructor" << endl; +} + + +//-------------------------------------------------------- +/** + * method : Tpg300Class::~Tpg300Class() + * description : destructor for the Tpg300Class + */ +//-------------------------------------------------------- +Tpg300Class::~Tpg300Class() +{ + /*----- PROTECTED REGION ID(Tpg300::Class::destructor) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : Tpg300Class::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +Tpg300Class *Tpg300Class::init(const char *name) +{ + if (_instance == NULL) + { + try + { + string s(name); + _instance = new Tpg300Class(s); + } + catch (bad_alloc) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : Tpg300Class::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +Tpg300Class *Tpg300Class::instance() +{ + if (_instance == NULL) + { + cerr << "Class is not initialised !!" << endl; + exit(-1); + } + return _instance; +} + + + + +//=================================================================== +// Command execution method calls +//=================================================================== +//-------------------------------------------------------- +/** + * method : SensorOnClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *SensorOnClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "SensorOnClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->sensor_on(argin)); + return new CORBA::Any(); +} +//-------------------------------------------------------- +/** + * method : SensorOffClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *SensorOffClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "SensorOffClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->sensor_off(argin)); + return new CORBA::Any(); +} +//-------------------------------------------------------- +/** + * method : WriteLowerThresholdClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *WriteLowerThresholdClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "WriteLowerThresholdClass::execute(): arrived" << endl; + + const Tango::DevVarDoubleArray *argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->write_lower_threshold(argin)); + return new CORBA::Any(); +} +//-------------------------------------------------------- +/** + * method : ReadLowerThresholdClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *ReadLowerThresholdClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "ReadLowerThresholdClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + return insert((static_cast<Tpg300 *>(device))->read_lower_threshold(argin)); +} +//-------------------------------------------------------- +/** + * method : WriteUpperThresholdClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *WriteUpperThresholdClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "WriteUpperThresholdClass::execute(): arrived" << endl; + + const Tango::DevVarDoubleArray *argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->write_upper_threshold(argin)); + return new CORBA::Any(); +} +//-------------------------------------------------------- +/** + * method : ReadUpperThresholdClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *ReadUpperThresholdClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "ReadUpperThresholdClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + return insert((static_cast<Tpg300 *>(device))->read_upper_threshold(argin)); +} +//-------------------------------------------------------- +/** + * method : ReadSensorSourceClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *ReadSensorSourceClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "ReadSensorSourceClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + return insert((static_cast<Tpg300 *>(device))->read_sensor_source(argin)); +} +//-------------------------------------------------------- +/** + * method : WriteSensorSourceClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *WriteSensorSourceClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "WriteSensorSourceClass::execute(): arrived" << endl; + + const Tango::DevVarShortArray *argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->write_sensor_source(argin)); + return new CORBA::Any(); +} +//-------------------------------------------------------- +/** + * method : RegisterNameClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *RegisterNameClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "RegisterNameClass::execute(): arrived" << endl; + + const Tango::DevVarLongStringArray *argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->register_name(argin)); + return new CORBA::Any(); +} +//-------------------------------------------------------- +/** + * method : UnregisterNameClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *UnregisterNameClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "UnregisterNameClass::execute(): arrived" << endl; + + Tango::DevShort argin; + extract(in_any, argin); + ((static_cast<Tpg300 *>(device))->unregister_name(argin)); + return new CORBA::Any(); +} + + + + +//=================================================================== +// Properties management +//=================================================================== + +//-------------------------------------------------------- +/** + * method : Tpg300Class::get_class_property + * description : Get the class property for specified name. + * + * @param name The property name + */ +//-------------------------------------------------------- +Tango::DbDatum Tpg300Class::get_class_property(string &prop_name) +{ + for (unsigned int i=0 ; i<cl_prop.size() ; i++) + if (cl_prop[i].name == prop_name) + return cl_prop[i]; + // if not found, returns an empty DbDatum + return Tango::DbDatum(prop_name); +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::get_default_device_property()() + * Description : Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum Tpg300Class::get_default_device_property(string &prop_name) +{ + for (unsigned int i=0 ; i<dev_def_prop.size() ; i++) + if (dev_def_prop[i].name == prop_name) + return dev_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::get_default_class_property()() + * Description : Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum Tpg300Class::get_default_class_property(string &prop_name) +{ + for (unsigned int i=0 ; i<cl_def_prop.size() ; i++) + if (cl_def_prop[i].name == prop_name) + return cl_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::get_class_property() + * Description : // Add your own code to initialize + */ +//-------------------------------------------------------- +void Tpg300Class::get_class_property() +{ +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::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. + */ +//-------------------------------------------------------- +void Tpg300Class::set_default_property() +{ + string prop_name; + string prop_desc; + string prop_def; + vector<string> vect_data; + + // Set Default Class Properties + + // Set Default Device Properties + + prop_name = "SerialDevice"; + prop_desc = ""; + prop_def = "undefined\n"; + vect_data.clear(); + vect_data.push_back("undefined"); + 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); + + prop_name = "Timeout"; + prop_desc = "Milliseconds"; + prop_def = "2500\n"; + vect_data.clear(); + vect_data.push_back("2500"); + 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); + + prop_name = "ThreadSleep"; + prop_desc = "Millisecond"; + prop_def = "1500\n"; + vect_data.clear(); + vect_data.push_back("1500"); + 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); + + prop_name = "ProxySleep"; + prop_desc = "Millisecond"; + prop_def = "1500\n"; + vect_data.clear(); + vect_data.push_back("1500"); + 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); +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::write_class_property() + * Description : Set class description fields as property in database + */ +//-------------------------------------------------------- +void Tpg300Class::write_class_property() +{ + // First time, check if database used + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + string classname = get_name(); + string header; + string::size_type start, end; + + // Put title + Tango::DbDatum title("ProjectTitle"); + string str_title("Blzer Tpg 300"); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + vector<string> str_desc; + str_desc.push_back("Total pressure gauge and controller"); + description << str_desc; + data.push_back(description); + + // put cvs or svn location + string filename("Tpg300"); + filename += "Class.cpp"; + + // check for cvs information + string src_path(CvsPath); + start = src_path.find("/"); + if (start!=string::npos) + { + end = src_path.find(filename); + if (end>start) + { + string strloc = src_path.substr(start, end-start); + // Check if specific repository + start = strloc.find("/cvsroot/"); + if (start!=string::npos && start>0) + { + string repository = strloc.substr(0, start); + if (repository.find("/segfs/")!=string::npos) + strloc = "ESRF:" + strloc.substr(start, strloc.length()-start); + } + Tango::DbDatum cvs_loc("cvs_location"); + cvs_loc << strloc; + data.push_back(cvs_loc); + } + } + // check for svn information + else + { + string src_path(SvnPath); + start = src_path.find("://"); + if (start!=string::npos) + { + end = src_path.find(filename); + if (end>start) + { + header = "$HeadURL: "; + start = header.length(); + string strloc = src_path.substr(start, (end-start)); + + Tango::DbDatum svn_loc("svn_location"); + svn_loc << strloc; + data.push_back(svn_loc); + } + } + } + + // Get CVS or SVN revision tag + + // CVS tag + string tagname(TagName); + header = "$Name: "; + start = header.length(); + string endstr(" $"); + + end = tagname.find(endstr); + if (end!=string::npos && end>start) + { + string strtag = tagname.substr(start, end-start); + Tango::DbDatum cvs_tag("cvs_tag"); + cvs_tag << strtag; + data.push_back(cvs_tag); + } + + // SVN tag + string svnpath(SvnPath); + header = "$HeadURL: "; + start = header.length(); + + end = svnpath.find(endstr); + if (end!=string::npos && end>start) + { + string strloc = svnpath.substr(start, end-start); + + string tagstr ("/tags/"); + start = strloc.find(tagstr); + if ( start!=string::npos ) + { + start = start + tagstr.length(); + end = strloc.find(filename); + string strtag = strloc.substr(start, end-start-1); + + Tango::DbDatum svn_tag("svn_tag"); + svn_tag << strtag; + data.push_back(svn_tag); + } + } + + // Get URL location + string httpServ(HttpServer); + if (httpServ.length()>0) + { + Tango::DbDatum db_doc_url("doc_url"); + db_doc_url << httpServ; + data.push_back(db_doc_url); + } + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + vector<string> inheritance; + inheritance.push_back("Device_Impl"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + get_db_class()->put_property(data); +} + + + + +//=================================================================== +// Factory methods +//=================================================================== + + +//-------------------------------------------------------- +/** + * method : Tpg300Class::device_factory + * description : Create the device object(s) + * and store them in the device list + * + * @param *devlist_ptr The device name list + */ +//-------------------------------------------------------- +void Tpg300Class::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + + /*----- PROTECTED REGION ID(Tpg300::Class::device_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::device_factory_before + + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl; + device_list.push_back(new Tpg300(this, (*devlist_ptr)[i])); + } + + // Manage dynamic attributes if any + erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); + + // Export devices to the outside world + for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) + { + // Add dynamic attributes if any + Tpg300 *dev = static_cast<Tpg300 *>(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(Tpg300::Class::device_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::device_factory_after + + +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::attribute_factory() + * Description : Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void Tpg300Class::attribute_factory(vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(Tpg300::Class::attribute_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::attribute_factory_before + + + // Attribute : Pressure_0 + Pressure_0Attrib *pressure_0 = new Pressure_0Attrib(); + Tango::UserDefaultAttrProp pressure_0_prop; + // description not set for Pressure_0 + // label not set for Pressure_0 + pressure_0_prop.set_unit("mbar"); + pressure_0_prop.set_standard_unit("mbar"); + pressure_0_prop.set_display_unit("mbar"); + // format not set for Pressure_0 + // max_value not set for Pressure_0 + // min_value not set for Pressure_0 + // max_alarm not set for Pressure_0 + // min_alarm not set for Pressure_0 + // max_warning not set for Pressure_0 + // min_warning not set for Pressure_0 + // delta_t not set for Pressure_0 + // delta_val not set for Pressure_0 + pressure_0->set_default_properties(pressure_0_prop); + // Not Polled + pressure_0->set_disp_level(Tango::OPERATOR); + // Not memorized + + // Pressure_0 does not fire change event + // Pressure_0 does not fire archive event + // Pressure_0 does not fire data_ready event + att_list.push_back(pressure_0); + + // Attribute : Pressure_1 + Pressure_1Attrib *pressure_1 = new Pressure_1Attrib(); + Tango::UserDefaultAttrProp pressure_1_prop; + // description not set for Pressure_1 + // label not set for Pressure_1 + pressure_1_prop.set_unit("mbar"); + pressure_1_prop.set_standard_unit("mbar"); + pressure_1_prop.set_display_unit("mbar"); + // format not set for Pressure_1 + // max_value not set for Pressure_1 + // min_value not set for Pressure_1 + // max_alarm not set for Pressure_1 + // min_alarm not set for Pressure_1 + // max_warning not set for Pressure_1 + // min_warning not set for Pressure_1 + // delta_t not set for Pressure_1 + // delta_val not set for Pressure_1 + pressure_1->set_default_properties(pressure_1_prop); + // Not Polled + pressure_1->set_disp_level(Tango::OPERATOR); + // Not memorized + + // Pressure_1 does not fire change event + // Pressure_1 does not fire archive event + // Pressure_1 does not fire data_ready event + att_list.push_back(pressure_1); + + // Attribute : Pressure_2 + Pressure_2Attrib *pressure_2 = new Pressure_2Attrib(); + Tango::UserDefaultAttrProp pressure_2_prop; + // description not set for Pressure_2 + // label not set for Pressure_2 + pressure_2_prop.set_unit("mbar"); + pressure_2_prop.set_standard_unit("mbar"); + pressure_2_prop.set_display_unit("mbar"); + // format not set for Pressure_2 + // max_value not set for Pressure_2 + // min_value not set for Pressure_2 + // max_alarm not set for Pressure_2 + // min_alarm not set for Pressure_2 + // max_warning not set for Pressure_2 + // min_warning not set for Pressure_2 + // delta_t not set for Pressure_2 + // delta_val not set for Pressure_2 + pressure_2->set_default_properties(pressure_2_prop); + // Not Polled + pressure_2->set_disp_level(Tango::OPERATOR); + // Not memorized + + // Pressure_2 does not fire change event + // Pressure_2 does not fire archive event + // Pressure_2 does not fire data_ready event + att_list.push_back(pressure_2); + + // Attribute : Pressure_3 + Pressure_3Attrib *pressure_3 = new Pressure_3Attrib(); + Tango::UserDefaultAttrProp pressure_3_prop; + // description not set for Pressure_3 + // label not set for Pressure_3 + pressure_3_prop.set_unit("mbar"); + pressure_3_prop.set_standard_unit("mbar"); + pressure_3_prop.set_display_unit("mbar"); + // format not set for Pressure_3 + // max_value not set for Pressure_3 + // min_value not set for Pressure_3 + // max_alarm not set for Pressure_3 + // min_alarm not set for Pressure_3 + // max_warning not set for Pressure_3 + // min_warning not set for Pressure_3 + // delta_t not set for Pressure_3 + // delta_val not set for Pressure_3 + pressure_3->set_default_properties(pressure_3_prop); + // Not Polled + pressure_3->set_disp_level(Tango::OPERATOR); + // Not memorized + + // Pressure_3 does not fire change event + // Pressure_3 does not fire archive event + // Pressure_3 does not fire data_ready event + att_list.push_back(pressure_3); + + // Attribute : State_0 + State_0Attrib *state_0 = new State_0Attrib(); + Tango::UserDefaultAttrProp state_0_prop; + // description not set for State_0 + // label not set for State_0 + // unit not set for State_0 + // standard_unit not set for State_0 + // display_unit not set for State_0 + // format not set for State_0 + // max_value not set for State_0 + // min_value not set for State_0 + // max_alarm not set for State_0 + // min_alarm not set for State_0 + // max_warning not set for State_0 + // min_warning not set for State_0 + // delta_t not set for State_0 + // delta_val not set for State_0 + state_0->set_default_properties(state_0_prop); + // Not Polled + state_0->set_disp_level(Tango::EXPERT); + // Not memorized + + // State_0 does not fire change event + // State_0 does not fire archive event + // State_0 does not fire data_ready event + att_list.push_back(state_0); + + // Attribute : State_1 + State_1Attrib *state_1 = new State_1Attrib(); + Tango::UserDefaultAttrProp state_1_prop; + // description not set for State_1 + // label not set for State_1 + // unit not set for State_1 + // standard_unit not set for State_1 + // display_unit not set for State_1 + // format not set for State_1 + // max_value not set for State_1 + // min_value not set for State_1 + // max_alarm not set for State_1 + // min_alarm not set for State_1 + // max_warning not set for State_1 + // min_warning not set for State_1 + // delta_t not set for State_1 + // delta_val not set for State_1 + state_1->set_default_properties(state_1_prop); + // Not Polled + state_1->set_disp_level(Tango::EXPERT); + // Not memorized + + // State_1 does not fire change event + // State_1 does not fire archive event + // State_1 does not fire data_ready event + att_list.push_back(state_1); + + // Attribute : State_2 + State_2Attrib *state_2 = new State_2Attrib(); + Tango::UserDefaultAttrProp state_2_prop; + // description not set for State_2 + // label not set for State_2 + // unit not set for State_2 + // standard_unit not set for State_2 + // display_unit not set for State_2 + // format not set for State_2 + // max_value not set for State_2 + // min_value not set for State_2 + // max_alarm not set for State_2 + // min_alarm not set for State_2 + // max_warning not set for State_2 + // min_warning not set for State_2 + // delta_t not set for State_2 + // delta_val not set for State_2 + state_2->set_default_properties(state_2_prop); + // Not Polled + state_2->set_disp_level(Tango::EXPERT); + // Not memorized + + // State_2 does not fire change event + // State_2 does not fire archive event + // State_2 does not fire data_ready event + att_list.push_back(state_2); + + // Attribute : State_3 + State_3Attrib *state_3 = new State_3Attrib(); + Tango::UserDefaultAttrProp state_3_prop; + // description not set for State_3 + // label not set for State_3 + // unit not set for State_3 + // standard_unit not set for State_3 + // display_unit not set for State_3 + // format not set for State_3 + // max_value not set for State_3 + // min_value not set for State_3 + // max_alarm not set for State_3 + // min_alarm not set for State_3 + // max_warning not set for State_3 + // min_warning not set for State_3 + // delta_t not set for State_3 + // delta_val not set for State_3 + state_3->set_default_properties(state_3_prop); + // Not Polled + state_3->set_disp_level(Tango::EXPERT); + // Not memorized + + // State_3 does not fire change event + // State_3 does not fire archive event + // State_3 does not fire data_ready event + att_list.push_back(state_3); + + // Attribute : Status_0 + Status_0Attrib *status_0 = new Status_0Attrib(); + Tango::UserDefaultAttrProp status_0_prop; + // description not set for Status_0 + // label not set for Status_0 + // unit not set for Status_0 + // standard_unit not set for Status_0 + // display_unit not set for Status_0 + // format not set for Status_0 + // max_value not set for Status_0 + // min_value not set for Status_0 + // max_alarm not set for Status_0 + // min_alarm not set for Status_0 + // max_warning not set for Status_0 + // min_warning not set for Status_0 + // delta_t not set for Status_0 + // delta_val not set for Status_0 + status_0->set_default_properties(status_0_prop); + // Not Polled + status_0->set_disp_level(Tango::EXPERT); + // Not memorized + + // Status_0 does not fire change event + // Status_0 does not fire archive event + // Status_0 does not fire data_ready event + att_list.push_back(status_0); + + // Attribute : Status_1 + Status_1Attrib *status_1 = new Status_1Attrib(); + Tango::UserDefaultAttrProp status_1_prop; + // description not set for Status_1 + // label not set for Status_1 + // unit not set for Status_1 + // standard_unit not set for Status_1 + // display_unit not set for Status_1 + // format not set for Status_1 + // max_value not set for Status_1 + // min_value not set for Status_1 + // max_alarm not set for Status_1 + // min_alarm not set for Status_1 + // max_warning not set for Status_1 + // min_warning not set for Status_1 + // delta_t not set for Status_1 + // delta_val not set for Status_1 + status_1->set_default_properties(status_1_prop); + // Not Polled + status_1->set_disp_level(Tango::EXPERT); + // Not memorized + + // Status_1 does not fire change event + // Status_1 does not fire archive event + // Status_1 does not fire data_ready event + att_list.push_back(status_1); + + // Attribute : Status_2 + Status_2Attrib *status_2 = new Status_2Attrib(); + Tango::UserDefaultAttrProp status_2_prop; + // description not set for Status_2 + // label not set for Status_2 + // unit not set for Status_2 + // standard_unit not set for Status_2 + // display_unit not set for Status_2 + // format not set for Status_2 + // max_value not set for Status_2 + // min_value not set for Status_2 + // max_alarm not set for Status_2 + // min_alarm not set for Status_2 + // max_warning not set for Status_2 + // min_warning not set for Status_2 + // delta_t not set for Status_2 + // delta_val not set for Status_2 + status_2->set_default_properties(status_2_prop); + // Not Polled + status_2->set_disp_level(Tango::EXPERT); + // Not memorized + + // Status_2 does not fire change event + // Status_2 does not fire archive event + // Status_2 does not fire data_ready event + att_list.push_back(status_2); + + // Attribute : Status_3 + Status_3Attrib *status_3 = new Status_3Attrib(); + Tango::UserDefaultAttrProp status_3_prop; + // description not set for Status_3 + // label not set for Status_3 + // unit not set for Status_3 + // standard_unit not set for Status_3 + // display_unit not set for Status_3 + // format not set for Status_3 + // max_value not set for Status_3 + // min_value not set for Status_3 + // max_alarm not set for Status_3 + // min_alarm not set for Status_3 + // max_warning not set for Status_3 + // min_warning not set for Status_3 + // delta_t not set for Status_3 + // delta_val not set for Status_3 + status_3->set_default_properties(status_3_prop); + // Not Polled + status_3->set_disp_level(Tango::EXPERT); + // Not memorized + + // Status_3 does not fire change event + // Status_3 does not fire archive event + // Status_3 does not fire data_ready event + att_list.push_back(status_3); + + // Attribute : Name_0 + Name_0Attrib *name_0 = new Name_0Attrib(); + Tango::UserDefaultAttrProp name_0_prop; + // description not set for Name_0 + // label not set for Name_0 + // unit not set for Name_0 + // standard_unit not set for Name_0 + // display_unit not set for Name_0 + // format not set for Name_0 + // max_value not set for Name_0 + // min_value not set for Name_0 + // max_alarm not set for Name_0 + // min_alarm not set for Name_0 + // max_warning not set for Name_0 + // min_warning not set for Name_0 + // delta_t not set for Name_0 + // delta_val not set for Name_0 + name_0->set_default_properties(name_0_prop); + // Not Polled + name_0->set_disp_level(Tango::EXPERT); + // Not memorized + + // Name_0 does not fire change event + // Name_0 does not fire archive event + // Name_0 does not fire data_ready event + att_list.push_back(name_0); + + // Attribute : Name_1 + Name_1Attrib *name_1 = new Name_1Attrib(); + Tango::UserDefaultAttrProp name_1_prop; + // description not set for Name_1 + // label not set for Name_1 + // unit not set for Name_1 + // standard_unit not set for Name_1 + // display_unit not set for Name_1 + // format not set for Name_1 + // max_value not set for Name_1 + // min_value not set for Name_1 + // max_alarm not set for Name_1 + // min_alarm not set for Name_1 + // max_warning not set for Name_1 + // min_warning not set for Name_1 + // delta_t not set for Name_1 + // delta_val not set for Name_1 + name_1->set_default_properties(name_1_prop); + // Not Polled + name_1->set_disp_level(Tango::EXPERT); + // Not memorized + + // Name_1 does not fire change event + // Name_1 does not fire archive event + // Name_1 does not fire data_ready event + att_list.push_back(name_1); + + // Attribute : Name_2 + Name_2Attrib *name_2 = new Name_2Attrib(); + Tango::UserDefaultAttrProp name_2_prop; + // description not set for Name_2 + // label not set for Name_2 + // unit not set for Name_2 + // standard_unit not set for Name_2 + // display_unit not set for Name_2 + // format not set for Name_2 + // max_value not set for Name_2 + // min_value not set for Name_2 + // max_alarm not set for Name_2 + // min_alarm not set for Name_2 + // max_warning not set for Name_2 + // min_warning not set for Name_2 + // delta_t not set for Name_2 + // delta_val not set for Name_2 + name_2->set_default_properties(name_2_prop); + // Not Polled + name_2->set_disp_level(Tango::EXPERT); + // Not memorized + + // Name_2 does not fire change event + // Name_2 does not fire archive event + // Name_2 does not fire data_ready event + att_list.push_back(name_2); + + // Attribute : Name_3 + Name_3Attrib *name_3 = new Name_3Attrib(); + Tango::UserDefaultAttrProp name_3_prop; + // description not set for Name_3 + // label not set for Name_3 + // unit not set for Name_3 + // standard_unit not set for Name_3 + // display_unit not set for Name_3 + // format not set for Name_3 + // max_value not set for Name_3 + // min_value not set for Name_3 + // max_alarm not set for Name_3 + // min_alarm not set for Name_3 + // max_warning not set for Name_3 + // min_warning not set for Name_3 + // delta_t not set for Name_3 + // delta_val not set for Name_3 + name_3->set_default_properties(name_3_prop); + // Not Polled + name_3->set_disp_level(Tango::EXPERT); + // Not memorized + + // Name_3 does not fire change event + // Name_3 does not fire archive event + // Name_3 does not fire data_ready event + att_list.push_back(name_3); + + // Attribute : DeviceState + DeviceStateAttrib *devicestate = new DeviceStateAttrib(); + Tango::UserDefaultAttrProp devicestate_prop; + // description not set for DeviceState + // label not set for DeviceState + // unit not set for DeviceState + // standard_unit not set for DeviceState + // display_unit not set for DeviceState + // format not set for DeviceState + // max_value not set for DeviceState + // min_value not set for DeviceState + // max_alarm not set for DeviceState + // min_alarm not set for DeviceState + // max_warning not set for DeviceState + // min_warning not set for DeviceState + // delta_t not set for DeviceState + // delta_val not set for DeviceState + devicestate->set_default_properties(devicestate_prop); + // Not Polled + devicestate->set_disp_level(Tango::OPERATOR); + devicestate->set_memorized(); + devicestate->set_memorized_init(false); + // DeviceState does not fire change event + // DeviceState does not fire archive event + // DeviceState does not fire data_ready event + att_list.push_back(devicestate); + + // Attribute : DeviceStatus + DeviceStatusAttrib *devicestatus = new DeviceStatusAttrib(); + Tango::UserDefaultAttrProp devicestatus_prop; + // description not set for DeviceStatus + // label not set for DeviceStatus + // unit not set for DeviceStatus + // standard_unit not set for DeviceStatus + // display_unit not set for DeviceStatus + // format not set for DeviceStatus + // max_value not set for DeviceStatus + // min_value not set for DeviceStatus + // max_alarm not set for DeviceStatus + // min_alarm not set for DeviceStatus + // max_warning not set for DeviceStatus + // min_warning not set for DeviceStatus + // delta_t not set for DeviceStatus + // delta_val not set for DeviceStatus + devicestatus->set_default_properties(devicestatus_prop); + // Not Polled + devicestatus->set_disp_level(Tango::OPERATOR); + // Not memorized + + // DeviceStatus does not fire change event + // DeviceStatus does not fire archive event + // DeviceStatus does not fire data_ready event + att_list.push_back(devicestatus); + + // Attribute : SetPointStatus + SetPointStatusAttrib *setpointstatus = new SetPointStatusAttrib(); + Tango::UserDefaultAttrProp setpointstatus_prop; + // description not set for SetPointStatus + // label not set for SetPointStatus + // unit not set for SetPointStatus + // standard_unit not set for SetPointStatus + // display_unit not set for SetPointStatus + // format not set for SetPointStatus + // max_value not set for SetPointStatus + // min_value not set for SetPointStatus + // max_alarm not set for SetPointStatus + // min_alarm not set for SetPointStatus + // max_warning not set for SetPointStatus + // min_warning not set for SetPointStatus + // delta_t not set for SetPointStatus + // delta_val not set for SetPointStatus + setpointstatus->set_default_properties(setpointstatus_prop); + // Not Polled + setpointstatus->set_disp_level(Tango::OPERATOR); + // Not memorized + + // SetPointStatus does not fire change event + // SetPointStatus does not fire archive event + // SetPointStatus does not fire data_ready event + att_list.push_back(setpointstatus); + + + // Create a list of static attributes + create_static_attribute_list(get_class_attr()->get_attr_list()); + + /*----- PROTECTED REGION ID(Tpg300::Class::attribute_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::attribute_factory_after + +} + + +//-------------------------------------------------------- +/** + * Method : Tpg300::Tpg300Class::command_factory() + * Description : Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void Tpg300Class::command_factory() +{ + /*----- PROTECTED REGION ID(Tpg300::Class::command_factory_before) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::command_factory_before + + SensorOnClass *pSensorOnCmd = + new SensorOnClass("SensorOn", + Tango::DEV_SHORT, Tango::DEV_VOID, + "Channel\n[0,3]", + "", + Tango::EXPERT); + command_list.push_back(pSensorOnCmd); + SensorOffClass *pSensorOffCmd = + new SensorOffClass("SensorOff", + Tango::DEV_SHORT, Tango::DEV_VOID, + "Channel\n[0,3]", + "", + Tango::EXPERT); + command_list.push_back(pSensorOffCmd); + WriteLowerThresholdClass *pWriteLowerThresholdCmd = + new WriteLowerThresholdClass("WriteLowerThreshold", + Tango::DEVVAR_DOUBLEARRAY, Tango::DEV_VOID, + "Setpoint, Pressure\n\nSetpoint\n0 -> Switching function 1\n1 -> Switching function 2\n2 -> Switching function 3\n3 -> Switching function 4\n4 -> Switching function A\n5 -> Switching function B\n\nPressure\n[1.0E-11, 9.9E+3]", + "", + Tango::EXPERT); + command_list.push_back(pWriteLowerThresholdCmd); + ReadLowerThresholdClass *pReadLowerThresholdCmd = + new ReadLowerThresholdClass("ReadLowerThreshold", + Tango::DEV_SHORT, Tango::DEV_DOUBLE, + "Setpoint\n0 -> Switching function 1\n1 -> Switching function 2\n2 -> Switching function 3\n3 -> Switching function 4\n4 -> Switching function A\n5 -> Switching function B", + "Pressure", + Tango::EXPERT); + command_list.push_back(pReadLowerThresholdCmd); + WriteUpperThresholdClass *pWriteUpperThresholdCmd = + new WriteUpperThresholdClass("WriteUpperThreshold", + Tango::DEVVAR_DOUBLEARRAY, Tango::DEV_VOID, + "Setpoint, Pressure\n\nSetpoint\n0 -> Switching function 1\n1 -> Switching function 2\n2 -> Switching function 3\n3 -> Switching function 4\n4 -> Switching function A\n5 -> Switching function B\n\nPressure\n[1.0E-11, 9.9E+3]", + "", + Tango::EXPERT); + command_list.push_back(pWriteUpperThresholdCmd); + ReadUpperThresholdClass *pReadUpperThresholdCmd = + new ReadUpperThresholdClass("ReadUpperThreshold", + Tango::DEV_SHORT, Tango::DEV_DOUBLE, + "Setpoint\n0 -> Switching function 1\n1 -> Switching function 2\n2 -> Switching function 3\n3 -> Switching function 4\n4 -> Switching function A\n5 -> Switching function B", + "Pressure", + Tango::EXPERT); + command_list.push_back(pReadUpperThresholdCmd); + ReadSensorSourceClass *pReadSensorSourceCmd = + new ReadSensorSourceClass("ReadSensorSource", + Tango::DEV_SHORT, Tango::DEV_SHORT, + "Setpoint\n0 -> Switching function 1\n1 -> Switching function 2\n2 -> Switching function 3\n3 -> Switching function 4\n4 -> Switching function A\n5 -> Switching function B", + "Source\n0 -> No assignment\n1 -> Measuring circuit A1\n2 -> Measuring circuit A2\n3 -> Measuring circuit B1\n4 -> Measuring circuit B2\n5 -> Measuring circuit A1 (for self monitoring)\n6 -> Measuring circuit A2 (for self monitoring)\n7 -> Measuring circuit B1 (for self monitoring)\n8 -> Measuring circuit B2 (for self monitoring)", + Tango::EXPERT); + command_list.push_back(pReadSensorSourceCmd); + WriteSensorSourceClass *pWriteSensorSourceCmd = + new WriteSensorSourceClass("WriteSensorSource", + Tango::DEVVAR_SHORTARRAY, Tango::DEV_VOID, + "Setpoint, Source\n\nSetpoint\n0 -> Switching function 1\n1 -> Switching function 2\n2 -> Switching function 3\n3 -> Switching function 4\n4 -> Switching function A\n5 -> Switching function B\n\nSource:\n0 -> No assignment\n1 -> Measuring circuit A1\n2 -> Measuring circuit A2\n3 -> Measuring circuit B1\n4 -> Measuring circuit B2\n5 -> Measuring circuit A1 (for self monitoring)\n6 -> Measuring circuit A2 (for self monitoring)\n7 -> Measuring circuit B1 (for self monitoring)\n8 -> Measuring circuit B2 (for self monitoring)", + "", + Tango::EXPERT); + command_list.push_back(pWriteSensorSourceCmd); + RegisterNameClass *pRegisterNameCmd = + new RegisterNameClass("RegisterName", + Tango::DEVVAR_LONGSTRINGARRAY, Tango::DEV_VOID, + "Channel, Name\n\nChannel\n[0,3]\n\nName\nmax 64 characters", + "", + Tango::EXPERT); + command_list.push_back(pRegisterNameCmd); + UnregisterNameClass *pUnregisterNameCmd = + new UnregisterNameClass("UnregisterName", + Tango::DEV_SHORT, Tango::DEV_VOID, + "Channel\n[0,3]", + "", + Tango::EXPERT); + command_list.push_back(pUnregisterNameCmd); + + /*----- PROTECTED REGION ID(Tpg300::Class::command_factory_after) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::command_factory_after + +} + + + + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + + +//-------------------------------------------------------- +/** + * method : Tpg300Class::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the ceated attribute list + */ +//-------------------------------------------------------- +void Tpg300Class::create_static_attribute_list(vector<Tango::Attr *> &att_list) +{ + for (unsigned long i=0 ; i<att_list.size() ; i++) + { + string att_name(att_list[i]->get_name()); + transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + defaultAttList.push_back(att_name); + } + + cout2 << defaultAttList.size() << " attributes in default list" << endl; + + + /*----- PROTECTED REGION ID(Tpg300::Class::create_static_att_list) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::create_static_att_list + +} + + +//-------------------------------------------------------- +/** + * method : Tpg300Class::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void Tpg300Class::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, vector<Tango::Attr *> &att_list) +{ + Tango::Util *tg = Tango::Util::instance(); + + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((string)(*devlist_ptr)[i]).c_str()); + Tpg300 *dev = static_cast<Tpg300 *> (dev_impl); + + vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list(); + vector<Tango::Attribute *>::iterator ite_att; + for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att) + { + string att_name((*ite_att)->get_name_lower()); + if ((att_name == "state") || (att_name == "status")) + continue; + vector<string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name); + if (ite_str == defaultAttList.end()) + { + cout2 << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << endl; + Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str()); + dev->remove_attribute(att_list[att.get_attr_idx()],true); + --ite_att; + } + } + } + /*----- PROTECTED REGION ID(Tpg300::Class::erase_dynamic_attributes) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::erase_dynamic_attributes + +} + + + + /*----- PROTECTED REGION ID(Tpg300::Class::Additional Methods) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Class::Additional Methods + +} // namespace diff --git a/src/Tpg300Class.h b/src/Tpg300Class.h new file mode 100644 index 0000000000000000000000000000000000000000..7dc4b90f4f92346ca2323ca0a7ee71faec26c7b2 --- /dev/null +++ b/src/Tpg300Class.h @@ -0,0 +1,619 @@ +/*----- PROTECTED REGION ID(Tpg300Class.h) ENABLED START -----*/ +//============================================================================= +// +// file : Tpg300Class.h +// +// description : Include for the Tpg300Class root class. +// This class is the singleton class for. +// the Tpg300 device class.. +// It contains all properties and methods which the . +// Tpg300 requires only once e.g. the commands. +// +// project : Blzer Tpg 300. +// +// $Author: lorenzo $ +// +// $Revision: 1.5 $ +// $Date: 2013-06-05 14:59:10 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/Tpg300Class.h,v $ +// $Log: Tpg300Class.h,v $ +// Revision 1.5 2013-06-05 14:59:10 lorenzo +// Tango 8.0.5 +// +// Revision 1.4 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef TPG300CLASS_H +#define TPG300CLASS_H + +#include <tango.h> +#include <Tpg300.h> + +/*----- PROTECTED REGION END -----*/ + +namespace Tpg300_ns +{ + /*----- PROTECTED REGION ID(Tpg300::classes for dynamic creation) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::classes for dynamic creation + + + +//========================================= +// Define classes for attributes +//========================================= +// Attribute Pressure_0 class definition +class Pressure_0Attrib: public Tango::Attr +{ +public: + Pressure_0Attrib():Attr("Pressure_0", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~Pressure_0Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Pressure_0(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Pressure_0_allowed(ty);} +}; + +// Attribute Pressure_1 class definition +class Pressure_1Attrib: public Tango::Attr +{ +public: + Pressure_1Attrib():Attr("Pressure_1", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~Pressure_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Pressure_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Pressure_1_allowed(ty);} +}; + +// Attribute Pressure_2 class definition +class Pressure_2Attrib: public Tango::Attr +{ +public: + Pressure_2Attrib():Attr("Pressure_2", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~Pressure_2Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Pressure_2(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Pressure_2_allowed(ty);} +}; + +// Attribute Pressure_3 class definition +class Pressure_3Attrib: public Tango::Attr +{ +public: + Pressure_3Attrib():Attr("Pressure_3", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~Pressure_3Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Pressure_3(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Pressure_3_allowed(ty);} +}; + +// Attribute State_0 class definition +class State_0Attrib: public Tango::Attr +{ +public: + State_0Attrib():Attr("State_0", + Tango::DEV_STATE, Tango::READ) {}; + ~State_0Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_State_0(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_State_0_allowed(ty);} +}; + +// Attribute State_1 class definition +class State_1Attrib: public Tango::Attr +{ +public: + State_1Attrib():Attr("State_1", + Tango::DEV_STATE, Tango::READ) {}; + ~State_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_State_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_State_1_allowed(ty);} +}; + +// Attribute State_2 class definition +class State_2Attrib: public Tango::Attr +{ +public: + State_2Attrib():Attr("State_2", + Tango::DEV_STATE, Tango::READ) {}; + ~State_2Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_State_2(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_State_2_allowed(ty);} +}; + +// Attribute State_3 class definition +class State_3Attrib: public Tango::Attr +{ +public: + State_3Attrib():Attr("State_3", + Tango::DEV_STATE, Tango::READ) {}; + ~State_3Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_State_3(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_State_3_allowed(ty);} +}; + +// Attribute Status_0 class definition +class Status_0Attrib: public Tango::Attr +{ +public: + Status_0Attrib():Attr("Status_0", + Tango::DEV_STRING, Tango::READ) {}; + ~Status_0Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Status_0(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Status_0_allowed(ty);} +}; + +// Attribute Status_1 class definition +class Status_1Attrib: public Tango::Attr +{ +public: + Status_1Attrib():Attr("Status_1", + Tango::DEV_STRING, Tango::READ) {}; + ~Status_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Status_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Status_1_allowed(ty);} +}; + +// Attribute Status_2 class definition +class Status_2Attrib: public Tango::Attr +{ +public: + Status_2Attrib():Attr("Status_2", + Tango::DEV_STRING, Tango::READ) {}; + ~Status_2Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Status_2(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Status_2_allowed(ty);} +}; + +// Attribute Status_3 class definition +class Status_3Attrib: public Tango::Attr +{ +public: + Status_3Attrib():Attr("Status_3", + Tango::DEV_STRING, Tango::READ) {}; + ~Status_3Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Status_3(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Status_3_allowed(ty);} +}; + +// Attribute Name_0 class definition +class Name_0Attrib: public Tango::Attr +{ +public: + Name_0Attrib():Attr("Name_0", + Tango::DEV_STRING, Tango::READ) {}; + ~Name_0Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Name_0(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Name_0_allowed(ty);} +}; + +// Attribute Name_1 class definition +class Name_1Attrib: public Tango::Attr +{ +public: + Name_1Attrib():Attr("Name_1", + Tango::DEV_STRING, Tango::READ) {}; + ~Name_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Name_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Name_1_allowed(ty);} +}; + +// Attribute Name_2 class definition +class Name_2Attrib: public Tango::Attr +{ +public: + Name_2Attrib():Attr("Name_2", + Tango::DEV_STRING, Tango::READ) {}; + ~Name_2Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Name_2(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Name_2_allowed(ty);} +}; + +// Attribute Name_3 class definition +class Name_3Attrib: public Tango::Attr +{ +public: + Name_3Attrib():Attr("Name_3", + Tango::DEV_STRING, Tango::READ) {}; + ~Name_3Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_Name_3(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_Name_3_allowed(ty);} +}; + +// Attribute DeviceState class definition +class DeviceStateAttrib: public Tango::Attr +{ +public: + DeviceStateAttrib():Attr("DeviceState", + Tango::DEV_UCHAR, Tango::READ_WRITE) {}; + ~DeviceStateAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_DeviceState(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<Tpg300 *>(dev))->write_DeviceState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_DeviceState_allowed(ty);} +}; + +// Attribute DeviceStatus class definition +class DeviceStatusAttrib: public Tango::Attr +{ +public: + DeviceStatusAttrib():Attr("DeviceStatus", + Tango::DEV_STRING, Tango::READ) {}; + ~DeviceStatusAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_DeviceStatus(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_DeviceStatus_allowed(ty);} +}; + +// Attribute SetPointStatus class definition +class SetPointStatusAttrib: public Tango::SpectrumAttr +{ +public: + SetPointStatusAttrib():SpectrumAttr("SetPointStatus", + Tango::DEV_BOOLEAN, Tango::READ, 6) {}; + ~SetPointStatusAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<Tpg300 *>(dev))->read_SetPointStatus(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<Tpg300 *>(dev))->is_SetPointStatus_allowed(ty);} +}; + + + + + +//========================================= +// Define classes for commands +//========================================= +// Command SensorOn class definition +class SensorOnClass : public Tango::Command +{ +public: + SensorOnClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + SensorOnClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~SensorOnClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_SensorOn_allowed(any);} +}; + +// Command SensorOff class definition +class SensorOffClass : public Tango::Command +{ +public: + SensorOffClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + SensorOffClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~SensorOffClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_SensorOff_allowed(any);} +}; + +// Command WriteLowerThreshold class definition +class WriteLowerThresholdClass : public Tango::Command +{ +public: + WriteLowerThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + WriteLowerThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~WriteLowerThresholdClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_WriteLowerThreshold_allowed(any);} +}; + +// Command ReadLowerThreshold class definition +class ReadLowerThresholdClass : public Tango::Command +{ +public: + ReadLowerThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + ReadLowerThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~ReadLowerThresholdClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_ReadLowerThreshold_allowed(any);} +}; + +// Command WriteUpperThreshold class definition +class WriteUpperThresholdClass : public Tango::Command +{ +public: + WriteUpperThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + WriteUpperThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~WriteUpperThresholdClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_WriteUpperThreshold_allowed(any);} +}; + +// Command ReadUpperThreshold class definition +class ReadUpperThresholdClass : public Tango::Command +{ +public: + ReadUpperThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + ReadUpperThresholdClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~ReadUpperThresholdClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_ReadUpperThreshold_allowed(any);} +}; + +// Command ReadSensorSource class definition +class ReadSensorSourceClass : public Tango::Command +{ +public: + ReadSensorSourceClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + ReadSensorSourceClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~ReadSensorSourceClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_ReadSensorSource_allowed(any);} +}; + +// Command WriteSensorSource class definition +class WriteSensorSourceClass : public Tango::Command +{ +public: + WriteSensorSourceClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + WriteSensorSourceClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~WriteSensorSourceClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_WriteSensorSource_allowed(any);} +}; + +// Command RegisterName class definition +class RegisterNameClass : public Tango::Command +{ +public: + RegisterNameClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + RegisterNameClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~RegisterNameClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_RegisterName_allowed(any);} +}; + +// Command UnregisterName class definition +class UnregisterNameClass : public Tango::Command +{ +public: + UnregisterNameClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + UnregisterNameClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~UnregisterNameClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<Tpg300 *>(dev))->is_UnregisterName_allowed(any);} +}; + + + + + +/** + * The TemplateDevServClass singleton definition + */ + +class +#ifdef _TG_WINDOWS_ + __declspec(dllexport) +#endif + Tpg300Class : public Tango::DeviceClass +{ + /*----- PROTECTED REGION ID(Tpg300::Additionnal DServer data members) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::Additionnal DServer data members + + + +public: +// write class properties data members + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + +// Method prototypes + static Tpg300Class *init(const char *); + static Tpg300Class *instance(); + ~Tpg300Class(); + Tango::DbDatum get_class_property(string &); + Tango::DbDatum get_default_device_property(string &); + Tango::DbDatum get_default_class_property(string &); + +protected: + Tpg300Class(string &); + static Tpg300Class *_instance; + void command_factory(); + void attribute_factory(vector<Tango::Attr *> &); + void write_class_property(); + void set_default_property(); + void get_class_property(); + string get_cvstag(); + string get_cvsroot(); + +private: + void device_factory(const Tango::DevVarStringArray *); + void create_static_attribute_list(vector<Tango::Attr *> &); + void erase_dynamic_attributes(const Tango::DevVarStringArray *,vector<Tango::Attr *> &); + vector<string> defaultAttList; + + +}; + +} // namespace + +#endif // TPG300CLASS_H + diff --git a/src/Tpg300Error.cpp b/src/Tpg300Error.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7602bd483596e3ddaa759f18abc2a9e1fe6e0865 --- /dev/null +++ b/src/Tpg300Error.cpp @@ -0,0 +1,131 @@ +/* + * Tpg300Error.cpp + * + * Created on: Jul 17, 2012 + * Author: mdm + */ + +#include <Tpg300Error.h> +#include <Tpg300Proxy.h> +#include <Tpg300Task.h> +#include <Tpg300Utils.h> +#include <ThreadGuard.h> + +namespace Tpg300_ns +{ + +//-------------------------------------------------------- +// Tpg300Error::Tpg300Error() +//-------------------------------------------------------- +Tpg300Error::Tpg300Error(Tpg300Proxy* p) : proxy(p) +{ + state = Tango::UNKNOWN; + status = "Unknown status"; +} + +//-------------------------------------------------------- +// Tpg300Error::update() +//-------------------------------------------------------- +void Tpg300Error::update() +{ + ThreadGuard lock(mutex); + + try + { + string result = proxy->write_read("ERR"); + + state = parse_state(result); + status = parse_status(result); + } + catch(Tango::DevFailed &ex) + { + state = Tango::FAULT; + status = Tpg300Utils::get_trace(ex); + } +} + +//-------------------------------------------------------- +// Tpg300Error::get_state() +//-------------------------------------------------------- +Tango::DevState Tpg300Error::get_state() +{ + ThreadGuard lock(mutex); + + return state; +} + +//-------------------------------------------------------- +// Tpg300Error::get_status() +//-------------------------------------------------------- +std::string Tpg300Error::get_status() +{ + ThreadGuard lock(mutex); + + return status; +} + +//======================================================== +// Utilities methods +//======================================================== + +//-------------------------------------------------------- +// Tpg300Error::parse_state() +//-------------------------------------------------------- +Tango::DevState Tpg300Error::parse_state(std::string result) +{ + Tango::DevState state; + + switch(atoi(result.c_str())) + { + case 0: + state = Tango::STANDBY; + break; + case 10: + state = Tango::ALARM; + break; + case 100: + state = Tango::ALARM; + break; + case 1000: + state = Tango::ALARM; + break; + default: + Tango::Except::throw_exception("", "Parsing error", "parse_state"); + break; + } + + return state; +} + +//-------------------------------------------------------- +// Tpg300Error::parse_status() +//-------------------------------------------------------- +std::string Tpg300Error::parse_status(std::string result) +{ + string status; + + switch(atoi(result.c_str())) + { + case 0: + status = "No error"; + break; + case 10: + status = "Invalid parameter"; + break; + case 100: + status = "Hardware not installed"; + break; + case 1000: + status = "Tpg error"; + break; + default: + Tango::Except::throw_exception("", "Parsing error", "parse_status"); + break; + } + + return status; +} + +} + + diff --git a/src/Tpg300Error.h b/src/Tpg300Error.h new file mode 100644 index 0000000000000000000000000000000000000000..ca801e75e8af0d17ca743fcdd16f7be57a63cd95 --- /dev/null +++ b/src/Tpg300Error.h @@ -0,0 +1,45 @@ +/* + * Tpg300Error.h + * + * Created on: Jul 17, 2012 + * Author: mdm + */ + +#ifndef TPG300ERROR_H_ +#define TPG300ERROR_H_ + +#include <tango.h> +#include <Tpg300Task.h> + +namespace Tpg300_ns +{ + +class Tpg300Proxy; + +class Tpg300Error : public Tpg300Task +{ +public: + Tpg300Error(Tpg300Proxy*); + virtual ~Tpg300Error() {}; + +public: + void update(); + virtual Tango::DevState get_state(); + virtual std::string get_status(); + +protected: + virtual Tango::DevState parse_state(std::string); + virtual std::string parse_status(std::string); + +private: + Tango::DevState state; + std::string status; + Tpg300Proxy* proxy; + omni_mutex mutex; + +}; + +} + + +#endif /* TPG300ERROR_H_ */ diff --git a/src/Tpg300Proxy.cpp b/src/Tpg300Proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce53e987caab57e7edac30a30ea133a18d4efab5 --- /dev/null +++ b/src/Tpg300Proxy.cpp @@ -0,0 +1,157 @@ +/* + * Tpg300Proxy.cpp + * + * Created on: May 22, 2012 + * Author: mdm + */ + +#include <iomanip> +#include "Tpg300Proxy.h" +#include "ThreadGuard.h" + +namespace Tpg300_ns +{ + +//-------------------------------------------------------- +// Tpg300Proxy::Tpg300Proxy() +//-------------------------------------------------------- +Tpg300Proxy::Tpg300Proxy(string serial_device, Tango::DevULong timeout, + Tango::DevULong proxySleep) throw(Tango::DevFailed) +{ + proxy = new Tango::DeviceProxy(serial_device); + proxy->set_timeout_millis(timeout); + + secs = proxySleep / 1000; + nanosecs = (proxySleep % 1000) * 1000000; +} + +//-------------------------------------------------------- +// Tpg300Proxy::~Tpg300Proxy() +//-------------------------------------------------------- +Tpg300Proxy::~Tpg300Proxy() +{ + delete proxy; +} + +//-------------------------------------------------------- +// Tpg300Proxy::write_read() +//-------------------------------------------------------- +std::string Tpg300Proxy::write_read(std::string input_str) throw(Tango::DevFailed) +{ + ThreadGuard lock(mutex); + + flush_data(); + + string output_str = serial_in_out(input_str); + + if(output_str.find(NAK) != string::npos) + Tango::Except::throw_exception("","Negative acknowledge received","write_read"); + + omni_thread::sleep(secs,nanosecs); + + input_str = ENQ; + + output_str = serial_in_out(input_str); + + return output_str; +} + +//======================================================== +// Utilities methods +//======================================================== + +//-------------------------------------------------------- +// Tpg300Proxy::flush_data() +//-------------------------------------------------------- +void Tpg300Proxy::flush_data() +{ + Tango::DeviceData dev_data; + Tango::DevLong flush = 2; + + dev_data << flush; + proxy->command_inout("DevSerFlush", dev_data); +} + +//-------------------------------------------------------- +// Tpg300Proxy::serial_in_out() +//-------------------------------------------------------- +string Tpg300Proxy::serial_in_out(std::string command_str) +{ + Tango::DeviceData dev_data; + + command_str.push_back(CR); + +#ifdef _VERBOSE_DEBUG + print_request_debug(command_str); +#endif + + dev_data << command_str; + proxy->command_inout("DevSerWriteString", dev_data); + + string output_str; + + dev_data = proxy->command_inout("DevSerReadLine"); + dev_data >> output_str; + +#ifdef _VERBOSE_DEBUG + print_response_debug(output_str); +#endif + + size_t pos; + + if ((pos=output_str.find_first_of(LF)) != string::npos) + output_str = output_str.substr(pos+1, string::npos); + + if ((pos=output_str.find_last_of(CR)) != string::npos) + output_str = output_str.substr(0, pos); + + return output_str; +} + +//-------------------------------------------------------- +// Tpg300Proxy::print_request_debug() +//-------------------------------------------------------- +void Tpg300Proxy::print_request_debug(string command_str) +{ + stringstream debug_stream; + + debug_stream << ">>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl; + for(unsigned int j=0; j<command_str.size(); j++) + { + debug_stream << "0x" << internal << setw(2) << setfill('0') + << hex << int(command_str[j]) << " | "; + + if(int(command_str[j]) > 31) + debug_stream << command_str[j]; + + debug_stream << endl; + } + debug_stream << ">>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl; + + cout << debug_stream.str() << endl; +} + +//-------------------------------------------------------- +// Tpg300Proxy::print_response_debug() +//-------------------------------------------------------- +void Tpg300Proxy::print_response_debug(string command_str) +{ + stringstream debug_stream; + + debug_stream << "<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; + for(unsigned int j=0; j<command_str.size(); j++) + { + debug_stream << "0x" << internal << setw(2) + << setfill('0') << hex << int(command_str[j]) << " | "; + + if(int(command_str[j]) > 31) + debug_stream << command_str[j]; + + debug_stream << endl; + } + debug_stream << "<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; + + cout << debug_stream.str() << endl; +} + +} diff --git a/src/Tpg300Proxy.h b/src/Tpg300Proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..9f608ad3ec50735a3ccbfd01c87cdff78815d08e --- /dev/null +++ b/src/Tpg300Proxy.h @@ -0,0 +1,44 @@ +/* + * Tpg300Proxy.h + * + * Created on: May 22, 2012 + * Author: mdm + */ + +#ifndef TPG300PROXY_H_ +#define TPG300PROXY_H_ + +#include <tango.h> + +namespace Tpg300_ns +{ + +class Tpg300Proxy +{ +public: + Tpg300Proxy(std::string, Tango::DevULong, Tango::DevULong) throw(Tango::DevFailed); + virtual ~Tpg300Proxy(); + +public: + virtual std::string write_read(std::string) throw(Tango::DevFailed); + +protected: + virtual void flush_data(); + virtual std::string serial_in_out(std::string); + virtual void print_request_debug(std::string); + virtual void print_response_debug(std::string); + +private: + Tango::DeviceProxy* proxy; + omni_mutex mutex; + unsigned long secs; + unsigned long nanosecs; + static const char NAK = 0x15; + static const char ENQ = 0x5; + static const char LF = 0xA; + static const char CR = 0xD; +}; + +} + +#endif /* TPG300PROXY_H_ */ diff --git a/src/Tpg300SPManager.cpp b/src/Tpg300SPManager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6af6725d8560d91d61087c12b2c8446ff624691f --- /dev/null +++ b/src/Tpg300SPManager.cpp @@ -0,0 +1,211 @@ +/* + * Tpg300SetPoint.cpp + * + * Created on: Jun 12, 2012 + * Author: mdm + */ + +#include <cmath> +#include "Tpg300SPManager.h" +#include "Tpg300Utils.h" +#include "Tpg300Proxy.h" +#include "ThreadGuard.h" + +namespace Tpg300_ns +{ + +//-------------------------------------------------------- +// Tpg300SetPoint::Tpg300SetPoint() +//-------------------------------------------------------- +Tpg300SPManager::Tpg300SPManager(Tpg300Proxy* p) : + proxy(p) +{ + valid = false; + trace = "Not yet initialized"; +} + +//-------------------------------------------------------- +// Tpg300SPManager::update_setpoints() +//-------------------------------------------------------- +void Tpg300SPManager::update() +{ + ThreadGuard lock(mutex); + + try + { + string result = proxy->write_read("SPS"); + + if(result.size() == 11) + { + setpoints[0] = atoi(&result.at(0)); + setpoints[1] = atoi(&result.at(2)); + setpoints[2] = atoi(&result.at(4)); + setpoints[3] = atoi(&result.at(6)); + setpoints[4] = atoi(&result.at(8)); + setpoints[5] = atoi(&result.at(10)); + + valid = true; + trace = "No exception"; + } + else + { + valid = false; + trace = "Parsing error"; + } + } + catch(Tango::DevFailed &ex) + { + valid = false; + trace = Tpg300Utils::get_trace(ex); + } +} + +//-------------------------------------------------------- +// Tpg300SPManager::get_setpoint_value() +//-------------------------------------------------------- +void Tpg300SPManager::get_setpoint_value(Tango::DevBoolean* attr_SetPointStatus_read, long size) throw(Tango::DevFailed) +{ + ThreadGuard lock(mutex); + + if(size != SETPOINT_SIZE) + Tango::Except::throw_exception("", "Attribute wrong size", "get_setpoint_value"); + + if(!valid) + Tango::Except::throw_exception("", trace, "get_setpoint_value"); + + for(unsigned int i=0; i<SETPOINT_SIZE; i++) + attr_SetPointStatus_read[i] = setpoints[i]; + +} + +//-------------------------------------------------------- +// Tpg300SPManager::get_lower_threshold() +//-------------------------------------------------------- +Tango::DevDouble Tpg300SPManager::get_lower_threshold(SetPoint setpoint) throw(Tango::DevFailed) +{ + SetPointConf conf = get_setpoint_conf(setpoint); + + return conf.lower_threshold; +} + +//-------------------------------------------------------- +// Tpg300SPManager::set_lower_threshold() +//-------------------------------------------------------- +void Tpg300SPManager::set_lower_threshold(SetPoint setpoint, Tango::DevDouble lower_threshold) throw(Tango::DevFailed) +{ + SetPointConf conf = get_setpoint_conf(setpoint); + + conf.lower_threshold = lower_threshold; + + set_setpoint_conf(setpoint, conf); +} + +//-------------------------------------------------------- +// Tpg300SPManager::get_upper_threshold() +//-------------------------------------------------------- +Tango::DevDouble Tpg300SPManager::get_upper_threshold(SetPoint setpoint) throw(Tango::DevFailed) +{ + SetPointConf conf = get_setpoint_conf(setpoint); + + return conf.upper_threshold; +} + +//-------------------------------------------------------- +// Tpg300SPManager::set_upper_threshold() +//-------------------------------------------------------- +void Tpg300SPManager::set_upper_threshold(SetPoint setpoint, Tango::DevDouble upper_threshold) throw(Tango::DevFailed) +{ + SetPointConf conf = get_setpoint_conf(setpoint); + + conf.upper_threshold = upper_threshold; + + set_setpoint_conf(setpoint, conf); +} + +//-------------------------------------------------------- +// Tpg300SPManager::get_source() +//-------------------------------------------------------- +Tango::DevShort Tpg300SPManager::get_source(SetPoint setpoint) throw(Tango::DevFailed) +{ + SetPointConf conf = get_setpoint_conf(setpoint); + + return conf.source; +} + +//-------------------------------------------------------- +// Tpg300SPManager::set_source() +//-------------------------------------------------------- +void Tpg300SPManager::set_source(SetPoint setpoint, Tango::DevShort source) throw(Tango::DevFailed) +{ + SetPointConf conf = get_setpoint_conf(setpoint); + + conf.source = source; + + set_setpoint_conf(setpoint, conf); +} + +//======================================================== +// Utilities methods +//======================================================== + +//-------------------------------------------------------- +// Tpg300SPManager::get_setpoint_conf() +//-------------------------------------------------------- +Tpg300SPManager::SetPointConf Tpg300SPManager::get_setpoint_conf(SetPoint setpoint) +{ + stringstream command_str; + command_str << "SP" << char(setpoint); + + string result = proxy->write_read(command_str.str()); + + size_t point_1_pos = result.find_first_of(POINT); + size_t point_2_pos = result.find_last_of(POINT); + + if(point_1_pos == string::npos || point_2_pos == string::npos) + Tango::Except::throw_exception("", "Parsing error", "get_setpoint_conf"); + + SetPointConf conf; + + conf.lower_threshold = strtod(result.substr(0, point_1_pos).c_str(), 0); + + size_t sub_str_len = point_2_pos - point_1_pos - 1; + conf.upper_threshold = strtod(result.substr(point_1_pos+1, sub_str_len).c_str(), 0); + + conf.source = atoi(result.substr(point_2_pos+1).c_str()); + + return conf; +} + +//-------------------------------------------------------- +// Tpg300SPManager::set_setpoint_conf() +//-------------------------------------------------------- +void Tpg300SPManager::set_setpoint_conf(SetPoint setpoint, Tpg300SPManager::SetPointConf conf) +{ + int l_exp = 0; + double l_thres = convert(conf.lower_threshold, l_exp); + + int u_exp = 0; + double u_thres = convert(conf.upper_threshold, u_exp); + + stringstream command_str; + command_str.precision(1); + + command_str << "SP" << char(setpoint) << "," + << fixed << l_thres << "E" << l_exp << "," + << fixed << u_thres << "E" << u_exp << "," + << dec << conf.source << endl; + + proxy->write_read(command_str.str()); +} + +//-------------------------------------------------------- +// Tpg300SPManager::convert() +//-------------------------------------------------------- +double Tpg300SPManager::convert(double value, int& n) +{ + n = floor( log10(value) ); + + return value * pow(10.0, -n); +} + +} diff --git a/src/Tpg300SPManager.h b/src/Tpg300SPManager.h new file mode 100644 index 0000000000000000000000000000000000000000..4c790aea271404a979bddffafcfa62065ac63d52 --- /dev/null +++ b/src/Tpg300SPManager.h @@ -0,0 +1,66 @@ +/* + * Tpg300SPManager.h + * + * Created on: Jun 12, 2012 + * Author: mdm + */ + +#ifndef TPG300SPMANAGER_H_ +#define TPG300SPMANAGER_H_ + +#include <tango.h> +#include <Tpg300Task.h> + +#define SETPOINT_SIZE 6 +#define POINT 0x2C + +namespace Tpg300_ns +{ + +class Tpg300Proxy; + +class Tpg300SPManager : public Tpg300Task +{ +public: + enum SetPoint{SETPOINT_0 = '1', SETPOINT_1 = '2', SETPOINT_2 = '3', + SETPOINT_3 = '4', SETPOINT_A = 'A', SETPOINT_B = 'B'}; + +protected: + struct SetPointConf + { + Tango::DevDouble lower_threshold; + Tango::DevDouble upper_threshold; + Tango::DevShort source; + }; + +public: + Tpg300SPManager(Tpg300Proxy*); + virtual ~Tpg300SPManager() {}; + +public: + virtual void update(); + virtual void get_setpoint_value(Tango::DevBoolean*, long) throw(Tango::DevFailed); + virtual Tango::DevDouble get_lower_threshold(SetPoint) throw(Tango::DevFailed); + virtual void set_lower_threshold(SetPoint, Tango::DevDouble) throw(Tango::DevFailed); + virtual Tango::DevDouble get_upper_threshold(SetPoint) throw(Tango::DevFailed); + virtual void set_upper_threshold(SetPoint, Tango::DevDouble) throw(Tango::DevFailed); + virtual Tango::DevShort get_source(SetPoint) throw(Tango::DevFailed); + virtual void set_source(SetPoint, Tango::DevShort) throw(Tango::DevFailed); + +protected: + virtual SetPointConf get_setpoint_conf(SetPoint); + virtual void set_setpoint_conf(SetPoint, SetPointConf); + virtual double convert(double, int &); + +private: + Tpg300Proxy* proxy; + omni_mutex mutex; + bool valid; + std::string trace; + bool setpoints[SETPOINT_SIZE]; + +}; + +} + +#endif /* TPG300SETPOINT_H_ */ diff --git a/src/Tpg300StateMachine.cpp b/src/Tpg300StateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4afb61099b54002dffc8ab603215eafa860fef56 --- /dev/null +++ b/src/Tpg300StateMachine.cpp @@ -0,0 +1,743 @@ +/*----- PROTECTED REGION ID(Tpg300StateMachine.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: Tpg300StateMachine.cpp,v 1.5 2013-06-05 14:59:10 lorenzo Exp $"; +//============================================================================= +// +// file : Tpg300StateMachine.cpp +// +// description : C++ source for the �name� and its alowed +// methods for commands and attributes +// +// project : Blzer Tpg 300. +// +// $Author: lorenzo $ +// +// $Revision: 1.5 $ +// $Date: 2013-06-05 14:59:10 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/Tpg300StateMachine.cpp,v $ +// $Log: Tpg300StateMachine.cpp,v $ +// Revision 1.5 2013-06-05 14:59:10 lorenzo +// Tango 8.0.5 +// +// Revision 1.4 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + + +#include <Tpg300.h> +#include <Tpg300Class.h> +#include "Tpg300Channel.h" + +/*----- PROTECTED REGION END -----*/ + + +/* + * Tpg300 states description: + * + * ON : + * OFF : + * ALARM : + * FAULT : + */ + +namespace Tpg300_ns +{ + +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Pressure_0State_allowed() + * Description : Execution allowed for Pressure_0 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Pressure_0_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Pressure_0 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_0StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + if(channel_0->get_state() == Tango::FAULT) + return false; + + if(channel_0->get_state() == Tango::UNKNOWN) + return false; + + if(channel_0->get_state() == Tango::DISABLE) + return false; + + if(channel_0->get_state() == Tango::OFF) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_0StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Pressure_1State_allowed() + * Description : Execution allowed for Pressure_1 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Pressure_1_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Pressure_1 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_1StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + if(channel_1->get_state() == Tango::FAULT) + return false; + + if(channel_1->get_state() == Tango::UNKNOWN) + return false; + + if(channel_1->get_state() == Tango::DISABLE) + return false; + + if(channel_1->get_state() == Tango::OFF) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_1StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Pressure_2State_allowed() + * Description : Execution allowed for Pressure_2 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Pressure_2_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Pressure_2 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_2StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + if(channel_2->get_state() == Tango::FAULT) + return false; + + if(channel_2->get_state() == Tango::UNKNOWN) + return false; + + if(channel_2->get_state() == Tango::DISABLE) + return false; + + if(channel_2->get_state() == Tango::OFF) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_2StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Pressure_3State_allowed() + * Description : Execution allowed for Pressure_3 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Pressure_3_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Pressure_3 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Pressure_3StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + if(channel_3->get_state() == Tango::FAULT) + return false; + + if(channel_3->get_state() == Tango::UNKNOWN) + return false; + + if(channel_3->get_state() == Tango::DISABLE) + return false; + + if(channel_3->get_state() == Tango::OFF) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Pressure_3StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_State_0State_allowed() + * Description : Execution allowed for State_0 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_State_0_allowed(Tango::AttReqType type) +{ + // Not any excluded states for State_0 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_State_0StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_0StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_State_1State_allowed() + * Description : Execution allowed for State_1 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_State_1_allowed(Tango::AttReqType type) +{ + // Not any excluded states for State_1 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_State_1StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_1StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_State_2State_allowed() + * Description : Execution allowed for State_2 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_State_2_allowed(Tango::AttReqType type) +{ + // Not any excluded states for State_2 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_State_2StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_2StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_State_3State_allowed() + * Description : Execution allowed for State_3 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_State_3_allowed(Tango::AttReqType type) +{ + // Not any excluded states for State_3 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_State_3StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_State_3StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Status_0State_allowed() + * Description : Execution allowed for Status_0 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Status_0_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Status_0 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Status_0StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_0StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Status_1State_allowed() + * Description : Execution allowed for Status_1 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Status_1_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Status_1 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Status_1StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_1StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Status_2State_allowed() + * Description : Execution allowed for Status_2 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Status_2_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Status_2 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Status_2StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_2StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Status_3State_allowed() + * Description : Execution allowed for Status_3 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Status_3_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Status_3 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Status_3StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Status_3StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Name_0State_allowed() + * Description : Execution allowed for Name_0 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Name_0_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Name_0 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Name_0StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_0StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Name_1State_allowed() + * Description : Execution allowed for Name_1 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Name_1_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Name_1 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Name_1StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_1StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Name_2State_allowed() + * Description : Execution allowed for Name_2 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Name_2_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Name_2 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Name_2StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_2StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_Name_3State_allowed() + * Description : Execution allowed for Name_3 attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_Name_3_allowed(Tango::AttReqType type) +{ + // Not any excluded states for Name_3 attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_Name_3StateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_Name_3StateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_DeviceStateState_allowed() + * Description : Execution allowed for DeviceState attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_DeviceState_allowed(Tango::AttReqType type) +{ + // Check if access type. + if ( type!=Tango::READ_REQ ) + { + // Not any excluded states for DeviceState attribute in WRITE access. + + /*----- PROTECTED REGION ID(Tpg300::DeviceStateStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::DeviceStateStateAllowed_WRITE + + return true; + } + else + // Not any excluded states for DeviceState attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_DeviceStateStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_DeviceStateStateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_DeviceStatusState_allowed() + * Description : Execution allowed for DeviceStatus attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_DeviceStatus_allowed(Tango::AttReqType type) +{ + // Not any excluded states for DeviceStatus attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_DeviceStatusStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_DeviceStatusStateAllowed_READ + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_SetPointStatusState_allowed() + * Description : Execution allowed for SetPointStatus attribute. + */ +//-------------------------------------------------------- + +bool Tpg300::is_SetPointStatus_allowed(Tango::AttReqType type) +{ + // Not any excluded states for SetPointStatus attribute in READ access. + + /*----- PROTECTED REGION ID(Tpg300::read_SetPointStatusStateAllowed_READ) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::read_SetPointStatusStateAllowed_READ + + return true; +} + + + /*----- PROTECTED REGION ID(Tpg300::are_dynamic_attributes_allowed) ENABLED START -----*/ + + // Add your code to check if dynamic attributes are alowed + + /*----- PROTECTED REGION END -----*/ // Tpg300::are_dynamic_attributes_allowed + + +//================================================= +// Commands Allowed Methods +//================================================= + + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_SensorOnState_allowed() + * Description : Execution allowed for SensorOn command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_SensorOn_allowed(const CORBA::Any &any) +{ + // Not any excluded states for SensorOn command. + + /*----- PROTECTED REGION ID(Tpg300::SensorOnStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::SensorOnStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_SensorOffState_allowed() + * Description : Execution allowed for SensorOff command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_SensorOff_allowed(const CORBA::Any &any) +{ + // Not any excluded states for SensorOff command. + + /*----- PROTECTED REGION ID(Tpg300::SensorOffStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::SensorOffStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_WriteLowerThresholdState_allowed() + * Description : Execution allowed for WriteLowerThreshold command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_WriteLowerThreshold_allowed(const CORBA::Any &any) +{ + // Not any excluded states for WriteLowerThreshold command. + + /*----- PROTECTED REGION ID(Tpg300::WriteLowerThresholdStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::WriteLowerThresholdStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_ReadLowerThresholdState_allowed() + * Description : Execution allowed for ReadLowerThreshold command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_ReadLowerThreshold_allowed(const CORBA::Any &any) +{ + // Not any excluded states for ReadLowerThreshold command. + + /*----- PROTECTED REGION ID(Tpg300::ReadLowerThresholdStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::ReadLowerThresholdStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_WriteUpperThresholdState_allowed() + * Description : Execution allowed for WriteUpperThreshold command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_WriteUpperThreshold_allowed(const CORBA::Any &any) +{ + // Not any excluded states for WriteUpperThreshold command. + + /*----- PROTECTED REGION ID(Tpg300::WriteUpperThresholdStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::WriteUpperThresholdStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_ReadUpperThresholdState_allowed() + * Description : Execution allowed for ReadUpperThreshold command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_ReadUpperThreshold_allowed(const CORBA::Any &any) +{ + // Not any excluded states for ReadUpperThreshold command. + + /*----- PROTECTED REGION ID(Tpg300::ReadUpperThresholdStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::ReadUpperThresholdStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_ReadSensorSourceState_allowed() + * Description : Execution allowed for ReadSensorSource command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_ReadSensorSource_allowed(const CORBA::Any &any) +{ + // Not any excluded states for ReadSensorSource command. + + /*----- PROTECTED REGION ID(Tpg300::ReadSensorSourceStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::ReadSensorSourceStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_WriteSensorSourceState_allowed() + * Description : Execution allowed for WriteSensorSource command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_WriteSensorSource_allowed(const CORBA::Any &any) +{ + // Not any excluded states for WriteSensorSource command. + + /*----- PROTECTED REGION ID(Tpg300::WriteSensorSourceStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::WriteSensorSourceStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_RegisterNameState_allowed() + * Description : Execution allowed for RegisterName command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_RegisterName_allowed(const CORBA::Any &any) +{ + // Not any excluded states for RegisterName command. + + /*----- PROTECTED REGION ID(Tpg300::RegisterNameStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::RegisterNameStateAllowed + + return true; +} + +//-------------------------------------------------------- +/** + * Method : Tpg300::is_UnregisterNameState_allowed() + * Description : Execution allowed for UnregisterName command. + */ +//-------------------------------------------------------- + +bool Tpg300::is_UnregisterName_allowed(const CORBA::Any &any) +{ + // Not any excluded states for UnregisterName command. + + /*----- PROTECTED REGION ID(Tpg300::UnregisterNameStateAllowed) ENABLED START -----*/ + + if(!init_completed) + return false; + + /*----- PROTECTED REGION END -----*/ // Tpg300::UnregisterNameStateAllowed + + return true; +} + + + /*----- PROTECTED REGION ID(Tpg300::are_dynamic_commands_allowed) ENABLED START -----*/ + + // Add your code to check if dynamic commands are alowed + + /*----- PROTECTED REGION END -----*/ // Tpg300::are_dynamic_commands_allowed + +} // namespace Tpg300_ns diff --git a/src/Tpg300Task.h b/src/Tpg300Task.h new file mode 100644 index 0000000000000000000000000000000000000000..3f6c1336bdc9b53e2b86975d522e3253aeb42cc3 --- /dev/null +++ b/src/Tpg300Task.h @@ -0,0 +1,27 @@ +/* + * Tpg300Task.h + * + * Created on: Jul 17, 2012 + * Author: mdm + */ + +#ifndef TPG300TASK_H_ +#define TPG300TASK_H_ + +#define SETPOINT_SIZE 6 +#define POINT 0x2C + +namespace Tpg300_ns +{ + +class Tpg300Task { + +public: + virtual ~Tpg300Task() {}; + virtual void update() = 0; + +}; + +} + +#endif /* TPG300TASK_H_ */ diff --git a/src/Tpg300Thread.cpp b/src/Tpg300Thread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e4a716fe99c052947596ad64940725c46e381366 --- /dev/null +++ b/src/Tpg300Thread.cpp @@ -0,0 +1,89 @@ +/* + * Tpg300Thread.cpp + * + * Created on: May 22, 2012 + * Author: mdm + */ + +#include <Tpg300Thread.h> +#include <Tpg300Channel.h> +#include <Tpg300SPManager.h> +#include <Tpg300Task.h> + +namespace Tpg300_ns +{ + +//-------------------------------------------------------- +// Tpg300Thread::Tpg300Thread() +//-------------------------------------------------------- +Tpg300Thread::Tpg300Thread(std::vector<Tpg300Task *> task, + Tango::DevULong msec, omni_condition* stop): + task_vector(task), stop_condition(stop) +{ + abort = false; + + sleep_sec = msec/1000; + + sleep_nsec = (msec%1000)*1000000; + + condition_mutex = new omni_mutex(); + + condition_var = new omni_condition(condition_mutex); + + start(); +} + +//-------------------------------------------------------- +// Tpg300Thread::kill_thread() +//-------------------------------------------------------- +void Tpg300Thread::kill_thread() +{ + abort = true; + + condition_var->signal(); +} + +//-------------------------------------------------------- +// Tpg300Thread::~Tpg300Thread() +//-------------------------------------------------------- +Tpg300Thread::~Tpg300Thread() +{ + delete condition_mutex; + + delete condition_var; +} + +//-------------------------------------------------------- +// Tpg300Thread::run() +//-------------------------------------------------------- +void Tpg300Thread::run(void*) +{ + vector<Tpg300Task *>::const_iterator it = task_vector.begin(); + + while(!abort) + { + (*it)->update(); + + if(++it == task_vector.end()) + it=task_vector.begin(); + + sleep(); + } + + stop_condition->signal(); +} + +//-------------------------------------------------------- +// Tpg300Thread::sleep() +//-------------------------------------------------------- +void Tpg300Thread::sleep() +{ + unsigned long sec; + unsigned long nsec; + + omni_thread::get_time(&sec, &nsec, sleep_sec, sleep_nsec); + + condition_var->timedwait(sec, nsec); +} + +} diff --git a/src/Tpg300Thread.h b/src/Tpg300Thread.h new file mode 100644 index 0000000000000000000000000000000000000000..6aa62d213699a7d1731614735ae7f4c3143d24c1 --- /dev/null +++ b/src/Tpg300Thread.h @@ -0,0 +1,44 @@ +/* + * Tpg300Thread.h + * + * Created on: May 22, 2012 + * Author: mdm + */ + +#ifndef SAMPLINGTHREAD_H_ +#define SAMPLINGTHREAD_H_ + +#include <tango.h> +#include <omnithread.h> + +namespace Tpg300_ns +{ + +class Tpg300Channel; +class Tpg300SPManager; +class Tpg300Task; + +class Tpg300Thread : public omni_thread +{ +public: + Tpg300Thread(std::vector<Tpg300Task *>, Tango::DevULong, omni_condition*); + virtual void kill_thread(); + +protected: + virtual ~Tpg300Thread(); + virtual void run(void *); + virtual void sleep(); + +private: + const std::vector<Tpg300Task *> task_vector; + omni_condition* stop_condition; + bool abort; + unsigned long sleep_sec; + unsigned long sleep_nsec; + omni_mutex* condition_mutex; + omni_condition* condition_var; +}; + +} + +#endif /* SAMPLINGTHREAD_H_ */ diff --git a/src/Tpg300Utils.cpp b/src/Tpg300Utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c80417d206e4a47c74906bc40381d2646904f1fb --- /dev/null +++ b/src/Tpg300Utils.cpp @@ -0,0 +1,64 @@ +/* + * Tpg300Utils.cpp + * + * Created on: Jun 12, 2012 + * Author: mdm + */ + +#include "Tpg300Utils.h" + +namespace Tpg300_ns +{ + +//-------------------------------------------------------- +// Tpg300Utils::string_alloc() +//-------------------------------------------------------- +void Tpg300Utils::string_alloc(Tango::DevString* str_pointer) +{ + *str_pointer = new char[STRING_SIZE]; +} + +//-------------------------------------------------------- +// Tpg300Utils::string_free() +//-------------------------------------------------------- +void Tpg300Utils::string_free(Tango::DevString* str_pointer) +{ + delete [] *str_pointer; +} + +//-------------------------------------------------------- +// Tpg300Utils::string_copy() +//-------------------------------------------------------- +void Tpg300Utils::string_copy(Tango::DevString* str_pointer, string status_str) +{ + if(status_str.size()+1 >= STRING_SIZE) + { + delete [] *str_pointer; + *str_pointer = new char[status_str.size()+1]; + } + + strcpy(*str_pointer, status_str.c_str()); +} + +//-------------------------------------------------------- +// Tpg300Utils::get_trace() +//-------------------------------------------------------- +string Tpg300Utils::get_trace(Tango::DevFailed & ex) +{ + std::stringstream error_msg; + + for (unsigned int i=0; i<ex.errors.length(); i++) + { + error_msg << ex.errors[i].reason.in() << endl; + error_msg << ex.errors[i].desc.in() << endl; + error_msg << ex.errors[i].origin.in() << endl; + } + +#ifdef _VERBOSE_DEBUG + cout << " Error: " << error_msg.str() << endl; +#endif + + return error_msg.str(); +} + +} diff --git a/src/Tpg300Utils.h b/src/Tpg300Utils.h new file mode 100644 index 0000000000000000000000000000000000000000..f140c57b57e51e45e64f26fdd7533fd9586a43ac --- /dev/null +++ b/src/Tpg300Utils.h @@ -0,0 +1,31 @@ +/* + * Tpg300Utils.h + * + * Created on: Jun 12, 2012 + * Author: mdm + */ + +#ifndef TPG300UTILS_H_ +#define TPG300UTILS_H_ + +#include <tango.h> + +namespace Tpg300_ns +{ + +class Tpg300Utils { + +public: + static void string_alloc(Tango::DevString *); + static void string_free(Tango::DevString *); + static void string_copy(Tango::DevString *, std::string); + static std::string get_trace(Tango::DevFailed &); + +public: + static const unsigned int STRING_SIZE = 1024; + +}; + +} + +#endif /* TPG300UTILS_H_ */ diff --git a/src/devicestate.h b/src/devicestate.h new file mode 100644 index 0000000000000000000000000000000000000000..b5233dd5511b12275834bc2c716bb472ca3c5ea8 --- /dev/null +++ b/src/devicestate.h @@ -0,0 +1,21 @@ +/* + * devicestate.h + * + * LP - 2013.01.03 + */ + +#ifndef DEVICESTATE_H +#define DEVICESTATE_H + +typedef enum { + UNKNOWN, + ONLINE, + OFFLINE, + SERVICE, + TEST, + DEVICESTATE_T_SIZE +} devicestate_t; + +#endif /* DEVICESTATE_H */ + +/* EOF */ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8781ce1f1602d6a30a5d6b94b59e798d3b2a8727 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,73 @@ +/*PROTECTED REGION ID(Tpg300::main.cpp) ENABLED START*/ +static const char *RcsId = "$Id: main.cpp,v 1.4 2012-09-10 08:01:04 mdm Exp $"; +//============================================================================= +// +// file : Tpg300.cpp +// +// description : C++ source for the Tpg300 device server main. +// The main rule is to initialise (and create) the Tango +// system and to create the DServerClass singleton. +// The main should be the same for every Tango device server. +// +// project : Blzer Tpg 300. +// +// $Author: mdm $ +// +// $Revision: 1.4 $ +// $Date: 2012-09-10 08:01:04 $ +// +// SVN only: +// $HeadURL: $ +// +// CVS only: +// $Source: /home/cvsadm/cvsroot/fermi/servers/tpg300/src/main.cpp,v $ +// $Log: main.cpp,v $ +// Revision 1.4 2012-09-10 08:01:04 mdm +// Bugfix in thread and on off commands +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include <tango.h> + + +int main(int argc,char *argv[]) +{ + Tango::Util *tg = NULL; + try + { + // Initialise the device server + //---------------------------------------- + tg = Tango::Util::init(argc,argv); + + // Create the device server singleton + // which will create everything + //---------------------------------------- + tg->server_init(false); + + // Run the endless loop + //---------------------------------------- + cout << "Ready to accept request" << endl; + tg->server_run(); + } + catch (bad_alloc) + { + cout << "Can't allocate memory to store device object !!!" << endl; + cout << "Exiting" << endl; + } + catch (CORBA::Exception &e) + { + Tango::Except::print_exception(e); + + cout << "Received a CORBA_Exception" << endl; + cout << "Exiting" << endl; + } + if (tg!=NULL) + tg->server_cleanup(); + return(0); +} +/*PROTECTED REGION END*/ +//========================================================