Instrument Neutral Distributed Interface INDI  1.9.5
weathersimulator.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2018 Jasem Mutlaq. All rights reserved.
3 
4  INDI Weather Simulator
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the Free
8  Software Foundation; either version 2 of the License, or (at your option)
9  any later version.
10 
11  This program is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 
21  The full GNU General Public License is included in this distribution in the
22  file called LICENSE.
23 *******************************************************************************/
24 
25 #include "weathersimulator.h"
26 
27 #include <memory>
28 #include <cstring>
29 
30 // We declare an auto pointer to WeatherSimulator.
31 std::unique_ptr<WeatherSimulator> weatherSimulator(new WeatherSimulator());
32 
34 {
35  setVersion(1, 0);
36 
38 }
39 
41 {
42  return (const char *)"Weather Simulator";
43 }
44 
46 {
47  return true;
48 }
49 
51 {
52  return true;
53 }
54 
56 {
58 
59  IUFillNumber(&ControlWeatherN[CONTROL_WEATHER], "Weather", "Weather", "%.f", 0, 1, 1, 0);
60  IUFillNumber(&ControlWeatherN[CONTROL_TEMPERATURE], "Temperature", "Temperature", "%.2f", -50, 70, 10, 15);
61  IUFillNumber(&ControlWeatherN[CONTROL_WIND], "Wind", "Wind", "%.2f", 0, 100, 5, 0);
62  IUFillNumber(&ControlWeatherN[CONTROL_GUST], "Gust", "Gust", "%.2f", 0, 50, 5, 0);
63  IUFillNumber(&ControlWeatherN[CONTROL_RAIN], "Precip", "Precip", "%.f", 0, 100, 10, 0);
64  IUFillNumberVector(&ControlWeatherNP, ControlWeatherN, 5, getDeviceName(), "WEATHER_CONTROL", "Control", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE);
65 
66  addParameter("WEATHER_FORECAST", "Weather", 0, 0, 15);
67  addParameter("WEATHER_TEMPERATURE", "Temperature (C)", -10, 30, 15);
68  addParameter("WEATHER_WIND_SPEED", "Wind (kph)", 0, 20, 15);
69  addParameter("WEATHER_WIND_GUST", "Gust (kph)", 0, 20, 15);
70  addParameter("WEATHER_RAIN_HOUR", "Precip (mm)", 0, 0, 15);
71 
72  setCriticalParameter("WEATHER_FORECAST");
73  setCriticalParameter("WEATHER_TEMPERATURE");
74  setCriticalParameter("WEATHER_WIND_SPEED");
75  setCriticalParameter("WEATHER_RAIN_HOUR");
76 
78 
79  return true;
80 }
81 
83 {
85 
86  if (isConnected())
87  defineProperty(&ControlWeatherNP);
88  else
89  deleteProperty(ControlWeatherNP.name);
90 
91  return true;
92 }
93 
95 {
96  setParameterValue("WEATHER_FORECAST", ControlWeatherN[CONTROL_WEATHER].value);
97  setParameterValue("WEATHER_TEMPERATURE", ControlWeatherN[CONTROL_TEMPERATURE].value);
98  setParameterValue("WEATHER_WIND_SPEED", ControlWeatherN[CONTROL_WIND].value);
99  setParameterValue("WEATHER_WIND_GUST", ControlWeatherN[CONTROL_GUST].value);
100  setParameterValue("WEATHER_RAIN_HOUR", ControlWeatherN[CONTROL_RAIN].value);
101 
102  return IPS_OK;
103 }
104 
105 bool WeatherSimulator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
106 {
107  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
108  {
109  if (!strcmp(name, ControlWeatherNP.name))
110  {
111  IUUpdateNumber(&ControlWeatherNP, values, names, n);
112  ControlWeatherNP.s = IPS_OK;
113  IDSetNumber(&ControlWeatherNP, nullptr);
114  LOG_INFO("Values are updated and should be active on the next weather update.");
115  return true;
116  }
117  }
118 
119  return INDI::Weather::ISNewNumber(dev, name, values, names, n);
120 }
121 
123 {
125 
126  IUSaveConfigNumber(fp, &ControlWeatherNP);
127 
128  return true;
129 }
WeatherSimulator::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: weathersimulator.cpp:122
INDI::WeatherInterface::setCriticalParameter
bool setCriticalParameter(std::string param)
setCriticalParameter Set parameter that is considered critical to the operation of the observatory....
Definition: indiweatherinterface.cpp:167
WeatherSimulator
Definition: weathersimulator.h:29
IPState
IPState
Property state.
Definition: indiapi.h:158
WeatherSimulator::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: weathersimulator.cpp:105
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
INDI::Weather::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indiweather.cpp:41
IUFillNumber
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition: indidriver.c:348
INDI::DefaultDevice::defineProperty
void defineProperty(INumberVectorProperty *property)
Definition: defaultdevice.cpp:997
MAIN_CONTROL_TAB
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
Definition: defaultdevice.cpp:34
WeatherSimulator::Disconnect
bool Disconnect() override
Disconnect from device.
Definition: weathersimulator.cpp:50
INDI::DefaultDevice::setVersion
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
Definition: defaultdevice.cpp:1219
INDI::BaseDevice::getDeviceName
const char * getDeviceName() const
Definition: basedevice.cpp:799
IUSaveConfigNumber
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
Definition: indicom.c:1455
LOG_INFO
#define LOG_INFO(txt)
Definition: indilogger.h:74
INDI::Weather::setWeatherConnection
void setWeatherConnection(const uint8_t &value)
setWeatherConnection Set Weather connection mode. Child class should call this in the constructor bef...
Definition: indiweather.cpp:402
weatherSimulator
std::unique_ptr< WeatherSimulator > weatherSimulator(new WeatherSimulator())
INDI::Weather::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: indiweather.cpp:369
INDI::Weather::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indiweather.cpp:176
INDI::Weather::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indiweather.cpp:101
IUFillNumberVector
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidriver.c:455
IPS_IDLE
@ IPS_IDLE
Definition: indiapi.h:160
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
WeatherSimulator::updateWeather
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: weathersimulator.cpp:94
INDI::BaseDevice::isConnected
bool isConnected() const
Definition: basedevice.cpp:518
WeatherSimulator::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: weathersimulator.cpp:82
WeatherSimulator::Connect
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: weathersimulator.cpp:45
WeatherSimulator::getDefaultName
const char * getDefaultName() override
Definition: weathersimulator.cpp:40
INDI::WeatherInterface::addParameter
void addParameter(std::string name, std::string label, double numMinOk, double numMaxOk, double percWarning)
addParameter Add a physical weather measurable parameter to the weather driver. The weather value has...
Definition: indiweatherinterface.cpp:131
WeatherSimulator::WeatherSimulator
WeatherSimulator()
Definition: weathersimulator.cpp:33
name
const char * name
Definition: indiserver.c:116
INDI::Weather::CONNECTION_NONE
@ CONNECTION_NONE
Definition: indiweather.h:83
IUUpdateNumber
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
Definition: indidriver.c:225
IP_RW
@ IP_RW
Definition: indiapi.h:185
WeatherSimulator::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: weathersimulator.cpp:55
INDI::DefaultDevice::addDebugControl
void addDebugControl()
Add Debug control to the driver.
Definition: defaultdevice.cpp:639
INDI::DefaultDevice::deleteProperty
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
Definition: defaultdevice.cpp:965
IDSetNumber
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
weathersimulator.h
INDI::WeatherInterface::setParameterValue
void setParameterValue(std::string name, double value)
setParameterValue Update weather parameter value
Definition: indiweatherinterface.cpp:155