Instrument Neutral Distributed Interface INDI 2.2.5
watchdogclient.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2015 Jasem Mutlaq. All rights reserved.
3
4 INDI Watchdog Client.
5
6 The clients communicates with INDI server to put devices in a safe state for shutdown
7 INDI Watchdog driver.
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#include "watchdogclient.h"
29
30#include <cstring>
31#include <memory>
32
33/**************************************************************************************
34**
35***************************************************************************************/
37{
38 isReady = isRunning = mountOnline = domeOnline = false;
39 mountParkSP = domeParkSP = nullptr;
40}
41
42/**************************************************************************************
43**
44***************************************************************************************/
48
49/**************************************************************************************
50**
51***************************************************************************************/
53{
54 IDLog("Receiving new device: %s\n", dp.getDeviceName());
55
56 if (dome.empty() || std::string(dp.getDeviceName()) == dome)
57 domeOnline = true;
58 if (mount.empty() || std::string(dp.getDeviceName()) == mount)
59 mountOnline = true;
60
61 isReady = (domeOnline && mountOnline);
62}
63
64/**************************************************************************************
65**
66*************************************************************************************/
68{
69 if (property.isNameMatch("TELESCOPE_PARK"))
70 mountParkSP = property.getSwitch();
71 else if (property.isNameMatch("DOME_PARK"))
72 domeParkSP = property.getSwitch();
73}
74
75/**************************************************************************************
76**
77***************************************************************************************/
78void WatchDogClient::setMount(const std::string &value)
79{
80 mount = value;
81 watchDevice(mount.c_str());
82}
83
84/**************************************************************************************
85**
86***************************************************************************************/
87void WatchDogClient::setDome(const std::string &value)
88{
89 dome = value;
90 watchDevice(dome.c_str());
91}
92
93/**************************************************************************************
94**
95***************************************************************************************/
97{
98 if (domeParkSP == nullptr)
99 return false;
100
101 auto sw = domeParkSP->findWidgetByName("PARK");
102
103 if (sw == nullptr)
104 return false;
105
106 domeParkSP->reset();
107 sw->setState(ISS_ON);
108
109 domeParkSP->setState(IPS_BUSY);
110
111 sendNewSwitch(domeParkSP);
112
113 return true;
114}
115
116/**************************************************************************************
117**
118***************************************************************************************/
120{
121 if (mountParkSP == nullptr)
122 return false;
123
124 auto sw = mountParkSP->findWidgetByName("PARK");
125
126 if (sw == nullptr)
127 return false;
128
129 mountParkSP->reset();
130 sw->setState(ISS_ON);
131
132 mountParkSP->setState(IPS_BUSY);
133
134 sendNewSwitch(mountParkSP);
135
136 return true;
137}
138
139/**************************************************************************************
140**
141***************************************************************************************/
143{
144 return domeParkSP->getState();
145}
146
147/**************************************************************************************
148**
149***************************************************************************************/
151{
152 return mountParkSP->getState();
153}
void sendNewSwitch(INDI::Property pp)
Send new Switch command to server.
void watchDevice(const char *deviceName)
Add a device to the watch list.
Class to provide basic INDI device functionality.
Definition basedevice.h:52
const char * getDeviceName() const
Provides generic container for INDI properties.
bool isNameMatch(const char *otherName) const
IPState getDomeParkState()
IPState getMountParkState()
virtual void newProperty(INDI::Property property) override
Emmited when a new property is created for an INDI driver.
void setMount(const std::string &value)
void setDome(const std::string &value)
virtual void newDevice(INDI::BaseDevice dp) override
Emmited when a new device is created from INDI server.
@ ISS_ON
Definition indiapi.h:150
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
void IDLog(const char *fmt,...)
Definition indicom.c:305
IPState getState() const
void setState(IPState state)
WidgetType * findWidgetByName(const char *name) const