00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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;}
00056
00057
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
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;
00077 };
00078
00084 class TelescopeTcp : public Telescope
00085 {
00086 Q_OBJECT
00087 public:
00088 TelescopeTcp(const QString &name,const QString ¶ms);
00089 ~TelescopeTcp(void)
00090 {
00091 hangup();
00092 }
00093 private:
00094 bool isConnected(void) const
00095 {
00096
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_