Instrument Neutral Distributed Interface INDI 2.2.5
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#include "inditimer.h"
32
33class WatchDogClient;
34
36{
37 public:
49
50 WatchDog();
51 virtual ~WatchDog();
52
53 virtual void ISGetProperties(const char *dev) override;
54 virtual bool ISSnoopDevice(XMLEle * root) override;
55 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
56 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
57 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
58
59 protected:
60 virtual bool initProperties() override;
61 virtual bool Connect() override;
62 virtual bool Disconnect() override;
63 virtual void TimerHit() override;
64 virtual const char *getDefaultName() override;
65
66 virtual bool saveConfigItems(FILE *fp) override;
67
68 private:
69 void processShutdown();
70 void parkDome();
71 void parkMount();
72 void executeScript();
73
74 // Heart Beat to check if client is alive
75 INDI::PropertyNumber HeartBeatNP {1};
76
77 // Weather threshold
78 INumberVectorProperty WeatherThresholdNP;
79 INumber WeatherThresholdN[1];
80
81 // Settings
82 ITextVectorProperty SettingsTP;
83 IText SettingsT[4] {};
84 enum {INDISERVER_HOST, INDISERVER_PORT, SHUTDOWN_SCRIPT};
85
86 // Shutdown steps
87 ISwitchVectorProperty ShutdownProcedureSP;
88 ISwitch ShutdownProcedureS[3];
89
90 // Mount Policy
91 ISwitchVectorProperty MountPolicySP;
92 ISwitch MountPolicyS[2];
93
94 // Which source should trigger the shutdown?
95 ISwitchVectorProperty ShutdownTriggerSP;
96 ISwitch ShutdownTriggerS[2];
97 enum { TRIGGER_CLIENT, TRIGGER_WEATHER };
98
99 // Active Devices to Snoop on
100 ITextVectorProperty ActiveDeviceTP;
101 IText ActiveDeviceT[3] {};
102 enum { ACTIVE_TELESCOPE, ACTIVE_DOME, ACTIVE_WEATHER };
103
104 // Pointer to client to issue commands to the respective mount and/or dome drivers.
105 std::unique_ptr<WatchDogClient> m_WatchDogClientInstance;
106 // Watchdog timer to ensure heart beat is there
107 INDI::Timer m_ClientAlertTimer;
108 // Weather timer to trigger shutdown if weather remains ALERT for this many seconds.
109 INDI::Timer m_WeatherAlertTimer;
110 // INDI Port
111 uint32_t m_INDIServerPort { 7624 };
112 // Weather State
113 IPState m_WeatherState { IPS_IDLE };
114 // Mount Parked?
115 bool m_IsMountParked { false };
116 // Dome Parked?
117 bool m_IsDomeParked { false };
118 // State machine to store where in the shutdown procedure we currently stand
119 ShutdownStages m_ShutdownStage;
120};
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The Timer class provides repetitive and single-shot timers.
Definition inditimer.h:41
ShutdownProcedure
Definition watchdog.h:47
@ EXECUTE_SCRIPT
Definition watchdog.h:47
@ PARK_DOME
Definition watchdog.h:47
@ PARK_MOUNT
Definition watchdog.h:47
virtual ~WatchDog()
Definition watchdog.cpp:61
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition watchdog.cpp:585
virtual bool Disconnect() override
Disconnect from device.
Definition watchdog.cpp:105
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:423
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition watchdog.cpp:119
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:176
virtual const char * getDefaultName() override
Definition watchdog.cpp:68
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition watchdog.cpp:314
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition watchdog.cpp:245
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition watchdog.cpp:76
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition watchdog.cpp:192
ShutdownStages
Definition watchdog.h:39
@ WATCHDOG_ERROR
Definition watchdog.h:45
@ WATCHDOG_IDLE
Definition watchdog.h:40
@ WATCHDOG_COMPLETE
Definition watchdog.h:44
@ WATCHDOG_CLIENT_STARTED
Definition watchdog.h:41
@ WATCHDOG_DOME_PARKED
Definition watchdog.h:43
@ WATCHDOG_MOUNT_PARKED
Definition watchdog.h:42
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition watchdog.cpp:536
@ MOUNT_IGNORED
Definition watchdog.h:48
@ MOUNT_LOCKS
Definition watchdog.h:48
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
@ IPS_IDLE
Definition indiapi.h:159
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244