~ubuntu-branches/ubuntu/precise/stellarium/precise

« back to all changes in this revision

Viewing changes to plugins/TelescopeControl/src/servers/Lx200Command.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2010-02-15 20:48:39 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20100215204839-u3qgbv60rho997yk
Tags: 0.10.3-0ubuntu1
* New upstream release.
  - fixes intel rendering bug (LP: #480553)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
The stellarium telescope library helps building
 
3
telescope server programs, that can communicate with stellarium
 
4
by means of the stellarium TCP telescope protocol.
 
5
It also contains smaple server classes (dummy, Meade LX200).
 
6
 
 
7
Author and Copyright of this file and of the stellarium telescope library:
 
8
Johannes Gajdosik, 2006
 
9
 
 
10
This library is free software; you can redistribute it and/or
 
11
modify it under the terms of the GNU Lesser General Public
 
12
License as published by the Free Software Foundation; either
 
13
version 2.1 of the License, or (at your option) any later version.
 
14
 
 
15
This library is distributed in the hope that it will be useful,
 
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
Lesser General Public License for more details.
 
19
 
 
20
You should have received a copy of the GNU Lesser General Public
 
21
License along with this library; if not, write to the Free Software
 
22
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
23
*/
 
24
 
 
25
#ifndef _LX200_COMMAND_HPP_
 
26
#define _LX200_COMMAND_HPP_
 
27
 
 
28
#include <QTextStream>
 
29
using namespace std;
 
30
 
 
31
class Server;
 
32
class TelescopeClientDirectLx200;
 
33
 
 
34
//! Abstract base class for Meade LX200 (and compatible) commands.
 
35
class Lx200Command
 
36
{
 
37
public:
 
38
        virtual ~Lx200Command(void) {}
 
39
        virtual bool writeCommandToBuffer(char *&buff, char *end) = 0;
 
40
        bool hasBeenWrittenToBuffer(void) const {return has_been_written_to_buffer;}
 
41
        virtual int readAnswerFromBuffer(const char *&buff, const char *end) = 0;
 
42
        virtual bool needsNoAnswer(void) const {return false;}
 
43
        virtual void print(QTextStream &o) const = 0;
 
44
        virtual bool isCommandGotoSelected(void) const {return false;}
 
45
        virtual bool shortAnswerReceived(void) const {return false;}
 
46
        //returns true when reading is finished
 
47
        
 
48
protected:
 
49
        Lx200Command(Server &server);
 
50
        TelescopeClientDirectLx200 &server;
 
51
        bool has_been_written_to_buffer;
 
52
};
 
53
 
 
54
inline QTextStream &operator<<(QTextStream &o, const Lx200Command &c)
 
55
{
 
56
        c.print(o);
 
57
        return o;
 
58
}
 
59
 
 
60
//! Meade LX200 command: Toggle long or short format.
 
61
//! Does not require an answer from the telescope.
 
62
class Lx200CommandToggleFormat : public Lx200Command
 
63
{
 
64
public:
 
65
        Lx200CommandToggleFormat(Server &server) : Lx200Command(server) {}
 
66
        
 
67
private:
 
68
        bool writeCommandToBuffer(char *&buff, char *end);
 
69
        int readAnswerFromBuffer(const char*&, const char*) {return 1;}
 
70
        bool needsNoAnswer(void) const {return true;}
 
71
        void print(QTextStream &o) const;
 
72
};
 
73
 
 
74
//! Meade LX200 command: Stop the current slew.
 
75
//! Does not require an answer from the telescope.
 
76
class Lx200CommandStopSlew : public Lx200Command
 
77
{
 
78
public:
 
79
        Lx200CommandStopSlew(Server &server) : Lx200Command(server) {}
 
80
        
 
81
private:
 
82
        bool writeCommandToBuffer(char *&buff, char *end);
 
83
        int readAnswerFromBuffer(const char*&, const char*) {return 1;}
 
84
        bool needsNoAnswer(void) const {return true;}
 
85
        void print(QTextStream &o) const;
 
86
};
 
87
 
 
88
//! Meade LX200 command: Set right ascension.
 
89
class Lx200CommandSetSelectedRa : public Lx200Command
 
90
{
 
91
public:
 
92
        Lx200CommandSetSelectedRa(Server &server, int ra)
 
93
                                 : Lx200Command(server), ra(ra) {}
 
94
        bool writeCommandToBuffer(char *&buff, char *end);
 
95
        int readAnswerFromBuffer(const char *&buff, const char *end);
 
96
        void print(QTextStream &o) const;
 
97
        
 
98
private:
 
99
        const int ra;
 
100
};
 
101
 
 
102
//! Meade LX200 command: Set declination.
 
103
class Lx200CommandSetSelectedDec : public Lx200Command
 
104
{
 
105
public:
 
106
        Lx200CommandSetSelectedDec(Server &server,int dec)
 
107
                                  : Lx200Command(server), dec(dec) {}
 
108
        bool writeCommandToBuffer(char *&buff, char *end);
 
109
        int readAnswerFromBuffer(const char *&buff, const char *end);
 
110
        void print(QTextStream &o) const;
 
111
        
 
112
private:
 
113
        const int dec;
 
114
};
 
115
 
 
116
//! Meade LX200 command: Slew to the coordinates set before.
 
117
class Lx200CommandGotoSelected : public Lx200Command
 
118
{
 
119
public:
 
120
        Lx200CommandGotoSelected(Server &server)
 
121
                                : Lx200Command(server), first_byte(256) {}
 
122
        bool writeCommandToBuffer(char *&buff, char *end);
 
123
        int readAnswerFromBuffer(const char *&buff, const char *end);
 
124
        void print(QTextStream &o) const;
 
125
        bool isCommandGotoSelected(void) const {return true;}
 
126
        bool shortAnswerReceived(void) const {return (first_byte != 256);}
 
127
        
 
128
private:
 
129
        int first_byte;
 
130
};
 
131
 
 
132
//! Meade LX200 command: Get the current right ascension.
 
133
class Lx200CommandGetRa : public Lx200Command
 
134
{
 
135
public:
 
136
        Lx200CommandGetRa(Server &server) : Lx200Command(server) {}
 
137
        bool writeCommandToBuffer(char *&buff, char *end);
 
138
        int readAnswerFromBuffer(const char *&buff, const char *end);
 
139
        void print(QTextStream &o) const;
 
140
};
 
141
 
 
142
//! Meade LX200 command: Get the current declination.
 
143
class Lx200CommandGetDec : public Lx200Command
 
144
{
 
145
public:
 
146
        Lx200CommandGetDec(Server &server) : Lx200Command(server) {}
 
147
        bool writeCommandToBuffer(char *&buff, char *end);
 
148
        int readAnswerFromBuffer(const char *&buff, const char *end);
 
149
        void print(QTextStream &o) const;
 
150
};
 
151
 
 
152
#endif //_LX200_COMMAND_HPP_