Instrument Neutral Distributed Interface INDI 2.2.5
lx200gps.cpp
Go to the documentation of this file.
1/*
2 LX200 GPS
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 "lx200gps.h"
22
23#include "lx200driver.h"
24
25#include <cstring>
26#include <unistd.h>
27
28#define GPS_TAB "Extended GPS Features"
29
35
37{
38 return "LX200 GPS";
39}
40
42{
44
45 IUFillSwitch(&GPSPowerS[0], "On", "", ISS_OFF);
46 IUFillSwitch(&GPSPowerS[1], "Off", "", ISS_OFF);
48 IPS_IDLE);
49
50 IUFillSwitch(&GPSStatusS[0], "Sleep", "", ISS_OFF);
51 IUFillSwitch(&GPSStatusS[1], "Wake Up", "", ISS_OFF);
52 IUFillSwitch(&GPSStatusS[2], "Restart", "", ISS_OFF);
54 IPS_IDLE);
55
56 IUFillSwitch(&GPSUpdateS[0], "Update GPS", "", ISS_OFF);
57 IUFillSwitch(&GPSUpdateS[1], "Update Client", "", ISS_OFF);
59 IPS_IDLE);
60
61 IUFillSwitch(&AltDecPecS[0], "Enable", "", ISS_OFF);
62 IUFillSwitch(&AltDecPecS[1], "Disable", "", ISS_OFF);
64 IPS_IDLE);
65
66 IUFillSwitch(&AzRaPecS[0], "Enable", "", ISS_OFF);
67 IUFillSwitch(&AzRaPecS[1], "Disable", "", ISS_OFF);
69 IPS_IDLE);
70
71 IUFillSwitch(&SelenSyncS[0], "Sync", "", ISS_OFF);
72 IUFillSwitchVector(&SelenSyncSP, SelenSyncS, 1, getDeviceName(), "Selenographic Sync", "", GPS_TAB, IP_RW,
74
75 IUFillSwitch(&AltDecBacklashS[0], "Activate", "", ISS_OFF);
76 IUFillSwitchVector(&AltDecBacklashSP, AltDecBacklashS, 1, getDeviceName(), "Alt/Dec Anti-backlash", "", GPS_TAB,
78
79 IUFillSwitch(&AzRaBacklashS[0], "Activate", "", ISS_OFF);
80 IUFillSwitchVector(&AzRaBacklashSP, AzRaBacklashS, 1, getDeviceName(), "Az/Ra Anti-backlash", "", GPS_TAB, IP_RW,
82
83 IUFillSwitch(&OTAUpdateS[0], "Update", "", ISS_OFF);
85 IPS_IDLE);
86
87 IUFillNumber(&OTATempN[0], "Temp", "", "%03g", -200.0, 500.0, 0.0, 0);
88 IUFillNumberVector(&OTATempNP, OTATempN, 1, getDeviceName(), "OTA Temp (C)", "", GPS_TAB, IP_RO, 0, IPS_IDLE);
89
90 GuideRateNP[0].fill("GUIDE_RATE_WE", "W/E Rate", "%g", 0, 2, 0.05, 0.5);
91 GuideRateNP[1].fill("GUIDE_RATE_NS", "N/S Rate", "%g", 0, 2, 0.05, 0.5);
92 GuideRateNP.fill(getDeviceName(), "GUIDE_RATE", "Custom Guide Rate", MOTION_TAB, IP_RW, 0, IPS_IDLE);
93
96
97 return true;
98}
99
100void LX200GPS::ISGetProperties(const char *dev)
101{
102 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
103 return;
104
105 // process parent first
107
108 /*
109 if (isConnected())
110 {
111 defineProperty(&GPSPowerSP);
112 defineProperty(&GPSStatusSP);
113 defineProperty(&GPSUpdateSP);
114 defineProperty(&AltDecPecSP);
115 defineProperty(&AzRaPecSP);
116 defineProperty(&SelenSyncSP);
117 defineProperty(&AltDecBacklashSP);
118 defineProperty(&AzRaBacklashSP);
119 defineProperty(&OTATempNP);
120 defineProperty(&OTAUpdateSP);
121 }
122 */
123}
124
160
161bool LX200GPS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
162{
163 int index = 0;
164 char msg[64];
165
166 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
167 {
168 /* GPS Power */
169 if (!strcmp(name, GPSPowerSP.name))
170 {
171 int ret = 0;
172
173 if (IUUpdateSwitch(&GPSPowerSP, states, names, n) < 0)
174 return false;
175
177 if (index == 0)
178 ret = turnGPSOn(PortFD);
179 else
180 ret = turnGPSOff(PortFD);
181
182 INDI_UNUSED(ret);
184 IDSetSwitch(&GPSPowerSP, index == 0 ? "GPS System is ON" : "GPS System is OFF");
185 return true;
186 }
187
188 /* GPS Status Update */
189 if (!strcmp(name, GPSStatusSP.name))
190 {
191 int ret = 0;
192
193 if (IUUpdateSwitch(&GPSStatusSP, states, names, n) < 0)
194 return false;
195
197
198 if (index == 0)
199 {
200 ret = gpsSleep(PortFD);
201 strncpy(msg, "GPS system is in sleep mode.", 64);
202 }
203 else if (index == 1)
204 {
205 ret = gpsWakeUp(PortFD)
206 strncpy(msg, "GPS system is reactivated.", 64);
207 }
208 else
209 {
210 ret = gpsRestart(PortFD)
211 strncpy(msg, "GPS system is restarting...", 64);
214 }
215
216 INDI_UNUSED(ret);
218 IDSetSwitch(&GPSStatusSP, "%s", msg);
219 return true;
220 }
221
222 /* GPS Update */
223 if (!strcmp(name, GPSUpdateSP.name))
224 {
225 if (IUUpdateSwitch(&GPSUpdateSP, states, names, n) < 0)
226 return false;
227
229
231
232 if (index == 0)
233 {
234 IDSetSwitch(&GPSUpdateSP, "Updating GPS system. This operation might take few minutes to complete...");
236 {
237 IDSetSwitch(&GPSUpdateSP, "GPS system update successful.");
240 }
241 else
242 {
244 IDSetSwitch(&GPSUpdateSP, "GPS system update failed.");
245 }
246 }
247 else
248 {
251 IDSetSwitch(&GPSUpdateSP, "Client time and location is synced to LX200 GPS Data.");
252 }
253 return true;
254 }
255
256 /* Alt Dec Periodic Error correction */
257 if (!strcmp(name, AltDecPecSP.name))
258 {
259 int ret = 0;
260
261 if (IUUpdateSwitch(&AltDecPecSP, states, names, n) < 0)
262 return false;
263
265
266 if (index == 0)
267 {
268 ret = enableDecAltPec(PortFD);
269 strncpy(msg, "Alt/Dec Compensation Enabled.", 64);
270 }
271 else
272 {
274 strncpy(msg, "Alt/Dec Compensation Disabled.", 64);
275 }
276
277 INDI_UNUSED(ret);
279 IDSetSwitch(&AltDecPecSP, "%s", msg);
280
281 return true;
282 }
283
284 /* Az RA periodic error correction */
285 if (!strcmp(name, AzRaPecSP.name))
286 {
287 int ret = 0;
288
289 if (IUUpdateSwitch(&AzRaPecSP, states, names, n) < 0)
290 return false;
291
293
294 if (index == 0)
295 {
296 ret = enableRaAzPec(PortFD);
297 strncpy(msg, "Ra/Az Compensation Enabled.", 64);
298 }
299 else
300 {
301 ret = disableRaAzPec(PortFD);
302 strncpy(msg, "Ra/Az Compensation Disabled.", 64);
303 }
304
305 INDI_UNUSED(ret);
307 IDSetSwitch(&AzRaPecSP, "%s", msg);
308
309 return true;
310 }
311
312 if (!strcmp(name, AltDecBacklashSP.name))
313 {
314 int ret = 0;
315
317 INDI_UNUSED(ret);
319 IDSetSwitch(&AltDecBacklashSP, "Alt/Dec Anti-backlash enabled");
320 return true;
321 }
322
323 if (!strcmp(name, AzRaBacklashSP.name))
324 {
325 int ret = 0;
326
329 INDI_UNUSED(ret);
330 IDSetSwitch(&AzRaBacklashSP, "Az/Ra Anti-backlash enabled");
331 return true;
332 }
333
334 if (!strcmp(name, OTAUpdateSP.name))
335 {
337
338 if (getOTATemp(PortFD, &OTATempNP.np[0].value) < 0)
339 {
342 IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
343 return false;
344 }
345 else
346 {
349 IDSetNumber(&OTATempNP, nullptr);
350 IDSetSwitch(&OTAUpdateSP, nullptr);
351 return true;
352 }
353 }
354 }
355
356 return LX200Autostar::ISNewSwitch(dev, name, states, names, n);
357}
358
359bool LX200GPS::updateTime(ln_date *utc, double utc_offset)
360{
361 ln_zonedate ltm;
362
363 if (isSimulation())
364 return true;
365
366 JD = ln_get_julian_day(utc);
367
368 LOGF_DEBUG("New JD is %.2f", JD);
369
370 ln_date_to_zonedate(utc, &ltm, utc_offset * 3600);
371
372 LOGF_DEBUG("Local time is %02d:%02d:%02g", ltm.hours, ltm.minutes, ltm.seconds);
373
374 // Set Local Time
375 if (setLocalTime24(ltm.hours, ltm.minutes, ltm.seconds) == false)
376 {
377 LOG_ERROR("Error setting local time time.");
378 return false;
379 }
380
381 // UTC Date, it's not Local for LX200GPS
382 if (setLocalDate(utc->days, utc->months, utc->years) == false)
383 {
384 LOG_ERROR("Error setting UTC date.");
385 return false;
386 }
387
388 // Meade defines UTC Offset as the offset ADDED to local time to yield UTC, which
389 // is the opposite of the standard definition of UTC offset!
390 if (setUTCOffset(utc_offset) == false)
391 {
392 LOG_ERROR("Error setting UTC Offset.");
393 return false;
394 }
395
396 LOG_INFO("Time updated, updating planetary data...");
397 return true;
398}
399
400bool LX200GPS::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
401{
402
403 if (strcmp(name, "GUIDE_RATE") == 0)
404 {
405 GuideRateNP[0].value = values[0];
406 GuideRateNP[1].value = values[1];
408 LOG_INFO("Guide rate set in INDI driver, please check mount is set to the same values");
409 }
410
411 return LX200Autostar::ISNewNumber(dev, name, values, names, n);
412}
413
415{
417 GuideRateNP.save(fp);
418 return true;
419}
420
422{
423 int ret = 0;
424
425 ret = initTelescope(PortFD);
426
427 INDI_UNUSED(ret);
429 SetParked(false);
430 return true;
431}
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)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
TelescopeStatus TrackState
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
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:125
ISwitch OTAUpdateS[1]
Definition lx200gps.h:67
ISwitch SelenSyncS[1]
Definition lx200gps.h:58
ISwitch AltDecBacklashS[1]
Definition lx200gps.h:61
INumberVectorProperty OTATempNP
Definition lx200gps.h:69
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
ISwitchVectorProperty AzRaPecSP
Definition lx200gps.h:54
ISwitchVectorProperty AltDecPecSP
Definition lx200gps.h:51
ISwitch AzRaBacklashS[1]
Definition lx200gps.h:64
ISwitchVectorProperty AzRaBacklashSP
Definition lx200gps.h:63
INDI::PropertyNumber GuideRateNP
Definition lx200gps.h:72
ISwitch GPSUpdateS[2]
Definition lx200gps.h:49
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition lx200gps.cpp:400
ISwitchVectorProperty AltDecBacklashSP
Definition lx200gps.h:60
ISwitchVectorProperty GPSStatusSP
Definition lx200gps.h:45
virtual bool UnPark()
Unpark the telescope if already parked.
Definition lx200gps.cpp:421
ISwitchVectorProperty GPSPowerSP
Definition lx200gps.h:42
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition lx200gps.cpp:414
ISwitch AltDecPecS[2]
Definition lx200gps.h:52
ISwitch GPSStatusS[3]
Definition lx200gps.h:46
ISwitch AzRaPecS[2]
Definition lx200gps.h:55
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
ISwitch GPSPowerS[2]
Definition lx200gps.h:43
ISwitchVectorProperty GPSUpdateSP
Definition lx200gps.h:48
ISwitchVectorProperty OTAUpdateSP
Definition lx200gps.h:66
const char * getDefaultName()
Definition lx200gps.cpp:36
virtual bool updateTime(ln_date *utc, double utc_offset)
Update telescope time, date, and UTC offset.
Definition lx200gps.cpp:359
INumber OTATempN[1]
Definition lx200gps.h:70
ISwitchVectorProperty SelenSyncSP
Definition lx200gps.h:57
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool sendScopeLocation()
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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)
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of 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
@ IP_RO
Definition indiapi.h:182
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_ATMOST1
Definition indiapi.h:172
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
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 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
#define getDeviceName
int getOTATemp(int fd, double *value)
#define enableRaAzPec(fd)
#define activateAltDecAntiBackSlash(fd)
#define initTelescope(fd)
#define gpsSleep(fd)
#define disableDecAltPec(fd)
#define turnGPSOff(fd)
#define gpsWakeUp(fd)
#define enableDecAltPec(fd)
#define gpsRestart(fd)
#define turnGPSOn(fd)
#define updateGPS_System(fd)
#define disableRaAzPec(fd)
#define activateAzRaAntiBackSlash(fd)
#define GPS_TAB
Definition lx200gps.cpp:28
char name[MAXINDINAME]
Definition indiapi.h:321
double value
Definition indiapi.h:288
char name[MAXINDINAME]
Definition indiapi.h:369