Skip to content
Snippets Groups Projects
Commit bbebd3e5 authored by Alessio Igor Bogani's avatar Alessio Igor Bogani
Browse files

Move Serial2Client class into a dedicated repository

parent 427745e4
No related branches found
No related tags found
No related merge requests found
/*----- PROTECTED REGION ID(Serial2Client.cpp) ENABLED START -----*/
static const char *RcsId = "$Id: Serial2Client.cpp,v 1.5 2018-07-09 13:58:05 alessio Exp $";
//=============================================================================
//
// file : Serial2Client.cpp
//
// description : C++ source for the Serial2Client class 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
// Serial2Client are implemented in this file.
//
// project :
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Author: alessio $
//
// $Revision: 1.5 $
// $Date: 2018-07-09 13:58:05 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <Serial2Client.h>
#include <Serial2ClientClass.h>
#include <iomanip>
/*----- PROTECTED REGION END -----*/ // Serial2Client.cpp
/**
* Serial2Client class description:
*
*/
//================================================================
// The following table gives the correspondence
// between command and method names.
//
// Command name | Method name
//================================================================
// State | Inherited (no method)
// Status | Inherited (no method)
//================================================================
//================================================================
// Attributes managed is:
//================================================================
//================================================================
namespace Serial2Client_ns
{
/*----- PROTECTED REGION ID(Serial2Client::namespace_starting) ENABLED START -----*/
// static initializations
/*----- PROTECTED REGION END -----*/ // Serial2Client::namespace_starting
//--------------------------------------------------------
/**
* Method : Serial2Client::Serial2Client()
* Description : Constructors for a Tango device
* implementing the classSerial2Client
*/
//--------------------------------------------------------
Serial2Client::Serial2Client(Tango::DeviceClass *cl, string &s)
: TANGO_BASE_CLASS(cl, s.c_str())
{
/*----- PROTECTED REGION ID(Serial2Client::constructor_1) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // Serial2Client::constructor_1
}
//--------------------------------------------------------
Serial2Client::Serial2Client(Tango::DeviceClass *cl, const char *s)
: TANGO_BASE_CLASS(cl, s)
{
/*----- PROTECTED REGION ID(Serial2Client::constructor_2) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // Serial2Client::constructor_2
}
//--------------------------------------------------------
Serial2Client::Serial2Client(Tango::DeviceClass *cl, const char *s, const char *d)
: TANGO_BASE_CLASS(cl, s, d)
{
/*----- PROTECTED REGION ID(Serial2Client::constructor_3) ENABLED START -----*/
init_device();
/*----- PROTECTED REGION END -----*/ // Serial2Client::constructor_3
}
//--------------------------------------------------------
/**
* Method : Serial2Client::delete_device()
* Description : will be called at device destruction or at init command
*/
//--------------------------------------------------------
void Serial2Client::delete_device()
{
DEBUG_STREAM << "Serial2Client::delete_device() " << device_name << endl;
/*----- PROTECTED REGION ID(Serial2Client::delete_device) ENABLED START -----*/
// Delete device allocated objects
if (device_proxy) {
delete device_proxy;
device_proxy = NULL;
}
/*----- PROTECTED REGION END -----*/ // Serial2Client::delete_device
}
//--------------------------------------------------------
/**
* Method : Serial2Client::init_device()
* Description : will be called at device initialization.
*/
//--------------------------------------------------------
void Serial2Client::init_device()
{
DEBUG_STREAM << "Serial2Client::init_device() create device " << device_name << endl;
/*----- PROTECTED REGION ID(Serial2Client::init_device_before) ENABLED START -----*/
// Initialization before get_device_property() call
device_proxy = NULL;
init_error.clear();
/*----- PROTECTED REGION END -----*/ // Serial2Client::init_device_before
// Get the device properties from database
get_device_property();
// No longer if mandatory property not set.
if (mandatoryNotDefined)
return;
/*----- PROTECTED REGION ID(Serial2Client::init_device) ENABLED START -----*/
// Initialize device
try
{
device_proxy = new Tango::DeviceProxy(deviceName);
} catch( Tango::DevFailed &e )
{
init_error = "Initialization failed: " + string(e.errors[0].desc);
}
catch( ... )
{
init_error = "Initialization failed: unknown reason";
}
/*----- PROTECTED REGION END -----*/ // Serial2Client::init_device
}
//--------------------------------------------------------
/**
* Method : Serial2Client::get_device_property()
* Description : Read database to initialize property data members.
*/
//--------------------------------------------------------
void Serial2Client::get_device_property()
{
/*----- PROTECTED REGION ID(Serial2Client::get_device_property_before) ENABLED START -----*/
// Initialize property data members
/*----- PROTECTED REGION END -----*/ // Serial2Client::get_device_property_before
mandatoryNotDefined = false;
// Read device properties from database.
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("DeviceName"));
// 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 Serial2ClientClass to get class property
Tango::DbDatum def_prop, cl_prop;
Serial2ClientClass *ds_class =
(static_cast<Serial2ClientClass *>(get_device_class()));
int i = -1;
// Try to initialize DeviceName from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> deviceName;
else {
// Try to initialize DeviceName from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> deviceName;
}
// And try to extract DeviceName value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> deviceName;
// Property StartDsPath is mandatory, check if has been defined in database.
check_mandatory_property(cl_prop, dev_prop[i]);
}
/*----- PROTECTED REGION ID(Serial2Client::get_device_property_after) ENABLED START -----*/
// Check device property data members init
/*----- PROTECTED REGION END -----*/ // Serial2Client::get_device_property_after
}
//--------------------------------------------------------
/**
* Method : Serial2Client::check_mandatory_property()
* Description : For mandatory properties check if defined in database.
*/
//--------------------------------------------------------
void Serial2Client::check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop)
{
// Check if all properties are empty
if (class_prop.is_empty() && dev_prop.is_empty())
{
TangoSys_OMemStream tms;
tms << endl <<"Property \'" << dev_prop.name;
if (Tango::Util::instance()->_UseDb==true)
tms << "\' is mandatory but not defined in database";
else
tms << "\' is mandatory but cannot be defined without database";
string status(get_status());
status += tms.str();
set_status(status);
mandatoryNotDefined = true;
/*----- PROTECTED REGION ID(Serial2Client::check_mandatory_property) ENABLED START -----*/
cerr << tms.str() << " for " << device_name << endl;
/*----- PROTECTED REGION END -----*/ // Serial2Client::check_mandatory_property
}
}
//--------------------------------------------------------
/**
* Method : Serial2Client::always_executed_hook()
* Description : method always executed before any command is executed
*/
//--------------------------------------------------------
void Serial2Client::always_executed_hook()
{
DEBUG_STREAM << "Serial2Client::always_executed_hook() " << device_name << endl;
if (mandatoryNotDefined)
{
string status(get_status());
Tango::Except::throw_exception(
(const char *)"PROPERTY_NOT_SET",
status.c_str(),
(const char *)"Serial2Client::always_executed_hook()");
}
/*----- PROTECTED REGION ID(Serial2Client::always_executed_hook) ENABLED START -----*/
// code always executed before all requests
if (! init_error.empty()) {
set_state( Tango::FAULT );
set_status( init_error );
}
/*----- PROTECTED REGION END -----*/ // Serial2Client::always_executed_hook
}
//--------------------------------------------------------
/**
* Method : Serial2Client::read_attr_hardware()
* Description : Hardware acquisition for attributes
*/
//--------------------------------------------------------
void Serial2Client::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
{
DEBUG_STREAM << "Serial2Client::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(Serial2Client::read_attr_hardware) ENABLED START -----*/
// Add your own code
check_init();
/*----- PROTECTED REGION END -----*/ // Serial2Client::read_attr_hardware
}
//--------------------------------------------------------
/**
* Method : Serial2Client::add_dynamic_attributes()
* Description : Create the dynamic attributes if any
* for specified device.
*/
//--------------------------------------------------------
void Serial2Client::add_dynamic_attributes()
{
/*----- PROTECTED REGION ID(Serial2Client::add_dynamic_attributes) ENABLED START -----*/
// Add your own code to create and add dynamic attributes if any
/*----- PROTECTED REGION END -----*/ // Serial2Client::add_dynamic_attributes
}
//--------------------------------------------------------
/**
* Method : Serial2Client::add_dynamic_commands()
* Description : Create the dynamic commands if any
* for specified device.
*/
//--------------------------------------------------------
void Serial2Client::add_dynamic_commands()
{
/*----- PROTECTED REGION ID(Serial2Client::add_dynamic_commands) ENABLED START -----*/
// Add your own code to create and add dynamic commands if any
/*----- PROTECTED REGION END -----*/ // Serial2Client::add_dynamic_commands
}
/*----- PROTECTED REGION ID(Serial2Client::namespace_ending) ENABLED START -----*/
// Additional Methods
void Serial2Client::check_init()
{
if (! init_error.empty())
Tango::Except::throw_exception( "",
init_error.c_str(),
"Serial2Client::check_init()");
}
void Serial2Client::write_(const vector<unsigned char> &data_to_write)
{
check_init();
vector<unsigned char> *data_to_write_
= const_cast< vector<unsigned char>* >(&data_to_write);
Tango::DeviceData dtw;
dtw << *data_to_write_;
device_proxy->command_inout("Write", dtw);
}
void Serial2Client::read_(const Tango::DevLong len, vector<unsigned char> &data_to_read)
{
check_init();
Tango::DeviceData dtr, dtr_len;
dtr_len << len;
dtr = device_proxy->command_inout("Read", dtr_len);
dtr >> data_to_read;
}
void Serial2Client::read_until_(const unsigned char delim, vector<unsigned char> &data_to_read)
{
check_init();
vector<unsigned char> delim_;
delim_.push_back(delim);
Tango::DeviceData dtr, dtr_delim;
dtr_delim << delim_;
dtr = device_proxy->command_inout("ReadUntil", dtr_delim);
dtr >> data_to_read;
}
void Serial2Client::write(const vector<unsigned char> &data_to_write)
{
write_(data_to_write);
DEBUG_STREAM << "Written " << data_to_write.size()
<< " byte(s): " << dump_hex(data_to_write) << endl;
}
void Serial2Client::read(const Tango::DevLong len, vector<unsigned char> &data_to_read)
{
read_(len, data_to_read);
DEBUG_STREAM << "Readed " << data_to_read.size()
<< " byte(s): " << dump_hex(data_to_read) << endl;
}
void Serial2Client::read_until(const unsigned char delim, vector<unsigned char> &data_to_read)
{
read_until_(delim, data_to_read);
DEBUG_STREAM << "Readed " << data_to_read.size()
<< " byte(s): " << dump_hex(data_to_read) << endl;
}
void Serial2Client::write(const string &data_to_write)
{
vector<unsigned char> data;
for (unsigned int i=0; i<data_to_write.size(); ++i)
data.push_back(data_to_write[i]);
write_(data);
DEBUG_STREAM << "Written " << data.size()
<< " byte(s): " << dump_ascii(data) << endl;
}
void Serial2Client::read(const Tango::DevLong len, string &data_readed)
{
vector<unsigned char> data;
read_(len, data);
data_readed = "";
for (unsigned int i=0; i<data.size(); ++i)
data_readed += data[i];
DEBUG_STREAM << "Readed " << data.size()
<< " byte(s): " << dump_ascii(data) << endl;
}
void Serial2Client::read_until(const char delim, string &data_readed)
{
vector<unsigned char> data;
read_until_(delim, data);
data_readed = "";
for (unsigned int i=0; i<data.size(); ++i)
data_readed += data[i];
DEBUG_STREAM << "Readed " << data.size()
<< " byte(s): " << dump_ascii(data) << endl;
}
int Serial2Client::output_length()
{
check_init();
Tango::DevLong ret;
device_proxy->read_attribute("OutputLength") >> ret;
return ret;
}
int Serial2Client::input_length()
{
check_init();
Tango::DevLong ret;
device_proxy->read_attribute("InputLength") >> ret;
return ret;
}
Tango::DevState Serial2Client::get_state2()
{
check_init();
Tango::DevState state;
device_proxy->read_attribute( "State" ) >> state;
return state;
}
string Serial2Client::get_status2()
{
check_init();
string status;
device_proxy->read_attribute( "Status" ) >> status;
return status;
}
/*
void StreamClient::read(Tango::DeviceProxy &dp, const Tango::DevLong len,
Tango::DevVarCharArray &data_readed)
{
Tango::DeviceData dtr, dtr_len;
dtr_len << len;
dtr = dp.command_inout("Read", dtr_len);
const Tango::DevVarCharArray *dvca;
dtr >> dvca;
data_readed.length(dvca->length());
for (unsigned int i=0; i<dvca->length(); ++i)
data_readed[i] = (*dvca)[i];
}
void StreamClient::read_until(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &delim,
Tango::DevVarCharArray &data_readed)
{
Tango::DeviceData dtr, d;
Tango::DevVarCharArray *temp = new Tango::DevVarCharArray();
temp->length(delim.length());
for (unsigned int i=0; i<delim.length(); ++i)
(*temp)[i] = delim[i];
d << temp;
dtr = dp.command_inout("ReadUntil", d);
const Tango::DevVarCharArray *dvca;
dtr >> dvca;
data_readed.length(dvca->length());
for (unsigned int i=0; i<dvca->length(); ++i)
data_readed[i] = (*dvca)[i];
}
*/
/*
void Serial2Client::write(const Tango::DevVarCharArray *data_to_write)
{
Tango::DeviceData dtw;
dtw << data_to_write;
device_proxy->command_inout("Write", dtw);
}
*/
/*
void StreamClient::write(const Tango::DevString *data_to_write)
{
}
void StreamClient::write_and_read(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &data_to_write,
const Tango::DevLong len, Tango::DevVarCharArray &data_readed)
{
write(dp, data_to_write);
read(dp, len, data_readed);
}
void StreamClient::write_and_read(Tango::DeviceProxy &dp,
const string &data_to_write, const Tango::DevLong len,
string &data_readed)
{
write(dp, data_to_write);
read(dp, len, data_readed);
}
void StreamClient::write_and_read_until(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &data_to_write,
const Tango::DevVarCharArray &delim,
Tango::DevVarCharArray &data_readed)
{
write(dp, data_to_write);
read_until(dp, delim, data_readed);
}
void StreamClient::write_and_read_until(Tango::DeviceProxy &dp,
const string &data_to_write, const string &delim,
string &data_readed)
{
write(dp, data_to_write);
read_until(dp, delim, data_readed);
}
*/
string Serial2Client::dump_ascii(const vector<unsigned char> &data)
{
stringstream mesg_ascii;
for (unsigned int i=0; i<data.size(); ++i) {
if (isspace((char)data[i])) {
if ((int)data[i] == 0x20)
mesg_ascii << (char)data[i];
} else
mesg_ascii << (char)data[i];
}
return mesg_ascii.str();
}
string Serial2Client::dump_hex(const vector<unsigned char> &data)
{
stringstream mesg_hex;
for (unsigned int i=0; i<data.size(); ++i) {
mesg_hex << setw(2) << setfill('0')
<< hex << (int)data[i] << " ";
}
return mesg_hex.str();
}
/*----- PROTECTED REGION END -----*/ // Serial2Client::namespace_ending
} // namespace
/*----- PROTECTED REGION ID(Serial2Client.h) ENABLED START -----*/
//=============================================================================
//
// file : Serial2Client.h
//
// description : Include file for the Serial2Client class
//
// project :
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Author: alessio $
//
// $Revision: 1.5 $
// $Date: 2018-07-09 13:58:05 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef Serial2Client_H
#define Serial2Client_H
#include <tango.h>
/*----- PROTECTED REGION END -----*/ // Serial2Client.h
/**
* Serial2Client class description:
*
*/
namespace Serial2Client_ns
{
/*----- PROTECTED REGION ID(Serial2Client::Additional Class Declarations) ENABLED START -----*/
// Additional Class Declarations
/*----- PROTECTED REGION END -----*/ // Serial2Client::Additional Class Declarations
class Serial2Client : public TANGO_BASE_CLASS
{
/*----- PROTECTED REGION ID(Serial2Client::Data Members) ENABLED START -----*/
// Add your own data members
private:
Tango::DeviceProxy *device_proxy;
string init_error;
/*----- PROTECTED REGION END -----*/ // Serial2Client::Data Members
// Device property data members
public:
// DeviceName:
string deviceName;
bool mandatoryNotDefined;
// Constructors and destructors
public:
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device Name
*/
Serial2Client(Tango::DeviceClass *cl,string &s);
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device Name
*/
Serial2Client(Tango::DeviceClass *cl,const char *s);
/**
* Constructs a newly device object.
*
* @param cl Class.
* @param s Device name
* @param d Device description.
*/
Serial2Client(Tango::DeviceClass *cl,const char *s,const char *d);
/**
* The device object destructor.
*/
~Serial2Client() {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();
/*
* Check if mandatory property has been set
*/
void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop);
// Attribute methods
public:
//--------------------------------------------------------
/*
* Method : Serial2Client::read_attr_hardware()
* Description : Hardware acquisition for attributes.
*/
//--------------------------------------------------------
virtual void read_attr_hardware(vector<long> &attr_list);
//--------------------------------------------------------
/**
* Method : Serial2Client::add_dynamic_attributes()
* Description : Add dynamic attributes if any.
*/
//--------------------------------------------------------
void add_dynamic_attributes();
// Command related methods
public:
//--------------------------------------------------------
/**
* Method : Serial2Client::add_dynamic_commands()
* Description : Add dynamic commands if any.
*/
//--------------------------------------------------------
void add_dynamic_commands();
/*----- PROTECTED REGION ID(Serial2Client::Additional Method prototypes) ENABLED START -----*/
// Additional Method prototypes
private:
void check_init();
void write_(const vector<unsigned char> &data_to_write);
void read_(const Tango::DevLong len, vector<unsigned char> &data_to_read);
void read_until_(const unsigned char delim, vector<unsigned char> &data_to_read);
protected:
int input_length();
int output_length();
// Methods for binary protocols (using std::vector<char>)
void write(const vector<unsigned char> &data_to_write);
void read(const Tango::DevLong len, vector<unsigned char> &data_to_read);
void read_until(const unsigned char delim, vector<unsigned char> &data_to_read);
// Methods for ascii protocols (using std::string)
void write(const string &data_to_write);
void read(const Tango::DevLong len, string &data_readed);
void read_until(const char delim, string &data_readed);
Tango::DevState get_state2();
string get_status2();
// Methods for binary protocols (using Tango::DevVarCharArray)
// void write(const Tango::DevVarCharArray *data_to_write);
/*
void write(const Tango::DevString *data_to_write);
*/
/* void read(Tango::DeviceProxy &dp, const Tango::DevLong len,
Tango::DevVarCharArray &data_readed);
void read_until(Tango::DeviceProxy &dp, const Tango::DevVarCharArray &delim,
Tango::DevVarCharArray &data_readed);
*/
/*
void write_and_read(Tango::DeviceProxy &dp, const Tango::DevVarCharArray &data_to_write,
const Tango::DevLong len, Tango::DevVarCharArray &data_readed);
void write_and_read_until(Tango::DeviceProxy &dp,
const Tango::DevVarCharArray &data_to_write,
const Tango::DevVarCharArray &delim,
Tango::DevVarCharArray &data_readed);
*/
// Methods for ascii protocols (using Tango::DevString)
/* void write_and_read(Tango::DeviceProxy &dp, const string &data_to_write,
const Tango::DevLong len, string &data_readed);
void write_and_read_until(Tango::DeviceProxy &dp, const string &data_to_write,
const string &delim, string &data_readed);
*/
string dump_ascii(const vector<unsigned char> &data);
string dump_hex(const vector<unsigned char> &data);
/*----- PROTECTED REGION END -----*/ // Serial2Client::Additional Method prototypes
};
/*----- PROTECTED REGION ID(Serial2Client::Additional Classes Definitions) ENABLED START -----*/
// Additional Classes Definitions
/*----- PROTECTED REGION END -----*/ // Serial2Client::Additional Classes Definitions
} // End of namespace
#endif // Serial2Client_H
<?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="Serial2Client" pogoRevision="9.4">
<description description="" title="" sourcePath="/home/alessio/WIP/fermi/servers/serial2/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at elettra.eu> - Alessio Igor Bogani &lt;alessio.bogani" author="Alessio Igor Bogani &lt;alessio.bogani" emailDomain="elettra.eu>" classFamily="Communication" siteSpecific="" platform="Unix Like" bus="Serial Line" manufacturer="none" reference=""/>
</description>
<deviceProperties name="DeviceName" mandatory="true" description="">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<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" concreteHere="false"/>
</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" polledPeriod="0" isDynamic="false">
<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" concreteHere="false"/>
</commands>
<preferences docHome="./doc_html" makefileHome="$(TANGO_HOME)"/>
</classes>
</pogoDsl:PogoSystem>
/*----- PROTECTED REGION ID(Serial2ClientClass.cpp) ENABLED START -----*/
static const char *RcsId = "$Id: Serial2ClientClass.cpp,v 1.3 2017-12-21 15:35:39 alessio Exp $";
static const char *TagName = "Serial2Client $Name: $";
static const char *CvsPath = "$Source: /home/cvsadm/cvsroot/fermi/servers/serial2/src/Serial2ClientClass.cpp,v $";
static const char *SvnPath = "$HeadURL: $";
static const char *HttpServer = "http://www.esrf.eu/computing/cs/tango/tango_doc/ds_doc/";
//=============================================================================
//
// file : Serial2ClientClass.cpp
//
// description : C++ source for the Serial2ClientClass.
// A singleton class derived from DeviceClass.
// It implements the command and attribute list
// and all properties and methods required
// by the Serial2Client once per process.
//
// project :
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Author: alessio $
//
// $Revision: 1.3 $
// $Date: 2017-12-21 15:35:39 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <Serial2ClientClass.h>
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass.cpp
//-------------------------------------------------------------------
/**
* Create Serial2ClientClass singleton and
* return it in a C function for Python usage
*/
//-------------------------------------------------------------------
extern "C" {
#ifdef _TG_WINDOWS_
__declspec(dllexport)
#endif
Tango::DeviceClass *_create_Serial2Client_class(const char *name) {
return Serial2Client_ns::Serial2ClientClass::init(name);
}
}
namespace Serial2Client_ns
{
//===================================================================
// Initialize pointer for singleton pattern
//===================================================================
Serial2ClientClass *Serial2ClientClass::_instance = NULL;
//--------------------------------------------------------
/**
* method : Serial2ClientClass::Serial2ClientClass(string &s)
* description : constructor for the Serial2ClientClass
*
* @param s The class name
*/
//--------------------------------------------------------
Serial2ClientClass::Serial2ClientClass(string &s):Tango::DeviceClass(s)
{
cout2 << "Entering Serial2ClientClass constructor" << endl;
set_default_property();
write_class_property();
/*----- PROTECTED REGION ID(Serial2ClientClass::constructor) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::constructor
cout2 << "Leaving Serial2ClientClass constructor" << endl;
}
//--------------------------------------------------------
/**
* method : Serial2ClientClass::~Serial2ClientClass()
* description : destructor for the Serial2ClientClass
*/
//--------------------------------------------------------
Serial2ClientClass::~Serial2ClientClass()
{
/*----- PROTECTED REGION ID(Serial2ClientClass::destructor) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::destructor
_instance = NULL;
}
//--------------------------------------------------------
/**
* method : Serial2ClientClass::init
* description : Create the object if not already done.
* Otherwise, just return a pointer to the object
*
* @param name The class name
*/
//--------------------------------------------------------
Serial2ClientClass *Serial2ClientClass::init(const char *name)
{
if (_instance == NULL)
{
try
{
string s(name);
_instance = new Serial2ClientClass(s);
}
catch (bad_alloc &)
{
throw;
}
}
return _instance;
}
//--------------------------------------------------------
/**
* method : Serial2ClientClass::instance
* description : Check if object already created,
* and return a pointer to the object
*/
//--------------------------------------------------------
Serial2ClientClass *Serial2ClientClass::instance()
{
if (_instance == NULL)
{
cerr << "Class is not initialised !!" << endl;
exit(-1);
}
return _instance;
}
//===================================================================
// Command execution method calls
//===================================================================
//===================================================================
// Properties management
//===================================================================
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::get_class_property()
* Description : Get the class property for specified name.
*/
//--------------------------------------------------------
Tango::DbDatum Serial2ClientClass::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 : Serial2ClientClass::get_default_device_property()
* Description : Return the default value for device property.
*/
//--------------------------------------------------------
Tango::DbDatum Serial2ClientClass::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 : Serial2ClientClass::get_default_class_property()
* Description : Return the default value for class property.
*/
//--------------------------------------------------------
Tango::DbDatum Serial2ClientClass::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 : Serial2ClientClass::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 Serial2ClientClass::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 = "DeviceName";
prop_desc = "";
prop_def = "";
vect_data.clear();
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
}
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::write_class_property()
* Description : Set class description fields as property in database
*/
//--------------------------------------------------------
void Serial2ClientClass::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("");
title << str_title;
data.push_back(title);
// Put Description
Tango::DbDatum description("Description");
vector<string> str_desc;
str_desc.push_back("");
description << str_desc;
data.push_back(description);
// put cvs or svn location
string filename("Serial2Client");
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("TANGO_BASE_CLASS");
inher_datum << inheritance;
data.push_back(inher_datum);
// Call database and and values
get_db_class()->put_property(data);
}
//===================================================================
// Factory methods
//===================================================================
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::device_factory()
* Description : Create the device object(s)
* and store them in the device list
*/
//--------------------------------------------------------
void Serial2ClientClass::device_factory(const Tango::DevVarStringArray *devlist_ptr)
{
/*----- PROTECTED REGION ID(Serial2ClientClass::device_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::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 Serial2Client(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
Serial2Client *dev = static_cast<Serial2Client *>(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(Serial2ClientClass::device_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::device_factory_after
}
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::attribute_factory()
* Description : Create the attribute object(s)
* and store them in the attribute list
*/
//--------------------------------------------------------
void Serial2ClientClass::attribute_factory(vector<Tango::Attr *> &att_list)
{
/*----- PROTECTED REGION ID(Serial2ClientClass::attribute_factory_before) ENABLED START -----*/
// Add your own code
(void)att_list;
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::attribute_factory_before
// Create a list of static attributes
create_static_attribute_list(get_class_attr()->get_attr_list());
/*----- PROTECTED REGION ID(Serial2ClientClass::attribute_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::attribute_factory_after
}
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::pipe_factory()
* Description : Create the pipe object(s)
* and store them in the pipe list
*/
//--------------------------------------------------------
void Serial2ClientClass::pipe_factory()
{
/*----- PROTECTED REGION ID(Serial2ClientClass::pipe_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::pipe_factory_before
/*----- PROTECTED REGION ID(Serial2ClientClass::pipe_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::pipe_factory_after
}
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::command_factory()
* Description : Create the command object(s)
* and store them in the command list
*/
//--------------------------------------------------------
void Serial2ClientClass::command_factory()
{
/*----- PROTECTED REGION ID(Serial2ClientClass::command_factory_before) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::command_factory_before
/*----- PROTECTED REGION ID(Serial2ClientClass::command_factory_after) ENABLED START -----*/
// Add your own code
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::command_factory_after
}
//===================================================================
// Dynamic attributes related methods
//===================================================================
//--------------------------------------------------------
/**
* method : Serial2ClientClass::create_static_attribute_list
* description : Create the a list of static attributes
*
* @param att_list the ceated attribute list
*/
//--------------------------------------------------------
void Serial2ClientClass::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(Serial2ClientClass::create_static_att_list) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::create_static_att_list
}
//--------------------------------------------------------
/**
* method : Serial2ClientClass::erase_dynamic_attributes
* description : delete the dynamic attributes if any.
*
* @param devlist_ptr the device list pointer
* @param list of all attributes
*/
//--------------------------------------------------------
void Serial2ClientClass::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());
Serial2Client *dev = static_cast<Serial2Client *> (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, false);
--ite_att;
}
}
}
/*----- PROTECTED REGION ID(Serial2ClientClass::erase_dynamic_attributes) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::erase_dynamic_attributes
}
//--------------------------------------------------------
/**
* Method : Serial2ClientClass::get_attr_by_name()
* Description : returns Tango::Attr * object found by name
*/
//--------------------------------------------------------
Tango::Attr *Serial2ClientClass::get_attr_object_by_name(vector<Tango::Attr *> &att_list, string attname)
{
vector<Tango::Attr *>::iterator it;
for (it=att_list.begin() ; it<att_list.end() ; ++it)
if ((*it)->get_name()==attname)
return (*it);
// Attr does not exist
return NULL;
}
/*----- PROTECTED REGION ID(Serial2ClientClass::Additional Methods) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::Additional Methods
} // namespace
/*----- PROTECTED REGION ID(Serial2ClientClass.h) ENABLED START -----*/
//=============================================================================
//
// file : Serial2ClientClass.h
//
// description : Include for the Serial2Client root class.
// This class is the singleton class for
// the Serial2Client device class.
// It contains all properties and methods which the
// Serial2Client requires only once e.g. the commands.
//
// project :
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Author: alessio $
//
// $Revision: 1.2 $
// $Date: 2017-12-21 15:35:39 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#ifndef Serial2ClientClass_H
#define Serial2ClientClass_H
#include <tango.h>
#include <Serial2Client.h>
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass.h
namespace Serial2Client_ns
{
/*----- PROTECTED REGION ID(Serial2ClientClass::classes for dynamic creation) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::classes for dynamic creation
/**
* The Serial2ClientClass singleton definition
*/
#ifdef _TG_WINDOWS_
class __declspec(dllexport) Serial2ClientClass : public Tango::DeviceClass
#else
class Serial2ClientClass : public Tango::DeviceClass
#endif
{
/*----- PROTECTED REGION ID(Serial2ClientClass::Additionnal DServer data members) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // Serial2ClientClass::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 Serial2ClientClass *init(const char *);
static Serial2ClientClass *instance();
~Serial2ClientClass();
Tango::DbDatum get_class_property(string &);
Tango::DbDatum get_default_device_property(string &);
Tango::DbDatum get_default_class_property(string &);
protected:
Serial2ClientClass(string &);
static Serial2ClientClass *_instance;
void command_factory();
void attribute_factory(vector<Tango::Attr *> &);
void pipe_factory();
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;
Tango::Attr *get_attr_object_by_name(vector<Tango::Attr *> &att_list, string attname);
};
} // End of namespace
#endif // Serial2Client_H
/*----- PROTECTED REGION ID(Serial2ClientStateMachine.cpp) ENABLED START -----*/
static const char *RcsId = "$Id: Serial2ClientStateMachine.cpp,v 1.2 2017-12-21 15:35:39 alessio Exp $";
//=============================================================================
//
// file : Serial2ClientStateMachine.cpp
//
// description : State machine file for the Serial2Client class
//
// project :
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see <http://www.gnu.org/licenses/>.
//
// $Author: alessio $
//
// $Revision: 1.2 $
// $Date: 2017-12-21 15:35:39 $
//
// $HeadURL: $
//
//=============================================================================
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <Serial2Client.h>
/*----- PROTECTED REGION END -----*/ // Serial2Client::Serial2ClientStateMachine.cpp
//================================================================
// States | Description
//================================================================
namespace Serial2Client_ns
{
//=================================================
// Attributes Allowed Methods
//=================================================
//=================================================
// Commands Allowed Methods
//=================================================
/*----- PROTECTED REGION ID(Serial2Client::Serial2ClientStateAllowed.AdditionalMethods) ENABLED START -----*/
// Additional Methods
/*----- PROTECTED REGION END -----*/ // Serial2Client::Serial2ClientStateAllowed.AdditionalMethods
} // End of namespace
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment