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

kstars

celestrongps.cpp

Go to the documentation of this file.
00001 #if 0
00002     Celestron GPS
00003     Copyright (C) 2003 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 <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <stdarg.h>
00025 #include <math.h>
00026 #include <unistd.h>
00027 #include <time.h>
00028 
00029 #include "celestronprotocol.h"
00030 #include "celestrongps.h"
00031 
00032 #define RA_THRESHOLD    0.01
00033 #define DEC_THRESHOLD   0.05
00034 #define mydev       "Celestron GPS"
00035 
00036 CelestronGPS *telescope = NULL;
00037 
00038 
00039 /* There is _one_ binary for all LX200 drivers, but each binary is renamed
00040 ** to its device name (i.e. lx200gps, lx200_16..etc). The main function will
00041 ** fetch from std args the binary name and ISInit will create the apporpiate
00042 ** device afterwards. If the binary name does not match any known devices,
00043 ** we simply create a generic device
00044 */
00045 extern char* me;
00046 
00047 #define COMM_GROUP  "Communication"
00048 #define BASIC_GROUP "Main Control"
00049 #define MOVE_GROUP  "Movement Control"
00050 
00051 static void ISPoll(void *);
00052 
00053 /*INDI controls */
00054 static ISwitch PowerS[]          = {{"CONNECT" , "Connect" , ISS_OFF, 0, 0},{"DISCONNECT", "Disconnect", ISS_ON, 0, 0}};
00055 static ISwitch SlewModeS[]       = {{"Slew", "", ISS_ON, 0, 0}, {"Find", "", ISS_OFF, 0, 0}, {"Centering", "", ISS_OFF, 0, 0}, {"Guide", "", ISS_OFF, 0, 0}};
00056 static ISwitch OnCoordSetS[]     = {{"SLEW", "Slew", ISS_ON, 0 , 0}, {"TRACK", "Track", ISS_OFF, 0, 0}, {"SYNC", "Sync", ISS_OFF, 0, 0}};
00057 static ISwitch abortSlewS[]      = {{"ABORT", "Abort", ISS_OFF, 0, 0}};
00058 
00059 static ISwitch MovementS[]       = {{"N", "North", ISS_OFF, 0, 0}, {"W", "West", ISS_OFF, 0, 0}, {"E", "East", ISS_OFF, 0, 0}, {"S", "South", ISS_OFF, 0, 0}};
00060 
00061 /* equatorial position */
00062 static INumber eq[] = {
00063     {"RA",  "RA  H:M:S", "%10.6m",  0., 24., 0., 0., 0, 0, 0},
00064     {"DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0., 0, 0, 0},
00065 };
00066 //TODO decide appropiate TIME_OUT
00067 static INumberVectorProperty eqNum = {
00068     mydev, "EQUATORIAL_EOD_COORD", "Equatorial JNow", BASIC_GROUP, IP_RW, 0, IPS_IDLE,
00069     eq, NARRAY(eq), "", 0};
00070 
00071 /* Fundamental group */
00072 static ISwitchVectorProperty PowerSw    = { mydev, "CONNECTION" , "Connection", COMM_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0};
00073 static IText PortT[]            = {{"PORT", "Port", 0, 0, 0, 0}};
00074 static ITextVectorProperty Port     = { mydev, "DEVICE_PORT", "Ports", COMM_GROUP, IP_RW, 0, IPS_IDLE, PortT, NARRAY(PortT), "", 0};
00075 
00076 /* Movement group */
00077 static ISwitchVectorProperty OnCoordSetSw    = { mydev, "ON_COORD_SET", "On Set", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, OnCoordSetS, NARRAY(OnCoordSetS), "", 0};
00078 static ISwitchVectorProperty abortSlewSw     = { mydev, "ABORT_MOTION", "Abort Slew/Track", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, abortSlewS, NARRAY(abortSlewS), "", 0};
00079 static ISwitchVectorProperty SlewModeSw      = { mydev, "Slew rate", "", MOVE_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, SlewModeS, NARRAY(SlewModeS), "", 0};
00080 
00081 static ISwitchVectorProperty MovementSw      = { mydev, "MOVEMENT", "Move toward", MOVE_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, MovementS, NARRAY(MovementS), "", 0};
00082 
00083 
00084 /* send client definitions of all properties */
00085 void ISInit()
00086 {
00087   static int isInit=0;
00088 
00089  if (isInit)
00090   return;
00091 
00092  isInit = 1;
00093 
00094   PortT[0].text = strcpy(new char[32], "/dev/ttyS0");
00095   
00096   telescope = new CelestronGPS();
00097 
00098   IEAddTimer (POLLMS, ISPoll, NULL);
00099 }
00100 
00101 void ISGetProperties (const char *dev)
00102 { ISInit(); telescope->ISGetProperties(dev);}
00103 void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
00104 { ISInit(); telescope->ISNewSwitch(dev, name, states, names, n);}
00105 void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
00106 { ISInit(); telescope->ISNewText(dev, name, texts, names, n);}
00107 void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
00108 { ISInit(); telescope->ISNewNumber(dev, name, values, names, n);}
00109 void ISPoll (void *p) { telescope->ISPoll(); IEAddTimer (POLLMS, ISPoll, NULL); p=p;}
00110 void ISNewBLOB (const char */*dev*/, const char */*name*/, int */*sizes[]*/, char **/*blobs[]*/, char **/*formats[]*/, char **/*names[]*/, int /*n*/)
00111 {}
00112 
00113 /**************************************************
00114 *** LX200 Generic Implementation
00115 ***************************************************/
00116 
00117 CelestronGPS::CelestronGPS()
00118 {
00119 
00120    targetRA  = lastRA = 0;
00121    targetDEC = lastDEC = 0;
00122    currentSet   = 0;
00123    lastSet      = -1;
00124    lastMove[0] = lastMove[1] = lastMove[2] = lastMove[3] = 0;
00125 
00126    JD = 0;
00127 
00128    // Children call parent routines, this is the default
00129    IDLog("initilizaing from Celeston GPS device...\n");
00130 
00131 }
00132 
00133 void CelestronGPS::ISGetProperties(const char *dev)
00134 {
00135 
00136  if (dev && strcmp (mydev, dev))
00137     return;
00138 
00139   // COMM_GROUP
00140   IDDefSwitch (&PowerSw, NULL);
00141   IDDefText   (&Port, NULL);
00142   
00143   // BASIC_GROUP
00144   IDDefNumber (&eqNum, NULL);
00145   IDDefSwitch (&OnCoordSetSw, NULL);
00146   IDDefSwitch (&abortSlewSw, NULL);
00147   IDDefSwitch (&SlewModeSw, NULL);
00148 
00149   // Movement group
00150   IDDefSwitch (&MovementSw, NULL);
00151   
00152   /* Send the basic data to the new client if the previous client(s) are already connected. */      
00153   if (PowerSw.s == IPS_OK)
00154         getBasicData();
00155 
00156 }
00157 
00158 void CelestronGPS::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
00159 {
00160         IText *tp;
00161 
00162     // suppress warning
00163     n=n;
00164     // ignore if not ours //
00165     if (strcmp (dev, mydev))
00166         return;
00167 
00168     if (!strcmp(name, Port.name) )
00169     {
00170       Port.s = IPS_OK;
00171 
00172       tp = IUFindText( &Port, names[0] );
00173       if (!tp)
00174        return;
00175 
00176       tp->text = new char[strlen(texts[0])+1];
00177       strcpy(tp->text, texts[0]);
00178       IDSetText (&Port, NULL);
00179       return;
00180     }
00181 }
00182 
00183 int CelestronGPS::handleCoordSet()
00184 {
00185 
00186   int i=0;
00187   char RAStr[32], DecStr[32];
00188 
00189   switch (currentSet)
00190   {
00191 
00192     // Slew
00193     case 0:
00194           lastSet = 0;
00195       if (eqNum.s == IPS_BUSY)
00196       {
00197          StopNSEW();
00198          // sleep for 500 mseconds
00199          usleep(500000);
00200       }
00201 
00202       if ((i = SlewToCoords(targetRA, targetDEC)))
00203       {
00204         slewError(i);
00205         return (-1);
00206       }
00207 
00208       eqNum.s = IPS_BUSY;
00209       fs_sexa(RAStr, targetRA, 2, 3600);
00210       fs_sexa(DecStr, targetDEC, 2, 3600);
00211       IDSetNumber(&eqNum, "Slewing to JNOW RA %s - DEC %s", RAStr, DecStr);
00212       IDLog("Slewing to JNOW RA %s - DEC %s", RAStr, DecStr);
00213       break;
00214 
00215 
00216   // Track
00217   case 1: 
00218           if (eqNum.s == IPS_BUSY)
00219       {
00220           StopNSEW();
00221          // sleep for 500 mseconds
00222          usleep(500000);
00223       }
00224 
00225       if ( (fabs ( targetRA - currentRA ) >= TRACKING_THRESHOLD) ||
00226            (fabs (targetDEC - currentDEC) >= TRACKING_THRESHOLD))
00227       {
00228 
00229             IDLog("Exceeded Tracking threshold, will attempt to slew to the new target.\n");
00230         IDLog("targetRA is %g, currentRA is %g\n", targetRA, currentRA);
00231             IDLog("targetDEC is %g, currentDEC is %g\n*************************\n", targetDEC, currentDEC);
00232 
00233             if (( i =  SlewToCoords(targetRA, targetDEC)))
00234         {
00235                 slewError(i);
00236                 return (-1);
00237         }
00238         
00239         fs_sexa(RAStr, targetRA, 2, 3600);
00240             fs_sexa(DecStr, targetDEC, 2, 3600);
00241         eqNum.s = IPS_BUSY;
00242         IDSetNumber(&eqNum, "Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
00243         IDLog("Slewing to JNOW RA %s - DEC %s", RAStr, DecStr);
00244       }
00245       else
00246       {
00247         IDLog("Tracking called, but tracking threshold not reached yet.\n");
00248         eqNum.s = IPS_OK;
00249         eqNum.np[0].value = currentRA;
00250         eqNum.np[1].value = currentDEC;
00251             if (lastSet != 1)
00252           IDSetNumber(&eqNum, "Tracking...");
00253         else
00254           IDSetNumber(&eqNum, NULL);
00255       }
00256       lastSet = 1;
00257       break;
00258       
00259     // Sync
00260     case 2:
00261           lastSet = 2;
00262       OnCoordSetSw.s = IPS_OK;
00263       SyncToCoords(targetRA, targetDEC);
00264           eqNum.s = IPS_OK;
00265       IDSetNumber(&eqNum, "Synchronization successful.");
00266       break;
00267    }
00268 
00269    return (0);
00270 
00271 }
00272 
00273 void CelestronGPS::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
00274 {
00275         double newRA=0, newDEC=0;
00276 
00277         // ignore if not ours //
00278     if (strcmp (dev, mydev))
00279         return;
00280 
00281     struct tm *tp;
00282     time_t t;
00283 
00284     time (&t);
00285     tp = gmtime (&t);
00286 
00287     if (!strcmp (name, eqNum.name))
00288     {
00289       int i=0, nset=0;
00290 
00291       if (checkPower(&eqNum))
00292        return;
00293 
00294         for (nset = i = 0; i < n; i++)
00295         {
00296         INumber *eqp = IUFindNumber (&eqNum, names[i]);
00297         if (eqp == &eq[0])
00298         {
00299                     newRA = values[i];
00300             nset += newRA >= 0 && newRA <= 24.0;
00301         } else if (eqp == &eq[1])
00302         {
00303             newDEC = values[i];
00304             nset += newDEC >= -90.0 && newDEC <= 90.0;
00305         }
00306         }
00307 
00308       if (nset == 2)
00309       {
00310        //eqNum.s = IPS_BUSY;
00311 
00312        tp->tm_mon   += 1;
00313        tp->tm_year  += 1900;
00314 
00315        // update JD
00316            JD = UTtoJD(tp);
00317 
00318        IDLog("We recevined JNOW RA %f - DEC %f\n", newRA, newDEC);;
00319        /*apparentCoord( (double) J2000, JD, &newRA, &newDEC);
00320        IDLog("Processed to RA %f - DEC %f\n", newRA, newDEC);*/
00321 
00322            //eqNum.np[0].value = values[0];
00323            //eqNum.np[1].value = values[1];
00324            targetRA  = newRA;
00325            targetDEC = newDEC;
00326            
00327            if (MovementSw.s == IPS_BUSY)
00328            {
00329         for (int i=0; i < 4; i++)
00330         {
00331                 lastMove[i] = 0;
00332                 MovementS[i].s = ISS_OFF;
00333         }
00334         
00335         MovementSw.s = IPS_IDLE;
00336         IDSetSwitch(&MovementSw, NULL);
00337            }
00338 
00339            if (handleCoordSet())
00340            {
00341             eqNum.s = IPS_IDLE;
00342             IDSetNumber(&eqNum, NULL);
00343            }
00344         }
00345         else
00346         {
00347         eqNum.s = IPS_IDLE;
00348         IDSetNumber(&eqNum, "RA or Dec missing or invalid.");
00349         }
00350 
00351         return;
00352      }
00353 }
00354 
00355 void CelestronGPS::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
00356 {
00357 
00358         int index;
00359     ISwitch *swp;
00360 
00361     // Suppress warning
00362     names = names;
00363 
00364     //IDLog("in new Switch with Device= %s and Property= %s and #%d items\n", dev, name,n);
00365     //IDLog("SolarSw name is %s\n", SolarSw.name);
00366 
00367     // ignore if not ours //
00368     if (strcmp (dev, mydev))
00369         return;
00370 
00371     // FIRST Switch ALWAYS for power
00372     if (!strcmp (name, PowerSw.name))
00373     {
00374      IUResetSwitches(&PowerSw);
00375      IUUpdateSwitches(&PowerSw, states, names, n);
00376      powerTelescope();
00377      return;
00378     }
00379 
00380     if (!strcmp(name, OnCoordSetSw.name))
00381     {
00382       if (checkPower(&OnCoordSetSw))
00383        return;
00384 
00385       IUResetSwitches(&OnCoordSetSw);
00386       IUUpdateSwitches(&OnCoordSetSw, states, names, n);
00387       currentSet = getOnSwitch(&OnCoordSetSw);
00388     }
00389     
00390     // Abort Slew
00391     if (!strcmp (name, abortSlewSw.name))
00392     {
00393       if (checkPower(&abortSlewSw))
00394       {
00395         abortSlewSw.s = IPS_IDLE;
00396         IDSetSwitch(&abortSlewSw, NULL);
00397         return;
00398       }
00399       
00400       IUResetSwitches(&abortSlewSw);
00401       StopNSEW();
00402 
00403         if (eqNum.s == IPS_BUSY)
00404         {
00405         abortSlewSw.s = IPS_OK;
00406         eqNum.s       = IPS_IDLE;
00407         IDSetSwitch(&abortSlewSw, "Slew aborted.");
00408         IDSetNumber(&eqNum, NULL);
00409             }
00410         else if (MovementSw.s == IPS_BUSY)
00411         {
00412             
00413         for (int i=0; i < 4; i++)
00414           lastMove[i] = 0;
00415         
00416         MovementSw.s  = IPS_IDLE; 
00417         abortSlewSw.s = IPS_OK;     
00418         eqNum.s       = IPS_IDLE;
00419         IUResetSwitches(&MovementSw);
00420         IUResetSwitches(&abortSlewSw);
00421         IDSetSwitch(&abortSlewSw, "Slew aborted.");
00422         IDSetSwitch(&MovementSw, NULL);
00423         IDSetNumber(&eqNum, NULL);
00424         }
00425         else
00426         {
00427             IUResetSwitches(&MovementSw);
00428             abortSlewSw.s = IPS_IDLE;
00429             IDSetSwitch(&abortSlewSw, NULL);
00430         }
00431 
00432         return;
00433     }
00434 
00435     // Slew mode
00436     if (!strcmp (name, SlewModeSw.name))
00437     {
00438       if (checkPower(&SlewModeSw))
00439        return;
00440 
00441       IUResetSwitches(&SlewModeSw);
00442       IUUpdateSwitches(&SlewModeSw, states, names, n);
00443       index = getOnSwitch(&SlewModeSw);
00444       SetRate(index);
00445           
00446       SlewModeSw.s = IPS_OK;
00447       IDSetSwitch(&SlewModeSw, NULL);
00448       return;
00449     }
00450 
00451     // Movement
00452     if (!strcmp (name, MovementSw.name))
00453     {
00454       if (checkPower(&MovementSw))
00455        return;
00456 
00457      index = -1;
00458      IUUpdateSwitches(&MovementSw, states, names, n);
00459      swp = IUFindSwitch(&MovementSw, names[0]);
00460      
00461      if (!swp)
00462      {
00463         StopNSEW();
00464         IUResetSwitches(&MovementSw);
00465         MovementSw.s = IPS_IDLE;
00466         IDSetSwitch(&MovementSw, NULL);
00467      }
00468      
00469      if (swp == &MovementS[0]) index = 0;
00470      else if (swp == &MovementS[1]) index = 1;
00471      else if (swp == &MovementS[2]) index = 2;
00472      else index = 3;
00473      
00474      lastMove[index] = lastMove[index] == 0 ? 1 : 0;
00475      if (lastMove[index] == 0)
00476        MovementS[index].s = ISS_OFF;
00477          
00478        // North/South movement is illegal
00479        if (lastMove[NORTH] && lastMove[SOUTH])  
00480        {
00481          StopNSEW();
00482           for (int i=0; i < 4; i++)
00483             lastMove[i] = 0;
00484             
00485           IUResetSwitches(&MovementSw);
00486           MovementSw.s       = IPS_IDLE;
00487           IDSetSwitch(&MovementSw, "Slew aborted.");
00488           return;
00489        }
00490        
00491        // East/West movement is illegal
00492        if (lastMove[EAST] && lastMove[WEST])    
00493        {
00494           StopNSEW();
00495           for (int i=0; i < 4; i++)
00496                 lastMove[i] = 0;
00497            
00498           IUResetSwitches(&MovementSw);
00499               MovementSw.s       = IPS_IDLE;
00500           IDSetSwitch(&MovementSw, "Slew aborted.");
00501           return;
00502        }
00503           
00504           //IDLog("We have switch %d \n ", index);
00505       //IDLog("NORTH: %d -- WEST: %d -- EAST: %d -- SOUTH %d\n", lastMove[0], lastMove[1], lastMove[2], lastMove[3]);
00506 
00507       if (lastMove[index] == 1)
00508         StartSlew(index);
00509       else
00510         StopSlew(index);
00511 
00512           if (!lastMove[0] && !lastMove[1] && !lastMove[2] && !lastMove[3])
00513          MovementSw.s = IPS_IDLE;
00514       
00515       if (lastMove[index] == 0)
00516          IDSetSwitch(&MovementSw, "Moving toward %s aborted.", Direction[index]);
00517       else
00518       {
00519          MovementSw.s = IPS_BUSY;
00520          IDSetSwitch(&MovementSw, "Moving %s...", Direction[index]);
00521       }
00522       return;
00523     }
00524     
00525 }
00526 
00527 
00528 int CelestronGPS::getOnSwitch(ISwitchVectorProperty *sp)
00529 {
00530  for (int i=0; i < sp->nsp ; i++)
00531      if (sp->sp[i].s == ISS_ON)
00532       return i;
00533 
00534  return -1;
00535 }
00536 
00537 
00538 int CelestronGPS::checkPower(ISwitchVectorProperty *sp)
00539 {
00540   if (PowerSw.s != IPS_OK)
00541   {
00542     if (!strcmp(sp->label, ""))
00543        IDMessage (mydev, "Cannot change property %s while the telescope is offline.", sp->name);
00544     else
00545        IDMessage (mydev, "Cannot change property %s while the telescope is offline.", sp->label);
00546        
00547     sp->s = IPS_IDLE;
00548     IDSetSwitch(sp, NULL);
00549     return -1;
00550   }
00551 
00552   return 0;
00553 }
00554 
00555 int CelestronGPS::checkPower(INumberVectorProperty *np)
00556 {
00557   if (PowerSw.s != IPS_OK)
00558   {
00559     if (!strcmp(np->label, ""))
00560        IDMessage (mydev, "Cannot change property %s while the telescope is offline.", np->name);
00561     else
00562        IDMessage (mydev, "Cannot change property %s while the telescope is offline.", np->label);
00563        
00564     np->s = IPS_IDLE;
00565     IDSetNumber(np, NULL);
00566     return -1;
00567   }
00568   return 0;
00569 }
00570 
00571 int CelestronGPS::checkPower(ITextVectorProperty *tp)
00572 {
00573 
00574   if (PowerSw.s != IPS_OK)
00575   {
00576     if (!strcmp(tp->label, ""))
00577        IDMessage (mydev, "Cannot change property %s while the telescope is offline.", tp->name);
00578     else
00579        IDMessage (mydev, "Cannot change property %s while the telescope is offline.", tp->label);
00580        
00581     tp->s = IPS_IDLE;
00582     IDSetText(tp, NULL);
00583     return -1;
00584   }
00585 
00586   return 0;
00587 
00588 }
00589 
00590 void CelestronGPS::ISPoll()
00591 {
00592        double dx, dy;
00593        double currentRA, currentDEC;
00594        int status;
00595 
00596     switch (eqNum.s)
00597     {
00598     case IPS_IDLE:
00599     if (PowerSw.s != IPS_OK)
00600      break;
00601     currentRA = GetRA();
00602     currentDEC = GetDec();
00603 
00604         if ( fabs (currentRA - lastRA) > 0.01 || fabs (currentDEC - lastDEC) > 0.01)
00605     {
00606             eqNum.np[0].value = currentRA;
00607         eqNum.np[1].value = currentDEC;
00608         lastRA  = currentRA;
00609         lastDEC = currentDEC;
00610         IDSetNumber (&eqNum, NULL);
00611 
00612     }
00613         break;
00614 
00615         case IPS_BUSY:
00616         currentRA = GetRA();
00617         currentDEC = GetDec();
00618         dx = targetRA - currentRA;
00619         dy = targetDEC - currentDEC;
00620 
00621         IDLog("targetRA is %f, currentRA is %f\n", (float) targetRA, (float) currentRA);
00622         IDLog("targetDEC is %f, currentDEC is %f\n****************************\n", (float) targetDEC, (float) currentDEC);
00623 
00624         eqNum.np[0].value = currentRA;
00625         eqNum.np[1].value = currentDEC;
00626 
00627         status = CheckCoords(targetRA, targetDEC);
00628 
00629         // Wait until acknowledged or within 3.6', change as desired.
00630         switch (status)
00631         {
00632         case 0:     /* goto in progress */
00633         IDSetNumber (&eqNum, NULL);
00634         break;
00635         case 1:     /* goto complete within tolerance */
00636         case 2:     /* goto complete but outside tolerance */
00637         currentRA = targetRA;
00638         currentDEC = targetDEC;
00639 
00640         /*apparentCoord( JD, (double) J2000, &currentRA, &currentDEC);*/
00641 
00642         eqNum.np[0].value = currentRA;
00643         eqNum.np[1].value = currentDEC;
00644 
00645         eqNum.s = IPS_OK;
00646 
00647         if (currentSet == 0)
00648         {
00649           IUResetSwitches(&OnCoordSetSw);
00650           OnCoordSetSw.sp[0].s = ISS_ON;
00651           IDSetNumber (&eqNum, "Slew is complete");
00652         }
00653         else
00654         {
00655           IUResetSwitches(&OnCoordSetSw);
00656           OnCoordSetSw.sp[1].s = ISS_ON;
00657           IDSetNumber (&eqNum, "Slew is complete. Tracking...");
00658         }
00659         
00660         IDSetSwitch (&OnCoordSetSw, NULL);
00661         break;
00662         }   
00663         break;
00664 
00665     case IPS_OK:
00666     if (PowerSw.s != IPS_OK)
00667      break;
00668     currentRA = GetRA();
00669     currentDEC = GetDec();
00670 
00671         if ( fabs (currentRA - lastRA) > 0.01 || fabs (currentDEC - lastDEC) > 0.01)
00672     {
00673 
00674         eqNum.np[0].value = currentRA;
00675         eqNum.np[1].value = currentDEC;
00676         lastRA  = currentRA;
00677         lastDEC = currentDEC;
00678         IDSetNumber (&eqNum, NULL);
00679 
00680     }
00681         break;
00682 
00683 
00684     case IPS_ALERT:
00685         break;
00686     }
00687 
00688     switch (MovementSw.s)
00689     {
00690       case IPS_IDLE:
00691        break;
00692      case IPS_BUSY:
00693          currentRA = GetRA();
00694          currentDEC = GetDec();
00695 
00696          /*apparentCoord( JD, (double) J2000, &currentRA, &currentDEC);*/
00697 
00698 
00699          eqNum.np[0].value = currentRA;
00700          eqNum.np[1].value = currentDEC;
00701 
00702          IDSetNumber (&eqNum, NULL);
00703 
00704          break;
00705      case IPS_OK:
00706        break;
00707      case IPS_ALERT:
00708        break;
00709      }
00710 
00711 }
00712 
00713 void CelestronGPS::getBasicData()
00714 {
00715 
00716   targetRA = GetRA();
00717   targetDEC = GetDec();
00718 
00719   eqNum.np[0].value = targetRA;
00720   eqNum.np[1].value = targetDEC;
00721 
00722   IDSetNumber(&eqNum, NULL);
00723 
00724 }
00725 
00726 void CelestronGPS::powerTelescope()
00727 {
00728 
00729      switch (PowerSw.sp[0].s)
00730      {
00731       case ISS_ON:
00732 
00733          if (ConnectTel(Port.tp[0].text) < 0)
00734      {
00735        PowerS[0].s = ISS_OFF;
00736        PowerS[1].s = ISS_ON;
00737        IDSetSwitch (&PowerSw, "Error connecting to port %s", Port.tp[0].text);
00738        return;
00739      }
00740 
00741     PowerSw.s = IPS_OK;
00742     IDSetSwitch (&PowerSw, "Telescope is online. Retrieving basic data...");
00743     getBasicData();
00744     break;
00745 
00746      case ISS_OFF:
00747          IDSetSwitch (&PowerSw, "Telescope is offline.");
00748      IDLog("Telescope is offline.");
00749      DisconnectTel();
00750      break;
00751 
00752     }
00753 }
00754 
00755 void CelestronGPS::slewError(int slewCode)
00756 {
00757     eqNum.s = IPS_IDLE;
00758 
00759     switch (slewCode)
00760     {
00761       case 1:
00762        IDSetNumber (&eqNum, "Invalid newDec in SlewToCoords");
00763        break;
00764       case 2:
00765        IDSetNumber (&eqNum, "RA count overflow in SlewToCoords");
00766        break;
00767       case 3:
00768        IDSetNumber (&eqNum, "Dec count overflow in SlewToCoords");
00769        break;
00770       case 4:
00771        IDSetNumber (&eqNum, "No acknowledgement from telescope after SlewToCoords");
00772        break;
00773       default:
00774        IDSetNumber (&eqNum, "Unknown error");
00775        break;
00776     }
00777 
00778 }

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