Instrument Neutral Distributed Interface INDI  2.0.2
ieqprolegacydriver.cpp
Go to the documentation of this file.
1 /*
2  IEQ Pro driver
3 
4  Copyright (C) 2015 Jasem Mutlaq
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #include "ieqprolegacydriver.h"
22 
23 #include "indicom.h"
24 #include "indilogger.h"
25 
26 #include <libnova/julian_day.h>
27 
28 #include <cmath>
29 #include <map>
30 #include <cstring>
31 #include <termios.h>
32 #include <unistd.h>
33 
34 #define IEQPRO_TIMEOUT 5 /* FD timeout in seconds */
35 
36 static bool ieqpro_debug = false;
37 static bool ieqpro_simulation = false;
38 static char ieqpro_device[MAXINDIDEVICE] = "iEQ";
39 static IEQInfo simInfo;
40 
41 struct
42 {
43  double ra;
44  double dec;
45  double ra_guide_rate;
46  double de_guide_rate;
48 
49 void set_ieqpro_debug(bool enable)
50 {
51  ieqpro_debug = enable;
52 }
53 
54 void set_ieqpro_simulation(bool enable)
55 {
56  ieqpro_simulation = enable;
57  if (enable)
58  {
59  simData.ra_guide_rate = 0.5;
60  simData.de_guide_rate = 0.5;
61  }
62 }
63 
64 void set_ieqpro_device(const char *name)
65 {
66  strncpy(ieqpro_device, name, MAXINDIDEVICE);
67 }
68 
70 {
71  simInfo.gpsStatus = value;
72 }
73 
75 {
76  simInfo.systemStatus = value;
77 }
78 
80 {
81  simInfo.trackRate = value;
82 }
83 
85 {
86  simInfo.slewRate = value;
87 }
88 
90 {
91  simInfo.timeSource = value;
92 }
93 
95 {
96  simInfo.hemisphere = value;
97 }
98 
99 void set_sim_ra(double ra)
100 {
101  simData.ra = ra;
102 }
103 
104 void set_sim_dec(double dec)
105 {
106  simData.dec = dec;
107 }
108 
109 void set_sim_guide_rate(double ra, double de)
110 {
111  simData.ra_guide_rate = ra;
112  simData.de_guide_rate = de;
113 }
114 
116 {
117  char initCMD[] = ":V#";
118  int errcode = 0;
119  char errmsg[MAXRBUF];
120  char response[8];
121  int nbytes_read = 0;
122  int nbytes_written = 0;
123 
124  DEBUGDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "Initializing IOptron using :V# CMD...");
125 
126  for (int i = 0; i < 2; i++)
127  {
128  if (ieqpro_simulation)
129  {
130  strcpy(response, "V1.00#");
131  nbytes_read = strlen(response);
132  }
133  else
134  {
135  tcflush(fd, TCIFLUSH);
136 
137  if ((errcode = tty_write(fd, initCMD, 3, &nbytes_written)) != TTY_OK)
138  {
139  tty_error_msg(errcode, errmsg, MAXRBUF);
140  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
141  usleep(50000);
142  continue;
143  }
144 
145  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
146  {
147  tty_error_msg(errcode, errmsg, MAXRBUF);
148  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
149  usleep(50000);
150  continue;
151  }
152  }
153 
154  if (nbytes_read > 0)
155  {
156  response[nbytes_read] = '\0';
157  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
158 
159  if (!strcmp(response, "V1.00#"))
160  return true;
161  }
162 
163  usleep(50000);
164  }
165 
166  return false;
167 }
168 
169 bool get_ieqpro_status(int fd, IEQInfo *info)
170 {
171  char cmd[] = ":GAS#";
172  int errcode = 0;
173  char errmsg[MAXRBUF];
174  char response[8];
175  int nbytes_read = 0;
176  int nbytes_written = 0;
177 
178  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_EXTRA_1, "CMD <%s>", cmd);
179 
180  if (ieqpro_simulation)
181  {
182  snprintf(response, 8, "%d%d%d%d%d%d#", simInfo.gpsStatus, simInfo.systemStatus, simInfo.trackRate,
183  simInfo.slewRate + 1, simInfo.timeSource, simInfo.hemisphere);
184  nbytes_read = strlen(response);
185  }
186  else
187  {
188  tcflush(fd, TCIFLUSH);
189 
190  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
191  {
192  tty_error_msg(errcode, errmsg, MAXRBUF);
193  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
194  return false;
195  }
196 
197  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
198  {
199  tty_error_msg(errcode, errmsg, MAXRBUF);
200  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
201  return false;
202  }
203  }
204 
205  if (nbytes_read > 0)
206  {
207  response[nbytes_read] = '\0';
208  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_EXTRA_1, "RES <%s>", response);
209 
210  if (nbytes_read == 7)
211  {
212  info->gpsStatus = (IEQ_GPS_STATUS)(response[0] - '0');
213  info->systemStatus = (IEQ_SYSTEM_STATUS)(response[1] - '0');
214  info->trackRate = (IEQ_TRACK_RATE)(response[2] - '0');
215  info->slewRate = (IEQ_SLEW_RATE)(response[3] - '0' - 1);
216  info->timeSource = (IEQ_TIME_SOURCE)(response[4] - '0');
217  info->hemisphere = (IEQ_HEMISPHERE)(response[5] - '0');
218 
219  tcflush(fd, TCIFLUSH);
220 
221  return true;
222  }
223  }
224 
225  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 7.", nbytes_read);
226  return false;
227 }
228 
230 {
231  bool rc = false;
232 
233  rc = get_ieqpro_model(fd, info);
234 
235  if (!rc)
236  return rc;
237 
238  rc = get_ieqpro_main_firmware(fd, info);
239 
240  if (!rc)
241  return rc;
242 
243  rc = get_ieqpro_radec_firmware(fd, info);
244 
245  return rc;
246 }
247 
249 {
250  char cmd[] = ":MountInfo#";
251  int errcode = 0;
252  char errmsg[MAXRBUF];
253  char response[16];
254  int nbytes_read = 0;
255  int nbytes_written = 0;
256 
257  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
258 
259  if (ieqpro_simulation)
260  {
261  strcpy(response, "0045");
262  nbytes_read = strlen(response);
263  }
264  else
265  {
266  tcflush(fd, TCIFLUSH);
267 
268  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
269  {
270  tty_error_msg(errcode, errmsg, MAXRBUF);
271  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
272  return false;
273  }
274 
275  if ((errcode = tty_read(fd, response, 4, IEQPRO_TIMEOUT, &nbytes_read)))
276  {
277  tty_error_msg(errcode, errmsg, MAXRBUF);
278  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
279  return false;
280  }
281  }
282 
283  if (nbytes_read > 0)
284  {
285  response[nbytes_read] = '\0';
286  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
287 
288  if (nbytes_read == 4)
289  {
290  std::map<std::string, std::string> models =
291  {
292  {"0010", "Cube II EQ"},
293  {"0011", "Smart EQ Pro+"},
294  {"0025", "CEM25"},
295  {"0026", "CEM25-EC"},
296  {"0030", "iEQ30Pro"},
297  {"0040", "CEM40"},
298  {"0041", "CEM40-EC"},
299  {"0043", "GEM45"},
300  {"0045", "iEQ45 Pro EQ"},
301  {"0046", "iEQ45 Pro AA"},
302  {"0060", "CEM60"},
303  {"0061", "CEM60-EC"},
304  {"0120", "CEM120"},
305  {"0121", "CEM120-EC"},
306  {"0122", "CEM120-EC2"},
307  {"5010", "Cube II AA"},
308  {"5035", "AZ Mount Pro"},
309  {"5045", "iEQ45 Pro AA"},
310  };
311 
312  if (models.find(response) != models.end())
313  info->Model = models[response];
314  else
315  info->Model = "Unknown";
316 
317  tcflush(fd, TCIFLUSH);
318 
319  return true;
320  }
321  }
322 
323  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 4.", nbytes_read);
324  return false;
325 }
326 
328 {
329  char cmd[] = ":FW1#";
330  int errcode = 0;
331  char errmsg[MAXRBUF];
332  char response[16];
333  int nbytes_read = 0;
334  int nbytes_written = 0;
335 
336  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
337 
338  if (ieqpro_simulation)
339  {
340  strcpy(response, "150324150101#");
341  nbytes_read = strlen(response);
342  }
343  else
344  {
345  tcflush(fd, TCIFLUSH);
346 
347  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
348  {
349  tty_error_msg(errcode, errmsg, MAXRBUF);
350  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
351  return false;
352  }
353 
354  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
355  {
356  tty_error_msg(errcode, errmsg, MAXRBUF);
357  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
358  return false;
359  }
360  }
361 
362  if (nbytes_read > 0)
363  {
364  response[nbytes_read] = '\0';
365  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
366 
367  if (nbytes_read == 13)
368  {
369  char board[8] = {0}, controller[8] = {0};
370 
371  strncpy(board, response, 6);
372  strncpy(controller, response + 6, 6);
373 
374  info->MainBoardFirmware.assign(board, 6);
375  info->ControllerFirmware.assign(controller, 6);
376 
377  tcflush(fd, TCIFLUSH);
378 
379  return true;
380  }
381  }
382 
383  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 13.", nbytes_read);
384  return false;
385 }
386 
388 {
389  char cmd[] = ":FW2#";
390  int errcode = 0;
391  char errmsg[MAXRBUF];
392  char response[16];
393  int nbytes_read = 0;
394  int nbytes_written = 0;
395 
396  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
397 
398  if (ieqpro_simulation)
399  {
400  strcpy(response, "140324140101#");
401  nbytes_read = strlen(response);
402  }
403  else
404  {
405  tcflush(fd, TCIFLUSH);
406 
407  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
408  {
409  tty_error_msg(errcode, errmsg, MAXRBUF);
410  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
411  return false;
412  }
413 
414  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
415  {
416  tty_error_msg(errcode, errmsg, MAXRBUF);
417  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
418  return false;
419  }
420  }
421 
422  if (nbytes_read > 0)
423  {
424  response[nbytes_read] = '\0';
425  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
426 
427  if (nbytes_read == 13)
428  {
429  char ra[8] = {0}, dec[8] = {0};
430 
431  strncpy(ra, response, 6);
432  strncpy(dec, response + 6, 6);
433 
434  info->RAFirmware.assign(ra, 6);
435  info->DEFirmware.assign(dec, 6);
436 
437  tcflush(fd, TCIFLUSH);
438 
439  return true;
440  }
441  }
442 
443  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 13.", nbytes_read);
444  return false;
445 }
446 
448 {
449  char cmd[16];
450  int errcode = 0;
451  char errmsg[MAXRBUF];
452  int nbytes_written = 0;
453 
454  switch (dir)
455  {
456  case IEQ_N:
457  strcpy(cmd, ":mn#");
458  break;
459  case IEQ_S:
460  strcpy(cmd, ":ms#");
461  break;
462  // case IEQ_W:
463  // strcpy(cmd, ":mw#");
464  // break;
465  // case IEQ_E:
466  // strcpy(cmd, ":me#");
467  // break;
468  // JM 2019-01-17: Appears iOptron implementation is reversed?
469  case IEQ_W:
470  strcpy(cmd, ":me#");
471  break;
472  case IEQ_E:
473  strcpy(cmd, ":mw#");
474  break;
475  }
476 
477  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
478 
479  if (ieqpro_simulation)
480  return true;
481 
482  tcflush(fd, TCIFLUSH);
483 
484  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
485  {
486  tty_error_msg(errcode, errmsg, MAXRBUF);
487  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
488  return false;
489  }
490 
491  tcflush(fd, TCIFLUSH);
492  return true;
493 }
494 
496 {
497  char cmd[16];
498  int errcode = 0;
499  char errmsg[MAXRBUF];
500  char response[8];
501  int nbytes_read = 0;
502  int nbytes_written = 0;
503 
504  switch (dir)
505  {
506  case IEQ_N:
507  case IEQ_S:
508  strcpy(cmd, ":qD#");
509  break;
510 
511  case IEQ_W:
512  case IEQ_E:
513  strcpy(cmd, ":qR#");
514  break;
515  }
516 
517  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
518 
519  if (ieqpro_simulation)
520  {
521  strcpy(response, "1");
522  nbytes_read = strlen(response);
523  }
524  else
525  {
526  tcflush(fd, TCIFLUSH);
527 
528  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
529  {
530  tty_error_msg(errcode, errmsg, MAXRBUF);
531  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
532  return false;
533  }
534 
535  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
536  {
537  tty_error_msg(errcode, errmsg, MAXRBUF);
538  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
539  return false;
540  }
541  }
542 
543  if (nbytes_read > 0)
544  {
545  response[nbytes_read] = '\0';
546  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
547 
548  tcflush(fd, TCIFLUSH);
549  return true;
550  }
551 
552  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
553  return false;
554 }
555 
557 {
558  char cmd[] = ":MSH#";
559  int errcode = 0;
560  char errmsg[MAXRBUF];
561  char response[8];
562  int nbytes_read = 0;
563  int nbytes_written = 0;
564 
565  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
566 
567  if (ieqpro_simulation)
568  {
569  strcpy(response, "1");
570  nbytes_read = strlen(response);
571  }
572  else
573  {
574  tcflush(fd, TCIFLUSH);
575 
576  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
577  {
578  tty_error_msg(errcode, errmsg, MAXRBUF);
579  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
580  return false;
581  }
582 
583  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
584  {
585  tty_error_msg(errcode, errmsg, MAXRBUF);
586  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
587  return false;
588  }
589  }
590 
591  if (nbytes_read > 0)
592  {
593  response[nbytes_read] = '\0';
594  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
595 
596  tcflush(fd, TCIFLUSH);
597  return true;
598  }
599 
600  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
601  return false;
602 }
603 
605 {
606  char cmd[] = ":MH#";
607  int errcode = 0;
608  char errmsg[MAXRBUF];
609  char response[8];
610  int nbytes_read = 0;
611  int nbytes_written = 0;
612 
613  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
614 
615  if (ieqpro_simulation)
616  {
617  strcpy(response, "1");
618  nbytes_read = strlen(response);
619  }
620  else
621  {
622  tcflush(fd, TCIFLUSH);
623 
624  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
625  {
626  tty_error_msg(errcode, errmsg, MAXRBUF);
627  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
628  return false;
629  }
630 
631  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
632  {
633  tty_error_msg(errcode, errmsg, MAXRBUF);
634  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
635  return false;
636  }
637  }
638 
639  if (nbytes_read > 0)
640  {
641  response[nbytes_read] = '\0';
642  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
643 
644  tcflush(fd, TCIFLUSH);
645  return true;
646  }
647 
648  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
649  return false;
650 }
651 
653 {
654  char cmd[] = ":SZP#";
655  int errcode = 0;
656  char errmsg[MAXRBUF];
657  char response[8];
658  int nbytes_read = 0;
659  int nbytes_written = 0;
660 
661  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
662 
663  if (ieqpro_simulation)
664  {
665  strcpy(response, "1");
666  nbytes_read = strlen(response);
667  }
668  else
669  {
670  tcflush(fd, TCIFLUSH);
671 
672  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
673  {
674  tty_error_msg(errcode, errmsg, MAXRBUF);
675  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
676  return false;
677  }
678 
679  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
680  {
681  tty_error_msg(errcode, errmsg, MAXRBUF);
682  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
683  return false;
684  }
685  }
686 
687  if (nbytes_read > 0)
688  {
689  response[nbytes_read] = '\0';
690  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
691 
692  tcflush(fd, TCIFLUSH);
693  return true;
694  }
695 
696  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
697  return false;
698 }
699 
701 {
702  char cmd[16];
703  int errcode = 0;
704  char errmsg[MAXRBUF];
705  char response[8];
706  int nbytes_read = 0;
707  int nbytes_written = 0;
708 
709  snprintf(cmd, 16, ":SR%d#", ((int)rate) + 1);
710 
711  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
712 
713  if (ieqpro_simulation)
714  {
715  simInfo.slewRate = rate;
716  strcpy(response, "1");
717  nbytes_read = strlen(response);
718  }
719  else
720  {
721  tcflush(fd, TCIFLUSH);
722 
723  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
724  {
725  tty_error_msg(errcode, errmsg, MAXRBUF);
726  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
727  return false;
728  }
729 
730  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
731  {
732  tty_error_msg(errcode, errmsg, MAXRBUF);
733  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
734  return false;
735  }
736  }
737 
738  if (nbytes_read > 0)
739  {
740  response[nbytes_read] = '\0';
741  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
742 
743  tcflush(fd, TCIFLUSH);
744  return true;
745  }
746 
747  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
748  return false;
749 }
750 
752 {
753  char cmd[16];
754  int errcode = 0;
755  char errmsg[MAXRBUF];
756  char response[8];
757  int nbytes_read = 0;
758  int nbytes_written = 0;
759 
760  switch (rate)
761  {
762  case TR_SIDEREAL:
763  strcpy(cmd, ":RT0#");
764  break;
765  case TR_LUNAR:
766  strcpy(cmd, ":RT1#");
767  break;
768  case TR_SOLAR:
769  strcpy(cmd, ":RT2#");
770  break;
771  case TR_KING:
772  strcpy(cmd, ":RT3#");
773  break;
774  case TR_CUSTOM:
775  strcpy(cmd, ":RT4#");
776  break;
777  }
778 
779  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
780 
781  if (ieqpro_simulation)
782  {
783  simInfo.trackRate = rate;
784  strcpy(response, "1");
785  nbytes_read = strlen(response);
786  }
787  else
788  {
789  tcflush(fd, TCIFLUSH);
790 
791  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
792  {
793  tty_error_msg(errcode, errmsg, MAXRBUF);
794  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
795  return false;
796  }
797 
798  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
799  {
800  tty_error_msg(errcode, errmsg, MAXRBUF);
801  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
802  return false;
803  }
804  }
805 
806  if (nbytes_read > 0)
807  {
808  response[nbytes_read] = '\0';
809  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
810 
811  tcflush(fd, TCIFLUSH);
812  return true;
813  }
814 
815  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
816  return false;
817 }
818 
819 bool set_ieqpro_custom_ra_track_rate(int fd, double rate)
820 {
821  char cmd[16];
822  char sign;
823  int errcode = 0;
824  char errmsg[MAXRBUF];
825  char response[8];
826  int nbytes_read = 0;
827  int nbytes_written = 0;
828 
829  if (rate < 0)
830  sign = '-';
831  else
832  sign = '+';
833 
834  snprintf(cmd, 16, ":RR%c%07.4f#", sign, fabs(rate));
835 
836  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
837 
838  if (ieqpro_simulation)
839  {
840  strcpy(response, "1");
841  nbytes_read = strlen(response);
842  }
843  else
844  {
845  tcflush(fd, TCIFLUSH);
846 
847  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
848  {
849  tty_error_msg(errcode, errmsg, MAXRBUF);
850  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
851  return false;
852  }
853 
854  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
855  {
856  tty_error_msg(errcode, errmsg, MAXRBUF);
857  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
858  return false;
859  }
860  }
861 
862  if (nbytes_read > 0)
863  {
864  response[nbytes_read] = '\0';
865  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
866 
867  tcflush(fd, TCIFLUSH);
868  return true;
869  }
870 
871  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
872  return false;
873 }
874 
875 bool set_ieqpro_custom_de_track_rate(int fd, double rate)
876 {
877  char cmd[16];
878  char sign;
879  int errcode = 0;
880  char errmsg[MAXRBUF];
881  char response[8];
882  int nbytes_read = 0;
883  int nbytes_written = 0;
884 
885  if (rate < 0)
886  sign = '-';
887  else
888  sign = '+';
889 
890  snprintf(cmd, 16, ":RD%c%07.4f#", sign, fabs(rate));
891 
892  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
893 
894  if (ieqpro_simulation)
895  {
896  strcpy(response, "1");
897  nbytes_read = strlen(response);
898  }
899  else
900  {
901  tcflush(fd, TCIFLUSH);
902 
903  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
904  {
905  tty_error_msg(errcode, errmsg, MAXRBUF);
906  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
907  return false;
908  }
909 
910  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
911  {
912  tty_error_msg(errcode, errmsg, MAXRBUF);
913  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
914  return false;
915  }
916  }
917 
918  if (nbytes_read > 0)
919  {
920  response[nbytes_read] = '\0';
921  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
922 
923  tcflush(fd, TCIFLUSH);
924  return true;
925  }
926 
927  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
928  return false;
929 }
930 
931 bool set_ieqpro_guide_rate(int fd, double raRate, double deRate)
932 {
933  char cmd[16] = {0};
934  int errcode = 0;
935  char errmsg[MAXRBUF];
936  char response[8];
937  int nbytes_read = 0;
938  int nbytes_written = 0;
939 
940  snprintf(cmd, 16, ":RG%02d%02d#", static_cast<int>(raRate * 100.0), static_cast<int>(deRate * 100.0));
941 
942  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
943 
944  if (ieqpro_simulation)
945  {
946  simData.ra_guide_rate = raRate;
947  simData.de_guide_rate = deRate;
948  strcpy(response, "1");
949  nbytes_read = strlen(response);
950  }
951  else
952  {
953  tcflush(fd, TCIFLUSH);
954 
955  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
956  {
957  tty_error_msg(errcode, errmsg, MAXRBUF);
958  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
959  return false;
960  }
961 
962  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
963  {
964  tty_error_msg(errcode, errmsg, MAXRBUF);
965  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
966  return false;
967  }
968  }
969 
970  if (nbytes_read > 0)
971  {
972  response[nbytes_read] = '\0';
973  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
974 
975  tcflush(fd, TCIFLUSH);
976  return true;
977  }
978 
979  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
980  return false;
981 }
982 
983 bool get_ieqpro_guide_rate(int fd, double *raRate, double *deRate)
984 {
985  char cmd[] = ":AG#";
986  int errcode = 0;
987  char errmsg[MAXRBUF];
988  char response[8] = {0};
989  int nbytes_read = 0;
990  int nbytes_written = 0;
991 
992  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
993 
994  if (ieqpro_simulation)
995  {
996  snprintf(response, 8, "%02d%02d#", static_cast<int>(simData.ra_guide_rate * 100),
997  static_cast<int>(simData.de_guide_rate * 100));
998  nbytes_read = strlen(response);
999  }
1000  else
1001  {
1002  tcflush(fd, TCIFLUSH);
1003 
1004  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1005  {
1006  tty_error_msg(errcode, errmsg, MAXRBUF);
1007  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1008  return false;
1009  }
1010 
1011  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
1012  {
1013  tty_error_msg(errcode, errmsg, MAXRBUF);
1014  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1015  return false;
1016  }
1017  }
1018 
1019  if (nbytes_read > 0)
1020  {
1021  response[nbytes_read - 1] = '\0';
1022  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1023 
1024  char raRateStr[8] = {0}, deRateStr[8] = {0};
1025  strncpy(response, raRateStr, 2);
1026  strncpy(response + 2, deRateStr, 2);
1027  *raRate = atoi(raRateStr) / 100.0;
1028  *deRate = atoi(deRateStr) / 100.0;
1029  tcflush(fd, TCIFLUSH);
1030  return true;
1031  }
1032 
1033  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1034  return false;
1035 }
1036 
1037 bool start_ieqpro_guide(int fd, IEQ_DIRECTION dir, uint32_t ms)
1038 {
1039  char cmd[16];
1040  int errcode = 0;
1041  char errmsg[MAXRBUF];
1042  int nbytes_written = 0;
1043 
1044  char dir_c = 0;
1045 
1046  switch (dir)
1047  {
1048  case IEQ_N:
1049  dir_c = 'n';
1050  break;
1051 
1052  case IEQ_S:
1053  dir_c = 's';
1054  break;
1055 
1056  case IEQ_W:
1057  dir_c = 'w';
1058  break;
1059 
1060  case IEQ_E:
1061  dir_c = 'e';
1062  break;
1063  }
1064 
1065  snprintf(cmd, 16, ":M%c%05d#", dir_c, ms);
1066 
1067  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1068 
1069  if (ieqpro_simulation)
1070  return true;
1071  else
1072  {
1073  tcflush(fd, TCIFLUSH);
1074 
1075  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1076  {
1077  tty_error_msg(errcode, errmsg, MAXRBUF);
1078  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1079  return false;
1080  }
1081  }
1082 
1083  tcflush(fd, TCIFLUSH);
1084  return true;
1085 }
1086 
1087 bool park_ieqpro(int fd)
1088 {
1089  char cmd[] = ":MP1#";
1090  int errcode = 0;
1091  char errmsg[MAXRBUF];
1092  char response[8];
1093  int nbytes_read = 0;
1094  int nbytes_written = 0;
1095 
1096  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1097 
1098  if (ieqpro_simulation)
1099  {
1100  simInfo.rememberSystemStatus = simInfo.systemStatus;
1102  strcpy(response, "1");
1103  nbytes_read = strlen(response);
1104  }
1105  else
1106  {
1107  tcflush(fd, TCIFLUSH);
1108 
1109  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1110  {
1111  tty_error_msg(errcode, errmsg, MAXRBUF);
1112  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1113  return false;
1114  }
1115 
1116  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1117  {
1118  tty_error_msg(errcode, errmsg, MAXRBUF);
1119  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1120  return false;
1121  }
1122  }
1123 
1124  if (nbytes_read > 0)
1125  {
1126  response[nbytes_read] = '\0';
1127  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1128 
1129  if (!strcmp(response, "1"))
1130  {
1131  tcflush(fd, TCIFLUSH);
1132  return true;
1133  }
1134  else
1135  {
1136  DEBUGDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Error: Requested parking position is below horizon.");
1137  return false;
1138  }
1139  }
1140 
1141  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1142  return false;
1143 }
1144 
1146 {
1147  char cmd[] = ":MP0#";
1148  int errcode = 0;
1149  char errmsg[MAXRBUF];
1150  char response[8];
1151  int nbytes_read = 0;
1152  int nbytes_written = 0;
1153 
1154  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1155 
1156  if (ieqpro_simulation)
1157  {
1159  strcpy(response, "1");
1160  nbytes_read = strlen(response);
1161  }
1162  else
1163  {
1164  tcflush(fd, TCIFLUSH);
1165 
1166  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1167  {
1168  tty_error_msg(errcode, errmsg, MAXRBUF);
1169  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1170  return false;
1171  }
1172 
1173  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1174  {
1175  tty_error_msg(errcode, errmsg, MAXRBUF);
1176  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1177  return false;
1178  }
1179  }
1180 
1181  if (nbytes_read > 0)
1182  {
1183  response[nbytes_read] = '\0';
1184  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1185 
1186  tcflush(fd, TCIFLUSH);
1187  return true;
1188  }
1189 
1190  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1191  return false;
1192 }
1193 
1194 bool abort_ieqpro(int fd)
1195 {
1196  char cmd[] = ":Q#";
1197  int errcode = 0;
1198  char errmsg[MAXRBUF];
1199  char response[8];
1200  int nbytes_read = 0;
1201  int nbytes_written = 0;
1202 
1203  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1204 
1205  if (ieqpro_simulation)
1206  {
1207  if (simInfo.systemStatus == ST_SLEWING)
1208  simInfo.systemStatus = simInfo.rememberSystemStatus;
1209  strcpy(response, "1");
1210  nbytes_read = strlen(response);
1211  }
1212  else
1213  {
1214  tcflush(fd, TCIFLUSH);
1215 
1216  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1217  {
1218  tty_error_msg(errcode, errmsg, MAXRBUF);
1219  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1220  return false;
1221  }
1222 
1223  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1224  {
1225  tty_error_msg(errcode, errmsg, MAXRBUF);
1226  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1227  return false;
1228  }
1229  }
1230 
1231  if (nbytes_read > 0)
1232  {
1233  response[nbytes_read] = '\0';
1234  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1235 
1236  tcflush(fd, TCIFLUSH);
1237  return true;
1238  }
1239 
1240  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1241  return false;
1242 }
1243 
1244 bool slew_ieqpro(int fd)
1245 {
1246  char cmd[] = ":MS#";
1247  int errcode = 0;
1248  char errmsg[MAXRBUF];
1249  char response[8];
1250  int nbytes_read = 0;
1251  int nbytes_written = 0;
1252 
1253  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1254 
1255  if (ieqpro_simulation)
1256  {
1257  simInfo.rememberSystemStatus = simInfo.systemStatus;
1258  simInfo.systemStatus = ST_SLEWING;
1259  strcpy(response, "1");
1260  nbytes_read = strlen(response);
1261  }
1262  else
1263  {
1264  tcflush(fd, TCIFLUSH);
1265 
1266  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1267  {
1268  tty_error_msg(errcode, errmsg, MAXRBUF);
1269  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1270  return false;
1271  }
1272 
1273  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1274  {
1275  tty_error_msg(errcode, errmsg, MAXRBUF);
1276  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1277  return false;
1278  }
1279  }
1280 
1281  if (nbytes_read > 0)
1282  {
1283  response[nbytes_read] = '\0';
1284  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1285 
1286  if (!strcmp(response, "1"))
1287  {
1288  tcflush(fd, TCIFLUSH);
1289  return true;
1290  }
1291  else
1292  {
1293  DEBUGDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Requested object is below horizon.");
1294  tcflush(fd, TCIFLUSH);
1295  return false;
1296  }
1297  }
1298 
1299  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1300  return false;
1301 }
1302 
1303 bool sync_ieqpro(int fd)
1304 {
1305  char cmd[] = ":CM#";
1306  int errcode = 0;
1307  char errmsg[MAXRBUF];
1308  char response[8];
1309  int nbytes_read = 0;
1310  int nbytes_written = 0;
1311 
1312  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1313 
1314  if (ieqpro_simulation)
1315  {
1316  strcpy(response, "1");
1317  nbytes_read = strlen(response);
1318  }
1319  else
1320  {
1321  tcflush(fd, TCIFLUSH);
1322 
1323  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1324  {
1325  tty_error_msg(errcode, errmsg, MAXRBUF);
1326  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1327  return false;
1328  }
1329 
1330  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1331  {
1332  tty_error_msg(errcode, errmsg, MAXRBUF);
1333  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1334  return false;
1335  }
1336  }
1337 
1338  if (nbytes_read > 0)
1339  {
1340  response[nbytes_read] = '\0';
1341  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1342 
1343  tcflush(fd, TCIFLUSH);
1344  return true;
1345  }
1346 
1347  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1348  return false;
1349 }
1350 
1351 bool set_ieqpro_track_enabled(int fd, bool enabled)
1352 {
1353  char cmd[32];
1354  int errcode = 0;
1355  char errmsg[MAXRBUF];
1356  char response[8];
1357  int nbytes_read = 0;
1358  int nbytes_written = 0;
1359 
1360  snprintf(cmd, 32, ":ST%d#", enabled ? 1 : 0);
1361 
1362  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1363 
1364  if (ieqpro_simulation)
1365  {
1366  simInfo.systemStatus = enabled ? ST_TRACKING_PEC_ON : ST_STOPPED;
1367  strcpy(response, "1");
1368  nbytes_read = strlen(response);
1369  }
1370  else
1371  {
1372  tcflush(fd, TCIFLUSH);
1373 
1374  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1375  {
1376  tty_error_msg(errcode, errmsg, MAXRBUF);
1377  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1378  return false;
1379  }
1380 
1381  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1382  {
1383  tty_error_msg(errcode, errmsg, MAXRBUF);
1384  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1385  return false;
1386  }
1387  }
1388 
1389  if (nbytes_read > 0)
1390  {
1391  response[nbytes_read] = '\0';
1392  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1393 
1394  tcflush(fd, TCIFLUSH);
1395  return true;
1396  }
1397 
1398  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1399  return false;
1400 }
1401 
1402 bool set_ieqpro_ra(int fd, double ra)
1403 {
1404  char cmd[32];
1405  int errcode = 0;
1406  char errmsg[MAXRBUF];
1407  char response[8];
1408  int nbytes_read = 0;
1409  int nbytes_written = 0;
1410 
1411  // Send as milliseconds resolution
1412  int ieqValue = ra * 60 * 60 * 1000;
1413 
1414  snprintf(cmd, 32, ":Sr%08d#", ieqValue);
1415 
1416  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1417 
1418  if (ieqpro_simulation)
1419  {
1420  simData.ra = ra;
1421  strcpy(response, "1");
1422  nbytes_read = strlen(response);
1423  }
1424  else
1425  {
1426  tcflush(fd, TCIFLUSH);
1427 
1428  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1429  {
1430  tty_error_msg(errcode, errmsg, MAXRBUF);
1431  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1432  return false;
1433  }
1434 
1435  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1436  {
1437  tty_error_msg(errcode, errmsg, MAXRBUF);
1438  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1439  return false;
1440  }
1441  }
1442 
1443  if (nbytes_read > 0)
1444  {
1445  response[nbytes_read] = '\0';
1446  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1447 
1448  tcflush(fd, TCIFLUSH);
1449  return true;
1450  }
1451 
1452  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1453  return false;
1454 }
1455 
1456 bool set_ieqpro_dec(int fd, double dec)
1457 {
1458  char cmd[32];
1459  char sign;
1460  int errcode = 0;
1461  char errmsg[MAXRBUF];
1462  char response[8];
1463  int nbytes_read = 0;
1464  int nbytes_written = 0;
1465 
1466  if (dec >= 0)
1467  sign = '+';
1468  else
1469  sign = '-';
1470 
1471  // Send as 0.01 arcseconds resolution
1472  int ieqValue = fabs(dec) * 60 * 60 * 100;
1473 
1474  snprintf(cmd, 32, ":Sd%c%08d#", sign, ieqValue);
1475 
1476  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1477 
1478  if (ieqpro_simulation)
1479  {
1480  simData.dec = dec;
1481  strcpy(response, "1");
1482  nbytes_read = strlen(response);
1483  }
1484  else
1485  {
1486  tcflush(fd, TCIFLUSH);
1487 
1488  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1489  {
1490  tty_error_msg(errcode, errmsg, MAXRBUF);
1491  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1492  return false;
1493  }
1494 
1495  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1496  {
1497  tty_error_msg(errcode, errmsg, MAXRBUF);
1498  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1499  return false;
1500  }
1501  }
1502 
1503  if (nbytes_read > 0)
1504  {
1505  response[nbytes_read] = '\0';
1506  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1507 
1508  tcflush(fd, TCIFLUSH);
1509  return true;
1510  }
1511 
1512  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1513  return false;
1514 }
1515 
1516 bool set_ieqpro_longitude(int fd, double longitude)
1517 {
1518  char cmd[16];
1519  char sign;
1520  int errcode = 0;
1521  char errmsg[MAXRBUF];
1522  char response[8];
1523  int nbytes_read = 0;
1524  int nbytes_written = 0;
1525 
1526  if (longitude >= 0)
1527  sign = '+';
1528  else
1529  sign = '-';
1530 
1531  int longitude_arcsecs = fabs(longitude) * 60 * 60;
1532  snprintf(cmd, 16, ":Sg%c%06d#", sign, longitude_arcsecs);
1533 
1534  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1535 
1536  if (ieqpro_simulation)
1537  {
1538  strcpy(response, "1");
1539  nbytes_read = strlen(response);
1540  }
1541  else
1542  {
1543  tcflush(fd, TCIFLUSH);
1544 
1545  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1546  {
1547  tty_error_msg(errcode, errmsg, MAXRBUF);
1548  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1549  return false;
1550  }
1551 
1552  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1553  {
1554  tty_error_msg(errcode, errmsg, MAXRBUF);
1555  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1556  return false;
1557  }
1558  }
1559 
1560  if (nbytes_read > 0)
1561  {
1562  response[nbytes_read] = '\0';
1563  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1564 
1565  tcflush(fd, TCIFLUSH);
1566  return true;
1567  }
1568 
1569  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1570  return false;
1571 }
1572 
1573 bool set_ieqpro_latitude(int fd, double latitude)
1574 {
1575  char cmd[16];
1576  char sign;
1577  int errcode = 0;
1578  char errmsg[MAXRBUF];
1579  char response[8];
1580  int nbytes_read = 0;
1581  int nbytes_written = 0;
1582 
1583  if (latitude >= 0)
1584  sign = '+';
1585  else
1586  sign = '-';
1587 
1588  int latitude_arcsecs = fabs(latitude) * 60 * 60;
1589  snprintf(cmd, 16, ":St%c%06d#", sign, latitude_arcsecs);
1590 
1591  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1592 
1593  if (ieqpro_simulation)
1594  {
1595  strcpy(response, "1");
1596  nbytes_read = strlen(response);
1597  }
1598  else
1599  {
1600  tcflush(fd, TCIFLUSH);
1601 
1602  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1603  {
1604  tty_error_msg(errcode, errmsg, MAXRBUF);
1605  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1606  return false;
1607  }
1608 
1609  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1610  {
1611  tty_error_msg(errcode, errmsg, MAXRBUF);
1612  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1613  return false;
1614  }
1615  }
1616 
1617  if (nbytes_read > 0)
1618  {
1619  response[nbytes_read] = '\0';
1620  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1621 
1622  tcflush(fd, TCIFLUSH);
1623  return true;
1624  }
1625 
1626  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1627  return false;
1628 }
1629 
1630 bool get_ieqpro_longitude(int fd, double *longitude)
1631 {
1632  char cmd[16];
1633  int errcode = 0;
1634  char errmsg[MAXRBUF];
1635  char response[8];
1636  int nbytes_read = 0;
1637  int nbytes_written = 0;
1638 
1639  strcpy(cmd, ":Gg#");
1640 
1641  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1642 
1643  if (ieqpro_simulation)
1644  {
1645  strcpy(response, "+172800");
1646  nbytes_read = strlen(response);
1647  }
1648  else
1649  {
1650  tcflush(fd, TCIFLUSH);
1651 
1652  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1653  {
1654  tty_error_msg(errcode, errmsg, MAXRBUF);
1655  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1656  return false;
1657  }
1658  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
1659  {
1660  tty_error_msg(errcode, errmsg, MAXRBUF);
1661  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1662  return false;
1663  }
1664  }
1665 
1666  if (nbytes_read > 0)
1667  {
1668  response[nbytes_read - 1] = '\0';
1669  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1670 
1671  tcflush(fd, TCIFLUSH);
1672 
1673  int longitude_arcsecs = 0;
1674 
1675  if (sscanf(response, "%d", &longitude_arcsecs) > 0)
1676  {
1677  *longitude = longitude_arcsecs / 3600.0;
1678  return true;
1679  }
1680 
1681  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Error: Malformed result (%s).", response);
1682  return false;
1683  }
1684 
1685  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 8.", nbytes_read);
1686  return false;
1687 }
1688 
1689 bool get_ieqpro_latitude(int fd, double *latitude)
1690 {
1691  char cmd[16];
1692  int errcode = 0;
1693  char errmsg[MAXRBUF];
1694  char response[8];
1695  int nbytes_read = 0;
1696  int nbytes_written = 0;
1697 
1698  strcpy(cmd, ":Gt#");
1699 
1700  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1701 
1702  if (ieqpro_simulation)
1703  {
1704  strcpy(response, "+106200");
1705  nbytes_read = strlen(response);
1706  }
1707  else
1708  {
1709  tcflush(fd, TCIFLUSH);
1710 
1711  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1712  {
1713  tty_error_msg(errcode, errmsg, MAXRBUF);
1714  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1715  return false;
1716  }
1717  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
1718  {
1719  tty_error_msg(errcode, errmsg, MAXRBUF);
1720  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1721  return false;
1722  }
1723  }
1724 
1725  if (nbytes_read > 0)
1726  {
1727  response[nbytes_read - 1] = '\0';
1728  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1729 
1730  tcflush(fd, TCIFLUSH);
1731 
1732  int latitude_arcsecs = 0;
1733 
1734  if (sscanf(response, "%d", &latitude_arcsecs) > 0)
1735  {
1736  *latitude = latitude_arcsecs / 3600.0;
1737  return true;
1738  }
1739 
1740  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Error: Malformed result (%s).", response);
1741  return false;
1742  }
1743 
1744  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 8.", nbytes_read);
1745  return false;
1746 }
1747 
1748 bool set_ieqpro_local_date(int fd, int yy, int mm, int dd)
1749 {
1750  char cmd[16];
1751  int errcode = 0;
1752  char errmsg[MAXRBUF];
1753  char response[8];
1754  int nbytes_read = 0;
1755  int nbytes_written = 0;
1756 
1757  snprintf(cmd, 16, ":SC%02d%02d%02d#", yy, mm, dd);
1758 
1759  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1760 
1761  if (ieqpro_simulation)
1762  {
1763  strcpy(response, "1");
1764  nbytes_read = strlen(response);
1765  }
1766  else
1767  {
1768  tcflush(fd, TCIFLUSH);
1769 
1770  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1771  {
1772  tty_error_msg(errcode, errmsg, MAXRBUF);
1773  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1774  return false;
1775  }
1776 
1777  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1778  {
1779  tty_error_msg(errcode, errmsg, MAXRBUF);
1780  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1781  return false;
1782  }
1783  }
1784 
1785  if (nbytes_read > 0)
1786  {
1787  response[nbytes_read] = '\0';
1788  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1789 
1790  tcflush(fd, TCIFLUSH);
1791  return true;
1792  }
1793 
1794  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1795  return false;
1796 }
1797 
1798 bool set_ieqpro_local_time(int fd, int hh, int mm, int ss)
1799 {
1800  char cmd[16];
1801  int errcode = 0;
1802  char errmsg[MAXRBUF];
1803  char response[8];
1804  int nbytes_read = 0;
1805  int nbytes_written = 0;
1806 
1807  snprintf(cmd, 16, ":SL%02d%02d%02d#", hh, mm, ss);
1808 
1809  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1810 
1811  if (ieqpro_simulation)
1812  {
1813  strcpy(response, "1");
1814  nbytes_read = strlen(response);
1815  }
1816  else
1817  {
1818  tcflush(fd, TCIFLUSH);
1819 
1820  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1821  {
1822  tty_error_msg(errcode, errmsg, MAXRBUF);
1823  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1824  return false;
1825  }
1826 
1827  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1828  {
1829  tty_error_msg(errcode, errmsg, MAXRBUF);
1830  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1831  return false;
1832  }
1833  }
1834 
1835  if (nbytes_read > 0)
1836  {
1837  response[nbytes_read] = '\0';
1838  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1839 
1840  tcflush(fd, TCIFLUSH);
1841  return true;
1842  }
1843 
1844  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1845  return false;
1846 }
1847 
1848 bool set_ieqpro_daylight_saving(int fd, bool enabled)
1849 {
1850  char cmd[16];
1851  int errcode = 0;
1852  char errmsg[MAXRBUF];
1853  char response[8];
1854  int nbytes_read = 0;
1855  int nbytes_written = 0;
1856 
1857  if (enabled)
1858  strcpy(cmd, ":SDS1#");
1859  else
1860  strcpy(cmd, ":SDS0#");
1861 
1862  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1863 
1864  if (ieqpro_simulation)
1865  {
1866  strcpy(response, "1");
1867  nbytes_read = strlen(response);
1868  }
1869  else
1870  {
1871  tcflush(fd, TCIFLUSH);
1872 
1873  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1874  {
1875  tty_error_msg(errcode, errmsg, MAXRBUF);
1876  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1877  return false;
1878  }
1879 
1880  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1881  {
1882  tty_error_msg(errcode, errmsg, MAXRBUF);
1883  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1884  return false;
1885  }
1886  }
1887 
1888  if (nbytes_read > 0)
1889  {
1890  response[nbytes_read] = '\0';
1891  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1892 
1893  tcflush(fd, TCIFLUSH);
1894  return true;
1895  }
1896 
1897  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1898  return false;
1899 }
1900 
1901 bool set_ieqpro_utc_offset(int fd, double offset)
1902 {
1903  char cmd[16];
1904  char sign;
1905  int errcode = 0;
1906  char errmsg[MAXRBUF];
1907  char response[8];
1908  int nbytes_read = 0;
1909  int nbytes_written = 0;
1910 
1911  if (offset >= 0)
1912  sign = '+';
1913  else
1914  sign = '-';
1915 
1916  int offset_minutes = fabs(offset) * 60.0;
1917 
1918  snprintf(cmd, 16, ":SG%c%03d#", sign, offset_minutes);
1919 
1920  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
1921 
1922  if (ieqpro_simulation)
1923  {
1924  strcpy(response, "1");
1925  nbytes_read = strlen(response);
1926  }
1927  else
1928  {
1929  tcflush(fd, TCIFLUSH);
1930 
1931  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1932  {
1933  tty_error_msg(errcode, errmsg, MAXRBUF);
1934  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1935  return false;
1936  }
1937 
1938  if ((errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))
1939  {
1940  tty_error_msg(errcode, errmsg, MAXRBUF);
1941  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1942  return false;
1943  }
1944  }
1945 
1946  if (nbytes_read > 0)
1947  {
1948  response[nbytes_read] = '\0';
1949  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
1950 
1951  tcflush(fd, TCIFLUSH);
1952  return true;
1953  }
1954 
1955  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
1956  return false;
1957 }
1958 
1959 bool get_ieqpro_coords(int fd, double *ra, double *dec)
1960 {
1961  char cmd[] = ":GEC#";
1962  int errcode = 0;
1963  char errmsg[MAXRBUF];
1964  char response[32];
1965  int nbytes_read = 0;
1966  int nbytes_written = 0;
1967 
1968  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_EXTRA_1, "CMD <%s>", cmd);
1969 
1970  if (ieqpro_simulation)
1971  {
1972  char ra_str[16], dec_str[16];
1973 
1974  char sign;
1975  if (simData.dec >= 0)
1976  sign = '+';
1977  else
1978  sign = '-';
1979 
1980  int ieqDEC = fabs(simData.dec) * 60 * 60 * 100;
1981 
1982  snprintf(dec_str, 16, "%c%08d", sign, ieqDEC);
1983 
1984  int ieqRA = simData.ra * 60 * 60 * 1000;
1985  snprintf(ra_str, 16, "%08d", ieqRA);
1986 
1987  snprintf(response, 32, "%s%s#", dec_str, ra_str);
1988  nbytes_read = strlen(response);
1989  }
1990  else
1991  {
1992  tcflush(fd, TCIFLUSH);
1993 
1994  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
1995  {
1996  tty_error_msg(errcode, errmsg, MAXRBUF);
1997  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
1998  return false;
1999  }
2000 
2001  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
2002  {
2003  tty_error_msg(errcode, errmsg, MAXRBUF);
2004  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
2005  return false;
2006  }
2007  }
2008 
2009  if (nbytes_read > 0)
2010  {
2011  tcflush(fd, TCIFLUSH);
2012  response[nbytes_read] = '\0';
2013  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_EXTRA_1, "RES <%s>", response);
2014 
2015  char ra_str[16] = {0}, dec_str[16] = {0};
2016 
2017  strncpy(dec_str, response, 9);
2018  strncpy(ra_str, response + 9, 8);
2019 
2020  int ieqDEC = atoi(dec_str);
2021  int ieqRA = atoi(ra_str);
2022 
2023  *ra = ieqRA / (60.0 * 60.0 * 1000.0);
2024  *dec = ieqDEC / (60.0 * 60.0 * 100.0);
2025 
2026  return true;
2027  }
2028 
2029  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
2030  return false;
2031 }
2032 
2033 bool get_ieqpro_utc_date_time(int fd, double *utc_hours, int *yy, int *mm, int *dd, int *hh, int *minute, int *ss)
2034 {
2035  char cmd[] = ":GLT#";
2036  int errcode = 0;
2037  char errmsg[MAXRBUF];
2038  char response[32];
2039  int nbytes_read = 0;
2040  int nbytes_written = 0;
2041 
2042  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD <%s>", cmd);
2043 
2044  // Format according to Manual is sMMMYYMMDDHHMMSS#
2045  // However as pointed out by user Shepherd on INDI forums, actual format is
2046  // sMMMxYYMMDDHHMMSS#
2047  // Where x is either 0 or 1 denoting daying savings
2048  if (ieqpro_simulation)
2049  {
2050  strncpy(response, "+1800150321173000#", 32);
2051  nbytes_read = strlen(response);
2052  }
2053  else
2054  {
2055  tcflush(fd, TCIFLUSH);
2056 
2057  if ((errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
2058  {
2059  tty_error_msg(errcode, errmsg, MAXRBUF);
2060  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
2061  return false;
2062  }
2063 
2064  if ((errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
2065  {
2066  tty_error_msg(errcode, errmsg, MAXRBUF);
2067  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
2068  return false;
2069  }
2070  }
2071 
2072  if (nbytes_read > 0)
2073  {
2074  tcflush(fd, TCIFLUSH);
2075  response[nbytes_read] = '\0';
2076  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES <%s>", response);
2077 
2078  char utc_str[8] = {0}, yy_str[8] = {0}, mm_str[8] = {0}, dd_str[8] = {0}, hh_str[8] = {0}, minute_str[8] = {0}, ss_str[8] = {0},
2079  dst_str[8] = {0};
2080 
2081  // UTC Offset
2082  strncpy(utc_str, response, 4);
2083  // Daylight savings
2084  strncpy(dst_str, response + 4, 1);
2085  // Year
2086  strncpy(yy_str, response + 5, 2);
2087  // Month
2088  strncpy(mm_str, response + 7, 2);
2089  // Day
2090  strncpy(dd_str, response + 9, 2);
2091  // Hour
2092  strncpy(hh_str, response + 11, 2);
2093  // Minute
2094  strncpy(minute_str, response + 13, 2);
2095  // Second
2096  strncpy(ss_str, response + 15, 2);
2097 
2098  *utc_hours = atoi(utc_str) / 60.0;
2099  *yy = atoi(yy_str) + 2000;
2100  //*mm = atoi(mm_str) + 1;
2101  *mm = atoi(mm_str);
2102  *dd = atoi(dd_str);
2103  *hh = atoi(hh_str);
2104  *minute = atoi(minute_str);
2105  *ss = atoi(ss_str);
2106 
2107  ln_zonedate localTime;
2108  ln_date utcTime;
2109 
2110  localTime.years = *yy;
2111  localTime.months = *mm;
2112  localTime.days = *dd;
2113  localTime.hours = *hh;
2114  localTime.minutes = *minute;
2115  localTime.seconds = *ss;
2116  localTime.gmtoff = *utc_hours * 3600;
2117 
2118  ln_zonedate_to_date(&localTime, &utcTime);
2119 
2120  *yy = utcTime.years;
2121  *mm = utcTime.months;
2122  *dd = utcTime.days;
2123  *hh = utcTime.hours;
2124  *minute = utcTime.minutes;
2125  *ss = utcTime.seconds;
2126 
2127  return true;
2128  }
2129 
2130  DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);
2131  return false;
2132 }
bool set_ieqpro_custom_de_track_rate(int fd, double rate)
double ra_guide_rate
bool goto_ieqpro_home(int fd)
bool set_ieqpro_latitude(int fd, double latitude)
bool sync_ieqpro(int fd)
bool set_ieqpro_current_home(int fd)
void set_sim_gps_status(IEQ_GPS_STATUS value)
bool start_ieqpro_guide(int fd, IEQ_DIRECTION dir, uint32_t ms)
void set_sim_dec(double dec)
bool get_ieqpro_main_firmware(int fd, FirmwareInfo *info)
bool find_ieqpro_home(int fd)
bool slew_ieqpro(int fd)
void set_sim_hemisphere(IEQ_HEMISPHERE value)
bool set_ieqpro_local_date(int fd, int yy, int mm, int dd)
bool get_ieqpro_utc_date_time(int fd, double *utc_hours, int *yy, int *mm, int *dd, int *hh, int *minute, int *ss)
bool get_ieqpro_status(int fd, IEQInfo *info)
bool set_ieqpro_daylight_saving(int fd, bool enabled)
bool set_ieqpro_local_time(int fd, int hh, int mm, int ss)
void set_ieqpro_debug(bool enable)
bool get_ieqpro_coords(int fd, double *ra, double *dec)
bool park_ieqpro(int fd)
double ra
void set_sim_guide_rate(double ra, double de)
bool get_ieqpro_radec_firmware(int fd, FirmwareInfo *info)
void set_ieqpro_device(const char *name)
void set_ieqpro_simulation(bool enable)
#define IEQPRO_TIMEOUT
bool get_ieqpro_firmware(int fd, FirmwareInfo *info)
bool set_ieqpro_custom_ra_track_rate(int fd, double rate)
bool set_ieqpro_dec(int fd, double dec)
bool set_ieqpro_guide_rate(int fd, double raRate, double deRate)
bool abort_ieqpro(int fd)
bool unpark_ieqpro(int fd)
bool set_ieqpro_track_mode(int fd, IEQ_TRACK_RATE rate)
void set_sim_system_status(IEQ_SYSTEM_STATUS value)
bool get_ieqpro_model(int fd, FirmwareInfo *info)
void set_sim_slew_rate(IEQ_SLEW_RATE value)
bool get_ieqpro_latitude(int fd, double *latitude)
bool check_ieqpro_connection(int fd)
double dec
bool set_ieqpro_ra(int fd, double ra)
bool set_ieqpro_slew_rate(int fd, IEQ_SLEW_RATE rate)
bool get_ieqpro_guide_rate(int fd, double *raRate, double *deRate)
bool start_ieqpro_motion(int fd, IEQ_DIRECTION dir)
void set_sim_time_source(IEQ_TIME_SOURCE value)
bool set_ieqpro_utc_offset(int fd, double offset)
bool set_ieqpro_longitude(int fd, double longitude)
struct @165 simData
bool get_ieqpro_longitude(int fd, double *longitude)
void set_sim_ra(double ra)
bool set_ieqpro_track_enabled(int fd, bool enabled)
bool stop_ieqpro_motion(int fd, IEQ_DIRECTION dir)
double de_guide_rate
void set_sim_track_rate(IEQ_TRACK_RATE value)
IEQ_TRACK_RATE
@ TR_SIDEREAL
@ TR_LUNAR
@ TR_KING
@ TR_SOLAR
@ TR_CUSTOM
IEQ_TIME_SOURCE
IEQ_HEMISPHERE
IEQ_SLEW_RATE
IEQ_DIRECTION
@ IEQ_E
@ IEQ_S
@ IEQ_N
@ IEQ_W
IEQ_GPS_STATUS
IEQ_SYSTEM_STATUS
@ ST_TRACKING_PEC_ON
#define MAXINDIDEVICE
Definition: indiapi.h:193
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition: indicom.c:566
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition: indicom.c:424
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:482
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition: indicom.c:1167
Implementations for common driver routines.
@ TTY_OK
Definition: indicom.h:150
#define DEBUGDEVICE(device, priority, msg)
Definition: indilogger.h:60
#define DEBUGFDEVICE(device, priority, msg,...)
Definition: indilogger.h:61
#define MAXRBUF
Definition: indiserver.cpp:102
int fd
Definition: intelliscope.c:43
@ ST_SLEWING
Definition: ieqdriverbase.h:35
@ ST_STOPPED
Definition: ieqdriverbase.h:33
__u8 cmd[4]
Definition: pwc-ioctl.h:2
std::string RAFirmware
std::string ControllerFirmware
std::string Model
std::string DEFirmware
std::string MainBoardFirmware
IEQ_GPS_STATUS gpsStatus
IEQ_SYSTEM_STATUS rememberSystemStatus
IEQ_SLEW_RATE slewRate
IEQ_TIME_SOURCE timeSource
IEQ_SYSTEM_STATUS systemStatus
IEQ_TRACK_RATE trackRate
IEQ_HEMISPHERE hemisphere