Instrument Neutral Distributed Interface INDI  2.0.2
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 {
34 
35 typedef enum
36 {
37  WSP_URL = 0,
40 
41 typedef enum
42 {
47 
48 typedef enum
49 {
51  WSP_SAFE
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 std::string &buffer);
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 };
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...
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
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 IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
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.
bool Disconnect() override
Disconnect from device.
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
std::vector< uint8_t > buffer
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246
@ WSP_USE_SCRIPT
@ WSP_USE_COUNT
@ WSP_USE_CURL
@ WSP_UNSAFE
@ WSP_SAFE
@ WSP_URL_COUNT
wsp_soft_error_enum
@ WSP_SOFT_ERROR_COUNT
@ WSP_SOFT_ERROR_MAX
@ WSP_SOFT_ERROR_RECOVERY
wsp_scripts_enum
@ WSP_SCRIPT_COUNT
@ WSP_SCRIPT