Stellarium  0.16.1
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 const QString TELESCOPECLIENT_TYPE;
58  static TelescopeClient *create(const QString &url);
59  virtual ~TelescopeClient(void) {}
60 
61  // Method inherited from StelObject
62  QString getEnglishName(void) const {return name;}
63  QString getNameI18n(void) const {return nameI18n;}
64  Vec3f getInfoColor(void) const
65  {
66  return Vec3f(1, 1, 1);
67  }
76  QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const;
77  QString getType(void) const {return TELESCOPECLIENT_TYPE;}
78  QString getID() const {return name;}
79  virtual double getAngularSize(const StelCore*) const {Q_ASSERT(0); return 0;} // TODO
80 
81  // Methods specific to telescope
82  virtual void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) = 0;
83  virtual bool isConnected(void) const = 0;
84  virtual bool hasKnownPosition(void) const = 0;
85  void addOcular(double fov) {if (fov>=0.0) oculars.push_back(fov);}
86  const QList<double> &getOculars(void) const {return oculars;}
87 
88  virtual bool prepareCommunication() {return false;}
89  virtual void performCommunication() {}
90 
91 protected:
92  TelescopeClient(const QString &name);
93  QString nameI18n;
94  const QString name;
95 
96  virtual QString getTelescopeInfoString(const StelCore* core, const InfoStringGroup& flags) const
97  {
98  Q_UNUSED(core);
99  Q_UNUSED(flags);
100  return QString();
101  }
102 private:
103  virtual bool isInitialized(void) const {return true;}
104  float getSelectPriority(const StelCore* core) const {Q_UNUSED(core); return -10.f;}
105 private:
106  QList<double> oculars; // fov of the oculars
107 };
108 
116 {
117 public:
118  TelescopeClientDummy(const QString &name, const QString &) : TelescopeClient(name)
119  {
120  desired_pos[0] = XYZ[0] = 1.0;
121  desired_pos[1] = XYZ[1] = 0.0;
122  desired_pos[2] = XYZ[2] = 0.0;
123  }
124  ~TelescopeClientDummy(void) {}
125  bool isConnected(void) const
126  {
127  return true;
128  }
129  bool prepareCommunication(void)
130  {
131  XYZ = XYZ * 31.0 + desired_pos;
132  const double lq = XYZ.lengthSquared();
133  if (lq > 0.0)
134  XYZ *= (1.0/std::sqrt(lq));
135  else
136  XYZ = desired_pos;
137  return true;
138  }
139  void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject)
140  {
141  desired_pos = j2000Pos;
142  desired_pos.normalize();
143  }
144  bool hasKnownPosition(void) const
145  {
146  return true;
147  }
149  {
150  return XYZ;
151  }
152 
153 private:
154  Vec3d XYZ; // j2000 position
155  Vec3d desired_pos;
156 };
157 
164 {
165  Q_OBJECT
166 public:
167  TelescopeTCP(const QString &name, const QString &params, Equinox eq = EquinoxJ2000);
168  ~TelescopeTCP(void)
169  {
170  hangup();
171  }
172  bool isConnected(void) const
173  {
174  //return (tcpSocket->isValid() && !wait_for_connection_establishment);
175  return (tcpSocket->state() == QAbstractSocket::ConnectedState);
176  }
177 
178 private:
179  Vec3d getJ2000EquatorialPos(const StelCore* core=Q_NULLPTR) const;
180  bool prepareCommunication();
181  void performCommunication();
182  void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject);
183  bool isInitialized(void) const
184  {
185  return (!address.isNull());
186  }
187  void performReading(void);
188  void performWriting(void);
189 
190 private:
191  void hangup(void);
192  QHostAddress address;
193  unsigned int port;
194  QTcpSocket * tcpSocket;
195  bool wait_for_connection_establishment;
196  qint64 end_of_timeout;
197  char readBuffer[120];
198  char *readBufferEnd;
199  char writeBuffer[120];
200  char *writeBufferEnd;
201  int time_delay;
202 
203  InterpolatedPosition interpolatedPosition;
204  virtual bool hasKnownPosition(void) const
205  {
206  return interpolatedPosition.isKnown();
207  }
208 
209  Equinox equinox;
210 
211 private slots:
212  void socketConnected(void);
213  void socketFailed(QAbstractSocket::SocketError socketError);
214 };
215 
216 #endif // _TELESCOPE_HPP_
This TelescopeClient class can control a telescope by communicating to a server process ("telescope s...
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.
QString getID() const
Returns a unique identifier for this object.
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.