Instrument Neutral Distributed Interface INDI  2.0.2
lx200gps.cpp
Go to the documentation of this file.
1 /*
2  LX200 GPS
3  Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
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 "lx200gps.h"
22 
23 #include "lx200driver.h"
24 
25 #include <cstring>
26 #include <unistd.h>
27 
28 #define GPS_TAB "Extended GPS Features"
29 
31 {
33 }
34 
36 {
37  return "LX200 GPS";
38 }
39 
41 {
43 
44  IUFillSwitch(&GPSPowerS[0], "On", "", ISS_OFF);
45  IUFillSwitch(&GPSPowerS[1], "Off", "", ISS_OFF);
47  IPS_IDLE);
48 
49  IUFillSwitch(&GPSStatusS[0], "Sleep", "", ISS_OFF);
50  IUFillSwitch(&GPSStatusS[1], "Wake Up", "", ISS_OFF);
51  IUFillSwitch(&GPSStatusS[2], "Restart", "", ISS_OFF);
53  IPS_IDLE);
54 
55  IUFillSwitch(&GPSUpdateS[0], "Update GPS", "", ISS_OFF);
56  IUFillSwitch(&GPSUpdateS[1], "Update Client", "", ISS_OFF);
58  IPS_IDLE);
59 
60  IUFillSwitch(&AltDecPecS[0], "Enable", "", ISS_OFF);
61  IUFillSwitch(&AltDecPecS[1], "Disable", "", ISS_OFF);
63  IPS_IDLE);
64 
65  IUFillSwitch(&AzRaPecS[0], "Enable", "", ISS_OFF);
66  IUFillSwitch(&AzRaPecS[1], "Disable", "", ISS_OFF);
68  IPS_IDLE);
69 
70  IUFillSwitch(&SelenSyncS[0], "Sync", "", ISS_OFF);
71  IUFillSwitchVector(&SelenSyncSP, SelenSyncS, 1, getDeviceName(), "Selenographic Sync", "", GPS_TAB, IP_RW,
72  ISR_ATMOST1, 0, IPS_IDLE);
73 
74  IUFillSwitch(&AltDecBacklashS[0], "Activate", "", ISS_OFF);
75  IUFillSwitchVector(&AltDecBacklashSP, AltDecBacklashS, 1, getDeviceName(), "Alt/Dec Anti-backlash", "", GPS_TAB,
77 
78  IUFillSwitch(&AzRaBacklashS[0], "Activate", "", ISS_OFF);
79  IUFillSwitchVector(&AzRaBacklashSP, AzRaBacklashS, 1, getDeviceName(), "Az/Ra Anti-backlash", "", GPS_TAB, IP_RW,
80  ISR_ATMOST1, 0, IPS_IDLE);
81 
82  IUFillSwitch(&OTAUpdateS[0], "Update", "", ISS_OFF);
84  IPS_IDLE);
85 
86  IUFillNumber(&OTATempN[0], "Temp", "", "%03g", -200.0, 500.0, 0.0, 0);
87  IUFillNumberVector(&OTATempNP, OTATempN, 1, getDeviceName(), "OTA Temp (C)", "", GPS_TAB, IP_RO, 0, IPS_IDLE);
88 
89  return true;
90 }
91 
92 void LX200GPS::ISGetProperties(const char *dev)
93 {
94  if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
95  return;
96 
97  // process parent first
99 
100  /*
101  if (isConnected())
102  {
103  defineProperty(&GPSPowerSP);
104  defineProperty(&GPSStatusSP);
105  defineProperty(&GPSUpdateSP);
106  defineProperty(&AltDecPecSP);
107  defineProperty(&AzRaPecSP);
108  defineProperty(&SelenSyncSP);
109  defineProperty(&AltDecBacklashSP);
110  defineProperty(&AzRaBacklashSP);
111  defineProperty(&OTATempNP);
112  defineProperty(&OTAUpdateSP);
113  }
114  */
115 }
116 
118 {
120 
121  if (isConnected())
122  {
133  }
134  else
135  {
146  }
147 
148  return true;
149 }
150 
151 bool LX200GPS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
152 {
153  int index = 0;
154  char msg[64];
155 
156  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
157  {
158  /* GPS Power */
159  if (!strcmp(name, GPSPowerSP.name))
160  {
161  int ret = 0;
162 
163  if (IUUpdateSwitch(&GPSPowerSP, states, names, n) < 0)
164  return false;
165 
167  if (index == 0)
168  ret = turnGPSOn(PortFD);
169  else
170  ret = turnGPSOff(PortFD);
171 
172  INDI_UNUSED(ret);
173  GPSPowerSP.s = IPS_OK;
174  IDSetSwitch(&GPSPowerSP, index == 0 ? "GPS System is ON" : "GPS System is OFF");
175  return true;
176  }
177 
178  /* GPS Status Update */
179  if (!strcmp(name, GPSStatusSP.name))
180  {
181  int ret = 0;
182 
183  if (IUUpdateSwitch(&GPSStatusSP, states, names, n) < 0)
184  return false;
185 
187 
188  if (index == 0)
189  {
190  ret = gpsSleep(PortFD);
191  strncpy(msg, "GPS system is in sleep mode.", 64);
192  }
193  else if (index == 1)
194  {
195  ret = gpsWakeUp(PortFD)
196  strncpy(msg, "GPS system is reactivated.", 64);
197  }
198  else
199  {
200  ret = gpsRestart(PortFD)
201  strncpy(msg, "GPS system is restarting...", 64);
202  sendScopeTime();
204  }
205 
206  INDI_UNUSED(ret);
207  GPSStatusSP.s = IPS_OK;
208  IDSetSwitch(&GPSStatusSP, "%s", msg);
209  return true;
210  }
211 
212  /* GPS Update */
213  if (!strcmp(name, GPSUpdateSP.name))
214  {
215  if (IUUpdateSwitch(&GPSUpdateSP, states, names, n) < 0)
216  return false;
217 
219 
220  GPSUpdateSP.s = IPS_OK;
221 
222  if (index == 0)
223  {
224  IDSetSwitch(&GPSUpdateSP, "Updating GPS system. This operation might take few minutes to complete...");
226  {
227  IDSetSwitch(&GPSUpdateSP, "GPS system update successful.");
228  sendScopeTime();
230  }
231  else
232  {
234  IDSetSwitch(&GPSUpdateSP, "GPS system update failed.");
235  }
236  }
237  else
238  {
239  sendScopeTime();
241  IDSetSwitch(&GPSUpdateSP, "Client time and location is synced to LX200 GPS Data.");
242  }
243  return true;
244  }
245 
246  /* Alt Dec Periodic Error correction */
247  if (!strcmp(name, AltDecPecSP.name))
248  {
249  int ret = 0;
250 
251  if (IUUpdateSwitch(&AltDecPecSP, states, names, n) < 0)
252  return false;
253 
255 
256  if (index == 0)
257  {
258  ret = enableDecAltPec(PortFD);
259  strncpy(msg, "Alt/Dec Compensation Enabled.", 64);
260  }
261  else
262  {
263  ret = disableDecAltPec(PortFD);
264  strncpy(msg, "Alt/Dec Compensation Disabled.", 64);
265  }
266 
267  INDI_UNUSED(ret);
268  AltDecPecSP.s = IPS_OK;
269  IDSetSwitch(&AltDecPecSP, "%s", msg);
270 
271  return true;
272  }
273 
274  /* Az RA periodic error correction */
275  if (!strcmp(name, AzRaPecSP.name))
276  {
277  int ret = 0;
278 
279  if (IUUpdateSwitch(&AzRaPecSP, states, names, n) < 0)
280  return false;
281 
282  index = IUFindOnSwitchIndex(&AzRaPecSP);
283 
284  if (index == 0)
285  {
286  ret = enableRaAzPec(PortFD);
287  strncpy(msg, "Ra/Az Compensation Enabled.", 64);
288  }
289  else
290  {
291  ret = disableRaAzPec(PortFD);
292  strncpy(msg, "Ra/Az Compensation Disabled.", 64);
293  }
294 
295  INDI_UNUSED(ret);
296  AzRaPecSP.s = IPS_OK;
297  IDSetSwitch(&AzRaPecSP, "%s", msg);
298 
299  return true;
300  }
301 
302  if (!strcmp(name, AltDecBacklashSP.name))
303  {
304  int ret = 0;
305 
307  INDI_UNUSED(ret);
309  IDSetSwitch(&AltDecBacklashSP, "Alt/Dec Anti-backlash enabled");
310  return true;
311  }
312 
313  if (!strcmp(name, AzRaBacklashSP.name))
314  {
315  int ret = 0;
316 
319  INDI_UNUSED(ret);
320  IDSetSwitch(&AzRaBacklashSP, "Az/Ra Anti-backlash enabled");
321  return true;
322  }
323 
324  if (!strcmp(name, OTAUpdateSP.name))
325  {
327 
328  if (getOTATemp(PortFD, &OTATempNP.np[0].value) < 0)
329  {
332  IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
333  return false;
334  }
335  else
336  {
337  OTAUpdateSP.s = IPS_OK;
338  OTATempNP.s = IPS_OK;
339  IDSetNumber(&OTATempNP, nullptr);
340  IDSetSwitch(&OTAUpdateSP, nullptr);
341  return true;
342  }
343  }
344  }
345 
346  return LX200Autostar::ISNewSwitch(dev, name, states, names, n);
347 }
348 
349 bool LX200GPS::updateTime(ln_date *utc, double utc_offset)
350 {
351  ln_zonedate ltm;
352 
353  if (isSimulation())
354  return true;
355 
356  JD = ln_get_julian_day(utc);
357 
358  LOGF_DEBUG("New JD is %.2f", JD);
359 
360  ln_date_to_zonedate(utc, &ltm, utc_offset * 3600);
361 
362  LOGF_DEBUG("Local time is %02d:%02d:%02g", ltm.hours, ltm.minutes, ltm.seconds);
363 
364  // Set Local Time
365  if (setLocalTime24(ltm.hours, ltm.minutes, ltm.seconds) == false)
366  {
367  LOG_ERROR("Error setting local time time.");
368  return false;
369  }
370 
371  // UTC Date, it's not Local for LX200GPS
372  if (setLocalDate(utc->days, utc->months, utc->years) == false)
373  {
374  LOG_ERROR("Error setting UTC date.");
375  return false;
376  }
377 
378  // Meade defines UTC Offset as the offset ADDED to local time to yield UTC, which
379  // is the opposite of the standard definition of UTC offset!
380  if (setUTCOffset(utc_offset) == false)
381  {
382  LOG_ERROR("Error setting UTC Offset.");
383  return false;
384  }
385 
386  LOG_INFO("Time updated, updating planetary data...");
387  return true;
388 }
389 
391 {
392  int ret = 0;
393 
394  ret = initTelescope(PortFD);
395 
396  INDI_UNUSED(ret);
398  return true;
399 }
bool isConnected() const
Definition: basedevice.cpp:520
const char * getDeviceName() const
Definition: basedevice.cpp:821
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
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
bool updateProperties()
Called when connected state changes, to add/remove properties.
Definition: lx200gps.cpp:117
ISwitch OTAUpdateS[1]
Definition: lx200gps.h:66
ISwitch SelenSyncS[1]
Definition: lx200gps.h:57
ISwitch AltDecBacklashS[1]
Definition: lx200gps.h:60
INumberVectorProperty OTATempNP
Definition: lx200gps.h:68
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:92
ISwitchVectorProperty AzRaPecSP
Definition: lx200gps.h:53
ISwitchVectorProperty AltDecPecSP
Definition: lx200gps.h:50
ISwitch AzRaBacklashS[1]
Definition: lx200gps.h:63
ISwitchVectorProperty AzRaBacklashSP
Definition: lx200gps.h:62
ISwitch GPSUpdateS[2]
Definition: lx200gps.h:48
ISwitchVectorProperty AltDecBacklashSP
Definition: lx200gps.h:59
ISwitchVectorProperty GPSStatusSP
Definition: lx200gps.h:44
virtual bool UnPark()
Unpark the telescope if already parked.
Definition: lx200gps.cpp:390
ISwitchVectorProperty GPSPowerSP
Definition: lx200gps.h:41
LX200GPS()
Definition: lx200gps.cpp:30
ISwitch AltDecPecS[2]
Definition: lx200gps.h:51
ISwitch GPSStatusS[3]
Definition: lx200gps.h:45
ISwitch AzRaPecS[2]
Definition: lx200gps.h:54
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: lx200gps.cpp:151
bool initProperties()
Called to initialize basic properties required all the time.
Definition: lx200gps.cpp:40
ISwitch GPSPowerS[2]
Definition: lx200gps.h:42
ISwitchVectorProperty GPSUpdateSP
Definition: lx200gps.h:47
ISwitchVectorProperty OTAUpdateSP
Definition: lx200gps.h:65
const char * getDefaultName()
Definition: lx200gps.cpp:35
virtual bool updateTime(ln_date *utc, double utc_offset)
Update telescope time, date, and UTC offset.
Definition: lx200gps.cpp:349
INumber OTATempN[1]
Definition: lx200gps.h:69
ISwitchVectorProperty SelenSyncSP
Definition: lx200gps.h:56
virtual bool sendScopeLocation()
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...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool sendScopeTime()
virtual bool setLocalDate(uint8_t days, uint8_t months, uint16_t years)
virtual bool setLocalTime24(uint8_t hour, uint8_t minute, uint8_t second)
virtual bool setUTCOffset(double offset)
ISState
Switch state.
Definition: indiapi.h:150
@ ISS_OFF
Definition: indiapi.h:151
@ IP_RW
Definition: indiapi.h:186
@ IP_RO
Definition: indiapi.h:184
@ IPS_ALERT
Definition: indiapi.h:164
@ IPS_IDLE
Definition: indiapi.h:161
@ IPS_OK
Definition: indiapi.h:162
@ ISR_1OFMANY
Definition: indiapi.h:173
@ ISR_ATMOST1
Definition: indiapi.h:174
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:272
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
Definition: indidevapi.c:128
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition: indidevapi.c:148
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:158
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:180
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:235
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
Definition: indidriver.c:1308
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1211
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
Definition: indidriver.c:1231
#define LOGF_DEBUG(fmt,...)
Definition: indilogger.h:83
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition: indilogger.h:72
#define LOG_INFO(txt)
Definition: indilogger.h:74
int getOTATemp(int fd, double *value)
#define enableRaAzPec(fd)
Definition: lx200driver.h:158
#define activateAltDecAntiBackSlash(fd)
Definition: lx200driver.h:160
#define initTelescope(fd)
Definition: lx200driver.h:175
#define gpsSleep(fd)
Definition: lx200driver.h:152
#define disableDecAltPec(fd)
Definition: lx200driver.h:157
#define turnGPSOff(fd)
Definition: lx200driver.h:150
#define gpsWakeUp(fd)
Definition: lx200driver.h:153
#define enableDecAltPec(fd)
Definition: lx200driver.h:156
#define gpsRestart(fd)
Definition: lx200driver.h:154
#define turnGPSOn(fd)
Definition: lx200driver.h:149
#define updateGPS_System(fd)
Definition: lx200driver.h:155
#define disableRaAzPec(fd)
Definition: lx200driver.h:159
#define activateAzRaAntiBackSlash(fd)
Definition: lx200driver.h:161
#define GPS_TAB
Definition: lx200gps.cpp:28
char name[MAXINDINAME]
Definition: indiapi.h:323
char name[MAXINDINAME]
Definition: indiapi.h:371