• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 17068063291

19 Aug 2025 11:22AM UTC coverage: 11.766%. Remained the same
17068063291

push

github

alex-w
Reformatting

14706 of 124990 relevant lines covered (11.77%)

18303.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.72
/plugins/TelescopeControl/src/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 TELESCOPECLIENT_HPP
27
#define TELESCOPECLIENT_HPP
28

29
#include <QHostAddress>
30
#include <QHostInfo>
31
#include <QList>
32
#include <QString>
33
#include <QTcpSocket>
34
#include <QObject>
35

36
#include "StelObject.hpp"
37
#include "StelTranslator.hpp"
38
#include "TelescopeControl.hpp"
39
#include "common/InterpolatedPosition.hpp"
40

41
class StelCore;
42

43

44
//! An abstract base class that should never be used directly, only inherited.
45
//! This class used to be called Telescope, but it has been renamed
46
//! to TelescopeClient in order to resolve a compiler/linker conflict
47
//! with the identically named Telescope class in Stellarium's main code.
48
class TelescopeClient : public QObject, public StelObject
49
{
50
        Q_OBJECT
51
public:
52
        static const QString TELESCOPECLIENT_TYPE;
53
        //! example url: My_first_telescope:TCP:J2000:localhost:10000:500000
54
        //! split to:
55
        //! name    = My_first_telescope
56
        //! type    = TCP
57
        //! equinox = J2000
58
        //! params  = localhost:10000:500000
59
        //!
60
        //! The params part is optional.  We use QRegularExpression to validate the url and extract the components.
61
        static TelescopeClient *create(const QString &url);
62
        ~TelescopeClient(void) override {}
1✔
63
        
64
        // Methods inherited from StelObject
65
        QString getEnglishName(void) const override {return name;}
×
66
        QString getNameI18n(void) const override {return nameI18n;}
×
67
        //Vec3f getInfoColor(void) const override
68
        //{
69
        //        return Vec3f(1.f, 1.f, 1.f);
70
        //}
71
        //! TelescopeClient supports the following InfoStringGroup flags:
72
        //! - Name
73
        //! - RaDecJ2000
74
        //! - RaDec
75
        //! - PlainText
76
        //! @param core the StelCore object
77
        //! @param flags a set of InfoStringGroup items to include in the return value.
78
        //! @return a QString containing an HTML encoded description of the Telescope.
79
        QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const override;
80
        QString getType(void) const override {return TELESCOPECLIENT_TYPE;}
×
81
        QString getObjectType(void) const override {return N_("telescope");}
×
82
        QString getObjectTypeI18n(void) const override {return q_(getObjectType());}
×
83
        QString getID() const override {return name;}
×
84
                
85
        // Methods specific to telescope
86
        virtual void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) = 0;
87
        //! Some telescopes can synchronize the telescope with the given position or object.
88
        //! The base client does nothing.
89
        //! Derived classes may override this command
90
        //! @todo: Properly document method and the arguments
91
        virtual void telescopeSync(const Vec3d &j2000Pos, StelObjectP selectObject)
×
92
        {
93
                Q_UNUSED(j2000Pos)
94
                Q_UNUSED(selectObject)
95
        };
×
96
        //! report whether this client can respond to sync commands.
97
        //! Can be used for GUI tweaks
98
        virtual bool isTelescopeSyncSupported() const {return false;}
×
99
        //! Send command to abort slew. Not all telescopes support this, base implementation only gives a warning.
100
        //! After abort, the current position should be retrieved and displayed.
101
        virtual void telescopeAbortSlew();
102
        //! report whether this client can abort a running slew.
103
        //! Can be used for GUI tweaks
104
        virtual bool isAbortSlewSupported() const {return false;}
×
105

106
        //!
107
        //! \brief move
108
        //! \param angle [0,360). 180=Down/South, 270=Right/West, 0=Up/North, 90=Left/East
109
        //! \param speed [0,1]
110
        //! The default implementation does nothing but emit a warning.
111
        virtual void move(double angle, double speed);
112
        virtual bool isConnected(void) const = 0;
113
        virtual bool hasKnownPosition(void) const = 0;
114
        //! Store field of view for an ocular circle (unrelated to Oculars plugin)
115
        void addOcular(double fov) {if (fov>=0.0) ocularFovs.push_back(fov);}
×
116
        //! Retrieve list of fields of view for this telescope
117
        const QList<double> &getOculars(void) const {return ocularFovs;}
×
118
        
119
        virtual bool prepareCommunication() {return false;}
×
120
        virtual void performCommunication() {}
×
121

122
        //! Some telescope types may override this method to display additional user interface elements.
123
        virtual QWidget* createControlWidget(QSharedPointer<TelescopeClient> telescope, QWidget* parent = nullptr) const { Q_UNUSED(telescope) Q_UNUSED(parent) return nullptr; }
×
124

125
protected:
126
        TelescopeClient(const QString &name);
