Instrument Neutral Distributed Interface INDI 2.2.5
skysafariclient.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 INDI SkySafari Client for INDI Mounts.
5
6 The clients communicates with INDI server to control the mount from SkySafari
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23 The full GNU General Public License is included in this distribution in the
24 file called LICENSE.
25*******************************************************************************/
26
27#include "skysafariclient.h"
28
29#include <cmath>
30#include <cstring>
31
32/**************************************************************************************
33**
34***************************************************************************************/
36{
37 isReady = mountOnline = false;
38}
39
40/**************************************************************************************
41**
42***************************************************************************************/
46
47/**************************************************************************************
48**
49***************************************************************************************/
51{
52 IDLog("Receiving %s Device...\n", dp.getDeviceName());
53
54 if (dp.isDeviceNameMatch(mount))
55 mountOnline = true;
56
57 if (mountOnline)
58 isReady = true;
59}
60
61/**************************************************************************************
62**
63*************************************************************************************/
65{
66 if (property.isNameMatch("TELESCOPE_PARK"))
67 mountParkSP = property.getSwitch();
68 else if (property.isNameMatch("EQUATORIAL_EOD_COORD"))
69 eqCoordsNP = property.getNumber();
70 else if (property.isNameMatch("GEOGRAPHIC_COORD"))
71 geoCoordsNP = property.getNumber();
72 else if (property.isNameMatch("ON_COORD_SET"))
73 gotoModeSP = property.getSwitch();
74 else if (property.isNameMatch("TELESCOPE_ABORT_MOTION"))
75 abortSP = property.getSwitch();
76 else if (property.isNameMatch("TELESCOPE_SLEW_RATE"))
77 slewRateSP = property.getSwitch();
78 else if (property.isNameMatch("TELESCOPE_MOTION_NS"))
79 motionNSSP = property.getSwitch();
80 else if (property.isNameMatch("TELESCOPE_MOTION_WE"))
81 motionWESP = property.getSwitch();
82 else if (property.isNameMatch("TIME_UTC"))
83 timeUTC = property.getText();
84}
85
86/**************************************************************************************
87**
88***************************************************************************************/
89void SkySafariClient::setMount(const std::string &value)
90{
91 mount = value;
92 watchDevice(mount.c_str());
93}
94
95/**************************************************************************************
96**
97***************************************************************************************/
99{
100 if (mountParkSP == nullptr)
101 return false;
102
103 auto sw = mountParkSP->findWidgetByName("PARK");
104
105 if (sw == nullptr)
106 return false;
107
108 mountParkSP->reset();
109 sw->setState(ISS_ON);
110
111 mountParkSP->setState(IPS_BUSY);
112
113 sendNewSwitch(mountParkSP);
114
115 return true;
116}
117
118/**************************************************************************************
119**
120***************************************************************************************/
122{
123 return mountParkSP->getState();
124}
125
126/**************************************************************************************
127**
128***************************************************************************************/
130{
131 if (eqCoordsNP == nullptr)
132 return false;
133
134 eqCoordsNP->setState(IPS_BUSY);
135 sendNewNumber(eqCoordsNP);
136 return true;
137}
138
139/**************************************************************************************
140**
141***************************************************************************************/
143{
144 if (geoCoordsNP == nullptr)
145 return false;
146
147 geoCoordsNP->setState(IPS_BUSY);
148 sendNewNumber(geoCoordsNP);
149 return true;
150}
151
152/**************************************************************************************
153**
154***************************************************************************************/
156{
157 if (gotoModeSP == nullptr)
158 return false;
159
160 sendNewSwitch(gotoModeSP);
161 return true;
162}
163
164/**************************************************************************************
165**
166***************************************************************************************/
168{
169 if (abortSP == nullptr)
170 return false;
171
172 abortSP->at(0)->setState(ISS_ON);
173
174 sendNewSwitch(abortSP);
175 return true;
176}
177
178/**************************************************************************************
179** We get 0 to 3 which we have to map to whatever supported by mount, if any
180***************************************************************************************/
182{
183 if (slewRateSP == nullptr)
184 return false;
185
186 int maxSlewRate = slewRateSP->count() - 1;
187
188 int finalSlewRate = slewRate;
189
190 // If slew rate is between min and max, we interpolate
191 if (slewRate > 0 && slewRate < maxSlewRate)
192 finalSlewRate = static_cast<int>(ceil(slewRate * maxSlewRate / 3.0));
193
194 slewRateSP->reset();
195 slewRateSP->at(finalSlewRate)->setState(ISS_ON);
196
197 sendNewSwitch(slewRateSP);
198
199 return true;
200}
201
202/**************************************************************************************
203**
204***************************************************************************************/
206{
207 if (motionNSSP == nullptr)
208 return false;
209
210 sendNewSwitch(motionNSSP);
211
212 return true;
213}
214
215/**************************************************************************************
216**
217***************************************************************************************/
219{
220 if (motionWESP == nullptr)
221 return false;
222
223 sendNewSwitch(motionWESP);
224
225 return true;
226}
227
228/**************************************************************************************
229**
230***************************************************************************************/
232{
233 if (timeUTC == nullptr)
234 return false;
235
236 sendNewText(timeUTC);
237
238 return true;
239}
void sendNewSwitch(INDI::Property pp)
Send new Switch command to server.
void watchDevice(const char *deviceName)
Add a device to the watch list.
void sendNewNumber(INDI::Property pp)
Send new Number command to server.
void sendNewText(INDI::Property pp)
Send new Text command to server.
Class to provide basic INDI device functionality.
Definition basedevice.h:52
const char * getDeviceName() const
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
Provides generic container for INDI properties.
bool isNameMatch(const char *otherName) const
bool setSlewRate(int slewRate)
virtual void newProperty(INDI::Property property) override
Emmited when a new property is created for an INDI driver.
IPState getMountParkState()
virtual void newDevice(INDI::BaseDevice dp) override
Emmited when a new device is created from INDI server.
void setMount(const std::string &value)
@ 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
int count() const
WidgetType * at(size_t index) const
void setState(IPState state)
WidgetType * findWidgetByName(const char *name) const
void setState(const ISState &state)