Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
  • release_1_0_0
  • release_1_1_0
3 results

Target

Select target project
  • software-control-system/tango-devices/motion/pi/picontroller
1 result
Select Git revision
  • main
  • release_1_0_0
  • release_1_1_0
3 results
Show changes

Commits on Source 58

Showing
with 3154 additions and 414 deletions
File mode changed from 100644 to 100755
This diff is collapsed.
......@@ -19,30 +19,57 @@
#define AXIS_CONTOLLER_H
#include <tango.h>
#include <yat4tango/DeviceTask.h>
#include <yat/memory/SharedPtr.h>
#include <yat/utils/String.h>
#include <yat/threading/Mutex.h>
#include "Serializable.h"
const size_t CTRL_ON_MSG = yat::FIRST_USER_MSG + 100;
const size_t CTRL_OFF_MSG = yat::FIRST_USER_MSG + 110;
const size_t CTRL_MODEL_MSG = yat::FIRST_USER_MSG + 120;
const size_t CTRL_SETPOSITION_MSG = yat::FIRST_USER_MSG + 130;
const size_t CTRL_GETPOSITION_MSG = yat::FIRST_USER_MSG + 140;
const size_t CTRL_SETVELOCITY_MSG = yat::FIRST_USER_MSG + 150;
const size_t CTRL_GETVELOCITY_MSG = yat::FIRST_USER_MSG + 160;
const size_t CTRL_SETACCELERATION_MSG = yat::FIRST_USER_MSG + 170;
const size_t CTRL_GETACCELERATION_MSG = yat::FIRST_USER_MSG + 180;
const size_t CTRL_SETDECELERATION_MSG = yat::FIRST_USER_MSG + 190;
const size_t CTRL_GETDECELERATION_MSG = yat::FIRST_USER_MSG + 200;
const size_t CTRL_STOP_MSG = yat::FIRST_USER_MSG + 210;
const size_t CTRL_BACKWARD_MSG = yat::FIRST_USER_MSG + 220;
const size_t CTRL_FORWARD_MSG = yat::FIRST_USER_MSG + 230;
const size_t CTRL_NLIMIT_MSG = yat::FIRST_USER_MSG + 240;
const size_t CTRL_PLIMIT_MSG = yat::FIRST_USER_MSG + 250;
const size_t CTRL_INIT_REFPOS_MSG = yat::FIRST_USER_MSG + 260;
const size_t CTRL_RON_MSG = yat::FIRST_USER_MSG + 270;
const size_t CTRL_POS_MSG = yat::FIRST_USER_MSG + 280;
const size_t CTRL_AUTO_ZERO_MSG = yat::FIRST_USER_MSG + 290;
namespace PIAxis_ns
{
//--------------------------------------------------------------------------------
//! \class BoxController
//! \brief class Controller
//--------------------------------------------------------------------------------
class AxisController
class AxisController : public yat4tango::DeviceTask
{
public:
//! \brief Constructor
AxisController(long axis_id);
AxisController(Tango::DeviceImpl* dev, long axis_id, yat::String init_type,
double init_position, double init_velocity);
//! \brief Destructor
~AxisController();
//! \brief Will ask to the Hardware for the model
yat::String get_model();
//! \brief Get the Hardware Controller model
std::string get_model();
//! \brief Set state and status accordingly
void is_axis_initialized();
//! \brief Turn motor on
void on();
......@@ -50,17 +77,79 @@ public:
//! \brief Turn motor off
void off();
//! \brief check status of the socket
void check_internal_state();
//! \brief compute state and status of the PIAxis controller
void compute_state_status();
//! \brief get internal state of PIBox
//! \brief get internal state of PIAxis
Tango::DevState get_state();
//! \brief get internal status of PIBox
Tango::DevString get_status();
//! \brief set internal state of PIAxis
void set_state(Tango::DevState state);
//! \brief get internal status of PIAxis
std::string get_status();
//! \brief set internal status of PIAxis
void set_status(const std::string& status);
//! \brief get current axis id
Tango::DevLong get_axis_id() const;
double get_axis_id() const;
//! \brief read the value of the position
double read_position();
//! \brief set the position
void write_position(double arg);
//! \brief read the value of the velocity
double read_velocity();
//! \brief set the velocity
void write_velocity(double arg);
//! \brief read the value of the acceleration
double read_acceleration();
//! \brief set the acceleration
void write_acceleration(double arg);
//! \brief read the value of the acceleration
double read_deceleration();
//! \brief set the acceleration
void write_deceleration(double arg);
//! \brief stop the axis motion
void stop();
//! \brief move to backward limit
void backward();
//! \brief move to forward limit
void forward();
//! \brief detect if motor reached backward limit
bool backward_limit();
//! \brief detect if motor reached forward limit
bool forward_limit();
//! \brief initialise the reference position point
void initialise_reference_position();
//! \brief process messages task
void process_message(yat::Message& msg);
//! \brief initialise the reference position point
void auto_zero();
//! \brief error handler for tango
void tango_error_handler(Tango::DevFailed& df);
//! \brief error handler for yat
void yat_error_handler(const yat::Exception& e,string error_display);
private:
//! \brief m_axis_id: Axis id
......@@ -78,11 +167,56 @@ private:
//! \brief m_is_moving: Serializable to know the moving state of the axe
IsMoving m_is_moving;
//! \brief m_position
Position m_position;
//! \brief m_pos
Pos m_pos;
//! \brief m_velocity
Velocity m_velocity;
//! \brief m_acceleration;
Acceleration m_acceleration;
//! \brief m_deceleration;
Deceleration m_deceleration;
//! \brief m_stop: Stop the motion of the axis
Stop m_stop;
//! \brief m_backward: move to backward limit
Backward m_backward;
//! \brief m_forward: move to forward limit
Forward m_forward;
//! \brief m_limit_switch
LimitSwitch m_limit_switch;
//! \brief m_ron
Ron m_ron;
//! \brief m_init_type
yat::String m_init_type;
//! \brief m_init_position
double m_init_position;
//! \brief m_init_velocity
double m_init_velocity;
//! \brief m_is_initialized
IsInitialized m_is_initialized;
//! \brief m_autozero
AutoZero m_auto_zero;
//! \brief m_state: internal state of PIBox
Tango::DevState m_state;
//! \brief m_status: internal status of PIBox
Tango::DevString m_status;
std::stringstream m_status;
//! \brief m_state_lock: Mutex used to protect state and status access
yat::Mutex m_state_status_lock;
......
This diff is collapsed.
......@@ -58,7 +58,7 @@ class PIAxis : public TANGO_BASE_CLASS
/*----- PROTECTED REGION ID(PIAxis::Data Members) ENABLED START -----*/
// Add your own data members
AxisController* m_axis_controller;
yat::SharedPtr<AxisController> m_axis_controller;
/*----- PROTECTED REGION END -----*/ // PIAxis::Data Members
......@@ -66,10 +66,21 @@ class PIAxis : public TANGO_BASE_CLASS
public:
// AxisDefinition: Axis Identification ID
Tango::DevULong axisDefinition;
// AxisInitType: The motion of reference throughout the definition of the position of referrence, it can be : FNL or FPL
string axisInitType;
// AxisInitPosition: Position set for the definition of the current position.
Tango::DevDouble axisInitPosition;
// AxisInitVelocity: The current velocity
Tango::DevDouble axisInitVelocity;
// Attribute data members
public:
Tango::DevDouble *attr_Position_read;
Tango::DevDouble *attr_position_read;
Tango::DevDouble *attr_velocity_read;
Tango::DevDouble *attr_acceleration_read;
Tango::DevDouble *attr_deceleration_read;
Tango::DevBoolean *attr_backwardLimitSwitch_read;
Tango::DevBoolean *attr_forwardLimitSwitch_read;
// Constructors and destructors
public:
......@@ -139,15 +150,63 @@ public:
virtual void write_attr_hardware(vector<long> &attr_list);
/**
* Attribute Position related methods
* Description:
* Attribute position related methods
* Description: Axis position, in user unit
*
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
virtual void read_Position(Tango::Attribute &attr);
virtual void write_Position(Tango::WAttribute &attr);
virtual bool is_Position_allowed(Tango::AttReqType type);
virtual void read_position(Tango::Attribute &attr);
virtual void write_position(Tango::WAttribute &attr);
virtual bool is_position_allowed(Tango::AttReqType type);
/**
* Attribute velocity related methods
* Description: Axis velocity in closed-loop mode
*
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
virtual void read_velocity(Tango::Attribute &attr);
virtual void write_velocity(Tango::WAttribute &attr);
virtual bool is_velocity_allowed(Tango::AttReqType type);
/**
* Attribute acceleration related methods
* Description: Axis acceleration in closed-loop mode
*
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
virtual void read_acceleration(Tango::Attribute &attr);
virtual void write_acceleration(Tango::WAttribute &attr);
virtual bool is_acceleration_allowed(Tango::AttReqType type);
/**
* Attribute deceleration related methods
* Description: Axis deceleration in closed-loop mode
*
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
virtual void read_deceleration(Tango::Attribute &attr);
virtual void write_deceleration(Tango::WAttribute &attr);
virtual bool is_deceleration_allowed(Tango::AttReqType type);
/**
* Attribute backwardLimitSwitch related methods
* Description: Is negative limit switch reached
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
virtual void read_backwardLimitSwitch(Tango::Attribute &attr);
virtual bool is_backwardLimitSwitch_allowed(Tango::AttReqType type);
/**
* Attribute forwardLimitSwitch related methods
* Description: Is positive limit switch reached
*
* Data type: Tango::DevBoolean
* Attr type: Scalar
*/
virtual void read_forwardLimitSwitch(Tango::Attribute &attr);
virtual bool is_forwardLimitSwitch_allowed(Tango::AttReqType type);
//--------------------------------------------------------
......@@ -184,6 +243,34 @@ public:
*/
virtual void off();
virtual bool is_Off_allowed(const CORBA::Any &any);
/**
* Command Stop related method
* Description: Command to stop the axe motion
*
*/
virtual void stop();
virtual bool is_Stop_allowed(const CORBA::Any &any);
/**
* Command Backward related method
* Description: Move To Negative Limit
*
*/
virtual void backward();
virtual bool is_Backward_allowed(const CORBA::Any &any);
/**
* Command Forward related method
* Description: Move to positive limit.
*
*/
virtual void forward();
virtual bool is_Forward_allowed(const CORBA::Any &any);
/**
* Command InitialiseReferencePosition related method
* Description: Define the reference position
*
*/
virtual void initialise_reference_position();
virtual bool is_InitialiseReferencePosition_allowed(const CORBA::Any &any);
//--------------------------------------------------------
......
......@@ -10,6 +10,21 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>0</DefaultPropValue>
</deviceProperties>
<deviceProperties name="AxisInitType" description="The motion of reference throughout the definition of the position of referrence, it can be : FNL or FPL">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>FNL</DefaultPropValue>
</deviceProperties>
<deviceProperties name="AxisInitPosition" description="Position set for the definition of the current position.">
<type xsi:type="pogoDsl:DoubleType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>0</DefaultPropValue>
</deviceProperties>
<deviceProperties name="AxisInitVelocity" description="The current velocity">
<type xsi:type="pogoDsl:DoubleType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>0.5</DefaultPropValue>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="none">
<type xsi:type="pogoDsl:VoidType"/>
......@@ -39,6 +54,7 @@
<excludedStates>ON</excludedStates>
<excludedStates>MOVING</excludedStates>
<excludedStates>FAULT</excludedStates>
<excludedStates>INIT</excludedStates>
</commands>
<commands name="Off" description="Turn motor off" execMethod="off" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="">
......@@ -51,18 +67,126 @@
<excludedStates>OFF</excludedStates>
<excludedStates>MOVING</excludedStates>
<excludedStates>FAULT</excludedStates>
<excludedStates>INIT</excludedStates>
</commands>
<commands name="Stop" description="Command to stop the axe motion" execMethod="stop" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="">
<type xsi:type="pogoDsl:VoidType"/>
</argin>
<argout description="">
<type xsi:type="pogoDsl:VoidType"/>
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<excludedStates>ON</excludedStates>
<excludedStates>OFF</excludedStates>
<excludedStates>FAULT</excludedStates>
<excludedStates>INIT</excludedStates>
</commands>
<attributes name="Position" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<commands name="Backward" description="Move To Negative Limit" execMethod="backward" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="">
<type xsi:type="pogoDsl:VoidType"/>
</argin>
<argout description="">
<type xsi:type="pogoDsl:VoidType"/>
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<excludedStates>OFF</excludedStates>
<excludedStates>MOVING</excludedStates>
<excludedStates>FAULT</excludedStates>
<excludedStates>INIT</excludedStates>
</commands>
<commands name="Forward" description="Move to positive limit." execMethod="forward" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="">
<type xsi:type="pogoDsl:VoidType"/>
</argin>
<argout description="">
<type xsi:type="pogoDsl:VoidType"/>
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<excludedStates>OFF</excludedStates>
<excludedStates>MOVING</excludedStates>
<excludedStates>FAULT</excludedStates>
<excludedStates>INIT</excludedStates>
</commands>
<commands name="InitialiseReferencePosition" description="Define the reference position" execMethod="initialise_reference_position" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="">
<type xsi:type="pogoDsl:VoidType"/>
</argin>
<argout description="">
<type xsi:type="pogoDsl:VoidType"/>
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<excludedStates>MOVING</excludedStates>
</commands>
<attributes name="position" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:DoubleType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Axis position, in user unit" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
<writeExcludedStates>OFF</writeExcludedStates>
<writeExcludedStates>MOVING</writeExcludedStates>
<writeExcludedStates>FAULT</writeExcludedStates>
<writeExcludedStates>INIT</writeExcludedStates>
</attributes>
<attributes name="velocity" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:DoubleType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Axis velocity in closed-loop mode" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
<writeExcludedStates>OFF</writeExcludedStates>
<writeExcludedStates>MOVING</writeExcludedStates>
<writeExcludedStates>FAULT</writeExcludedStates>
<writeExcludedStates>INIT</writeExcludedStates>
</attributes>
<attributes name="acceleration" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:DoubleType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Axis acceleration in closed-loop mode" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
<writeExcludedStates>OFF</writeExcludedStates>
<writeExcludedStates>MOVING</writeExcludedStates>
<writeExcludedStates>FAULT</writeExcludedStates>
<writeExcludedStates>INIT</writeExcludedStates>
</attributes>
<attributes name="deceleration" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:DoubleType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<properties description="Axis deceleration in closed-loop mode" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
<writeExcludedStates>OFF</writeExcludedStates>
<writeExcludedStates>MOVING</writeExcludedStates>
<writeExcludedStates>FAULT</writeExcludedStates>
<writeExcludedStates>INIT</writeExcludedStates>
</attributes>
<attributes name="backwardLimitSwitch" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:BooleanType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Is negative limit switch reached" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
</attributes>
<attributes name="forwardLimitSwitch" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:BooleanType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Is positive limit switch reached" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
</attributes>
<states name="ON" description="Motor on">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
......@@ -76,6 +200,9 @@
<states name="FAULT" description="Motor is in fault">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
<states name="INIT" description="Waiting for InitialiseReferencePosition to be done">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
<preferences docHome="../doc/doc_html" makefileHome="$(TANGO_HOME)"/>
</classes>
</pogoDsl:PogoSystem>
......@@ -184,6 +184,78 @@ CORBA::Any *OffClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORB
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : StopClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *StopClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "StopClass::execute(): arrived" << endl;
((static_cast<PIAxis *>(device))->stop());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : BackwardClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *BackwardClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "BackwardClass::execute(): arrived" << endl;
((static_cast<PIAxis *>(device))->backward());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : ForwardClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *ForwardClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "ForwardClass::execute(): arrived" << endl;
((static_cast<PIAxis *>(device))->forward());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : InitialiseReferencePositionClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *InitialiseReferencePositionClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "InitialiseReferencePositionClass::execute(): arrived" << endl;
((static_cast<PIAxis *>(device))->initialise_reference_position());
return new CORBA::Any();
}
//===================================================================
// Properties management
......@@ -267,6 +339,48 @@ void PIAxisClass::set_default_property()
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "AxisInitType";
prop_desc = "The motion of reference throughout the definition of the position of referrence, it can be : FNL or FPL";
prop_def = "FNL";
vect_data.clear();
vect_data.push_back("FNL");
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "AxisInitPosition";
prop_desc = "Position set for the definition of the current position.";
prop_def = "0";
vect_data.clear();
vect_data.push_back("0");
if (prop_def.length()>0)
{
Tango::DbDatum data(prop_name);
data << vect_data ;
dev_def_prop.push_back(data);
add_wiz_dev_prop(prop_name, prop_desc, prop_def);
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "AxisInitVelocity";
prop_desc = "The current velocity";
prop_def = "0.5";
vect_data.clear();
vect_data.push_back("0.5");
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);
}
//--------------------------------------------------------
......@@ -396,23 +510,23 @@ void PIAxisClass::attribute_factory(vector<Tango::Attr *> &att_list)
// Add your own code
/*----- PROTECTED REGION END -----*/ // PIAxisClass::attribute_factory_before
// Attribute : Position
PositionAttrib *position = new PositionAttrib();
// Attribute : position
positionAttrib *position = new positionAttrib();
Tango::UserDefaultAttrProp position_prop;
// description not set for Position
// label not set for Position
// unit not set for Position
// standard_unit not set for Position
// display_unit not set for Position
// format not set for Position
// max_value not set for Position
// min_value not set for Position
// max_alarm not set for Position
// min_alarm not set for Position
// max_warning not set for Position
// min_warning not set for Position
// delta_t not set for Position
// delta_val not set for Position
position_prop.set_description("Axis position, in user unit");
// label not set for position
// unit not set for position
// standard_unit not set for position
// display_unit not set for position
// format not set for position
// max_value not set for position
// min_value not set for position
// max_alarm not set for position
// min_alarm not set for position
// max_warning not set for position
// min_warning not set for position
// delta_t not set for position
// delta_val not set for position
position->set_default_properties(position_prop);
// Not Polled
......@@ -420,6 +534,126 @@ void PIAxisClass::attribute_factory(vector<Tango::Attr *> &att_list)
// Not Memorized
att_list.push_back(position);
// Attribute : velocity
velocityAttrib *velocity = new velocityAttrib();
Tango::UserDefaultAttrProp velocity_prop;
velocity_prop.set_description("Axis velocity in closed-loop mode");
// label not set for velocity
// unit not set for velocity
// standard_unit not set for velocity
// display_unit not set for velocity
// format not set for velocity
// max_value not set for velocity
// min_value not set for velocity
// max_alarm not set for velocity
// min_alarm not set for velocity
// max_warning not set for velocity
// min_warning not set for velocity
// delta_t not set for velocity
// delta_val not set for velocity
velocity->set_default_properties(velocity_prop);
// Not Polled
velocity->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(velocity);
// Attribute : acceleration
accelerationAttrib *acceleration = new accelerationAttrib();
Tango::UserDefaultAttrProp acceleration_prop;
acceleration_prop.set_description("Axis acceleration in closed-loop mode");
// label not set for acceleration
// unit not set for acceleration
// standard_unit not set for acceleration
// display_unit not set for acceleration
// format not set for acceleration
// max_value not set for acceleration
// min_value not set for acceleration
// max_alarm not set for acceleration
// min_alarm not set for acceleration
// max_warning not set for acceleration
// min_warning not set for acceleration
// delta_t not set for acceleration
// delta_val not set for acceleration
acceleration->set_default_properties(acceleration_prop);
// Not Polled
acceleration->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(acceleration);
// Attribute : deceleration
decelerationAttrib *deceleration = new decelerationAttrib();
Tango::UserDefaultAttrProp deceleration_prop;
deceleration_prop.set_description("Axis deceleration in closed-loop mode");
// label not set for deceleration
// unit not set for deceleration
// standard_unit not set for deceleration
// display_unit not set for deceleration
// format not set for deceleration
// max_value not set for deceleration
// min_value not set for deceleration
// max_alarm not set for deceleration
// min_alarm not set for deceleration
// max_warning not set for deceleration
// min_warning not set for deceleration
// delta_t not set for deceleration
// delta_val not set for deceleration
deceleration->set_default_properties(deceleration_prop);
// Not Polled
deceleration->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(deceleration);
// Attribute : backwardLimitSwitch
backwardLimitSwitchAttrib *backwardlimitswitch = new backwardLimitSwitchAttrib();
Tango::UserDefaultAttrProp backwardlimitswitch_prop;
backwardlimitswitch_prop.set_description("Is negative limit switch reached");
// label not set for backwardLimitSwitch
// unit not set for backwardLimitSwitch
// standard_unit not set for backwardLimitSwitch
// display_unit not set for backwardLimitSwitch
// format not set for backwardLimitSwitch
// max_value not set for backwardLimitSwitch
// min_value not set for backwardLimitSwitch
// max_alarm not set for backwardLimitSwitch
// min_alarm not set for backwardLimitSwitch
// max_warning not set for backwardLimitSwitch
// min_warning not set for backwardLimitSwitch
// delta_t not set for backwardLimitSwitch
// delta_val not set for backwardLimitSwitch
backwardlimitswitch->set_default_properties(backwardlimitswitch_prop);
// Not Polled
backwardlimitswitch->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(backwardlimitswitch);
// Attribute : forwardLimitSwitch
forwardLimitSwitchAttrib *forwardlimitswitch = new forwardLimitSwitchAttrib();
Tango::UserDefaultAttrProp forwardlimitswitch_prop;
forwardlimitswitch_prop.set_description("Is positive limit switch reached");
// label not set for forwardLimitSwitch
// unit not set for forwardLimitSwitch
// standard_unit not set for forwardLimitSwitch
// display_unit not set for forwardLimitSwitch
// format not set for forwardLimitSwitch
// max_value not set for forwardLimitSwitch
// min_value not set for forwardLimitSwitch
// max_alarm not set for forwardLimitSwitch
// min_alarm not set for forwardLimitSwitch
// max_warning not set for forwardLimitSwitch
// min_warning not set for forwardLimitSwitch
// delta_t not set for forwardLimitSwitch
// delta_val not set for forwardLimitSwitch
forwardlimitswitch->set_default_properties(forwardlimitswitch_prop);
// Not Polled
forwardlimitswitch->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(forwardlimitswitch);
// Create a list of static attributes
create_static_attribute_list(get_class_attr()->get_attr_list());
......@@ -483,6 +717,42 @@ void PIAxisClass::command_factory()
Tango::OPERATOR);
command_list.push_back(pOffCmd);
// Command Stop
StopClass *pStopCmd =
new StopClass("Stop",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pStopCmd);
// Command Backward
BackwardClass *pBackwardCmd =
new BackwardClass("Backward",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pBackwardCmd);
// Command Forward
ForwardClass *pForwardCmd =
new ForwardClass("Forward",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pForwardCmd);
// Command InitialiseReferencePosition
InitialiseReferencePositionClass *pInitialiseReferencePositionCmd =
new InitialiseReferencePositionClass("InitialiseReferencePosition",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pInitialiseReferencePositionCmd);
/*----- PROTECTED REGION ID(PIAxisClass::command_factory_after) ENABLED START -----*/
// Add your own code
......
......@@ -54,19 +54,90 @@ namespace PIAxis_ns
//=========================================
// Define classes for attributes
//=========================================
// Attribute Position class definition
class PositionAttrib: public Tango::Attr
// Attribute position class definition
class positionAttrib: public Tango::Attr
{
public:
PositionAttrib():Attr("Position",
positionAttrib():Attr("position",
Tango::DEV_DOUBLE, Tango::READ_WRITE) {};
~PositionAttrib() {};
~positionAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIAxis *>(dev))->read_Position(att);}
{(static_cast<PIAxis *>(dev))->read_position(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<PIAxis *>(dev))->write_Position(att);}
{(static_cast<PIAxis *>(dev))->write_position(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIAxis *>(dev))->is_Position_allowed(ty);}
{return (static_cast<PIAxis *>(dev))->is_position_allowed(ty);}
};
// Attribute velocity class definition
class velocityAttrib: public Tango::Attr
{
public:
velocityAttrib():Attr("velocity",
Tango::DEV_DOUBLE, Tango::READ_WRITE) {};
~velocityAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIAxis *>(dev))->read_velocity(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<PIAxis *>(dev))->write_velocity(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIAxis *>(dev))->is_velocity_allowed(ty);}
};
// Attribute acceleration class definition
class accelerationAttrib: public Tango::Attr
{
public:
accelerationAttrib():Attr("acceleration",
Tango::DEV_DOUBLE, Tango::READ_WRITE) {};
~accelerationAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIAxis *>(dev))->read_acceleration(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<PIAxis *>(dev))->write_acceleration(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIAxis *>(dev))->is_acceleration_allowed(ty);}
};
// Attribute deceleration class definition
class decelerationAttrib: public Tango::Attr
{
public:
decelerationAttrib():Attr("deceleration",
Tango::DEV_DOUBLE, Tango::READ_WRITE) {};
~decelerationAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIAxis *>(dev))->read_deceleration(att);}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{(static_cast<PIAxis *>(dev))->write_deceleration(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIAxis *>(dev))->is_deceleration_allowed(ty);}
};
// Attribute backwardLimitSwitch class definition
class backwardLimitSwitchAttrib: public Tango::Attr
{
public:
backwardLimitSwitchAttrib():Attr("backwardLimitSwitch",
Tango::DEV_BOOLEAN, Tango::READ) {};
~backwardLimitSwitchAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIAxis *>(dev))->read_backwardLimitSwitch(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIAxis *>(dev))->is_backwardLimitSwitch_allowed(ty);}
};
// Attribute forwardLimitSwitch class definition
class forwardLimitSwitchAttrib: public Tango::Attr
{
public:
forwardLimitSwitchAttrib():Attr("forwardLimitSwitch",
Tango::DEV_BOOLEAN, Tango::READ) {};
~forwardLimitSwitchAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIAxis *>(dev))->read_forwardLimitSwitch(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIAxis *>(dev))->is_forwardLimitSwitch_allowed(ty);}
};
......@@ -119,6 +190,98 @@ public:
{return (static_cast<PIAxis *>(dev))->is_Off_allowed(any);}
};
// Command Stop class definition
class StopClass : public Tango::Command
{
public:
StopClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
StopClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~StopClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<PIAxis *>(dev))->is_Stop_allowed(any);}
};
// Command Backward class definition
class BackwardClass : public Tango::Command
{
public:
BackwardClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
BackwardClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~BackwardClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<PIAxis *>(dev))->is_Backward_allowed(any);}
};
// Command Forward class definition
class ForwardClass : public Tango::Command
{
public:
ForwardClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
ForwardClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~ForwardClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<PIAxis *>(dev))->is_Forward_allowed(any);}
};
// Command InitialiseReferencePosition class definition
class InitialiseReferencePositionClass : public Tango::Command
{
public:
InitialiseReferencePositionClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out,
const char *in_desc,
const char *out_desc,
Tango::DispLevel level)
:Command(name,in,out,in_desc,out_desc, level) {};
InitialiseReferencePositionClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~InitialiseReferencePositionClass() {};
virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
{return (static_cast<PIAxis *>(dev))->is_InitialiseReferencePosition_allowed(any);}
};
/**
* The PIAxisClass singleton definition
......
......@@ -40,6 +40,7 @@
// OFF | Motor Off
// MOVING | Motor is moving
// FAULT | Motor is in fault
// INIT | Waiting for InitialiseReferencePosition to be done
namespace PIAxis_ns
......@@ -50,11 +51,11 @@ namespace PIAxis_ns
//--------------------------------------------------------
/**
* Method : PIAxis::is_Position_allowed()
* Description : Execution allowed for Position attribute
* Method : PIAxis::is_position_allowed()
* Description : Execution allowed for position attribute
*/
//--------------------------------------------------------
bool PIAxis::is_Position_allowed(TANGO_UNUSED(Tango::AttReqType type))
bool PIAxis::is_position_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Check access type.
if ( type!=Tango::READ_REQ )
......@@ -62,14 +63,15 @@ bool PIAxis::is_Position_allowed(TANGO_UNUSED(Tango::AttReqType type))
// Compare device state with not allowed states for WRITE
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT)
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::PositionStateAllowed_WRITE) ENABLED START -----*/
/*----- PROTECTED REGION ID(PIAxis::positionStateAllowed_WRITE) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::PositionStateAllowed_WRITE
/*----- PROTECTED REGION END -----*/ // PIAxis::positionStateAllowed_WRITE
return false;
}
return true;
......@@ -82,12 +84,212 @@ bool PIAxis::is_Position_allowed(TANGO_UNUSED(Tango::AttReqType type))
// Compare device state with not allowed states for READ
if (get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(PIAxis::PositionStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION ID(PIAxis::positionStateAllowed_READ) ENABLED START -----*/
if (is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::PositionStateAllowed_READ
/*----- PROTECTED REGION END -----*/ // PIAxis::positionStateAllowed_READ
return false;
}
return true;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_velocity_allowed()
* Description : Execution allowed for velocity attribute
*/
//--------------------------------------------------------
bool PIAxis::is_velocity_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Check access type.
if ( type!=Tango::READ_REQ )
{
// Compare device state with not allowed states for WRITE
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::velocityStateAllowed_WRITE) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::velocityStateAllowed_WRITE
return false;
}
return true;
}
else
// Check access type.
if ( type==Tango::READ_REQ )
{
// Compare device state with not allowed states for READ
if (get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(PIAxis::velocityStateAllowed_READ) ENABLED START -----*/
if (is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::velocityStateAllowed_READ
return false;
}
return true;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_acceleration_allowed()
* Description : Execution allowed for acceleration attribute
*/
//--------------------------------------------------------
bool PIAxis::is_acceleration_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Check access type.
if ( type!=Tango::READ_REQ )
{
// Compare device state with not allowed states for WRITE
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::accelerationStateAllowed_WRITE) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::accelerationStateAllowed_WRITE
return false;
}
return true;
}
else
// Check access type.
if ( type==Tango::READ_REQ )
{
// Compare device state with not allowed states for READ
if (get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(PIAxis::accelerationStateAllowed_READ) ENABLED START -----*/
if ( is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::accelerationStateAllowed_READ
return false;
}
return true;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_deceleration_allowed()
* Description : Execution allowed for deceleration attribute
*/
//--------------------------------------------------------
bool PIAxis::is_deceleration_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Check access type.
if ( type!=Tango::READ_REQ )
{
// Compare device state with not allowed states for WRITE
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::decelerationStateAllowed_WRITE) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::decelerationStateAllowed_WRITE
return false;
}
return true;
}
else
// Check access type.
if ( type==Tango::READ_REQ )
{
// Compare device state with not allowed states for READ
if (get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(PIAxis::decelerationStateAllowed_READ) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::decelerationStateAllowed_READ
return false;
}
return true;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_backwardLimitSwitch_allowed()
* Description : Execution allowed for backwardLimitSwitch attribute
*/
//--------------------------------------------------------
bool PIAxis::is_backwardLimitSwitch_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Check access type.
if ( type==Tango::READ_REQ )
{
// Compare device state with not allowed states for READ
if (get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(PIAxis::backwardLimitSwitchStateAllowed_READ) ENABLED START -----*/
if (is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::backwardLimitSwitchStateAllowed_READ
return false;
}
return true;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_forwardLimitSwitch_allowed()
* Description : Execution allowed for forwardLimitSwitch attribute
*/
//--------------------------------------------------------
bool PIAxis::is_forwardLimitSwitch_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Check access type.
if ( type==Tango::READ_REQ )
{
// Compare device state with not allowed states for READ
if (get_state()==Tango::FAULT)
{
/*----- PROTECTED REGION ID(PIAxis::forwardLimitSwitchStateAllowed_READ) ENABLED START -----*/
if (is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::forwardLimitSwitchStateAllowed_READ
return false;
}
return true;
......@@ -111,7 +313,8 @@ bool PIAxis::is_On_allowed(TANGO_UNUSED(const CORBA::Any &any))
// Compare device state with not allowed states.
if (get_state()==Tango::ON ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT)
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::OnStateAllowed) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
......@@ -135,7 +338,8 @@ bool PIAxis::is_Off_allowed(TANGO_UNUSED(const CORBA::Any &any))
// Compare device state with not allowed states.
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT)
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::OffStateAllowed) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
......@@ -148,6 +352,100 @@ bool PIAxis::is_Off_allowed(TANGO_UNUSED(const CORBA::Any &any))
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_Stop_allowed()
* Description : Execution allowed for Stop attribute
*/
//--------------------------------------------------------
bool PIAxis::is_Stop_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Compare device state with not allowed states.
if (get_state()==Tango::ON ||
get_state()==Tango::OFF ||
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::StopStateAllowed) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::StopStateAllowed
return false;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_Backward_allowed()
* Description : Execution allowed for Backward attribute
*/
//--------------------------------------------------------
bool PIAxis::is_Backward_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Compare device state with not allowed states.
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::BackwardStateAllowed) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::BackwardStateAllowed
return false;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_Forward_allowed()
* Description : Execution allowed for Forward attribute
*/
//--------------------------------------------------------
bool PIAxis::is_Forward_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Compare device state with not allowed states.
if (get_state()==Tango::OFF ||
get_state()==Tango::MOVING ||
get_state()==Tango::FAULT ||
get_state()==Tango::INIT)
{
/*----- PROTECTED REGION ID(PIAxis::ForwardStateAllowed) ENABLED START -----*/
if (get_state()==Tango::FAULT && is_device_initialized())
{
return true;
}
/*----- PROTECTED REGION END -----*/ // PIAxis::ForwardStateAllowed
return false;
}
return true;
}
//--------------------------------------------------------
/**
* Method : PIAxis::is_InitialiseReferencePosition_allowed()
* Description : Execution allowed for InitialiseReferencePosition attribute
*/
//--------------------------------------------------------
bool PIAxis::is_InitialiseReferencePosition_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Compare device state with not allowed states.
if (get_state()==Tango::MOVING)
{
/*----- PROTECTED REGION ID(PIAxis::InitialiseReferencePositionStateAllowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // PIAxis::InitialiseReferencePositionStateAllowed
return false;
}
return true;
}
/*----- PROTECTED REGION ID(PIAxis::PIAxisStateAllowed.AdditionalMethods) ENABLED START -----*/
......
......@@ -14,7 +14,6 @@ namespace PIAxis_ns
{
yat::String Serializable::m_model = "Unkown";
int Serializable::m_axis_id = 1;
// ---------------- Command ---------------- //
......@@ -22,7 +21,7 @@ int Serializable::m_axis_id = 1;
// Command::pull_request()
// A command do not have a pull request
//----------------------------------------------------
yat::String Command::pull_request()
yat::String Command::pull_request(int axis_id)
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"This method is not available",
......@@ -33,7 +32,7 @@ yat::String Command::pull_request()
//----------------------------------------------------
// Command::extract()
//----------------------------------------------------
void Command::extract(yat::String str)
void Command::extract(yat::String str, int axis_id)
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"This method is not available",
......@@ -46,7 +45,7 @@ void Command::extract(yat::String str)
// Model::pull_request()
// Command to get the model of the controller
//----------------------------------------------------
yat::String Model::pull_request()
yat::String Model::pull_request(int axis_id)
{
return "*IDN?";
}
......@@ -56,23 +55,37 @@ yat::String Model::pull_request()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void Model::extract(yat::String str)
void Model::extract(yat::String str, int axis_id)
{
size_t pos = str.find("C-884");
if (pos != std::string::npos)
size_t pos_ctrl_884 = str.find("C-884");
if ( pos_ctrl_884 != std::string::npos)
{
m_value = str.substr(pos, 5);
m_value = str.substr(pos_ctrl_884, 5);
return;
}
size_t pos_ctrl_754 = str.find("E-754");
if(pos_ctrl_754 != std::string::npos)
{
m_value = str.substr(pos_ctrl_754, 5);
return;
}
size_t pos_ctrl_simu = str.find("SIMULATOR");
if(pos_ctrl_simu != std::string::npos )
{
m_value = "SIMULATOR";
return;
}
}
//----------------------------------------------------
// Model::push_request()
//----------------------------------------------------
yat::String Model::push_request()
yat::String Model::push_request(int axis_id)
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"This method is not available",
"Command::extract()");
"Model::push_request()");
return "";
}
......@@ -91,9 +104,9 @@ yat::String Model::get_value()
// On::pull_request()
// Command to get the servo mode
//----------------------------------------------------
yat::String On::pull_request()
yat::String On::pull_request(int axis_id)
{
return "SVO? " + yat::StringUtil::to_string(m_axis_id);
return "SVO? " + yat::StringUtil::to_string(axis_id);
}
//----------------------------------------------------
......@@ -101,7 +114,7 @@ yat::String On::pull_request()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void On::extract(yat::String str)
void On::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
......@@ -114,10 +127,9 @@ void On::extract(yat::String str)
// On::push_request()
// Command to set the servo mode to 1
//----------------------------------------------------
yat::String On::push_request()
yat::String On::push_request(int axis_id)
{
yat::String axis_id = yat::StringUtil::to_string(m_axis_id);
return "SVO " + axis_id + " 1";
return "SVO " + yat::StringUtil::to_string(axis_id) + " 1";
}
//----------------------------------------------------
......@@ -134,9 +146,9 @@ int On::get_value()
// Off::pull_request()
// Command to get the servo mode
//----------------------------------------------------
yat::String Off::pull_request()
yat::String Off::pull_request(int axis_id)
{
return "SVO? " + yat::StringUtil::to_string(m_axis_id);
return "SVO? " + yat::StringUtil::to_string(axis_id);
}
//----------------------------------------------------
......@@ -144,7 +156,7 @@ yat::String Off::pull_request()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void Off::extract(yat::String str)
void Off::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
......@@ -157,10 +169,9 @@ void Off::extract(yat::String str)
// Off::push_request()
// Command to set the servo mode to 0
//----------------------------------------------------
yat::String Off::push_request()
yat::String Off::push_request(int axis_id)
{
yat::String axis_id = yat::StringUtil::to_string(m_axis_id);
return "SVO " + axis_id + " 0";
return "SVO " + yat::StringUtil::to_string(axis_id) + " 0";
}
//----------------------------------------------------
......@@ -177,33 +188,39 @@ int Off::get_value()
// IsMoving::pull_request()
// Command to get the moving state of an axis
//----------------------------------------------------
yat::String IsMoving::pull_request()
yat::String IsMoving::pull_request(int axis_id)
{
if (m_model == "SIMULATOR")
{
/*yat::String cmd;
cdm = 5;
return cmd;*/
return "#5"; //Command for the MockServer
}
else
{
yat::String cmd;
cmd = 5;
return cmd;
}
}
//----------------------------------------------------
// IsMoving::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void IsMoving::extract(yat::String str)
void IsMoving::extract(yat::String str, int axis_id)
{
size_t state = yat::StringUtil::to_num<int>(str);
m_value = 1 & (state >> (m_axis_id - 1));
m_value = 1 & (state >> (axis_id - 1));
}
//----------------------------------------------------
// IsMoving::push_request()
//----------------------------------------------------
yat::String IsMoving::push_request()
yat::String IsMoving::push_request(int axis_id)
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"This method is not available",
"IsMoving::extract()");
"IsMoving::push_request()");
return "";
}
......@@ -215,4 +232,411 @@ int IsMoving::get_value()
return m_value;
}
// ---------------- Position ---------------- //
//----------------------------------------------------
// Position::pull_request()
// Command to get the moving state of an axis
//----------------------------------------------------
yat::String Position::pull_request(int axis_id)
{
return "POS? " + yat::StringUtil::to_string(axis_id);
}
//----------------------------------------------------
// Position::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void Position::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
{
m_value = yat::StringUtil::to_num<double>(str.substr(pos + 1, str.size() - 2));
}
}
//----------------------------------------------------
// Position::push_request()
//----------------------------------------------------
yat::String Position::push_request(int axis_id)
{
return "MOV " + yat::StringUtil::to_string(axis_id) + " " + yat::StringUtil::to_string(m_arg);
}
//----------------------------------------------------
// Position::get_value()
//----------------------------------------------------
double Position::get_value()
{
return m_value;
}
//----------------------------------------------------
// Position::set_value()
//----------------------------------------------------
void Position::set_value(double arg)
{
m_arg = arg;
}
// ---------------- Velocity ---------------- //
//----------------------------------------------------
// Velocity::pull_request()
// Command to get the moving state of an axis
//----------------------------------------------------
yat::String Velocity::pull_request(int axis_id)
{
return "VEL? " + yat::StringUtil::to_string(axis_id);
}
//----------------------------------------------------
// Velocity::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void Velocity::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
{
m_value = yat::StringUtil::to_num<double>(str.substr(pos + 1, str.size() - 2));
}
}
//----------------------------------------------------
// Velocity::push_request()
//----------------------------------------------------
yat::String Velocity::push_request(int axis_id)
{
return "VEL " + yat::StringUtil::to_string(axis_id) + " " + yat::StringUtil::to_string(m_arg);
}
//----------------------------------------------------
// Velocity::get_value()
//----------------------------------------------------
double Velocity::get_value()
{
return m_value;
}
//----------------------------------------------------
// Velocity::set_value()
//----------------------------------------------------
void Velocity::set_value(double arg)
{
m_arg = arg;
}
// ---------------- Acceleration ---------------- //
//----------------------------------------------------
// Acceleration::pull_request()
// Command to get the acceleration of an axis
//----------------------------------------------------
yat::String Acceleration::pull_request(int axis_id)
{
return "ACC? " + yat::StringUtil::to_string(axis_id);
}
//----------------------------------------------------
// Acceleration::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void Acceleration::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
{
m_value = yat::StringUtil::to_num<double>(str.substr(pos + 1, str.size() - 2));
}
}
//----------------------------------------------------
// Acceleration::push_request()
//----------------------------------------------------
yat::String Acceleration::push_request(int axis_id)
{
return "ACC " + yat::StringUtil::to_string(axis_id) + " " + yat::StringUtil::to_string(m_arg);
}
//----------------------------------------------------
// Acceleration::get_value()
//----------------------------------------------------
double Acceleration::get_value()
{
return m_value;
}
//----------------------------------------------------
// Acceleration::set_value()
//----------------------------------------------------
void Acceleration::set_value(double arg)
{
m_arg = arg;
}
// ---------------- Deceleration ---------------- //
//----------------------------------------------------
// Deceleration::pull_request()
// Command to get the deceleration of an axis
//----------------------------------------------------
yat::String Deceleration::pull_request(int axis_id)
{
return "DEC? " + yat::StringUtil::to_string(axis_id);
}
//----------------------------------------------------
// Deceleration::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void Deceleration::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
{
m_value = yat::StringUtil::to_num<double>(str.substr(pos + 1, str.size() - 2));
}
}
//----------------------------------------------------
// Deceleration::push_request()
//----------------------------------------------------
yat::String Deceleration::push_request(int axis_id)
{
return "DEC " + yat::StringUtil::to_string(axis_id) + " " + yat::StringUtil::to_string(m_arg);
}
//----------------------------------------------------
// Deceleration::get_value()
//----------------------------------------------------
double Deceleration::get_value()
{
return m_value;
}
//----------------------------------------------------
// Deceleration::set_value()
//----------------------------------------------------
void Deceleration::set_value(double arg)
{
m_arg = arg;
}
// ---------------- Stop ---------------- //
//----------------------------------------------------
// Stop::push_request()
// Command to stop the axis motion
//----------------------------------------------------
yat::String Stop::push_request(int axis_id)
{
return "HLT " + yat::StringUtil::to_string(axis_id);
}
// ---------------- Forward ---------------- //
//----------------------------------------------------
// Forward::push_request()
// Command to move to positive limit
//----------------------------------------------------
yat::String Forward::push_request(int axis_id)
{
yat::String return_str("");
if (m_model == "C-884" || m_model == "SIMULATOR")
{
return_str = "FPL " + yat::StringUtil::to_string(axis_id);
}
else
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"Command not handled for this device",
"Forward::push_request()");
}
return return_str;
}
// ---------------- Backward ---------------- //
//----------------------------------------------------
// Backward::push_request()
// Command to move to negative limit
//----------------------------------------------------
yat::String Backward::push_request(int axis_id)
{
yat::String return_str("");
if (m_model == "C-884" || m_model == "SIMULATOR")
{
return_str = "FNL " + yat::StringUtil::to_string(axis_id);
}
else if (m_model == "E-754")
{
return_str = "MOV " + yat::StringUtil::to_string(axis_id) + " 0";
}
else
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"Command not handled for this device",
"Backward::push_request()");
}
return return_str;
}
// ---------------- LimitSwitch ---------------- //
//----------------------------------------------------
// LimitSwitch::pull_request()
//----------------------------------------------------
yat::String LimitSwitch::pull_request(int axis_id)
{
return "SRG? " + yat::StringUtil::to_string(axis_id) + " 1";
}
//----------------------------------------------------
// LimitSwitch::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void LimitSwitch::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
{
m_value = std::strtol(str.substr(pos + 1, str.size() - 4).c_str(), NULL, 0);
}
}
//----------------------------------------------------
// LimitSwitch::push_request()
//----------------------------------------------------
yat::String LimitSwitch::push_request(int axis_id)
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"This method is not available",
"LimitSwitch::push_request()");
return "";
}
//----------------------------------------------------
// LimitSwitch::get_value()
//----------------------------------------------------
int LimitSwitch::get_value()
{
return m_value;
}
// ---------------- Ron ---------------- //
//----------------------------------------------------
// Ron::push_request()
// Command to move to negative limit
//----------------------------------------------------
yat::String Ron::push_request(int axis_id)
{
return "RON " + yat::StringUtil::to_string(axis_id) + " " + yat::StringUtil::to_string(m_value);
}
//----------------------------------------------------
// Ron::set_value()
//----------------------------------------------------
void Ron::set_value(int arg)
{
m_value = arg;
}
// ---------------- Pos ---------------- //
//----------------------------------------------------
// Pos::push_request()
// Command to move to negative limit
//----------------------------------------------------
yat::String Pos::push_request(int axis_id)
{
return "POS " + yat::StringUtil::to_string(axis_id) + " " + yat::StringUtil::to_string(m_value);
}
//----------------------------------------------------
// Pos::set_value()
//----------------------------------------------------
void Pos::set_value(double arg)
{
m_value = arg;
}
// ---------------- IsInitialized ---------------- //
//----------------------------------------------------
// IsInitialized::pull_request()
// Command to know is the device is initiliazed
//----------------------------------------------------
yat::String IsInitialized::pull_request(int axis_id)
{
yat::String return_str;
if (m_model == "C-884" || m_model == "SIMULATOR")
{
return_str = "FRF? " + yat::StringUtil::to_string(axis_id);
}
else if (m_model == "E-754")
{
return_str = "ATZ? " + yat::StringUtil::to_string(axis_id);
}
else
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"Command not handled for this device",
"Backward::push_request()");
}
return return_str;
}
//----------------------------------------------------
// IsInitialized::extract()
// Extract the information from the response to the
// pull request
//----------------------------------------------------
void IsInitialized::extract(yat::String str, int axis_id)
{
size_t pos = str.find("=");
if (pos != std::string::npos)
{
m_value = yat::StringUtil::to_num<int>(str.substr(pos + 1, str.size() - 2));
}
}
//----------------------------------------------------
// IsInitialized::push_request()
//----------------------------------------------------
yat::String IsInitialized::push_request(int axis_id)
{
Tango::Except::throw_exception("INTERNAL_ERROR",
"This method is not available",
"IsInitialized::push_request()");
return " ";
}
//----------------------------------------------------
// IsInitialized::get_value()
//----------------------------------------------------
bool IsInitialized::get_value()
{
return m_value;
}
// ---------------- AutoZero ---------------- //
//----------------------------------------------------
// AutoZero::push_request()
// Command to move to ZERO
//----------------------------------------------------
yat::String AutoZero::push_request(int axis_id)
{
return "ATZ " + yat::StringUtil::to_string(axis_id) + " NaN";
}
} // namespace PIAxis_ns
......@@ -18,8 +18,10 @@
#ifndef SERIALIZABLE_h
#define SERIALIZABLE_h
#include <stdlib.h>
#include <yat/utils/String.h>
namespace PIAxis_ns
{
//--------------------------------------------------------------------------------
......@@ -31,17 +33,15 @@ class Serializable
public:
//! \brief Create a request that need a response from the Hardware
virtual yat::String pull_request() = 0;
virtual yat::String pull_request(int axis_id) = 0;
//! \brief Extract the needed information from a yat::String
//! \param str: yat::String that contains the informations we need
virtual void extract(yat::String str) = 0;
virtual void extract(yat::String str, int axis_id) = 0;
//! \brief Create a request that do not need a response from the Hardware
virtual yat::String push_request() = 0;
virtual yat::String push_request(int axis_id) = 0;
//! \brief m_axis_id: ID of the PIAxis
static int m_axis_id;
//! \brief m_model: model of the controller
static yat::String m_model;
......@@ -50,16 +50,16 @@ public:
class Command : public Serializable
{
public:
yat::String pull_request();
void extract(yat::String str);
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
};
class Model : public Serializable
{
public:
yat::String pull_request();
void extract(yat::String str);
yat::String push_request();
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
yat::String get_value();
private:
......@@ -69,9 +69,9 @@ private:
class On : public Serializable
{
public:
yat::String pull_request();
void extract(yat::String str);
yat::String push_request();
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
int get_value();
private:
......@@ -81,9 +81,9 @@ private:
class Off : public Serializable
{
public:
yat::String pull_request();
void extract(yat::String str);
yat::String push_request();
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
int get_value();
private:
......@@ -93,15 +93,140 @@ private:
class IsMoving : public Serializable
{
public:
yat::String pull_request();
void extract(yat::String str);
yat::String push_request();
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
int get_value();
private:
int m_value;
};
class Position : public Serializable
{
public:
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
double get_value();
void set_value(double arg);
private:
double m_value;
double m_arg;
};
class Velocity : public Serializable
{
public:
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
double get_value();
void set_value(double arg);
private:
double m_value;
double m_arg;
};
class Acceleration : public Serializable
{
public:
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
double get_value();
void set_value(double arg);
private:
double m_value;
double m_arg;
};
class Deceleration : public Serializable
{
public:
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
double get_value();
void set_value(double arg);
private:
double m_value;
double m_arg;
};
class Stop : public Command
{
public:
yat::String push_request(int axis_id);
};
class Forward : public Command
{
public:
yat::String push_request(int axis_id);
};
class Backward : public Command
{
public:
yat::String push_request(int axis_id);
};
class Ron : public Command
{
public:
yat::String push_request(int axis_id);
void set_value(int arg);
private:
int m_value;
};
class Pos : public Command
{
public:
yat::String push_request(int axis_id);
void set_value(double arg);
private:
double m_value;
};
class LimitSwitch : public Serializable
{
public:
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
int get_value();
private:
int m_value;
};
class IsInitialized : public Serializable
{
public:
yat::String pull_request(int axis_id);
void extract(yat::String str, int axis_id);
yat::String push_request(int axis_id);
bool get_value();
private:
bool m_value;
};
class AutoZero : public Command
{
public:
yat::String push_request(int axis_id);
};
} // namespace PIAxis_ns
......
......@@ -18,10 +18,9 @@ namespace PIAxis_ns
// Serializer::push_to_server()
// Send a push request to the server
//----------------------------------------------------
void Serializer::push_to_server(Serializable* serial)
void Serializer::push_to_server(Serializable* serial, int axis_id)
{
yat::MutexLock scoped_lock(PIBox_ns::SocketManager::get_mutex());
yat::String request = serial->push_request() + "\n";
yat::String request = serial->push_request(axis_id) + "\n";
PIBox_ns::SocketManager::get_instance()->write(request);
error_handler();
}
......@@ -30,13 +29,12 @@ void Serializer::push_to_server(Serializable* serial)
// Serializer::pull_from_server()
// Send a pull request to the server
//----------------------------------------------------
void Serializer::pull_from_server(Serializable* serial)
void Serializer::pull_from_server(Serializable* serial, int axis_id)
{
yat::MutexLock scoped_lock(PIBox_ns::SocketManager::get_mutex());
yat::String request = serial->pull_request() + "\n";
yat::String request = serial->pull_request(axis_id) + "\n";
yat::String response = PIBox_ns::SocketManager::get_instance()->write_read(request);
error_handler();
serial->extract(response);
serial->extract(response, axis_id);
}
//----------------------------------------------------
......@@ -47,8 +45,25 @@ void Serializer::error_handler()
yat::String err = PIBox_ns::SocketManager::get_instance()->write_read("ERR?\n");
if (err[0] != '0')
{
yat::String desc = "Hardware error code: " + err;
if (err == "7\n")
{
desc += ": Position out of limits";
}
else if (err == "8\n")
{
desc += ": Velocity out of limits";
}
else if (err == "10\n")
{
desc += ": Controller was stopped by command";
}
else if (err == "17\n")
{
desc += ": Parameter out of range";
}
Tango::Except::throw_exception("HARDWARE_ERROR",
"Hardware error code: " + yat::StringUtil::to_string(err),
desc,
"Serializer::error_handler()");
}
}
......
......@@ -34,11 +34,11 @@ public:
//! \brief Push from device a request that do not need a response
//! \param serial: Serializable object
static void push_to_server(Serializable* serial);
static void push_to_server(Serializable* serial, int axis_id);
//! \brief Push from device a request that need a response from the server
//! \param serial: Serializable object
static void pull_from_server(Serializable* serial);
static void pull_from_server(Serializable* serial, int axis_id);
private:
//! \brief Ask for the error code from the server and handle it
......
......@@ -7,25 +7,31 @@
/*************************************************************************/
#include <yat/utils/Logging.h>
#include <yat/time/Time.h>
#include <yat4tango/LogHelper.h>
#include "BoxController.h"
#include "SocketManager.h"
#include <yat4tango/LogHelper.h>
namespace PIBox_ns
{
//----------------------------------------------------
// BoxController::BoxController()
//----------------------------------------------------
BoxController::BoxController(yat::String ip_address, int port, yat::StringDictionary dict, Tango::DeviceImpl* dev)
: Tango::LogAdapter(dev)
BoxController::BoxController(yat::String ip_address, int port, yat::StringDictionary dict_socket_config, yat::StringDictionary dict_historic_config, Tango::DeviceImpl* dev)
:yat4tango::DeviceTask(dev),
m_exec_low_level_cmd_out_value(""),
m_model(""),
m_dict_historic_config(dict_historic_config)
{
INFO_STREAM << "BoxController::BoxController()" << std::endl;
try
{
SocketManager::instantiate(ip_address, port, dict, dev);
SocketManager::instantiate(ip_address, port, dict_socket_config, dev);
PIBox_ns::SocketManager::get_instance()->write_read("ERR?\n"); // Catch the hardware turning on error
}
catch(const yat::Exception& e)
{
......@@ -38,6 +44,15 @@ BoxController::BoxController(yat::String ip_address, int port, yat::StringDictio
ERROR_STREAM << "Exception from - BoxController::BoxController() :\n"
<< error_msg.str() << std::endl;
}
//fix max size of allSocketMessages attribute
unsigned int max_logs = yat::StringUtil::to_num<unsigned int>(m_dict_historic_config.get("max").value_or("100"));
m_socket_messages_vect.resize(max_logs);
m_socket_messages_vect.clear();
enable_timeout_msg(false);
enable_periodic_msg(false);
set_periodic_msg_period(1000);
}
//----------------------------------------------------
......@@ -54,40 +69,20 @@ BoxController::~BoxController()
//----------------------------------------------------
yat::String BoxController::get_model()
{
yat::String request = "*IDN?\n";
yat::String model;
try
{
yat::MutexLock scoped_lock(PIBox_ns::SocketManager::get_mutex());
model = PIBox_ns::SocketManager::get_instance()->write_read(request);
}
catch(Tango::DevFailed& df)
{
set_state(Tango::FAULT);
set_status("Socket communication error" );
ERROR_STREAM << std::string(df.errors[0].desc) << endl;
}
catch(const yat::Exception& e)
{
set_state(Tango::FAULT);
set_status("Error while connecting the socket" );
std::stringstream cmd("*IDN?\n");
std::stringstream error_msg("");
error_msg << "Origin\t: " << e.errors[0].origin << std::endl;
error_msg << "Desc\t: " << e.errors[0].desc << std::endl;
error_msg << "Reason\t: " << e.errors[0].reason << std::endl;
ERROR_STREAM << "Exception from - BoxController::BoxController() :\n"
<< error_msg.str() << std::endl;
}
return model;
yat::Message* msg = yat::Message::allocate(EXEC_READ_MODEL_MSG, DEFAULT_MSG_PRIORITY, true);
msg->attach_data(cmd.str());
wait_msg_handled(msg, 5000);
return m_model;
}
//----------------------------------------------------
// BoxController::check_internal_state()
// BoxController::compute_state_status()
//----------------------------------------------------
void BoxController::check_internal_state()
void BoxController::compute_state_status()
{
yat::MutexLock scoped_lock(m_state_status_lock);
if (SocketManager::get_instance())
{
set_state(SocketManager::get_instance()->get_state());
......@@ -101,7 +96,7 @@ void BoxController::check_internal_state()
Tango::DevState BoxController::get_state()
{
yat::MutexLock scoped_lock(m_state_status_lock);
check_internal_state();
compute_state_status();
return m_state;
}
......@@ -117,7 +112,7 @@ void BoxController::set_state(Tango::DevState state)
//----------------------------------------------------
// BoxController::get_status()
//----------------------------------------------------
std::string BoxController::get_status()
yat::String BoxController::get_status()
{
yat::MutexLock scoped_lock(m_state_status_lock);
return (m_status_message.str());
......@@ -126,7 +121,7 @@ std::string BoxController::get_status()
//----------------------------------------------------
// BoxController::set_status()
//----------------------------------------------------
void BoxController::set_status(const std::string& status)
void BoxController::set_status(const yat::String& status)
{
yat::MutexLock scoped_lock(m_state_status_lock);
m_status_message.str("");
......@@ -136,61 +131,244 @@ void BoxController::set_status(const std::string& status)
//----------------------------------------------------
// BoxController::exec_low_level_cmd()
//----------------------------------------------------
void BoxController::exec_low_level_cmd(std::string cmd, std::string &outParam)
yat::String BoxController::exec_low_level_cmd(yat::String cmd)
{
INFO_STREAM << "BoxController::exec_low_level_cmd("<< cmd << ")" << std::endl;
yat::String out_param("");
std::stringstream cmd_ss("");
cmd_ss << cmd <<"\n";
yat::Message* msg = yat::Message::allocate(EXEC_LOW_LEVEL_CMD_MSG, DEFAULT_MSG_PRIORITY, true);
msg->attach_data(cmd_ss.str());
wait_msg_handled(msg, 5000);
out_param = m_exec_low_level_cmd_out_value;
DEBUG_STREAM << "BoxController::exec_low_level_cmd( " << cmd_ss << " ) => " << out_param << std::endl;
return out_param;
}
// ============================================================================
// BoxController::compute_socket_messages_logs
// ============================================================================
void BoxController::compute_socket_messages_logs()
{
DEBUG_STREAM << "BoxController::compute_socket_messages_logs()" << endl;
try
{
yat::MutexLock scoped_lock(PIBox_ns::SocketManager::get_mutex());
yat::String request = cmd + "\n";
yat::String error_code = 0;
std::vector<yat::String> socket_msg_vect = SocketManager::get_instance()->get_socket_msg();
for (size_t i = 0; i<socket_msg_vect.size(); i++)
{
yat::String socket_msg = socket_msg_vect[i];
//Remove new line character
size_t pos_new_line = socket_msg.find_first_of('\n');
if ( pos_new_line != std::string::npos)
{
socket_msg.resize(socket_msg.size () - (socket_msg.size () - pos_new_line));
}
if(socket_msg !="")
{
yat::String is_timestamp = m_dict_historic_config.get("timestamp").value_or("TRUE");
std::transform(is_timestamp.begin(), is_timestamp.end(), is_timestamp.begin(), ::toupper);
int start_pos = request.find('?', 0);
if( request.find('?', 0) != std::string::npos )
std::vector<std::string> parsed_args;
if(m_socket_messages_vect.size()!=0 && (is_timestamp == "TRUE"))
{
outParam = PIBox_ns::SocketManager::get_instance()->write_read(request).c_str();
yat::StringUtil::match(m_socket_messages_vect.at(0), "* - *", &parsed_args);
if(socket_msg == parsed_args.at(1))
{
return ;
}
}
else if ( request.find('#', 0) != std::string::npos )
yat::CurrentTime t;
yat::String date_format = m_dict_historic_config.get("format").value_or("%Y-%m-%dT%H:%M:%S");
std::stringstream socket_msg_timestamp("");
if(is_timestamp == "TRUE")
{
//request = 5 + "\n"; // /!\ Comment if testing on the mock /!\
outParam = PIBox_ns::SocketManager::get_instance()->write_read(request).c_str();
socket_msg_timestamp<<t.to_string(date_format, yat::Time::microsec)<<" - "<<socket_msg;
}
else
{
PIBox_ns::SocketManager::get_instance()->write(request);
outParam = "";
socket_msg_timestamp<<socket_msg;
}
DEBUG_STREAM << "BoxController::exec_low_level_cmd - outParam: " << outParam << std::endl;
m_socket_messages_vect.insert(m_socket_messages_vect.begin(), socket_msg_timestamp.str());
unsigned int max_logs = yat::StringUtil::to_num<unsigned int>(m_dict_historic_config.get("max").value_or("100"));
if(m_socket_messages_vect.size() > max_logs)//in order to keep a max logs only in the attribute
{
m_socket_messages_vect.erase(m_socket_messages_vect.end()-1);
}
catch(Tango::DevFailed &df)
}
}
}
catch (yat::Exception& ex)
{
set_state(Tango::FAULT);
set_status("Socket communication error");
ERROR_STREAM << string(ex.errors[0].desc).c_str() << std::endl;
std::stringstream error_msg("");
error_msg << "Origin: " << ex.errors[0].origin << std::endl;
error_msg << "Desc: " << ex.errors[0].desc << std::endl;
error_msg << "Reason: " << ex.errors[0].reason << std::endl;
ERROR_STREAM << std::string(df.errors[0].desc) << endl;
THROW_DEVFAILED("TANGO_DEVICE_ERROR",
string(ex.errors[0].desc).c_str(),
"BoxController::compute_socket_messages_logs");
}
catch(const yat::Exception& e)
}
// ============================================================================
// BoxController::get_socket_messages
// ============================================================================
vector<yat::String>& BoxController::get_socket_messages()
{
set_state(Tango::FAULT);
set_status("Error while connecting the socket");
return m_socket_messages_vect;
}
//----------------------------------------------------
// BoxController::process_message()
//----------------------------------------------------
void BoxController::process_message(yat::Message& msg)
{
try
{
switch(msg.type())
{
case yat::TASK_INIT:
{
INFO_STREAM << "BoxController::process_message::TASK_INIT" << std::endl;
enable_periodic_msg(true);
}
break;
case EXEC_READ_MODEL_MSG:
{
yat::String request = msg.get_data<std::string>();
yat::String model_temp = PIBox_ns::SocketManager::get_instance()->write_read(request);
size_t pos_new_line = model_temp.find_first_of('\n');
if ( pos_new_line != std::string::npos)
{
model_temp.resize(model_temp.size () - (model_temp.size () - pos_new_line));
}
m_model = model_temp;
}
break;
case EXEC_LOW_LEVEL_CMD_MSG:
{
INFO_STREAM << "BoxController::process_message::EXEC_LOW_LEVEL_CMD_MSG " << std::endl;
m_exec_low_level_cmd_out_value = "";
yat::String cmd = msg.get_data<std::string>();
if( cmd.find('?', 0) != std::string::npos )
{
m_exec_low_level_cmd_out_value = PIBox_ns::SocketManager::get_instance()->write_read(cmd);
}
else if ( cmd.find('#', 0) != std::string::npos )
{
INFO_STREAM << "BoxController::process_message::EXEC_LOW_LEVEL_CMD_MSG -m_model = " << m_model << std::endl;
yat::String::size_type pos = m_model.find("SIMULATOR");
if(pos != std::string::npos)
{
DEBUG_STREAM << "BoxController::process_message::EXEC_LOW_LEVEL_CMD_MSG - IN SIMULATOR MODE" << std::endl;
}
else
{
cmd = 5;
cmd = cmd + '\n';
DEBUG_STREAM << "BoxController::process_message::EXEC_LOW_LEVEL_CMD_MSG - NEW CMD: " << cmd << std::endl;
}
m_exec_low_level_cmd_out_value = PIBox_ns::SocketManager::get_instance()->write_read(cmd);
}
else
{
PIBox_ns::SocketManager::get_instance()->write(cmd);
}
}
break;
case yat::TASK_PERIODIC:
{
DEBUG_STREAM << "BoxController::process_message::TASK_PERIODIC" << std::endl;
compute_socket_messages_logs();
}
break;
case yat::TASK_EXIT:
{
INFO_STREAM << "BoxController::process_message::TASK_EXIT" << std::endl;
}
break;
case yat::TASK_TIMEOUT:
{
INFO_STREAM << "BoxController::process_message::TASK_EXIT" << std::endl;
}
break;
default:
{
INFO_STREAM << "BoxController::process_message - Unhandled msg type!" << std::endl;
}
break;
}
}
catch(Tango::DevFailed& df)
{
on_fault(df);
ERROR_STREAM << "BoxController::process_message - Tango::DevFailed exception: " << yat::String(df.errors[0].desc) << std::endl;
}
catch (const yat::SocketException & se)
{
std::stringstream error_msg("");
error_msg << "Origin\t: " << e.errors[0].origin << std::endl;
error_msg << "Desc\t: " << e.errors[0].desc << std::endl;
error_msg << "Reason\t: " << e.errors[0].reason << std::endl;
ERROR_STREAM << "Exception from - BoxController::exec_low_level_cmd() :\n" << error_msg.str() << std::endl;
error_msg << "Origin\t: " << se.errors[0].origin << std::endl;
error_msg << "Desc\t: " << se.errors[0].desc << std::endl;
error_msg << "Reason\t: " << se.errors[0].reason << std::endl;
ERROR_STREAM << "BoxController::process_message - yat::SocketException: " << error_msg.str() << std::endl;
on_fault(error_msg.str());
}
catch(...)
catch (yat::Exception& ex)
{
set_state(Tango::FAULT);
set_status("Caught unknown exception");
std::stringstream error_msg("");
error_msg << "Origin: " << ex.errors[0].origin << std::endl;
error_msg << "Desc: " << ex.errors[0].desc << std::endl;
error_msg << "Reason: " << ex.errors[0].reason << std::endl;
ERROR_STREAM << m_status_message.str() << std::endl;
Tango::Except::throw_exception("DEVICE_ERROR",
"Failed to send low level cmd - Caught unknown exception!",
"BoxController::exec_low_level_cmd");
ERROR_STREAM << "BoxController::process_message - Exception from SocketManager() : " << error_msg.str() << std::endl;
on_fault(error_msg.str());
}
}
// ============================================================================
// BoxController::on_fault(Tango::DevFailed df)
// ============================================================================
void BoxController::on_fault(Tango::DevFailed df)
{
std::stringstream status;
status.str("");
status << "Origin\t: " << df.errors[0].origin << std::endl;
status << "Desc\t: " << df.errors[0].desc << std::endl;
status << "Reason\t: " << df.errors[0].reason << std::endl;
ERROR_STREAM << "BoxController::on_fault(Tango::DevFailed) => " << status.str() << std::endl;
set_status(status.str());
set_state(Tango::FAULT);
}
// ============================================================================
// BoxController::on_fault(const yat::String& error_str)
// ============================================================================
void BoxController::on_fault(const yat::String& error_str)
{
ERROR_STREAM << "BoxController::on_fault(Tango::DevFailed) => " << error_str << std::endl;
set_state(Tango::FAULT);
set_status(error_str);
}
} // namespace PIBox_ns
......@@ -23,15 +23,20 @@
#include <yat/utils/String.h>
#include <yat/utils/Dictionary.h>
#include <yat4tango/DeviceTask.h>
#include <sstream>
const size_t EXEC_LOW_LEVEL_CMD_MSG = yat::FIRST_USER_MSG + 100;
const size_t EXEC_READ_MODEL_MSG = yat::FIRST_USER_MSG + 110;
namespace PIBox_ns
{
//--------------------------------------------------------------------------------
//! \class BoxController
//! \brief class Controller
//--------------------------------------------------------------------------------
class BoxController : public Tango::LogAdapter
class BoxController : public yat4tango::DeviceTask
{
public:
......@@ -40,7 +45,7 @@ public:
//! \param ip_address: yat::String in the format 192.168.0.1
//! \param port: int that represent the port
//! \param dict: yat::StringDictionary that contains the Socket options
BoxController(yat::String ip_address, int port, yat::StringDictionary dict, Tango::DeviceImpl* dev);
BoxController(yat::String ip_address, int port, yat::StringDictionary dict_socket_config, yat::StringDictionary dict_historic_config, Tango::DeviceImpl* dev);
//! \brief Destructor
~BoxController();
......@@ -48,26 +53,43 @@ public:
//! \brief Get Hardware Model
yat::String get_model();
//! \brief check status of the socket
void check_internal_state();
//! \brief compute state and status of the Box controller
void compute_state_status();
//! \brief get internal state of PIBox
//! \brief get the state of the Box controller
Tango::DevState get_state();
//! \brief set the state of the Box controller
void set_state(Tango::DevState state);
//! \brief get internal status of PIBox
std::string get_status();
void set_status(const std::string& status);
//! \brief get the status of the Box controller
yat::String get_status();
//! \brief set the status of the Box controller
void set_status(const yat::String& status);
//! \brief Executes a low level command.
//! \param cmd The low level command
//! \param outParam Command reply
void exec_low_level_cmd(std::string cmd, std::string &outParam);
yat::String exec_low_level_cmd(yat::String cmd);
//! \brief get the list of the socket exchanged messages
vector<yat::String>& get_socket_messages();
private:
//! \brief DeviceTask pure virtual method implementation: the yat messages handler
//! \param msg Message to handle.
virtual void process_message(yat::Message& msg);
//! \brief Manage catch Tango::DevFailed error block
void on_fault(Tango::DevFailed df);
//! \brief Manage catch yat::String error block
void on_fault(const yat::String& error_str);
//! \brief Compute the socket messages logs
void compute_socket_messages_logs();
//! \brief m_state: internal state of PIBox
Tango::DevState m_state;
......@@ -77,6 +99,18 @@ private:
//! \brief m_state_lock: Mutex used to protect state and status access
yat::Mutex m_state_status_lock;
//! \brief m_exec_low_level_cmd_out_value: Returned request value
yat::String m_exec_low_level_cmd_out_value;
//! \brief m_model: Hardware model value
yat::String m_model;
//! \brief m_socket_messages_vect: history of socket messages
std::vector<yat::String> m_socket_messages_vect;
//! \brief yat::StringDictionary that contains the list of the socket exchanged requests
yat::StringDictionary m_dict_historic_config;
};
} // namespace PIBox_ns
......
......@@ -35,6 +35,7 @@
#include <PIBox.h>
#include <PIBoxClass.h>
#include <helpers/PogoHelper.h>
#include <yat4tango/PropertyHelper.h>
#define MAX_ATTRIBUTE_STRING_LENGTH 256
......@@ -58,9 +59,10 @@
//================================================================
//================================================================
// Attributes managed is:
// Attributes managed are:
//================================================================
// model | Tango::DevString Scalar
// allSocketMessages | Tango::DevString Spectrum ( max = 1024)
//================================================================
namespace PIBox_ns
......@@ -113,17 +115,15 @@ PIBox::PIBox(Tango::DeviceClass *cl, const char *s, const char *d)
//--------------------------------------------------------
void PIBox::delete_device()
{
DEBUG_STREAM << "PIBox::delete_device() " << device_name << endl;
/*----- PROTECTED REGION ID(PIBox::delete_device) ENABLED START -----*/
INFO_STREAM << "PIBox::delete_device() " << device_name << std::endl;
DELETE_DEVSTRING_ATTRIBUTE(attr_model_read);
// Delete device allocated objects
if (m_box_controller != NULL)
{
delete m_box_controller;
m_box_controller = NULL;
}
m_box_controller.reset();
// Delete device allocated objects
DEBUG_STREAM << "Remove the YatLogAdapter." << std::endl;
......@@ -146,13 +146,13 @@ void PIBox::delete_device()
//--------------------------------------------------------
void PIBox::init_device()
{
DEBUG_STREAM << "PIBox::init_device() create device " << device_name << endl;
/*----- PROTECTED REGION ID(PIBox::init_device_before) ENABLED START -----*/
INFO_STREAM << "PIBox::init_device() create device " << device_name << std::endl;
// Initialization before get_device_property() call
set_state(Tango::INIT);
m_is_device_initialized = false;
m_status_message.str("Initialization in progress...");
//- instanciate the appender in order to manage logs
INFO_STREAM << "Create the inner-appender in order to manage logs." << std::endl;
......@@ -176,14 +176,14 @@ void PIBox::init_device()
CREATE_DEVSTRING_ATTRIBUTE(attr_model_read, MAX_ATTRIBUTE_STRING_LENGTH);
yat::StringDictionary dict_args;
yat::StringDictionary dict_socket_config;
{
if(socketConfig.size() > 0)
{
std::transform(socketConfig.begin(), socketConfig.end(), socketConfig.begin(), ::tolower);
dict_args = yat::StringDictionary(socketConfig,';', '=');
dict_socket_config = yat::StringDictionary(socketConfig,';', '=');
}
if(dict_args.size() != 5)
if(dict_socket_config.size() != 5)
{
std::stringstream ss("");
ss << "Parameter(s) of the Socket Configuration property are missing!" ;
......@@ -194,12 +194,27 @@ void PIBox::init_device()
}
}
try
yat::StringDictionary dict_historic_config;
{
if (m_box_controller == NULL)
if(historicSocketMessagesConfig.size() > 0)
{
m_box_controller = new BoxController(iPAddress, tCPPort, dict_args, this);
dict_historic_config = yat::StringDictionary(historicSocketMessagesConfig,';', '=');
}
if(dict_historic_config.size() != 3)
{
std::stringstream ss("");
ss << "Parameter(s) of the Historic Socket Messages Configuration property are missing!" ;
ERROR_STREAM << ss.str() << std::endl;;
m_status_message << "Initialization Failed : " << ss.str() << std::endl;
return;
}
}
try
{
m_box_controller.reset(new BoxController(iPAddress, tCPPort, dict_socket_config, dict_historic_config, this));
m_box_controller->go();
}
catch(Tango::DevFailed& df)
{
......@@ -245,6 +260,7 @@ void PIBox::get_device_property()
dev_prop.push_back(Tango::DbDatum("IPAddress"));
dev_prop.push_back(Tango::DbDatum("TCPPort"));
dev_prop.push_back(Tango::DbDatum("SocketConfig"));
dev_prop.push_back(Tango::DbDatum("HistoricSocketMessagesConfig"));
// is there at least one property to be read ?
if (dev_prop.size()>0)
......@@ -292,6 +308,17 @@ void PIBox::get_device_property()
// And try to extract SocketConfig value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> socketConfig;
// Try to initialize HistoricSocketMessagesConfig from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> historicSocketMessagesConfig;
else {
// Try to initialize HistoricSocketMessagesConfig from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> historicSocketMessagesConfig;
}
// And try to extract HistoricSocketMessagesConfig value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> historicSocketMessagesConfig;
}
/*----- PROTECTED REGION ID(PIBox::get_device_property_after) ENABLED START -----*/
......@@ -300,7 +327,7 @@ void PIBox::get_device_property()
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, "172.16.4.37", "IPAddress");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, "50000", "TCPPort");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, "blocking = true; keepalive = true; nodelay = true; sndtmo = 1000; rcvtmo = 1000", "SocketConfig");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, "max = 10; timestamp = true; format = %Y-%m-%dT%H:%M:%S", "HistoricSocketMessagesConfig");
/*----- PROTECTED REGION END -----*/ // PIBox::get_device_property_after
}
......@@ -312,6 +339,7 @@ void PIBox::get_device_property()
//--------------------------------------------------------
void PIBox::always_executed_hook()
{
//DEBUG_STREAM << "PIBox::always_executed_hook() " << device_name << endl;
/*----- PROTECTED REGION ID(PIBox::always_executed_hook) ENABLED START -----*/
// code always executed before all requests
......@@ -323,7 +351,6 @@ void PIBox::always_executed_hook()
{
m_status_message << "Initialization Failed : " << string(df.errors[0].desc) << std::endl;
ERROR_STREAM << m_status_message.str() << std::endl;
m_is_device_initialized = false;
set_state(Tango::FAULT);
//- rethrow exception
......@@ -343,6 +370,7 @@ void PIBox::always_executed_hook()
//--------------------------------------------------------
void PIBox::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
{
//DEBUG_STREAM << "PIBox::read_attr_hardware(vector<long> &attr_list) entering... " << endl;
/*----- PROTECTED REGION ID(PIBox::read_attr_hardware) ENABLED START -----*/
// Add your own code
......@@ -361,7 +389,7 @@ void PIBox::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
//--------------------------------------------------------
void PIBox::read_model(Tango::Attribute &attr)
{
DEBUG_STREAM << "PIBox::read_model(Tango::Attribute &attr) entering... " << endl;
//DEBUG_STREAM << "PIBox::read_model(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(PIBox::read_model) ENABLED START -----*/
// Set the attribute value
yat::String model = m_box_controller->get_model();
......@@ -370,6 +398,42 @@ void PIBox::read_model(Tango::Attribute &attr)
/*----- PROTECTED REGION END -----*/ // PIBox::read_model
}
//--------------------------------------------------------
/**
* Read attribute allSocketMessages related method
* Description: Gets history of the exchanged requests through the socket
*
* Data type: Tango::DevString
* Attr type: Spectrum max = 1024
*/
//--------------------------------------------------------
void PIBox::read_allSocketMessages(Tango::Attribute &attr)
{
//DEBUG_STREAM << "PIBox::read_allSocketMessages(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(PIBox::read_allSocketMessages) ENABLED START -----*/
// Set the attribute value
try
{
Tango::DevString *ptr_array = new Tango::DevString [m_box_controller->get_socket_messages().size()];
for(size_t i = 0;i < m_box_controller->get_socket_messages().size();i++)
{
ptr_array[i] = Tango::string_dup(m_box_controller->get_socket_messages()[i].c_str());
}
attr.set_value(ptr_array, m_box_controller->get_socket_messages().size(), 0, true);
}
catch(Tango::DevFailed& df)
{
ERROR_STREAM << df << endl;
//- rethrow exception
Tango::Except::re_throw_exception(df,
"TANGO_DEVICE_ERROR",
string(df.errors[0].desc).c_str(),
"PIBox::read_allSocketMessages()");
}
/*----- PROTECTED REGION END -----*/ // PIBox::read_allSocketMessages
}
//--------------------------------------------------------
/**
......@@ -405,13 +469,27 @@ Tango::DevState PIBox::dev_state()
if (!m_is_device_initialized)
{
argout = Tango::FAULT;
if(!m_box_controller)
{
set_status(m_status_message.str());
}
else
{
set_status(m_box_controller->get_status());
}
}
else
{
if(m_box_controller->get_state() == Tango::FAULT)
{
m_is_device_initialized = false;
}
else
{
argout = m_box_controller->get_state();
set_status(m_box_controller->get_status());
}
}
/*----- PROTECTED REGION END -----*/ // PIBox::dev_state
set_state(argout); // Give the state to Tango.
if (argout!=Tango::ALARM)
......@@ -432,20 +510,19 @@ Tango::DevString PIBox::exec_low_level_command(Tango::DevString argin)
Tango::DevString argout;
DEBUG_STREAM << "PIBox::ExecLowLevelCommand() - " << device_name << endl;
/*----- PROTECTED REGION ID(PIBox::exec_low_level_command) ENABLED START -----*/
INFO_STREAM << "PIBox::exec_low_level_command() - " << device_name << std::endl;
// Add your own code
std::string argin_str(argin);
std::string argout_str;
try
{
m_box_controller->exec_low_level_cmd(argin_str, argout_str);
argout_str = m_box_controller->exec_low_level_cmd(argin_str);
}
catch (Tango::DevFailed &df)
{
m_status_message << "exec_low_lovel_command Failed : " << string(df.errors[0].desc) << std::endl;
ERROR_STREAM << m_status_message.str() << std::endl;
m_is_device_initialized = false;
set_state(Tango::FAULT);
Tango::Except::re_throw_exception(df,
......@@ -457,7 +534,6 @@ Tango::DevString PIBox::exec_low_level_command(Tango::DevString argin)
{
m_status_message << "exec_low_lovel_command Failed : Caught unknown exception" << std::endl;
ERROR_STREAM << m_status_message.str() << std::endl;
m_is_device_initialized = false;
set_state(Tango::FAULT);
Tango::Except::throw_exception("TANGO_DEVICE_ERROR",
......@@ -471,7 +547,7 @@ Tango::DevString PIBox::exec_low_level_command(Tango::DevString argin)
::memset(argout, 0, len);
::memcpy(argout, argout_str.c_str(), len);
DEBUG_STREAM << " PIBox::exec_low_lovel_command - cmd answer = " << argout << std::endl;
DEBUG_STREAM << " PIBox::exec_low_lovel_command - returned value = " << argout << std::endl;
/*----- PROTECTED REGION END -----*/ // PIBox::exec_low_level_command
return argout;
}
......
......@@ -34,11 +34,11 @@
#define PIBox_H
#include <tango.h>
#include <helpers/PogoHelper.h>
#include "BoxController.h"
#include <yat/utils/Dictionary.h>
#include <yat/memory/UniquePtr.h>
#include <yat4tango/InnerAppender.h>
#include <yat4tango/YatLogAdapter.h>
#include <yat4tango/DeviceInfo.h>
......@@ -64,7 +64,9 @@ class PIBox : public TANGO_BASE_CLASS
/*----- PROTECTED REGION ID(PIBox::Data Members) ENABLED START -----*/
// Add your own data members
BoxController* m_box_controller;
//! \brief m_box_controller: the BoxController object
yat::UniquePtr<BoxController, yat4tango::DeviceTaskExiter> m_box_controller;
/*----- PROTECTED REGION END -----*/ // PIBox::Data Members
// Device property data members
......@@ -91,10 +93,13 @@ public:
// The Receiver Timeout parameter:<BR>
// Sets the timeuot value specifying the maximum amount of time that an input function waits untils its completes.[in ms]<BR>
string socketConfig;
// HistoricSocketMessagesConfig: Configuration of the socket log system
string historicSocketMessagesConfig;
// Attribute data members
public:
Tango::DevString *attr_model_read;
Tango::DevString *attr_allSocketMessages_read;
// Constructors and destructors
public:
......@@ -165,6 +170,15 @@ public:
*/
virtual void read_model(Tango::Attribute &attr);
virtual bool is_model_allowed(Tango::AttReqType type);
/**
* Attribute allSocketMessages related methods
* Description: Gets history of the exchanged requests through the socket
*
* Data type: Tango::DevString
* Attr type: Spectrum max = 1024
*/
virtual void read_allSocketMessages(Tango::Attribute &attr);
virtual bool is_allSocketMessages_allowed(Tango::AttReqType type);
//--------------------------------------------------------
......
<?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="PIBox" pogoRevision="9.6">
<description description="" title="" sourcePath="/home/informatique/ica/desgrangesm/workspace/picontroller/src/pibox" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<description description="" title="" sourcePath="/home/informatique/ica/bahji/Repositories_Dev/PIController/picontroller/src/pibox" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at synchrotron-soleil.fr - marc.desganges" author="marc.desganges" emailDomain="synchrotron-soleil.fr" classFamily="Motion" siteSpecific="" platform="All Platforms" bus="TCP/UDP" manufacturer="none" reference=""/>
</description>
......@@ -20,6 +20,11 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>blocking = true;keepalive = true;nodelay = true;sndtmo = 1000;rcvtmo = 1000</DefaultPropValue>
</deviceProperties>
<deviceProperties name="HistoricSocketMessagesConfig" description="Configuration of the socket log system">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>max = 100; timestamp = true; format = %Y-%m-%dT%H:%M:%S</DefaultPropValue>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
<argin description="none">
<type xsi:type="pogoDsl:VoidType"/>
......@@ -57,6 +62,14 @@
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
<readExcludedStates>FAULT</readExcludedStates>
</attributes>
<attributes name="allSocketMessages" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="1024" maxY="" allocReadMember="false" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Gets history of the exchanged requests through the socket" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<states name="ON" description="Connected to Server TCP/IP">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
......
......@@ -278,6 +278,20 @@ void PIBoxClass::set_default_property()
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "HistoricSocketMessagesConfig";
prop_desc = "Configuration of the socket log system";
prop_def = "max = 100; timestamp = true; format = %Y-%m-%dT%H:%M:%S";
vect_data.clear();
vect_data.push_back("max = 100; timestamp = true; format = %Y-%m-%dT%H:%M:%S");
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);
}
//--------------------------------------------------------
......@@ -432,6 +446,30 @@ void PIBoxClass::attribute_factory(vector<Tango::Attr *> &att_list)
// Not Memorized
att_list.push_back(model);
// Attribute : allSocketMessages
allSocketMessagesAttrib *allsocketmessages = new allSocketMessagesAttrib();
Tango::UserDefaultAttrProp allsocketmessages_prop;
allsocketmessages_prop.set_description("Gets history of the exchanged requests through the socket");
// label not set for allSocketMessages
// unit not set for allSocketMessages
// standard_unit not set for allSocketMessages
// display_unit not set for allSocketMessages
// format not set for allSocketMessages
// max_value not set for allSocketMessages
// min_value not set for allSocketMessages
// max_alarm not set for allSocketMessages
// min_alarm not set for allSocketMessages
// max_warning not set for allSocketMessages
// min_warning not set for allSocketMessages
// delta_t not set for allSocketMessages
// delta_val not set for allSocketMessages
allsocketmessages->set_default_properties(allsocketmessages_prop);
// Not Polled
allsocketmessages->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(allsocketmessages);
// Create a list of static attributes
create_static_attribute_list(get_class_attr()->get_attr_list());
......
......@@ -67,6 +67,19 @@ public:
{return (static_cast<PIBox *>(dev))->is_model_allowed(ty);}
};
// Attribute allSocketMessages class definition
class allSocketMessagesAttrib: public Tango::SpectrumAttr
{
public:
allSocketMessagesAttrib():SpectrumAttr("allSocketMessages",
Tango::DEV_STRING, Tango::READ, 1024) {};
~allSocketMessagesAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<PIBox *>(dev))->read_allSocketMessages(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<PIBox *>(dev))->is_allSocketMessages_allowed(ty);}
};
//=========================================
// Define classes for commands
......