Instrument Neutral Distributed Interface INDI  1.9.5
weather_safety_proxy.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2019 Hans Lambermont. All rights reserved.
3 
4  INDI Weather Safety Proxy
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 #pragma once
26 
27 #include "indiweather.h"
28 
29 typedef enum
30 {
31  WSP_SCRIPT = 0,
34 
35 typedef enum
36 {
37  WSP_URL = 0,
40 
41 typedef enum
42 {
46 } wsp_use_enum;
47 
48 typedef enum
49 {
52 } wsp_safety;
53 
54 typedef enum
55 {
60 
62 {
63  public:
65  virtual ~WeatherSafetyProxy();
66 
67  // Generic indi device entries
68  bool Connect() override;
69  bool Disconnect() override;
70  const char *getDefaultName() override;
71 
72  virtual bool initProperties() override;
73  virtual bool updateProperties() override;
74  virtual void ISGetProperties(const char *dev) override;
75  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
76  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
77  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
78 
79 
80  protected:
81  virtual IPState updateWeather() override;
82  virtual bool saveConfigItems(FILE *fp) override;
83 
84  private:
85  IPState executeScript();
86  IPState executeCurl();
87  IPState parseSafetyJSON(const char *buf, int byte_count);
88 
89  IText keywordT[1] {};
90  ITextVectorProperty keywordTP;
91 
92  IText ScriptsT[WSP_SCRIPT_COUNT] {};
93  ITextVectorProperty ScriptsTP;
94 
95  IText UrlT[WSP_URL_COUNT] {};
96  ITextVectorProperty UrlTP;
97 
98  ISwitch ScriptOrCurlS[WSP_USE_COUNT];
99  ISwitchVectorProperty ScriptOrCurlSP;
100 
101  IText reasonsT[1] {};
102  ITextVectorProperty reasonsTP;
103 
104  INumber softErrorHysteresisN[WSP_SOFT_ERROR_COUNT];
105  INumberVectorProperty softErrorHysteresisNP;
106 
107  int Safety = -1;
108  int SofterrorCount = 0;
109  int SofterrorRecoveryCount = 0;
110  bool SofterrorRecoveryMode = false;
111  bool LastParseSuccess = false;
112 };
WeatherSafetyProxy::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: weather_safety_proxy.cpp:114
WeatherSafetyProxy::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: weather_safety_proxy.cpp:142
WeatherSafetyProxy::Disconnect
bool Disconnect() override
Disconnect from device.
Definition: weather_safety_proxy.cpp:61
IPState
IPState
Property state.
Definition: indiapi.h:158
WeatherSafetyProxy::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: weather_safety_proxy.cpp:191
WeatherSafetyProxy::getDefaultName
const char * getDefaultName() override
Definition: weather_safety_proxy.cpp:51
WSP_SOFT_ERROR_RECOVERY
@ WSP_SOFT_ERROR_RECOVERY
Definition: weather_safety_proxy.h:57
ISwitch
One switch descriptor.
INumber
One number descriptor.
WeatherSafetyProxy::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: weather_safety_proxy.cpp:158
INDI::Weather
Definition: indiweather.h:68
WeatherSafetyProxy::~WeatherSafetyProxy
virtual ~WeatherSafetyProxy()
Definition: weather_safety_proxy.cpp:49
wsp_safety
wsp_safety
Definition: weather_safety_proxy.h:48
WeatherSafetyProxy::Connect
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: weather_safety_proxy.cpp:56
WSP_SOFT_ERROR_COUNT
@ WSP_SOFT_ERROR_COUNT
Definition: weather_safety_proxy.h:58
WSP_USE_SCRIPT
@ WSP_USE_SCRIPT
Definition: weather_safety_proxy.h:43
WSP_UNSAFE
@ WSP_UNSAFE
Definition: weather_safety_proxy.h:50
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
WSP_SCRIPT
@ WSP_SCRIPT
Definition: weather_safety_proxy.h:53
wsp_use_enum
wsp_use_enum
Definition: weather_safety_proxy.h:41
wsp_soft_error_enum
wsp_soft_error_enum
Definition: weather_safety_proxy.h:54
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
WSP_URL_COUNT
@ WSP_URL_COUNT
Definition: weather_safety_proxy.h:38
IText
One text descriptor.
wsp_urls_enum
wsp_urls_enum
Definition: weather_safety_proxy.h:35
WSP_SOFT_ERROR_MAX
@ WSP_SOFT_ERROR_MAX
Definition: weather_safety_proxy.h:56
WeatherSafetyProxy::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: weather_safety_proxy.cpp:98
WeatherSafetyProxy::WeatherSafetyProxy
WeatherSafetyProxy()
Definition: weather_safety_proxy.cpp:42
WSP_URL
@ WSP_URL
Definition: weather_safety_proxy.h:37
WSP_SAFE
@ WSP_SAFE
Definition: weather_safety_proxy.h:51
wsp_scripts_enum
wsp_scripts_enum
Definition: weather_safety_proxy.h:29
WeatherSafetyProxy::ISGetProperties
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...
Definition: weather_safety_proxy.cpp:124
WSP_SCRIPT_COUNT
@ WSP_SCRIPT_COUNT
Definition: weather_safety_proxy.h:54
WSP_USE_COUNT
@ WSP_USE_COUNT
Definition: weather_safety_proxy.h:45
WeatherSafetyProxy::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: weather_safety_proxy.cpp:66
name
const char * name
Definition: indiserver.c:116
WeatherSafetyProxy
Definition: weather_safety_proxy.h:61
WeatherSafetyProxy::updateWeather
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
Definition: weather_safety_proxy.cpp:209
ISState
ISState
Switch state.
Definition: indiapi.h:148
indiweather.h
WSP_USE_CURL
@ WSP_USE_CURL
Definition: weather_safety_proxy.h:44
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365