1 #include "TangoHKLAdapter.h"
2 #include "PseudoAxisAdapter.h"
5 namespace Diffractometer_ns
8 PseudoAxisAdapter::PseudoAxisAdapter(TangoHKLAdapter
&hklAdapter
, HklPseudoAxis
*pseudo_r
, HklPseudoAxis
*pseudo_w
):
9 _hklAdapter(hklAdapter
),
16 std::vector
<AxisAdapter
> &axes
= hklAdapter
.get_axes();
19 _state
= Tango::UNKNOWN
;
23 len
= HKL_LIST_LEN(_pseudo_r
->engine
->mode
->axes_names
);
24 names
= _pseudo_r
->engine
->mode
->axes_names
;
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
);
34 len
= HKL_LIST_LEN(_pseudo_r
->engine
->modes
);
35 _mode_names
.resize(len
, 1);
37 _mode_names
.data
[i
] = const_cast<char *>(_pseudo_r
->engine
->modes
[i
]->name
);
40 PseudoAxisAdapter::~PseudoAxisAdapter(void)
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
);
57 if(!diffractometer
|| !diffractometer
->samples
){
58 _state
= Tango::FAULT
;
59 _status
= "Internal Error";
64 if(!diffractometer
->samples
->current
){
65 _state
= Tango::FAULT
;
66 _status
= "Sample not set";
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";
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)
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);
112 //TODO remove this try catch when tango group will be updated
118 bool PseudoAxisAdapter::is_ready(void)
123 for(i
=0; i
<_axes
.size(); ++i
)
124 if(!_axes
[i
]->is_ready())
128 _group
= new Tango::Group("tmp");
130 for(i
=0; i
<_axes
.size(); ++i
)
131 _group
->add(_axes
[i
]->get_device_name());
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
);