diff --git a/CMakeLists.txt b/CMakeLists.txt index 27872415325156255e65af8f491ac7dd4ee36a70..d04718d144bffe017e025f74336648bd432f5a5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.15) project(${PROJECT_NAME} CXX) find_package(yat4tango CONFIG REQUIRED) -find_package(utils CONFIG REQUIRED) if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") find_package(crashreporting2 CONFIG) endif() @@ -21,7 +20,6 @@ set(includedirs add_executable(${EXECUTABLE_NAME} ${sources}) target_include_directories(${EXECUTABLE_NAME} PRIVATE ${includedirs}) target_link_libraries(${EXECUTABLE_NAME} PRIVATE yat4tango::yat4tango) -target_link_libraries(${EXECUTABLE_NAME} PRIVATE utils::utils) if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") target_link_libraries(${EXECUTABLE_NAME} PRIVATE crashreporting2::crashreporting2) endif() diff --git a/conanfile.py b/conanfile.py index 7ca9c8da2870255990afcb56d953093127bccfb0..fa3a23fd11ea6cbdfe9ae98499852f7317337562 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ from conan import ConanFile class SimulatedMotorRecipe(ConanFile): name = "simulatedmotor" executable = "ds_SimulatedMotor" - version = "2.0.2" + version = "2.0.3" package_type = "application" user = "soleil" python_requires = "base/[>=1.0]@soleil/stable" @@ -22,6 +22,5 @@ class SimulatedMotorRecipe(ConanFile): def requirements(self): self.requires("yat4tango/[>=1.0]@soleil/stable") - self.requires("utils/[>=1.0]@soleil/stable") if self.settings.os == "Linux": self.requires("crashreporting2/[>=1.0]@soleil/stable") diff --git a/src/SimulatedMotor.cpp b/src/SimulatedMotor.cpp index 3330b0ba535c8098e02efc6c426515fc67f6e674..b23b25c386688ffc859c9d24b693d159d50ef186 100644 --- a/src/SimulatedMotor.cpp +++ b/src/SimulatedMotor.cpp @@ -61,7 +61,6 @@ static const char *RcsId = "$Id: $"; #include <tango.h> #include "PogoHelper.h" -#include "Tools.h" #include <SimulatedMotor.h> #include <SimulatedMotorClass.h> #include <float.h> @@ -593,8 +592,6 @@ void SimulatedMotor::write_accuracy(Tango::WAttribute &attr) INFO_STREAM << "accuracy <- " << attr_accuracy_write; } - - //+------------------------------------------------------------------ /** * method: SimulatedMotor::forward @@ -608,9 +605,7 @@ void SimulatedMotor::write_accuracy(Tango::WAttribute &attr) //+------------------------------------------------------------------ void SimulatedMotor::forward() { - DEBUG_STREAM << "SimulatedMotor::forward(): entering... !" << endl; - - INFO_STREAM << "Command called: forward"; + INFO_STREAM << "SimulatedMotor::forward(): entering... !" << endl; if (*attr_positionLocked_read == true) { @@ -635,9 +630,7 @@ void SimulatedMotor::forward() //+------------------------------------------------------------------ void SimulatedMotor::backward() { - DEBUG_STREAM << "SimulatedMotor::backward(): entering... !" << endl; - - INFO_STREAM << "Command called: backward"; + INFO_STREAM << "SimulatedMotor::backward(): entering... !" << endl; if (*attr_positionLocked_read == true) { @@ -661,9 +654,7 @@ void SimulatedMotor::backward() //+------------------------------------------------------------------ void SimulatedMotor::stop() { - DEBUG_STREAM << "SimulatedMotor::stop(): entering... !" << endl; - - INFO_STREAM << "Command called: stop"; + INFO_STREAM << "SimulatedMotor::stop(): entering... !" << endl; yat::Message * msg = new yat::Message(MSG_STOP, DEFAULT_MSG_PRIORITY, true); m_task->wait_msg_handled(msg); // handle message synchronously (ensure exiting backward() in STANDBY state) @@ -681,9 +672,7 @@ void SimulatedMotor::stop() //+------------------------------------------------------------------ void SimulatedMotor::motor_on() { - DEBUG_STREAM << "SimulatedMotor::motor_on(): entering... !" << endl; - - INFO_STREAM << "Command called: motor_on"; + INFO_STREAM << "SimulatedMotor::motor_on(): entering... !" << endl; if (get_state() == Tango::STANDBY) return; @@ -703,9 +692,7 @@ void SimulatedMotor::motor_on() //+------------------------------------------------------------------ void SimulatedMotor::motor_off() { - DEBUG_STREAM << "SimulatedMotor::motor_off(): entering... !" << endl; - - INFO_STREAM << "Command called: motor_off"; + INFO_STREAM << "SimulatedMotor::motor_off(): entering... !" << endl; yat::Message * msg = new yat::Message(MSG_OFF); m_task->post(msg); @@ -762,7 +749,7 @@ Tango::DevState SimulatedMotor::dev_state() default: { - device_status << GetDeviceState(device_state); + device_status << Tango::DevStateName[device_state]; } } @@ -787,7 +774,7 @@ Tango::DevState SimulatedMotor::dev_state() //+------------------------------------------------------------------ void SimulatedMotor::force_state(Tango::DevString argin) { - DEBUG_STREAM << "SimulatedMotor::force_state(): entering... !" << endl; + INFO_STREAM << "SimulatedMotor::force_state(): entering... !" << endl; // Find the index of the given string yat::String state_in = argin; diff --git a/src/SimulatedMotor.cpp.bak b/src/SimulatedMotor.cpp.bak deleted file mode 100755 index 3579bd115d18cd57981f0fd54766df15afc9d1fa..0000000000000000000000000000000000000000 --- a/src/SimulatedMotor.cpp.bak +++ /dev/null @@ -1,812 +0,0 @@ -static const char *RcsId = "$Id: $"; -//+============================================================================= -// -// file : SimulatedMotor.cpp -// -// description : C++ source for the SimulatedMotor 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 -// SimulatedMotor are implemented in this file. -// -// project : TANGO Device Server -// -// $Author: $ -// -// $Revision: $ -// -// $Revision: $ -// $Date: $ -// -// SVN only: -// $HeadURL: $ -// -// CVS only: -// $Source: $ -// $Log: $ -// -// copyleft : Synchrotron SOLEIL -// L'Orme des merisiers - Saint Aubin -// BP48 - 91192 Gif sur Yvette -// 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() -// Forward | forward() -// Backward | backward() -// Stop | stop() -// MotorON | motor_on() -// MotorOFF | motor_off() -// ForceSTATE | force_state() -// -//=================================================================== - - -#include <tango.h> -#include "PogoHelper.h" -#include "Tools.h" -#include <SimulatedMotor.h> -#include <SimulatedMotorClass.h> -#include <float.h> - -namespace SimulatedMotor_ns -{ - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::SimulatedMotor(string &s) -// -// description : constructor for simulated SimulatedMotor -// -// in : - cl : Pointer to the DeviceClass object -// - s : Device name -// -//----------------------------------------------------------------------------- -SimulatedMotor::SimulatedMotor(Tango::DeviceClass *cl,string &s) -:Tango::Device_4Impl(cl,s.c_str()), m_is_init_startup(true) -{ - init_device(); -} - -SimulatedMotor::SimulatedMotor(Tango::DeviceClass *cl,const char *s) -:Tango::Device_4Impl(cl,s), m_is_init_startup(true) -{ - init_device(); -} - -SimulatedMotor::SimulatedMotor(Tango::DeviceClass *cl,const char *s,const char *d) -:Tango::Device_4Impl(cl,s,d), m_is_init_startup(true) -{ - init_device(); -} -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::delete_device() -// -// description : will be called at device destruction or at init command. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::delete_device() -{ - // Delete device allocated objects - DELETE_SCALAR_ATTRIBUTE(attr_position_read); - DELETE_SCALAR_ATTRIBUTE(attr_offset_read); - DELETE_SCALAR_ATTRIBUTE(attr_velocity_read); - DELETE_SCALAR_ATTRIBUTE(attr_accuracy_read); - DELETE_SCALAR_ATTRIBUTE(attr_backlash_read); - DELETE_SCALAR_ATTRIBUTE(attr_acceleration_read); - DELETE_SCALAR_ATTRIBUTE(attr_deceleration_read); - DELETE_SCALAR_ATTRIBUTE(attr_backwardLimitSwitch_read); - DELETE_SCALAR_ATTRIBUTE(attr_forwardLimitSwitch_read); - DELETE_SCALAR_ATTRIBUTE(attr_positionLocked_read); - - //- release the inner-appender - INFO_STREAM << "Remove the inner-appender." << endl; - yat4tango::InnerAppender::release(this); - - INFO_STREAM << "Remove the log-adapter." << endl; - yat4tango::YatLogAdapter::release(); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::init_device() -// -// description : will be called at device initialization. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::init_device() -{ - INFO_STREAM << "SimulatedMotor::init_device() entering ..."; - - //- instanciate the appender in order ton manage logs - DEBUG_STREAM << "Add the inner-appender." << endl; - try - { - //- specify both the associated device and the log buffer depth - yat4tango::InnerAppender::initialize(this, 1024); - } - catch (Tango::DevFailed& df) - { - ERROR_STREAM << df << endl; - set_state(Tango::INIT); - return; - } - - // Initialise variables to default values - //-------------------------------------------- - get_device_property(); - - CREATE_SCALAR_ATTRIBUTE(attr_position_read); - CREATE_SCALAR_ATTRIBUTE(attr_offset_read); - CREATE_SCALAR_ATTRIBUTE(attr_velocity_read); - CREATE_SCALAR_ATTRIBUTE(attr_accuracy_read); - CREATE_SCALAR_ATTRIBUTE(attr_backlash_read); - CREATE_SCALAR_ATTRIBUTE(attr_acceleration_read); - CREATE_SCALAR_ATTRIBUTE(attr_deceleration_read); - CREATE_SCALAR_ATTRIBUTE(attr_backwardLimitSwitch_read); - CREATE_SCALAR_ATTRIBUTE(attr_forwardLimitSwitch_read); - CREATE_SCALAR_ATTRIBUTE(attr_positionLocked_read); - - m_statuses.push_back("ON"); - m_statuses.push_back("OFF"); - m_statuses.push_back("CLOSE"); - m_statuses.push_back("OPEN"); - m_statuses.push_back("INSERT"); - m_statuses.push_back("EXTRACT"); - m_statuses.push_back("MOVING"); - m_statuses.push_back("STANDBY"); - m_statuses.push_back("FAULT"); - m_statuses.push_back("INIT"); - m_statuses.push_back("RUNNING"); - m_statuses.push_back("ALARM"); - m_statuses.push_back("DISABLE"); - m_statuses.push_back("UNKNOWN"); - - // Log - yat4tango::YatLogAdapter::initialize(this); - - m_previous_state = Tango::INIT; - set_state(Tango::INIT); - - // Create and start the task - m_task.reset(new SimulatedMotorTask(this), TaskExiter()); - yat::Message* msg = yat::Message::allocate(yat::TASK_INIT, INIT_MSG_PRIORITY, true); - m_task->go(msg); - - // Init default values - if (m_is_init_startup) - { - m_is_init_startup = false; - - attr_velocity_write = 10.0; - Tango::WAttribute &init_velocity = dev_attr->get_w_attr_by_name("velocity"); - init_velocity.set_write_value(attr_velocity_write); - write_velocity(init_velocity); - } - - attr_positionLocked_write = false; - Tango::WAttribute &init_positionLocked = dev_attr->get_w_attr_by_name("positionLocked"); - init_positionLocked.set_write_value(attr_positionLocked_write); - write_positionLocked(init_positionLocked); - - m_is_write_at_init = true; - - INFO_STREAM << "SimulatedMotor::init_device() exiting ...\n"; -} - - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::get_device_property() -// -// description : Read the device properties from database. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::get_device_property() -{ - // Initialize your default values here (if not done with POGO). -} -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::always_executed_hook() -// -// description : method always executed before any command is executed -// -//----------------------------------------------------------------------------- -void SimulatedMotor::always_executed_hook() -{ - try - { - dev_state(); - } - catch (Tango::DevFailed& df) - { - ERROR_STREAM << df << endl; - RETHROW_DEVFAILED( df, "TANGO_DEVICE_ERROR", string(df.errors[0].desc).c_str(), "SimulatedMotor::always_executed_hook" ); - } -} -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_attr_hardware -// -// description : Hardware acquisition for attributes. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_attr_hardware(vector<long> &attr_list) -{ - DEBUG_STREAM << "SimulatedMotor::read_attr_hardware(vector<long> &attr_list) entering... "<< endl; - // Add your own code here -} -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_positionLocked -// -// description : Extract real attribute values for positionLocked acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_positionLocked(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_positionLocked(Tango::Attribute &attr) entering... "<< endl; - attr.set_value(attr_positionLocked_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_positionLocked -// -// description : Write positionLocked attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_positionLocked(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_positionLocked(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_positionLocked_write); - *attr_positionLocked_read = attr_positionLocked_write; - - INFO_STREAM << "positionLocked <- " << attr_positionLocked_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_backwardLimitSwitch -// -// description : Extract real attribute values for backwardLimitSwitch acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_backwardLimitSwitch(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_backwardLimitSwitch(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_backwardLimitSwitch_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_backwardLimitSwitch -// -// description : Write backwardLimitSwitch attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_backwardLimitSwitch(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_backwardLimitSwitch(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_backwardLimitSwitch_write); - *attr_backwardLimitSwitch_read = attr_backwardLimitSwitch_write; - - INFO_STREAM << "backwardLimitSwitch <- " << attr_backwardLimitSwitch_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_forwardLimitSwitch -// -// description : Extract real attribute values for forwardLimitSwitch acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_forwardLimitSwitch(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_forwardLimitSwitch(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_forwardLimitSwitch_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_forwardLimitSwitch -// -// description : Write forwardLimitSwitch attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_forwardLimitSwitch(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_forwardLimitSwitch(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_forwardLimitSwitch_write); - *attr_forwardLimitSwitch_read = attr_forwardLimitSwitch_write; - - INFO_STREAM << "forwardLimitSwitch <- " << attr_forwardLimitSwitch_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_backlash -// -// description : Extract real attribute values for backlash acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_backlash(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_backlash(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_backlash_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_backlash -// -// description : Write backlash attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_backlash(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_backlash(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_backlash_write); - *attr_backlash_read = attr_backlash_write; - - INFO_STREAM << "backlash <- " << attr_backlash_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_acceleration -// -// description : Extract real attribute values for acceleration acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_acceleration(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_acceleration(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_acceleration_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_acceleration -// -// description : Write acceleration attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_acceleration(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_acceleration(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_acceleration_write); - *attr_acceleration_read = attr_acceleration_write; - - INFO_STREAM << "acceleration <- " << attr_acceleration_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_deceleration -// -// description : Extract real attribute values for deceleration acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_deceleration(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_deceleration(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_deceleration_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_deceleration -// -// description : Write deceleration attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_deceleration(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_deceleration(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_deceleration_write); - *attr_deceleration_read = attr_deceleration_write; - - INFO_STREAM << "deceleration <- " << attr_deceleration_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_position -// -// description : Extract real attribute values for position acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_position(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_position(Tango::Attribute &attr) entering... "<< endl; - - *attr_position_read = m_task->get_position() + (*attr_offset_read); - attr.set_value(attr_position_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_position -// -// description : Write position attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_position(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_position(Tango::WAttribute &attr) entering... "<< endl; - - if (*attr_positionLocked_read == true) - { - Tango::Except::throw_exception("TANGO_DEVICE_ERROR","Position is locked.", "SimulatedMotor::write_position"); - } - - attr.get_write_value(attr_position_write); - - INFO_STREAM << "position <- " << attr_position_write; - - // Init position in task at init - if (m_is_write_at_init) - { - m_is_write_at_init = false; - yat::Message * msg = new yat::Message(MSG_INITPOSITION); - msg->attach_data(attr_position_write); - m_task->post(msg); - } - else - // Move only if displacement is greater than accuracy - if ( fabs(attr_position_write - *attr_position_read) > *attr_accuracy_read) - { - yat::Message * msg = new yat::Message(MSG_SETPOSITION); - msg->attach_data(attr_position_write); - m_task->post(msg); - } -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_offset -// -// description : Extract real attribute values for offset acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_offset(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_offset(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_offset_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_offset -// -// description : Write offset attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_offset(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_offset(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_offset_write); - *attr_offset_read = attr_offset_write; - - INFO_STREAM << "offset <- " << attr_offset_write; -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_velocity -// -// description : Extract real attribute values for velocity acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_velocity(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_velocity(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_velocity_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_velocity -// -// description : Write velocity attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_velocity(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_velocity(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_velocity_write); - - INFO_STREAM << "velocity <- " << attr_velocity_write; - - *attr_velocity_read = attr_velocity_write; - yat::Message * msg = new yat::Message(MSG_SETVELOCITY); - msg->attach_data(attr_velocity_write); - m_task->post(msg); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::read_accuracy -// -// description : Extract real attribute values for accuracy acquisition result. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::read_accuracy(Tango::Attribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::read_accuracy(Tango::Attribute &attr) entering... "<< endl; - - attr.set_value(attr_accuracy_read); -} - -//+---------------------------------------------------------------------------- -// -// method : SimulatedMotor::write_accuracy -// -// description : Write accuracy attribute values to hardware. -// -//----------------------------------------------------------------------------- -void SimulatedMotor::write_accuracy(Tango::WAttribute &attr) -{ - DEBUG_STREAM << "SimulatedMotor::write_accuracy(Tango::WAttribute &attr) entering... "<< endl; - - attr.get_write_value(attr_accuracy_write); - *attr_accuracy_read = attr_accuracy_write; - - INFO_STREAM << "accuracy <- " << attr_accuracy_write; -} - - - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::forward - * - * description: method to execute "Forward" - * Increment in a continuous way the position attribute value of the device.<BR> - * Each increment is equal to StepSize. - * - * - */ -//+------------------------------------------------------------------ -void SimulatedMotor::forward() -{ - DEBUG_STREAM << "SimulatedMotor::forward(): entering... !" << endl; - - INFO_STREAM << "Command called: forward"; - - if (*attr_positionLocked_read == true) - { - Tango::Except::throw_exception("TANGO_DEVICE_ERROR","Position is locked.", "SimulatedMotor::forward"); - } - - yat::Message * msg = new yat::Message(MSG_SETPOSITION); - msg->attach_data(DBL_MAX); - m_task->post(msg); -} - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::backward - * - * description: method to execute "Backward" - * decrement in a continuous way the position attribute value of the device.<BR> - * Each increment is equal to StepSize. - * - * - */ -//+------------------------------------------------------------------ -void SimulatedMotor::backward() -{ - DEBUG_STREAM << "SimulatedMotor::backward(): entering... !" << endl; - - INFO_STREAM << "Command called: backward"; - - if (*attr_positionLocked_read == true) - { - Tango::Except::throw_exception("TANGO_DEVICE_ERROR","Position is locked.", "SimulatedMotor::backward"); - } - - yat::Message * msg = new yat::Message(MSG_SETPOSITION); - msg->attach_data(-DBL_MAX); - m_task->post(msg); -} - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::stop - * - * description: method to execute "Stop" - * Stop the current movement of the device. - * - * - */ -//+------------------------------------------------------------------ -void SimulatedMotor::stop() -{ - DEBUG_STREAM << "SimulatedMotor::stop(): entering... !" << endl; - - INFO_STREAM << "Command called: stop"; - - yat::Message * msg = new yat::Message(MSG_STOP); - msg->attach_data(-DBL_MAX); - m_task->post(msg); -} - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::motor_on - * - * description: method to execute "MotorON" - * Switch the power of the motor to On. State is switched to Standby. - * - * - */ -//+------------------------------------------------------------------ -void SimulatedMotor::motor_on() -{ - DEBUG_STREAM << "SimulatedMotor::motor_on(): entering... !" << endl; - - INFO_STREAM << "Command called: motor_on"; - - if (get_state() == Tango::STANDBY) return; - - yat::Message * msg = new yat::Message(MSG_ON); - m_task->post(msg); -} - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::motor_off - * - * description: method to execute "MotorOFF" - * Switch the power of the motor to Off. State is switched to Off. - * - * - */ -//+------------------------------------------------------------------ -void SimulatedMotor::motor_off() -{ - DEBUG_STREAM << "SimulatedMotor::motor_off(): entering... !" << endl; - - INFO_STREAM << "Command called: motor_off"; - - yat::Message * msg = new yat::Message(MSG_OFF); - m_task->post(msg); -} - - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::dev_state - * - * description: method to execute "State" - * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller. - * - * @return State Code - * - */ -//+------------------------------------------------------------------ -Tango::DevState SimulatedMotor::dev_state() -{ - DEBUG_STREAM << "SimulatedMotor::dev_state(): entering... !" << endl; - - // Add your own code to control device here - stringstream device_status; - device_status << ""; - Tango::DevState device_state = m_task->get_state(); - set_state(device_state); - - switch (device_state) - { - case Tango::STANDBY: - { - if (*attr_positionLocked_read) - { - device_status << "axis position locked [STANDBY]"; - } - else - { - device_status << "axis up and ready [STANDBY]"; - } - break; - } - - case Tango::MOVING: - { - device_status << "axis is MOVING"; - break; - } - - case Tango::OFF: - { - device_status << "axis off [motor is OFF]"; - break; - } - - default: - { - device_status << GetDeviceState(device_state); - } - } - - set_status(device_status.str()); - - return device_state; -} - - - - -//+------------------------------------------------------------------ -/** - * method: SimulatedMotor::force_state - * - * description: method to execute "ForceSTATE" - * This command allows forcing the state of the device for tests purposes. - * - * @param argin A tango devstate name (FAULT, INIT ...) - * - */ -//+------------------------------------------------------------------ -void SimulatedMotor::force_state(Tango::DevString argin) -{ - DEBUG_STREAM << "SimulatedMotor::force_state(): entering... !" << endl; - - // Find the index of the given string - yat::String state_in = argin; - state_in.to_upper(); - - vector<string>::const_iterator it = find(m_statuses.begin(), m_statuses.end(), state_in); - if (it!=m_statuses.end()) - { - Tango::DevState state = Tango::DevState(it - m_statuses.begin()); - - yat::Message * msg = new yat::Message(MSG_FORCESTATE); - msg->attach_data(state); - m_task->post(msg); - } - else - { - yat::String msg = "Possible states are:\n"; - for (unsigned int i=0; i<m_statuses.size(); i++) msg.printf("%s%s\n", msg.c_str(), m_statuses.at(i).c_str() ); - Tango::Except::throw_exception("TANGO_DEVICE_ERROR", msg.c_str(), "SimulatedMotor::force_state"); - } -} - - -} // namespace