Instrument Neutral Distributed Interface INDI 2.2.5
lx200_16.cpp
Go to the documentation of this file.
1/*
2 LX200 16"
3 Copyright (C) 2003 Jasem Mutlaq ([email protected])
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19*/
20
21#include "lx200_16.h"
22
23#include "indicom.h"
24#include "lx200driver.h"
25
26#include <cmath>
27#include <cstring>
28#include <unistd.h>
29
30#define LX16_TAB "GPS/16 inch Features"
31
36
38{
39 return "LX200 16";
40}
41
43{
45
46 IUFillSwitch(&FanStatusS[0], "On", "", ISS_OFF);
47 IUFillSwitch(&FanStatusS[1], "Off", "", ISS_OFF);
49 IPS_IDLE);
50
51 IUFillSwitch(&HomeSearchS[0], "Save Home", "", ISS_OFF);
52 IUFillSwitch(&HomeSearchS[1], "Set Home", "", ISS_OFF);
54 IPS_IDLE);
55
56 IUFillSwitch(&FieldDeRotatorS[0], "On", "", ISS_OFF);
57 IUFillSwitch(&FieldDeRotatorS[1], "Off", "", ISS_OFF);
60
61 IUFillNumber(&HorizontalCoordsN[0], "ALT", "Alt D:M:S", "%10.6m", -90., 90.0, 0.0, 0);
62 IUFillNumber(&HorizontalCoordsN[1], "AZ", "Az D:M:S", "%10.6m", 0.0, 360.0, 0.0, 0);
64 "Horizontal Coord", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE);
65
67
68 return true;
69}
70
71void LX200_16::ISGetProperties(const char *dev)
72{
73 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
74 return;
75
76 // process parent first
78
79 /*
80 if (isConnected())
81 {
82 defineProperty(&HorizontalCoordsNP);
83 defineProperty(&FanStatusSP);
84 defineProperty(&HomeSearchSP);
85 defineProperty(&FieldDeRotatorSP);
86 }
87 */
88}
89
91{
92 // process parent first
94
95 if (isConnected())
96 {
101 }
102 else
103 {
108 }
109
110 return true;
111}
112
113bool LX200_16::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
114{
115 double newAlt = 0, newAz = 0;
116
117 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
118 {
119 if (!strcmp(name, HorizontalCoordsNP.name))
120 {
121 int i = 0, nset = 0;
122
123 for (nset = i = 0; i < n; i++)
124 {
125 INumber *horp = IUFindNumber(&HorizontalCoordsNP, names[i]);
126 if (horp == &HorizontalCoordsN[0])
127 {
128 newAlt = values[i];
129 nset += newAlt >= -90. && newAlt <= 90.0;
130 }
131 else if (horp == &HorizontalCoordsN[1])
132 {
133 newAz = values[i];
134 nset += newAz >= 0. && newAz <= 360.0;
135 }
136 }
137
138 if (nset == 2)
139 {
140 if (!isSimulation() && (setObjAz(PortFD, newAz) < 0 || setObjAlt(PortFD, newAlt) < 0))
141 {
143 IDSetNumber(&HorizontalCoordsNP, "Error setting Alt/Az.");
144 return false;
145 }
146 targetAZ = newAz;
147 targetALT = newAlt;
148
149 return handleAltAzSlew();
150 }
151 else
152 {
154 IDSetNumber(&HorizontalCoordsNP, "Altitude or Azimuth missing or invalid");
155 return false;
156 }
157 }
158 }
159
160 LX200GPS::ISNewNumber(dev, name, values, names, n);
161 return true;
162}
163
164bool LX200_16::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
165{
166 int index = 0;
167
168 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
169 {
170 if (!strcmp(name, FanStatusSP.name))
171 {
173 IUUpdateSwitch(&FanStatusSP, states, names, n);
175
176 if (index == 0)
177 {
178 if (turnFanOn(PortFD) < 0)
179 {
181 IDSetSwitch(&FanStatusSP, "Error changing fan status.");
182 return false;
183 }
184 }
185 else
186 {
187 if (turnFanOff(PortFD) < 0)
188 {
190 IDSetSwitch(&FanStatusSP, "Error changing fan status.");
191 return false;
192 }
193 }
194
196 IDSetSwitch(&FanStatusSP, index == 0 ? "Fan is ON" : "Fan is OFF");
197 return true;
198 }
199
200 if (!strcmp(name, HomeSearchSP.name))
201 {
202 int ret = 0;
203
205 IUUpdateSwitch(&HomeSearchSP, states, names, n);
207
208 if (index == 0)
209 ret = seekHomeAndSave(PortFD);
210 else
211 ret = seekHomeAndSet(PortFD);
212
213 INDI_UNUSED(ret);
215 IDSetSwitch(&HomeSearchSP, index == 0 ? "Seek Home and Save" : "Seek Home and Set");
216 return true;
217 }
218
219 if (!strcmp(name, FieldDeRotatorSP.name))
220 {
221 int ret = 0;
222
224 IUUpdateSwitch(&FieldDeRotatorSP, states, names, n);
226
227 if (index == 0)
229 else
231
232 INDI_UNUSED(ret);
234 IDSetSwitch(&FieldDeRotatorSP, index == 0 ? "Field deRotator is ON" : "Field deRotator is OFF");
235 return true;
236 }
237 }
238
239 return LX200GPS::ISNewSwitch(dev, name, states, names, n);
240}
241
243{
244 const struct timespec timeout = {0, 100000000L};
245 char altStr[64], azStr[64];
246
248 {
250
251 // sleep for 100 mseconds
252 nanosleep(&timeout, nullptr);
253 }
254
256 {
258 IDSetNumber(&HorizontalCoordsNP, "Slew is not possible.");
259 return false;
260 }
261
263 fs_sexa(azStr, targetAZ, 2, 3600);
264 fs_sexa(altStr, targetALT, 2, 3600);
265
267 IDSetNumber(&HorizontalCoordsNP, "Slewing to Alt %s - Az %s", altStr, azStr);
268 return true;
269}
270
272{
273 int searchResult = 0;
274 double dx, dy;
275
277
278 switch (HomeSearchSP.s)
279 {
280 case IPS_IDLE:
281 break;
282
283 case IPS_BUSY:
284
285 if (isSimulation())
286 searchResult = 1;
287 else if (getHomeSearchStatus(PortFD, &searchResult) < 0)
288 {
290 IDSetSwitch(&HomeSearchSP, "Error updating home search status.");
291 return false;
292 }
293
294 if (searchResult == 0)
295 {
297 IDSetSwitch(&HomeSearchSP, "Home search failed.");
298 }
299 else if (searchResult == 1)
300 {
302 IDSetSwitch(&HomeSearchSP, "Home search successful.");
303 }
304 else if (searchResult == 2)
305 IDSetSwitch(&HomeSearchSP, "Home search in progress...");
306 else
307 {
309 IDSetSwitch(&HomeSearchSP, "Home search error.");
310 }
311 break;
312
313 case IPS_OK:
314 break;
315 case IPS_ALERT:
316 break;
317 }
318
319 switch (HorizontalCoordsNP.s)
320 {
321 case IPS_IDLE:
322 break;
323
324 case IPS_BUSY:
325
326 if (isSimulation())
327 {
328 currentAZ = targetAZ;
329 currentALT = targetALT;
331 return true;
332 }
333 if (getLX200Az(PortFD, &currentAZ) < 0 || getLX200Alt(PortFD, &currentALT) < 0)
334 {
336 IDSetNumber(&HorizontalCoordsNP, "Error getting Alt/Az.");
337 return false;
338 }
339
340 dx = targetAZ - currentAZ;
341 dy = targetALT - currentALT;
342
343 HorizontalCoordsNP.np[0].value = currentALT;
344 HorizontalCoordsNP.np[1].value = currentAZ;
345
346 // accuracy threshold (3'), can be changed as desired.
347 if (fabs(dx) <= 0.05 && fabs(dy) <= 0.05)
348 {
350 currentAZ = targetAZ;
351 currentALT = targetALT;
352 IDSetNumber(&HorizontalCoordsNP, "Slew is complete.");
353 }
354 else
356 break;
357
358 case IPS_OK:
359 break;
360
361 case IPS_ALERT:
362 break;
363 }
364
365 return true;
366}
367
369{
371
372 if (!isSimulation())
373 {
374 getLX200Az(PortFD, &currentAZ);
375 getLX200Alt(PortFD, &currentALT);
376 HorizontalCoordsNP.np[0].value = currentALT;
377 HorizontalCoordsNP.np[1].value = currentAZ;
379 }
380}
bool isConnected() const
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
TelescopeStatus TrackState
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
virtual void getBasicData() override
bool updateProperties()
Called when connected state changes, to add/remove properties.
Definition lx200gps.cpp:124
void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition lx200gps.cpp:99
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition lx200gps.cpp:399
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition lx200gps.cpp:160
bool initProperties()
Called to initialize basic properties required all the time.
Definition lx200gps.cpp:41
virtual bool ReadScopeStatus() override
Read telescope status.
ISwitch FanStatusS[2]
Definition lx200_16.h:49
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition lx200_16.cpp:164
bool handleAltAzSlew()
Definition lx200_16.cpp:242
INumber HorizontalCoordsN[2]
Definition lx200_16.h:52
bool initProperties()
Called to initialize basic properties required all the time.
Definition lx200_16.cpp:42
const char * getDefaultName()
Definition lx200_16.cpp:37
void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition lx200_16.cpp:71
bool ReadScopeStatus()
Read telescope status.
Definition lx200_16.cpp:271
ISwitchVectorProperty HomeSearchSP
Definition lx200_16.h:45
ISwitchVectorProperty FieldDeRotatorSP
Definition lx200_16.h:42
ISwitch HomeSearchS[2]
Definition lx200_16.h:46
ISwitchVectorProperty FanStatusSP
Definition lx200_16.h:48
INumberVectorProperty HorizontalCoordsNP
Definition lx200_16.h:51
void getBasicData()
Definition lx200_16.cpp:368
ISwitch FieldDeRotatorS[2]
Definition lx200_16.h:43
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition lx200_16.cpp:113
bool updateProperties()
Called when connected state changes, to add/remove properties.
Definition lx200_16.cpp:90
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ IP_RW
Definition indiapi.h:184
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition indicom.c:130
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:490
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
Definition indidevapi.c:337
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition indidevapi.c:366
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Definition indidevapi.c:275
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition indidevapi.c:398
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
#define INDI_UNUSED(x)
Definition indidevapi.h:132
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
*brief user defined string literal for JSON values *sa std::size_t n
#define getDeviceName
#define LX16_TAB
Definition lx200_16.cpp:30
int setObjAlt(int fd, double alt)
int getHomeSearchStatus(int fd, int *status)
int setObjAz(int fd, double az)
int abortSlew(int fd)
#define seekHomeAndSave(fd)
#define turnFanOff(fd)
#define turnFieldDeRotatorOn(fd)
#define turnFieldDeRotatorOff(fd)
#define getLX200Alt(fd, x)
#define seekHomeAndSet(fd)
#define getLX200Az(fd, x)
#define slewToAltAz(fd)
#define turnFanOn(fd)
One number descriptor.