• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

lx200basic.cpp

Go to the documentation of this file.
00001 #if 0
00002     LX200 Basic Driver
00003     Copyright (C) 2005 Jasem Mutlaq (mutlaqja@ikarustech.com)
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #endif
00020 
00021 #include "config.h"
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <stdarg.h>
00027 #include <math.h>
00028 #include <unistd.h>
00029 #include <time.h>
00030 
00031 #include "indicom.h"
00032 #include "lx200driver.h"
00033 #include "lx200basic.h"
00034 
00035 /*
00036 ** Return the timezone offset in hours (as a double, so fractional
00037 ** hours are possible, for instance in Newfoundland). Also sets
00038 ** daylight on non-Linux systems to record whether DST is in effect.
00039 */
00040 
00041 
00042 LX200Basic *telescope = NULL;
00043 extern char* me;
00044 
00045 #define BASIC_GROUP "Main Control"
00046 
00047 #define currentRA   EqN[0].value
00048 #define currentDEC  EqN[1].value
00049 
00050 #define RA_THRESHOLD    0.01
00051 #define DEC_THRESHOLD   0.05
00052 #define LX200_SLEW  0
00053 #define LX200_TRACK 1
00054 #define LX200_SYNC  2
00055 #define LX200_PARK  3
00056 
00057 static void ISPoll(void *);
00058 static void retryConnection(void *);
00059 
00060 /*INDI controls */
00061 
00062 
00063 /* send client definitions of all properties */
00064 void ISInit()
00065 {
00066   static int isInit=0;
00067 
00068  if (isInit)
00069   return;
00070 
00071  isInit = 1;
00072   
00073   telescope = new LX200Basic();
00074   IEAddTimer (POLLMS, ISPoll, NULL);
00075 }
00076 
00077 void ISGetProperties (const char *dev)
00078 {
00079  ISInit(); 
00080  telescope->ISGetProperties(dev);
00081 }
00082 
00083 void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
00084 {
00085  ISInit();
00086  telescope->ISNewSwitch(dev, name, states, names, n);
00087 }
00088 
00089 void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
00090 {
00091  ISInit();
00092  telescope->ISNewText(dev, name, texts, names, n);
00093 }
00094 
00095 void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
00096 {
00097  ISInit();
00098  telescope->ISNewNumber(dev, name, values, names, n);
00099 }
00100 
00101 void ISPoll (void */*p*/)
00102 {
00103  telescope->ISPoll(); 
00104  IEAddTimer (POLLMS, ISPoll, NULL);
00105 }
00106 
00107 void ISNewBLOB (const char */*dev*/, const char */*name*/, int */*sizes[]*/, char **/*blobs[]*/, char **/*formats[]*/, char **/*names[]*/, int /*n*/)
00108 {}
00109 
00110 /**************************************************
00111 *** AP Mount
00112 ***************************************************/
00113 
00114 LX200Basic::LX200Basic()
00115 {
00116    struct tm *utp;
00117    time_t t;
00118    time (&t);
00119    utp = gmtime (&t);
00120 
00121    initProperties();
00122 
00123    lastSet        = -1;
00124    simulation     = false;
00125    targetRA       = 0;
00126    targetDEC      = 0;
00127    lastRA     = 0;
00128    lastDEC    = 0;
00129    currentSet     = 0;
00130    UTCOffset      = 0;
00131 
00132    localTM = new tm;
00133    
00134    utp->tm_mon  += 1;
00135    utp->tm_year += 1900;
00136    JD = UTtoJD(utp);
00137    
00138    IDLog("Julian Day is %g\n", JD);
00139    IDLog("Initilizing from LX200 Basic device...\n");
00140    IDLog("Driver Version: 2005-07-20\n");
00141  
00142    //enableSimulation(true);  
00143 }
00144 
00145 void LX200Basic::initProperties()
00146 {
00147 
00148   fillSwitch(&PowerS[0], "CONNECT", "Connect", ISS_OFF);
00149   fillSwitch(&PowerS[1], "DISCONNECT", "Disconnect", ISS_ON);
00150   fillSwitchVector(&PowerSP, PowerS, NARRAY(PowerS), mydev, "CONNECTION", "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
00151 
00152   fillSwitch(&OnCoordSetS[0], "SLEW", "Slew", ISS_ON);
00153   fillSwitch(&OnCoordSetS[1], "TRACK", "Track", ISS_OFF);
00154   fillSwitch(&OnCoordSetS[2], "SYNC", "Sync", ISS_OFF);
00155   fillSwitchVector(&OnCoordSetSP, OnCoordSetS, NARRAY(OnCoordSetS), mydev, "ON_COORD_SET", "On Set", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
00156 
00157    fillSwitch(&AbortSlewS[0], "ABORT", "Abort", ISS_OFF);
00158    fillSwitchVector(&AbortSlewSP, AbortSlewS, NARRAY(AbortSlewS), mydev, "ABORT_MOTION", "Abort Slew/Track", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
00159 
00160   fillText(&PortT[0], "PORT", "Port", "/dev/ttyS0");
00161   fillTextVector(&PortTP, PortT, NARRAY(PortT), mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
00162 
00163   fillText(&ObjectT[0], "OBJECT_NAME", "Name", "--");
00164   fillTextVector(&ObjectTP, ObjectT, NARRAY(ObjectT), mydev, "OBJECT_INFO", "Object", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
00165 
00166    fillNumber(&EqN[0], "RA", "RA  H:M:S", "%10.6m",  0., 24., 0., 0.);
00167    fillNumber(&EqN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.);
00168    fillNumberVector(&EqNP, EqN, NARRAY(EqN), mydev, "EQUATORIAL_EOD_COORD" , "Equatorial JNow", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
00169 
00170    
00171 }
00172 
00173 void LX200Basic::ISGetProperties(const char *dev)
00174 {
00175 
00176  if (dev && strcmp (mydev, dev))
00177     return;
00178 
00179   // Main Control
00180   IDDefSwitch(&PowerSP, NULL);
00181   IDDefText(&PortTP, NULL);
00182   IDDefText(&ObjectTP, NULL);
00183   IDDefNumber(&EqNP, NULL);
00184   IDDefSwitch(&OnCoordSetSP, NULL);
00185   IDDefSwitch(&AbortSlewSP, NULL);
00186   
00187 }
00188 
00189 void LX200Basic::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int /*n*/)
00190 {
00191     IText *tp;
00192 
00193     // ignore if not ours 
00194     if (strcmp (dev, mydev))
00195         return;
00196 
00197     // Port name
00198     if (!strcmp(name, PortTP.name) )
00199     {
00200       PortTP.s = IPS_OK;
00201       tp = IUFindText( &PortTP, names[0] );
00202       if (!tp)
00203        return;
00204 
00205        IUSaveText(tp, texts[0]);
00206        IDSetText (&PortTP, NULL);
00207       return;
00208     }
00209 
00210        if (!strcmp (name, ObjectTP.name))
00211        {
00212       if (checkPower(&ObjectTP))
00213        return;
00214 
00215           IUSaveText(&ObjectT[0], texts[0]);
00216           ObjectTP.s = IPS_OK;
00217           IDSetText(&ObjectTP, NULL);
00218           return;
00219        }
00220           
00221 }
00222 
00223 
00224 void LX200Basic::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
00225 {
00226     int err;
00227     double newRA =0, newDEC =0;
00228     
00229     // ignore if not ours //
00230     if (strcmp (dev, mydev))
00231         return;
00232 
00233     if (!strcmp (name, EqNP.name))
00234     {
00235       int i=0, nset=0;
00236 
00237       if (checkPower(&EqNP))
00238        return;
00239 
00240         for (nset = i = 0; i < n; i++)
00241         {
00242         INumber *eqp = IUFindNumber (&EqNP, names[i]);
00243         if (eqp == &EqN[0])
00244         {
00245                     newRA = values[i];
00246             nset += newRA >= 0 && newRA <= 24.0;
00247         } else if (eqp == &EqN[1])
00248         {
00249             newDEC = values[i];
00250             nset += newDEC >= -90.0 && newDEC <= 90.0;
00251         }
00252         }
00253 
00254       if (nset == 2)
00255       {
00256        char RAStr[32], DecStr[32];
00257 
00258        fs_sexa(RAStr, newRA, 2, 3600);
00259        fs_sexa(DecStr, newDEC, 2, 3600);
00260       
00261        IDLog("We received JNow RA %g - DEC %g\n", newRA, newDEC);
00262        IDLog("We received JNow RA %s - DEC %s\n", RAStr, DecStr);
00263        
00264        if ( (err = setObjectRA(newRA)) < 0 || ( err = setObjectDEC(newDEC)) < 0)
00265        {
00266          handleError(&EqNP, err, "Setting RA/DEC");
00267          return;
00268        } 
00269        
00270        targetRA  = newRA;
00271        targetDEC = newDEC;
00272        
00273        if (handleCoordSet())
00274        {
00275          EqNP.s = IPS_IDLE;
00276          IDSetNumber(&EqNP, NULL);
00277          
00278        }
00279     } // end nset
00280     else
00281     {
00282         EqNP.s = IPS_IDLE;
00283         IDSetNumber(&EqNP, "RA or Dec missing or invalid");
00284     }
00285 
00286         return;
00287      } /* end EqNP */
00288 
00289 
00290 }
00291 
00292 void LX200Basic::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
00293 {
00294     // ignore if not ours //
00295     if (strcmp (mydev, dev))
00296         return;
00297 
00298     // Connection
00299     if (!strcmp (name, PowerSP.name))
00300     {
00301      IUResetSwitches(&PowerSP);
00302      IUUpdateSwitches(&PowerSP, states, names, n);
00303      powerTelescope();
00304      return;
00305     }
00306 
00307     // Coord set
00308     if (!strcmp(name, OnCoordSetSP.name))
00309     {
00310       if (checkPower(&OnCoordSetSP))
00311        return;
00312 
00313       IUResetSwitches(&OnCoordSetSP);
00314       IUUpdateSwitches(&OnCoordSetSP, states, names, n);
00315       currentSet = getOnSwitch(&OnCoordSetSP);
00316       OnCoordSetSP.s = IPS_OK;
00317       IDSetSwitch(&OnCoordSetSP, NULL);
00318     }
00319       
00320     // Abort Slew
00321     if (!strcmp (name, AbortSlewSP.name))
00322     {
00323       if (checkPower(&AbortSlewSP))
00324       {
00325         AbortSlewSP.s = IPS_IDLE;
00326         IDSetSwitch(&AbortSlewSP, NULL);
00327         return;
00328       }
00329       
00330       IUResetSwitches(&AbortSlewSP);
00331       abortSlew();
00332 
00333         if (EqNP.s == IPS_BUSY)
00334         {
00335         AbortSlewSP.s = IPS_OK;
00336         EqNP.s       = IPS_IDLE;
00337         IDSetSwitch(&AbortSlewSP, "Slew aborted.");
00338         IDSetNumber(&EqNP, NULL);
00339             }
00340 
00341         return;
00342     }
00343 
00344 }
00345 
00346 void LX200Basic::handleError(ISwitchVectorProperty *svp, int err, const char *msg)
00347 {
00348   
00349   svp->s = IPS_ALERT;
00350   
00351   /* First check to see if the telescope is connected */
00352     if (testTelescope())
00353     {
00354       /* The telescope is off locally */
00355       PowerS[0].s = ISS_OFF;
00356       PowerS[1].s = ISS_ON;
00357       PowerSP.s = IPS_BUSY;
00358       IDSetSwitch(&PowerSP, "Telescope is not responding to commands, will retry in 10 seconds.");
00359       
00360       IDSetSwitch(svp, NULL);
00361       IEAddTimer(10000, retryConnection, NULL);
00362       return;
00363     }
00364     
00365    /* If the error is a time out, then the device doesn't support this property or busy*/
00366       if (err == -2)
00367       {
00368        svp->s = IPS_ALERT;
00369        IDSetSwitch(svp, "Device timed out. Current device may be busy or does not support %s. Will retry again.", msg);
00370       }
00371       else
00372     /* Changing property failed, user should retry. */
00373        IDSetSwitch( svp , "%s failed.", msg);
00374        
00375        fault = true;
00376 }
00377 
00378 void LX200Basic::handleError(INumberVectorProperty *nvp, int err, const char *msg)
00379 {
00380   
00381   nvp->s = IPS_ALERT;
00382   
00383   /* First check to see if the telescope is connected */
00384     if (testTelescope())
00385     {
00386       /* The telescope is off locally */
00387       PowerS[0].s = ISS_OFF;
00388       PowerS[1].s = ISS_ON;
00389       PowerSP.s = IPS_BUSY;
00390       IDSetSwitch(&PowerSP, "Telescope is not responding to commands, will retry in 10 seconds.");
00391       
00392       IDSetNumber(nvp, NULL);
00393       IEAddTimer(10000, retryConnection, NULL);
00394       return;
00395     }
00396     
00397    /* If the error is a time out, then the device doesn't support this property */
00398       if (err == -2)
00399       {
00400        nvp->s = IPS_ALERT;
00401        IDSetNumber(nvp, "Device timed out. Current device may be busy or does not support %s. Will retry again.", msg);
00402       }
00403       else
00404     /* Changing property failed, user should retry. */
00405        IDSetNumber( nvp , "%s failed.", msg);
00406        
00407        fault = true;
00408 }
00409 
00410 void LX200Basic::handleError(ITextVectorProperty *tvp, int err, const char *msg)
00411 {
00412   
00413   tvp->s = IPS_ALERT;
00414   
00415   /* First check to see if the telescope is connected */
00416     if (testTelescope())
00417     {
00418       /* The telescope is off locally */
00419       PowerS[0].s = ISS_OFF;
00420       PowerS[1].s = ISS_ON;
00421       PowerSP.s = IPS_BUSY;
00422       IDSetSwitch(&PowerSP, "Telescope is not responding to commands, will retry in 10 seconds.");
00423       
00424       IDSetText(tvp, NULL);
00425       IEAddTimer(10000, retryConnection, NULL);
00426       return;
00427     }
00428     
00429    /* If the error is a time out, then the device doesn't support this property */
00430       if (err == -2)
00431       {
00432        tvp->s = IPS_ALERT;
00433        IDSetText(tvp, "Device timed out. Current device may be busy or does not support %s. Will retry again.", msg);
00434       }
00435        
00436       else
00437     /* Changing property failed, user should retry. */
00438        IDSetText( tvp , "%s failed.", msg);
00439        
00440        fault = true;
00441 }
00442 
00443  void LX200Basic::correctFault()
00444  {
00445  
00446    fault = false;
00447    IDMessage(mydev, "Telescope is online.");
00448    
00449  }
00450 
00451 bool LX200Basic::isTelescopeOn(void)
00452 {
00453   if (simulation) return true;
00454   
00455   return (PowerSP.sp[0].s == ISS_ON);
00456 }
00457 
00458 static void retryConnection(void * p)
00459 {
00460   p=p;
00461   
00462   if (testTelescope())
00463     telescope->connectionLost();
00464   else
00465     telescope->connectionResumed();
00466 }
00467 
00468 void LX200Basic::ISPoll()
00469 {
00470         double dx, dy;
00471     int err=0;
00472     
00473     if (!isTelescopeOn())
00474      return;
00475 
00476     switch (EqNP.s)
00477     {
00478     case IPS_IDLE:
00479     getLX200RA(&currentRA);
00480     getLX200DEC(&currentDEC);
00481     
00482         if ( fabs (currentRA - lastRA) > 0.01 || fabs (currentDEC - lastDEC) > 0.01)
00483     {
00484             lastRA = currentRA;
00485         lastDEC = currentDEC;
00486         IDSetNumber (&EqNP, NULL);
00487     }
00488         break;
00489 
00490         case IPS_BUSY:
00491         getLX200RA(&currentRA);
00492         getLX200DEC(&currentDEC);
00493         dx = targetRA - currentRA;
00494         dy = targetDEC - currentDEC;
00495 
00496         IDLog("targetRA is %g, currentRA is %g\n", targetRA, currentRA);
00497         IDLog("targetDEC is %g, currentDEC is %g\n*************************\n", targetDEC, currentDEC);
00498 
00499         // Wait until acknowledged or within threshold
00500         if (fabs(dx) <= RA_THRESHOLD && fabs(dy) <= DEC_THRESHOLD)
00501         {
00502         
00503            lastRA  = currentRA;
00504            lastDEC = currentDEC;
00505            IUResetSwitches(&OnCoordSetSP);
00506            OnCoordSetSP.s = IPS_OK;
00507            EqNP.s = IPS_OK;
00508            IDSetNumber (&EqNP, NULL);
00509 
00510         switch (currentSet)
00511         {
00512           case LX200_SLEW:
00513             OnCoordSetSP.sp[0].s = ISS_ON;
00514             IDSetSwitch (&OnCoordSetSP, "Slew is complete.");
00515             break;
00516           
00517           case LX200_TRACK:
00518             OnCoordSetSP.sp[1].s = ISS_ON;
00519             IDSetSwitch (&OnCoordSetSP, "Slew is complete. Tracking...");
00520             break;
00521           
00522           case LX200_SYNC:
00523             break;
00524         }
00525           
00526         } else
00527         IDSetNumber (&EqNP, NULL);
00528         break;
00529 
00530     case IPS_OK:
00531       
00532     if ( (err = getLX200RA(&currentRA)) < 0 || (err = getLX200DEC(&currentDEC)) < 0)
00533     {
00534       handleError(&EqNP, err, "Getting RA/DEC");
00535       return;
00536     }
00537     
00538     if (fault)
00539       correctFault();
00540     
00541     if ( (currentRA != lastRA) || (currentDEC != lastDEC))
00542     {
00543         lastRA  = currentRA;
00544         lastDEC = currentDEC;
00545         IDSetNumber (&EqNP, NULL);
00546     }
00547         break;
00548 
00549 
00550     case IPS_ALERT:
00551         break;
00552     }
00553 
00554 }
00555 
00556 void LX200Basic::getBasicData()
00557 {
00558   // Get current RA/DEC
00559   getLX200RA(&currentRA);
00560   getLX200DEC(&currentDEC);
00561   targetRA = currentRA;
00562   targetDEC = currentDEC;
00563 
00564   IDSetNumber (&EqNP, NULL);  
00565 }
00566 
00567 int LX200Basic::handleCoordSet()
00568 {
00569 
00570   int  err;
00571   char syncString[256];
00572   char RAStr[32], DecStr[32];
00573   double dx, dy;
00574   
00575   switch (currentSet)
00576   {
00577 
00578     // Slew
00579     case LX200_SLEW:
00580           lastSet = LX200_SLEW;
00581       if (EqNP.s == IPS_BUSY)
00582       {
00583          IDLog("Aboring Slew\n");
00584          abortSlew();
00585 
00586          // sleep for 100 mseconds
00587          usleep(100000);
00588       }
00589 
00590       if ((err = Slew()))
00591       {
00592         slewError(err);
00593         return (-1);
00594       }
00595 
00596       EqNP.s = IPS_BUSY;
00597       fs_sexa(RAStr, targetRA, 2, 3600);
00598       fs_sexa(DecStr, targetDEC, 2, 3600);
00599       IDSetNumber(&EqNP, "Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
00600       IDLog("Slewing to JNow RA %s - DEC %s\n", RAStr, DecStr);
00601       break;
00602 
00603      // Track
00604      case LX200_TRACK:
00605           IDLog("We're in LX200_TRACK\n");
00606           if (EqNP.s == IPS_BUSY)
00607       {
00608          IDLog("Aboring Slew\n");
00609          abortSlew();
00610 
00611          // sleep for 200 mseconds
00612          usleep(200000);
00613       }
00614 
00615       dx = fabs ( targetRA - currentRA );
00616       dy = fabs (targetDEC - currentDEC);
00617 
00618       
00619       if (dx >= TRACKING_THRESHOLD || dy >= TRACKING_THRESHOLD) 
00620       {
00621             IDLog("Exceeded Tracking threshold, will attempt to slew to the new target.\n");
00622         IDLog("targetRA is %g, currentRA is %g\n", targetRA, currentRA);
00623             IDLog("targetDEC is %g, currentDEC is %g\n*************************\n", targetDEC, currentDEC);
00624 
00625             if ((err = Slew()))
00626         {
00627                 slewError(err);
00628                 return (-1);
00629         }
00630 
00631         fs_sexa(RAStr, targetRA, 2, 3600);
00632             fs_sexa(DecStr, targetDEC, 2, 3600);
00633         EqNP.s = IPS_BUSY;
00634         IDSetNumber(&EqNP, "Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
00635         IDLog("Slewing to JNow RA %s - DEC %s\n", RAStr, DecStr);
00636       }
00637       else
00638       {
00639         IDLog("Tracking called, but tracking threshold not reached yet.\n");
00640         EqNP.s = IPS_OK;
00641         EqNP.np[0].value = currentRA;
00642         EqNP.np[1].value = currentDEC;
00643 
00644         if (lastSet != LX200_TRACK)
00645           IDSetNumber(&EqNP, "Tracking...");
00646         else
00647           IDSetNumber(&EqNP, NULL);
00648       }
00649       lastSet = LX200_TRACK;
00650       break;
00651 
00652     // Sync
00653     case LX200_SYNC:
00654           lastSet = LX200_SYNC;
00655       EqNP.s = IPS_IDLE;
00656        
00657       if ( ( err = Sync(syncString) < 0) )
00658       {
00659             IDSetNumber( &EqNP , "Synchronization failed.");
00660         return (-1);
00661       }
00662 
00663       EqNP.s = IPS_OK;
00664       IDLog("Synchronization successful %s\n", syncString);
00665       IDSetNumber(&EqNP, "Synchronization successful.");
00666       break;
00667     }
00668 
00669    return (0);
00670 
00671 }
00672 
00673 int LX200Basic::getOnSwitch(ISwitchVectorProperty *sp)
00674 {
00675  for (int i=0; i < sp->nsp ; i++)
00676      if (sp->sp[i].s == ISS_ON)
00677       return i;
00678 
00679  return -1;
00680 }
00681 
00682 
00683 int LX200Basic::checkPower(ISwitchVectorProperty *sp)
00684 {
00685   if (simulation) return 0;
00686   
00687   if (PowerSP.s != IPS_OK)
00688   {
00689     if (!strcmp(sp->label, ""))
00690         IDMessage (mydev, "Cannot change property %s while the telescope is offline.", sp->name);
00691     else
00692         IDMessage (mydev, "Cannot change property %s while the telescope is offline.", sp->label);
00693     
00694     sp->s = IPS_IDLE;
00695     IDSetSwitch(sp, NULL);
00696     return -1;
00697   }
00698 
00699   return 0;
00700 }
00701 
00702 int LX200Basic::checkPower(INumberVectorProperty *np)
00703 {
00704   if (simulation) return 0;
00705   
00706   if (PowerSP.s != IPS_OK)
00707   {
00708     
00709     if (!strcmp(np->label, ""))
00710         IDMessage (mydev, "Cannot change property %s while the telescope is offline.", np->name);
00711     else
00712         IDMessage (mydev, "Cannot change property %s while the telescope is offline.", np->label);
00713     
00714     np->s = IPS_IDLE;
00715     IDSetNumber(np, NULL);
00716     return -1;
00717   }
00718 
00719   return 0;
00720 
00721 }
00722 
00723 int LX200Basic::checkPower(ITextVectorProperty *tp)
00724 {
00725 
00726   if (simulation) return 0;
00727   
00728   if (PowerSP.s != IPS_OK)
00729   {
00730     if (!strcmp(tp->label, ""))
00731         IDMessage (mydev, "Cannot change property %s while the telescope is offline.", tp->name);
00732     else
00733         IDMessage (mydev, "Cannot change property %s while the telescope is offline.", tp->label);
00734     
00735     tp->s = IPS_IDLE;
00736     IDSetText(tp, NULL);
00737     return -1;
00738   }
00739 
00740   return 0;
00741 
00742 }
00743 
00744 void LX200Basic::powerTelescope()
00745 {
00746      switch (PowerSP.sp[0].s)
00747      {
00748       case ISS_ON:  
00749     
00750         if (simulation)
00751     {
00752       PowerSP.s = IPS_OK;
00753       IDSetSwitch (&PowerSP, "Simulated telescope is online.");
00754       return;
00755     }
00756     
00757          if (Connect(PortT[0].text))
00758      {
00759        PowerS[0].s = ISS_OFF;
00760        PowerS[1].s = ISS_ON;
00761        IDSetSwitch (&PowerSP, "Error connecting to port %s\n", PortT[0].text);
00762        return;
00763      }
00764 
00765      if (testTelescope())
00766      {   
00767        PowerS[0].s = ISS_OFF;
00768        PowerS[1].s = ISS_ON;
00769        IDSetSwitch (&PowerSP, "Error connecting to Telescope. Telescope is offline.");
00770        return;
00771      }
00772 
00773         IDLog("telescope test successfful\n");
00774     PowerSP.s = IPS_OK;
00775     IDSetSwitch (&PowerSP, "Telescope is online. Retrieving basic data...");
00776     getBasicData();
00777     break;
00778 
00779      case ISS_OFF:
00780          PowerS[0].s = ISS_OFF;
00781      PowerS[1].s = ISS_ON;
00782          PowerSP.s = IPS_IDLE;
00783      if (simulation)
00784          {
00785         IDSetSwitch (&PowerSP, "Simulated Telescope is offline.");
00786         return;
00787          }
00788          IDSetSwitch (&PowerSP, "Telescope is offline.");
00789      IDLog("Telescope is offline.");
00790          
00791      Disconnect();
00792      break;
00793 
00794     }
00795 
00796 }
00797 
00798 void LX200Basic::slewError(int slewCode)
00799 {
00800     OnCoordSetSP.s = IPS_IDLE;
00801 
00802     if (slewCode == 1)
00803     IDSetSwitch (&OnCoordSetSP, "Object below horizon.");
00804     else if (slewCode == 2)
00805     IDSetSwitch (&OnCoordSetSP, "Object below the minimum elevation limit.");
00806     else
00807         IDSetSwitch (&OnCoordSetSP, "Slew failed.");
00808     
00809 
00810 }
00811 
00812 void LX200Basic::enableSimulation(bool enable)
00813 {
00814    simulation = enable;
00815    
00816    if (simulation)
00817      IDLog("Warning: Simulation is activated.\n");
00818    else
00819      IDLog("Simulation is disabled.\n");
00820 }
00821 
00822 void LX200Basic::connectionLost()
00823 {
00824     PowerSP.s = IPS_IDLE;
00825     IDSetSwitch(&PowerSP, "The connection to the telescope is lost.");
00826     return;
00827  
00828 }
00829 
00830 void LX200Basic::connectionResumed()
00831 {
00832   PowerS[0].s = ISS_ON;
00833   PowerS[1].s = ISS_OFF;
00834   PowerSP.s = IPS_OK;
00835    
00836   IDSetSwitch(&PowerSP, "The connection to the telescope has been resumed.");
00837 }
00838 
00839 

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal