Stellarium 0.15.2
TelescopeClient.hpp
1 /*
2  * Stellarium Telescope Control Plug-in
3  *
4  * Copyright (C) 2006 Johannes Gajdosik
5  * Copyright (C) 2009 Bogdan Marinov
6  *
7  * This module was originally written by Johannes Gajdosik in 2006
8  * as a core module of Stellarium. In 2009 it was significantly extended with
9  * GUI features and later split as an external plug-in module by Bogdan Marinov.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
24  */
25 
26 #ifndef _TELESCOPE_HPP_
27 #define _TELESCOPE_HPP_
28 
29 #include <QHostAddress>
30 #include <QHostInfo>
31 #include <QList>
32 #include <QString>
33 #include <QTcpSocket>
34 #include <QObject>
35 
36 #include "StelApp.hpp"
37 #include "StelObject.hpp"
38 #include "InterpolatedPosition.hpp"
39 
40 class StelCore;
41 
42 qint64 getNow(void);
43 
44 enum Equinox {
45  EquinoxJ2000,
46  EquinoxJNow
47 };
48 
53 class TelescopeClient : public QObject, public StelObject
54 {
55  Q_OBJECT
56 public:
57  static TelescopeClient *create(const QString &url);
58  virtual ~TelescopeClient(void) {}
59 
60  // Method inherited from StelObject
61  QString getEnglishName(void) const {return name;}
62  QString getNameI18n(void) const {return nameI18n;}
63  Vec3f getInfoColor(void) const
64  {
65  return Vec3f(1, 1, 1);
66  }
75  QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const;
76  QString getType(void) const {return "Telescope";}
77  virtual double getAngularSize(const StelCore*) const {Q_ASSERT(0); return 0;} // TODO
78 
79  // Methods specific to telescope
80  virtual void telescopeGoto(const Vec3d &j2000Pos) = 0;
81  virtual bool isConnected(void) const = 0;
82  virtual bool hasKnownPosition(void) const = 0;
83  void addOcular(double fov) {if (fov>=0.0) oculars.push_back(fov);}
84  const QList<double> &getOculars(void) const {return oculars;}
85 
86  virtual bool prepareCommunication() {return false;}
87  virtual void performCommunication() {}
88 
89 protected:
90  TelescopeClient(const QString &name);
91  QString nameI18n;
92  const QString name;
93 private:
94  virtual bool isInitialized(void) const {return true;}
95  float getSelectPriority(const StelCore* core) const {Q_UNUSED(core); return -10.f;}
96 private:
97  QList<double> oculars; // fov of the oculars
98 };
99 
107 {
108 public:
109  TelescopeClientDummy(const QString &name, const QString &) : TelescopeClient(name)
110  {
111  desired_pos[0] = XYZ[0] = 1.0;
112  desired_pos[1] = XYZ[1] = 0.0;
113  desired_pos[2] = XYZ[2] = 0.0;
114  }
115  ~TelescopeClientDummy(void) {}
116  bool isConnected(void) const
117  {
118  return true;
119  }
120  bool prepareCommunication(void)
121  {
122  XYZ = XYZ * 31.0 + desired_pos;
123  const double lq = XYZ.lengthSquared();
124  if (lq > 0.0)
125  XYZ *= (1.0/std::sqrt(lq));
126  else
127  XYZ = desired_pos;
128  return true;
129  }
130  void telescopeGoto(const Vec3d &j2000Pos)
131  {
132  desired_pos = j2000Pos;
133  desired_pos.normalize();
134  }
135  bool hasKnownPosition(void) const
136  {
137  return true;
138  }
140  {
141  return XYZ;
142  }
143 
144 private:
145  Vec3d XYZ; // j2000 position
146  Vec3d desired_pos;
147 };
148 
155 {
156  Q_OBJECT
157 public:
158  TelescopeTCP(const QString &name, const QString &params, Equinox eq = EquinoxJ2000);
159  ~TelescopeTCP(void)
160  {
161  hangup();
162  }
163  bool isConnected(void) const
164  {
165  //return (tcpSocket->isValid() && !wait_for_connection_establishment);
166  return (tcpSocket->state() == QAbstractSocket::ConnectedState);
167  }
168 
169 private:
170  Vec3d getJ2000EquatorialPos(const StelCore* core=0) const;
171  bool prepareCommunication();
172  void performCommunication();
173  void telescopeGoto(const Vec3d &j2000Pos);
174  bool isInitialized(void) const
175  {
176  return (!address.isNull());
177  }
178  void performReading(void);
179  void performWriting(void);
180 
181 private:
182  void hangup(void);
183  QHostAddress address;
184  unsigned int port;
185  QTcpSocket * tcpSocket;
186  bool wait_for_connection_establishment;
187  qint64 end_of_timeout;
188  char readBuffer[120];
189  char *readBufferEnd;
190  char writeBuffer[120];
191  char *writeBufferEnd;
192  int time_delay;
193 
194  InterpolatedPosition interpolatedPosition;
195  virtual bool hasKnownPosition(void) const
196  {
197  return interpolatedPosition.isKnown();
198  }
199 
200  Equinox equinox;
201 
202 private slots:
203  void socketConnected(void);
204  void socketFailed(QAbstractSocket::SocketError socketError);
205 };
206 
207 #endif // _TELESCOPE_HPP_
This TelescopeClient class can controll a telescope by communicating to a server process ("telescope ...
Example Telescope class.
The base abstract class for sky objects used in Stellarium like Stars, Planets, Constellations etc...
Definition: StelObject.hpp:36
An abstract base class that should never be used directly, only inherited.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const =0
Get observer-centered equatorial coordinates at equinox J2000.
virtual double getAngularSize(const StelCore *) const
Return the angular radius of a circle containing the object as seen from the observer with the circle...
QString getInfoString(const StelCore *core, const InfoStringGroup &flags) const
TelescopeClient supports the following InfoStringGroup flags:
QString getEnglishName(void) const
Return object&#39;s name in english.
Vec3d getJ2000EquatorialPos(const StelCore *) const
Get observer-centered equatorial coordinates at equinox J2000.
Vec3f getInfoColor(void) const
Get a color used to display info about the object.
QString getType(void) const
Return object&#39;s type. It should be the name of the class.
QString getNameI18n(void) const
Return translated object&#39;s name.