Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

modules/Telescope.hpp

00001 /*
00002  * Author and Copyright of this file and of the stellarium telescope feature:
00003  * Johannes Gajdosik, 2006
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program 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
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #ifndef _TELESCOPE_HPP_
00021 #define _TELESCOPE_HPP_
00022 
00023 #include <QHostAddress>
00024 #include <QHostInfo>
00025 #include <QList>
00026 #include <QString>
00027 #include <QTcpSocket>
00028 #include <QObject>
00029 
00030 #include "StelObject.hpp"
00031 #include "StelNavigator.hpp"
00032 
00033 qint64 getNow(void);
00034 
00035 class Telescope : public QObject, public StelObject
00036 {
00037     Q_OBJECT
00038 public:
00039     static Telescope *create(const QString &url);
00040     virtual ~Telescope(void) {}
00041 
00042     // Method inherited from StelObject
00043     QString getEnglishName(void) const {return name;}
00044     QString getNameI18n(void) const {return nameI18n;}
00053     QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const;
00054     QString getType(void) const {return "Telescope";}
00055     virtual double getAngularSize(const StelCore* core) const {Q_ASSERT(0); return 0;}  // TODO
00056 
00057     // Methods specific to telescope
00058     virtual void telescopeGoto(const Vec3d &j2000Pos) = 0;
00059     virtual bool isConnected(void) const = 0;
00060     virtual bool hasKnownPosition(void) const = 0;
00061     void addOcular(double fov) {if (fov>=0.0) oculars.push_back(fov);}
00062     const QList<double> &getOculars(void) const {return oculars;}
00063 
00064     // all TCP (and all possible other style) communication shall be done in these functions:
00065     virtual bool prepareCommunication() {return false;}
00066     virtual void performCommunication() {}
00067 
00068 protected:
00069     Telescope(const QString &name);
00070     QString nameI18n;
00071     const QString name;
00072 private:
00073     bool isInitialized(void) const {return true;}
00074     float getSelectPriority(const StelNavigator *nav) const {return -10.f;}
00075 private:
00076     QList<double> oculars; // fov of the oculars
00077 };
00078 
00084 class TelescopeTcp : public Telescope
00085 {
00086     Q_OBJECT
00087 public:
00088     TelescopeTcp(const QString &name,const QString &params);
00089     ~TelescopeTcp(void)
00090     {
00091         hangup();
00092     }
00093 private:
00094     bool isConnected(void) const
00095     {
00096         //return (tcpSocket->isValid() && !wait_for_connection_establishment);
00097         return (tcpSocket->state() == QAbstractSocket::ConnectedState);
00098     }
00099     Vec3d getJ2000EquatorialPos(const StelNavigator *nav=0) const;
00100     bool prepareCommunication();
00101     void performCommunication();
00102     void telescopeGoto(const Vec3d &j2000Pos);
00103     bool isInitialized(void) const
00104     {
00105         return (!address.isNull());
00106     }
00107     void performReading(void);
00108     void performWriting(void);
00109 private:
00110     void hangup(void);
00111     void resetPositions(void);
00112     QHostAddress address;
00113     unsigned int port;
00114     QTcpSocket * tcpSocket;
00115     bool wait_for_connection_establishment;
00116     qint64 end_of_timeout;
00117     char readBuffer[120];
00118     char *readBufferEnd;
00119     char writeBuffer[120];
00120     char *writeBufferEnd;
00121     int time_delay;
00122     struct Position
00123     {
00124         qint64 server_micros;
00125         qint64 client_micros;
00126         Vec3d pos;
00127         int status;
00128     };
00129     Position positions[16];
00130     Position *position_pointer;
00131     Position *const end_position;
00132     virtual bool hasKnownPosition(void) const
00133     {
00134         return (position_pointer->client_micros != 0x7FFFFFFFFFFFFFFFLL);
00135     }
00136 private slots:
00137     void socketFailed(QAbstractSocket::SocketError socketError);
00138 };
00139 
00140 #endif // _TELESCOPE_HPP_

Generated on Mon Mar 22 09:55:38 2010 for Stellarium by  doxygen 1.5.5