1 static const char *RcsId
= "$Header: /cvsroot/tango-ds/Instrumentation/Diffractometer/src/pseudoaxis/PseudoAxisClass.cpp,v 1.3 2008/09/24 08:37:48 piccaf Exp $";
2 static const char *TagName
= "$Name: $";
3 static const char *HttpServer
= "http://www.esrf.fr/computing/cs/tango/tango_doc/ds_doc/";
4 //+=============================================================================
6 // file : PseudoAxisClass.cpp
8 // description : C++ source for the PseudoAxisClass. A singleton
9 // class derived from DeviceClass. It implements the
10 // command list and all properties and methods required
11 // by the PseudoAxis once per process.
13 // project : TANGO Device Server
19 // $Log: PseudoAxisClass.cpp,v $
20 // Revision 1.3 2008/09/24 08:37:48 piccaf
21 // * add dummy commandes for the Axis V2 interface
23 // Revision 1.2 2008/09/22 08:46:40 piccaf
24 // * add files from the new diffractometer Device
26 // Revision 1.3 2007/07/11 07:19:27 picca
27 // * add the "offset" and the "relativeMove" attributes to the PseudoAxes.
28 // * syntax in Kappa6C
30 // Revision 1.2 2007/05/15 08:26:58 hardion
31 // * Merge with branch DIFFRACTO_KAPPA_6C
33 // Revision 1.1.2.2 2007/02/19 13:14:48 hardion
34 // * compil with rhel and test on cristal beamline
36 // Revision 1.1.2.1 2006/08/25 15:08:22 hardion
37 // * Merge corrections of hubert
38 // * Create directory for each class of device
39 // * Fix problem when PseudoAxis is initialized on first
40 // * Tested on diffabs for the communication part
42 // Revision 1.2 2006/07/06 10:29:44 hardion
43 // * commit to keep modification about Pseudo axis management but it doesn't work ( Error Check the wavelength)
44 // try to come back to old version to see if the problem persists
46 // Revision 1.1 2006/03/29 16:45:47 hardion
47 // * Add PseudoAxis device
48 // * Add DiffractometerFactory which associates Diffracto and PseudoAxis
51 // copyleft : European Synchrotron Radiation Facility
52 // BP 220, Grenoble 38043
55 //-=============================================================================
57 // This file is generated by POGO
58 // (Program Obviously used to Generate tango Object)
60 // (c) - Software Engineering Group - ESRF
61 //=============================================================================
66 #include <PseudoAxis.h>
67 #include <PseudoAxisClass.h>
70 namespace PseudoAxis_ns
72 //+----------------------------------------------------------------------------
74 // method : SetModeParametersClass::execute()
76 // description : method to trigger the execution of the command.
77 // PLEASE DO NOT MODIFY this method core without pogo
79 // in : - device : The device on which the command must be excuted
80 // - in_any : The command input data
82 // returns : The command output data (packed in the Any object)
84 //-----------------------------------------------------------------------------
85 CORBA::Any
*SetModeParametersClass::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
88 cout2
<< "SetModeParametersClass::execute(): arrived" << endl
;
90 const Tango::DevVarDoubleStringArray
*argin
;
91 extract(in_any
, argin
);
93 ((static_cast<PseudoAxis
*>(device
))->set_mode_parameters(argin
));
94 return new CORBA::Any();
97 //+----------------------------------------------------------------------------
99 // method : GetModeParametersClass::execute()
101 // description : method to trigger the execution of the command.
102 // PLEASE DO NOT MODIFY this method core without pogo
104 // in : - device : The device on which the command must be excuted
105 // - in_any : The command input data
107 // returns : The command output data (packed in the Any object)
109 //-----------------------------------------------------------------------------
110 CORBA::Any
*GetModeParametersClass::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
113 cout2
<< "GetModeParametersClass::execute(): arrived" << endl
;
115 return insert((static_cast<PseudoAxis
*>(device
))->get_mode_parameters());
118 //+----------------------------------------------------------------------------
120 // method : InitializeReferencePositionCmd::execute()
122 // description : method to trigger the execution of the command.
123 // PLEASE DO NOT MODIFY this method core without pogo
125 // in : - device : The device on which the command must be excuted
126 // - in_any : The command input data
128 // returns : The command output data (packed in the Any object)
130 //-----------------------------------------------------------------------------
131 CORBA::Any
*InitializeReferencePositionCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
134 cout2
<< "InitializeReferencePositionCmd::execute(): arrived" << endl
;
136 ((static_cast<PseudoAxis
*>(device
))->initialize_reference_position());
137 return new CORBA::Any();
140 //+----------------------------------------------------------------------------
142 // method : DefinePositionCmd::execute()
144 // description : method to trigger the execution of the command.
145 // PLEASE DO NOT MODIFY this method core without pogo
147 // in : - device : The device on which the command must be excuted
148 // - in_any : The command input data
150 // returns : The command output data (packed in the Any object)
152 //-----------------------------------------------------------------------------
153 CORBA::Any
*DefinePositionCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
156 cout2
<< "DefinePositionCmd::execute(): arrived" << endl
;
158 Tango::DevDouble argin
;
159 extract(in_any
, argin
);
161 ((static_cast<PseudoAxis
*>(device
))->define_position(argin
));
162 return new CORBA::Any();
165 //+----------------------------------------------------------------------------
167 // method : ForwardCmd::execute()
169 // description : method to trigger the execution of the command.
170 // PLEASE DO NOT MODIFY this method core without pogo
172 // in : - device : The device on which the command must be excuted
173 // - in_any : The command input data
175 // returns : The command output data (packed in the Any object)
177 //-----------------------------------------------------------------------------
178 CORBA::Any
*ForwardCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
181 cout2
<< "ForwardCmd::execute(): arrived" << endl
;
183 ((static_cast<PseudoAxis
*>(device
))->forward());
184 return new CORBA::Any();
187 //+----------------------------------------------------------------------------
189 // method : BackwardClass::execute()
191 // description : method to trigger the execution of the command.
192 // PLEASE DO NOT MODIFY this method core without pogo
194 // in : - device : The device on which the command must be excuted
195 // - in_any : The command input data
197 // returns : The command output data (packed in the Any object)
199 //-----------------------------------------------------------------------------
200 CORBA::Any
*BackwardClass::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
203 cout2
<< "BackwardClass::execute(): arrived" << endl
;
205 ((static_cast<PseudoAxis
*>(device
))->backward());
206 return new CORBA::Any();
209 //+----------------------------------------------------------------------------
211 // method : MotorInitCmd::execute()
213 // description : method to trigger the execution of the command.
214 // PLEASE DO NOT MODIFY this method core without pogo
216 // in : - device : The device on which the command must be excuted
217 // - in_any : The command input data
219 // returns : The command output data (packed in the Any object)
221 //-----------------------------------------------------------------------------
222 CORBA::Any
*MotorInitCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
225 cout2
<< "MotorInitCmd::execute(): arrived" << endl
;
227 ((static_cast<PseudoAxis
*>(device
))->motor_init());
228 return new CORBA::Any();
231 //+----------------------------------------------------------------------------
233 // method : StopCmd::execute()
235 // description : method to trigger the execution of the command.
236 // PLEASE DO NOT MODIFY this method core without pogo
238 // in : - device : The device on which the command must be excuted
239 // - in_any : The command input data
241 // returns : The command output data (packed in the Any object)
243 //-----------------------------------------------------------------------------
244 CORBA::Any
*StopCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
247 cout2
<< "StopCmd::execute(): arrived" << endl
;
249 ((static_cast<PseudoAxis
*>(device
))->stop());
250 return new CORBA::Any();
253 //+----------------------------------------------------------------------------
255 // method : ComputeNewOffsetCmd::execute()
257 // description : method to trigger the execution of the command.
258 // PLEASE DO NOT MODIFY this method core without pogo
260 // in : - device : The device on which the command must be excuted
261 // - in_any : The command input data
263 // returns : The command output data (packed in the Any object)
265 //-----------------------------------------------------------------------------
266 CORBA::Any
*ComputeNewOffsetCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
269 cout2
<< "ComputeNewOffsetCmd::execute(): arrived" << endl
;
271 Tango::DevDouble argin
;
272 extract(in_any
, argin
);
274 ((static_cast<PseudoAxis
*>(device
))->compute_new_offset(argin
));
275 return new CORBA::Any();
279 //+----------------------------------------------------------------------------
281 // method : MotorONCmd::execute()
283 // description : method to trigger the execution of the command.
284 // PLEASE DO NOT MODIFY this method core without pogo
286 // in : - device : The device on which the command must be excuted
287 // - in_any : The command input data
289 // returns : The command output data (packed in the Any object)
291 //-----------------------------------------------------------------------------
292 CORBA::Any
*MotorONCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
295 cout2
<< "MotorONCmd::execute(): arrived" << endl
;
297 ((static_cast<PseudoAxis
*>(device
))->motor_on());
298 return new CORBA::Any();
301 //+----------------------------------------------------------------------------
303 // method : MotorOFFCmd::execute()
305 // description : method to trigger the execution of the command.
306 // PLEASE DO NOT MODIFY this method core without pogo
308 // in : - device : The device on which the command must be excuted
309 // - in_any : The command input data
311 // returns : The command output data (packed in the Any object)
313 //-----------------------------------------------------------------------------
314 CORBA::Any
*MotorOFFCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
317 cout2
<< "MotorOFFCmd::execute(): arrived" << endl
;
319 ((static_cast<PseudoAxis
*>(device
))->motor_off());
320 return new CORBA::Any();
324 //----------------------------------------------------------------
325 // Initialize pointer for singleton pattern
326 //----------------------------------------------------------------
328 PseudoAxisClass
*PseudoAxisClass::_instance
= NULL
;
330 //+----------------------------------------------------------------------------
332 // method : PseudoAxisClass::PseudoAxisClass(string &s)
334 // description : constructor for the PseudoAxisClass
336 // in : - s : The class name
338 //-----------------------------------------------------------------------------
339 PseudoAxisClass::PseudoAxisClass(string
&s
):DeviceClass(s
)
342 cout2
<< "Entering PseudoAxisClass constructor" << endl
;
343 set_default_property();
344 write_class_property();
345 get_class_property();
347 cout2
<< "Leaving PseudoAxisClass constructor" << endl
;
350 //+----------------------------------------------------------------------------
352 // method : PseudoAxisClass::~PseudoAxisClass()
354 // description : destructor for the PseudoAxisClass
356 //-----------------------------------------------------------------------------
357 PseudoAxisClass::~PseudoAxisClass()
362 //+----------------------------------------------------------------------------
364 // method : PseudoAxisClass::instance
366 // description : Create the object if not already done. Otherwise, just
367 // return a pointer to the object
369 // in : - name : The class name
371 //-----------------------------------------------------------------------------
372 PseudoAxisClass
*PseudoAxisClass::init(const char *name
)
374 if (_instance
== NULL
)
379 _instance
= new PseudoAxisClass(s
);
389 PseudoAxisClass
*PseudoAxisClass::instance()
391 if (_instance
== NULL
)
393 cerr
<< "Class is not initialised !!" << endl
;
399 //+----------------------------------------------------------------------------
401 // method : PseudoAxisClass::command_factory
403 // description : Create the command object(s) and store them in the
406 //-----------------------------------------------------------------------------
407 void PseudoAxisClass::command_factory()
409 command_list
.push_back(new StopCmd("Stop",
410 Tango::DEV_VOID
, Tango::DEV_VOID
,
414 command_list
.push_back(new MotorOFFCmd("MotorOFF",
415 Tango::DEV_VOID
, Tango::DEV_VOID
,
419 command_list
.push_back(new MotorONCmd("MotorON",
420 Tango::DEV_VOID
, Tango::DEV_VOID
,
424 command_list
.push_back(new MotorInitCmd("MotorInit",
425 Tango::DEV_VOID
, Tango::DEV_VOID
,
429 command_list
.push_back(new ComputeNewOffsetCmd("ComputeNewOffset",
430 Tango::DEV_DOUBLE
, Tango::DEV_VOID
,
431 "The new user position",
434 command_list
.push_back(new BackwardClass("Backward",
435 Tango::DEV_VOID
, Tango::DEV_VOID
,
439 command_list
.push_back(new ForwardCmd("Forward",
440 Tango::DEV_VOID
, Tango::DEV_VOID
,
444 command_list
.push_back(new DefinePositionCmd("DefinePosition",
445 Tango::DEV_DOUBLE
, Tango::DEV_VOID
,
449 command_list
.push_back(new InitializeReferencePositionCmd("InitializeReferencePosition",
450 Tango::DEV_VOID
, Tango::DEV_VOID
,
454 command_list
.push_back(new GetModeParametersClass("GetModeParameters",
455 Tango::DEV_VOID
, Tango::DEVVAR_DOUBLESTRINGARRAY
,
457 "parameters names and values",
459 command_list
.push_back(new SetModeParametersClass("SetModeParameters",
460 Tango::DEVVAR_DOUBLESTRINGARRAY
, Tango::DEV_VOID
,
461 "The parameters to set",
465 // add polling if any
466 for (unsigned int i
=0 ; i
<command_list
.size(); i
++)
471 //+----------------------------------------------------------------------------
473 // method : PseudoAxisClass::get_class_property
475 // description : Get the class property for specified name.
477 // in : string name : The property name
479 //+----------------------------------------------------------------------------
480 Tango::DbDatum
PseudoAxisClass::get_class_property(string
&prop_name
)
482 for (unsigned int i
=0 ; i
<cl_prop
.size() ; i
++)
483 if (cl_prop
[i
].name
== prop_name
)
485 // if not found, return an empty DbDatum
486 return Tango::DbDatum(prop_name
);
488 //+----------------------------------------------------------------------------
490 // method : PseudoAxisClass::get_default_device_property()
492 // description : Return the default value for device property.
494 //-----------------------------------------------------------------------------
495 Tango::DbDatum
PseudoAxisClass::get_default_device_property(string
&prop_name
)
497 for (unsigned int i
=0 ; i
<dev_def_prop
.size() ; i
++)
498 if (dev_def_prop
[i
].name
== prop_name
)
499 return dev_def_prop
[i
];
500 // if not found, return an empty DbDatum
501 return Tango::DbDatum(prop_name
);
504 //+----------------------------------------------------------------------------
506 // method : PseudoAxisClass::get_default_class_property()
508 // description : Return the default value for class property.
510 //-----------------------------------------------------------------------------
511 Tango::DbDatum
PseudoAxisClass::get_default_class_property(string
&prop_name
)
513 for (unsigned int i
=0 ; i
<cl_def_prop
.size() ; i
++)
514 if (cl_def_prop
[i
].name
== prop_name
)
515 return cl_def_prop
[i
];
516 // if not found, return an empty DbDatum
517 return Tango::DbDatum(prop_name
);
519 //+----------------------------------------------------------------------------
521 // method : PseudoAxisClass::device_factory
523 // description : Create the device object(s) and store them in the
526 // in : Tango::DevVarStringArray *devlist_ptr : The device name list
528 //-----------------------------------------------------------------------------
529 void PseudoAxisClass::device_factory(const Tango::DevVarStringArray
*devlist_ptr
)
532 // Create all devices.(Automatic code generation)
533 //-------------------------------------------------------------
534 for (unsigned long i
=0 ; i
< devlist_ptr
->length() ; i
++)
536 cout4
<< "Device name : " << (*devlist_ptr
)[i
].in() << endl
;
538 // Create devices and add it into the device list
539 //----------------------------------------------------
540 device_list
.push_back(new PseudoAxis(this, (*devlist_ptr
)[i
]));
542 // Export device to the outside world
543 // Check before if database used.
544 //---------------------------------------------
545 if ((Tango::Util::_UseDb
== true) && (Tango::Util::_FileDb
== false))
546 export_device(device_list
.back());
548 export_device(device_list
.back(), (*devlist_ptr
)[i
]);
550 // End of Automatic code generation
551 //-------------------------------------------------------------
554 //+----------------------------------------------------------------------------
555 // Method: PseudoAxisClass::attribute_factory(vector<Tango::Attr *> &att_list)
556 //-----------------------------------------------------------------------------
557 void PseudoAxisClass::attribute_factory(vector
<Tango::Attr
*> &att_list
)
559 // Attribute : position
560 positionAttrib
*position
= new positionAttrib();
561 Tango::UserDefaultAttrProp position_prop
;
562 position_prop
.set_label("position ");
563 position_prop
.set_unit("UserUnits");
564 position_prop
.set_description("Current position of Axis in UserUnits");
565 position
->set_default_properties(position_prop
);
566 att_list
.push_back(position
);
568 // Attribute : offset
569 offsetAttrib
*offset
= new offsetAttrib();
570 Tango::UserDefaultAttrProp offset_prop
;
571 offset_prop
.set_label("offset");
572 offset_prop
.set_unit("UserUnit");
573 offset_prop
.set_description("The offset of the axis");
574 offset
->set_default_properties(offset_prop
);
575 offset
->set_memorized();
576 offset
->set_memorized_init(true);
577 att_list
.push_back(offset
);
579 // Attribute : IsInitialised
580 IsInitialisedAttrib
*is_initialised
= new IsInitialisedAttrib();
581 Tango::UserDefaultAttrProp is_initialised_prop
;
582 is_initialised_prop
.set_label("IsInitialised");
583 is_initialised_prop
.set_description("toggle the axis initialization. this attribut is non relevant on\nsome pseudoaxis.");
584 is_initialised
->set_default_properties(is_initialised_prop
);
585 att_list
.push_back(is_initialised
);
587 // Attribute : relativeMove
588 relativeMoveAttrib
*relative_move
= new relativeMoveAttrib();
589 Tango::UserDefaultAttrProp relative_move_prop
;
590 relative_move_prop
.set_description("The relative move you want on this axis");
591 relative_move
->set_default_properties(relative_move_prop
);
592 att_list
.push_back(relative_move
);
595 modeAttrib
*mode
= new modeAttrib();
596 att_list
.push_back(mode
);
598 // Attribute : modeNames
599 modeNamesAttrib
*mode_names
= new modeNamesAttrib();
600 att_list
.push_back(mode_names
);
602 // End of Automatic code generation
603 //-------------------------------------------------------------
606 //+----------------------------------------------------------------------------
608 // method : PseudoAxisClass::get_class_property()
610 // description : Read the class properties from database.
612 //-----------------------------------------------------------------------------
613 void PseudoAxisClass::get_class_property()
615 // Initialize your default values here (if not done with POGO).
616 //------------------------------------------------------------------
618 // Read class properties from database.(Automatic code generation)
619 //------------------------------------------------------------------
621 // Call database and extract values
622 //--------------------------------------------
623 if (Tango::Util::instance()->_UseDb
==true)
624 get_db_class()->get_property(cl_prop
);
625 Tango::DbDatum def_prop
;
629 // End of Automatic code generation
630 //------------------------------------------------------------------
634 //+----------------------------------------------------------------------------
636 // method : PseudoAxisClass::set_default_property
638 // description: Set default property (class and device) for wizard.
639 // For each property, add to wizard property name and description
640 // If default value has been set, add it to wizard property and
641 // store it in a DbDatum.
643 //-----------------------------------------------------------------------------
644 void PseudoAxisClass::set_default_property()
650 vector
<string
> vect_data
;
651 // Set Default Class Properties
652 // Set Default Device Properties
653 prop_name
= "DiffractometerProxy";
654 prop_desc
= "This is the tango url to the device Diffractometer.\nN.B : The instance of the diffractometer must be the same that this PseudoAxis";
656 if (prop_def
.length()>0)
658 Tango::DbDatum
data(prop_name
);
660 dev_def_prop
.push_back(data
);
661 add_wiz_dev_prop(prop_name
, prop_desc
, prop_def
);
664 add_wiz_dev_prop(prop_name
, prop_desc
);
666 prop_name
= "PseudoAxisName";
667 prop_desc
= "This name must be register in the HKL library.\n\ni.e :\nFor Eulerian 4 circles : psi, q, q2th, th2th";
669 if (prop_def
.length()>0)
671 Tango::DbDatum
data(prop_name
);
673 dev_def_prop
.push_back(data
);
674 add_wiz_dev_prop(prop_name
, prop_desc
, prop_def
);
677 add_wiz_dev_prop(prop_name
, prop_desc
);
680 //+----------------------------------------------------------------------------
682 // method : PseudoAxisClass::write_class_property
684 // description : Set class description as property in database
686 //-----------------------------------------------------------------------------
687 void PseudoAxisClass::write_class_property()
689 // First time, check if database used
690 //--------------------------------------------
691 if (Tango::Util::_UseDb
== false)
695 string classname
= get_name();
697 string::size_type start
, end
;
700 Tango::DbDatum
title("ProjectTitle");
701 string
str_title("null");
703 data
.push_back(title
);
706 Tango::DbDatum
description("Description");
707 vector
<string
> str_desc
;
708 str_desc
.push_back(" ");
709 description
<< str_desc
;
710 data
.push_back(description
);
714 string
filename(classname
);
715 start
= rcsId
.find("/");
716 if (start
!=string::npos
)
718 filename
+= "Class.cpp";
719 end
= rcsId
.find(filename
);
722 string strloc
= rcsId
.substr(start
, end
-start
);
723 // Check if specific repository
724 start
= strloc
.find("/cvsroot/");
725 if (start
!=string::npos
&& start
>0)
727 string repository
= strloc
.substr(0, start
);
728 if (repository
.find("/segfs/")!=string::npos
)
729 strloc
= "ESRF:" + strloc
.substr(start
, strloc
.length()-start
);
731 Tango::DbDatum
cvs_loc("cvs_location");
733 data
.push_back(cvs_loc
);
737 // Get CVS tag revision
738 string
tagname(TagName
);
740 start
= header
.length();
742 end
= tagname
.find(endstr
);
743 if (end
!=string::npos
&& end
>start
)
745 string strtag
= tagname
.substr(start
, end
-start
);
746 Tango::DbDatum
cvs_tag("cvs_tag");
748 data
.push_back(cvs_tag
);
752 string
httpServ(HttpServer
);
753 if (httpServ
.length()>0)
755 Tango::DbDatum
db_doc_url("doc_url");
756 db_doc_url
<< httpServ
;
757 data
.push_back(db_doc_url
);
761 Tango::DbDatum
inher_datum("InheritedFrom");
762 vector
<string
> inheritance
;
763 inheritance
.push_back("Device_3Impl");
764 inher_datum
<< inheritance
;
765 data
.push_back(inher_datum
);
767 // Call database and and values
768 //--------------------------------------------
769 get_db_class()->put_property(data
);