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__ <<
" ";
188 std::cerr <<
"from " << p.getName() <<
"." << els[n] <<
": ";
193 std::cerr <<
"Exception caught at " << __FILE__ <<
" " << __LINE__ <<
" ";
194 std::cerr <<
"from " << p.getName() <<
"." << els[n] <<
"\n";
205 template<
class indiDriverT>
207 const std::string & el,
208 const pcf::IndiElement::SwitchStateType & newVal,
210 pcf::IndiProperty::PropertyStateType newState = pcf::IndiProperty::Ok
217 pcf::IndiElement::SwitchStateType oldVal = p[el].getSwitchState();
219 pcf::IndiProperty::PropertyStateType oldState = p.getState();
221 if(oldVal != newVal || oldState != newState)
223 p[el].setSwitchState(newVal);
224 p.setTimeStamp(pcf::TimeStamp());
225 p.setState (newState);
231 std::cerr <<
"INDI Exception at " << __FILE__ <<
" " << __LINE__ <<
"\n";
232 std::cerr <<
"from " << p.getName() <<
"." << el <<
"\n";
242 template<
class indiDriverT>
244 const std::string & el,
246 pcf::IndiProperty::PropertyStateType newState = pcf::IndiProperty::Ok
253 std::cerr <<
"INDI error at " << __FILE__ <<
" " << __LINE__ <<
"\n";
254 std::cerr << p.getName() <<
" does not have " << el <<
"\n";
261 bool changed =
false;
262 for(
auto elit = p.getElements().begin(); elit != p.getElements().end(); ++elit)
264 if( elit->first == el )
266 if(elit->second.getSwitchState() != pcf::IndiElement::On)
268 p[elit->first].setSwitchState(pcf::IndiElement::On);
274 if(elit->second.getSwitchState() != pcf::IndiElement::Off)
276 p[elit->first].setSwitchState(pcf::IndiElement::Off);
282 pcf::IndiProperty::PropertyStateType oldState = p.getState();
284 if(changed || oldState != newState)
286 p.setState (newState);
287 p.setTimeStamp(pcf::TimeStamp());
294 std::cerr <<
"INDI Exception at " << __FILE__ <<
" " << __LINE__ <<
"\n";
295 std::cerr <<
"from " << p.getName() <<
"." << el <<
"\n";
312 std::string & propName,
313 const std::string & key
321 size_t p = key.find(
'.');
323 if(p == std::string::npos)
337 if(p == key.size()-1)
344 devName = key.substr(0, p);
345 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.