7#ifndef indiPropNode_hpp
8#define indiPropNode_hpp
32 pcf::IndiElement::SwitchStateType
m_propValSw{ pcf::IndiElement::SwitchStateType::UnknownSwitchState };
35 pcf::IndiProperty::Type
m_type{ pcf::IndiProperty::Unknown };
49 ingr::instGraphXML *parentGraph
53 void propKey(
const std::string &pk );
59 const std::string &
propKey()
const;
62 void propEl(
const std::string &pe );
68 const std::string &
propEl()
const;
91 const pcf::IndiElement::SwitchStateType &
propValSw();
97 const pcf::IndiProperty::Type &
type()
const;
103 const double &
tol()
const;
109 const bool &
state()
const;
126 void loadConfig( mx::app::appConfigurator &config );
198 if( ipRecv.getType() == pcf::IndiProperty::Type::Number )
200 m_type = pcf::IndiProperty::Type::Number;
205 catch(
const std::exception &e )
207 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::firstSetProperty",
"exception caught" );
211 throw std::runtime_error( msg );
214 else if( ipRecv.getType() == pcf::IndiProperty::Type::Switch )
216 m_type = pcf::IndiProperty::Type::Switch;
224 m_propValSw = pcf::IndiElement::SwitchStateType::On;
226 else if( ustr ==
"OFF" )
228 m_propValSw = pcf::IndiElement::SwitchStateType::Off;
232 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::firstSetProperty",
"invalid switch state" );
233 throw std::invalid_argument( msg );
236 catch(
const std::exception &e )
238 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::firstSetProperty",
"exception caught" );
242 throw std::runtime_error( msg );
245 else if( ipRecv.getType() == pcf::IndiProperty::Type::Text )
247 m_type = pcf::IndiProperty::Type::Text;
251 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::firstSetProperty",
"INDI property of type not implemented" );
252 throw std::runtime_error( msg );
260 bool actionTaken =
false;
265 std::cerr <<
"Error from fsmNode::handleSetProperty\n";
274 if( ipRecv.createUniqueKey() !=
m_propKey )
281 std::cerr <<
"!ipRecv.find( m_propEl )\n";
292 std::cerr <<
"Error from firstSetProperty\n";
296 catch(
const std::exception &e )
298 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::handleSetProperty",
"exception caught" );
302 throw std::runtime_error( msg );
308 if(
m_type == pcf::IndiProperty::Type::Number )
315 else if(
m_type == pcf::IndiProperty::Type::Switch )
322 else if(
m_type == pcf::IndiProperty::Type::Text )
331 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::handleSetProperty",
"type not implemented" );
332 throw std::runtime_error( msg );
386 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::loadConfig",
"parent graph is null" );
387 throw std::runtime_error( msg );
391 config.configUnused(
type, mx::app::iniFile::makeKey(
name(),
"type" ) );
393 if(
type !=
"indiProp" )
395 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::loadConfig",
"node type is not indiProp" );
396 throw std::runtime_error( msg );
402 config.configUnused( pk, mx::app::iniFile::makeKey(
name(),
"propKey" ) );
406 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::loadConfig",
"propKey can not be empty" );
407 throw std::runtime_error( msg );
411 config.configUnused( pe, mx::app::iniFile::makeKey(
name(),
"propEl" ) );
415 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::loadConfig",
"propEl can not be empty" );
416 throw std::runtime_error( msg );
420 config.configUnused( pv, mx::app::iniFile::makeKey(
name(),
"propVal" ) );
424 std::string msg =
XIGN_EXCEPTION(
"indiPropNode::loadConfig",
"propVal can not be empty" );
425 throw std::runtime_error( msg );
428 config.configUnused(
m_tol, mx::app::iniFile::makeKey(
name(),
"tol" ) );
435 config.configUnused(
m_onStr, mx::app::iniFile::makeKey(
name(),
"onStr" ) );
436 config.configUnused(
m_offStr, mx::app::iniFile::makeKey(
name(),
"offStr" ) );
Implementation of an instGraph node interface for a MagAO-X Finite State Machine (FSM)
virtual int handleSetProperty(const pcf::IndiProperty &ipRecv)
INDI SetProperty callback.
void loadConfigDerived(mx::app::appConfigurator &config)
Load this specific node's settings from an application configuration of a derived class.
An instGraph node which tracks a specific INDI property and element of that property.
const std::string & propEl() const
Get the element of the INDI property to track.
const pcf::IndiProperty::Type & type() const
Get the type of the INDI property being tracked.
std::string m_propKey
unique key, device.name, of the property tp track
const pcf::IndiElement::SwitchStateType & propValSw()
Get the target value of the INDI element if it's a switch.
void loadConfig(mx::app::appConfigurator &config)
Configure this node form an appConfigurator.
bool m_state
The current state of the comparison.
bool m_first
Flag indicating if it's the first call to handleSetProperty.
virtual int handleSetProperty(const pcf::IndiProperty &ipRecv)
INDI SetProperty callback.
indiPropNode(const std::string &name, ingr::instGraphXML *parentGraph)
Only c'tor. Must be constructed with node name and a parent graph.
const bool & state() const
Get the current value of the comparison.
const std::string & propValStr() const
Get the target value of the INDI element.
virtual void toggleOff()
Toggle all puts off.
std::string m_propValStr
the target value of the element. This is always set.
double m_tol
The tolerance for floating point comparison. Default is 1e-7.
pcf::IndiProperty::Type m_type
The property type. Discovered introspectively on first call to handleSetProperty.
pcf::IndiElement::SwitchStateType m_propValSw
const std::string & propKey() const
Get the unique key of the INDI property to track.
std::string m_propEl
the element of the property to track
virtual void toggleOn()
Toggle all puts on.
virtual int firstSetProperty(const pcf::IndiProperty &ipRecv)
On first call to handleSetProperty we find the property type and convert the target value.
const double & tol() const
Get the tolerance used for numeric comparison.
const double & propValNum() const
Get the target value of the INDI element if it's a number.
void key(const std::string &nkey)
Add a key to the set.
ingr::instNode * m_node
The underlying instGraph node.
virtual void togglePutsOn()
Change the state of all inputs and all outputs to on.
int m_changes
Counter that can be incremented when changes are detected. Set to 0 when graph is updated.
ingr::instGraphXML * m_parentGraph
The parent instGraph that this node is a part of.
std::string name()
Get the name of this node.
virtual void togglePutsOff()
Change the state of all inputs and all outputs to off.
The MagAO-X Instrument Graph fsmNode header file.
#define XIGN_EXCEPTION(src, expl)