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
68
69 return true;
70}
71
72void LX200_16::ISGetProperties(const char *dev)
73{
74 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
75 return;
76
77 // process parent first
79
80 /*
81 if (isConnected())
82 {
83 defineProperty(&HorizontalCoordsNP);
84 defineProperty(&FanStatusSP);
85 defineProperty(&HomeSearchSP);
86 defineProperty(&FieldDeRotatorSP);
87 }
88 */
89}
90
113
114bool LX200_16::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
115{
116 double newAlt = 0, newAz = 0;
117
118 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
119 {
120 if (!strcmp(name, HorizontalCoordsNP.name))
121 {
122 int i = 0, nset = 0;
123
124 for (nset = i = 0; i < n; i++)
125 {
126 INumber *horp = IUFindNumber(&HorizontalCoordsNP, names[i]);
127 if (horp == &HorizontalCoordsN[0])
128 {
129 newAlt = values[i];
130 nset += newAlt >= -90. && newAlt <= 90.0;
131 }
132 else if (horp == &HorizontalCoordsN[1])
133 {
134 newAz = values[i];
135 nset += newAz >= 0. && newAz <= 360.0;
136 }
137 }
138
139 if (nset == 2)
140 {
141 if (!isSimulation() && (setObjAz(PortFD, newAz) < 0 || setObjAlt(PortFD, newAlt) < 0))
142 {
144 IDSetNumber(&HorizontalCoordsNP, "Error setting Alt/Az.");
145 return false;
146 }
147 targetAZ = newAz;
148 targetALT = newAlt;
149
150 return handleAltAzSlew();
151 }
152 else
153 {
155 IDSetNumber(&HorizontalCoordsNP, "Altitude or Azimuth missing or invalid");
156 return false;
157 }
158 }
159 }
160
161 LX200GPS::ISNewNumber(dev, name, values, names, n);
162 return true;
163}
164
165bool LX200_16::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
166{
167 int index = 0;
168
169 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
170 {
171 if (!strcmp(name, FanStatusSP.name))
172 {
174 IUUpdateSwitch(&FanStatusSP, states, names, n);
176
177 if (index == 0)
178 {
179 if (turnFanOn(PortFD) < 0)
180 {
182 IDSetSwitch(&FanStatusSP, "Error changing fan status.");
183 return false;
184 }
185 }
186 else
187 {
188 if (turnFanOff(PortFD) < 0)
189 {
191 IDSetSwitch(&FanStatusSP, "Error changing fan status.");
192 return false;
193 }
194 }
195
197 IDSetSwitch(&FanStatusSP, index == 0 ? "Fan is ON" : "Fan is OFF");
198 return true;
199 }
200
201 if (!strcmp(name, HomeSearchSP.name))
202 {
203 int ret = 0;
204
206 IUUpdateSwitch(&HomeSearchSP, states, names, n);
208
209 if (index == 0)
210 ret = seekHomeAndSave(PortFD);
211 else
212 ret = seekHomeAndSet(PortFD);
213
214 INDI_UNUSED(ret);
216 IDSetSwitch(&HomeSearchSP, index == 0 ? "Seek Home and Save" : "Seek Home and Set");
217 return true;
218 }
219
220 if (!strcmp(name, FieldDeRotatorSP.name))
221 {
222 int ret = 0;
223
225 IUUpdateSwitch(&FieldDeRotatorSP, states, names, n);
227
228 if (index == 0)
230 else
232
233 INDI_UNUSED(ret);
235 IDSetSwitch(&FieldDeRotatorSP, index == 0 ? "Field deRotator is ON" : "Field deRotator is OFF");
236 return true;
237 }
238 }
239
240 return LX200GPS::ISNewSwitch(dev, name, states, names, n);
241}
242
244{
245 const struct timespec timeout = {0, 100000000L};
246 char altStr[64], azStr[64];
247
249 {
251
252 // sleep for 100 mseconds
253 nanosleep(&timeout, nullptr);
254 }
255
257 {
259 IDSetNumber(&HorizontalCoordsNP, "Slew is not possible.");
260 return false;
261 }
262
264 fs_sexa(azStr, targetAZ, 2, 3600);
265 fs_sexa(altStr, targetALT, 2, 3600);
266
268 IDSetNumber(&HorizontalCoordsNP, "Slewing to Alt %s - Az %s", altStr, azStr);
269 return true;
270}
271
273{
274 int searchResult = 0;
275 double dx, dy;
276
278
279 switch (HomeSearchSP.s)
280 {
281 case IPS_IDLE:
282 break;
283
284 case IPS_BUSY:
285
286 if (isSimulation())
287 searchResult = 1;
288 else if (getHomeSearchStatus(PortFD, &searchResult) < 0)
289 {
291 IDSetSwitch(&HomeSearchSP, "Error updating home search status.");
292 return false;
293 }
294
295 if (searchResult == 0)
296 {
298 IDSetSwitch(&HomeSearchSP, "Home search failed.");
299 }
300 else if (searchResult == 1)
301 {
303 IDSetSwitch(&HomeSearchSP, "Home search successful.");
304 }
305 else if (searchResult == 2)
306 IDSetSwitch(&HomeSearchSP, "Home search in progress...");
307 else
308 {
310 IDSetSwitch(&HomeSearchSP, "Home search error.");
311 }
312 break;
313
314 case IPS_OK:
315 break;
316 case IPS_ALERT:
317 break;
318 }
319
320 switch (HorizontalCoordsNP.s)
321 {
322 case IPS_IDLE:
323 break;
324
325 case IPS_BUSY:
326
327 if (isSimulation())
328 {
329 currentAZ = targetAZ;
330 currentALT = targetALT;
332 return true;
333 }
334 if (getLX200Az(PortFD, &currentAZ) < 0 || getLX200Alt(PortFD, &currentALT) < 0)
335 {
337 IDSetNumber(&HorizontalCoordsNP, "Error getting Alt/Az.");
338 return false;
339 }
340
341 dx = targetAZ - currentAZ;
342 dy = targetALT - currentALT;
343
344 HorizontalCoordsNP.np[0].value = currentALT;
345 HorizontalCoordsNP.np[1].value = currentAZ;
346
347 // accuracy threshold (3'), can be changed as desired.
348 if (fabs(dx) <= 0.05 && fabs(dy) <= 0.05)
349 {
351 currentAZ = targetAZ;
352 currentALT = targetALT;
353 IDSetNumber(&HorizontalCoordsNP, "Slew is complete.");
354 }
355 else
357 break;
358
359 case IPS_OK:
360 break;
361
362 case IPS_ALERT:
363 break;
364 }
365
366 return true;
367}
368
370{
372
373 if (!isSimulation())
374 {
375 getLX200Az(PortFD, &currentAZ);
376 getLX200Alt(PortFD, &currentALT);
377 HorizontalCoordsNP.np[0].value = currentALT;
378 HorizontalCoordsNP.np[1].value = currentAZ;
380 }
381}
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
void setState(IPState state)
TelescopeStatus TrackState
virtual void getBasicData() override
bool updateProperties()
Called when connected state changes, to add/remove properties.
Definition lx200gps.cpp:125
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:100
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition lx200gps.cpp:400
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition lx200gps.cpp:161
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:165
bool handleAltAzSlew()
Definition lx200_16.cpp:243
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:72
bool ReadScopeStatus()
Read telescope status.
Definition lx200_16.cpp:272
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:369
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:114
bool updateProperties()
Called when connected state changes, to add/remove properties.
Definition lx200_16.cpp:91
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
INDI::PropertySwitch MountTypeSP
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ 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,...)
#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.
char name[MAXINDINAME]
Definition indiapi.h:321
double value
Definition indiapi.h:288
char name[MAXINDINAME]
Definition indiapi.h:369