LCOV - code coverage report
Current view: top level - apps/xInstGraph/xigNodes - pwrOnOffNode.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 64.5 % 62 40
Test Date: 2026-01-03 21:03:39 Functions: 85.7 % 7 6

            Line data    Source code
       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              : 
      12              : class pwrOnOffNode : public xigNode
      13              : {
      14              : 
      15              :   protected:
      16              :     std::string m_pwrKey;
      17              :     int         m_pwrState{ -1 };
      18              : 
      19              :   public:
      20            3 :     pwrOnOffNode( const std::string &name, ingr::instGraphXML *parentGraph ) : xigNode( name, parentGraph )
      21              :     {
      22            3 :         if( m_parentGraph )
      23              :         {
      24           12 :             m_parentGraph->valueExtra( m_node->name(), "fsmstate", "---" );
      25           15 :             m_parentGraph->valueExtra( m_node->name(), "state", "" );
      26              :         }
      27            3 :     }
      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              : 
      43            2 : inline void pwrOnOffNode::pwrKey( const std::string &pk )
      44              : {
      45            2 :     m_pwrKey = pk;
      46              : 
      47            2 :     key( m_pwrKey );
      48            2 : }
      49              : 
      50            1 : inline const std::string & pwrOnOffNode::pwrKey() const
      51              : {
      52            1 :     return m_pwrKey;
      53              : }
      54              : 
      55            1 : inline int pwrOnOffNode::handleSetProperty( const pcf::IndiProperty &ipRecv )
      56              : {
      57            1 :     if( ipRecv.createUniqueKey() != m_pwrKey )
      58              :     {
      59            0 :         return -1;
      60              :     }
      61              : 
      62            2 :     if( !ipRecv.find( "state" ) )
      63              :     {
      64            0 :         return -1;
      65              :     }
      66              : 
      67            2 :     if( ipRecv["state"].get<std::string>() == "On" )
      68              :     {
      69            1 :         toggleOn();
      70            1 :         return 0;
      71              :     }
      72              :     else
      73              :     {
      74            0 :         toggleOff();
      75            0 :         return 0;
      76              :     }
      77              : }
      78              : 
      79            1 : inline void pwrOnOffNode::toggleOn()
      80              : {
      81            1 :     m_pwrState = 1;
      82              : 
      83            1 :     togglePutsOn();
      84              : 
      85            1 :     if( m_parentGraph )
      86              :     {
      87            1 :         std::cerr << "writing\n";
      88            6 :         m_parentGraph->valueExtra( m_node->name(), "fsmstate", "ON" );
      89              :     }
      90            1 : }
      91              : 
      92            0 : inline void pwrOnOffNode::toggleOff()
      93              : {
      94            0 :     m_pwrState = 1;
      95              : 
      96            0 :     togglePutsOff();
      97              : 
      98            0 :     if( m_parentGraph )
      99              :     {
     100            0 :         m_parentGraph->valueExtra( m_node->name(), "fsmstate", "OFF" );
     101              :     }
     102            0 : }
     103              : 
     104            3 : inline void pwrOnOffNode::loadConfig( mx::app::appConfigurator &config )
     105              : {
     106            3 :     if( !m_parentGraph )
     107              :     {
     108            0 :         std::string msg = "pwrOnOffNode::loadConfig: parent graph is null";
     109            0 :         msg += " at ";
     110            0 :         msg += __FILE__;
     111            0 :         msg += " " + std::to_string( __LINE__ );
     112              : 
     113            0 :         throw std::runtime_error( msg );
     114            0 :     }
     115              : 
     116            3 :     std::string type;
     117            3 :     config.configUnused( type, mx::app::iniFile::makeKey( name(), "type" ) );
     118              : 
     119            3 :     if( type != "pwrOnOff" )
     120              :     {
     121            0 :         std::string msg = "pwrOnOffNode::loadConfig: node type is not pwrOnOff";
     122            0 :         msg += " at ";
     123            0 :         msg += __FILE__;
     124            0 :         msg += " " + std::to_string( __LINE__ );
     125            0 :         throw std::runtime_error( msg );
     126            0 :     }
     127              : 
     128            3 :     std::string pk;
     129            3 :     config.configUnused( pk, mx::app::iniFile::makeKey( name(), "pwrKey" ) );
     130              : 
     131            3 :     if( pk == "" )
     132              :     {
     133            1 :         std::string msg = "pwrOnOffNode::loadConfig: pwrKey can not be empty";
     134            1 :         msg += " at ";
     135            1 :         msg += __FILE__;
     136            1 :         msg += " " + std::to_string( __LINE__ );
     137              : 
     138            1 :         throw std::runtime_error( msg );
     139            1 :     }
     140              : 
     141            2 :     pwrKey( pk );
     142            4 : }
     143              : 
     144              : #endif // pwrOnOffNode_hpp
        

Generated by: LCOV version 2.0-1