127
        QString nameI18n;
128
        const QString name;
129

130
        virtual QString getTelescopeInfoString(const StelCore* core, const InfoStringGroup& flags) const
×
131
        {
132
                Q_UNUSED(core)
133
                Q_UNUSED(flags)
134
                return QString();
×
135
        }
136

137
        //! returns the current system time in microseconds since the Epoch
138
        static qint64 getNow(void);
139
private:
140
        virtual bool isInitialized(void) const {return true;}
×
141
        float getSelectPriority(const StelCore* core) const override {Q_UNUSED(core) return -10.f;}
×
142
private:
143
        QList<double> ocularFovs; // fov of the oculars
144
};
145

146
//! Example Telescope class. A physical telescope does not exist.
147
//! This can be used as a starting point for implementing a derived
148
//! Telescope class.
149
//! This class used to be called TelescopeDummy, but it had to be renamed
150
//! in order to resolve a compiler/linker conflict with the identically named
151
//! TelescopeDummy class in Stellarium's main code.
152
class TelescopeClientDummy : public TelescopeClient
153
{
154
public:
155
        TelescopeClientDummy(const QString &name, const QString &) : TelescopeClient(name)
×
156
        {
157
                desired_pos[0] = XYZ[0] = 1.0;
×
158
                desired_pos[1] = XYZ[1] = 0.0;
×
159
                desired_pos[2] = XYZ[2] = 0.0;
×
160
        }
×
161
        ~TelescopeClientDummy(void) override {}
×
162
        bool isConnected(void) const override
×
163
        {
164
                return true;
×
165
        }
166
        bool prepareCommunication(void) override
×
167
        {
168
                XYZ = XYZ * 31.0 + desired_pos;
×
169
                const double lq = XYZ.normSquared();
×
170
                if (lq > 0.0)
×
171
                        XYZ *= (1.0/std::sqrt(lq));
×
172
                else
173
                        XYZ = desired_pos;
×
174
                return true;
×
175
        }
176
        void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) override
×
177
        {
178
                Q_UNUSED(selectObject)
179
                desired_pos = j2000Pos;
×
180
                desired_pos.normalize();
×
181
        }
×
182
        void telescopeAbortSlew() override
×
183
        {
184
                desired_pos=XYZ;
×
185
                qDebug() << "Telescope" << getID() << "Slew aborted";
×
186
        }
×
187
        bool isAbortSlewSupported() const override {return true;}
×
188
        bool hasKnownPosition(void) const override
×
189
        {
190
                return true;
×
191
        }
192
        Vec3d getJ2000EquatorialPos(const StelCore*) const override
×
193
        {
194
                return XYZ;
×
195
        }
196
        
197
private:
198
        Vec3d XYZ; // j2000 position
199
        Vec3d desired_pos;
200
};
201

202
//! This TelescopeClient class can control a telescope by communicating
203
//! to a server process ("telescope server") via 
204
//! the "Stellarium telescope control protocol" over TCP/IP.
205
//! The "Stellarium telescope control protocol" is specified in a separate
206
//! document along with the telescope server software.
207
class TelescopeTCP : public TelescopeClient
208
{
209
        Q_OBJECT
210
public:
211
        TelescopeTCP(const QString &name, const QString &params, TelescopeControl::Equinox eq = TelescopeControl::EquinoxJ2000);
212
        ~TelescopeTCP(void) override
×
213
        {
×
214
                hangup();
×
215
        }
×
216
        bool isConnected(void) const override
×
217
        {
218
                //return (tcpSocket->isValid() && !wait_for_connection_establishment);
219
                return (tcpSocket->state() == QAbstractSocket::ConnectedState);
×
220
        }
221
        
222
private:
223
        Vec3d getJ2000EquatorialPos(const StelCore* core=nullptr) const override;
224
        bool prepareCommunication() override;
225
        void performCommunication() override;
226
        void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) override;
227
        bool isInitialized(void) const override
×
228
        {
229
                return (!address.isNull());
×
230
        }
231
        void performReading(void);
232
        void performWriting(void);
233
        
234
private:
235
        void hangup(void);
236
        QHostAddress address;
237
        quint16 port;
238
        QTcpSocket * tcpSocket;
239
        bool wait_for_connection_establishment;
240
        qint64 end_of_timeout;
241
        char readBuffer[120];
242
        char *readBufferEnd;
243
        char writeBuffer[120];
244
        char *writeBufferEnd;
245
        int time_delay;
246

247
        InterpolatedPosition interpolatedPosition;
248
        bool hasKnownPosition(void) const override
×
249
        {
250
                return interpolatedPosition.isKnown();
×
251
        }
252

253
        TelescopeControl::Equinox equinox;
254
        
255
private slots:
256
        void socketConnected(void);
257
        void socketFailed(QAbstractSocket::SocketError socketError);
258
};
259

260
#endif // TELESCOPECLIENT_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc