37static std::unique_ptr<WeatherWatcher> weatherWatcher(
new WeatherWatcher());
39static size_t write_data(
void *contents,
size_t size,
size_t nmemb,
void *userp)
41 ((std::string *)userp)->append((
char *)contents, size * nmemb);
53 return "Weather Watcher";
58 if (watchFileTP[0].isEmpty() || watchFileTP[0].
getText()[0] ==
'\0')
60 LOG_ERROR(
"Watch file must be specified first in options.");
72bool WeatherWatcher::createProperties()
74 if (readWatchFile() ==
false)
76 double minOK = 0, maxOK = 0, percWarn = 15;
77 for (
auto const &x : weatherMap)
214 oneProperty.resize(0);
224bool WeatherWatcher::getProperties()
272 watchFileTP[0].
fill(
"URL",
"URL",
nullptr);
296 watchFileTP.
update(texts, names, n);
340 if (readWatchFile() ==
false)
343 for (
auto const &x : weatherMap)
351 setParameterValue(
"WEATHER_TEMPERATURE", std::strtod(x.second.c_str(),
nullptr));
381bool WeatherWatcher::readWatchFile()
390 if (std::string(watchFileTP[0].
getText()).find(
"http") == 0)
393 snprintf(requestURL,
MAXRBUF,
"file://%s", watchFileTP[0].
getText());
395 curl = curl_easy_init();
399 std::string readBuffer;
400 curl_easy_setopt(curl, CURLOPT_URL, requestURL);
401 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
402 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
403 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
404 res = curl_easy_perform(curl);
408 weatherMap = createMap(readBuffer);
411 curl_easy_cleanup(curl);
422 watchFileTP.
save(fp);
429std::map<std::string, std::string> WeatherWatcher::createMap(std::string
const &s)
431 std::map<std::string, std::string> m;
433 std::string key, val;
434 std::istringstream iss(s);
436 while(std::getline(std::getline(iss, key,
separatorTP[0].
getText()[0]) >> std::ws, val))
INDI::PropertyText getText(const char *name) const
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
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 addDebugControl()
Add Debug control to the driver.
void setState(IPState state)
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
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)
bool update(const char *const texts[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
INDI::PropertyViewText * getText() const
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.
bool setCriticalParameter(std::string name)
setCriticalParameter Set parameter that is considered critical to the operation of the observatory....
void setParameterValue(std::string name, double value)
setParameterValue Update weather parameter value
INDI::PropertyNumber ParametersNP
std::vector< INDI::PropertyNumber > ParametersRangeNP
INDI::PropertyLight critialParametersLP
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void setWeatherConnection(const uint8_t &value)
setWeatherConnection Set Weather connection mode. Child class should call this in the constructor bef...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
INDI::PropertyText keywordTP
INDI::PropertyText separatorTP
bool Disconnect() override
Disconnect from device.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
INDI::PropertyText labelTP
INDI::PropertySwitch criticalSP
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int IUGetConfigNumber(const char *dev, const char *property, const char *member, double *value)
IUGetConfigNumber Opens configuration file and reads single number property.
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
const char * PARAMETERS_TAB