7 #ifndef stateRuleEngine_hpp
8 #define stateRuleEngine_hpp
11 #include "../../libMagAOX/libMagAOX.hpp"
12 #include "../../magaox_git_version.h"
101 const pcf::IndiProperty &
ipRecv
126 config.add(
"rules.dir",
134 "Directory containing config files containing rules to load. Relative to config directory. If this is "
135 "set, then rules in the device config file are ignored" );
142 std::map<std::string, ruleRuleKeys> rrkMap;
151 catch(mx::err::mxException & e)
153 return log<
software_critical,-1>({__FILE__,__LINE__, std::string(
"Rule config exception caught:\n") + e.what()});
158 std::vector<std::string> conffiles = mx::ioutils::getFileNames(
m_configDir +
"/" +
m_ruleDir,
"",
"",
".conf");
160 for(
auto & cnf : conffiles)
163 mx::app::appConfigurator fcfg;
165 fcfg.m_sources =
true;
169 if( fcfg.readConfig(cnf) < 0 )
171 return log<
software_critical,-1>({__FILE__,__LINE__,
"error reading rule config file: " + cnf});
179 catch(mx::err::mxException & e)
181 return log<
software_critical,-1>({__FILE__,__LINE__, std::string(
"Rule config exception caught from ") + cnf +
":\n" + e.what()});
189 catch(
const std::exception& e)
191 return log<
software_critical,-1>({__FILE__,__LINE__, std::string(
"Error finalizing rules:\n") + e.what()});
203 log<software_critical>({__FILE__,__LINE__,
"error in configuration"});
217 pcf::IndiProperty::Idle, pcf::IndiProperty::AnyOfMany,
nullptr) < 0)
223 pcf::IndiElement elem = pcf::IndiElement(
it->first, pcf::IndiElement::Off);
232 pcf::IndiProperty::Idle, pcf::IndiProperty::AnyOfMany,
nullptr) < 0)
238 pcf::IndiElement elem = pcf::IndiElement(
it->first, pcf::IndiElement::Off);
247 pcf::IndiProperty::Idle, pcf::IndiProperty::AnyOfMany,
nullptr) < 0)
253 pcf::IndiElement elem = pcf::IndiElement(
it->first, pcf::IndiElement::Off);
262 pcf::IndiProperty::Idle, pcf::IndiProperty::AnyOfMany,
nullptr) < 0)
268 pcf::IndiElement elem = pcf::IndiElement(
it->first, pcf::IndiElement::Off);
275 if(
it->second ==
nullptr)
continue;
277 std::string devName, propName;
282 log<software_error>({__FILE__, __LINE__, 0, rv,
"error parsing INDI key: " +
it->first});
301 bool val =
it->second->value();
311 bool val =
it->second->value();
313 pcf::IndiElement::SwitchStateType onoff = pcf::IndiElement::Off;
314 if(val) onoff = pcf::IndiElement::On;
334 catch(
const std::exception & e)
357 const pcf::IndiProperty &
ipRecv
369 std::string key =
ipRecv.createUniqueKey();
The base-class for MagAO-X applications.
std::string m_configName
The name of the configuration file (minus .conf).
stateCodes::stateCodeT state()
Get the current state code.
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
static void configLog(const std::string &name, const int &code, const std::string &value, const std::string &source)
Callback for config system logging.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::string m_configDir
The path to configuration files for MagAOX.
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.
The MagAO-X stateRuleEngine.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
friend class stateRuleEngine_test
pcf::IndiProperty m_indiP_warning
virtual int appStartup()
Startup function.
pcf::IndiProperty m_indiP_caution
virtual void loadConfig()
~stateRuleEngine() noexcept
D'tor, declared and defined for noexcept.
virtual int appShutdown()
Shutdown the app.
virtual void setupConfig()
pcf::IndiProperty m_indiP_info
static int st_newCallBack_ruleProp(void *app, const pcf::IndiProperty &ipRecv)
The static callback function to be registered for rule properties.
pcf::IndiProperty m_indiP_alert
stateRuleEngine()
Default c'tor.
int newCallBack_ruleProp(const pcf::IndiProperty &ipRecv)
Callback to process a NEW preset position request.
virtual int appLogic()
Implementation of the FSM for stateRuleEngine.
@ READY
The device is ready for operation, but is not operating.
Configuration of rules for the MagAO-X stateRuleEngine.
void loadRuleConfig(indiRuleMaps &maps, std::map< std::string, ruleRuleKeys > &rrkMap, mx::app::appConfigurator &config)
Load the rule and properties maps for a rule engine from a configuration file.
void finalizeRuleValRules(indiRuleMaps &maps, std::map< std::string, ruleRuleKeys > &rrkMap)
Finalize ruleVal rules.
@ caution
Caution – make sure you know what you're doing.
@ warning
Warning – something is probably wrong, you should check.
@ alert
Alert – something is definitely wrong, you should take action.
@ info
For information only.
int parseIndiKey(std::string &devName, std::string &propName, const std::string &key)
Parse an INDI key into the device and property names.
const pcf::IndiProperty & ipRecv
Software CRITICAL log entry.
Structure to provide management of the rule and property maps.