API
magAOXMaths.hpp
Go to the documentation of this file.
1 
2 #ifndef magAOXMaths_hpp
3 #define magAOXMaths_hpp
4 
5 #include "../../libMagAOX/libMagAOX.hpp" //Note this is included on command line to trigger pch
6 #include "../../magaox_git_version.h"
7 
8 #include <limits>
9 
10 namespace MagAOX
11 {
12 namespace app
13 {
14 
15 /*
16 void externalLog ( const std::string & name,
17  const int & code,
18  const std::string & valueStr,
19  const std::string & source
20  )
21 {
22  std::cerr << name << " " << code << " " << valueStr << " " << source << "\n";
23 }*/
24 
25 
26 /** MagAO-X application to do math on some numbers
27  *
28  */
29 class magAOXMaths : public MagAOXApp<>
30 {
31 
32 protected:
33  double m_val {0};
34 
35  // declare our properties
36  pcf::IndiProperty m_indiP_myVal;
37  pcf::IndiProperty m_indiP_myVal_maths;
38 
39  pcf::IndiProperty m_indiP_otherVal;
40 
41  pcf::IndiProperty m_indiP_setOtherVal;
42 
43  std::string m_myVal {"x"};
44  std::string m_otherDevName;
45  std::string m_otherValName;
46 
47  int updateVals();
48 
49 public:
50 
51  /// Default c'tor.
52  magAOXMaths();
53 
54  ~magAOXMaths() noexcept
55  {
56  }
57 
58 
59  /// Setup the configuration system (called by MagAOXApp::setup())
60  virtual void setupConfig();
61 
62  /// Load the configuration system results (called by MagAOXApp::setup())
63  virtual void loadConfig();
64 
65  /// Checks if the device was found during loadConfig.
66  virtual int appStartup();
67 
68  /// Implementation of the FSM for the maths.
69  virtual int appLogic();
70 
71  /// Do any needed shutdown tasks. Currently nothing in this app.
72  virtual int appShutdown();
73 
74 
76 
78 
80 
81 };
82 
83 magAOXMaths::magAOXMaths() : MagAOXApp(MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED)
84 {
85  return;
86 }
87 
89 {
90  config.add("myVal", "", "myVal", argType::Required, "", "myVal", false, "string", "The name of this app's value.");
91  config.add("otherDevName", "", "otherDevName", argType::Required, "", "otherDevName", false, "string", "The name of the other app name.");
92  config.add("otherValName", "", "otherValName", argType::Required, "", "otherValName", false, "string", "The name of the other val name.");
93 }
94 
96 {
97  config(m_myVal, "myVal");
98  config(m_otherDevName, "otherDevName");
99  config(m_otherValName, "otherValName");
100 
101 }
102 
104 {
105  // set up the x input property
106  REG_INDI_NEWPROP(m_indiP_myVal, m_myVal, pcf::IndiProperty::Number);
107  indi::addNumberElement<double>( m_indiP_myVal, "value", std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), 1.0, "%f", "");
108  m_indiP_myVal["value"].set<double>(0.0);
109 
110 
111  // set up the result maths property
112  REG_INDI_NEWPROP_NOCB(m_indiP_myVal_maths, "maths", pcf::IndiProperty::Number);
113  indi::addNumberElement<double>(m_indiP_myVal_maths,"value", std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), 1.0, "%f", "");
114  indi::addNumberElement<double>(m_indiP_myVal_maths, "sqr", std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), 1.0, "%f", "");
115  indi::addNumberElement<double>(m_indiP_myVal_maths, "sqrt", std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), 1.0, "%f", "");
116  indi::addNumberElement<double>(m_indiP_myVal_maths, "abs", std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), 1.0, "%f", "");
117  indi::addNumberElement<double>(m_indiP_myVal_maths, "prod", std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), 1.0, "%f", "");
118 
120  m_indiP_otherVal.add (pcf::IndiElement("value"));
121  m_indiP_otherVal["value"].set<double>(0.0);
122 
123  createStandardIndiNumber<double>( m_indiP_setOtherVal, "other_val", -1e50, 1e50, 0, "%0.f");
124  m_indiP_setOtherVal["current"].set<double>(0.0);
125  m_indiP_setOtherVal["target"].set<double>(0.0);
127 
128  updateVals();
130  return 0;
131 }
132 
134 {
135  return 0;
136 
137 }
138 
140 {
141 
142  return 0;
143 }
144 
146 {
147  // extract value
148  double v = m_indiP_myVal["value"].get<double>();
149 
150  if(v == -1) log<text_log>( "value set to -1!", logPrio::LOG_WARNING);
151  if(v == -2) log<text_log>( "value set to -2!", logPrio::LOG_ERROR);
152  if(v == -3) log<text_log>( "value set to -3!", logPrio::LOG_CRITICAL);
153  if(v == -4) log<text_log>( "value set to -4!", logPrio::LOG_ALERT);
154  if(v == -5) log<text_log>( "value set to -5!", logPrio::LOG_EMERGENCY);
155 
156  // fill maths
157  m_indiP_myVal_maths["value"] = v;
158  m_indiP_myVal_maths["sqr"] = v*v;
159  m_indiP_myVal_maths["sqrt"] = sqrt(v);
160  m_indiP_myVal_maths["abs"] = fabs(v);
161 
162  m_indiP_myVal_maths["prod"] = v*m_indiP_otherVal["value"].get<double>();
163  updateIfChanged( m_indiP_setOtherVal, "current", m_indiP_otherVal["value"].get<double>());
164 
165  log<text_log>("set new value: " + std::to_string(v), logPrio::LOG_NOTICE);
166  // publish maths
167  m_indiP_myVal_maths.setState (pcf::IndiProperty::Ok);
168  if(m_indiDriver) m_indiDriver->sendSetProperty (m_indiP_myVal_maths);
169 
170  return 0;
171 }
172 
173 INDI_NEWCALLBACK_DEFN(magAOXMaths, m_indiP_myVal)(const pcf::IndiProperty &ipRecv)
174 {
175 
176  if (ipRecv.getName() == m_indiP_myVal.getName())
177  {
178  // received a new value for property val
179  m_indiP_myVal["value"] = ipRecv["value"].get<double>();
180  m_indiP_myVal.setState (pcf::IndiProperty::Ok);
181  m_indiDriver->sendSetProperty (m_indiP_myVal);
182 
183  updateVals();
184 
185  return 0;
186  }
187  return -1;
188 }
189 
190 INDI_SETCALLBACK_DEFN(magAOXMaths, m_indiP_otherVal)(const pcf::IndiProperty &ipRecv)
191 {
192  m_indiP_otherVal = ipRecv;
193 
194  updateVals();
195  return 0;
196 }
197 
198 INDI_NEWCALLBACK_DEFN(magAOXMaths, m_indiP_setOtherVal)(const pcf::IndiProperty &ipRecv)
199 {
200 
201  if (ipRecv.getName() == m_indiP_setOtherVal.getName())
202  {
203  std::cerr << " m_indiP_setOtherVal\n";
204 
205  // received a new value for property val
206  m_indiP_setOtherVal["target"] = ipRecv["target"].get<double>();
207  m_indiP_setOtherVal.setState (pcf::IndiProperty::Ok);
208  //m_indiDriver->sendSetProperty (m_indiP_myVal);
209 
210  sendNewProperty(m_indiP_otherVal, "value", m_indiP_setOtherVal["target"].get<double>());
211 
212  updateVals();
213 
214  return 0;
215  }
216  return -1;
217 }
218 
219 } //namespace app
220 } //namespace MagAOX
221 
222 #endif //magAOXMaths_hpp
The base-class for MagAO-X applications.
Definition: MagAOXApp.hpp:73
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI property element value if it has changed.
Definition: MagAOXApp.hpp:3120
stateCodes::stateCodeT state()
Get the current state code.
Definition: MagAOXApp.hpp:2297
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.
indiDriver< MagAOXApp > * m_indiDriver
The INDI driver wrapper. Constructed and initialized by execute, which starts and stops communication...
Definition: MagAOXApp.hpp:542
pcf::IndiProperty m_indiP_myVal_maths
Definition: magAOXMaths.hpp:37
pcf::IndiProperty m_indiP_myVal
Definition: magAOXMaths.hpp:36
virtual int appStartup()
Checks if the device was found during loadConfig.
INDI_SETCALLBACK_DECL(magAOXMaths, m_indiP_otherVal)
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
Definition: magAOXMaths.hpp:88
magAOXMaths()
Default c'tor.
Definition: magAOXMaths.hpp:83
pcf::IndiProperty m_indiP_otherVal
Definition: magAOXMaths.hpp:39
INDI_NEWCALLBACK_DECL(magAOXMaths, m_indiP_setOtherVal)
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
virtual void loadConfig()
Load the configuration system results (called by MagAOXApp::setup())
Definition: magAOXMaths.hpp:95
INDI_NEWCALLBACK_DECL(magAOXMaths, m_indiP_myVal)
virtual int appLogic()
Implementation of the FSM for the maths.
pcf::IndiProperty m_indiP_setOtherVal
Definition: magAOXMaths.hpp:41
#define REG_INDI_NEWPROP_NOCB(prop, propName, type)
Register a NEW INDI property with the class, with no callback.
Definition: indiMacros.hpp:248
#define INDI_NEWCALLBACK(prop)
Get the name of the static callback wrapper for a new property.
Definition: indiMacros.hpp:208
#define REG_INDI_NEWPROP(prop, propName, type)
Register a NEW INDI property with the class, using the standard callback name.
Definition: indiMacros.hpp:230
#define REG_INDI_SETPROP(prop, devName, propName)
Register a SET INDI property with the class, using the standard callback name.
Definition: indiMacros.hpp:282
@ READY
The device is ready for operation, but is not operating.
Definition: stateCodes.hpp:56
std::ostream & cerr()
const pcf::IndiProperty & ipRecv
Definition: MagAOXApp.hpp:3434
INDI_SETCALLBACK_DEFN(adcTracker, m_indiP_teldata)(const pcf
Definition: adcTracker.hpp:461
INDI_NEWCALLBACK_DEFN(acesxeCtrl, m_indiP_windspeed)(const pcf
Definition: acesxeCtrl.hpp:687
Definition: dm.hpp:24
constexpr static logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
Definition: logPriority.hpp:37
constexpr static logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
Definition: logPriority.hpp:40
constexpr static logPrioT LOG_ALERT
This should only be used if some action is required by operators to keep the system safe.
Definition: logPriority.hpp:34
constexpr static logPrioT LOG_EMERGENCY
Normal operations of the entire system should be shut down immediately.
Definition: logPriority.hpp:31
constexpr static logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
Definition: logPriority.hpp:43
constexpr static logPrioT LOG_NOTICE
A normal but significant condition.
Definition: logPriority.hpp:46