Commit f63d1cd3 authored by Roberto Borghes's avatar Roberto Borghes
Browse files

First Import from CVS repository

parent 8c678e11
# exclude binaries
bin/*
#exclude objects
obj/*
.nse_depinfo
NAME_SRV = wagoadc-srv
CXXFLAGS =
LDFLAGS =
include ../makefiles/Make-9.3.3.in
/*----- PROTECTED REGION ID(Wagoadc::ClassFactory.cpp) ENABLED START -----*/
static const char *RcsId = "$Id: ClassFactory.cpp,v 1.1.1.1 2010/10/20 13:45:35 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 : TANGO Device Server
//
// $Author: mdm $
//
// $Revision: 1.1.1.1 $
// $Date: 2010/10/20 13:45:35 $
//
// SVN only:
// $HeadURL: $
//
// CVS only:
// $Source: /home/cvsadm/cvsroot/fermi/servers/wagoadc/src/ClassFactory.cpp,v $
// $Log: ClassFactory.cpp,v $
// Revision 1.1.1.1 2010/10/20 13:45:35 mdm
// first import
//
//
// copyleft : European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
//-=============================================================================
//
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//
// (c) - Software Engineering Group - ESRF
//=============================================================================
#include <tango.h>
#include <WagoadcClass.h>
/**
* Create WagoadcClass singleton and store it in DServer object.
*/
void Tango::DServer::class_factory()
{
add_class(Wagoadc_ns::WagoadcClass::init("Wagoadc"));
}
/*----- PROTECTED REGION END -----*/
#PROTECTED REGION ID(Wagoadc::Makefile) ENABLED START#
#=============================================================================
#
# file : Makefile
#
# description : Makefile to generate a TANGO device server.
#
# project : Wago ADC
#
# $Author: $
#
# $Revision: $
#
# $Log: $
#
#=============================================================================
# This file is generated by POGO
# (Program Obviously used to Generate tango Object)
#=============================================================================
#
#
#=============================================================================
# MAKE_ENV is the path to find common environment to buil project
#
MAKE_ENV = /usr/local/tango-7.2.6/share/pogo/preferences
#=============================================================================
# PACKAGE_NAME is the name of the library/device/exe you want to build
#
PACKAGE_NAME = Wagoadc
MAJOR_VERS = 1
MINOR_VERS = 0
RELEASE = Release_$(MAJOR_VERS)_$(MINOR_VERS)
# #=============================================================================
# # RELEASE_TYPE
# # - DEBUG : debug symbols - no optimization
# # - OPTIMIZED : no debug symbols - optimization level set to O2
# #-----------------------------------------------------------------------------
RELEASE_TYPE = DEBUG
#=============================================================================
# OUTPUT_TYPE can be one of the following :
# - 'STATIC_LIB' for a static library (.a)
# - 'SHARED_LIB' for a dynamic library (.so)
# - 'DEVICE' for a device server (will automatically include and link
# with Tango dependencies)
# - 'SIMPLE_EXE' for an executable with no dependency (for exemple the test tool
# of a library with no Tango dependencies)
#
OUTPUT_TYPE = DEVICE
#=============================================================================
# OUTPUT_DIR is the directory which contains the build result.
# if not set, the standard location is :
# - $HOME/DeviceServers if OUTPUT_TYPE is DEVICE
# - ../bin for others
#
OUTPUT_DIR = ./bin/$(BIN_DIR)
#=============================================================================
# INC_DIR_USER is the list of all include path needed by your sources
# - for a device server, tango dependencies are automatically appended
# - '-I ../include' and '-I .' are automatically appended in all cases
#
#
INC_DIR_USER= -I .
#=============================================================================
# LIB_DIR_USER is the list of user library directories
# - for a device server, tango libraries directories are automatically appended
# - '-L ../lib' is automatically appended in all cases
#
LIB_DIR_USER=
#=============================================================================
# LFLAGS_USR is the list of user link flags
# - for a device server, tango libraries directories are automatically appended
# - '-ldl -lpthread' is automatically appended in all cases
#
# !!! ATTENTION !!!
# Be aware that the order matters.
# For example if you must link with libA, and if libA depends itself on libB
# you must use '-lA -lB' in this order as link flags, otherwise you will get
# 'undefined reference' errors
#
#LFLAGS_USR+=
#=============================================================================
# CXXFLAGS_USR lists the compilation flags specific for your library/device/exe
# This is the place where to put your compile-time macros using '-Dmy_macro'
#
# -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ for ACE
#
#CXXFLAGS_USR+= -Wall
#=============================================================================
# TANGO_REQUIRED
# - TRUE : your project depends on TANGO
# - FALSE : your project does not depend on TANGO
#-----------------------------------------------------------------------------
# - NOTE : if PROJECT_TYPE is set to DEVICE, TANGO will be auto. added
#-----------------------------------------------------------------------------
TANGO_REQUIRED = TRUE
#=============================================================================
# include Standard TANGO compilation options
#
include $(MAKE_ENV)/tango.opt
#=============================================================================
# POST_PROCESSING: action to be done after normal make.
# e.g.: change executable file name, .....
#POST_PROCESSING = \
# mv bin/$(BIN_DIR)/$(PACKAGE_NAME) bin/$(BIN_DIR)/$(PACKAGE_NAME)_DS
#=============================================================================
# SVC_OBJS is the list of all objects needed to make the output
#
SVC_INCL = $(PACKAGE_NAME).h $(PACKAGE_NAME)Class.h
SVC_OBJS = \
$(OBJDIR)/$(PACKAGE_NAME).o \
$(OBJDIR)/$(PACKAGE_NAME)Class.o \
$(OBJDIR)/$(PACKAGE_NAME)StateMachine.o \
$(OBJDIR)/ClassFactory.o \
$(OBJDIR)/main.o \
$(ADDITIONAL_OBJS)
#------------ Object files for additional files ------------
ADDITIONAL_OBJS =
#=============================================================================
# include common targets
#
include $(MAKE_ENV)/common_target.opt
#PROTECTED REGION END#
#PROTECTED REGION ID(Wagoadc::Makefile) ENABLED START#
#=============================================================================
#
# file : Makefile
#
# description : Makefile to generate a TANGO device server.
#
# project : Wago ADC
#
# $Author: $
#
# $Revision: $
#
# $Log: $
#
#=============================================================================
# This file is generated by POGO
# (Program Obviously used to Generate tango Object)
#=============================================================================
#
#
#=============================================================================
# MAKE_ENV is the path to find common environment to buil project
#
MAKE_ENV = /usr/local/tango-7.2.6/share/pogo/preferences
#=============================================================================
# PACKAGE_NAME is the name of the library/device/exe you want to build
#
PACKAGE_NAME = Wagoadc
MAJOR_VERS = 1
MINOR_VERS = 0
RELEASE = Release_$(MAJOR_VERS)_$(MINOR_VERS)
# #=============================================================================
# # RELEASE_TYPE
# # - DEBUG : debug symbols - no optimization
# # - OPTIMIZED : no debug symbols - optimization level set to O2
# #-----------------------------------------------------------------------------
RELEASE_TYPE = DEBUG
#=============================================================================
# OUTPUT_TYPE can be one of the following :
# - 'STATIC_LIB' for a static library (.a)
# - 'SHARED_LIB' for a dynamic library (.so)
# - 'DEVICE' for a device server (will automatically include and link
# with Tango dependencies)
# - 'SIMPLE_EXE' for an executable with no dependency (for exemple the test tool
# of a library with no Tango dependencies)
#
OUTPUT_TYPE = DEVICE
#=============================================================================
# OUTPUT_DIR is the directory which contains the build result.
# if not set, the standard location is :
# - $HOME/DeviceServers if OUTPUT_TYPE is DEVICE
# - ../bin for others
#
OUTPUT_DIR = ./bin/$(BIN_DIR)
#=============================================================================
# INC_DIR_USER is the list of all include path needed by your sources
# - for a device server, tango dependencies are automatically appended
# - '-I ../include' and '-I .' are automatically appended in all cases
#
#
INC_DIR_USER= -I .
#=============================================================================
# LIB_DIR_USER is the list of user library directories
# - for a device server, tango libraries directories are automatically appended
# - '-L ../lib' is automatically appended in all cases
#
LIB_DIR_USER=
#=============================================================================
# LFLAGS_USR is the list of user link flags
# - for a device server, tango libraries directories are automatically appended
# - '-ldl -lpthread' is automatically appended in all cases
#
# !!! ATTENTION !!!
# Be aware that the order matters.
# For example if you must link with libA, and if libA depends itself on libB
# you must use '-lA -lB' in this order as link flags, otherwise you will get
# 'undefined reference' errors
#
#LFLAGS_USR+=
#=============================================================================
# CXXFLAGS_USR lists the compilation flags specific for your library/device/exe
# This is the place where to put your compile-time macros using '-Dmy_macro'
#
# -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ for ACE
#
#CXXFLAGS_USR+= -Wall
#=============================================================================
# TANGO_REQUIRED
# - TRUE : your project depends on TANGO
# - FALSE : your project does not depend on TANGO
#-----------------------------------------------------------------------------
# - NOTE : if PROJECT_TYPE is set to DEVICE, TANGO will be auto. added
#-----------------------------------------------------------------------------
TANGO_REQUIRED = TRUE
#=============================================================================
# include Standard TANGO compilation options
#
include $(MAKE_ENV)/tango.opt
#=============================================================================
# POST_PROCESSING: action to be done after normal make.
# e.g.: change executable file name, .....
#POST_PROCESSING = \
# mv bin/$(BIN_DIR)/$(PACKAGE_NAME) bin/$(BIN_DIR)/$(PACKAGE_NAME)_DS
#=============================================================================
# SVC_OBJS is the list of all objects needed to make the output
#
SVC_INCL = $(PACKAGE_NAME).h $(PACKAGE_NAME)Class.h
SVC_OBJS = \
$(OBJDIR)/$(PACKAGE_NAME).o \
$(OBJDIR)/$(PACKAGE_NAME)Class.o \
$(OBJDIR)/$(PACKAGE_NAME)StateMachine.o \
$(OBJDIR)/ClassFactory.o \
$(OBJDIR)/main.o \
$(ADDITIONAL_OBJS)
#------------ Object files for additional files ------------
ADDITIONAL_OBJS =
#=============================================================================
# include common targets
#
include $(MAKE_ENV)/common_target.opt
#PROTECTED REGION END#
/**
* Device Class Identification:
*
* Class Name : Wagoadc
* Contact : marco.demarco@elettra.trieste.it
* Class Family : InputOutput
* Platform : Unix Like
* Bus : Modbus
* Manufacturer : Wago
* Reference : all wago adc modules
*/
/*----- PROTECTED REGION ID(Wagoadc.cpp) ENABLED START -----*/
static const char *RcsId = "$Id: $";
//=============================================================================
//
// file : Wagoadc.cpp
//
// description : C++ source for the Wagoadc 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
// Wagoadc are implemented in this file.
//
// project : Wago ADC.
//
// $Author: $
//
// $Revision: $
// $Date: $
//
// SVN only:
// $HeadURL: $
//
// CVS only:
// $Source: $
// $Log: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango.h>
#include <Wagoadc.h>
#include <WagoadcClass.h>
/*----- PROTECTED REGION END -----*/
/**
* Wagoadc class description:
* Server for all wago adc modules
*/
//================================================================
//
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//----------------------------------------------------------------
// State | Inherited (no method)
// Status | Inherited (no method)
//================================================================
namespace Wagoadc_ns
{
/*----- PROTECTED REGION ID(Wagoadc::namespace_starting) ENABLED START -----*/
// static initializations
/*----- PROTECTED REGION END -----*/ // Wagoadc::namespace_starting
//--------------------------------------------------------
/**
* Method : Wagoadc::Wagoadc()
* Description : Constructors for a Tango device
* implementing the class Wagoadc
*/
//--------------------------------------------------------
Wagoadc::Wagoadc(Tango::DeviceClass *cl, string &s)
: Tango::Device_4Impl(cl, s.c_str())
{
/*----- PROTECTED REGION ID(Wagoadc::constructor_1) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // Wagoadc::constructor_1
}
//--------------------------------------------------------
Wagoadc::Wagoadc(Tango::DeviceClass *cl, const char *s)
: Tango::Device_4Impl(cl, s)
{
/*----- PROTECTED REGION ID(Wagoadc::constructor_2) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // Wagoadc::constructor_2
}
//--------------------------------------------------------
Wagoadc::Wagoadc(Tango::DeviceClass *cl, const char *s, const char *d)
: Tango::Device_4Impl(cl, s, d)
{
/*----- PROTECTED REGION ID(Wagoadc::constructor_3) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // Wagoadc::constructor_3
}
//--------------------------------------------------------
/**
* Method : Wagoadc::delete_device()()
* Description : will be called at device destruction or at init command
*/
//--------------------------------------------------------
void Wagoadc::delete_device()
{
/*----- PROTECTED REGION ID(Wagoadc::delete_device) ENABLED START -----*/
// Delete device allocated objects
if(attr_AnalogInput_read)
{
delete attr_AnalogInput_read;
attr_AnalogInput_read = 0;
}
if(device_proxy)
{
delete device_proxy;
device_proxy = 0;
}
/*----- PROTECTED REGION END -----*/ // Wagoadc::delete_device
}
//--------------------------------------------------------
/**
* Method : Wagoadc::init_device()
* Description : // will be called at device initialization.
*/
//--------------------------------------------------------
void Wagoadc::init_device()
{
DEBUG_STREAM << "Wagoadc::init_device() create device " << device_name << endl;
/*----- PROTECTED REGION ID(Wagoadc::init_device_before) ENABLED START -----*/
// Initialization before get_device_property() call
attr_AnalogInput_read = new Tango::DevFloat();
*attr_AnalogInput_read = 0.0;
/*----- PROTECTED REGION END -----*/ // Wagoadc::init_device_before
// Get the device properties (if any) from database
get_device_property();
/*----- PROTECTED REGION ID(Wagoadc::init_device) ENABLED START -----*/
// Initialize device
if(modbus_server.empty())
{
Tango::Except::throw_exception((const char *)"Wagoadc::error_init",
(const char *)"Modbus_server property must be defined",
(const char *)"Wagoadc::init_device");
}
if(timeout<0 || timeout>10000)
{
timeout = 4000;
DEBUG_STREAM << "Wagoadc::Wagoadc() timeout property not set; default is " << timeout << "ms" << endl;
}
else
{
DEBUG_STREAM << "Wagoadc::Wagoadc() timeout " << timeout << "ms" << endl;
}
try
{
device_proxy = new Tango::DeviceProxy(modbus_server);
device_proxy->set_timeout_millis(timeout);
if(device_proxy->ping())
{
INFO_STREAM << "Wagoadc::Wagoadc() connected to " << modbus_server << endl;
set_state(Tango::ON);
set_status("Connected to " + modbus_server);
}
else
{
WARN_STREAM << "Wagoadc::Wagoadc() cannot connected to " << modbus_server << endl;
set_state(Tango::FAULT);
set_status("connection fault");
}
}
catch(Tango::DevFailed &ex)
{
Tango::DevErrorList list = ex.errors;
Tango::DevError* error = list.get_buffer();
stringstream ex_str;
ex_str << error->desc << " - " << error->origin << endl;
set_state(Tango::FAULT);
set_status(ex_str.str());
}
/*----- PROTECTED REGION END -----*/ // Wagoadc::init_device
}
//--------------------------------------------------------
/**
* Method : Wagoadc::get_device_property()
* Description : Read database to initialize property data members.
*/
//--------------------------------------------------------
void Wagoadc::get_device_property()
{
/*----- PROTECTED REGION ID(Wagoadc::get_device_property_before) ENABLED START -----*/
// Initialize property data members
/*----- PROTECTED REGION END -----*/ // Wagoadc::get_device_property_before
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("M_factor"));
dev_prop.push_back(Tango::DbDatum("Q_factor"));
dev_prop.push_back(Tango::DbDatum("Modbus_server"));
dev_prop.push_back(Tango::DbDatum("Modbus_address"));
dev_prop.push_back(Tango::DbDatum("Timeout"));
// 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 WagoadcClass to get class property
Tango::DbDatum def_prop, cl_prop;
WagoadcClass *ds_class =
(static_cast<WagoadcClass *>(get_device_class()));
int i = -1;
// Try to initialize M_factor from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> m_factor;
else {
// Try to initialize M_factor from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> m_factor;
}
// And try to extract M_factor value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> m_factor;
// Try to initialize Q_factor from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> q_factor;
else {
// Try to initialize Q_factor from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> q_factor;