30#define getDeviceName m_defaultDevice->getDeviceName
45 m_ParametersGroup = paramsGroup;
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");
254 LOG_INFO(
"Periodic updates are disabled.");
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);
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);
418 if (oneParameter->getMin() == 0 && oneParameter->getMax() == 0 && oneParameter->getValue() != 0)
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))
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...
bool updateProperty(PropertyType &property, ValueType *values, char *names[], int n, std::function< bool()> updater, bool saveConfig=false)
Generic helper function to update an INDI property based on an external operation.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
void push(WidgetView< T > &&item)
void setState(IPState state)
WidgetView< T > * findWidgetByName(const char *name) const
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
void fill(const char *device, const char *name, const char *label, const char *group, IPState state)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
bool update(const ISState states[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
void setSingleShot(bool singleShot)
Set whether the timer is a single-shot timer.
void callOnTimeout(const std::function< void()> &callback)
void start()
Starts or restarts the timer with the timeout specified in interval.
void setInterval(int msec)
Set the timeout interval in milliseconds.
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
#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.