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
95
96 return true;
97}
98
99void LX200GPS::ISGetProperties(const char *dev)
100{
101 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0)
102 return;
103
104 // process parent first
106
107 /*
108 if (isConnected())
109 {
110 defineProperty(&GPSPowerSP);
111 defineProperty(&GPSStatusSP);
112 defineProperty(&GPSUpdateSP);
113 defineProperty(&AltDecPecSP);
114 defineProperty(&AzRaPecSP);
115 defineProperty(&SelenSyncSP);
116 defineProperty(&AltDecBacklashSP);
117 defineProperty(&AzRaBacklashSP);
118 defineProperty(&OTATempNP);
119 defineProperty(&OTAUpdateSP);
120 }
121 */
122}
123
159
160bool LX200GPS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
161{
162 int index = 0;
163 char msg[64];
164
165 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
166 {
167 /* GPS Power */
168 if (!strcmp(name, GPSPowerSP.name))
169 {
170 int ret = 0;
171
172 if (IUUpdateSwitch(&GPSPowerSP, states, names, n) < 0)
173 return false;
174
176 if (index == 0)
177 ret = turnGPSOn(PortFD);
178 else
179 ret = turnGPSOff(PortFD);
180
181 INDI_UNUSED(ret);
182 GPSPowerSP.s = IPS_OK;
183 IDSetSwitch(&GPSPowerSP, index == 0 ? "GPS System is ON" : "GPS System is OFF");
184 return true;
185 }
186
187 /* GPS Status Update */
188 if (!strcmp(name, GPSStatusSP.name))
189 {
190 int ret = 0;
191
192 if (IUUpdateSwitch(&GPSStatusSP, states, names, n) < 0)
193 return false;
194
196
197 if (index == 0)
198 {
199 ret = gpsSleep(PortFD);
200 strncpy(msg, "GPS system is in sleep mode.", 64);
201 }
202 else if (index == 1)
203 {
204 ret = gpsWakeUp(PortFD)
205 strncpy(msg, "GPS system is reactivated.", 64);
206 }
207 else
208 {
209 ret = gpsRestart(PortFD)
210 strncpy(msg, "GPS system is restarting...", 64);
213 }
214
215 INDI_UNUSED(ret);
217 IDSetSwitch(&GPSStatusSP, "%s", msg);
218 return true;
219 }
220
221 /* GPS Update */
222 if (!strcmp(name, GPSUpdateSP.name))
223 {
224 if (IUUpdateSwitch(&GPSUpdateSP, states, names, n) < 0)
225 return false;
226
228
230
231 if (index == 0)
232 {
233 IDSetSwitch(&GPSUpdateSP, "Updating GPS system. This operation might take few minutes to complete...");
235 {
236 IDSetSwitch(&GPSUpdateSP, "GPS system update successful.");
239 }
240 else
241 {
243 IDSetSwitch(&GPSUpdateSP, "GPS system update failed.");
244 }
245 }
246 else
247 {
250 IDSetSwitch(&GPSUpdateSP, "Client time and location is synced to LX200 GPS Data.");
251 }
252 return true;
253 }
254
255 /* Alt Dec Periodic Error correction */
256 if (!strcmp(name, AltDecPecSP.name))
257 {
258 int ret = 0;
259
260 if (IUUpdateSwitch(&AltDecPecSP, states, names, n) < 0)
261 return false;
262
264
265 if (index == 0)
266 {
267 ret = enableDecAltPec(PortFD);
268 strncpy(msg, "Alt/Dec Compensation Enabled.", 64);
269 }
270 else
271 {
273 strncpy(msg, "Alt/Dec Compensation Disabled.", 64);
274 }
275
276 INDI_UNUSED(ret);
278 IDSetSwitch(&AltDecPecSP, "%s", msg);
279
280 return true;
281 }
282
283 /* Az RA periodic error correction */
284 if (!strcmp(name, AzRaPecSP.name))
285 {
286 int ret = 0;
287
288 if (IUUpdateSwitch(&AzRaPecSP, states, names, n) < 0)
289 return false;
290
292
293 if (index == 0)
294 {
295 ret = enableRaAzPec(PortFD);
296 strncpy(msg, "Ra/Az Compensation Enabled.", 64);
297 }
298 else
299 {
300 ret = disableRaAzPec(PortFD);
301 strncpy(msg, "Ra/Az Compensation Disabled.", 64);
302 }
303
304 INDI_UNUSED(ret);
305 AzRaPecSP.s = IPS_OK;
306 IDSetSwitch(&AzRaPecSP, "%s", msg);
307
308 return true;
309 }
310
311 if (!strcmp(name, AltDecBacklashSP.name))
312 {
313 int ret = 0;
314
316 INDI_UNUSED(ret);
318 IDSetSwitch(&AltDecBacklashSP, "Alt/Dec Anti-backlash enabled");
319 return true;
320 }
321
322 if (!strcmp(name, AzRaBacklashSP.name))
323 {
324 int ret = 0;
325
328 INDI_UNUSED(ret);
329 IDSetSwitch(&AzRaBacklashSP, "Az/Ra Anti-backlash enabled");
330 return true;
331 }
332
333 if (!strcmp(name, OTAUpdateSP.name))
334 {
336
337 if (getOTATemp(PortFD, &OTATempNP.np[0].value) < 0)
338 {
341 IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
342 return false;
343 }
344 else
345 {
347 OTATempNP.s = IPS_OK;
348 IDSetNumber(&OTATempNP, nullptr);
349 IDSetSwitch(&OTAUpdateSP, nullptr);
350 return true;
351 }
352 }
353 }
354
355 return LX200Autostar::ISNewSwitch(dev, name, states, names, n);
356}
357
358bool LX200GPS::updateTime(ln_date *utc, double utc_offset)
359{
360 ln_zonedate ltm;
361
362 if (isSimulation())
363 return true;
364
365 JD = ln_get_julian_day(utc);
366
367 LOGF_DEBUG("New JD is %.2f", JD);
368
369 ln_date_to_zonedate(utc, &ltm, utc_offset * 3600);
370
371 LOGF_DEBUG("Local time is %02d:%02d:%02g", ltm.hours, ltm.minutes, ltm.seconds);
372
373 // Set Local Time
374 if (setLocalTime24(ltm.hours, ltm.minutes, ltm.seconds) == false)
375 {
376 LOG_ERROR("Error setting local time time.");
377 return false;
378 }
379
380 // UTC Date, it's not Local for LX200GPS
381 if (setLocalDate(utc->days, utc->months, utc->years) == false)
382 {
383 LOG_ERROR("Error setting UTC date.");
384 return false;
385 }
386
387 // Meade defines UTC Offset as the offset ADDED to local time to yield UTC, which
388 // is the opposite of the standard definition of UTC offset!
389 if (setUTCOffset(utc_offset) == false)
390 {
391 LOG_ERROR("Error setting UTC Offset.");
392 return false;
393 }
394
395 LOG_INFO("Time updated, updating planetary data...");
396 return true;
397}
398
399bool LX200GPS::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
400{
401
402 if (strcmp(name, "GUIDE_RATE") == 0)
403 {
404 GuideRateNP[0].value = values[0];
405 GuideRateNP[1].value = values[1];
406 GuideRateNP.apply();
407 LOG_INFO("Guide rate set in INDI driver, please check mount is set to the same values");
408 }
409
410 return LX200Autostar::ISNewNumber(dev, name, values, names, n);
411}
412
414{
416 GuideRateNP.save(fp);
417 return true;
418}
419
421{
422 int ret = 0;
423
424 ret = initTelescope(PortFD);
425
426 INDI_UNUSED(ret);
428 SetParked(false);
429 return true;
430}
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 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.
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
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:124
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:99
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:399
ISwitchVectorProperty AltDecBacklashSP
Definition lx200gps.h:60
ISwitchVectorProperty GPSStatusSP
Definition lx200gps.h:45
virtual bool UnPark()
Unpark the telescope if already parked.
Definition lx200gps.cpp:420
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:413
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:160
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:358
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.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ 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,...)
*brief user defined string literal for JSON values *sa std::size_t n
#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