HLCC Documentation 2.2.0
Loading...
Searching...
No Matches
commandsImpl.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020-2025 European Southern Observatory (ESO)
2//
3// SPDX-License-Identifier: LGPL-3.0-only
4
13#ifndef HLCC_TELIF_TELIF_COMMANDSIMPL_HPP
14#define HLCC_TELIF_TELIF_COMMANDSIMPL_HPP
15
16#include <Stdif.hpp>
17
18#include <rad/exceptions.hpp>
19#include <rad/smAdapter.hpp>
20
21#include "telif/commands.rad.hpp"
22#include "telif/logger.hpp"
23
24
25namespace hlcc::telif {
26
27class CommandsImpl : public ccsinsif::AsyncCommands {
28public:
29 explicit CommandsImpl(rad::SMAdapter& sm) : m_sm(sm) {
30 /* GCH
31 * I do the registration of the RejectionHandler
32 * in the definition of each command handler method
33 * by adding the line:
34 * m_sm.RegisterDefaultRequestRejectHandler<StdCmds::Exit>();
35 * This has the advantage of putting the registration one by one
36 * together with the code of each handler, making it easy to keep the
37 * code aligned and to handle special cases, for example with
38 * specific handlers for commands returning something different form
39 * a string or not setting an handler for commands that are always available,
40 * in any state and will never be rejected.
41 * The drawback is a small performance penalty, since it will try to
42 * insert the registration in the std::map every time.
43 * Nothing will happen, since std::map will not insert a duplicate and will
44 * simply ignore the additional insertion.
45 * If that is a problem, we might do the registration here in the constructor,
46 * but it will be error prone when keeping the code aligned when
47 * adding or removing commands
48 */
49 RAD_TRACE(GetLogger());
50 }
51
52 virtual ~CommandsImpl() {
53 RAD_TRACE(GetLogger());
54 }
55
56 virtual elt::mal::future<std::string> Preset(const std::shared_ptr<ccsinsif::PresetArgs>& preset_args) override {
57 RAD_TRACE(GetLogger());
58 LOG4CPLUS_INFO(GetLogger(), "Preset command received with PresetData - Ra "
59 << preset_args->getPreset_data()->getRa() << ", Dec " << preset_args->getPreset_data()->getDec()
60 << ", Epoch " << preset_args->getPreset_data()->getEpoch() << " , Parallax " << preset_args->getPreset_data()->getParallax()
61 << ", Object_name " << preset_args->getPreset_data()->getObject_name()
62 << ", Proper_motion_ra " << preset_args->getPreset_data()->getProper_motion_ra()
63 << ", Proper_motion_dec " << preset_args->getPreset_data()->getProper_motion_dec()
64 << ", Radvel " << preset_args->getPreset_data()->getRadvel()
65 << ", Rshift " << preset_args->getPreset_data()->getRshift()
66 << ", System " << preset_args->getPreset_data()->getSystem()
67 << ", Velocity_offset_ra " << preset_args->getPreset_data()->getVelocity_offset_ra()
68 << ", Velocity_offset_dec " << preset_args->getPreset_data()->getVelocity_offset_dec());
69
70 auto ev = std::make_shared<TelifCommands::Preset>(preset_args->clone());
71 RAD_TRACE(GetLogger());
72 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::Preset>();
73 m_sm.PostEvent(ev);
74 RAD_TRACE(GetLogger());
75 return ev->GetPayload().GetReplyFuture();
76
77 }
78
79 virtual elt::mal::future<std::string> PresetEphem(const std::shared_ptr<ccsinsif::PresetEphemArgs>& preset_args) override {
80 RAD_TRACE(GetLogger());
81 LOG4CPLUS_INFO(GetLogger(), "Received PresetEphem with: Command " << preset_args->getCommand()
82 << ", PresetEphemArgs " << preset_args->getPreset_data());
83 auto ev = std::make_shared<TelifCommands::PresetEphem>(preset_args->clone());
84 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::PresetEphem>();
85 m_sm.PostEvent(ev);
86 return ev->GetPayload().GetReplyFuture();
87 }
88
89 virtual elt::mal::future<std::string> RequestControl(ccsinsif::ControlMode control_mode) override {
90 RAD_TRACE(GetLogger());
91 LOG4CPLUS_INFO(GetLogger(), "Received RequestControl with: Control_mode " << control_mode);
92 auto ev = std::make_shared<TelifCommands::RequestControl>(control_mode);
93 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::RequestControl>();
94 m_sm.PostEvent(ev);
95
96 return ev->GetPayload().GetReplyFuture();
97 }
98
99 virtual elt::mal::future<std::string> ReleaseControl() override {
100 RAD_TRACE(GetLogger());
101 LOG4CPLUS_INFO(GetLogger(), "Received ReleaseControl");
102 auto ev = std::make_shared<TelifCommands::ReleaseControl>();
103 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::ReleaseControl>();
104 m_sm.PostEvent(ev);
105
106 return ev->GetPayload().GetReplyFuture();
107 }
108
109 virtual elt::mal::future<std::string> GetConfig() override {
110 RAD_TRACE(GetLogger());
111 LOG4CPLUS_INFO(GetLogger(), "Received GetConfig");
112
113 auto ev = std::make_shared<EventsApp::GetConfig>("");
114 m_sm.RegisterDefaultRequestRejectHandler<EventsApp::GetConfig>();
115 m_sm.PostEvent(ev);
116
117 return ev->GetPayload().GetReplyFuture();
118 }
119
120 virtual elt::mal::future<std::string> SetObservingWavelength(double wavelength) override {
121 RAD_TRACE(GetLogger());
122 LOG4CPLUS_INFO(GetLogger(), "Received SetObservingWavelength with: Wavelength " << wavelength);
123
124 auto ev = std::make_shared<TelifCommands::SetObservingWavelength>(wavelength);
125 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::SetObservingWavelength>();
126 m_sm.PostEvent(ev);
127
128 return ev->GetPayload().GetReplyFuture();
129 }
130
131 virtual elt::mal::future<std::string> SetVelocityOffset(const std::shared_ptr<ccsinsif::VelocityOffset>& offset) override {
132 RAD_TRACE(GetLogger());
133 LOG4CPLUS_INFO(GetLogger(), "Received SetVelocityOffset with: Ra " << offset->getRa()
134 << ", Dec " << offset->getDec());
135
136 auto ev = std::make_shared<TelifCommands::SetVelocityOffset>(offset->clone());
137 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::SetVelocityOffset>();
138 m_sm.PostEvent(ev);
139
140 return ev->GetPayload().GetReplyFuture();
141 }
142
143 virtual elt::mal::future<std::string> SkyOffset(const std::shared_ptr<ccsinsif::OffsetSkyArgs>& offset_args) override {
144 RAD_TRACE(GetLogger());
145 LOG4CPLUS_INFO(GetLogger(), "Received SkyOffset with: Ra " << offset_args->getRa()
146 << ", Dec " << offset_args->getDec() << ", Field_stabilization "
147 << offset_args->getField_stabilization()
148 << ", Guide_star_param " << offset_args->getGuide_star_param());
149 auto ev = std::make_shared<TelifCommands::SkyOffset>(offset_args->clone());
150 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::SkyOffset>();
151 m_sm.PostEvent(ev);
152
153 return ev->GetPayload().GetReplyFuture();
154 }
155
156 virtual elt::mal::future<std::string> OffsetSetFocalPlane(const std::shared_ptr<ccsinsif::OffsetFocalPlaneArgs>& offset_args) override {
157 RAD_TRACE(GetLogger());
158 LOG4CPLUS_INFO(GetLogger(), "Received OffsetSetFocalPlane with: X " << offset_args->getX()
159 << ", Y " << offset_args->getY() << ", Field_stabilization "
160 << offset_args->getField_stabilization()
161 << ", Guide_star_param " << offset_args->getGuide_star_param());
162 auto ev = std::make_shared<TelifCommands::OffsetSetFocalPlane>(offset_args->clone());
163
164 //m_sm.PostEvent(ev);
165 stdif::ExceptionErr icd_ex {"NOT IMPLEMENTED", 0};
166 ev->GetPayload().SetException(icd_ex);
167
168 return ev->GetPayload().GetReplyFuture();
169 }
170
171 virtual elt::mal::future<std::string> SetReferenceFocus(double offset) override {
172 RAD_TRACE(GetLogger());
173 LOG4CPLUS_INFO(GetLogger(), "Received SetReferenceFocus with: Offset " << offset);
174
175 auto ev = std::make_shared<TelifCommands::SetReferenceFocus>(offset);
176 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::SetReferenceFocus>();
177 m_sm.PostEvent(ev);
178
179 return ev->GetPayload().GetReplyFuture();
180 }
181
182 virtual elt::mal::future<std::string> SetReferenceAberration(const elt::mal::shared_vector<const double>& aberration_offset) override {
183 RAD_TRACE(GetLogger());
184 LOG4CPLUS_INFO(GetLogger(), "Received SetReferenceAberration with: Aberration_offset " << aberration_offset);
185
186 /* Create a copy obj for the aberration_offset
187 * which in this case still have the same shared pointer of the original*/
188 elt::mal::shared_vector<const double> aberration_offset_temp(aberration_offset);
189
190 /* Make the copy obj unique by reseting the shared pointer reference to a new obj
191 * Its equivalent to the Clone() method of other types */
192 aberration_offset_temp.make_unique();
193
194 auto ev = std::make_shared<TelifCommands::SetReferenceAberration>(aberration_offset_temp);
195
196 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::SetReferenceAberration>();
197
198 m_sm.PostEvent(ev);
199
200 return ev->GetPayload().GetReplyFuture();
201 }
202
203 virtual elt::mal::future<std::string> RousConfig(ccsinsif::RousMode mode) override {
204 RAD_TRACE(GetLogger());
205 LOG4CPLUS_INFO(GetLogger(), "Received RousConfig with: Mode " << mode);
206
207 auto ev = std::make_shared<TelifCommands::RousConfig>(mode);
208 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::RousConfig>();
209 m_sm.PostEvent(ev);
210
211 return ev->GetPayload().GetReplyFuture();
212 }
213
214 virtual elt::mal::future<std::string> RousExecute() override {
215 RAD_TRACE(GetLogger());
216 LOG4CPLUS_INFO(GetLogger(), "Received RousExecute");
217
218 auto ev = std::make_shared<TelifCommands::RousExecute>();
219 m_sm.RegisterDefaultRequestRejectHandler<TelifCommands::RousExecute>();
220 m_sm.PostEvent(ev);
221
222 return ev->GetPayload().GetReplyFuture();
223 }
224
225private:
226 rad::SMAdapter& m_sm;
227};
228
229} // namespace hlcc::telif
230
231#endif // HLCC_TELIF_TELIF_COMMANDSIMPL_HPP
Default logger name.
Definition commandsImpl.hpp:27
virtual elt::mal::future< std::string > SetReferenceFocus(double offset) override
Definition commandsImpl.hpp:171
virtual elt::mal::future< std::string > SetVelocityOffset(const std::shared_ptr< ccsinsif::VelocityOffset > &offset) override
Definition commandsImpl.hpp:131
virtual elt::mal::future< std::string > SkyOffset(const std::shared_ptr< ccsinsif::OffsetSkyArgs > &offset_args) override
Definition commandsImpl.hpp:143
virtual elt::mal::future< std::string > SetObservingWavelength(double wavelength) override
Definition commandsImpl.hpp:120
virtual elt::mal::future< std::string > RousConfig(ccsinsif::RousMode mode) override
Definition commandsImpl.hpp:203
CommandsImpl(rad::SMAdapter &sm)
Definition commandsImpl.hpp:29
virtual elt::mal::future< std::string > OffsetSetFocalPlane(const std::shared_ptr< ccsinsif::OffsetFocalPlaneArgs > &offset_args) override
Definition commandsImpl.hpp:156
virtual elt::mal::future< std::string > RequestControl(ccsinsif::ControlMode control_mode) override
Definition commandsImpl.hpp:89
virtual elt::mal::future< std::string > SetReferenceAberration(const elt::mal::shared_vector< const double > &aberration_offset) override
Definition commandsImpl.hpp:182
virtual elt::mal::future< std::string > GetConfig() override
Definition commandsImpl.hpp:109
virtual elt::mal::future< std::string > PresetEphem(const std::shared_ptr< ccsinsif::PresetEphemArgs > &preset_args) override
Definition commandsImpl.hpp:79
virtual elt::mal::future< std::string > Preset(const std::shared_ptr< ccsinsif::PresetArgs > &preset_args) override
Definition commandsImpl.hpp:56
virtual elt::mal::future< std::string > ReleaseControl() override
Definition commandsImpl.hpp:99
virtual ~CommandsImpl()
Definition commandsImpl.hpp:52
virtual elt::mal::future< std::string > RousExecute() override
Definition commandsImpl.hpp:214
Definition configTest.cpp:22
log4cplus::Logger & GetLogger()
Definition logger.cpp:21