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 | #include "lx200driver.h"
|
---|
23 |
|
---|
24 | #include <stdio.h>
|
---|
25 | #include <stdlib.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include <unistd.h>
|
---|
28 |
|
---|
29 | #define GPSGroup "Extended GPS Features"
|
---|
30 |
|
---|
31 | extern LX200Generic *telescope;
|
---|
32 | extern int MaxReticleFlashRate;
|
---|
33 |
|
---|
34 | static ISwitch GPSPowerS[] = {{ "On", "", ISS_OFF, 0, 0}, {"Off", "", ISS_ON, 0, 0}};
|
---|
35 | static ISwitch GPSStatusS[] = {{ "Sleep", "", ISS_OFF, 0, 0}, {"Wake up", "", ISS_OFF, 0 ,0}, {"Restart", "", ISS_OFF, 0, 0}};
|
---|
36 | static ISwitch GPSUpdateS[] = { {"Update GPS", "", ISS_OFF, 0, 0}, {"Update Client", "", ISS_OFF, 0, 0}};
|
---|
37 | static ISwitch AltDecPecS[] = {{ "Enable", "", ISS_OFF, 0 ,0}, {"Disable", "", ISS_OFF, 0 ,0}};
|
---|
38 | static ISwitch AzRaPecS[] = {{ "Enable", "", ISS_OFF, 0, 0}, {"Disable", "", ISS_OFF, 0 ,0}};
|
---|
39 | static ISwitch SelenSyncS[] = {{ "Sync", "", ISS_OFF, 0, 0}};
|
---|
40 | static ISwitch AltDecBackSlashS[] = {{ "Activate", "", ISS_OFF, 0, 0}};
|
---|
41 | static ISwitch AzRaBackSlashS[] = {{ "Activate", "", ISS_OFF, 0, 0}};
|
---|
42 | static ISwitch OTAUpdateS[] = {{ "Update", "", ISS_OFF, 0, 0}};
|
---|
43 |
|
---|
44 | static ISwitchVectorProperty GPSPowerSP = { mydev, "GPS Power", "", GPSGroup, IP_RW, ISR_1OFMANY, 0 , IPS_IDLE, GPSPowerS, NARRAY(GPSPowerS), "", 0};
|
---|
45 | static ISwitchVectorProperty GPSStatusSP = { mydev, "GPS Status", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, GPSStatusS, NARRAY(GPSStatusS), "", 0};
|
---|
46 | static ISwitchVectorProperty GPSUpdateSP = { mydev, "GPS System", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, GPSUpdateS, NARRAY(GPSUpdateS), "", 0};
|
---|
47 | static ISwitchVectorProperty AltDecPecSP = { mydev, "Alt/Dec PEC", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, AltDecPecS, NARRAY(AltDecPecS), "", 0};
|
---|
48 | static ISwitchVectorProperty AzRaPecSP = { mydev, "Az/Ra PEC", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, AzRaPecS, NARRAY(AzRaPecS), "", 0};
|
---|
49 | static ISwitchVectorProperty SelenSyncSP = { mydev, "Selenographic Sync", "", GPSGroup, IP_RW, ISR_ATMOST1, 0, IPS_IDLE, SelenSyncS, NARRAY(SelenSyncS), "", 0};
|
---|
50 | static ISwitchVectorProperty AltDecBackSlashSP = { mydev, "Alt/Dec Anti-backslash", "", GPSGroup, IP_RW, ISR_ATMOST1, 0, IPS_IDLE, AltDecBackSlashS, NARRAY(AltDecBackSlashS), "", 0};
|
---|
51 | static ISwitchVectorProperty AzRaBackSlashSP = { mydev, "Az/Ra Anti-backslash", "", GPSGroup, IP_RW, ISR_ATMOST1, 0, IPS_IDLE, AzRaBackSlashS, NARRAY(AzRaBackSlashS), "", 0};
|
---|
52 | static ISwitchVectorProperty OTAUpdateSP = { mydev, "OTA Update", "", GPSGroup, IP_RW, ISR_ATMOST1, 0, IPS_IDLE, OTAUpdateS, NARRAY(OTAUpdateS), "", 0};
|
---|
53 |
|
---|
54 | static INumber OTATempN[] = { {"Temp.", "", "%g", -200., 500., 0., 0., 0, 0, 0 } };
|
---|
55 | static INumberVectorProperty OTATempNP = { mydev, "OTA Temperature (C)", "", GPSGroup, IP_RO, 0, IPS_IDLE, OTATempN, NARRAY(OTATempN), "", 0};
|
---|
56 |
|
---|
57 | void updateTemp(void *p);
|
---|
58 |
|
---|
59 | void changeLX200GPSDeviceName(const char *newName)
|
---|
60 | {
|
---|
61 | strcpy(GPSPowerSP.device, newName);
|
---|
62 | strcpy(GPSStatusSP.device, newName );
|
---|
63 | strcpy(GPSUpdateSP.device, newName );
|
---|
64 | strcpy(AltDecPecSP.device, newName );
|
---|
65 | strcpy(AzRaPecSP.device,newName );
|
---|
66 | strcpy(SelenSyncSP.device, newName );
|
---|
67 | strcpy(AltDecBackSlashSP.device, newName );
|
---|
68 | strcpy(AzRaBackSlashSP.device, newName );
|
---|
69 | strcpy(OTATempNP.device, newName );
|
---|
70 | strcpy(OTAUpdateSP.device, newName);
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | LX200GPS::LX200GPS() : LX200_16()
|
---|
75 | {
|
---|
76 | IEAddTimer(900000, updateTemp, &fd);
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | void LX200GPS::ISGetProperties (const char *dev)
|
---|
81 | {
|
---|
82 |
|
---|
83 | if (dev && strcmp (thisDevice, dev))
|
---|
84 | return;
|
---|
85 |
|
---|
86 | // process parent first
|
---|
87 | LX200_16::ISGetProperties(dev);
|
---|
88 |
|
---|
89 | IDDefSwitch (&GPSPowerSP, NULL);
|
---|
90 | IDDefSwitch (&GPSStatusSP, NULL);
|
---|
91 | IDDefSwitch (&GPSUpdateSP, NULL);
|
---|
92 | IDDefSwitch (&AltDecPecSP, NULL);
|
---|
93 | IDDefSwitch (&AzRaPecSP, NULL);
|
---|
94 | IDDefSwitch (&SelenSyncSP, NULL);
|
---|
95 | IDDefSwitch (&AltDecBackSlashSP, NULL);
|
---|
96 | IDDefSwitch (&AzRaBackSlashSP, NULL);
|
---|
97 | IDDefNumber (&OTATempNP, NULL);
|
---|
98 | IDDefSwitch (&OTAUpdateSP, NULL);
|
---|
99 |
|
---|
100 | }
|
---|
101 |
|
---|
102 | void LX200GPS::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
|
---|
103 | {
|
---|
104 | // ignore if not ours //
|
---|
105 | if (strcmp (dev, thisDevice))
|
---|
106 | return;
|
---|
107 |
|
---|
108 | LX200_16::ISNewText (dev, name, texts, names, n);
|
---|
109 | }
|
---|
110 |
|
---|
111 | void LX200GPS::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
|
---|
112 | {
|
---|
113 |
|
---|
114 | LX200_16::ISNewNumber (dev, name, values, names, n);
|
---|
115 |
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | void LX200GPS::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
|
---|
120 | {
|
---|
121 | int index=0, err=0;
|
---|
122 | char msg[64];
|
---|
123 |
|
---|
124 | if (strcmp (dev, thisDevice))
|
---|
125 | return;
|
---|
126 |
|
---|
127 | /* GPS Power */
|
---|
128 | if (!strcmp(name,GPSPowerSP.name))
|
---|
129 | {
|
---|
130 | if (checkPower(&GPSPowerSP))
|
---|
131 | return;
|
---|
132 |
|
---|
133 | if (IUUpdateSwitch(&GPSPowerSP, states, names, n) < 0)
|
---|
134 | return;
|
---|
135 |
|
---|
136 | index = getOnSwitch(&GPSPowerSP);
|
---|
137 | if (index == 0)
|
---|
138 | turnGPSOn(fd);
|
---|
139 | else
|
---|
140 | turnGPSOff(fd);
|
---|
141 |
|
---|
142 | GPSPowerSP.s = IPS_OK;
|
---|
143 | IDSetSwitch (&GPSPowerSP, index == 0 ? "GPS System is ON" : "GPS System is OFF" );
|
---|
144 | return;
|
---|
145 | }
|
---|
146 |
|
---|
147 | /* GPS Status Update */
|
---|
148 | if (!strcmp(name,GPSStatusSP.name))
|
---|
149 | {
|
---|
150 | if (checkPower(&GPSStatusSP))
|
---|
151 | return;
|
---|
152 |
|
---|
153 | if (IUUpdateSwitch(&GPSStatusSP, states, names, n) < 0)
|
---|
154 | return;
|
---|
155 |
|
---|
156 | index = getOnSwitch(&GPSStatusSP);
|
---|
157 |
|
---|
158 | if (index == 0)
|
---|
159 | {
|
---|
160 | err = gpsSleep(fd);
|
---|
161 | strcpy(msg, "GPS system is in sleep mode.");
|
---|
162 | }
|
---|
163 | else if (index == 1)
|
---|
164 | {
|
---|
165 | err = gpsWakeUp(fd);
|
---|
166 | strcpy(msg, "GPS system is reactivated.");
|
---|
167 | }
|
---|
168 | else
|
---|
169 | {
|
---|
170 | err = gpsRestart(fd);
|
---|
171 | strcpy(msg, "GPS system is restarting...");
|
---|
172 | updateTime();
|
---|
173 | updateLocation();
|
---|
174 | }
|
---|
175 |
|
---|
176 | GPSStatusSP.s = IPS_OK;
|
---|
177 | IDSetSwitch (&GPSStatusSP, "%s", msg);
|
---|
178 | return;
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | /* GPS Update */
|
---|
183 | if (!strcmp(name,GPSUpdateSP.name))
|
---|
184 | {
|
---|
185 | if (checkPower(&GPSUpdateSP))
|
---|
186 | return;
|
---|
187 |
|
---|
188 | if (IUUpdateSwitch(&GPSUpdateSP, states, names, n) < 0)
|
---|
189 | return;
|
---|
190 |
|
---|
191 | index = getOnSwitch(&GPSUpdateSP);
|
---|
192 |
|
---|
193 | GPSUpdateSP.s = IPS_OK;
|
---|
194 |
|
---|
195 | if (index == 0)
|
---|
196 | {
|
---|
197 |
|
---|
198 | IDSetSwitch(&GPSUpdateSP, "Updating GPS system. This operation might take few minutes to complete...");
|
---|
199 | if (updateGPS_System(fd))
|
---|
200 | {
|
---|
201 | IDSetSwitch(&GPSUpdateSP, "GPS system update successful.");
|
---|
202 | updateTime();
|
---|
203 | updateLocation();
|
---|
204 | }
|
---|
205 | else
|
---|
206 | {
|
---|
207 | GPSUpdateSP.s = IPS_IDLE;
|
---|
208 | IDSetSwitch(&GPSUpdateSP, "GPS system update failed.");
|
---|
209 | }
|
---|
210 | }
|
---|
211 | else
|
---|
212 | {
|
---|
213 | updateTime();
|
---|
214 | updateLocation();
|
---|
215 | IDSetSwitch(&GPSUpdateSP, "Client time and location is synced to LX200 GPS Data.");
|
---|
216 |
|
---|
217 | }
|
---|
218 | return;
|
---|
219 | }
|
---|
220 |
|
---|
221 | /* Alt Dec Periodic Error correction */
|
---|
222 | if (!strcmp(name, AltDecPecSP.name))
|
---|
223 | {
|
---|
224 | if (checkPower(&AltDecPecSP))
|
---|
225 | return;
|
---|
226 |
|
---|
227 | if (IUUpdateSwitch(&AltDecPecSP, states, names, n) < 0)
|
---|
228 | return;
|
---|
229 |
|
---|
230 | index = getOnSwitch(&AltDecPecSP);
|
---|
231 |
|
---|
232 | if (index == 0)
|
---|
233 | {
|
---|
234 | err = enableDecAltPec(fd);
|
---|
235 | strcpy (msg, "Alt/Dec Compensation Enabled");
|
---|
236 | }
|
---|
237 | else
|
---|
238 | {
|
---|
239 | err = disableDecAltPec(fd);
|
---|
240 | strcpy (msg, "Alt/Dec Compensation Disabled");
|
---|
241 | }
|
---|
242 |
|
---|
243 | AltDecPecSP.s = IPS_OK;
|
---|
244 | IDSetSwitch(&AltDecPecSP, "%s", msg);
|
---|
245 |
|
---|
246 | return;
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* Az RA periodic error correction */
|
---|
250 | if (!strcmp(name, AzRaPecSP.name))
|
---|
251 | {
|
---|
252 | if (checkPower(&AzRaPecSP))
|
---|
253 | return;
|
---|
254 |
|
---|
255 | if (IUUpdateSwitch(&AzRaPecSP, states, names, n) < 0)
|
---|
256 | return;
|
---|
257 |
|
---|
258 | index = getOnSwitch(&AzRaPecSP);
|
---|
259 |
|
---|
260 | if (index == 0)
|
---|
261 | {
|
---|
262 | err = enableRaAzPec(fd);
|
---|
263 | strcpy (msg, "Ra/Az Compensation Enabled");
|
---|
264 | }
|
---|
265 | else
|
---|
266 | {
|
---|
267 | err = disableRaAzPec(fd);
|
---|
268 | strcpy (msg, "Ra/Az Compensation Disabled");
|
---|
269 | }
|
---|
270 |
|
---|
271 | AzRaPecSP.s = IPS_OK;
|
---|
272 | IDSetSwitch(&AzRaPecSP, "%s", msg);
|
---|
273 |
|
---|
274 | return;
|
---|
275 | }
|
---|
276 |
|
---|
277 | if (!strcmp(name, AltDecBackSlashSP.name))
|
---|
278 | {
|
---|
279 | if (checkPower(&AltDecBackSlashSP))
|
---|
280 | return;
|
---|
281 |
|
---|
282 | err = activateAltDecAntiBackSlash(fd);
|
---|
283 | AltDecBackSlashSP.s = IPS_OK;
|
---|
284 | IDSetSwitch(&AltDecBackSlashSP, "Alt/Dec Anti-backslash enabled");
|
---|
285 | return;
|
---|
286 | }
|
---|
287 |
|
---|
288 | if (!strcmp(name, AzRaBackSlashSP.name))
|
---|
289 | {
|
---|
290 | if (checkPower(&AzRaBackSlashSP))
|
---|
291 | return;
|
---|
292 |
|
---|
293 | err = activateAzRaAntiBackSlash(fd);
|
---|
294 | AzRaBackSlashSP.s = IPS_OK;
|
---|
295 | IDSetSwitch(&AzRaBackSlashSP, "Az/Ra Anti-backslash enabled");
|
---|
296 | return;
|
---|
297 | }
|
---|
298 |
|
---|
299 | if (!strcmp(name, OTAUpdateSP.name))
|
---|
300 | {
|
---|
301 | int error_type=0;
|
---|
302 |
|
---|
303 | if (checkPower(&OTAUpdateSP))
|
---|
304 | return;
|
---|
305 |
|
---|
306 | IUResetSwitch(&OTAUpdateSP);
|
---|
307 |
|
---|
308 | if ( (error_type = getOTATemp(fd, &OTATempNP.np[0].value)) < 0)
|
---|
309 | {
|
---|
310 | OTAUpdateSP.s = IPS_ALERT;
|
---|
311 | OTATempNP.s = IPS_ALERT;
|
---|
312 | IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
|
---|
313 | }
|
---|
314 | else
|
---|
315 | {
|
---|
316 | OTAUpdateSP.s = IPS_OK;
|
---|
317 | OTATempNP.s = IPS_OK;
|
---|
318 | IDSetNumber(&OTATempNP, NULL);
|
---|
319 | }
|
---|
320 |
|
---|
321 | return;
|
---|
322 | }
|
---|
323 |
|
---|
324 | LX200_16::ISNewSwitch (dev, name, states, names, n);
|
---|
325 |
|
---|
326 | }
|
---|
327 |
|
---|
328 | void LX200GPS::ISPoll ()
|
---|
329 | {
|
---|
330 |
|
---|
331 | LX200_16::ISPoll();
|
---|
332 |
|
---|
333 |
|
---|
334 | }
|
---|
335 |
|
---|
336 | void updateTemp(void * p)
|
---|
337 | {
|
---|
338 |
|
---|
339 | int fd = *((int *) p);
|
---|
340 |
|
---|
341 | if (telescope->isTelescopeOn())
|
---|
342 | {
|
---|
343 | if (getOTATemp(fd, &OTATempNP.np[0].value) < 0)
|
---|
344 | {
|
---|
345 | OTATempNP.s = IPS_ALERT;
|
---|
346 | IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
|
---|
347 | return;
|
---|
348 | }
|
---|
349 | else
|
---|
350 | {
|
---|
351 | OTATempNP.s = IPS_OK;
|
---|
352 | IDSetNumber(&OTATempNP, NULL);
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | IEAddTimer(900000, updateTemp, &fd);
|
---|
357 |
|
---|
358 | }
|
---|
359 |
|
---|
360 | void LX200GPS::getBasicData()
|
---|
361 | {
|
---|
362 |
|
---|
363 | //getOTATemp(&OTATempNP.np[0].value);
|
---|
364 | //IDSetNumber(&OTATempNP, NULL);
|
---|
365 |
|
---|
366 | // process parent
|
---|
367 | LX200_16::getBasicData();
|
---|
368 | }
|
---|
369 |
|
---|