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 : OnCmd::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
*OnCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
88 cout2
<< "OnCmd::execute(): arrived" << endl
;
90 ((static_cast<PseudoAxis
*>(device
))->on());
91 return new CORBA::Any();
94 //+----------------------------------------------------------------------------
96 // method : SetModeParametersClass::execute()
98 // description : method to trigger the execution of the command.
99 // PLEASE DO NOT MODIFY this method core without pogo
101 // in : - device : The device on which the command must be excuted
102 // - in_any : The command input data
104 // returns : The command output data (packed in the Any object)
106 //-----------------------------------------------------------------------------
107 CORBA::Any
*SetModeParametersClass::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
110 cout2
<< "SetModeParametersClass::execute(): arrived" << endl
;
112 const Tango::DevVarDoubleStringArray
*argin
;
113 extract(in_any
, argin
);
115 ((static_cast<PseudoAxis
*>(device
))->set_mode_parameters(argin
));
116 return new CORBA::Any();
119 //+----------------------------------------------------------------------------
121 // method : GetModeParametersClass::execute()
123 // description : method to trigger the execution of the command.
124 // PLEASE DO NOT MODIFY this method core without pogo
126 // in : - device : The device on which the command must be excuted
127 // - in_any : The command input data
129 // returns : The command output data (packed in the Any object)
131 //-----------------------------------------------------------------------------
132 CORBA::Any
*GetModeParametersClass::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
135 cout2
<< "GetModeParametersClass::execute(): arrived" << endl
;
137 return insert((static_cast<PseudoAxis
*>(device
))->get_mode_parameters());
140 //+----------------------------------------------------------------------------
142 // method : InitializeReferencePositionCmd::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
*InitializeReferencePositionCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
156 cout2
<< "InitializeReferencePositionCmd::execute(): arrived" << endl
;
158 ((static_cast<PseudoAxis
*>(device
))->initialize_reference_position());
159 return new CORBA::Any();
162 //+----------------------------------------------------------------------------
164 // method : DefinePositionCmd::execute()
166 // description : method to trigger the execution of the command.
167 // PLEASE DO NOT MODIFY this method core without pogo
169 // in : - device : The device on which the command must be excuted
170 // - in_any : The command input data
172 // returns : The command output data (packed in the Any object)
174 //-----------------------------------------------------------------------------
175 CORBA::Any
*DefinePositionCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
178 cout2
<< "DefinePositionCmd::execute(): arrived" << endl
;
180 Tango::DevDouble argin
;
181 extract(in_any
, argin
);
183 ((static_cast<PseudoAxis
*>(device
))->define_position(argin
));
184 return new CORBA::Any();
187 //+----------------------------------------------------------------------------
189 // method : ForwardCmd::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
*ForwardCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
203 cout2
<< "ForwardCmd::execute(): arrived" << endl
;
205 ((static_cast<PseudoAxis
*>(device
))->forward());
206 return new CORBA::Any();
209 //+----------------------------------------------------------------------------
211 // method : BackwardClass::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
*BackwardClass::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
225 cout2
<< "BackwardClass::execute(): arrived" << endl
;
227 ((static_cast<PseudoAxis
*>(device
))->backward());
228 return new CORBA::Any();
231 //+----------------------------------------------------------------------------
233 // method : MotorInitCmd::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
*MotorInitCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
247 cout2
<< "MotorInitCmd::execute(): arrived" << endl
;
249 ((static_cast<PseudoAxis
*>(device
))->motor_init());
250 return new CORBA::Any();
253 //+----------------------------------------------------------------------------
255 // method : StopCmd::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
*StopCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
269 cout2
<< "StopCmd::execute(): arrived" << endl
;
271 ((static_cast<PseudoAxis
*>(device
))->stop());
272 return new CORBA::Any();
275 //+----------------------------------------------------------------------------
277 // method : ComputeNewOffsetCmd::execute()
279 // description : method to trigger the execution of the command.
280 // PLEASE DO NOT MODIFY this method core without pogo
282 // in : - device : The device on which the command must be excuted
283 // - in_any : The command input data
285 // returns : The command output data (packed in the Any object)
287 //-----------------------------------------------------------------------------
288 CORBA::Any
*ComputeNewOffsetCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
291 cout2
<< "ComputeNewOffsetCmd::execute(): arrived" << endl
;
293 Tango::DevDouble argin
;
294 extract(in_any
, argin
);
296 ((static_cast<PseudoAxis
*>(device
))->compute_new_offset(argin
));
297 return new CORBA::Any();
301 //+----------------------------------------------------------------------------
303 // method : MotorONCmd::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
*MotorONCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
317 cout2
<< "MotorONCmd::execute(): arrived" << endl
;
319 ((static_cast<PseudoAxis
*>(device
))->motor_on());
320 return new CORBA::Any();
323 //+----------------------------------------------------------------------------
325 // method : MotorOFFCmd::execute()
327 // description : method to trigger the execution of the command.
328 // PLEASE DO NOT MODIFY this method core without pogo
330 // in : - device : The device on which the command must be excuted
331 // - in_any : The command input data
333 // returns : The command output data (packed in the Any object)
335 //-----------------------------------------------------------------------------
336 CORBA::Any
*MotorOFFCmd::execute(Tango::DeviceImpl
*device
,const CORBA::Any
&in_any
)
339 cout2
<< "MotorOFFCmd::execute(): arrived" << endl
;
341 ((static_cast<PseudoAxis
*>(device
))->motor_off());
342 return new CORBA::Any();
346 //----------------------------------------------------------------
347 // Initialize pointer for singleton pattern
348 //----------------------------------------------------------------
350 PseudoAxisClass
*PseudoAxisClass::_instance
= NULL
;
352 //+----------------------------------------------------------------------------
354 // method : PseudoAxisClass::PseudoAxisClass(string &s)
356 // description : constructor for the PseudoAxisClass
358 // in : - s : The class name
360 //-----------------------------------------------------------------------------
361 PseudoAxisClass::PseudoAxisClass(string
&s
):DeviceClass(s
)
364 cout2
<< "Entering PseudoAxisClass constructor" << endl
;
365 set_default_property();
366 write_class_property();
367 get_class_property();
369 cout2
<< "Leaving PseudoAxisClass constructor" << endl
;
372 //+----------------------------------------------------------------------------
374 // method : PseudoAxisClass::~PseudoAxisClass()
376 // description : destructor for the PseudoAxisClass
378 //-----------------------------------------------------------------------------
379 PseudoAxisClass::~PseudoAxisClass()
384 //+----------------------------------------------------------------------------
386 // method : PseudoAxisClass::instance
388 // description : Create the object if not already done. Otherwise, just
389 // return a pointer to the object
391 // in : - name : The class name
393 //-----------------------------------------------------------------------------
394 PseudoAxisClass
*PseudoAxisClass::init(const char *name
)
396 if (_instance
== NULL
)
401 _instance
= new PseudoAxisClass(s
);
411 PseudoAxisClass
*PseudoAxisClass::instance()
413 if (_instance
== NULL
)
415 cerr
<< "Class is not initialised !!" << endl
;
421 //+----------------------------------------------------------------------------
423 // method : PseudoAxisClass::command_factory
425 // description : Create the command object(s) and store them in the
428 //-----------------------------------------------------------------------------
429 void PseudoAxisClass::command_factory()
431 command_list
.push_back(new StopCmd("Stop",
432 Tango::DEV_VOID
, Tango::DEV_VOID
,
436 command_list
.push_back(new OnCmd("On",
437 Tango::DEV_VOID
, Tango::DEV_VOID
,
441 command_list
.push_back(new MotorOFFCmd("MotorOFF",
442 Tango::DEV_VOID
, Tango::DEV_VOID
,
446 command_list
.push_back(new MotorONCmd("MotorON",
447 Tango::DEV_VOID
, Tango::DEV_VOID
,
451 command_list
.push_back(new MotorInitCmd("MotorInit",
452 Tango::DEV_VOID
, Tango::DEV_VOID
,
456 command_list
.push_back(new ComputeNewOffsetCmd("ComputeNewOffset",
457 Tango::DEV_DOUBLE
, Tango::DEV_VOID
,
458 "The new user position",
461 command_list
.push_back(new BackwardClass("Backward",
462 Tango::DEV_VOID
, Tango::DEV_VOID
,
466 command_list
.push_back(new ForwardCmd("Forward",
467 Tango::DEV_VOID
, Tango::DEV_VOID
,
471 command_list
.push_back(new DefinePositionCmd("DefinePosition",
472 Tango::DEV_DOUBLE
, Tango::DEV_VOID
,
476 command_list
.push_back(new InitializeReferencePositionCmd("InitializeReferencePosition",
477 Tango::DEV_VOID
, Tango::DEV_VOID
,
481 command_list
.push_back(new GetModeParametersClass("GetModeParameters",
482 Tango::DEV_VOID
, Tango::DEVVAR_DOUBLESTRINGARRAY
,
484 "parameters names and values",
486 command_list
.push_back(new SetModeParametersClass("SetModeParameters",
487 Tango::DEVVAR_DOUBLESTRINGARRAY
, Tango::DEV_VOID
,
488 "The parameters to set",
492 // add polling if any
493 for (unsigned int i
=0 ; i
<command_list
.size(); i
++)
498 //+----------------------------------------------------------------------------
500 // method : PseudoAxisClass::get_class_property
502 // description : Get the class property for specified name.
504 // in : string name : The property name
506 //+----------------------------------------------------------------------------
507 Tango::DbDatum
PseudoAxisClass::get_class_property(string
&prop_name
)
509 for (unsigned int i
=0 ; i
<cl_prop
.size() ; i
++)
510 if (cl_prop
[i
].name
== prop_name
)
512 // if not found, return an empty DbDatum
513 return Tango::DbDatum(prop_name
);
515 //+----------------------------------------------------------------------------
517 // method : PseudoAxisClass::get_default_device_property()
519 // description : Return the default value for device property.
521 //-----------------------------------------------------------------------------
522 Tango::DbDatum
PseudoAxisClass::get_default_device_property(string
&prop_name
)
524 for (unsigned int i
=0 ; i
<dev_def_prop
.size() ; i
++)
525 if (dev_def_prop
[i
].name
== prop_name
)
526 return dev_def_prop
[i
];
527 // if not found, return an empty DbDatum
528 return Tango::DbDatum(prop_name
);
531 //+----------------------------------------------------------------------------
533 // method : PseudoAxisClass::get_default_class_property()
535 // description : Return the default value for class property.
537 //-----------------------------------------------------------------------------
538 Tango::DbDatum
PseudoAxisClass::get_default_class_property(string
&prop_name
)
540 for (unsigned int i
=0 ; i
<cl_def_prop
.size() ; i
++)
541 if (cl_def_prop
[i
].name
== prop_name
)
542 return cl_def_prop
[i
];
543 // if not found, return an empty DbDatum
544 return Tango::DbDatum(prop_name
);
546 //+----------------------------------------------------------------------------
548 // method : PseudoAxisClass::device_factory
550 // description : Create the device object(s) and store them in the
553 // in : Tango::DevVarStringArray *devlist_ptr : The device name list
555 //-----------------------------------------------------------------------------
556 void PseudoAxisClass::device_factory(const Tango::DevVarStringArray
*devlist_ptr
)
559 // Create all devices.(Automatic code generation)
560 //-------------------------------------------------------------
561 for (unsigned long i
=0 ; i
< devlist_ptr
->length() ; i
++)
563 cout4
<< "Device name : " << (*devlist_ptr
)[i
].in() << endl
;
565 // Create devices and add it into the device list
566 //----------------------------------------------------
567 device_list
.push_back(new PseudoAxis(this, (*devlist_ptr
)[i
]));
569 // Export device to the outside world
570 // Check before if database used.
571 //---------------------------------------------
572 if ((Tango::Util::_UseDb
== true) && (Tango::Util::_FileDb
== false))
573 export_device(device_list
.back());
575 export_device(device_list
.back(), (*devlist_ptr
)[i
]);
577 // End of Automatic code generation
578 //-------------------------------------------------------------
581 //+----------------------------------------------------------------------------
582 // Method: PseudoAxisClass::attribute_factory(vector<Tango::Attr *> &att_list)
583 //-----------------------------------------------------------------------------
584 void PseudoAxisClass::attribute_factory(vector
<Tango::Attr
*> &att_list
)
586 // Attribute : position
587 positionAttrib
*position
= new positionAttrib();
588 Tango::UserDefaultAttrProp position_prop
;
589 position_prop
.set_label("position ");
590 position_prop
.set_unit("UserUnits");
591 position_prop
.set_description("Current position of Axis in UserUnits");
592 position
->set_default_properties(position_prop
);
593 att_list
.push_back(position
);
595 // Attribute : offset
596 offsetAttrib
*offset
= new offsetAttrib();
597 Tango::UserDefaultAttrProp offset_prop
;
598 offset_prop
.set_label("offset");
599 offset_prop
.set_unit("UserUnit");
600 offset_prop
.set_description("The offset of the axis");
601 offset
->set_default_properties(offset_prop
);
602 offset
->set_memorized();
603 offset
->set_memorized_init(true);
604 att_list
.push_back(offset
);
606 // Attribute : initialized
607 initializedAttrib
*initialized
= new initializedAttrib();
608 Tango::UserDefaultAttrProp initialized_prop
;
609 initialized_prop
.set_description("toggle the axis initialization. this attribut is non relevant on\nsome pseudoaxis.");
610 initialized
->set_default_properties(initialized_prop
);
611 att_list
.push_back(initialized
);
613 // Attribute : relativeMove
614 relativeMoveAttrib
*relative_move
= new relativeMoveAttrib();
615 Tango::UserDefaultAttrProp relative_move_prop
;
616 relative_move_prop
.set_description("The relative move you want on this axis");
617 relative_move
->set_default_properties(relative_move_prop
);
618 att_list
.push_back(relative_move
);
621 modeAttrib
*mode
= new modeAttrib();
622 att_list
.push_back(mode
);
624 // Attribute : IsInitialised
625 IsInitialisedAttrib
*is_initialised
= new IsInitialisedAttrib();
626 Tango::UserDefaultAttrProp is_initialised_prop
;
627 is_initialised_prop
.set_label("IsInitialised");
628 is_initialised_prop
.set_description("DEPRECATED");
629 is_initialised
->set_default_properties(is_initialised_prop
);
630 att_list
.push_back(is_initialised
);
632 // Attribute : modeNames
633 modeNamesAttrib
*mode_names
= new modeNamesAttrib();
634 att_list
.push_back(mode_names
);
636 // End of Automatic code generation
637 //-------------------------------------------------------------
640 //+----------------------------------------------------------------------------
642 // method : PseudoAxisClass::get_class_property()
644 // description : Read the class properties from database.
646 //-----------------------------------------------------------------------------
647 void PseudoAxisClass::get_class_property()
649 // Initialize your default values here (if not done with POGO).
650 //------------------------------------------------------------------
652 // Read class properties from database.(Automatic code generation)
653 //------------------------------------------------------------------
655 // Call database and extract values
656 //--------------------------------------------
657 if (Tango::Util::instance()->_UseDb
==true)
658 get_db_class()->get_property(cl_prop
);
659 Tango::DbDatum def_prop
;
663 // End of Automatic code generation
664 //------------------------------------------------------------------
668 //+----------------------------------------------------------------------------
670 // method : PseudoAxisClass::set_default_property
672 // description: Set default property (class and device) for wizard.
673 // For each property, add to wizard property name and description
674 // If default value has been set, add it to wizard property and
675 // store it in a DbDatum.
677 //-----------------------------------------------------------------------------
678 void PseudoAxisClass::set_default_property()
684 vector
<string
> vect_data
;
685 // Set Default Class Properties
686 // Set Default Device Properties
687 prop_name
= "DiffractometerProxy";
688 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";
690 if (prop_def
.length()>0)
692 Tango::DbDatum
data(prop_name
);
694 dev_def_prop
.push_back(data
);
695 add_wiz_dev_prop(prop_name
, prop_desc
, prop_def
);
698 add_wiz_dev_prop(prop_name
, prop_desc
);
700 prop_name
= "PseudoAxisName";
701 prop_desc
= "This name must be register in the HKL library.\n\ni.e :\nFor Eulerian 4 circles : psi, q, q2th, th2th";
703 if (prop_def
.length()>0)
705 Tango::DbDatum
data(prop_name
);
707 dev_def_prop
.push_back(data
);
708 add_wiz_dev_prop(prop_name
, prop_desc
, prop_def
);
711 add_wiz_dev_prop(prop_name
, prop_desc
);
714 //+----------------------------------------------------------------------------
716 // method : PseudoAxisClass::write_class_property
718 // description : Set class description as property in database
720 //-----------------------------------------------------------------------------
721 void PseudoAxisClass::write_class_property()
723 // First time, check if database used
724 //--------------------------------------------
725 if (Tango::Util::_UseDb
== false)
729 string classname
= get_name();
731 string::size_type start
, end
;
734 Tango::DbDatum
title("ProjectTitle");
735 string
str_title("null");
737 data
.push_back(title
);
740 Tango::DbDatum
description("Description");
741 vector
<string
> str_desc
;
742 str_desc
.push_back(" ");
743 description
<< str_desc
;
744 data
.push_back(description
);
748 string
filename(classname
);
749 start
= rcsId
.find("/");
750 if (start
!=string::npos
)
752 filename
+= "Class.cpp";
753 end
= rcsId
.find(filename
);
756 string strloc
= rcsId
.substr(start
, end
-start
);
757 // Check if specific repository
758 start
= strloc
.find("/cvsroot/");
759 if (start
!=string::npos
&& start
>0)
761 string repository
= strloc
.substr(0, start
);
762 if (repository
.find("/segfs/")!=string::npos
)
763 strloc
= "ESRF:" + strloc
.substr(start
, strloc
.length()-start
);
765 Tango::DbDatum
cvs_loc("cvs_location");
767 data
.push_back(cvs_loc
);
771 // Get CVS tag revision
772 string
tagname(TagName
);
774 start
= header
.length();
776 end
= tagname
.find(endstr
);
777 if (end
!=string::npos
&& end
>start
)
779 string strtag
= tagname
.substr(start
, end
-start
);
780 Tango::DbDatum
cvs_tag("cvs_tag");
782 data
.push_back(cvs_tag
);
786 string
httpServ(HttpServer
);
787 if (httpServ
.length()>0)
789 Tango::DbDatum
db_doc_url("doc_url");
790 db_doc_url
<< httpServ
;
791 data
.push_back(db_doc_url
);
795 Tango::DbDatum
inher_datum("InheritedFrom");
796 vector
<string
> inheritance
;
797 inheritance
.push_back("Device_3Impl");
798 inher_datum
<< inheritance
;
799 data
.push_back(inher_datum
);
801 // Call database and and values
802 //--------------------------------------------
803 get_db_class()->put_property(data
);