Commit 2c14ea7e authored by Roberto  Borghes's avatar Roberto Borghes
Browse files

First import from SVN

parent 95fe6adc
NAME_SRV = aml-srv
CXXFLAGS =
LDFLAGS =
include ../../../cs/ds/makefiles/Make-9.3.3.in
static const char *RcsId = "$Header: $";
//+=============================================================================
//
// file : Aml.cpp
//
// description : C++ source for the Aml 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
// Aml are implemented in this file.
//
// project : TANGO Device Server
//
// $Author: $
//
// $Revision: $
//
// $Log: $
//
// 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
//=============================================================================
//===================================================================
//
// The following table gives the correspondence
// between commands and method name.
//
// Command name | Method name
// ----------------------------------------
// State | dev_state()
// Status | dev_status()
// Axis1_MoveRelative | axis1__move_relative()
// Axis2_MoveRelative | axis2__move_relative()
// Axis1_MoveAbsolute | axis1__move_absolute()
// Axis2_MoveAbsolute | axis2__move_absolute()
// InitMotor | init_motor()
// Stop | stop()
// GetPosition | get_position()
//
//===================================================================
#include <tango.h>
#include <Aml.h>
#include <AmlClass.h>
namespace Aml_ns
{
//+----------------------------------------------------------------------------
//
// method : Aml::Aml(string &s)
//
// description : constructor for simulated Aml
//
// in : - cl : Pointer to the DeviceClass object
// - s : Device name
//
//-----------------------------------------------------------------------------
Aml::Aml(Tango::DeviceClass *cl,string &s)
:Tango::Device_4Impl(cl,s.c_str())
{
device = 0;
init_device();
}
Aml::Aml(Tango::DeviceClass *cl,const char *s)
:Tango::Device_4Impl(cl,s)
{
device = 0;
init_device();
}
Aml::Aml(Tango::DeviceClass *cl,const char *s,const char *d)
:Tango::Device_4Impl(cl,s,d)
{
device = 0;
init_device();
}
//+----------------------------------------------------------------------------
//
// method : Aml::delete_device()
//
// description : will be called at device destruction or at init command.
//
//-----------------------------------------------------------------------------
void Aml::delete_device()
{
// Delete device's allocated object
if (device > 0)
close(device);
device = 0;
}
//+----------------------------------------------------------------------------
//
// method : Aml::init_device()
//
// description : will be called at device initialization.
//
//-----------------------------------------------------------------------------
void Aml::init_device()
{
INFO_STREAM << "Aml::Aml() create device " << device_name << endl;
// Initialise variables to default values
//--------------------------------------------
get_device_property();
initSerialPort();
init_motor();
Motor1Name = logicalName + axis1_Name;
Motor2Name = logicalName + axis2_Name;
errorMessage="";
errorNumber=0;
logMessage="";
}
//+----------------------------------------------------------------------------
//
// method : Aml::get_device_property()
//
// description : Read the device properties from database.
//
//-----------------------------------------------------------------------------
void Aml::get_device_property()
{
// Initialize your default values here (if not done with POGO).
//------------------------------------------------------------------
// Read device properties from database.(Automatic code generation)
//------------------------------------------------------------------
Tango::DbData dev_prop;
dev_prop.push_back(Tango::DbDatum("LogicalName"));
dev_prop.push_back(Tango::DbDatum("SerialPort"));
dev_prop.push_back(Tango::DbDatum("ControllerVersion"));
dev_prop.push_back(Tango::DbDatum("Axis1_Name"));
dev_prop.push_back(Tango::DbDatum("Axis1_MinStepRate1"));
dev_prop.push_back(Tango::DbDatum("Axis1_MinStepRate2"));
dev_prop.push_back(Tango::DbDatum("Axis1_MinStepRate3"));
dev_prop.push_back(Tango::DbDatum("Axis1_PhaseCurrent"));
dev_prop.push_back(Tango::DbDatum("Axis1_Ramp"));
dev_prop.push_back(Tango::DbDatum("Axis1_StartStopSpeed"));
dev_prop.push_back(Tango::DbDatum("Axis1_SleewSpeed"));
dev_prop.push_back(Tango::DbDatum("Axis1_Range"));
dev_prop.push_back(Tango::DbDatum("Axis1_SetAccelerAndRetardPars"));
dev_prop.push_back(Tango::DbDatum("Axis2_Name"));
dev_prop.push_back(Tango::DbDatum("Axis2_MinStepRate1"));
dev_prop.push_back(Tango::DbDatum("Axis2_MinStepRate2"));
dev_prop.push_back(Tango::DbDatum("Axis2_MinStepRate3"));
dev_prop.push_back(Tango::DbDatum("Axis2_PhaseCurrent"));
dev_prop.push_back(Tango::DbDatum("Axis2_Ramp"));
dev_prop.push_back(Tango::DbDatum("Axis2_StartStopSpeed"));
dev_prop.push_back(Tango::DbDatum("Axis2_SleewSpeed"));
dev_prop.push_back(Tango::DbDatum("Axis2_Range"));
dev_prop.push_back(Tango::DbDatum("Axis2_SetAccelerAndRetardPars"));
// Call database and extract values
//--------------------------------------------
if (Tango::Util::instance()->_UseDb==true)
get_db_device()->get_property(dev_prop);
Tango::DbDatum def_prop, cl_prop;
AmlClass *ds_class =
(static_cast<AmlClass *>(get_device_class()));
int i = -1;
// Try to initialize LogicalName from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> logicalName;
else {
// Try to initialize LogicalName from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> logicalName;
}
// And try to extract LogicalName value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> logicalName;
// Try to initialize SerialPort from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> serialPort;
else {
// Try to initialize SerialPort from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> serialPort;
}
// And try to extract SerialPort value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> serialPort;
// Try to initialize ControllerVersion from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> controllerVersion;
else {
// Try to initialize ControllerVersion from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> controllerVersion;
}
// And try to extract ControllerVersion value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> controllerVersion;
// Try to initialize Axis1_Name from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_Name;
else {
// Try to initialize Axis1_Name from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_Name;
}
// And try to extract Axis1_Name value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_Name;
// Try to initialize Axis1_MinStepRate1 from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_MinStepRate1;
else {
// Try to initialize Axis1_MinStepRate1 from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_MinStepRate1;
}
// And try to extract Axis1_MinStepRate1 value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_MinStepRate1;
// Try to initialize Axis1_MinStepRate2 from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_MinStepRate2;
else {
// Try to initialize Axis1_MinStepRate2 from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_MinStepRate2;
}
// And try to extract Axis1_MinStepRate2 value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_MinStepRate2;
// Try to initialize Axis1_MinStepRate3 from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_MinStepRate3;
else {
// Try to initialize Axis1_MinStepRate3 from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_MinStepRate3;
}
// And try to extract Axis1_MinStepRate3 value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_MinStepRate3;
// Try to initialize Axis1_PhaseCurrent from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_PhaseCurrent;
else {
// Try to initialize Axis1_PhaseCurrent from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_PhaseCurrent;
}
// And try to extract Axis1_PhaseCurrent value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_PhaseCurrent;
// Try to initialize Axis1_Ramp from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_Ramp;
else {
// Try to initialize Axis1_Ramp from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_Ramp;
}
// And try to extract Axis1_Ramp value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_Ramp;
// Try to initialize Axis1_StartStopSpeed from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_StartStopSpeed;
else {
// Try to initialize Axis1_StartStopSpeed from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_StartStopSpeed;
}
// And try to extract Axis1_StartStopSpeed value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_StartStopSpeed;
// Try to initialize Axis1_SleewSpeed from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_SleewSpeed;
else {
// Try to initialize Axis1_SleewSpeed from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_SleewSpeed;
}
// And try to extract Axis1_SleewSpeed value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_SleewSpeed;
// Try to initialize Axis1_Range from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_Range;
else {
// Try to initialize Axis1_Range from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_Range;
}
// And try to extract Axis1_Range value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_Range;
// Try to initialize Axis1_SetAccelerAndRetardPars from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis1_SetAccelerAndRetardPars;
else {
// Try to initialize Axis1_SetAccelerAndRetardPars from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis1_SetAccelerAndRetardPars;
}
// And try to extract Axis1_SetAccelerAndRetardPars value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis1_SetAccelerAndRetardPars;
// Try to initialize Axis2_Name from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_Name;
else {
// Try to initialize Axis2_Name from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_Name;
}
// And try to extract Axis2_Name value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_Name;
// Try to initialize Axis2_MinStepRate1 from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_MinStepRate1;
else {
// Try to initialize Axis2_MinStepRate1 from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_MinStepRate1;
}
// And try to extract Axis2_MinStepRate1 value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_MinStepRate1;
// Try to initialize Axis2_MinStepRate2 from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_MinStepRate2;
else {
// Try to initialize Axis2_MinStepRate2 from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_MinStepRate2;
}
// And try to extract Axis2_MinStepRate2 value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_MinStepRate2;
// Try to initialize Axis2_MinStepRate3 from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_MinStepRate3;
else {
// Try to initialize Axis2_MinStepRate3 from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_MinStepRate3;
}
// And try to extract Axis2_MinStepRate3 value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_MinStepRate3;
// Try to initialize Axis2_PhaseCurrent from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_PhaseCurrent;
else {
// Try to initialize Axis2_PhaseCurrent from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_PhaseCurrent;
}
// And try to extract Axis2_PhaseCurrent value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_PhaseCurrent;
// Try to initialize Axis2_Ramp from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_Ramp;
else {
// Try to initialize Axis2_Ramp from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_Ramp;
}
// And try to extract Axis2_Ramp value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_Ramp;
// Try to initialize Axis2_StartStopSpeed from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_StartStopSpeed;
else {
// Try to initialize Axis2_StartStopSpeed from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_StartStopSpeed;
}
// And try to extract Axis2_StartStopSpeed value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_StartStopSpeed;
// Try to initialize Axis2_SleewSpeed from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_SleewSpeed;
else {
// Try to initialize Axis2_SleewSpeed from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_SleewSpeed;
}
// And try to extract Axis2_SleewSpeed value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_SleewSpeed;
// Try to initialize Axis2_Range from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_Range;
else {
// Try to initialize Axis2_Range from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_Range;
}
// And try to extract Axis2_Range value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_Range;
// Try to initialize Axis2_SetAccelerAndRetardPars from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> axis2_SetAccelerAndRetardPars;
else {
// Try to initialize Axis2_SetAccelerAndRetardPars from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> axis2_SetAccelerAndRetardPars;
}
// And try to extract Axis2_SetAccelerAndRetardPars value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> axis2_SetAccelerAndRetardPars;
// End of Automatic code generation
//------------------------------------------------------------------
}
//+----------------------------------------------------------------------------
//
// method : Aml::always_executed_hook()
//
// description : method always executed before any command is executed
//
//-----------------------------------------------------------------------------
void Aml::always_executed_hook()
{
}
//+----------------------------------------------------------------------------
//
// method : Aml::read_attr_hardware
//
// description : Hardware acquisition for attributes.
//
//-----------------------------------------------------------------------------
void Aml::read_attr_hardware(vector<long> &attr_list)
{
DEBUG_STREAM << "Aml::read_attr_hardware(vector<long> &attr_list) entering... "<< endl;
// Add your own code here
}
//+----------------------------------------------------------------------------
//
// method : Aml::read_Axis1_Position
//
// description : Extract real attribute values for Axis1_Position acquisition result.
//
//-----------------------------------------------------------------------------
void Aml::read_Axis1_Position(Tango::Attribute &attr)
{
DEBUG_STREAM << "Aml::read_Axis1_Position(Tango::Attribute &attr) entering... "<< endl;
attr_long_value=get_position(1);
currentPosAxis1=attr_long_value;
attr.set_value(&attr_long_value);
}
//+----------------------------------------------------------------------------
//
// method : Aml::read_Axis2_Position
//
// description : Extract real attribute values for Axis2_Position acquisition result.
//
//-----------------------------------------------------------------------------
void Aml::read_Axis2_Position(Tango::Attribute &attr)
{
DEBUG_STREAM << "Aml::read_Axis2_Position(Tango::Attribute &attr) entering... "<< endl;
attr_long_value=get_position(2);
currentPosAxis2=attr_long_value;
attr.set_value(&attr_long_value);
}
//+------------------------------------------------------------------
/**
* method: Aml::init_motor
*
* description: method to execute "InitMotor"
*
*
*/
//+------------------------------------------------------------------
void Aml::init_motor()
{
DEBUG_STREAM << "Aml::init_motor(): entering... !" << endl;
// Add your own code to control device here
char *answ;
string cmd;
string selMot;
char *char_cmd;
actualSelectedMotor = -1;
//select 1st axis
selMot=string(AML_AXIS1);
selectMotor(selMot);
//set 1st axis parameters
if (device != 0) {
if (controllerVersion)
cmd=axis1_MinStepRate1;
else
cmd=string(AML_SET_MIN_STEP_RATE1) + "," + axis1_MinStepRate1;
char_cmd=new char[cmd.length()+1];
strcpy(char_cmd, cmd.c_str());
answ=talkListen(char_cmd, AML_MAX_RETRY);
if (answ == 0) {
TangoSys_OMemStream os;
os << "Error->"<< Motor1Name<<" init_motor: setting min step rate1 failed";
Tango::Except::throw_exception("Init Motor Error", os.str(), __func__);
}
free(answ);
delete []char_cmd;
}
if ((device != 0) && (!controllerVersion)) {
cmd=string(AML_SET_MIN_STEP_RATE2) + "," + axis1_MinStepRate2;
char_cmd=new char[cmd.length()+1];
strcpy(char_cmd, cmd.c_str());
answ=talkListen(char_cmd, AML_MAX_RETRY);
if (answ == 0) {
TangoSys_OMemStream os;
os << "Error->"<< Motor1Name<<" init_motor: setting min step rate2 failed";
Tango::Except::throw_exception("Init Motor Error", os.str(), __func__);
}
free(answ);
delete []char_cmd;
}
if ((device != 0) && (!controllerVersion)) {
cmd=string(AML_SET_MIN_STEP_RATE4) + "," + axis1_MinStepRate3;
char_cmd=new char[cmd.length()+1];
strcpy(char_cmd, cmd.c_str());
answ=talkListen(char_cmd, AML_MAX_RETRY);
if (answ == 0) {
TangoSys_OMemStream os;
os << "Error->"<< Motor1Name<<" init_motor: setting min step rate4 failed";
Tango::Except::throw_exception("Init Motor Error", os.str(), __func__);
}
free(answ);
delete []char_cmd;
}
if (device != 0) {
cmd=string(AML_REMOVE_PHASE_CURRENT) + axis1_PhaseCurrent;
char_cmd=new char[cmd.length()+1];
strcpy(char_cmd, cmd.c_str());
answ=talkListen(char_cmd, AML_MAX_RETRY);
if (answ == 0) {
TangoSys_OMemStream os;
os << "Error->"<< Motor1Name<<" init_motor: setting phase current failed";
Tango::Except::throw_exception("Init Motor Error", os.str(), __func__);
}
free(answ);
delete []char_cmd;
}
if ((device != 0) && (!controllerVersion)) {
cmd=string(AML_SET_RAMP) + axis1_Ramp;
char_cmd=new char[cmd.length()+1];
strcpy(char_cmd, cmd.c_str());
answ=talkListen(char_cmd, AML_MAX_RETRY);
if (answ == 0) {
TangoSys_OMemStream os;
os << "Error->"<< Motor1Name<<" init_motor: setting ramp failed";
Tango::Except::throw_exception("Init Motor Error", os.str(), __func__);
}
free(answ);
delete []char_cmd;
}
if (device != 0) {
cmd=string(AML_SMOOTH_STOP);
char_cmd=new char[cmd.length()+1];
strcpy(char_cmd, cmd.c_str());
answ=talkListen(char_cmd, AML_MAX_RETRY);
if (answ == 0) {
TangoSys_OMemStream os;
os << "Error->"<< Motor1Name<<" init_motor: setting smooth stop failed";