Instrument Neutral Distributed Interface INDI  2.0.2
watchdog.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2015 Jasem Mutlaq. All rights reserved.
3 
4  INDI Watchdog driver.
5 
6  The driver expects a heartbeat from the client every X minutes. If no heartbeat
7  is received, the driver executes the shutdown procedures.
8 
9  This program is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by the Free
11  Software Foundation; either version 2 of the License, or (at your option)
12  any later version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17  more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 
24  The full GNU General Public License is included in this distribution in the
25  file called LICENSE.
26 *******************************************************************************/
27 
28 #pragma once
29 
30 #include "defaultdevice.h"
31 
32 class WatchDogClient;
33 
35 {
36  public:
37  typedef enum
38  {
48 
49  WatchDog();
50  virtual ~WatchDog();
51 
52  virtual void ISGetProperties(const char *dev) override;
53  virtual bool ISSnoopDevice(XMLEle * root) override;
54  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
55  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
56  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
57 
58  protected:
59  virtual bool initProperties() override;
60 
61  virtual void TimerHit() override;
62 
63  virtual bool Connect() override;
64  virtual bool Disconnect() override;
65  virtual const char *getDefaultName() override;
66 
67  virtual bool saveConfigItems(FILE *fp) override;
68 
69  private:
70  void parkDome();
71  void parkMount();
72  void executeScript();
73 
74  // Heart Beat to check if client is alive
75  INumberVectorProperty HeartBeatNP;
76  INumber HeartBeatN[1];
77 
78  // Weather threshold
79  INumberVectorProperty WeatherThresholdNP;
80  INumber WeatherThresholdN[1];
81 
82  // Settings
83  ITextVectorProperty SettingsTP;
84  IText SettingsT[4] {};
85  enum {INDISERVER_HOST, INDISERVER_PORT, SHUTDOWN_SCRIPT};
86 
87  // Shutdown steps
88  ISwitchVectorProperty ShutdownProcedureSP;
89  ISwitch ShutdownProcedureS[3];
90 
91  // Mount Policy
92  ISwitchVectorProperty MountPolicySP;
93  ISwitch MountPolicyS[2];
94 
95  // Which source should trigger the shutdown?
96  ISwitchVectorProperty ShutdownTriggerSP;
97  ISwitch ShutdownTriggerS[2];
98  enum { TRIGGER_CLIENT, TRIGGER_WEATHER };
99 
100  // Active Devices to Snoop on
101  ITextVectorProperty ActiveDeviceTP;
102  IText ActiveDeviceT[3] {};
103  enum { ACTIVE_TELESCOPE, ACTIVE_DOME, ACTIVE_WEATHER };
104 
105  // Pointer to client to issue commands to the respective mount and/or dome drivers.
106  WatchDogClient *watchdogClient {nullptr};
107  // Watchdog timer to ensure heart beat is there
108  int32_t m_WatchDogTimer {-1};
109  // Weather timer to trigger shutdown if weather remains ALERT for this many seconds.
110  int32_t m_WeatherAlertTimer {-1};
111  // INDI Port
112  uint32_t m_INDIServerPort { 7624 };
113  // Weather State
114  IPState m_WeatherState { IPS_IDLE };
115  // Mount Parked?
116  bool m_IsMountParked { false };
117  // Dome Parked?
118  bool m_IsDomeParked { false };
119  // State machine to store where in the shutdown procedure we currently stand
120  ShutdownStages m_ShutdownStage;
121 };
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
ShutdownProcedure
Definition: watchdog.h:46
@ EXECUTE_SCRIPT
Definition: watchdog.h:46
@ PARK_DOME
Definition: watchdog.h:46
@ PARK_MOUNT
Definition: watchdog.h:46
virtual ~WatchDog()
Definition: watchdog.cpp:56
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: watchdog.cpp:573
virtual bool Disconnect() override
Disconnect from device.
Definition: watchdog.cpp:102
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: watchdog.cpp:437
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: watchdog.cpp:124
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: watchdog.cpp:179
virtual const char * getDefaultName() override
Definition: watchdog.cpp:64
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: watchdog.cpp:321
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: watchdog.cpp:248
WatchDog()
Definition: watchdog.cpp:43
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: watchdog.cpp:72
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: watchdog.cpp:195
ShutdownStages
Definition: watchdog.h:38
@ WATCHDOG_ERROR
Definition: watchdog.h:44
@ WATCHDOG_IDLE
Definition: watchdog.h:39
@ WATCHDOG_COMPLETE
Definition: watchdog.h:43
@ WATCHDOG_CLIENT_STARTED
Definition: watchdog.h:40
@ WATCHDOG_DOME_PARKED
Definition: watchdog.h:42
@ WATCHDOG_MOUNT_PARKED
Definition: watchdog.h:41
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: watchdog.cpp:555
MountPolicy
Definition: watchdog.h:47
@ MOUNT_IGNORED
Definition: watchdog.h:47
@ MOUNT_LOCKS
Definition: watchdog.h:47
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
@ IPS_IDLE
Definition: indiapi.h:161
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