source: BAORadio/libindi/libindi/drivers/telescope/ieq45.cpp @ 646

Last change on this file since 646 was 646, checked in by frichard, 12 years ago
File size: 23.5 KB
Line 
1#if 0
2    IEQ45 Basic Driver
3    Copyright (C) 2011 Nacho Mas (mas.ignacio@gmail.com). Only litle changes
4    from lx200basic made it by Jasem Mutlaq (mutlaqja@ikarustech.com)
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#endif
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <stdarg.h>
26#include <math.h>
27#include <unistd.h>
28#include <time.h>
29#include <memory>
30
31#include <config.h>
32
33/* INDI Common Library Routines */
34#include "indicom.h"
35
36/* IEQ45 Command Set */
37#include "ieq45driver.h"
38
39/* Our driver header */
40#include "ieq45.h"
41
42using namespace std;
43
44/* Our telescope auto pointer */
45auto_ptr<IEQ45Basic> telescope(0);
46
47const int POLLMS = 100;                         // Period of update, 1 second.
48const char *mydev = "IEQ45";                            // Name of our device.
49
50const char *BASIC_GROUP    = "Main Control";            // Main Group
51const char *OPTIONS_GROUP  = "Options";                 // Options Group
52
53/* Handy Macros */
54#define currentRA       EquatorialCoordsRN[0].value
55#define currentDEC      EquatorialCoordsRN[1].value
56#define targetRA        EquatorialCoordsWN[0].value
57#define targetDEC       EquatorialCoordsWN[1].value
58
59static void ISPoll(void *);
60static void retry_connection(void *);
61
62/**************************************************************************************
63** Send client definitions of all properties.
64***************************************************************************************/
65void ISInit()
66{
67 static int isInit=0;
68
69 if (isInit)
70  return;
71
72 if (telescope.get() == 0) telescope.reset(new IEQ45Basic());
73
74 isInit = 1;
75 
76 IEAddTimer (POLLMS, ISPoll, NULL);
77}
78
79/**************************************************************************************
80**
81***************************************************************************************/
82void ISGetProperties (const char *dev)
83{
84 ISInit(); 
85 telescope->ISGetProperties(dev);
86}
87
88/**************************************************************************************
89**
90***************************************************************************************/
91void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
92{
93 ISInit();
94 telescope->ISNewSwitch(dev, name, states, names, n);
95}
96
97/**************************************************************************************
98**
99***************************************************************************************/
100void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
101{
102 ISInit();
103 telescope->ISNewText(dev, name, texts, names, n);
104}
105
106/**************************************************************************************
107**
108***************************************************************************************/
109void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
110{
111 ISInit();
112 telescope->ISNewNumber(dev, name, values, names, n);
113}
114
115/**************************************************************************************
116**
117***************************************************************************************/
118void ISPoll (void *p)
119{
120 INDI_UNUSED(p);
121
122 telescope->ISPoll(); 
123 IEAddTimer (POLLMS, ISPoll, NULL);
124}
125
126/**************************************************************************************
127**
128***************************************************************************************/
129void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
130{
131  INDI_UNUSED(dev);
132  INDI_UNUSED(name);
133  INDI_UNUSED(sizes);
134  INDI_UNUSED(blobsizes);
135  INDI_UNUSED(blobs);
136  INDI_UNUSED(formats);
137  INDI_UNUSED(names);
138  INDI_UNUSED(n);
139}
140
141/**************************************************************************************
142**
143***************************************************************************************/
144void ISSnoopDevice (XMLEle *root) 
145{
146  INDI_UNUSED(root);
147}
148
149/**************************************************************************************
150** IEQ45 Basic constructor
151***************************************************************************************/
152IEQ45Basic::IEQ45Basic()
153{
154   init_properties();
155
156   lastSet        = -1;
157   fd             = -1;
158   simulation     = false;
159   lastRA         = 0;
160   lastDEC        = 0;
161   currentSet     = 0;
162
163   IDLog("Initilizing from IEQ45 device...\n");
164   IDLog("Driver Version: 0.1 (2011-11-07)\n");
165 
166   enable_simulation(false); 
167
168 }
169
170/**************************************************************************************
171**
172***************************************************************************************/
173IEQ45Basic::~IEQ45Basic()
174{
175
176}
177
178/**************************************************************************************
179** Initialize all properties & set default values.
180***************************************************************************************/
181void IEQ45Basic::init_properties()
182{
183    // Connection
184    IUFillSwitch(&ConnectS[0], "CONNECT", "Connect", ISS_OFF);
185    IUFillSwitch(&ConnectS[1], "DISCONNECT", "Disconnect", ISS_ON);
186    IUFillSwitchVector(&ConnectSP, ConnectS, NARRAY(ConnectS), mydev, "CONNECTION", "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
187
188    // Coord Set
189    IUFillSwitch(&OnCoordSetS[0], "SLEW", "Slew", ISS_ON);
190    IUFillSwitch(&OnCoordSetS[1], "SYNC", "Sync", ISS_OFF);
191    IUFillSwitchVector(&OnCoordSetSP, OnCoordSetS, NARRAY(OnCoordSetS), mydev, "ON_COORD_SET", "On Set", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
192
193    //Track MODE
194    IUFillSwitch(&TrackModeS[0],"SIDERAL", "Sideral", ISS_ON);
195    IUFillSwitch(&TrackModeS[1],"LUNAR","Lunar", ISS_OFF);
196    IUFillSwitch(&TrackModeS[2],"SOLAR", "Solar", ISS_OFF);
197    IUFillSwitch(&TrackModeS[3],"ZERO", "Stop", ISS_OFF);
198    IUFillSwitchVector(&TrackModeSP, TrackModeS, NARRAY(TrackModeS), mydev, "TRACK_MODE", "Track Mode", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
199
200    // Abort
201    IUFillSwitch(&AbortSlewS[0], "ABORT", "Abort", ISS_OFF);
202    IUFillSwitchVector(&AbortSlewSP, AbortSlewS, NARRAY(AbortSlewS), mydev, "ABORT_MOTION", "Abort Slew/Track", BASIC_GROUP, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
203
204    // Port
205    IUFillText(&PortT[0], "PORT", "Port", "/dev/ttyS0");
206    IUFillTextVector(&PortTP, PortT, NARRAY(PortT), mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
207
208    // Equatorial Coords - SET
209    IUFillNumber(&EquatorialCoordsWN[0], "RA", "RA  H:M:S", "%10.6m",  0., 24., 0., 0.);
210    IUFillNumber(&EquatorialCoordsWN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.);
211    IUFillNumberVector(&EquatorialCoordsWNP, EquatorialCoordsWN, NARRAY(EquatorialCoordsWN), mydev, "EQUATORIAL_EOD_COORD_REQUEST" , "Equatorial JNow", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
212
213    // Equatorial Coords - READ
214    IUFillNumber(&EquatorialCoordsRN[0], "RA", "RA  H:M:S", "%10.6m",  0., 24., 0., 0.);
215    IUFillNumber(&EquatorialCoordsRN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.);
216    IUFillNumberVector(&EquatorialCoordsRNP, EquatorialCoordsRN, NARRAY(EquatorialCoordsRN), mydev, "EQUATORIAL_EOD_COORD" , "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE);
217
218}
219
220/**************************************************************************************
221** Define IEQ45 Basic properties to clients.
222***************************************************************************************/
223void IEQ45Basic::ISGetProperties(const char *dev)
224{
225
226 if (dev && strcmp (mydev, dev))
227    return;
228
229  // Main Control
230  IDDefSwitch(&ConnectSP, NULL);
231  IDDefText(&PortTP, NULL);
232  IDDefNumber(&EquatorialCoordsWNP, NULL);
233  IDDefNumber(&EquatorialCoordsRNP, NULL);
234  IDDefSwitch(&OnCoordSetSP, NULL);
235  IDDefSwitch(&TrackModeSP, NULL);
236  IDDefSwitch(&AbortSlewSP, NULL);
237
238
239 
240}
241
242/**************************************************************************************
243** Process Text properties
244***************************************************************************************/
245void IEQ45Basic::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
246{
247        // Ignore if not ours
248        if (strcmp (dev, mydev))
249            return;
250
251        // ===================================
252        // Port Name
253        // ===================================
254        if (!strcmp(name, PortTP.name) )
255        {
256          if (IUUpdateText(&PortTP, texts, names, n) < 0)
257                return;
258
259          PortTP.s = IPS_OK;
260          IDSetText (&PortTP, NULL);
261          return;
262        }
263
264        if (is_connected() == false)
265        {
266                IDMessage(mydev, "IEQ45 is offline. Please connect before issuing any commands.");
267                reset_all_properties();
268                return;
269        }
270
271}
272
273/**************************************************************************************
274**
275***************************************************************************************/
276void IEQ45Basic::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
277{
278       
279        // Ignore if not ours
280        if (strcmp (dev, mydev))
281            return;
282
283        if (is_connected() == false)
284        {
285                IDMessage(mydev, "IEQ45 is offline. Please connect before issuing any commands.");
286                reset_all_properties();
287                return;
288        }
289
290        // ===================================
291        // Equatorial Coords
292        // ===================================
293        if (!strcmp (name, EquatorialCoordsWNP.name))
294        {
295          int i=0, nset=0, error_code=0;
296          double newRA =0, newDEC =0;
297
298            for (nset = i = 0; i < n; i++)
299            {
300                INumber *eqp = IUFindNumber (&EquatorialCoordsWNP, names[i]);
301                if (eqp == &EquatorialCoordsWN[0])
302                {
303                    newRA = values[i];
304                    nset += newRA >= 0 && newRA <= 24.0;
305                } else if (eqp == &EquatorialCoordsWN[1])
306                {
307                    newDEC = values[i];
308                    nset += newDEC >= -90.0 && newDEC <= 90.0;
309                }
310            }
311
312          if (nset == 2)
313          {
314           char RAStr[32], DecStr[32];
315
316           fs_sexa(RAStr, newRA, 2, 3600);
317           fs_sexa(DecStr, newDEC, 2, 3600);
318         
319           #ifdef INDI_DEBUG
320           IDLog("We received JNow RA %g - DEC %g\n", newRA, newDEC);
321           IDLog("We received JNow RA %s - DEC %s\n", RAStr, DecStr);
322           #endif
323           
324           if (!simulation && ( (error_code = setObjectRA(fd, newRA)) < 0 || ( error_code = setObjectDEC(fd, newDEC)) < 0))
325           {
326             handle_error(&EquatorialCoordsWNP, error_code, "Setting RA/DEC");
327             return;
328           } 
329           
330           targetRA  = newRA;
331           targetDEC = newDEC;
332           
333           if (process_coords() == false)
334           {
335             EquatorialCoordsWNP.s = IPS_ALERT;
336             IDSetNumber(&EquatorialCoordsWNP, NULL);
337             
338           }
339        } // end nset
340        else
341        {
342                EquatorialCoordsWNP.s = IPS_ALERT;
343                IDSetNumber(&EquatorialCoordsWNP, "RA or Dec missing or invalid");
344        }
345
346            return;
347     } /* end EquatorialCoordsWNP */
348
349}
350
351/**************************************************************************************
352**
353***************************************************************************************/
354void IEQ45Basic::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
355{
356        // ignore if not ours //
357        if (strcmp (mydev, dev))
358            return;
359
360        // ===================================
361        // Connect Switch
362        // ===================================
363        if (!strcmp (name, ConnectSP.name))
364        {
365            if (IUUpdateSwitch(&ConnectSP, states, names, n) < 0)
366                return;
367
368            connect_telescope();
369            return;
370        }
371
372        if (is_connected() == false)
373        {
374                IDMessage(mydev, "IEQ45 is offline. Please connect before issuing any commands.");
375                reset_all_properties();
376                return;
377        }
378
379        // ===================================
380        // Coordinate Set
381        // ===================================
382        if (!strcmp(name, OnCoordSetSP.name))
383        {
384           if (IUUpdateSwitch(&OnCoordSetSP, states, names, n) < 0)
385                return;
386
387          currentSet = get_switch_index(&OnCoordSetSP);
388          OnCoordSetSP.s = IPS_OK;
389          IDSetSwitch(&OnCoordSetSP, NULL);
390        }
391
392        // ===================================
393        // Track Mode Set
394        // ===================================
395        if (!strcmp(name, TrackModeSP.name))
396        {
397           if (IUUpdateSwitch(&TrackModeSP, states, names, n) < 0)
398                return;
399
400          int trackMode = get_switch_index(&TrackModeSP);
401          selectTrackingMode(fd, trackMode);
402          TrackModeSP.s = IPS_OK;
403          IDSetSwitch(&TrackModeSP, NULL);
404        }
405         
406        // ===================================
407        // Abort slew
408        // ===================================
409        if (!strcmp (name, AbortSlewSP.name))
410        {
411
412          IUResetSwitch(&AbortSlewSP);
413          abortSlew(fd);
414
415            if (EquatorialCoordsWNP.s == IPS_BUSY)
416            {
417                AbortSlewSP.s = IPS_OK;
418                EquatorialCoordsWNP.s       = IPS_IDLE;
419                EquatorialCoordsRNP.s       = IPS_IDLE;
420                IDSetSwitch(&AbortSlewSP, "Slew aborted.");
421                IDSetNumber(&EquatorialCoordsWNP, NULL);
422                IDSetNumber(&EquatorialCoordsRNP, NULL);
423            }
424
425            return;
426        }
427
428}
429
430/**************************************************************************************
431** Retry connecting to the telescope on error. Give up if there is no hope.
432***************************************************************************************/
433void IEQ45Basic::handle_error(INumberVectorProperty *nvp, int err, const char *msg)
434{
435 
436  nvp->s = IPS_ALERT;
437 
438  /* First check to see if the telescope is connected */
439    if (check_IEQ45_connection(fd))
440    {
441      /* The telescope is off locally */
442      ConnectS[0].s = ISS_OFF;
443      ConnectS[1].s = ISS_ON;
444      ConnectSP.s = IPS_BUSY;
445      IDSetSwitch(&ConnectSP, "Telescope is not responding to commands, will retry in 10 seconds.");
446     
447      IDSetNumber(nvp, NULL);
448      IEAddTimer(10000, retry_connection, &fd);
449      return;
450    }
451   
452   /* If the error is a time out, then the device doesn't support this property */
453      if (err == -2)
454      {
455       nvp->s = IPS_ALERT;
456       IDSetNumber(nvp, "Device timed out. Current device may be busy or does not support %s. Will retry again.", msg);
457      }
458      else
459    /* Changing property failed, user should retry. */
460       IDSetNumber( nvp , "%s failed.", msg);
461       
462       fault = true;
463}
464
465/**************************************************************************************
466** Set all properties to idle and reset most switches to clean state.
467***************************************************************************************/
468void IEQ45Basic::reset_all_properties()
469{
470    ConnectSP.s                 = IPS_IDLE;
471    OnCoordSetSP.s              = IPS_IDLE;
472    TrackModeSP.s               = IPS_IDLE; 
473    AbortSlewSP.s               = IPS_IDLE;
474    PortTP.s                    = IPS_IDLE;
475    EquatorialCoordsWNP.s       = IPS_IDLE;
476    EquatorialCoordsRNP.s       = IPS_IDLE;
477
478
479    IUResetSwitch(&OnCoordSetSP);
480    IUResetSwitch(&TrackModeSP);
481    IUResetSwitch(&AbortSlewSP);
482
483    OnCoordSetS[0].s = ISS_ON;
484    TrackModeS[0].s = ISS_ON;
485    ConnectS[0].s = ISS_OFF;
486    ConnectS[1].s = ISS_ON;
487
488    IDSetSwitch(&ConnectSP, NULL);
489    IDSetSwitch(&OnCoordSetSP, NULL);
490    IDSetSwitch(&TrackModeSP, NULL);
491    IDSetSwitch(&AbortSlewSP, NULL);
492    IDSetText(&PortTP, NULL);
493    IDSetNumber(&EquatorialCoordsWNP, NULL);
494    IDSetNumber(&EquatorialCoordsRNP, NULL);
495}
496
497/**************************************************************************************
498**
499***************************************************************************************/
500void IEQ45Basic::correct_fault()
501{
502  fault = false;
503  IDMessage(mydev, "Telescope is online.");
504}
505
506/**************************************************************************************
507**
508***************************************************************************************/
509bool IEQ45Basic::is_connected()
510{
511  if (simulation) return true;
512 
513  return (ConnectSP.sp[0].s == ISS_ON);
514}
515
516/**************************************************************************************
517**
518***************************************************************************************/
519static void retry_connection(void * p)
520{
521  int fd = *((int *) p);
522
523  if (check_IEQ45_connection(fd))
524        telescope->connection_lost();
525  else
526        telescope->connection_resumed();
527}
528
529/**************************************************************************************
530**
531***************************************************************************************/
532void IEQ45Basic::ISPoll()
533{       
534        if (is_connected() == false || simulation)
535         return;
536
537        double dx, dy;
538        int error_code=0;
539
540        switch (EquatorialCoordsWNP.s)
541        {
542                case IPS_IDLE:
543                getIEQ45RA(fd, &currentRA);
544                getIEQ45DEC(fd, &currentDEC);
545                if ( fabs (currentRA - lastRA) > 0.01 || fabs (currentDEC - lastDEC) > 0.01)
546                {
547                        lastRA = currentRA;
548                        lastDEC = currentDEC;
549                        IDSetNumber (&EquatorialCoordsRNP, NULL);
550                        IDLog("IDLE update coord\n"); 
551                }
552                break;
553
554                case IPS_BUSY:
555                getIEQ45RA(fd, &currentRA);
556                getIEQ45DEC(fd, &currentDEC);
557                dx = targetRA - currentRA;
558                dy = targetDEC - currentDEC;
559
560                // Wait until acknowledged or within threshold
561                if ( fabs(dx) <= (3/(900.0)) && fabs(dy) <= (3/60.0))
562                {
563                        lastRA  = currentRA;
564                        lastDEC = currentDEC;
565                        IUResetSwitch(&OnCoordSetSP);
566                        OnCoordSetSP.s = IPS_OK;
567                        EquatorialCoordsWNP.s = IPS_OK;
568                        EquatorialCoordsRNP.s = IPS_OK;
569                        IDSetNumber (&EquatorialCoordsWNP, NULL);
570                        IDSetNumber (&EquatorialCoordsRNP, NULL);
571
572                        switch (currentSet)
573                        {
574                                case IEQ45_SLEW:
575                                OnCoordSetSP.sp[IEQ45_SLEW].s = ISS_ON;
576                                IDSetSwitch (&OnCoordSetSP, "Slew is complete.");
577                                break;
578                   
579                                case IEQ45_SYNC:
580                                break;
581                        }
582                 
583                }
584                else
585                        IDSetNumber (&EquatorialCoordsRNP, NULL);
586                break;
587
588                case IPS_OK:
589                         
590                if ( (error_code = getIEQ45RA(fd, &currentRA)) < 0 || (error_code = getIEQ45DEC(fd, &currentDEC)) < 0)
591                {
592                        handle_error(&EquatorialCoordsRNP, error_code, "Getting RA/DEC");
593                        return;
594                }
595       
596                if (fault == true)
597                        correct_fault();
598
599                if ( (currentRA != lastRA) || (currentDEC != lastDEC))
600                {
601                        lastRA  = currentRA;
602                        lastDEC = currentDEC;
603                        //IDLog("IPS_OK update coords %g %g\n",currentRA,currentDEC);
604                        IDSetNumber (&EquatorialCoordsRNP, NULL);
605                }
606                break;
607
608                case IPS_ALERT:
609                break;
610        }
611}
612
613/**************************************************************************************
614**
615***************************************************************************************/
616bool IEQ45Basic::process_coords()
617{
618
619  int  error_code;
620  char syncString[256];
621  char RAStr[32], DecStr[32];
622  double dx, dy;
623 
624  switch (currentSet)
625  {
626
627    // Slew
628    case IEQ45_SLEW:
629          lastSet = IEQ45_SLEW;
630          if (EquatorialCoordsWNP.s == IPS_BUSY)
631          {
632             IDLog("Aboring Slew\n");
633             abortSlew(fd);
634
635             // sleep for 100 mseconds
636             usleep(100000);
637          }
638
639          if ( !simulation && (error_code = Slew(fd)))
640          {
641            slew_error(error_code);
642            return false;
643          }
644
645          EquatorialCoordsWNP.s = IPS_BUSY;
646          EquatorialCoordsRNP.s = IPS_BUSY;
647          fs_sexa(RAStr, targetRA, 2, 3600);
648          fs_sexa(DecStr, targetDEC, 2, 3600);
649          IDSetNumber(&EquatorialCoordsWNP, "Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
650          IDSetNumber(&EquatorialCoordsRNP, NULL);
651          IDLog("Slewing to JNow RA %s - DEC %s\n", RAStr, DecStr);
652          break;
653
654
655    // Sync
656    case IEQ45_SYNC:
657          lastSet = IEQ45_SYNC;
658          EquatorialCoordsWNP.s = IPS_IDLE;
659           
660          if ( !simulation && ( error_code = Sync(fd, syncString) < 0) )
661          {
662                IDSetNumber( &EquatorialCoordsWNP , "Synchronization failed.");
663                return false;
664          }
665
666          if (simulation)
667          {
668             EquatorialCoordsRN[0].value = EquatorialCoordsWN[0].value;
669             EquatorialCoordsRN[1].value = EquatorialCoordsWN[1].value;
670          }
671
672          EquatorialCoordsWNP.s = IPS_OK;
673          EquatorialCoordsRNP.s = IPS_OK;
674          IDSetNumber(&EquatorialCoordsRNP, NULL);
675          IDLog("Synchronization successful %s\n", syncString);
676          IDSetNumber(&EquatorialCoordsWNP, "Synchronization successful.");
677          break;
678    }
679
680   return true;
681
682}
683
684/**************************************************************************************
685**
686***************************************************************************************/
687int IEQ45Basic::get_switch_index(ISwitchVectorProperty *sp)
688{
689 for (int i=0; i < sp->nsp ; i++)
690     if (sp->sp[i].s == ISS_ON)
691      return i;
692
693 return -1;
694}
695
696/**************************************************************************************
697**
698***************************************************************************************/
699void IEQ45Basic::connect_telescope()
700{
701     switch (ConnectSP.sp[0].s)
702     {
703      case ISS_ON: 
704       
705        if (simulation)
706        {
707          ConnectSP.s = IPS_OK;
708          IDSetSwitch (&ConnectSP, "Simulated telescope is online.");
709          return;
710        }
711       
712         if (tty_connect(PortT[0].text, 9600, 8, 0, 1, &fd) != TTY_OK)
713         {
714           ConnectS[0].s = ISS_OFF;
715           ConnectS[1].s = ISS_ON;
716           IDSetSwitch (&ConnectSP, "Error connecting to port %s. Make sure you have BOTH read and write permission to the port.", PortT[0].text);
717           return;
718         }
719
720         if (check_IEQ45_connection(fd))
721         {   
722           ConnectS[0].s = ISS_OFF;
723           ConnectS[1].s = ISS_ON;
724           IDSetSwitch (&ConnectSP, "Error connecting to Telescope. Telescope is offline.");
725           return;
726         }
727
728        ConnectSP.s = IPS_OK;
729        IDSetSwitch (&ConnectSP, "Telescope is online. Retrieving basic data...");
730        get_initial_data();
731        break;
732
733     case ISS_OFF:
734         ConnectS[0].s = ISS_OFF;
735         ConnectS[1].s = ISS_ON;
736         ConnectSP.s = IPS_IDLE;
737         if (simulation)
738         {
739            IDSetSwitch (&ConnectSP, "Simulated Telescope is offline.");
740            return;
741         }
742         IDSetSwitch (&ConnectSP, "Telescope is offline.");
743         IDLog("Telescope is offline.");
744         
745         tty_disconnect(fd);
746         break;
747    }
748}
749
750/**************************************************************************************
751**
752***************************************************************************************/
753void IEQ45Basic::get_initial_data()
754{
755
756  // Make sure short
757  checkIEQ45Format(fd);
758
759  // Get current RA/DEC
760  getIEQ45RA(fd, &currentRA);
761  getIEQ45DEC(fd, &currentDEC);
762
763  IDSetNumber (&EquatorialCoordsRNP, NULL); 
764}
765
766/**************************************************************************************
767**
768***************************************************************************************/
769void IEQ45Basic::slew_error(int slewCode)
770{
771    OnCoordSetSP.s = IPS_IDLE;
772    IDLog("Aboring Slew\n");
773    abortSlew(fd);
774    if (slewCode == 1)
775        IDSetSwitch (&OnCoordSetSP, "Object below horizon.");
776    else if (slewCode == 2)
777        IDSetSwitch (&OnCoordSetSP, "Object below the minimum elevation limit.");
778    else
779        IDSetSwitch (&OnCoordSetSP, "Slew failed.");
780}
781
782/**************************************************************************************
783**
784***************************************************************************************/
785void IEQ45Basic::enable_simulation(bool enable)
786{
787   simulation = enable;
788   
789   if (simulation)
790     IDLog("Warning: Simulation is activated.\n");
791   else
792     IDLog("Simulation is disabled.\n");
793}
794
795/**************************************************************************************
796**
797***************************************************************************************/
798void IEQ45Basic::connection_lost()
799{
800    ConnectSP.s = IPS_IDLE;
801    IDSetSwitch(&ConnectSP, "The connection to the telescope is lost.");
802    return;
803 
804}
805
806/**************************************************************************************
807**
808***************************************************************************************/
809void IEQ45Basic::connection_resumed()
810{
811  ConnectS[0].s = ISS_ON;
812  ConnectS[1].s = ISS_OFF;
813  ConnectSP.s = IPS_OK;
814   
815  IDSetSwitch(&ConnectSP, "The connection to the telescope has been resumed.");
816}
Note: See TracBrowser for help on using the repository browser.