API
instGraph.hpp
Go to the documentation of this file.
1 /** \file instGraph.hpp
2  * \brief The MagAO-X XXXXXX header file
3  *
4  * \ingroup instGraph_files
5  */
6 
7 #ifndef instGraph_hpp
8 #define instGraph_hpp
9 
10 #include <instGraph/instGraph.hpp>
11 
12 #include "../../libMagAOX/libMagAOX.hpp" //Note this is included on command line to trigger pch
13 #include "../../magaox_git_version.h"
14 
15 /** \defgroup instGraph
16  * \brief The XXXXXX application to do YYYYYYY
17  *
18  * <a href="../handbook/operating/software/apps/XXXXXX.html">Application Documentation</a>
19  *
20  * \ingroup apps
21  *
22  */
23 
24 /** \defgroup instGraph_files
25  * \ingroup instGraph
26  */
27 
28 namespace MagAOX
29 {
30 namespace app
31 {
32 
33 class xigNode : public ingr::instNode
34 {
35 public:
36 
37  std::set<std::string> m_keys;
38 
39  void key( const std::string nkey )
40  {
41  m_keys.insert(nkey);
42  }
43 
44  virtual void handleSetProperty( const pcf::IndiProperty & ipRecv ) = 0;
45 };
46 
47 class pwrOnOffNode : public xigNode
48 {
49 
50 public:
51 
52  std::string m_pwrKey;
53 
54  virtual void handleSetProperty( const pcf::IndiProperty & ipRecv )
55  {
56  if(m_keys.size() != 1) return;
57 
58  if(m_keys.count(ipRecv.createUniqueKey()) == 0) return;
59 
60  if(!ipRecv.find("state")) return;
61 
62  if(ipRecv["state"].get<std::string>() == "On") return toggleOn();
63  else return toggleOff();
64  }
65 
66  void toggleOn()
67  {
68  std::cerr << "toggle on\n";
69  for(auto && iput : m_inputs)
70  {
71  iput.second->state(ingr::putState::on);
72  }
73 
74  for(auto && oput : m_outputs)
75  {
76  oput.second->state(ingr::putState::on);
77  }
78 
79  }
80 
81  void toggleOff()
82  {
83  std::cerr << "toggle off\n";
84 
85  for(auto && iput : m_inputs)
86  {
87  iput.second->state(ingr::putState::off);
88  }
89 
90  for(auto && oput : m_outputs)
91  {
92  oput.second->state(ingr::putState::off);
93  }
94 
95  }
96 };
97 
98 /// The MagAO-X xxxxxxxx
99 /**
100  * \ingroup instGraph
101  */
102 class instGraph : public MagAOXApp<true>
103 {
104 
105  //Give the test harness access.
106  friend class instGraph_test;
107 
108 protected:
109 
110  /** \name Configurable Parameters
111  *@{
112  */
113 
114  //here add parameters which will be config-able at runtime
115 
116  ///@}
117 
118  ingr::instGraph m_igr;
119 
120  ingr::instBeam * m_beam_source2fwtelsim {nullptr};
121 
122  std::map<std::string, xigNode *> m_nodes;
123  std::multimap<std::string, xigNode *> m_nodeHandleSets;
124 
125 
126 public:
127  /// Default c'tor.
128  instGraph();
129 
130  /// D'tor, declared and defined for noexcept.
131  ~instGraph() noexcept
132  {}
133 
134  virtual void setupConfig();
135 
136  /// Implementation of loadConfig logic, separated for testing.
137  /** This is called by loadConfig().
138  */
139  int loadConfigImpl( mx::app::appConfigurator & _config /**< [in] an application configuration from which to load values*/);
140 
141  virtual void loadConfig();
142 
143  /// Startup function
144  /**
145  *
146  */
147  virtual int appStartup();
148 
149  /// Implementation of the FSM for instGraph.
150  /**
151  * \returns 0 on no critical error
152  * \returns -1 on an error requiring shutdown
153  */
154  virtual int appLogic();
155 
156  /// Shutdown the app.
157  /**
158  *
159  */
160  virtual int appShutdown();
161 
162  /// The static callback function to be registered for node properties
163  /** Dispatches to the relevant handler
164  *
165  * \returns 0 on success.
166  * \returns -1 on error.
167  */
168  static int st_setCallBack_nodeProperties( void * app, ///< [in] a pointer to this, will be static_cast-ed to this
169  const pcf::IndiProperty &ipRecv ///< [in] the INDI property sent with the the new property request.
170  );
171 
172  int setCallBack_nodeProperties( const pcf::IndiProperty &ipRecv /**< [in] the INDI property sent with the the new property request.*/);
173 
174 };
175 
176 instGraph::instGraph() : MagAOXApp(MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED)
177 {
178 
179  return;
180 }
181 
183 {
184 }
185 
186 int instGraph::loadConfigImpl( mx::app::appConfigurator & _config )
187 {
188  static_cast<void>(_config);
189 
190  return 0;
191 }
192 
194 {
195  loadConfigImpl(config);
196 }
197 
198 std::string deviceFromKey(const std::string & key)
199 {
200  size_t dot = key.find('.');
201  if(dot == std::string::npos) return "";
202 
203  return key.substr(0, dot);
204 }
205 
206 std::string nameFromKey(const std::string & key)
207 {
208  size_t dot = key.find('.');
209  if(dot == std::string::npos) return "";
210 
211  return key.substr(dot+1);
212 }
213 
215 {
216  pwrOnOffNode * nn = new pwrOnOffNode;
217  nn->name("source");
218  nn->key("pdu0.source");
219  m_nodes.insert({nn->name(), nn});
220 
221  nn = new pwrOnOffNode;
222  nn->name("fwtelsim");
223  nn->key("usbdu0.fwtelsim");
224  m_nodes.insert({nn->name(), nn});
225 
226  for(auto it=m_nodes.begin(); it != m_nodes.end(); ++it)
227  {
228  for(auto kit=it->second->m_keys.begin(); kit != it->second->m_keys.end(); ++kit)
229  {
230  m_nodeHandleSets.insert({*kit, it->second});
231  pcf::IndiProperty * ip = new pcf::IndiProperty;
232  std::string devname = deviceFromKey(*kit);
233  std::string propname = nameFromKey(*kit);
234  ip->setDevice(devname);
235  ip->setName(propname);
236  registerIndiPropertySet( *ip, devname, propname, st_setCallBack_nodeProperties);
237  }
238  }
239 
240 /* m_node_fwtelsim = new pwrOnOffNode;
241  m_node_fwtelsim->name("fwtelsim");
242 
243  m_node_source->m_device = "pdu0";
244  m_node_source->m_property = "source";
245 
246  REG_INDI_SETPROP(m_indiP_sourcePower, "pdu0", "source");
247 
248  m_node_fwtelsim->m_device = "usbdu0";
249  m_node_fwtelsim->m_property = "fwtelsim";
250 
251  REG_INDI_SETPROP(m_indiP_fwtelsimPower, "usbdu0", "fwtelsim");
252 
253  m_beam_source2fwtelsim = new ingr::instBeam;
254  m_beam_source2fwtelsim->name("source2fwtelsim");
255 
256  ingr::instIOPut * newput = new ingr::instIOPut({m_node_source,ingr::ioDir::output,"out",ingr::putType::light,m_beam_source2fwtelsim});
257  m_node_source->addIOPut(newput);
258 
259  newput = new ingr::instIOPut({m_node_fwtelsim,ingr::ioDir::input,"in",ingr::putType::light,m_beam_source2fwtelsim});
260  m_node_fwtelsim->addIOPut(newput);
261 */
262 
263 
264  return 0;
265 }
266 
268 {
269  //std::cout << ingr::beamState2String(m_beam_source2fwtelsim->state()) << "\n";
270  return 0;
271 }
272 
274 {
275  return 0;
276 }
277 
279  const pcf::IndiProperty &ipRecv
280  )
281 {
282  instGraph * ig = static_cast<instGraph *>(app);
284 }
285 
286 int instGraph::setCallBack_nodeProperties( const pcf::IndiProperty &ipRecv )
287 {
288  auto range = m_nodeHandleSets.equal_range(ipRecv.createUniqueKey());
289 
290  for(auto it=range.first; it != range.second; ++it)
291  {
292  it->second->handleSetProperty(ipRecv);
293  }
294 
295  return 0;
296 }
297 
298 
299 /*
300 INDI_SETCALLBACK_DEFN(instGraph, m_indiP_sourcePower)(const pcf::IndiProperty & ipRecv)
301 {
302  std::cerr << "callback\n";
303 
304  std::cerr << ipRecv.createUniqueKey() << "\n";
305  std::cerr << m_indiP_sourcePower.createUniqueKey() << "\n";
306 
307  if(ipRecv.createUniqueKey() != m_indiP_sourcePower.createUniqueKey())
308  {
309  return -1;
310  }
311 
312  std::cerr << __LINE__ << "\n";
313  //std::cerr << ipRecv.getDevice() << " " << m_node_source->m_device << "\n";
314  if(ipRecv.getDevice() == m_node_source->m_device)
315  {
316  std::cerr << __LINE__ << "\n";
317  if(ipRecv["state"].get<std::string>() == "On") m_node_source->toggleOn();
318  else m_node_source->toggleOff();
319  }
320 
321  return 0;
322 }*/
323 
324 /*
325 INDI_SETCALLBACK_DEFN(instGraph, m_indiP_fwtelsimPower)(const pcf::IndiProperty & ipRecv)
326 {
327  std::cerr << "callback\n";
328 
329  std::cerr << ipRecv.createUniqueKey() << "\n";
330  std::cerr << m_indiP_fwtelsimPower.createUniqueKey() << "\n";
331 
332  if(ipRecv.createUniqueKey() != m_indiP_fwtelsimPower.createUniqueKey())
333  {
334  return -1;
335  }
336 
337  if(ipRecv.getDevice() == m_node_fwtelsim->m_device)
338  {
339  if(ipRecv["state"].get<std::string>() == "On") m_node_fwtelsim->toggleOn();
340  else m_node_fwtelsim->toggleOff();
341  }
342 
343  return 0;
344 }*/
345 
346 } //namespace app
347 } //namespace MagAOX
348 
349 #endif //instGraph_hpp
The base-class for MagAO-X applications.
Definition: MagAOXApp.hpp:75
int registerIndiPropertySet(pcf::IndiProperty &prop, const std::string &devName, const std::string &propName, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is monitored for updates from others.
Definition: MagAOXApp.hpp:2569
The MagAO-X xxxxxxxx.
Definition: instGraph.hpp:103
~instGraph() noexcept
D'tor, declared and defined for noexcept.
Definition: instGraph.hpp:131
int setCallBack_nodeProperties(const pcf::IndiProperty &ipRecv)
Definition: instGraph.hpp:286
virtual void setupConfig()
Definition: instGraph.hpp:182
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
Definition: instGraph.hpp:186
virtual int appStartup()
Startup function.
Definition: instGraph.hpp:214
std::multimap< std::string, xigNode * > m_nodeHandleSets
Definition: instGraph.hpp:123
std::map< std::string, xigNode * > m_nodes
Definition: instGraph.hpp:122
virtual void loadConfig()
Definition: instGraph.hpp:193
virtual int appLogic()
Implementation of the FSM for instGraph.
Definition: instGraph.hpp:267
instGraph()
Default c'tor.
Definition: instGraph.hpp:176
ingr::instGraph m_igr
Definition: instGraph.hpp:118
static int st_setCallBack_nodeProperties(void *app, const pcf::IndiProperty &ipRecv)
The static callback function to be registered for node properties.
Definition: instGraph.hpp:278
friend class instGraph_test
Definition: instGraph.hpp:106
ingr::instBeam * m_beam_source2fwtelsim
Definition: instGraph.hpp:120
virtual int appShutdown()
Shutdown the app.
Definition: instGraph.hpp:273
virtual void handleSetProperty(const pcf::IndiProperty &ipRecv)
Definition: instGraph.hpp:54
std::set< std::string > m_keys
Definition: instGraph.hpp:37
virtual void handleSetProperty(const pcf::IndiProperty &ipRecv)=0
void key(const std::string nkey)
Definition: instGraph.hpp:39
The MagAO-X XXXXXX header file.
GeneratorWrapper< T > range(T const &start, T const &end, T const &step)
Definition: catch.hpp:4700
std::ostream & cerr()
const pcf::IndiProperty & ipRecv
std::string deviceFromKey(const std::string &key)
Definition: instGraph.hpp:198
std::string nameFromKey(const std::string &key)
Definition: instGraph.hpp:206
Definition: dm.hpp:24