API
 
Loading...
Searching...
No Matches
pwrOnOffNode.hpp
Go to the documentation of this file.
1/** \file pwrOnOffNode.hpp
2 * \brief The MagAO-X Instrument Graph pwrOnOffNode header file
3 *
4 * \ingroup instGraph_files
5 */
6
7#ifndef pwrOnOffNode_hpp
8#define pwrOnOffNode_hpp
9
10#include "xigNode.hpp"
11
12class pwrOnOffNode : public xigNode
13{
14
15 protected:
16 std::string m_pwrKey;
17 int m_pwrState{ -1 };
18
19 public:
20 pwrOnOffNode( const std::string &name, ingr::instGraphXML *parentGraph ) : xigNode( name, parentGraph )
21 {
22 if( m_parentGraph )
23 {
24 m_parentGraph->valueExtra( m_node->name(), "fsmstate", "---" );
25 m_parentGraph->valueExtra( m_node->name(), "state", "" );
26 }
27 }
28
29 void pwrKey( const std::string &pk );
30
31 const std::string & pwrKey() const;
32
33 /// INDI SetProperty callback
34 virtual int handleSetProperty( const pcf::IndiProperty &ipRecv /**< [in] the received INDI property to handle*/ );
35
36 virtual void toggleOn();
37
38 virtual void toggleOff();
39
40 void loadConfig( mx::app::appConfigurator &config );
41};
42
43inline void pwrOnOffNode::pwrKey( const std::string &pk )
44{
45 m_pwrKey = pk;
46
47 key( m_pwrKey );
48}
49
50inline const std::string & pwrOnOffNode::pwrKey() const
51{
52 return m_pwrKey;
53}
54
55inline int pwrOnOffNode::handleSetProperty( const pcf::IndiProperty &ipRecv )
56{
57 if( ipRecv.createUniqueKey() != m_pwrKey )
58 {
59 return -1;
60 }
61
62 if( !ipRecv.find( "state" ) )
63 {
64 return -1;
65 }
66
67 if( ipRecv["state"].get<std::string>() == "On" )
68 {
69 toggleOn();
70 return 0;
71 }
72 else
73 {
74 toggleOff();
75 return 0;
76 }
77}
78
80{
81 m_pwrState = 1;
82
84
85 if( m_parentGraph )
86 {
87 std::cerr << "writing\n";
88 m_parentGraph->valueExtra( m_node->name(), "fsmstate", "ON" );
89 }
90}
91
93{
94 m_pwrState = 1;
95
97
98 if( m_parentGraph )
99 {
100 m_parentGraph->valueExtra( m_node->name(), "fsmstate", "OFF" );
101 }
102}
103
104inline void pwrOnOffNode::loadConfig( mx::app::appConfigurator &config )
105{
106 if( !m_parentGraph )
107 {
108 std::string msg = "pwrOnOffNode::loadConfig: parent graph is null";
109 msg += " at ";
110 msg += __FILE__;
111 msg += " " + std::to_string( __LINE__ );
112
113 throw std::runtime_error( msg );
114 }
115
116 std::string type;
117 config.configUnused( type, mx::app::iniFile::makeKey( name(), "type" ) );
118
119 if( type != "pwrOnOff" )
120 {
121 std::string msg = "pwrOnOffNode::loadConfig: node type is not pwrOnOff";
122 msg += " at ";
123 msg += __FILE__;
124 msg += " " + std::to_string( __LINE__ );
125 throw std::runtime_error( msg );
126 }
127
128 std::string pk;
129 config.configUnused( pk, mx::app::iniFile::makeKey( name(), "pwrKey" ) );
130
131 if( pk == "" )
132 {
133 std::string msg = "pwrOnOffNode::loadConfig: pwrKey can not be empty";
134 msg += " at ";
135 msg += __FILE__;
136 msg += " " + std::to_string( __LINE__ );
137
138 throw std::runtime_error( msg );
139 }
140
141 pwrKey( pk );
142}
143
144#endif // pwrOnOffNode_hpp
void loadConfig(mx::app::appConfigurator &config)
pwrOnOffNode(const std::string &name, ingr::instGraphXML *parentGraph)
const std::string & pwrKey() const
virtual int handleSetProperty(const pcf::IndiProperty &ipRecv)
INDI SetProperty callback.
virtual void toggleOff()
virtual void toggleOn()
std::string m_pwrKey
Implementation of basic instGraph node interface for MagAO-X.
Definition xigNode.hpp:31
void key(const std::string &nkey)
Add a key to the set.
Definition xigNode.hpp:116
ingr::instNode * m_node
The underlying instGraph node.
Definition xigNode.hpp:37
virtual void togglePutsOn()
Change the state of all inputs and all outputs to on.
Definition xigNode.hpp:126
ingr::instGraphXML * m_parentGraph
The parent instGraph that this node is a part of.
Definition xigNode.hpp:35
std::string name()
Get the name of this node.
Definition xigNode.hpp:106
virtual void togglePutsOff()
Change the state of all inputs and all outputs to off.
Definition xigNode.hpp:141
The base MagAO-X instGraph node header file.