Stellarium 0.14.3
SerialPort.hpp
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 General Public License
12 as published by the Free Software Foundation; either version 2
13 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
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
23 */
24 
25 #ifndef _SERIAL_PORT_HPP_
26 #define _SERIAL_PORT_HPP_
27 
28 #include "Connection.hpp"
29 
30 #ifdef Q_OS_WIN
31  #include <windows.h>
32 #else
33  #include <termios.h>
34 #endif
35 
37 class SerialPort : public Connection
38 {
39 public:
44  SerialPort(Server &server, const char *serial_device);
45  ~SerialPort(void);
48  virtual bool isClosed(void) const
49  {
50  #ifdef Q_OS_WIN
51  return (handle == INVALID_HANDLE_VALUE);
52  #else
53  return IS_INVALID_SOCKET(fd);
54  #endif
55  }
56 
57 protected:
58  void prepareSelectFds(fd_set&, fd_set&, int&);
59 
60 private:
62  bool isTcpConnection(void) const {return false;}
64  bool isAsciiConnection(void) const {return true;}
65 
66 private:
67 #ifdef Q_OS_WIN
68  int readNonblocking(char *buf, int count);
69  int writeNonblocking(const char *buf, int count);
70  void handleSelectFds(const fd_set&, const fd_set&) {}
71  HANDLE handle;
72  DCB dcb_original;
73 #else
74  struct termios termios_original;
75 #endif
76 };
77 
78 #endif
Base class for telescope server classes.
Definition: Server.hpp:45
SerialPort(Server &server, const char *serial_device)
Class constructor.
virtual bool isClosed(void) const
Returns true if the connection is closed.
Definition: SerialPort.hpp:48
TCP/IP connection to a client.
Definition: Connection.hpp:31
Serial interface connection.
Definition: SerialPort.hpp:37