* add the soleil pom.xml file
[diffractometer.git] / src / PseudoAxisAdapter.cpp
bloba6b6c26bdd09d910d33016475d8711df93783d89
1 #include "TangoHKLAdapter.h"
2 #include "PseudoAxisAdapter.h"
3 #include "macros.h"
5 namespace Diffractometer_ns
8 PseudoAxisAdapter::PseudoAxisAdapter(TangoHKLAdapter &hklAdapter, HklPseudoAxis *pseudo_r, HklPseudoAxis *pseudo_w):
9 _hklAdapter(hklAdapter),
10 _pseudo_r(pseudo_r),
11 _pseudo_w(pseudo_w)
13 size_t len;
14 size_t i, j;
15 char const **names;
16 std::vector<AxisAdapter> &axes = hklAdapter.get_axes();
18 _ready = false;
19 _state = Tango::UNKNOWN;
20 _group = NULL;
22 _axes.clear();
23 len = HKL_LIST_LEN(_pseudo_r->engine->mode->axes_names);
24 names = _pseudo_r->engine->mode->axes_names;
25 for(i=0; i<len; ++i)
26 for(j=0; j<axes.size(); ++j){
27 AxisAdapter & axis = axes[j];
28 if(axis.get_name() == names[i]) {
29 _axes.push_back(&axis);
30 continue;
34 len = HKL_LIST_LEN(_pseudo_r->engine->modes);
35 _mode_names.resize(len, 1);
36 for(i=0; i<len; ++i)
37 _mode_names.data[i] = const_cast<char *>(_pseudo_r->engine->modes[i]->name);
40 PseudoAxisAdapter::~PseudoAxisAdapter(void)
42 if(_group){
43 _group->remove_all();
44 delete _group;
45 _group = NULL;
49 void PseudoAxisAdapter::update(void)
51 HklDiffractometer *diffractometer = _hklAdapter.diffractometer();
53 _read = hkl_parameter_get_value_unit((HklParameter *)_pseudo_r);
54 _write = hkl_parameter_get_value_unit((HklParameter *)_pseudo_w);
56 // the internal part
57 if(!diffractometer || !diffractometer->samples){
58 _state = Tango::FAULT;
59 _status = "Internal Error";
60 return;
63 // the sample part
64 if(!diffractometer->samples->current){
65 _state = Tango::FAULT;
66 _status = "Sample not set";
67 return;
70 // now compute the state ans status of the pseudo axes.
71 _state = Tango::STANDBY;
72 std::string extra_status;
74 _status = "REAL Mode: Motors will REALLY move.";
75 if (!this->is_ready()) {
76 _state = Tango::FAULT;
77 extra_status = "\nCan not connect to axes proxies";
78 } else {
79 for(size_t i=0;i<_axes.size();++i) {
80 AxisAdapter const * axis = _axes[i];
81 ::compose_state(_state, axis->get_state());
82 if (axis->get_state() != Tango::STANDBY)
83 extra_status += "\n" + axis->get_device_name() + " is in " + Tango::DevStateName[axis->get_state()];
86 extra_status += "\nPseudoAxe status: ";
87 extra_status += Tango::DevStateName[_state];
88 _status += extra_status;
91 void PseudoAxisAdapter::to_proxies(void)
93 if(this->is_ready()){
94 long len = _axes.size();
95 std::vector<double> values(len);
97 for (long i=0; i<len; ++i) {
98 _axes[i]->from_HklAxis();
99 values[i] = _axes[i]->get_write_real();
100 _axes[i]->set_state(Tango::MOVING);
103 #ifdef WRITE_TO_PROXY_ALLOWED
104 // Launch in one time
107 _group->command_inout(AXIS_COMMAND_STOP_NAME);
108 _group->write_attribute(AXIS_ATTRIBUTE_POSITION_NAME, values, true);
110 catch(...)
112 //TODO remove this try catch when tango group will be updated
114 #endif
118 bool PseudoAxisAdapter::is_ready(void)
120 if(!_ready){
121 size_t i;
123 for(i=0; i<_axes.size(); ++i)
124 if(!_axes[i]->is_ready())
125 return _ready;
126 _ready = true;
127 //create the _group
128 _group = new Tango::Group("tmp");
129 if(_group)
130 for(i=0; i<_axes.size(); ++i)
131 _group->add(_axes[i]->get_device_name());
133 return _ready;
136 Tango::DevString *PseudoAxisAdapter::get_mode(void) const
138 return _hklAdapter.pseudo_axis_get_mode(this);
141 void PseudoAxisAdapter::set_mode(Tango::DevString const & mode)
143 _hklAdapter.pseudo_axis_set_mode(this, mode);
146 void PseudoAxisAdapter::get_mode_parameters(Tango::DevVarDoubleStringArray *argout)
148 _hklAdapter.pseudo_axis_get_mode_parameters(this, argout);
151 void PseudoAxisAdapter::set_mode_parameters(const Tango::DevVarDoubleStringArray *argin)
153 _hklAdapter.pseudo_axis_set_mode_parameters(this, argin);