1 | #if 0
|
---|
2 | LX200 Driver
|
---|
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 | #endif
|
---|
20 |
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <stdarg.h>
|
---|
25 | #include <math.h>
|
---|
26 | #include <sys/time.h>
|
---|
27 | #include <unistd.h>
|
---|
28 | #include <fcntl.h>
|
---|
29 | #include <time.h>
|
---|
30 |
|
---|
31 | #include "indicom.h"
|
---|
32 | #include "indidevapi.h"
|
---|
33 | #include "lx200driver.h"
|
---|
34 |
|
---|
35 | #ifndef _WIN32
|
---|
36 | #include <termios.h>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #define LX200_TIMEOUT 5 /* FD timeout in seconds */
|
---|
40 |
|
---|
41 | int controller_format;
|
---|
42 |
|
---|
43 | /**************************************************************************
|
---|
44 | Diagnostics
|
---|
45 | **************************************************************************/
|
---|
46 | char ACK(int fd);
|
---|
47 | /*int testTelescope(void);
|
---|
48 | int testAP(void);*/
|
---|
49 | int check_lx200_connection(int fd);
|
---|
50 |
|
---|
51 | /**************************************************************************
|
---|
52 | Get Commands: store data in the supplied buffer. Return 0 on success or -1 on failure
|
---|
53 | **************************************************************************/
|
---|
54 |
|
---|
55 | /* Get Double from Sexagisemal */
|
---|
56 | int getCommandSexa(int fd, double *value, const char *cmd);
|
---|
57 | /* Get String */
|
---|
58 | int getCommandString(int fd, char *data, const char* cmd);
|
---|
59 | /* Get Int */
|
---|
60 | int getCommandInt(int fd, int *value, const char* cmd);
|
---|
61 | /* Get tracking frequency */
|
---|
62 | int getTrackFreq(int fd, double * value);
|
---|
63 | /* Get site Latitude */
|
---|
64 | int getSiteLatitude(int fd, int *dd, int *mm);
|
---|
65 | /* Get site Longitude */
|
---|
66 | int getSiteLongitude(int fd, int *ddd, int *mm);
|
---|
67 | /* Get Calender data */
|
---|
68 | int getCalenderDate(int fd, char *date);
|
---|
69 | /* Get site Name */
|
---|
70 | int getSiteName(int fd, char *siteName, int siteNum);
|
---|
71 | /* Get Number of Bars */
|
---|
72 | int getNumberOfBars(int fd, int *value);
|
---|
73 | /* Get Home Search Status */
|
---|
74 | int getHomeSearchStatus(int fd, int *status);
|
---|
75 | /* Get OTA Temperature */
|
---|
76 | int getOTATemp(int fd, double * value);
|
---|
77 | /* Get time format: 12 or 24 */
|
---|
78 | int getTimeFormat(int fd, int *format);
|
---|
79 |
|
---|
80 |
|
---|
81 | /**************************************************************************
|
---|
82 | Set Commands
|
---|
83 | **************************************************************************/
|
---|
84 |
|
---|
85 | /* Set Int */
|
---|
86 | int setCommandInt(int fd, int data, const char *cmd);
|
---|
87 | /* Set Sexigesimal */
|
---|
88 | int setCommandXYZ(int fd, int x, int y, int z, const char *cmd);
|
---|
89 | /* Common routine for Set commands */
|
---|
90 | int setStandardProcedure(int fd, char * writeData);
|
---|
91 | /* Set Slew Mode */
|
---|
92 | int setSlewMode(int fd, int slewMode);
|
---|
93 | /* Set Alignment mode */
|
---|
94 | int setAlignmentMode(int fd, unsigned int alignMode);
|
---|
95 | /* Set Object RA */
|
---|
96 | int setObjectRA(int fd, double ra);
|
---|
97 | /* set Object DEC */
|
---|
98 | int setObjectDEC(int fd, double dec);
|
---|
99 | /* Set Calender date */
|
---|
100 | int setCalenderDate(int fd, int dd, int mm, int yy);
|
---|
101 | /* Set UTC offset */
|
---|
102 | int setUTCOffset(int fd, double hours);
|
---|
103 | /* Set Track Freq */
|
---|
104 | int setTrackFreq(int fd, double trackF);
|
---|
105 | /* Set current site longitude */
|
---|
106 | int setSiteLongitude(int fd, double Long);
|
---|
107 | /* Set current site latitude */
|
---|
108 | int setSiteLatitude(int fd, double Lat);
|
---|
109 | /* Set Object Azimuth */
|
---|
110 | int setObjAz(int fd, double az);
|
---|
111 | /* Set Object Altitude */
|
---|
112 | int setObjAlt(int fd, double alt);
|
---|
113 | /* Set site name */
|
---|
114 | int setSiteName(int fd, char * siteName, int siteNum);
|
---|
115 | /* Set maximum slew rate */
|
---|
116 | int setMaxSlewRate(int fd, int slewRate);
|
---|
117 | /* Set focuser motion */
|
---|
118 | int setFocuserMotion(int fd, int motionType);
|
---|
119 | /* Set focuser speed mode */
|
---|
120 | int setFocuserSpeedMode (int fd, int speedMode);
|
---|
121 | /* Set minimum elevation limit */
|
---|
122 | int setMinElevationLimit(int fd, int min);
|
---|
123 | /* Set maximum elevation limit */
|
---|
124 | int setMaxElevationLimit(int fd, int max);
|
---|
125 |
|
---|
126 | /**************************************************************************
|
---|
127 | Motion Commands
|
---|
128 | **************************************************************************/
|
---|
129 | /* Slew to the selected coordinates */
|
---|
130 | int Slew(int fd);
|
---|
131 | /* Synchronize to the selected coordinates and return the matching object if any */
|
---|
132 | int Sync(int fd, char *matchedObject);
|
---|
133 | /* Abort slew in all axes */
|
---|
134 | int abortSlew(int fd);
|
---|
135 | /* Move into one direction, two valid directions can be stacked */
|
---|
136 | int MoveTo(int fd, int direction);
|
---|
137 | /* Half movement in a particular direction */
|
---|
138 | int HaltMovement(int fd, int direction);
|
---|
139 | /* Select the tracking mode */
|
---|
140 | int selectTrackingMode(int fd, int trackMode);
|
---|
141 | /* Select Astro-Physics tracking mode */
|
---|
142 | int selectAPTrackingMode(int fd, int trackMode);
|
---|
143 | /* Send Pulse-Guide command (timed guide move), two valid directions can be stacked */
|
---|
144 | int SendPulseCmd(int fd, int direction, int duration_msec);
|
---|
145 |
|
---|
146 | /**************************************************************************
|
---|
147 | Other Commands
|
---|
148 | **************************************************************************/
|
---|
149 | /* Ensures LX200 RA/DEC format is long */
|
---|
150 | int checkLX200Format(int fd);
|
---|
151 | /* Select a site from the LX200 controller */
|
---|
152 | int selectSite(int fd, int siteNum);
|
---|
153 | /* Select a catalog object */
|
---|
154 | int selectCatalogObject(int fd, int catalog, int NNNN);
|
---|
155 | /* Select a sub catalog */
|
---|
156 | int selectSubCatalog(int fd, int catalog, int subCatalog);
|
---|
157 |
|
---|
158 | int check_lx200_connection(int in_fd)
|
---|
159 | {
|
---|
160 |
|
---|
161 | int i=0;
|
---|
162 | char ack[1] = { (char) 0x06 };
|
---|
163 | char MountAlign[64];
|
---|
164 | int nbytes_read=0;
|
---|
165 |
|
---|
166 | #ifdef INDI_DEBUG
|
---|
167 | IDLog("Testing telescope's connection using ACK...\n");
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | if (in_fd <= 0) return -1;
|
---|
171 |
|
---|
172 | for (i=0; i < 2; i++)
|
---|
173 | {
|
---|
174 | if (write(in_fd, ack, 1) < 0) return -1;
|
---|
175 | tty_read(in_fd, MountAlign, 1, LX200_TIMEOUT, &nbytes_read);
|
---|
176 | if (nbytes_read == 1)
|
---|
177 | return 0;
|
---|
178 | usleep(50000);
|
---|
179 | }
|
---|
180 |
|
---|
181 | return -1;
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | /**********************************************************************
|
---|
186 | * GET
|
---|
187 | **********************************************************************/
|
---|
188 |
|
---|
189 | char ACK(int fd)
|
---|
190 | {
|
---|
191 | char ack[1] = { (char) 0x06 };
|
---|
192 | char MountAlign[2];
|
---|
193 | int nbytes_write=0, nbytes_read=0, error_type;
|
---|
194 |
|
---|
195 | nbytes_write = write(fd, ack, 1);
|
---|
196 |
|
---|
197 | if (nbytes_write < 0)
|
---|
198 | return -1;
|
---|
199 |
|
---|
200 | /*read_ret = portRead(MountAlign, 1, LX200_TIMEOUT);*/
|
---|
201 | error_type = tty_read(fd, MountAlign, 1, LX200_TIMEOUT, &nbytes_read);
|
---|
202 |
|
---|
203 | if (nbytes_read == 1)
|
---|
204 | return MountAlign[0];
|
---|
205 | else
|
---|
206 | return error_type;
|
---|
207 | }
|
---|
208 |
|
---|
209 | int getCommandSexa(int fd, double *value, const char * cmd)
|
---|
210 | {
|
---|
211 | char temp_string[16];
|
---|
212 | int error_type;
|
---|
213 | int nbytes_write=0, nbytes_read=0;
|
---|
214 |
|
---|
215 | tcflush(fd, TCIFLUSH);
|
---|
216 |
|
---|
217 | if ( (error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
|
---|
218 | return error_type;
|
---|
219 |
|
---|
220 | /*if ( (read_ret = portRead(temp_string, -1, LX200_TIMEOUT)) < 1)
|
---|
221 | return read_ret;*/
|
---|
222 | tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
223 |
|
---|
224 | temp_string[nbytes_read - 1] = '\0';
|
---|
225 |
|
---|
226 | /*IDLog("getComandSexa: %s\n", temp_string);*/
|
---|
227 |
|
---|
228 | if (f_scansexa(temp_string, value))
|
---|
229 | {
|
---|
230 | #ifdef INDI_DEBUG
|
---|
231 | IDLog("unable to process [%s]\n", temp_string);
|
---|
232 | #endif
|
---|
233 | return -1;
|
---|
234 | }
|
---|
235 |
|
---|
236 | tcflush(fd, TCIFLUSH);
|
---|
237 | return 0;
|
---|
238 | }
|
---|
239 |
|
---|
240 | int getCommandInt(int fd, int *value, const char* cmd)
|
---|
241 | {
|
---|
242 | char temp_string[16];
|
---|
243 | float temp_number;
|
---|
244 | int error_type;
|
---|
245 | int nbytes_write=0, nbytes_read=0;
|
---|
246 |
|
---|
247 |
|
---|
248 | tcflush(fd, TCIFLUSH);
|
---|
249 |
|
---|
250 | if ( (error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
|
---|
251 | return error_type;
|
---|
252 |
|
---|
253 | tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
254 |
|
---|
255 | temp_string[nbytes_read - 1] = '\0';
|
---|
256 |
|
---|
257 | /* Float */
|
---|
258 | if (strchr(temp_string, '.'))
|
---|
259 | {
|
---|
260 | if (sscanf(temp_string, "%f", &temp_number) != 1)
|
---|
261 | return -1;
|
---|
262 |
|
---|
263 | *value = (int) temp_number;
|
---|
264 | }
|
---|
265 | /* Int */
|
---|
266 | else if (sscanf(temp_string, "%d", value) != 1)
|
---|
267 | return -1;
|
---|
268 |
|
---|
269 | return 0;
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | int getCommandString(int fd, char *data, const char* cmd)
|
---|
274 | {
|
---|
275 | char * term;
|
---|
276 | int error_type;
|
---|
277 | int nbytes_write=0, nbytes_read=0;
|
---|
278 |
|
---|
279 | /*if (portWrite(cmd) < 0)
|
---|
280 | return -1;*/
|
---|
281 |
|
---|
282 | if ( (error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
|
---|
283 | return error_type;
|
---|
284 |
|
---|
285 | /*read_ret = portRead(data, -1, LX200_TIMEOUT);*/
|
---|
286 | error_type = tty_read_section(fd, data, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
287 | tcflush(fd, TCIFLUSH);
|
---|
288 |
|
---|
289 | if (error_type != TTY_OK)
|
---|
290 | return error_type;
|
---|
291 |
|
---|
292 | term = strchr (data, '#');
|
---|
293 | if (term)
|
---|
294 | *term = '\0';
|
---|
295 |
|
---|
296 | #ifdef INDI_DEBUG
|
---|
297 | /*IDLog("Requested data: %s\n", data);*/
|
---|
298 | #endif
|
---|
299 |
|
---|
300 | return 0;
|
---|
301 | }
|
---|
302 |
|
---|
303 | int getCalenderDate(int fd, char *date)
|
---|
304 | {
|
---|
305 |
|
---|
306 | int dd, mm, yy;
|
---|
307 | int error_type;
|
---|
308 | int nbytes_read=0;
|
---|
309 | char mell_prefix[3];
|
---|
310 |
|
---|
311 |
|
---|
312 | if ( (error_type = getCommandString(fd, date, "#:GC#")) )
|
---|
313 | return error_type;
|
---|
314 |
|
---|
315 | /* Meade format is MM/DD/YY */
|
---|
316 |
|
---|
317 | nbytes_read = sscanf(date, "%d%*c%d%*c%d", &mm, &dd, &yy);
|
---|
318 | if (nbytes_read < 3)
|
---|
319 | return -1;
|
---|
320 |
|
---|
321 | /* We consider years 50 or more to be in the last century, anything less in the 21st century.*/
|
---|
322 | if (yy > 50)
|
---|
323 | strncpy(mell_prefix, "19", 3);
|
---|
324 | else
|
---|
325 | strncpy(mell_prefix, "20", 3);
|
---|
326 |
|
---|
327 | /* We need to have in in YYYY/MM/DD format */
|
---|
328 | snprintf(date, 16, "%s%02d/%02d/%02d", mell_prefix, yy, mm, dd);
|
---|
329 |
|
---|
330 | return (0);
|
---|
331 |
|
---|
332 | }
|
---|
333 |
|
---|
334 | int getTimeFormat(int fd, int *format)
|
---|
335 | {
|
---|
336 | char temp_string[16];
|
---|
337 | int error_type;
|
---|
338 | int nbytes_write=0, nbytes_read=0;
|
---|
339 | int tMode;
|
---|
340 |
|
---|
341 | /*if (portWrite("#:Gc#") < 0)
|
---|
342 | return -1;*/
|
---|
343 |
|
---|
344 | if ( (error_type = tty_write_string(fd, "#:Gc#", &nbytes_write)) != TTY_OK)
|
---|
345 | return error_type;
|
---|
346 |
|
---|
347 | /*read_ret = portRead(temp_string, -1, LX200_TIMEOUT);*/
|
---|
348 | if ( (error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read)) != TTY_OK)
|
---|
349 | return error_type;
|
---|
350 |
|
---|
351 | tcflush(fd, TCIFLUSH);
|
---|
352 |
|
---|
353 | if (nbytes_read < 1)
|
---|
354 | return error_type;
|
---|
355 |
|
---|
356 | temp_string[nbytes_read-1] = '\0';
|
---|
357 |
|
---|
358 | nbytes_read = sscanf(temp_string, "(%d)", &tMode);
|
---|
359 |
|
---|
360 | if (nbytes_read < 1)
|
---|
361 | return -1;
|
---|
362 | else
|
---|
363 | *format = tMode;
|
---|
364 |
|
---|
365 | return 0;
|
---|
366 |
|
---|
367 | }
|
---|
368 |
|
---|
369 | int getSiteName(int fd, char *siteName, int siteNum)
|
---|
370 | {
|
---|
371 | char * term;
|
---|
372 | int error_type;
|
---|
373 | int nbytes_write=0, nbytes_read=0;
|
---|
374 |
|
---|
375 | switch (siteNum)
|
---|
376 | {
|
---|
377 | case 1:
|
---|
378 | /*if (portWrite("#:GM#") < 0)
|
---|
379 | return -1;*/
|
---|
380 | if ( (error_type = tty_write_string(fd, "#:GM#", &nbytes_write)) != TTY_OK)
|
---|
381 | return error_type;
|
---|
382 | break;
|
---|
383 | case 2:
|
---|
384 | /*if (portWrite("#:GN#") < 0)
|
---|
385 | return -1;*/
|
---|
386 | if ( (error_type = tty_write_string(fd, "#:GN#", &nbytes_write)) != TTY_OK)
|
---|
387 | return error_type;
|
---|
388 | break;
|
---|
389 | case 3:
|
---|
390 | /*if (portWrite("#:GO#") < 0)
|
---|
391 | return -1;*/
|
---|
392 | if ( (error_type = tty_write_string(fd, "#:GO#", &nbytes_write)) != TTY_OK)
|
---|
393 | return error_type;
|
---|
394 | break;
|
---|
395 | case 4:
|
---|
396 | /*if (portWrite("#:GP#") < 0)
|
---|
397 | return -1;*/
|
---|
398 | if ( (error_type = tty_write_string(fd, "#:GP#", &nbytes_write)) != TTY_OK)
|
---|
399 | return error_type;
|
---|
400 | break;
|
---|
401 | default:
|
---|
402 | return -1;
|
---|
403 | }
|
---|
404 |
|
---|
405 | /*read_ret = portRead(siteName, -1, LX200_TIMEOUT);*/
|
---|
406 | error_type = tty_read_section(fd, siteName, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
407 | tcflush(fd, TCIFLUSH);
|
---|
408 |
|
---|
409 | if (nbytes_read < 1)
|
---|
410 | return error_type;
|
---|
411 |
|
---|
412 | siteName[nbytes_read - 1] = '\0';
|
---|
413 |
|
---|
414 | term = strchr (siteName, ' ');
|
---|
415 | if (term)
|
---|
416 | *term = '\0';
|
---|
417 |
|
---|
418 | term = strchr (siteName, '<');
|
---|
419 | if (term)
|
---|
420 | strcpy(siteName, "unused site");
|
---|
421 |
|
---|
422 | #ifdef INDI_DEBUG
|
---|
423 | IDLog("Requested site name: %s\n", siteName);
|
---|
424 | #endif
|
---|
425 |
|
---|
426 | return 0;
|
---|
427 | }
|
---|
428 |
|
---|
429 | int getSiteLatitude(int fd, int *dd, int *mm)
|
---|
430 | {
|
---|
431 | char temp_string[16];
|
---|
432 | int error_type;
|
---|
433 | int nbytes_write=0, nbytes_read=0;
|
---|
434 |
|
---|
435 | /*if (portWrite("#:Gt#") < 0)
|
---|
436 | return -1;*/
|
---|
437 | if ( (error_type = tty_write_string(fd, "#:Gt#", &nbytes_write)) != TTY_OK)
|
---|
438 | return error_type;
|
---|
439 |
|
---|
440 | /*read_ret = portRead(temp_string, -1, LX200_TIMEOUT);*/
|
---|
441 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
442 | tcflush(fd, TCIFLUSH);
|
---|
443 |
|
---|
444 | if (nbytes_read < 1)
|
---|
445 | return error_type;
|
---|
446 |
|
---|
447 | temp_string[nbytes_read -1] = '\0';
|
---|
448 |
|
---|
449 | if (sscanf (temp_string, "%d%*c%d", dd, mm) < 2)
|
---|
450 | return -1;
|
---|
451 |
|
---|
452 | #ifdef INDI_DEBUG
|
---|
453 | fprintf(stderr, "Requested site latitude in String %s\n", temp_string);
|
---|
454 | fprintf(stderr, "Requested site latitude %d:%d\n", *dd, *mm);
|
---|
455 | #endif
|
---|
456 |
|
---|
457 | return 0;
|
---|
458 | }
|
---|
459 |
|
---|
460 | int getSiteLongitude(int fd, int *ddd, int *mm)
|
---|
461 | {
|
---|
462 | char temp_string[16];
|
---|
463 | int error_type;
|
---|
464 | int nbytes_write=0, nbytes_read=0;
|
---|
465 |
|
---|
466 | if ( (error_type = tty_write_string(fd, "#:Gg#", &nbytes_write)) != TTY_OK)
|
---|
467 | return error_type;
|
---|
468 |
|
---|
469 | /*if (portWrite("#:Gg#") < 0)
|
---|
470 | return -1;*/
|
---|
471 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
472 | /*read_ret = portRead(temp_string, -1, LX200_TIMEOUT);*/
|
---|
473 |
|
---|
474 | tcflush(fd, TCIFLUSH);
|
---|
475 |
|
---|
476 | if (nbytes_read < 1)
|
---|
477 | return error_type;
|
---|
478 |
|
---|
479 | temp_string[nbytes_read -1] = '\0';
|
---|
480 |
|
---|
481 | if (sscanf (temp_string, "%d%*c%d", ddd, mm) < 2)
|
---|
482 | return -1;
|
---|
483 |
|
---|
484 | #ifdef INDI_DEBUG
|
---|
485 | fprintf(stderr, "Requested site longitude in String %s\n", temp_string);
|
---|
486 | fprintf(stderr, "Requested site longitude %d:%d\n", *ddd, *mm);
|
---|
487 | #endif
|
---|
488 |
|
---|
489 | return 0;
|
---|
490 | }
|
---|
491 |
|
---|
492 | int getTrackFreq(int fd, double *value)
|
---|
493 | {
|
---|
494 | float Freq;
|
---|
495 | char temp_string[16];
|
---|
496 | int error_type;
|
---|
497 | int nbytes_write=0, nbytes_read=0;
|
---|
498 |
|
---|
499 | if ( (error_type = tty_write_string(fd, "#:GT#", &nbytes_write)) != TTY_OK)
|
---|
500 | return error_type;
|
---|
501 |
|
---|
502 | /*if (portWrite("#:GT#") < 0)
|
---|
503 | return -1;*/
|
---|
504 |
|
---|
505 | /*read_ret = portRead(temp_string, -1, LX200_TIMEOUT);*/
|
---|
506 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
507 | tcflush(fd, TCIFLUSH);
|
---|
508 |
|
---|
509 | if (nbytes_read < 1)
|
---|
510 | return error_type;
|
---|
511 |
|
---|
512 | temp_string[nbytes_read] = '\0';
|
---|
513 |
|
---|
514 | /*fprintf(stderr, "Telescope tracking freq str: %s\n", temp_string);*/
|
---|
515 |
|
---|
516 | if (sscanf(temp_string, "%f#", &Freq) < 1)
|
---|
517 | return -1;
|
---|
518 |
|
---|
519 | *value = (double) Freq;
|
---|
520 |
|
---|
521 | #ifdef INDI_DEBUG
|
---|
522 | fprintf(stderr, "Tracking frequency value is %f\n", Freq);
|
---|
523 | #endif
|
---|
524 |
|
---|
525 | return 0;
|
---|
526 | }
|
---|
527 |
|
---|
528 | int getNumberOfBars(int fd, int *value)
|
---|
529 | {
|
---|
530 | char temp_string[128];
|
---|
531 | int error_type;
|
---|
532 | int nbytes_write=0, nbytes_read=0;
|
---|
533 |
|
---|
534 | if ( (error_type = tty_write_string(fd, "#:D#", &nbytes_write)) != TTY_OK)
|
---|
535 | return error_type;
|
---|
536 | /*if (portWrite("#:D#") < 0)
|
---|
537 | return -1;*/
|
---|
538 |
|
---|
539 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
540 | tcflush(fd, TCIFLUSH);
|
---|
541 |
|
---|
542 | if (nbytes_read < 0)
|
---|
543 | return error_type;
|
---|
544 |
|
---|
545 | *value = nbytes_read -1;
|
---|
546 |
|
---|
547 | return 0;
|
---|
548 | }
|
---|
549 |
|
---|
550 | int getHomeSearchStatus(int fd, int *status)
|
---|
551 | {
|
---|
552 | char temp_string[16];
|
---|
553 | int error_type;
|
---|
554 | int nbytes_write=0, nbytes_read=0;
|
---|
555 |
|
---|
556 | if ( (error_type = tty_write_string(fd, "#:h?#", &nbytes_write)) != TTY_OK)
|
---|
557 | return error_type;
|
---|
558 | /*if (portWrite("#:h?#") < 0)
|
---|
559 | return -1;*/
|
---|
560 |
|
---|
561 | /*read_ret = portRead(temp_string, 1, LX200_TIMEOUT);*/
|
---|
562 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
563 | tcflush(fd, TCIFLUSH);
|
---|
564 |
|
---|
565 | if (nbytes_read < 1)
|
---|
566 | return error_type;
|
---|
567 |
|
---|
568 | temp_string[1] = '\0';
|
---|
569 |
|
---|
570 | if (temp_string[0] == '0')
|
---|
571 | *status = 0;
|
---|
572 | else if (temp_string[0] == '1')
|
---|
573 | *status = 1;
|
---|
574 | else if (temp_string[0] == '2')
|
---|
575 | *status = 1;
|
---|
576 |
|
---|
577 | return 0;
|
---|
578 | }
|
---|
579 |
|
---|
580 | int getOTATemp(int fd, double *value)
|
---|
581 | {
|
---|
582 |
|
---|
583 | char temp_string[16];
|
---|
584 | int error_type;
|
---|
585 | int nbytes_write=0, nbytes_read=0;
|
---|
586 | float temp;
|
---|
587 |
|
---|
588 | if ( (error_type = tty_write_string(fd, "#:fT#", &nbytes_write)) != TTY_OK)
|
---|
589 | return error_type;
|
---|
590 |
|
---|
591 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
592 |
|
---|
593 | if (nbytes_read < 1)
|
---|
594 | return error_type;
|
---|
595 |
|
---|
596 | temp_string[nbytes_read - 1] = '\0';
|
---|
597 |
|
---|
598 | if (sscanf(temp_string, "%f", &temp) < 1)
|
---|
599 | return -1;
|
---|
600 |
|
---|
601 | *value = (double) temp;
|
---|
602 |
|
---|
603 | return 0;
|
---|
604 |
|
---|
605 | }
|
---|
606 |
|
---|
607 | int updateSkyCommanderCoord(int fd, double *ra, double *dec)
|
---|
608 | {
|
---|
609 | char coords[16];
|
---|
610 | char CR[1] = { (char) 0x0D };
|
---|
611 | float RA=0.0, DEC=0.0;
|
---|
612 | int error_type;
|
---|
613 | int nbytes_read=0;
|
---|
614 |
|
---|
615 | error_type = write(fd, CR, 1);
|
---|
616 |
|
---|
617 | error_type = tty_read(fd, coords, 16, LX200_TIMEOUT, &nbytes_read);
|
---|
618 | /*read_ret = portRead(coords, 16, LX200_TIMEOUT);*/
|
---|
619 | tcflush(fd, TCIFLUSH);
|
---|
620 |
|
---|
621 | nbytes_read = sscanf(coords, " %g %g", &RA, &DEC);
|
---|
622 |
|
---|
623 | if (nbytes_read < 2)
|
---|
624 | {
|
---|
625 | #ifdef INDI_DEBUG
|
---|
626 | IDLog("Error in Sky commander number format [%s], exiting.\n", coords);
|
---|
627 | #endif
|
---|
628 | return error_type;
|
---|
629 | }
|
---|
630 |
|
---|
631 | *ra = RA;
|
---|
632 | *dec = DEC;
|
---|
633 |
|
---|
634 | return 0;
|
---|
635 |
|
---|
636 | }
|
---|
637 |
|
---|
638 | int updateIntelliscopeCoord (int fd, double *ra, double *dec)
|
---|
639 | {
|
---|
640 | char coords[16];
|
---|
641 | char CR[1] = { (char) 0x51 }; /* "Q" */
|
---|
642 | float RA = 0.0, DEC = 0.0;
|
---|
643 | int error_type;
|
---|
644 | int nbytes_read=0;
|
---|
645 |
|
---|
646 | /*IDLog ("Sending a Q\n");*/
|
---|
647 | error_type = write (fd, CR, 1);
|
---|
648 | /* We start at 14 bytes in case its a Sky Wizard,
|
---|
649 | but read one more later it if it's a intelliscope */
|
---|
650 | /*read_ret = portRead (coords, 14, LX200_TIMEOUT);*/
|
---|
651 | error_type = tty_read(fd, coords, 14, LX200_TIMEOUT, &nbytes_read);
|
---|
652 | tcflush(fd, TCIFLUSH);
|
---|
653 | /*IDLog ("portRead() = [%s]\n", coords);*/
|
---|
654 |
|
---|
655 | /* Remove the Q in the response from the Intelliscope but not the Sky Wizard */
|
---|
656 | if (coords[0] == 'Q') {
|
---|
657 | coords[0] = ' ';
|
---|
658 | /* Read one more byte if Intelliscope to get the "CR" */
|
---|
659 | error_type = tty_read(fd, coords, 1, LX200_TIMEOUT, &nbytes_read);
|
---|
660 | /*read_ret = portRead (coords, 1, LX200_TIMEOUT);*/
|
---|
661 | }
|
---|
662 | nbytes_read = sscanf (coords, " %g %g", &RA, &DEC);
|
---|
663 | /*IDLog ("sscanf() RA = [%f]\n", RA * 0.0390625);*/
|
---|
664 | /*IDLog ("sscanf() DEC = [%f]\n", DEC * 0.0390625);*/
|
---|
665 |
|
---|
666 | /*IDLog ("Intelliscope output [%s]", coords);*/
|
---|
667 | if (nbytes_read < 2)
|
---|
668 | {
|
---|
669 | #ifdef INDI_DEBUG
|
---|
670 | IDLog ("Error in Intelliscope number format [%s], exiting.\n", coords);
|
---|
671 | #endif
|
---|
672 | return -1;
|
---|
673 | }
|
---|
674 |
|
---|
675 | *ra = RA * 0.0390625;
|
---|
676 | *dec = DEC * 0.0390625;
|
---|
677 |
|
---|
678 | return 0;
|
---|
679 |
|
---|
680 | }
|
---|
681 |
|
---|
682 |
|
---|
683 | /**********************************************************************
|
---|
684 | * SET
|
---|
685 | **********************************************************************/
|
---|
686 |
|
---|
687 | int setStandardProcedure(int fd, char * data)
|
---|
688 | {
|
---|
689 | char bool_return[2];
|
---|
690 | int error_type;
|
---|
691 | int nbytes_write=0, nbytes_read=0;
|
---|
692 |
|
---|
693 | if ( (error_type = tty_write_string(fd, data, &nbytes_write)) != TTY_OK)
|
---|
694 | return error_type;
|
---|
695 |
|
---|
696 | error_type = tty_read(fd, bool_return, 1, LX200_TIMEOUT, &nbytes_read);
|
---|
697 | /*read_ret = portRead(boolRet, 1, LX200_TIMEOUT);*/
|
---|
698 | tcflush(fd, TCIFLUSH);
|
---|
699 |
|
---|
700 | if (nbytes_read < 1)
|
---|
701 | return error_type;
|
---|
702 |
|
---|
703 | if (bool_return[0] == '0')
|
---|
704 | {
|
---|
705 | #ifdef INDI_DEBUG
|
---|
706 | IDLog("%s Failed.\n", data);
|
---|
707 | #endif
|
---|
708 | return -1;
|
---|
709 | }
|
---|
710 |
|
---|
711 | #ifdef INDI_DEBUG
|
---|
712 | IDLog("%s Successful\n", data);
|
---|
713 | #endif
|
---|
714 |
|
---|
715 | return 0;
|
---|
716 |
|
---|
717 |
|
---|
718 | }
|
---|
719 |
|
---|
720 | int setCommandInt(int fd, int data, const char *cmd)
|
---|
721 | {
|
---|
722 | char temp_string[16];
|
---|
723 | int error_type;
|
---|
724 | int nbytes_write=0;
|
---|
725 |
|
---|
726 | snprintf(temp_string, sizeof( temp_string ), "%s%d#", cmd, data);
|
---|
727 |
|
---|
728 | if ( (error_type = tty_write_string(fd, temp_string, &nbytes_write)) != TTY_OK)
|
---|
729 | return error_type;
|
---|
730 |
|
---|
731 | /* if (portWrite(temp_string) < 0)
|
---|
732 | return -1;*/
|
---|
733 |
|
---|
734 | return 0;
|
---|
735 | }
|
---|
736 |
|
---|
737 | int setMinElevationLimit(int fd, int min)
|
---|
738 | {
|
---|
739 | char temp_string[16];
|
---|
740 |
|
---|
741 | snprintf(temp_string, sizeof( temp_string ), "#:Sh%02d#", min);
|
---|
742 |
|
---|
743 | return (setStandardProcedure(fd, temp_string));
|
---|
744 | }
|
---|
745 |
|
---|
746 | int setMaxElevationLimit(int fd, int max)
|
---|
747 | {
|
---|
748 | char temp_string[16];
|
---|
749 |
|
---|
750 | snprintf(temp_string, sizeof( temp_string ), "#:So%02d*#", max);
|
---|
751 |
|
---|
752 | return (setStandardProcedure(fd, temp_string));
|
---|
753 |
|
---|
754 | }
|
---|
755 |
|
---|
756 | int setMaxSlewRate(int fd, int slewRate)
|
---|
757 | {
|
---|
758 |
|
---|
759 | char temp_string[16];
|
---|
760 |
|
---|
761 | if (slewRate < 2 || slewRate > 8)
|
---|
762 | return -1;
|
---|
763 |
|
---|
764 | snprintf(temp_string, sizeof( temp_string ), "#:Sw%d#", slewRate);
|
---|
765 |
|
---|
766 | return (setStandardProcedure(fd, temp_string));
|
---|
767 |
|
---|
768 | }
|
---|
769 |
|
---|
770 | int setObjectRA(int fd, double ra)
|
---|
771 | {
|
---|
772 |
|
---|
773 | int h, m, s, frac_m;
|
---|
774 | char temp_string[16];
|
---|
775 |
|
---|
776 | getSexComponents(ra, &h, &m, &s);
|
---|
777 |
|
---|
778 | frac_m = (s / 60.0) * 10.;
|
---|
779 |
|
---|
780 | if (controller_format == LX200_LONG_FORMAT)
|
---|
781 | snprintf(temp_string, sizeof( temp_string ), "#:Sr %02d:%02d:%02d#", h, m, s);
|
---|
782 | else
|
---|
783 | snprintf(temp_string, sizeof( temp_string ), "#:Sr %02d:%02d.%01d#", h, m, frac_m);
|
---|
784 |
|
---|
785 | /*IDLog("Set Object RA String %s\n", temp_string);*/
|
---|
786 | return (setStandardProcedure(fd, temp_string));
|
---|
787 | }
|
---|
788 |
|
---|
789 |
|
---|
790 | int setObjectDEC(int fd, double dec)
|
---|
791 | {
|
---|
792 | int d, m, s;
|
---|
793 | char temp_string[16];
|
---|
794 |
|
---|
795 | getSexComponents(dec, &d, &m, &s);
|
---|
796 |
|
---|
797 | switch(controller_format)
|
---|
798 | {
|
---|
799 |
|
---|
800 | case LX200_SHORT_FORMAT:
|
---|
801 | /* case with negative zero */
|
---|
802 | if (!d && dec < 0)
|
---|
803 | snprintf(temp_string, sizeof( temp_string ), "#:Sd -%02d*%02d#", d, m);
|
---|
804 | else
|
---|
805 | snprintf(temp_string, sizeof( temp_string ), "#:Sd %+03d*%02d#", d, m);
|
---|
806 | break;
|
---|
807 |
|
---|
808 | case LX200_LONG_FORMAT:
|
---|
809 | /* case with negative zero */
|
---|
810 | if (!d && dec < 0)
|
---|
811 | snprintf(temp_string, sizeof( temp_string ), "#:Sd -%02d:%02d:%02d#", d, m, s);
|
---|
812 | else
|
---|
813 | snprintf(temp_string, sizeof( temp_string ), "#:Sd %+03d:%02d:%02d#", d, m, s);
|
---|
814 | break;
|
---|
815 | }
|
---|
816 |
|
---|
817 | /*IDLog("Set Object DEC String %s\n", temp_string);*/
|
---|
818 |
|
---|
819 | return (setStandardProcedure(fd, temp_string));
|
---|
820 |
|
---|
821 | }
|
---|
822 |
|
---|
823 | int setCommandXYZ(int fd, int x, int y, int z, const char *cmd)
|
---|
824 | {
|
---|
825 | char temp_string[16];
|
---|
826 |
|
---|
827 | snprintf(temp_string, sizeof( temp_string ), "%s %02d:%02d:%02d#", cmd, x, y, z);
|
---|
828 |
|
---|
829 | return (setStandardProcedure(fd, temp_string));
|
---|
830 | }
|
---|
831 |
|
---|
832 | int setAlignmentMode(int fd, unsigned int alignMode)
|
---|
833 | {
|
---|
834 | /*fprintf(stderr , "Set alignment mode %d\n", alignMode);*/
|
---|
835 | int error_type;
|
---|
836 | int nbytes_write=0;
|
---|
837 |
|
---|
838 | switch (alignMode)
|
---|
839 | {
|
---|
840 | case LX200_ALIGN_POLAR:
|
---|
841 | if ( (error_type = tty_write_string(fd, "#:AP#", &nbytes_write)) != TTY_OK)
|
---|
842 | return error_type;
|
---|
843 | /*if (portWrite("#:AP#") < 0)
|
---|
844 | return -1;*/
|
---|
845 | break;
|
---|
846 | case LX200_ALIGN_ALTAZ:
|
---|
847 | if ( (error_type = tty_write_string(fd, "#:AA#", &nbytes_write)) != TTY_OK)
|
---|
848 | return error_type;
|
---|
849 | /*if (portWrite("#:AA#") < 0)
|
---|
850 | return -1;*/
|
---|
851 | break;
|
---|
852 | case LX200_ALIGN_LAND:
|
---|
853 | if ( (error_type = tty_write_string(fd, "#:AL#", &nbytes_write)) != TTY_OK)
|
---|
854 | return error_type;
|
---|
855 | /*if (portWrite("#:AL#") < 0)
|
---|
856 | return -1;*/
|
---|
857 | break;
|
---|
858 | }
|
---|
859 |
|
---|
860 | tcflush(fd, TCIFLUSH);
|
---|
861 | return 0;
|
---|
862 | }
|
---|
863 |
|
---|
864 | int setCalenderDate(int fd, int dd, int mm, int yy)
|
---|
865 | {
|
---|
866 | char temp_string[32];
|
---|
867 | char dumpPlanetaryUpdateString[64];
|
---|
868 | char bool_return[2];
|
---|
869 | int error_type;
|
---|
870 | int nbytes_write=0, nbytes_read=0;
|
---|
871 | yy = yy % 100;
|
---|
872 |
|
---|
873 | snprintf(temp_string, sizeof( temp_string ), "#:SC %02d/%02d/%02d#", mm, dd, yy);
|
---|
874 |
|
---|
875 | if ( (error_type = tty_write_string(fd, temp_string, &nbytes_write)) != TTY_OK)
|
---|
876 | return error_type;
|
---|
877 |
|
---|
878 | /*if (portWrite(temp_string) < 0)
|
---|
879 | return -1;*/
|
---|
880 |
|
---|
881 | /*read_ret = portRead(boolRet, 1, LX200_TIMEOUT);*/
|
---|
882 | error_type = tty_read(fd, bool_return, 1, LX200_TIMEOUT, &nbytes_read);
|
---|
883 | tcflush(fd, TCIFLUSH);
|
---|
884 |
|
---|
885 | if (nbytes_read < 1)
|
---|
886 | return error_type;
|
---|
887 |
|
---|
888 | bool_return[1] = '\0';
|
---|
889 |
|
---|
890 | if (bool_return[0] == '0')
|
---|
891 | return -1;
|
---|
892 |
|
---|
893 | /* Read dumped data */
|
---|
894 | error_type = tty_read_section(fd, dumpPlanetaryUpdateString, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
895 | error_type = tty_read_section(fd, dumpPlanetaryUpdateString, '#', 5, &nbytes_read);
|
---|
896 |
|
---|
897 | return 0;
|
---|
898 | }
|
---|
899 |
|
---|
900 | int setUTCOffset(int fd, double hours)
|
---|
901 | {
|
---|
902 | char temp_string[16];
|
---|
903 |
|
---|
904 | snprintf(temp_string, sizeof( temp_string ), "#:SG %+03d#", (int) hours);
|
---|
905 |
|
---|
906 | /*IDLog("UTC string is %s\n", temp_string);*/
|
---|
907 |
|
---|
908 | return (setStandardProcedure(fd, temp_string));
|
---|
909 |
|
---|
910 | }
|
---|
911 |
|
---|
912 | int setSiteLongitude(int fd, double Long)
|
---|
913 | {
|
---|
914 | int d, m, s;
|
---|
915 | char temp_string[32];
|
---|
916 |
|
---|
917 | getSexComponents(Long, &d, &m, &s);
|
---|
918 |
|
---|
919 | snprintf(temp_string, sizeof( temp_string ), "#:Sg%03d:%02d#", d, m);
|
---|
920 |
|
---|
921 | return (setStandardProcedure(fd, temp_string));
|
---|
922 | }
|
---|
923 |
|
---|
924 | int setSiteLatitude(int fd, double Lat)
|
---|
925 | {
|
---|
926 | int d, m, s;
|
---|
927 | char temp_string[32];
|
---|
928 |
|
---|
929 | getSexComponents(Lat, &d, &m, &s);
|
---|
930 |
|
---|
931 | snprintf(temp_string, sizeof( temp_string ), "#:St%+03d:%02d:%02d#", d, m, s);
|
---|
932 |
|
---|
933 | return (setStandardProcedure(fd, temp_string));
|
---|
934 | }
|
---|
935 |
|
---|
936 | int setObjAz(int fd, double az)
|
---|
937 | {
|
---|
938 | int d,m,s;
|
---|
939 | char temp_string[16];
|
---|
940 |
|
---|
941 | getSexComponents(az, &d, &m, &s);
|
---|
942 |
|
---|
943 | snprintf(temp_string, sizeof( temp_string ), "#:Sz%03d:%02d#", d, m);
|
---|
944 |
|
---|
945 | return (setStandardProcedure(fd, temp_string));
|
---|
946 |
|
---|
947 | }
|
---|
948 |
|
---|
949 | int setObjAlt(int fd, double alt)
|
---|
950 | {
|
---|
951 | int d, m, s;
|
---|
952 | char temp_string[16];
|
---|
953 |
|
---|
954 | getSexComponents(alt, &d, &m, &s);
|
---|
955 |
|
---|
956 | snprintf(temp_string, sizeof( temp_string ), "#:Sa%+02d*%02d#", d, m);
|
---|
957 |
|
---|
958 | return (setStandardProcedure(fd, temp_string));
|
---|
959 | }
|
---|
960 |
|
---|
961 |
|
---|
962 | int setSiteName(int fd, char * siteName, int siteNum)
|
---|
963 | {
|
---|
964 |
|
---|
965 | char temp_string[16];
|
---|
966 |
|
---|
967 | switch (siteNum)
|
---|
968 | {
|
---|
969 | case 1:
|
---|
970 | snprintf(temp_string, sizeof( temp_string ), "#:SM %s#", siteName);
|
---|
971 | break;
|
---|
972 | case 2:
|
---|
973 | snprintf(temp_string, sizeof( temp_string ), "#:SN %s#", siteName);
|
---|
974 | break;
|
---|
975 | case 3:
|
---|
976 | snprintf(temp_string, sizeof( temp_string ), "#:SO %s#", siteName);
|
---|
977 | break;
|
---|
978 | case 4:
|
---|
979 | snprintf(temp_string, sizeof( temp_string ), "#:SP %s#", siteName);
|
---|
980 | break;
|
---|
981 | default:
|
---|
982 | return -1;
|
---|
983 | }
|
---|
984 |
|
---|
985 | return (setStandardProcedure(fd, temp_string));
|
---|
986 | }
|
---|
987 |
|
---|
988 | int setSlewMode(int fd, int slewMode)
|
---|
989 | {
|
---|
990 | int error_type;
|
---|
991 | int nbytes_write=0;
|
---|
992 |
|
---|
993 | switch (slewMode)
|
---|
994 | {
|
---|
995 | case LX200_SLEW_MAX:
|
---|
996 | if ( (error_type = tty_write_string(fd, "#:RS#", &nbytes_write)) != TTY_OK)
|
---|
997 | return error_type;
|
---|
998 | /*if (portWrite("#:RS#") < 0)
|
---|
999 | return -1;*/
|
---|
1000 | break;
|
---|
1001 | case LX200_SLEW_FIND:
|
---|
1002 | if ( (error_type = tty_write_string(fd, "#:RM#", &nbytes_write)) != TTY_OK)
|
---|
1003 | return error_type;
|
---|
1004 | /*if (portWrite("#:RM#") < 0)
|
---|
1005 | return -1;*/
|
---|
1006 | break;
|
---|
1007 | case LX200_SLEW_CENTER:
|
---|
1008 | if ( (error_type = tty_write_string(fd, "#:RC#", &nbytes_write)) != TTY_OK)
|
---|
1009 | return error_type;
|
---|
1010 | /*if (portWrite("#:RC#") < 0)
|
---|
1011 | return -1;*/
|
---|
1012 | break;
|
---|
1013 | case LX200_SLEW_GUIDE:
|
---|
1014 | if ( (error_type = tty_write_string(fd, "#:RG#", &nbytes_write)) != TTY_OK)
|
---|
1015 | return error_type;
|
---|
1016 | /*if (portWrite("#:RG#") < 0)
|
---|
1017 | return -1;*/
|
---|
1018 | break;
|
---|
1019 | default:
|
---|
1020 | break;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | tcflush(fd, TCIFLUSH);
|
---|
1024 | return 0;
|
---|
1025 |
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | int setFocuserMotion(int fd, int motionType)
|
---|
1029 | {
|
---|
1030 | int error_type;
|
---|
1031 | int nbytes_write=0;
|
---|
1032 |
|
---|
1033 | switch (motionType)
|
---|
1034 | {
|
---|
1035 | case LX200_FOCUSIN:
|
---|
1036 | if ( (error_type = tty_write_string(fd, "#:F+#", &nbytes_write)) != TTY_OK)
|
---|
1037 | return error_type;
|
---|
1038 | #ifdef INDI_DEBUG
|
---|
1039 | /*IDLog("Focus IN Command\n");*/
|
---|
1040 | #endif
|
---|
1041 | /*if (portWrite("#:F+#") < 0)
|
---|
1042 | return -1;*/
|
---|
1043 | break;
|
---|
1044 | case LX200_FOCUSOUT:
|
---|
1045 | if ( (error_type = tty_write_string(fd, "#:F-#", &nbytes_write)) != TTY_OK)
|
---|
1046 | return error_type;
|
---|
1047 | #ifdef INDI_DEBUG
|
---|
1048 | /*IDLog("Focus OUT Command\n");*/
|
---|
1049 | #endif
|
---|
1050 | /*if (portWrite("#:F-#") < 0)
|
---|
1051 | return -1;*/
|
---|
1052 | break;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | tcflush(fd, TCIFLUSH);
|
---|
1056 | return 0;
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | int setFocuserSpeedMode (int fd, int speedMode)
|
---|
1060 | {
|
---|
1061 | int error_type;
|
---|
1062 | int nbytes_write=0;
|
---|
1063 |
|
---|
1064 | switch (speedMode)
|
---|
1065 | {
|
---|
1066 | case LX200_HALTFOCUS:
|
---|
1067 | if ( (error_type = tty_write_string(fd, "#:FQ#", &nbytes_write)) != TTY_OK)
|
---|
1068 | return error_type;
|
---|
1069 | #ifdef INDI_DEBUG
|
---|
1070 | /*IDLog("Halt Focus Command\n");*/
|
---|
1071 | #endif
|
---|
1072 | /* if (portWrite("#:FQ#") < 0)
|
---|
1073 | return -1;*/
|
---|
1074 | break;
|
---|
1075 | case LX200_FOCUSSLOW:
|
---|
1076 | if ( (error_type = tty_write_string(fd, "#:FS#", &nbytes_write)) != TTY_OK)
|
---|
1077 | return error_type;
|
---|
1078 | #ifdef INDI_DEBUG
|
---|
1079 | /*IDLog("Focus Slow (FS) Command\n");*/
|
---|
1080 | #endif
|
---|
1081 | /*if (portWrite("#:FS#") < 0)
|
---|
1082 | return -1;*/
|
---|
1083 | break;
|
---|
1084 | case LX200_FOCUSFAST:
|
---|
1085 | if ( (error_type = tty_write_string(fd, "#:FF#", &nbytes_write)) != TTY_OK)
|
---|
1086 | return error_type;
|
---|
1087 | #ifdef INDI_DEBUG
|
---|
1088 | /*IDLog("Focus Fast (FF) Command\n");*/
|
---|
1089 | #endif
|
---|
1090 | /*if (portWrite("#:FF#") < 0)
|
---|
1091 | return -1;*/
|
---|
1092 | break;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | tcflush(fd, TCIFLUSH);
|
---|
1096 | return 0;
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | int setGPSFocuserSpeed (int fd, int speed)
|
---|
1100 | {
|
---|
1101 | char speed_str[8];
|
---|
1102 | int error_type;
|
---|
1103 | int nbytes_write=0;
|
---|
1104 |
|
---|
1105 | if (speed == 0)
|
---|
1106 | {
|
---|
1107 | /*if (portWrite("#:FQ#") < 0)
|
---|
1108 | return -1;*/
|
---|
1109 | if ( (error_type = tty_write_string(fd, "#:FQ#", &nbytes_write)) != TTY_OK)
|
---|
1110 | return error_type;
|
---|
1111 | #ifdef INDI_DEBUG
|
---|
1112 | /*IDLog("GPS Focus HALT Command (FQ) \n");*/
|
---|
1113 | #endif
|
---|
1114 |
|
---|
1115 | return 0;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | snprintf(speed_str, 8, "#:F%d#", speed);
|
---|
1119 |
|
---|
1120 | if ( (error_type = tty_write_string(fd, speed_str, &nbytes_write)) != TTY_OK)
|
---|
1121 | return error_type;
|
---|
1122 |
|
---|
1123 | #ifdef INDI_DEBUG
|
---|
1124 | /*IDLog("GPS Focus Speed command %s \n", speed_str);*/
|
---|
1125 | #endif
|
---|
1126 | /*if (portWrite(speed_str) < 0)
|
---|
1127 | return -1;*/
|
---|
1128 |
|
---|
1129 | tcflush(fd, TCIFLUSH);
|
---|
1130 | return 0;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | int setTrackFreq(int fd, double trackF)
|
---|
1134 | {
|
---|
1135 | char temp_string[16];
|
---|
1136 |
|
---|
1137 | snprintf(temp_string, sizeof( temp_string ), "#:ST %04.1f#", trackF);
|
---|
1138 |
|
---|
1139 | return (setStandardProcedure(fd, temp_string));
|
---|
1140 |
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | /**********************************************************************
|
---|
1144 | * Misc
|
---|
1145 | *********************************************************************/
|
---|
1146 |
|
---|
1147 | int Slew(int fd)
|
---|
1148 | {
|
---|
1149 | char slewNum[2];
|
---|
1150 | int error_type;
|
---|
1151 | int nbytes_write=0, nbytes_read=0;
|
---|
1152 |
|
---|
1153 | if ( (error_type = tty_write_string(fd, "#:MS#", &nbytes_write)) != TTY_OK)
|
---|
1154 | return error_type;
|
---|
1155 |
|
---|
1156 | error_type = tty_read(fd, slewNum, 1, LX200_TIMEOUT, &nbytes_read);
|
---|
1157 |
|
---|
1158 | if (nbytes_read < 1)
|
---|
1159 | return error_type;
|
---|
1160 |
|
---|
1161 | /* We don't need to read the string message, just return corresponding error code */
|
---|
1162 | tcflush(fd, TCIFLUSH);
|
---|
1163 |
|
---|
1164 | if (slewNum[0] == '0')
|
---|
1165 | return 0;
|
---|
1166 | else if (slewNum[0] == '1')
|
---|
1167 | return 1;
|
---|
1168 | else return 2;
|
---|
1169 |
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | int MoveTo(int fd, int direction)
|
---|
1173 | {
|
---|
1174 | int nbytes_write=0;
|
---|
1175 |
|
---|
1176 | switch (direction)
|
---|
1177 | {
|
---|
1178 | case LX200_NORTH:
|
---|
1179 | tty_write_string(fd, "#:Mn#", &nbytes_write);
|
---|
1180 | /*portWrite("#:Mn#");*/
|
---|
1181 | break;
|
---|
1182 | case LX200_WEST:
|
---|
1183 | tty_write_string(fd, "#:Mw#", &nbytes_write);
|
---|
1184 | /*portWrite("#:Mw#");*/
|
---|
1185 | break;
|
---|
1186 | case LX200_EAST:
|
---|
1187 | tty_write_string(fd, "#:Me#", &nbytes_write);
|
---|
1188 | /*portWrite("#:Me#");*/
|
---|
1189 | break;
|
---|
1190 | case LX200_SOUTH:
|
---|
1191 | tty_write_string(fd, "#:Ms#", &nbytes_write);
|
---|
1192 | /*portWrite("#:Ms#");*/
|
---|
1193 | break;
|
---|
1194 | default:
|
---|
1195 | break;
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | tcflush(fd, TCIFLUSH);
|
---|
1199 | return 0;
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | int SendPulseCmd(int fd, int direction, int duration_msec)
|
---|
1203 | {
|
---|
1204 | int nbytes_write=0;
|
---|
1205 | char cmd[20];
|
---|
1206 | switch (direction)
|
---|
1207 | {
|
---|
1208 | case LX200_NORTH: sprintf(cmd, "#:Mgn%04d#", duration_msec); break;
|
---|
1209 | case LX200_SOUTH: sprintf(cmd, "#:Mgs%04d#", duration_msec); break;
|
---|
1210 | case LX200_EAST: sprintf(cmd, "#:Mge%04d#", duration_msec); break;
|
---|
1211 | case LX200_WEST: sprintf(cmd, "#:Mgw%04d#", duration_msec); break;
|
---|
1212 | default: return 1;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | tty_write_string(fd, cmd, &nbytes_write);
|
---|
1216 |
|
---|
1217 | tcflush(fd, TCIFLUSH);
|
---|
1218 | return 0;
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | int HaltMovement(int fd, int direction)
|
---|
1222 | {
|
---|
1223 | int error_type;
|
---|
1224 | int nbytes_write=0;
|
---|
1225 |
|
---|
1226 | switch (direction)
|
---|
1227 | {
|
---|
1228 | case LX200_NORTH:
|
---|
1229 | /*if (portWrite("#:Qn#") < 0)
|
---|
1230 | return -1;*/
|
---|
1231 | if ( (error_type = tty_write_string(fd, "#:Qn#", &nbytes_write)) != TTY_OK)
|
---|
1232 | return error_type;
|
---|
1233 | break;
|
---|
1234 | case LX200_WEST:
|
---|
1235 | /*if (portWrite("#:Qw#") < 0)
|
---|
1236 | return -1;*/
|
---|
1237 | if ( (error_type = tty_write_string(fd, "#:Qw#", &nbytes_write)) != TTY_OK)
|
---|
1238 | return error_type;
|
---|
1239 | break;
|
---|
1240 | case LX200_EAST:
|
---|
1241 | /*if (portWrite("#:Qe#") < 0)
|
---|
1242 | return -1;*/
|
---|
1243 | if ( (error_type = tty_write_string(fd, "#:Qe#", &nbytes_write)) != TTY_OK)
|
---|
1244 | return error_type;
|
---|
1245 | break;
|
---|
1246 | case LX200_SOUTH:
|
---|
1247 | if ( (error_type = tty_write_string(fd, "#:Qs#", &nbytes_write)) != TTY_OK)
|
---|
1248 | return error_type;
|
---|
1249 | /*if (portWrite("#:Qs#") < 0)
|
---|
1250 | return -1;*/
|
---|
1251 | break;
|
---|
1252 | case LX200_ALL:
|
---|
1253 | /*if (portWrite("#:Q#") < 0)
|
---|
1254 | return -1;*/
|
---|
1255 | if ( (error_type = tty_write_string(fd, "#:Q#", &nbytes_write)) != TTY_OK)
|
---|
1256 | return error_type;
|
---|
1257 | break;
|
---|
1258 | default:
|
---|
1259 | return -1;
|
---|
1260 | break;
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | tcflush(fd, TCIFLUSH);
|
---|
1264 | return 0;
|
---|
1265 |
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | int abortSlew(int fd)
|
---|
1269 | {
|
---|
1270 | /*if (portWrite("#:Q#") < 0)
|
---|
1271 | return -1;*/
|
---|
1272 | int error_type;
|
---|
1273 | int nbytes_write=0;
|
---|
1274 |
|
---|
1275 | if ( (error_type = tty_write_string(fd, "#:Q#", &nbytes_write)) != TTY_OK)
|
---|
1276 | return error_type;
|
---|
1277 |
|
---|
1278 | tcflush(fd, TCIFLUSH);
|
---|
1279 | return 0;
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | int Sync(int fd, char *matchedObject)
|
---|
1283 | {
|
---|
1284 | int error_type;
|
---|
1285 | int nbytes_write=0, nbytes_read=0;
|
---|
1286 |
|
---|
1287 | if ( (error_type = tty_write_string(fd, "#:CM#", &nbytes_write)) != TTY_OK)
|
---|
1288 | return error_type;
|
---|
1289 |
|
---|
1290 | /*portWrite("#:CM#");*/
|
---|
1291 |
|
---|
1292 | /*read_ret = portRead(matchedObject, -1, LX200_TIMEOUT);*/
|
---|
1293 | error_type = tty_read_section(fd, matchedObject, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
1294 |
|
---|
1295 | if (nbytes_read < 1)
|
---|
1296 | return error_type;
|
---|
1297 |
|
---|
1298 | matchedObject[nbytes_read-1] = '\0';
|
---|
1299 |
|
---|
1300 | /*IDLog("Matched Object: %s\n", matchedObject);*/
|
---|
1301 |
|
---|
1302 | /* Sleep 10ms before flushing. This solves some issues with LX200 compatible devices. */
|
---|
1303 | usleep(10000);
|
---|
1304 | tcflush(fd, TCIFLUSH);
|
---|
1305 |
|
---|
1306 | return 0;
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | int selectSite(int fd, int siteNum)
|
---|
1310 | {
|
---|
1311 | int error_type;
|
---|
1312 | int nbytes_write=0;
|
---|
1313 |
|
---|
1314 | switch (siteNum)
|
---|
1315 | {
|
---|
1316 | case 1:
|
---|
1317 | if ( (error_type = tty_write_string(fd, "#:W1#", &nbytes_write)) != TTY_OK)
|
---|
1318 | return error_type;
|
---|
1319 | /*if (portWrite("#:W1#") < 0)
|
---|
1320 | return -1;*/
|
---|
1321 | break;
|
---|
1322 | case 2:
|
---|
1323 | if ( (error_type = tty_write_string(fd, "#:W2#", &nbytes_write)) != TTY_OK)
|
---|
1324 | return error_type;
|
---|
1325 | /*if (portWrite("#:W2#") < 0)
|
---|
1326 | return -1;*/
|
---|
1327 | break;
|
---|
1328 | case 3:
|
---|
1329 | if ( (error_type = tty_write_string(fd, "#:W3#", &nbytes_write)) != TTY_OK)
|
---|
1330 | return error_type;
|
---|
1331 | /*if (portWrite("#:W3#") < 0)
|
---|
1332 | return -1;*/
|
---|
1333 | break;
|
---|
1334 | case 4:
|
---|
1335 | if ( (error_type = tty_write_string(fd, "#:W4#", &nbytes_write)) != TTY_OK)
|
---|
1336 | return error_type;
|
---|
1337 | /*if (portWrite("#:W4#") < 0)
|
---|
1338 | return -1;*/
|
---|
1339 | break;
|
---|
1340 | default:
|
---|
1341 | return -1;
|
---|
1342 | break;
|
---|
1343 | }
|
---|
1344 |
|
---|
1345 | tcflush(fd, TCIFLUSH);
|
---|
1346 | return 0;
|
---|
1347 |
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | int selectCatalogObject(int fd, int catalog, int NNNN)
|
---|
1351 | {
|
---|
1352 | char temp_string[16];
|
---|
1353 | int error_type;
|
---|
1354 | int nbytes_write=0;
|
---|
1355 |
|
---|
1356 | switch (catalog)
|
---|
1357 | {
|
---|
1358 | case LX200_STAR_C:
|
---|
1359 | snprintf(temp_string, sizeof( temp_string ), "#:LS%d#", NNNN);
|
---|
1360 | break;
|
---|
1361 | case LX200_DEEPSKY_C:
|
---|
1362 | snprintf(temp_string, sizeof( temp_string ), "#:LC%d#", NNNN);
|
---|
1363 | break;
|
---|
1364 | case LX200_MESSIER_C:
|
---|
1365 | snprintf(temp_string, sizeof( temp_string ), "#:LM%d#", NNNN);
|
---|
1366 | break;
|
---|
1367 | default:
|
---|
1368 | return -1;
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | if ( (error_type = tty_write_string(fd, temp_string, &nbytes_write)) != TTY_OK)
|
---|
1372 | return error_type;
|
---|
1373 | /*if (portWrite(temp_string) < 0)
|
---|
1374 | return -1;*/
|
---|
1375 |
|
---|
1376 | tcflush(fd, TCIFLUSH);
|
---|
1377 | return 0;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | int selectSubCatalog(int fd, int catalog, int subCatalog)
|
---|
1381 | {
|
---|
1382 | char temp_string[16];
|
---|
1383 | switch (catalog)
|
---|
1384 | {
|
---|
1385 | case LX200_STAR_C:
|
---|
1386 | snprintf(temp_string, sizeof( temp_string ), "#:LsD%d#", subCatalog);
|
---|
1387 | break;
|
---|
1388 | case LX200_DEEPSKY_C:
|
---|
1389 | snprintf(temp_string, sizeof( temp_string ), "#:LoD%d#", subCatalog);
|
---|
1390 | break;
|
---|
1391 | case LX200_MESSIER_C:
|
---|
1392 | return 1;
|
---|
1393 | default:
|
---|
1394 | return 0;
|
---|
1395 | }
|
---|
1396 |
|
---|
1397 | return (setStandardProcedure(fd, temp_string));
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | int checkLX200Format(int fd)
|
---|
1401 | {
|
---|
1402 | char temp_string[16];
|
---|
1403 | controller_format = LX200_LONG_FORMAT;
|
---|
1404 | int error_type;
|
---|
1405 | int nbytes_write=0, nbytes_read=0;
|
---|
1406 |
|
---|
1407 | if ( (error_type = tty_write_string(fd, "#:GR#", &nbytes_write)) != TTY_OK)
|
---|
1408 | return error_type;
|
---|
1409 |
|
---|
1410 | /*if (portWrite("#:GR#") < 0)
|
---|
1411 | return -1;*/
|
---|
1412 |
|
---|
1413 | /*read_ret = portRead(temp_string, -1, LX200_TIMEOUT);*/
|
---|
1414 | error_type = tty_read_section(fd, temp_string, '#', LX200_TIMEOUT, &nbytes_read);
|
---|
1415 |
|
---|
1416 | if (nbytes_read < 1)
|
---|
1417 | return error_type;
|
---|
1418 |
|
---|
1419 | temp_string[nbytes_read - 1] = '\0';
|
---|
1420 |
|
---|
1421 | /* Check whether it's short or long */
|
---|
1422 | if (temp_string[5] == '.')
|
---|
1423 | {
|
---|
1424 | controller_format = LX200_SHORT_FORMAT;
|
---|
1425 | return 0;
|
---|
1426 | }
|
---|
1427 | else
|
---|
1428 | return 0;
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | int selectTrackingMode(int fd, int trackMode)
|
---|
1432 | {
|
---|
1433 | int error_type;
|
---|
1434 | int nbytes_write=0;
|
---|
1435 |
|
---|
1436 | switch (trackMode)
|
---|
1437 | {
|
---|
1438 | case LX200_TRACK_DEFAULT:
|
---|
1439 | #ifdef INDI_DEBUG
|
---|
1440 | IDLog("Setting tracking mode to sidereal.\n");
|
---|
1441 | #endif
|
---|
1442 | if ( (error_type = tty_write_string(fd, "#:TQ#", &nbytes_write)) != TTY_OK)
|
---|
1443 | return error_type;
|
---|
1444 | /*if (portWrite("#:TQ#") < 0)
|
---|
1445 | return -1;*/
|
---|
1446 | break;
|
---|
1447 | case LX200_TRACK_LUNAR:
|
---|
1448 | #ifdef INDI_DEBUG
|
---|
1449 | IDLog("Setting tracking mode to LUNAR.\n");
|
---|
1450 | #endif
|
---|
1451 | if ( (error_type = tty_write_string(fd, "#:TL#", &nbytes_write)) != TTY_OK)
|
---|
1452 | return error_type;
|
---|
1453 | /*if (portWrite("#:TL#") < 0)
|
---|
1454 | return -1;*/
|
---|
1455 | break;
|
---|
1456 | case LX200_TRACK_MANUAL:
|
---|
1457 | #ifdef INDI_DEBUG
|
---|
1458 | IDLog("Setting tracking mode to CUSTOM.\n");
|
---|
1459 | #endif
|
---|
1460 | if ( (error_type = tty_write_string(fd, "#:TM#", &nbytes_write)) != TTY_OK)
|
---|
1461 | return error_type;
|
---|
1462 | /*if (portWrite("#:TM#") < 0)
|
---|
1463 | return -1;*/
|
---|
1464 | break;
|
---|
1465 | default:
|
---|
1466 | return -1;
|
---|
1467 | break;
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 | tcflush(fd, TCIFLUSH);
|
---|
1471 | return 0;
|
---|
1472 |
|
---|
1473 | }
|
---|
1474 |
|
---|