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

kstars

lx200gps.cpp

Go to the documentation of this file.
00001 /*
00002     LX200 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 */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <unistd.h>
00025 
00026 #include "lx200gps.h"
00027 #include "lx200driver.h"
00028 
00029 #define GPSGroup   "Extended GPS Features"
00030 
00031 extern LX200Generic *telescope;
00032 extern int MaxReticleFlashRate;
00033 
00034 static ISwitch GPSPowerS[]      = {{ "On", "", ISS_OFF, 0, 0}, {"Off", "", ISS_ON, 0, 0}};
00035 static ISwitch GPSStatusS[]     = {{ "Sleep", "", ISS_OFF, 0, 0}, {"Wake up", "", ISS_OFF, 0 ,0}, {"Restart", "", ISS_OFF, 0, 0}};
00036 static ISwitch GPSUpdateS[]     = { {"Update", "", ISS_OFF, 0, 0}};
00037 static ISwitch AltDecPecS[]     = {{ "Enable", "", ISS_OFF, 0 ,0}, {"Disable", "", ISS_OFF, 0 ,0}};
00038 static ISwitch AzRaPecS[]       = {{ "Enable", "", ISS_OFF, 0, 0}, {"Disable", "", ISS_OFF, 0 ,0}};
00039 static ISwitch SelenSyncS[]     = {{ "Sync", "",  ISS_OFF, 0, 0}};
00040 static ISwitch AltDecBackSlashS[]   = {{ "Activate", "", ISS_OFF, 0, 0}};
00041 static ISwitch AzRaBackSlashS[]     = {{ "Activate", "", ISS_OFF, 0, 0}};
00042 static ISwitch OTAUpdateS[]     = {{ "Update", "", ISS_OFF, 0, 0}};
00043 
00044 static ISwitchVectorProperty GPSPowerSw    = { mydev, "GPS Power", "", GPSGroup, IP_RW, ISR_1OFMANY, 0 , IPS_IDLE, GPSPowerS, NARRAY(GPSPowerS), "", 0};
00045 static ISwitchVectorProperty GPSStatusSw   = { mydev, "GPS Status", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, GPSStatusS, NARRAY(GPSStatusS), "", 0};
00046 static ISwitchVectorProperty GPSUpdateSw   = { mydev, "GPS System", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, GPSUpdateS, NARRAY(GPSUpdateS), "", 0};
00047 static ISwitchVectorProperty AltDecPecSw   = { mydev, "Alt/Dec PEC", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, AltDecPecS, NARRAY(AltDecPecS), "", 0};
00048 static ISwitchVectorProperty AzRaPecSw     = { mydev, "Az/Ra PEC", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, AzRaPecS, NARRAY(AzRaPecS), "", 0};
00049 static ISwitchVectorProperty SelenSyncSw   = { mydev, "Selenographic Sync", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, SelenSyncS, NARRAY(SelenSyncS), "", 0};
00050 static ISwitchVectorProperty AltDecBackSlashSw  = { mydev, "Alt/Dec Anti-backslash", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, AltDecBackSlashS, NARRAY(AltDecBackSlashS), "", 0};
00051 static ISwitchVectorProperty AzRaBackSlashSw    = { mydev, "Az/Ra Anti-backslash", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, AzRaBackSlashS, NARRAY(AzRaBackSlashS), "", 0};
00052 static ISwitchVectorProperty OTAUpdateSw    = { mydev, "OTA Update", "", GPSGroup, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, OTAUpdateS, NARRAY(OTAUpdateS), "", 0};
00053 
00054 static INumber Temp[]   = { {"Temp.", "", "%g", -200., 500., 0., 0., 0, 0, 0 } };
00055 static INumberVectorProperty OTATemp =   { mydev, "OTA Temperature (C)", "", GPSGroup, IP_RO, 0, IPS_IDLE, Temp, NARRAY(Temp), "", 0};
00056 
00057 void updateTemp(void * /*p*/);
00058 
00059 void changeLX200GPSDeviceName(const char *newName)
00060 {
00061  strcpy(GPSPowerSw.device, newName);
00062  strcpy(GPSStatusSw.device, newName );
00063  strcpy(GPSUpdateSw.device, newName  );
00064  strcpy(AltDecPecSw.device, newName );
00065  strcpy(AzRaPecSw.device,newName  );
00066  strcpy(SelenSyncSw.device, newName );
00067  strcpy(AltDecBackSlashSw.device, newName );
00068  strcpy(AzRaBackSlashSw.device, newName );
00069  strcpy(OTATemp.device, newName );
00070  strcpy(OTAUpdateSw.device, newName);
00071  
00072 }
00073 
00074 LX200GPS::LX200GPS() : LX200_16()
00075 {
00076    IEAddTimer(900000, updateTemp, NULL);
00077    
00078 }
00079 
00080 void LX200GPS::ISGetProperties (const char *dev)
00081 {
00082 
00083 if (dev && strcmp (thisDevice, dev))
00084     return;
00085 
00086 // process parent first
00087    LX200_16::ISGetProperties(dev);
00088 
00089 IDDefSwitch (&GPSPowerSw, NULL);
00090 IDDefSwitch (&GPSStatusSw, NULL);
00091 IDDefSwitch (&GPSUpdateSw, NULL);
00092 IDDefSwitch (&AltDecPecSw, NULL);
00093 IDDefSwitch (&AzRaPecSw, NULL);
00094 IDDefSwitch (&SelenSyncSw, NULL);
00095 IDDefSwitch (&AltDecBackSlashSw, NULL);
00096 IDDefSwitch (&AzRaBackSlashSw, NULL);
00097 IDDefNumber (&OTATemp, NULL);
00098 IDDefSwitch (&OTAUpdateSw, NULL);
00099 
00100 }
00101 
00102 void LX200GPS::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
00103 {
00104     // ignore if not ours //
00105     if (strcmp (dev, thisDevice))
00106         return;
00107 
00108      LX200_16::ISNewText (dev, name, texts, names, n);
00109 }
00110 
00111 void LX200GPS::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
00112 {
00113         
00114     LX200_16::ISNewNumber (dev, name, values, names, n);
00115 
00116  }
00117 
00118 
00119  void LX200GPS::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
00120  {
00121     int index;
00122     char msg[64];
00123 
00124     if (strcmp (dev, thisDevice))
00125         return;
00126 
00127     /* GPS Power */
00128     if (!strcmp(name,GPSPowerSw.name))
00129     {
00130        if (checkPower(&GPSPowerSw))
00131        return;
00132 
00133       IUResetSwitches(&GPSPowerSw);
00134       IUUpdateSwitches(&GPSPowerSw, states, names, n);
00135       index = getOnSwitch(&GPSPowerSw);
00136       index == 0 ? turnGPSOn() : turnGPSOff();
00137       GPSPowerSw.s = IPS_OK;
00138       IDSetSwitch (&GPSPowerSw, index == 0 ? "GPS System is ON" : "GPS System is OFF" );
00139       return;
00140     }
00141 
00142     /* GPS Status Update */
00143     if (!strcmp(name,GPSStatusSw.name))
00144     {
00145        if (checkPower(&GPSStatusSw))
00146        return;
00147 
00148       IUResetSwitches(&GPSStatusSw);
00149       IUUpdateSwitches(&GPSStatusSw, states, names, n);
00150       index = getOnSwitch(&GPSStatusSw);
00151 
00152       if (index == 0)
00153       {
00154        gpsSleep();
00155        strcpy(msg, "GPS system is in sleep mode.");
00156       }
00157       else if (index == 1)
00158       {
00159        gpsWakeUp();
00160            strcpy(msg, "GPS system is reactivated.");
00161       }
00162       else
00163       {
00164        gpsRestart();
00165        strcpy(msg, "GPS system is restarting...");
00166        updateTime();
00167        updateLocation();
00168       }
00169 
00170     GPSStatusSw.s = IPS_OK;
00171     IDSetSwitch (&GPSStatusSw, "%s", msg);
00172     return;
00173 
00174     }
00175 
00176     /* GPS Update */
00177     if (!strcmp(name,GPSUpdateSw.name))
00178     {
00179        if (checkPower(&GPSUpdateSw))
00180        return;
00181 
00182      GPSUpdateSw.s = IPS_OK;
00183      IDSetSwitch(&GPSUpdateSw, "Updating GPS system. This operation might take few minutes to complete...");
00184      if (updateGPS_System())
00185      {
00186         IDSetSwitch(&GPSUpdateSw, "GPS system update successful.");
00187     updateTime();
00188     updateLocation();
00189      }
00190      else
00191      {
00192         GPSUpdateSw.s = IPS_IDLE;
00193         IDSetSwitch(&GPSUpdateSw, "GPS system update failed.");
00194      }
00195      return;
00196     }
00197 
00198     /* Alt Dec Periodic Error correction */
00199     if (!strcmp(name, AltDecPecSw.name))
00200     {
00201        if (checkPower(&AltDecPecSw))
00202        return;
00203 
00204       IUResetSwitches(&AltDecPecSw);
00205       IUUpdateSwitches(&AltDecPecSw, states, names, n);
00206       index = getOnSwitch(&AltDecPecSw);
00207       
00208        if (index == 0)
00209       {
00210         enableDecAltPec();
00211     strcpy (msg, "Alt/Dec Compensation Enabled");
00212       }
00213       else
00214       {
00215         disableDecAltPec();
00216     strcpy (msg, "Alt/Dec Compensation Disabled");
00217       }
00218 
00219       AltDecPecSw.s = IPS_OK;
00220       IDSetSwitch(&AltDecPecSw, "%s", msg);
00221 
00222       return;
00223     }
00224 
00225     /* Az RA periodic error correction */
00226     if (!strcmp(name, AzRaPecSw.name))
00227     {
00228        if (checkPower(&AzRaPecSw))
00229        return; 
00230 
00231       IUResetSwitches(&AzRaPecSw);
00232       IUUpdateSwitches(&AzRaPecSw, states, names, n);
00233       index = getOnSwitch(&AzRaPecSw);
00234 
00235        if (index == 0)
00236       {
00237         enableRaAzPec();
00238     strcpy (msg, "Ra/Az Compensation Enabled");
00239       }
00240       else
00241       {
00242         disableRaAzPec();
00243     strcpy (msg, "Ra/Az Compensation Disabled");
00244       }
00245 
00246       AzRaPecSw.s = IPS_OK;
00247       IDSetSwitch(&AzRaPecSw, "%s", msg);
00248 
00249       return;
00250     }
00251 
00252    if (!strcmp(name, AltDecBackSlashSw.name))
00253    {
00254       if (checkPower(&AltDecBackSlashSw))
00255       return;
00256 
00257      activateAltDecAntiBackSlash();
00258      AltDecBackSlashSw.s = IPS_OK;
00259      IDSetSwitch(&AltDecBackSlashSw, "Alt/Dec Anti-backslash enabled");
00260      return;
00261    }
00262 
00263    if (!strcmp(name, AzRaBackSlashSw.name))
00264    {
00265      if (checkPower(&AzRaBackSlashSw))
00266       return;
00267 
00268      activateAzRaAntiBackSlash();
00269      AzRaBackSlashSw.s = IPS_OK;
00270      IDSetSwitch(&AzRaBackSlashSw, "Az/Ra Anti-backslash enabled");
00271      return;
00272    }
00273    
00274    if (!strcmp(name, OTAUpdateSw.name))
00275    {
00276      if (checkPower(&OTAUpdateSw))
00277       return;
00278       
00279       IUResetSwitches(&OTAUpdateSw);
00280       
00281       if (getOTATemp(&OTATemp.np[0].value) < 0)
00282       {
00283     OTATemp.s = IPS_ALERT;
00284     IDSetNumber(&OTATemp, "Error: OTA temperature read timed out.");
00285       }
00286       else
00287       {
00288     OTATemp.s = IPS_OK;
00289     IDSetNumber(&OTATemp, NULL);
00290       }
00291       
00292       return;
00293    }
00294       
00295      
00296    
00297    LX200_16::ISNewSwitch (dev, name, states, names,  n);
00298 
00299 }
00300 
00301  void LX200GPS::ISPoll ()
00302  {
00303 
00304    LX200_16::ISPoll();
00305 
00306 
00307  }
00308  
00309  void updateTemp(void * /*p*/)
00310  {
00311    
00312    if (telescope->isTelescopeOn())
00313    {
00314      if (getOTATemp(&OTATemp.np[0].value) < 0)
00315      {
00316        OTATemp.s = IPS_ALERT;
00317        IDSetNumber(&OTATemp, "Error: OTA temperature read timed out.");
00318        return;
00319      }
00320      else
00321      {
00322         OTATemp.s = IPS_OK; 
00323     IDSetNumber(&OTATemp, NULL);
00324      }
00325    } 
00326  
00327    IEAddTimer(900000, updateTemp, NULL);
00328       
00329  }
00330 
00331  void LX200GPS::getBasicData()
00332  {
00333 
00334    //getOTATemp(&OTATemp.np[0].value);
00335    //IDSetNumber(&OTATemp, NULL);
00336    
00337    // process parent
00338    LX200_16::getBasicData();
00339  }
00340 

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