11 #ifndef app_indiUtils_hpp
12 #define app_indiUtils_hpp
17 #include "../../INDI/libcommon/IndiProperty.hpp"
18 #include "../../INDI/libcommon/IndiElement.hpp"
28 #define INDI_IDLE (pcf::IndiProperty::Idle)
29 #define INDI_OK (pcf::IndiProperty::Ok)
30 #define INDI_BUSY (pcf::IndiProperty::Busy)
31 #define INDI_ALERT (pcf::IndiProperty::Alert)
41 const std::string & name,
42 const std::string & label =
""
45 prop.add(pcf::IndiElement(name, 0));
50 prop[name].setLabel(label);
64 const std::string & name,
68 const std::string & format,
69 const std::string & label =
""
72 prop.add(pcf::IndiElement(name, 0));
73 prop[name].setMin(min);
74 prop[name].setMax(max);
75 prop[name].setStep(step);
76 prop[name].setFormat(format);
81 prop[name].setLabel(label);
94 template<
typename T,
class indiDriverT>
96 const std::string & el,
99 pcf::IndiProperty::PropertyStateType newState = pcf::IndiProperty::Ok
107 std::stringstream ssValue;
108 ssValue.precision( 15 );
109 ssValue << std::boolalpha << newVal;
111 pcf::IndiProperty::PropertyStateType oldState = p.getState();
114 if(p[el].getValue() != ssValue.str()|| oldState != newState)
117 p.setTimeStamp(pcf::TimeStamp());
118 p.setState (newState);
122 catch(std::exception & e)
124 std::cerr <<
"Exception caught at " << __FILE__ <<
" " << __LINE__ <<
" ";
125 std::cerr <<
"from " << p.getName() <<
"." << el <<
": ";
130 std::cerr <<
"Exception caught at " << __FILE__ <<
" " << __LINE__ <<
" ";
131 std::cerr <<
"from " << p.getName() <<
"." << el <<
"\n";
142 template<
typename T,
class indiDriverT>
144 const std::vector<std::string> & els,
145 const std::vector<T> & newVals,
147 pcf::IndiProperty::PropertyStateType newState = pcf::IndiProperty::Ok
157 bool changed =
false;
158 pcf::IndiProperty::PropertyStateType oldState = p.getState();
160 if(oldState != newState) changed =
true;
162 for(n=0; n< els.size() && changed !=
true; ++n)
165 std::stringstream ssValue;
166 ssValue.precision( 15 );
167 ssValue << std::boolalpha << newVals[n];
170 if(p[els[n]].getValue() != ssValue.str()) changed =
true;
176 for(n=0; n< els.size(); ++n)
178 p[els[n]].set(newVals[n]);
180 p.setTimeStamp(pcf::TimeStamp());
181 p.setState (newState);
185 catch(std::exception & e)
187 std::cerr <<
"Exception caught at " << __FILE__ <<
" " << __LINE__ <<
" ";
190 std::cerr <<
"from " << p.getName() <<
"." << els[n] <<
": ";
196 std::cerr <<
"Exception caught at " << __FILE__ <<
" " << __LINE__ <<
" ";
199 std::cerr <<
"from " << p.getName() <<
"." << els[n] <<
"\n";
211 template<
class indiDriverT>
213 const std::string & el,
214 const pcf::IndiElement::SwitchStateType & newVal,
216 pcf::IndiProperty::PropertyStateType newState = pcf::IndiProperty::Ok
223 pcf::IndiElement::SwitchStateType oldVal = p[el].getSwitchState();
225 pcf::IndiProperty::PropertyStateType oldState = p.getState();
227 if(oldVal != newVal || oldState != newState)
229 p[el].setSwitchState(newVal);
230 p.setTimeStamp(pcf::TimeStamp());
231 p.setState (newState);
237 std::cerr <<
"INDI Exception at " << __FILE__ <<
" " << __LINE__ <<
"\n";
238 std::cerr <<
"from " << p.getName() <<
"." << el <<
"\n";
248 template<
class indiDriverT>
250 const std::string & el,
252 pcf::IndiProperty::PropertyStateType newState = pcf::IndiProperty::Ok
259 std::cerr <<
"INDI error at " << __FILE__ <<
" " << __LINE__ <<
"\n";
260 std::cerr << p.getName() <<
" does not have " << el <<
"\n";
267 bool changed =
false;
268 for(
auto elit = p.getElements().begin(); elit != p.getElements().end(); ++elit)
270 if( elit->first == el )
272 if(elit->second.getSwitchState() != pcf::IndiElement::On)
274 p[elit->first].setSwitchState(pcf::IndiElement::On);
280 if(elit->second.getSwitchState() != pcf::IndiElement::Off)
282 p[elit->first].setSwitchState(pcf::IndiElement::Off);
288 pcf::IndiProperty::PropertyStateType oldState = p.getState();
290 if(changed || oldState != newState)
292 p.setState (newState);
293 p.setTimeStamp(pcf::TimeStamp());
300 std::cerr <<
"INDI Exception at " << __FILE__ <<
" " << __LINE__ <<
"\n";
301 std::cerr <<
"from " << p.getName() <<
"." << el <<
"\n";
318 std::string & propName,
319 const std::string & key
327 size_t p = key.find(
'.');
329 if(p == std::string::npos)
343 if(p == key.size()-1)
350 devName = key.substr(0, p);
351 propName = key.substr(p+1);
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, indiDriverT *indiDriver, pcf::IndiProperty::PropertyStateType newState=pcf::IndiProperty::Ok)
Update the value of the INDI element, but only if it has changed.
void updateSelectionSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, indiDriverT *indiDriver, pcf::IndiProperty::PropertyStateType newState=pcf::IndiProperty::Ok)
Update the values of a one-of-many INDI switch vector, but only if it has changed.
int parseIndiKey(std::string &devName, std::string &propName, const std::string &key)
Parse an INDI key into the device and property names.
int addTextElement(pcf::IndiProperty &prop, const std::string &name, const std::string &label="")
Add a standard INDI Text element.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, indiDriverT *indiDriver, pcf::IndiProperty::PropertyStateType newState=pcf::IndiProperty::Ok)
Update the value of the INDI element, but only if it has changed.
int addNumberElement(pcf::IndiProperty &prop, const std::string &name, const T &min, const T &max, const T &step, const std::string &format, const std::string &label="")
Add a standard INDI Number element.