30#define getDeviceName m_defaultDevice->getDeviceName
35 m_UpdateTimer.setSingleShot(
true);
36 m_UpdateTimer.setInterval(60000);
45 m_ParametersGroup = paramsGroup;
49 UpdatePeriodNP[0].fill(
"PERIOD",
"Period (s)",
"%.f", 0, 3600, 60, 60);
81 if (m_defaultDevice->isConnected())
84 m_defaultDevice->defineProperty(
RefreshSP);
96 m_defaultDevice->defineProperty(oneProperty);
103 m_defaultDevice->deleteProperty(
RefreshSP);
117 m_defaultDevice->deleteProperty(oneProperty);
126 if (!m_defaultDevice->isConnected())
192 m_UpdateTimer.start(5000);
216 LOG_WARN(
"Weather override is enabled. Observatory is not safe. Turn off override as soon as possible.");
230 LOG_INFO(
"Weather override is disabled");
251 m_defaultDevice->updateProperty(
UpdatePeriodNP, values, names,
n, [
this, values]()
254 LOG_INFO(
"Periodic updates are disabled.");
257 m_UpdateTimer.setInterval(values[0] * 1000);
258 m_UpdateTimer.start();
269 if (oneRange.isNameMatch(name))
271 m_defaultDevice->updateProperty(oneRange, values, names,
n, [
this, &oneRange, values, names,
n]()
273 oneRange.update(values, names,
n);
288 LOG_ERROR(
"updateWeather() must be implemented in Weather device child class to update weather properties.");
314 double percWarning,
bool flipWarning)
316 LOGF_DEBUG(
"Parameter %s is added. Ok (%.2f,%.2f,%.2f,%s) ", name.c_str(), numMinOk, numMaxOk, percWarning,
317 (flipWarning ?
"true" :
"false"));
320 oneParameter.
fill(name.c_str(), label.c_str(),
"%.2f", numMinOk, numMaxOk, 0, 0);
323 if (numMinOk != numMaxOk)
324 createParameterRange(name, label, numMinOk, numMaxOk, percWarning, flipWarning);
334 auto oneParameter =
ParametersNP.findWidgetByName(name.c_str());
336 oneParameter->setValue(value);
350 auto oneParameter =
ParametersNP.findWidgetByName(name.c_str());
353 LOGF_WARN(
"Unable to find parameter %s in list of existing parameters!", name.c_str());
358 oneLight.
fill(name.c_str(), oneParameter->getLabel(),
IPS_IDLE);
408 return oneElement.isNameMatch(name);
411 auto oneParameter =
ParametersNP.findWidgetByName(name.c_str());
418 if (oneParameter->getMin() == 0 && oneParameter->getMax() == 0 && oneParameter->getValue() != 0)
424 auto minLimit = (*oneRange)[
MIN_OK].getValue();
425 auto maxLimit = (*oneRange)[
MAX_OK].getValue();
427 auto rangeWarn = (maxLimit - minLimit) * (percentageWarning / 100);
430 auto value = oneParameter->getValue();
435 if (value < minLimit || value > maxLimit)
437 else if (((value < (minLimit + rangeWarn)) && minLimit != 0) || ((value > (maxLimit - rangeWarn)) && maxLimit != 0))
445 if (value < minLimit || value > maxLimit)
447 else if (((value < (minLimit + rangeWarn)) && minLimit != 0) || ((value > (maxLimit - rangeWarn)) && maxLimit != 0))
478 auto oneParameter =
ParametersNP.findWidgetByName(oneCriticalParam.getName());
487 oneCriticalParam.setState(
IPS_BUSY);
488 LOGF_WARN(
"Warning: Parameter %s value (%.2f) is in the warning zone!", oneParameter->getLabel(), oneParameter->getValue());
493 LOGF_WARN(
"Caution: Parameter %s value (%.2f) is in the danger zone!", oneParameter->getLabel(), oneParameter->getValue());
498 oneCriticalParam.setState(
IPS_OK);
539void WeatherInterface::createParameterRange(std::string name, std::string label,
double numMinOk,
double numMaxOk,
540 double percWarning,
bool flipWarning)
543 minWidget.
fill(
"MIN_OK",
"OK range min",
"%.2f", -1e6, 1e6, 0, numMinOk);
544 maxWidget.
fill(
"MAX_OK",
"OK range max",
"%.2f", -1e6, 1e6, 0, numMaxOk);
545 warnWidget.
fill(
"PERC_WARN",
"% for Warning",
"%.f", 0, 100, 5, percWarning);
546 typeWidget.
fill(
"ALERT_TYPE",
"Flip alerting to in-bounds",
"%.f", 0, 1, 1, (flipWarning ? 1 : 0));
549 oneRange.
push(std::move(minWidget));
550 oneRange.
push(std::move(maxWidget));
551 oneRange.
push(std::move(warnWidget));
552 oneRange.
push(std::move(typeWidget));
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
void push(WidgetView< T > &&item)
void save(FILE *f) const
save Save property to configuration file.
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
void addParameter(std::string name, std::string label, double numMinOk, double numMaxOk, double percWarning, bool flipWarning=false)
Add a physical weather measurable parameter to the weather driver.
virtual ~WeatherInterface()
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process weather switch properties.
bool setCriticalParameter(std::string name)
setCriticalParameter Set parameter that is considered critical to the operation of the observatory....
bool syncCriticalParameters()
Synchronize and update the state of all critical parameters.
virtual IPState updateWeather()
updateWeather Update weather conditions from device or service. The function should not change the st...
void setParameterValue(std::string name, double value)
setParameterValue Update weather parameter value
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process weather number properties.
WeatherInterface(DefaultDevice *defaultDevice)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save parameters ranges in the config file.
INDI::PropertyNumber ParametersNP
std::vector< INDI::PropertyNumber > ParametersRangeNP
INDI::PropertySwitch OverrideSP
IPState checkParameterState(const std::string ¶m) const
Checks the given parameter against the defined bounds.
void checkWeatherUpdate()
checkWeatherUpdate Calls updateWeather and update critical parameters accordingly.
INDI::PropertyLight SafetyStatusLP
void initProperties(const char *statusGroup, const char *paramsGroup)
Initialize focuser properties. It is recommended to call this function within initProperties() of you...
INDI::PropertySwitch RefreshSP
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
INDI::PropertyLight critialParametersLP
INDI::PropertyNumber UpdatePeriodNP
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Namespace to encapsulate INDI client, drivers, and mediator classes.
INDI::WidgetViewLight WidgetLight
INDI::WidgetViewNumber WidgetNumber