diff options
author | Bogdan Marinov <bogdan.marinov84@gmail.com> | 2012-01-06 00:14:16 +0200 |
---|---|---|
committer | Bogdan Marinov <bogdan.marinov84@gmail.com> | 2012-01-06 00:14:16 +0200 |
commit | b3c8e830d21ee03ca1cf3e19a2ed3653541495a5 (patch) | |
tree | 140dff91287d9553b54861ad9d64b84c32fe2da9 | |
parent | 8a30abc7e7711b392aed6aa4cd2fdfec86767482 (diff) |
removed the Celestron Ultima 2000 codetelescope-control-servo-cat
13 files changed, 6 insertions, 1312 deletions
diff --git a/plugins/TelescopeControl/ChangeLog b/plugins/TelescopeControl/ChangeLog index 36d6b05fa8..034e649904 100644 --- a/plugins/TelescopeControl/ChangeLog +++ b/plugins/TelescopeControl/ChangeLog @@ -1,9 +1,10 @@ -[0.3.1] -Added (experimental) support for the Celestron Ultima 2000 GOTO telescope -(may also include support for Celestron 16-bit commands). - +[branch] Added (experimental) support for the ServoCAT GOTO kit (may also include read-only support for the Sky Commander digital setting cirlce). +Experimented with support for the Celestron Ultima 2000 GOTO telescope +(may also include support for Celestron 16-bit commands). The experiment was +unsuccessfull. The code was removed at local revision 4866 (the files can be +re-added with the merge command - see the Bazaar documentation/use Google). [0.3.0] Minor code cleanup. diff --git a/plugins/TelescopeControl/resources/device_models.json b/plugins/TelescopeControl/resources/device_models.json index fd64f71423..2607823596 100644 --- a/plugins/TelescopeControl/resources/device_models.json +++ b/plugins/TelescopeControl/resources/device_models.json @@ -55,12 +55,6 @@ "description" : "StellarCAT's ServoCAT GOTO kit.", "server" : "TelescopeServerServoCat", "default_delay" : 500000 - }, - { - "name" : "Celestron Ultima 2000", - "description" : "Celestron's Ultima 2000 GOTO telescope.", - "server" : "TelescopeServerUltima2000", - "default_delay" : 500000 } ] } diff --git a/plugins/TelescopeControl/src/CMakeLists.txt b/plugins/TelescopeControl/src/CMakeLists.txt index 276c9232af..c23c8921e5 100644 --- a/plugins/TelescopeControl/src/CMakeLists.txt +++ b/plugins/TelescopeControl/src/CMakeLists.txt @@ -18,8 +18,6 @@ SET(TelescopeControl_SRCS clients/TelescopeClientDirectNexStar.cpp clients/TelescopeClientDirectServoCat.hpp clients/TelescopeClientDirectServoCat.cpp - clients/TelescopeClientDirectUltima2000.hpp - clients/TelescopeClientDirectUltima2000.cpp TelescopeControl.hpp TelescopeControl.cpp gui/SlewDialog.hpp @@ -40,8 +38,6 @@ SET(TelescopeControl_SRCS servers/Connection.cpp servers/SerialPort.hpp servers/SerialPort.cpp - servers/SerialPortUltima2000.hpp - servers/SerialPortUltima2000.cpp servers/Lx200Connection.hpp servers/Lx200Connection.cpp servers/Lx200Command.hpp @@ -54,10 +50,6 @@ SET(TelescopeControl_SRCS servers/ServoCatConnection.cpp servers/ServoCatCommand.hpp servers/ServoCatCommand.cpp - servers/Ultima2000Connection.hpp - servers/Ultima2000Connection.cpp - servers/Ultima2000Command.hpp - servers/Ultima2000Command.cpp ) # Add here all the .ui files @@ -84,7 +76,6 @@ SET(TelescopeControl_MOC_HDRS clients/TelescopeClientDirectLx200.hpp clients/TelescopeClientDirectNexStar.hpp clients/TelescopeClientDirectServoCat.hpp - clients/TelescopeClientDirectUltima2000.hpp ) # After this call, TelescopeControl_MOC_SRCS = moc_TelescopeControl.cxx diff --git a/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp b/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp index 8b1f3c84c7..68ab22bb70 100644 --- a/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp +++ b/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp @@ -76,7 +76,7 @@ namespace TelescopeControlGlobals { #endif //! List of the telescope servers that don't need external executables - const QStringList EMBEDDED_TELESCOPE_SERVERS = QString("TelescopeServerDummy TelescopeServerLx200 TelescopeServerNexStar TelescopeServerServoCat TelescopeServerUltima2000").split(' ', QString::SkipEmptyParts); + const QStringList EMBEDDED_TELESCOPE_SERVERS = QString("TelescopeServerDummy TelescopeServerLx200 TelescopeServerNexStar TelescopeServerServoCat").split(' ', QString::SkipEmptyParts); }; #endif //_TELESCOPE_CONTROL_GLOBALS_ diff --git a/plugins/TelescopeControl/src/clients/TelescopeClient.cpp b/plugins/TelescopeControl/src/clients/TelescopeClient.cpp index 270bf55f99..1426347813 100644 --- a/plugins/TelescopeControl/src/clients/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/clients/TelescopeClient.cpp @@ -27,7 +27,6 @@ #include "TelescopeClientDirectLx200.hpp" #include "TelescopeClientDirectNexStar.hpp" #include "TelescopeClientDirectServoCat.hpp" -#include "TelescopeClientDirectUltima2000.hpp" #include "StelUtils.hpp" #include "StelTranslator.hpp" #include "StelCore.hpp" @@ -107,10 +106,6 @@ TelescopeClient *TelescopeClient::create(const QString &url) { newTelescope= new TelescopeClientDirectServoCat(name, params, eq); } - else if (type == "TelescopeServerUltima2000") - { - newTelescope= new TelescopeClientDirectUltima2000(name, params, eq); - } else { qWarning() << "WARNING - unknown telescope type" << type << "- not creating a telescope object for url" << url; diff --git a/plugins/TelescopeControl/src/clients/TelescopeClientDirectUltima2000.cpp b/plugins/TelescopeControl/src/clients/TelescopeClientDirectUltima2000.cpp deleted file mode 100644 index 730e55a6fa..0000000000 --- a/plugins/TelescopeControl/src/clients/TelescopeClientDirectUltima2000.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Stellarium Telescope Control Plug-in - * - * Copyright (C) 2009-2011 Bogdan Marinov (this file, - * reusing code written by Johannes Gajdosik in 2006) - * - * Johannes Gajdosik wrote in 2006 the original telescope control feature - * as a core module of Stellarium. In 2009 it was significantly extended with - * GUI features and later split as an external plug-in module by Bogdan Marinov. - * - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "TelescopeClientDirectUltima2000.hpp" - -#include "Ultima2000Connection.hpp" -#include "Ultima2000Command.hpp" -#include "LogFile.hpp" - -#include <QRegExp> -#include <QStringList> - -TelescopeClientDirectUltima2000::TelescopeClientDirectUltima2000(const QString &name, const QString ¶meters, Equinox eq) : - TelescopeClient(name), - equinox(eq) -{ - interpolatedPosition.reset(); - - //Extract parameters - //Format: "serial_port_name:time_delay" - QRegExp paramRx("^([^:]*):(\\d+)$"); - QString serialDeviceName; - if (paramRx.exactMatch(parameters)) - { - // This QRegExp only matches valid integers - serialDeviceName = paramRx.capturedTexts().at(1).trimmed(); - time_delay = paramRx.capturedTexts().at(2).toInt(); - } - else - { - qWarning() << "ERROR creating TelescopeClientDirectUltima2000: invalid parameters."; - return; - } - - qDebug() << "TelescopeClientDirectUltima2000 paramaters: port, time_delay:" << serialDeviceName << time_delay; - - //Validation: Time delay - if (time_delay <= 0 || time_delay > 10000000) - { - qWarning() << "ERROR creating TelescopeClientDirectUltima2000: time_delay not valid (should be less than 10000000)"; - return; - } - - //end_of_timeout = -0x8000000000000000LL; - - #ifdef Q_OS_WIN32 - if(serialDeviceName.right(serialDeviceName.size() - 3).toInt() > 9) - serialDeviceName = "\\\\.\\" + serialDeviceName;//"\\.\COMxx", not sure if it will work - else - serialDeviceName = serialDeviceName; - #endif //Q_OS_WIN32 - - //Try to establish a connection to the telescope - ultima2000 = new Ultima2000Connection(*this, qPrintable(serialDeviceName)); - if (ultima2000->isClosed()) - { - qWarning() << "ERROR creating TelescopeClientDirectUltima2000: cannot open serial device" << serialDeviceName; - return; - } - - //This connection will be deleted in the destructor of Server - addConnection(ultima2000); - - queue_get_position = true; - next_pos_time = -0x8000000000000000LL; -} - -//! queues a GOTO command -void TelescopeClientDirectUltima2000::telescopeGoto(const Vec3d &j2000Pos) -{ - if (!isConnected()) - return; - - Vec3d position = j2000Pos; - if (equinox == EquinoxJNow) - { - const StelCore* core = StelApp::getInstance().getCore(); - position = core->j2000ToEquinoxEqu(j2000Pos); - } - - //if (writeBufferEnd - writeBuffer + 20 < (int)sizeof(writeBuffer)) - //TODO: See the else clause, think how to do the same thing - { - const double ra_signed = atan2(position[1], position[0]); - //Workaround for the discrepancy in precision between Windows/Linux/PPC Macs and Intel Macs: - const double ra = (ra_signed >= 0) ? ra_signed : (ra_signed + 2.0 * M_PI); - const double dec = atan2(position[2], sqrt(position[0]*position[0]+position[1]*position[1])); - unsigned int ra_int = (unsigned int)floor(0.5 + ra*(((unsigned int)0x80000000)/M_PI)); - int dec_int = (int)floor(0.5 + dec*(((unsigned int)0x80000000)/M_PI)); - - gotoReceived(ra_int, dec_int); - } - /* - else - { - qDebug() << "TelescopeTCP(" << name << ")::telescopeGoto: "<< "communication is too slow, I will ignore this command"; - } - */ -} - -void TelescopeClientDirectUltima2000::gotoReceived(unsigned int ra_int, int dec_int) -{ - ultima2000->sendGoto(ra_int, dec_int); -} - -//! estimates where the telescope is by interpolation in the stored -//! telescope positions: -Vec3d TelescopeClientDirectUltima2000::getJ2000EquatorialPos(const StelCore*) const -{ - const qint64 now = getNow() - time_delay; - return interpolatedPosition.get(now); -} - -bool TelescopeClientDirectUltima2000::prepareCommunication() -{ - //TODO: Nothing to prepare? - return true; -} - -void TelescopeClientDirectUltima2000::performCommunication() -{ - step(10000); -} - -void TelescopeClientDirectUltima2000::communicationResetReceived() -{ - queue_get_position = true; - next_pos_time = -0x8000000000000000LL; - -#ifndef QT_NO_DEBUG - *log_file << Now() << "TelescopeClientDirectUltima2000::communicationResetReceived" << endl; -#endif -} - -//! Called by Ultima2000CommandGetRaDec::readAnswerFromBuffer(). -void TelescopeClientDirectUltima2000::raDecReceived(unsigned int ra_int, unsigned int dec_int) -{ -#ifndef QT_NO_DEBUG - *log_file << Now() << "TelescopeClientDirectUltima2000::raDecReceived: " << ra_int << ", " << dec_int << endl; -#endif - - const int serial_status = 0; - sendPosition(ra_int, dec_int, serial_status); - queue_get_position = true; -} - -void TelescopeClientDirectUltima2000::step(long long int timeout_micros) -{ - long long int now = GetNow(); - if (queue_get_position && now >= next_pos_time) - { - ultima2000->sendCommand(new Ultima2000CommandGetRaDec(*this)); - queue_get_position = false; - next_pos_time = now + 500000; - } - Server::step(timeout_micros); -} - -bool TelescopeClientDirectUltima2000::isConnected() const -{ - return (!ultima2000->isClosed());//TODO -} - -bool TelescopeClientDirectUltima2000::isInitialized() const -{ - return (!ultima2000->isClosed()); -} - -//Merged from Connection::sendPosition() and TelescopeTCP::performReading() -void TelescopeClientDirectUltima2000::sendPosition(unsigned int ra_int, int dec_int, int status) -{ - //Server time is "now", because this class is the server - const qint64 server_micros = (qint64) GetNow(); - const double ra = ra_int * (M_PI/(unsigned int)0x80000000); - const double dec = dec_int * (M_PI/(unsigned int)0x80000000); - const double cdec = cos(dec); - Vec3d position(cos(ra)*cdec, sin(ra)*cdec, sin(dec)); - Vec3d j2000Position = position; - if (equinox == EquinoxJNow) - { - const StelCore* core = StelApp::getInstance().getCore(); - j2000Position = core->equinoxEquToJ2000(position); - } - interpolatedPosition.add(j2000Position, getNow(), server_micros, status); -} diff --git a/plugins/TelescopeControl/src/clients/TelescopeClientDirectUltima2000.hpp b/plugins/TelescopeControl/src/clients/TelescopeClientDirectUltima2000.hpp deleted file mode 100644 index 1b490e94b9..0000000000 --- a/plugins/TelescopeControl/src/clients/TelescopeClientDirectUltima2000.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Stellarium Telescope Control Plug-in - * - * Copyright (C) 2009-2011 Bogdan Marinov (this file, - * reusing code written by Johannes Gajdosik in 2006) - * - * Johannes Gajdosik wrote in 2006 the original telescope control feature - * as a core module of Stellarium. In 2009 it was significantly extended with - * GUI features and later split as an external plug-in module by Bogdan Marinov. - * - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _TELESCOPE_CLIENT_DIRECT_ULTIMA_2000_ -#define _TELESCOPE_CLIENT_DIRECT_ULTIMA_2000_ - -#include <QObject> -#include <QString> - -#include "StelApp.hpp" -#include "StelObject.hpp" -#include "StelCore.hpp" - -#include "Server.hpp" //from the telescope server source tree -#include "TelescopeClient.hpp" //from the plug-in's source tree -#include "InterpolatedPosition.hpp" - -class Ultima2000Connection; - -//! Telescope client that connects directly to a Celestron Ultima 2000 through -//! a serial port. This class has been created by reusing code from -//! TelescopeClientDirectNexStar. -class TelescopeClientDirectUltima2000 : public TelescopeClient, public Server -{ - Q_OBJECT -public: - TelescopeClientDirectUltima2000(const QString &name, const QString ¶meters, Equinox eq = EquinoxJ2000); - ~TelescopeClientDirectUltima2000() - { - //hangup(); - } - - //====================================================================== - // Methods inherited from TelescopeClient - bool isConnected() const; - - //====================================================================== - // Methods inherited from Server - virtual void step(long long int timeout_micros); - void communicationResetReceived(); - void raDecReceived(unsigned int ra_int, unsigned int dec_int); - -private: - //====================================================================== - // Methods inherited from TelescopeClient - Vec3d getJ2000EquatorialPos(const StelCore* nav=0) const; - bool prepareCommunication(); - void performCommunication(); - void telescopeGoto(const Vec3d &j2000Pos); - bool isInitialized() const; - - //====================================================================== - // Methods inherited from Server - void sendPosition(unsigned int ra_int, int dec_int, int status); - //Inherited from pure virtual Server::gotoReceived(), so the parameters - //can't be changed. - void gotoReceived(unsigned int ra_int, int dec_int); - -private: - void hangup(); - int time_delay; - - InterpolatedPosition interpolatedPosition; - virtual bool hasKnownPosition() const - { - return interpolatedPosition.isKnown(); - } - - Equinox equinox; - - Ultima2000Connection *ultima2000; - - bool queue_get_position; - long long int next_pos_time; -}; - -#endif //_TELESCOPE_CLIENT_DIRECT_ULTIMA_2000_ diff --git a/plugins/TelescopeControl/src/servers/SerialPortUltima2000.cpp b/plugins/TelescopeControl/src/servers/SerialPortUltima2000.cpp deleted file mode 100644 index 325085906e..0000000000 --- a/plugins/TelescopeControl/src/servers/SerialPortUltima2000.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* -Stellarium telescope control -Copyright (C) 2006 Johannes Gajdosik -Copyright (C) 2011 Bogdan Marinov (Ultima2000 modifications) - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "SerialPortUltima2000.hpp" -#include "LogFile.hpp" - -#ifndef Q_OS_WIN32 -#include <unistd.h> -#endif - -#include <string.h> // memset - -using namespace std; - -SerialPortUltima2000::SerialPortUltima2000(Server &server, - const char *serial_device) - : Connection(server, INVALID_SOCKET) -{ -#ifdef Q_OS_WIN32 - handle = CreateFile(serial_device, - GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); - if (handle == INVALID_HANDLE_VALUE) - { - *log_file << Now() << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): CreateFile() failed: " - << GetLastError() << endl; - } - else - { - COMMTIMEOUTS timeouts; - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = 0; - timeouts.ReadTotalTimeoutConstant = 0; - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 0; - if (!SetCommTimeouts(handle, &timeouts)) - { - *log_file << Now() << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): SetCommTimeouts() failed: " - << GetLastError() << endl; - } - else - { - if (!GetCommState(handle, &dcb_original)) - { - *log_file << Now() - << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): GetCommState() failed: " - << GetLastError() << endl; - } - else - { - DCB dcb; - memset(&dcb, 0, sizeof(dcb)); - dcb.DCBlength = sizeof(dcb); - if (!BuildCommDCB("9600,n,8,1", &dcb)) - { - *log_file << Now() - << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): BuildCommDCB() failed: " - << GetLastError() << endl; - } - else - { - //Turn off all possible flow of control flags - dcb.fOutxCtsFlow = FALSE; - dcb.fOutxDsrFlow = FALSE; - dcb.fDsrSensitivity = FALSE; - dcb.fDtrControl = DTR_CONTROL_DISABLE; - dcb.fRtsControl = RTS_CONTROL_DISABLE; - *log_file << "SerialPortUltima2000: Default EOF character: " - << (int)dcb.EofChar << endl; - - if (!SetCommState(handle,&dcb)) - { - *log_file << Now() - << "SerialPort::SerialPortUltima2000(" - << serial_device - << "): SetCommState() failed: " - << GetLastError() << endl; - } - else - { - // success - return; - } - } - } - } - CloseHandle(handle); - handle = INVALID_HANDLE_VALUE; - } -#else - fd = open(serial_device, O_RDWR|O_NOCTTY); - if (fd < 0) - { - *log_file << Now() << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): open() failed: " - << strerror(errno) << endl; - } - else - { - if (SETNONBLOCK(fd) < 0) - { - *log_file << Now() << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): fcntl(O_NONBLOCK) failed: " - << STRERROR(ERRNO) << endl; - } - else - { - if (tcgetattr(fd,&termios_original) < 0) - { - *log_file << Now() - << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): tcgetattr failed: " - << strerror(errno) << endl; - } - else - { - struct termios termios_new; - memset(&termios_new, 0, sizeof(termios_new)); - termios_new.c_cflag = CS8 | // 8 data bits - // no parity because PARENB is not set - CLOCAL | // Ignore modem control lines - CREAD; // Enable receiver - cfsetospeed(&termios_new, B9600); - termios_new.c_lflag = 0; - termios_new.c_cc[VTIME] = 0; - termios_new.c_cc[VMIN] = 1; - if (tcsetattr(fd,TCSAFLUSH,&termios_new) < 0) - { - *log_file << Now() - << "SerialPortUltima2000::SerialPortUltima2000(" - << serial_device << "): tcsetattr failed: " - << strerror(errno) << endl; - } - else - { - // success - return; - } - } - } - close(fd); - fd = -1; - } -#endif //Q_OS_WIN32 -} - -SerialPortUltima2000::~SerialPortUltima2000() -{ -#ifdef Q_OS_WIN32 - if (handle != INVALID_HANDLE_VALUE) - { - // restore original settings - SetCommState(handle, &dcb_original); - CloseHandle(handle); - } -#else - if (fd >= 0) - { - // restore original settings - tcsetattr(fd, TCSANOW, &termios_original); - close(fd); - } -#endif -} - - -#ifdef Q_OS_WIN32 - -int SerialPortUltima2000::readNonblocking(char *buf, int count) -{ - DWORD rval; - if (ReadFile(handle, buf, count, &rval, 0)) - return (int)rval; - if (GetLastError() == ERROR_IO_PENDING) - return 0; - return -1; -} - -int SerialPortUltima2000::writeNonblocking(const char *buf, int count) -{ - DWORD rval; - if (WriteFile(handle, buf, count, &rval, 0)) - return (int)rval; - if (GetLastError() == ERROR_IO_PENDING) - return 0; - return -1; -} - -#endif - -void SerialPortUltima2000::prepareSelectFds(fd_set &read_fds, - fd_set &write_fds, - int &fd_max) -{ -#ifdef Q_OS_WIN32 - // handle all IO here - if (write_buff_end > write_buff) - performWriting(); - performReading(); -#else - Connection::prepareSelectFds(read_fds, write_fds, fd_max); -#endif //Q_OS_WIN32 -} diff --git a/plugins/TelescopeControl/src/servers/SerialPortUltima2000.hpp b/plugins/TelescopeControl/src/servers/SerialPortUltima2000.hpp deleted file mode 100644 index d3a521a95f..0000000000 --- a/plugins/TelescopeControl/src/servers/SerialPortUltima2000.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -Stellarium telescope control -Copyright (C) 2006 Johannes Gajdosik -Copyright (C) 2011 Bogdan Marinov (Ultima2000 modifications) - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef _SERIAL_PORT_ULTIMA_2000_HPP_ -#define _SERIAL_PORT_ULTIMA_2000_HPP_ - -#include "Connection.hpp" - -#ifdef Q_OS_WIN32 - #include <windows.h> -#else - #include <termios.h> -#endif - -//! Serial interface connection, tailored for Ultima 2000. -//! A separate class is used until SerialPort can handle serial connection -//! parameters. -//! \todo Merge with SerialPort -class SerialPortUltima2000 : public Connection -{ -public: - //! Class constructor. - //! @param serial_device A string containing the name of a serial port. - //! On UNIX systems, this should be something like "/dev/ttyS0". - //! On Microsoft Windows systems, this should be something like "COM1:". - SerialPortUltima2000(Server &server, const char *serial_device); - ~SerialPortUltima2000(); - //! Returns true if the connection is closed. - //! This method has different platform-dependent implementations. - virtual bool isClosed() const - { - #ifdef Q_OS_WIN32 - return (handle == INVALID_HANDLE_VALUE); - #else - return IS_INVALID_SOCKET(fd); - #endif - } - -protected: - void prepareSelectFds(fd_set&, fd_set&, int&); - -private: - //! Returns false, as SerialPort implements a serial port connection. - bool isTcpConnection() const {return false;} - //! Returns true, as SerialPort implements a serial port connection. - bool isAsciiConnection() const {return true;} - -private: -#ifdef Q_OS_WIN32 - int readNonblocking(char *buf, int count); - int writeNonblocking(const char *buf, int count); - void handleSelectFds(const fd_set&, const fd_set&) {} - HANDLE handle; - DCB dcb_original; -#else - struct termios termios_original; -#endif -}; - -#endif diff --git a/plugins/TelescopeControl/src/servers/Ultima2000Command.cpp b/plugins/TelescopeControl/src/servers/Ultima2000Command.cpp deleted file mode 100644 index 3c3d0763f6..0000000000 --- a/plugins/TelescopeControl/src/servers/Ultima2000Command.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* -Stellarium telescope control -Copyright (c) 2006 Johannes Gajdosik -Copyright (c) 2006 Michael Heinz (NexStar modifications) -Copyright (c) 2011 Bogdan Marinov (Ultima2000 modifications) - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "Ultima2000Command.hpp" -#include "TelescopeClientDirectUltima2000.hpp" -#include "LogFile.hpp" - -#include <cmath> - -using namespace std; - -Ultima2000Command::Ultima2000Command(Server &server) : server(*static_cast<TelescopeClientDirectUltima2000*>(&server)), has_been_written_to_buffer(false) -{ -} - -Ultima2000CommandGotoPosition::Ultima2000CommandGotoPosition(Server &server, - quint16 ra_int, - qint16 dec_int) - : Ultima2000Command(server), - ra(ra_int), - dec(dec_int) -{ - // -} - -#define NIBTOASCII(x) (((x)<10)?('0'+(x)):('A'+(x)-10)) -#define ASCIITONIB(x) (((x)<'A')?((x)-'0'):((x)-'A'+10)) - -bool Ultima2000CommandGotoPosition::writeCommandToBuffer(char *&p,char *end) -{ - #ifdef DEBUG5 - char *b = p; - #endif - - //Is there enough space in the buffer? The GOTO command is 10 bytes long. - if (end-p < 11) - //if (end-p < 12) - return false; - - *p++ = 'R'; - - //16-bit RA to hexadecimal digits - int x = ra; - //*p++ = NIBTOASCII ((x>>28) & 0x0f); - //*p++ = NIBTOASCII ((x>>24) & 0x0f); - //*p++ = NIBTOASCII ((x>>20) & 0x0f); - //*p++ = NIBTOASCII ((x>>16) & 0x0f); - *p++ = NIBTOASCII ((x>>12) & 0x0f); - *p++ = NIBTOASCII ((x>>8) & 0x0f); - *p++ = NIBTOASCII ((x>>4) & 0x0f); - *p++ = NIBTOASCII (x & 0x0f); - *p++ = ','; - - //16-bit Dec to hexadecimal digits - x = dec; - //*p++ = NIBTOASCII ((x>>28) & 0x0f); - //*p++ = NIBTOASCII ((x>>24) & 0x0f); - //*p++ = NIBTOASCII ((x>>20) & 0x0f); - //*p++ = NIBTOASCII ((x>>16) & 0x0f); - *p++ = NIBTOASCII ((x>>12) & 0x0f); - *p++ = NIBTOASCII ((x>>8) & 0x0f); - *p++ = NIBTOASCII ((x>>4) & 0x0f); - *p++ = NIBTOASCII (x & 0x0f); - *p++ = 0x0D;//'\r';//The command should be termiated with a carriage return. - //*p++ = 0x0A;//'\n' - //*p = 0; - - has_been_written_to_buffer = true; - #ifdef DEBUG5 - *log_file << Now() << "Ultima2000CommandGotoPosition::writeCommandToBuffer:" - << b << endl; - #endif - - return true; -} - -int Ultima2000CommandGotoPosition::readAnswerFromBuffer(const char *&buff, const char *end) const -{ - if (buff >= end) - return 0; - - if (*buff=='#') - { - #ifdef DEBUG4 - *log_file << Now() << "Ultima2000CommandGotoPosition::readAnswerFromBuffer: slew ok" - << endl; - #endif - } - else - { - #ifdef DEBUG4 - *log_file << Now() << "Ultima2000CommandGotoPosition::readAnswerFromBuffer: slew failed." << endl; - #endif - } - buff++; - return 1; -} - -void Ultima2000CommandGotoPosition::print(QTextStream &o) const -{ - o << "Ultima2000CommandGotoPosition(" - << ra << "," << dec <<')'; -} - -bool Ultima2000CommandGetRaDec::writeCommandToBuffer(char *&p, char *end) -{ - if (end-p < 2) - //if (end-p < 3) - return false; - - *p++ = 'E'; - *p++ = 0x0D;//'\r';//The command should be termiated with a carriage return. - //*p++ = 0x0A;//'\n' - has_been_written_to_buffer = true; - return true; -} - -int Ultima2000CommandGetRaDec::readAnswerFromBuffer(const char *&buff, const char *end) const -{ - //Skip possible carriage returns: - while (buff < end && *buff=='\r') - { - //TODO: Remove log - *log_file << Now() << "Ultima2000CommandGetRaDec::readAnswerFromBuffer:" - << " Carriage return skipped." << endl; - buff++; - } - - //Is there enough space in the buffer? The answer is 10 bytes long. - if (end-buff < 10) - return 0; - - //Note: the parameters of TelescopeClientDirectUltima2000::raDecReceived() - //are "unsigned int" at the moment, so something has to be changed in the - //future. - quint32 ra, dec; - const char *p = buff; - - // Next 4 bytes are RA as hexadecimal digits - ra = 0; - ra += ASCIITONIB(*p); ra <<= 4; p++; - ra += ASCIITONIB(*p); ra <<= 4; p++; - ra += ASCIITONIB(*p); ra <<= 4; p++; - //ra += ASCIITONIB(*p); ra <<= 4; p++; - //ra += ASCIITONIB(*p); ra <<= 4; p++; - //ra += ASCIITONIB(*p); ra <<= 4; p++; - //ra += ASCIITONIB(*p); ra <<= 4; p++; - ra += ASCIITONIB(*p); p++; - - if (*p++ != ',') - { - #ifdef DEBUG4 - *log_file << Now() << "Ultima2000CommandGetRaDec::readAnswerFromBuffer: " - "error: ',' expected" << endl; - #endif - return -1; - } - - // Next 4 bytes are Dec as hexadecimal digits - dec = 0; - dec += ASCIITONIB(*p); dec <<= 4; p++; - dec += ASCIITONIB(*p); dec <<= 4; p++; - dec += ASCIITONIB(*p); dec <<= 4; p++; - //dec += ASCIITONIB(*p); dec <<= 4; p++; - //dec += ASCIITONIB(*p); dec <<= 4; p++; - //dec += ASCIITONIB(*p); dec <<= 4; p++; - //dec += ASCIITONIB(*p); dec <<= 4; p++; - dec += ASCIITONIB(*p); p++; - - if (*p++ != '#') - { - #ifdef DEBUG4 - *log_file << Now() << "Ultima2000CommandGetRaDec::readAnswerFromBuffer: " - "error: '#' expected" << endl; - #endif - return -1; - } - - - #ifdef DEBUG4 - *log_file << Now() << "Ultima2000CommandGetRaDec::readAnswerFromBuffer: " - "ra = " << ra << ", dec = " << dec - << endl; - #endif - buff = p; - - //Conversion back to 32-bit values - ra *= 65536; - dec *= 65536; - server.raDecReceived(ra, dec); - return 1; -} - -void Ultima2000CommandGetRaDec::print(QTextStream &o) const -{ - o << "Ultima2000CommandGetRaDec"; -} - diff --git a/plugins/TelescopeControl/src/servers/Ultima2000Command.hpp b/plugins/TelescopeControl/src/servers/Ultima2000Command.hpp deleted file mode 100644 index 3d3fcb01ad..0000000000 --- a/plugins/TelescopeControl/src/servers/Ultima2000Command.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -Stellarium telescope control -Copyright (c) 2006 Johannes Gajdosik -Copyright (c) 2006 Michael Heinz (NexStar modifications) -Copyright (c) 2011 Bogdan Marinov (Ultima2000 modifications) - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef _ULTIMA_2000_COMMAND_HPP_ -#define _ULTIMA_2000_COMMAND_HPP_ - -#include <QtGlobal> -#include <QTextStream> -using namespace std; - -class Server; -class TelescopeClientDirectUltima2000; - -//! Abstract base class for Celestron Ultima 2000 (and compatible) commands. -class Ultima2000Command -{ -public: - virtual ~Ultima2000Command() {} - virtual bool writeCommandToBuffer(char *&buff, char *end) = 0; - bool hasBeenWrittenToBuffer() const { return has_been_written_to_buffer; } - virtual int readAnswerFromBuffer(const char *&buff, const char *end) const = 0; - virtual bool needsNoAnswer() const { return false; } - virtual void print(QTextStream &o) const = 0; - virtual bool isCommandGoto() const {return false;} - // returns true when reading is finished - -protected: - Ultima2000Command(Server &server); - TelescopeClientDirectUltima2000 &server; - bool has_been_written_to_buffer; -}; - -inline QTextStream &operator<<(QTextStream &o, const Ultima2000Command &c) -{ - c.print(o); - return o; -} - -//! Celestron Ultima2000 command: Slew to a given position. -//! Sends the Celestron 16-bit "go to RA/Dec" command <tt>R34AB,12CE</tt>. -class Ultima2000CommandGotoPosition : public Ultima2000Command -{ -public: - Ultima2000CommandGotoPosition(Server &server, quint16 ra_int, qint16 dec_int); - bool writeCommandToBuffer(char *&buff, char *end); - int readAnswerFromBuffer(const char *&buff, const char *end) const; - void print(QTextStream &o) const; - bool isCommandGoto() const {return true;} - -private: - quint16 ra; - qint16 dec; -}; - -//! Celestron Ultima 2000 command: Get the current position. -//! Sends the Celestron 16-bit "get RA/Dec" command <tt>E</tt> and reads the -//! answer in format <tt>34AB,12CE#</tt>. -class Ultima2000CommandGetRaDec : public Ultima2000Command -{ -public: - Ultima2000CommandGetRaDec(Server &server) : Ultima2000Command(server) {} - bool writeCommandToBuffer(char *&buff, char *end); - int readAnswerFromBuffer(const char *&buff, const char *end) const; - void print(QTextStream &o) const; -}; - -#endif//_ULTIMA_2000_COMMAND_HPP_ diff --git a/plugins/TelescopeControl/src/servers/Ultima2000Connection.cpp b/plugins/TelescopeControl/src/servers/Ultima2000Connection.cpp deleted file mode 100644 index a43dcc2df5..0000000000 --- a/plugins/TelescopeControl/src/servers/Ultima2000Connection.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* -Stellarium telescope control -Copyright (c) 2006 Johannes Gajdosik -Copyright (c) 2006 Michael Heinz (NexStar modifications) -Copyright (c) 2011 Bogdan Marinov (Ultima2000 modifications) - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "Ultima2000Connection.hpp" -#include "Ultima2000Command.hpp" -#include "TelescopeClientDirectUltima2000.hpp" -#include "LogFile.hpp" - -#include <iostream> -#include <cmath> -using namespace std; - -Ultima2000Connection::Ultima2000Connection(Server &server, - const char *serial_device) - : SerialPortUltima2000(server, serial_device) -{ - time_between_commands = 0; - next_send_time = GetNow(); - read_timeout_endtime = 0x7FFFFFFFFFFFFFFFLL; - goto_commands_queued = 0; -} - -void Ultima2000Connection::resetCommunication() -{ - while (!commandQueue.empty()) - { - delete commandQueue.front(); - commandQueue.pop_front(); - } - - read_buff_end = read_buff; - write_buff_end = write_buff; -#ifdef DEBUG4 - *log_file << Now() - << "Ultima2000Connection::resetCommunication" - << endl; -#endif - // wait 10 seconds before sending the next command in order to read - // and ignore data coming from the telescope: - next_send_time = GetNow() + 10000000; - read_timeout_endtime = 0x7FFFFFFFFFFFFFFFLL; - goto_commands_queued = 0; - static_cast<TelescopeClientDirectUltima2000&>(server).communicationResetReceived(); -} - -void Ultima2000Connection::sendGoto(unsigned int ra32, int dec32) -{ - if (goto_commands_queued <= 1) - { - //Conversion - //This is a bit stupid... - quint16 ra16 = (quint16)floor(ra32 / 65536.0); - qint16 dec16 = (qint16)floor(dec32 / 65536.0); - - sendCommand(new Ultima2000CommandGotoPosition(server, ra16, dec16)); - goto_commands_queued++; - } - else - { -#ifdef DEBUG4 - *log_file << Now() - << "Ultima2000Connection::sendGoto: " - << "Too much GOTO commands in queue; " - << "The last one has been ignored." << endl; -#endif - } -} - -bool Ultima2000Connection::writeFrontCommandToBuffer() -{ - if(commandQueue.empty()) - { - return false; - } - - const long long int now = GetNow(); - if (now < next_send_time) - { -#ifdef DEBUG4 - /* - *log_file << Now() - << "Ultima2000Connection::writeFrontCommandToBuffer(" - << (*command_list.front()) << "): delayed for " - << (next_send_time-now) << endl; - */ -#endif - return false; - } - - const bool rval = commandQueue.front()-> - writeCommandToBuffer(write_buff_end, - write_buff + sizeof(write_buff)); - if (rval) - { - next_send_time = now; - if (commandQueue.front()->needsNoAnswer()) - { - next_send_time += time_between_commands; - read_timeout_endtime = 0x7FFFFFFFFFFFFFFFLL; - } - else - { - if (commandQueue.front()->isCommandGoto()) - { - // shorter timeout for AutoStar 494 slew: - read_timeout_endtime = now + 3000000; - } - else - { - // extra long timeout for AutoStar 494: - read_timeout_endtime = now + 5000000; - } - } - #ifdef DEBUG4 - *log_file << Now() - << "Ultima2000Connection::writeFrontCommandToBuffer(" - << (*commandQueue.front()) - << "): queued" - << endl; - #endif - } - - return rval; -} - -void Ultima2000Connection::dataReceived(const char *&p,const char *read_buff_end) -{ - if (isClosed()) - { - *log_file << Now() - << "Ultima2000Connection::dataReceived: strange: fd is closed" - << endl; - } - else if (commandQueue.empty()) - { - if (GetNow() < next_send_time) - { - // just ignore - p = read_buff_end; - } - else - { -#ifdef DEBUG4 - *log_file << Now() << "Ultima2000Connection::dataReceived: " - "error: command_list is empty" << endl; -#endif - resetCommunication(); - static_cast<TelescopeClientDirectUltima2000*>(&server)->communicationResetReceived(); - } - } - else if (commandQueue.front()->needsNoAnswer()) - { - *log_file << Now() << "Ultima2000Connection::dataReceived: " - << "strange: command(" - << *commandQueue.front() - << ") needs no answer." - << endl; - p = read_buff_end; - } - else - { - while(true) - { - if (!commandQueue.front()->hasBeenWrittenToBuffer()) - { - *log_file << Now() - << "Ultima2000Connection::dataReceived: " - "strange: no answer expected" - << endl; - p = read_buff_end; - break; - } - const int rc = commandQueue.front()-> - readAnswerFromBuffer(p, read_buff_end); - //*log_file << Now() << "Ultima2000Connection::dataReceived: " - // << *command_list.front() << "->readAnswerFromBuffer returned " - // << rc << endl; - if (rc <= 0) - { - if (rc < 0) - { - resetCommunication(); - static_cast<TelescopeClientDirectUltima2000*>(&server)->communicationResetReceived(); - } - break; - } - if (commandQueue.front()->isCommandGoto()) - { - goto_commands_queued--; - } - delete commandQueue.front(); - commandQueue.pop_front(); - read_timeout_endtime = 0x7FFFFFFFFFFFFFFFLL; - if (!writeFrontCommandToBuffer()) - break; - } - } -} - -void Ultima2000Connection::prepareSelectFds(fd_set& read_fds, - fd_set& write_fds, - int& fd_max) -{ - // if some telegram is delayed try to queue it now: - flushCommandList(); - if (!commandQueue.empty() && GetNow() > read_timeout_endtime) - { - /*if (command_list.front()->shortAnswerReceived()) - { - // the lazy telescope, propably AutoStar 494 - // has not sent the full answer - #ifdef DEBUG4 - *log_file << Now() << "Ultima2000Connection::prepareSelectFds: " - "dequeueing command(" - << *command_list.front() - << ") because of timeout" - << endl; - #endif - if (command_list.front()->isCommandGoto()) - { - goto_commands_queued--; - } - delete command_list.front(); - command_list.pop_front(); - read_timeout_endtime = 0x7FFFFFFFFFFFFFFFLL; - } - else*/ - { - resetCommunication(); - } - } - SerialPortUltima2000::prepareSelectFds(read_fds, write_fds, fd_max); -} - -void Ultima2000Connection::flushCommandList() -{ - if (!commandQueue.empty()) - { - while (!commandQueue.front()->hasBeenWrittenToBuffer()) - { - if (writeFrontCommandToBuffer()) - { - //*log_file << Now() - // << "Ultima2000Connection::flushCommandList: " - // << (*command_list.front()) - // << "::writeFrontCommandToBuffer ok" - // << endl; - if (commandQueue.front()->needsNoAnswer()) - { - delete commandQueue.front(); - commandQueue.pop_front(); - read_timeout_endtime = 0x7FFFFFFFFFFFFFFFLL; - if (commandQueue.empty()) - break; - } - else - { - break; - } - } - else - { - //*log_file << Now() << "Ultima2000Connection::flushCommandList: " - // << (*command_list.front()) - // << "::writeFrontCommandToBuffer failed/delayed" << endl; - break; - } - } - } -} - -void Ultima2000Connection::sendCommand(Ultima2000Command *command) -{ - if (command) - { -#ifdef DEBUG4 - *log_file << Now() - << "Ultima2000Connection::sendCommand(" - << *command - << ")" - << endl; -#endif - commandQueue.push_back(command); - flushCommandList(); - /* - *log_file << Now() - << "Ultima2000Connection::sendCommand(" - << *command - << ") end" - << endl; - */ - } -} - diff --git a/plugins/TelescopeControl/src/servers/Ultima2000Connection.hpp b/plugins/TelescopeControl/src/servers/Ultima2000Connection.hpp deleted file mode 100644 index 778a7381e8..0000000000 --- a/plugins/TelescopeControl/src/servers/Ultima2000Connection.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -Stellarium telescope control -Copyright (c) 2006 Johannes Gajdosik -Copyright (c) 2011 Bogdan Marinov (Ultima2000 modifications) - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef _ULTIMA_2000_CONNECTION_HPP_ -#define _ULTIMA_2000_CONNECTION_HPP_ - -#include "SerialPortUltima2000.hpp" - -#include <list> -using namespace std; - -class Ultima2000Command; - -//! Serial port connection to a Celestron Ultima 2000 or a compatible telescope. -class Ultima2000Connection : public SerialPortUltima2000 -{ -public: - Ultima2000Connection(Server &server, const char *serial_device); - ~Ultima2000Connection() { resetCommunication(); } - void sendGoto(unsigned int ra_int, int dec_int); - void sendCommand(Ultima2000Command * command); - void setTimeBetweenCommands(long long int micro_seconds) - { - time_between_commands = micro_seconds; - } - -private: - //! Parses read buffer data received from the telescope. - void dataReceived(const char *&p, const char *read_buff_end); - //! Not implemented, as this is not a connection to a client. - void sendPosition(unsigned int ra_int, int dec_int, int status) {Q_UNUSED(ra_int); Q_UNUSED(dec_int); Q_UNUSED(status);} - void resetCommunication(); - void prepareSelectFds(fd_set &read_fds, fd_set &write_fds, int &fd_max); - bool writeFrontCommandToBuffer(); - //! Flushes the command queue, sending commands to the write buffer. - //! This method iterates over the queue, writing to the write buffer - //! as many commands as possible, until it reaches a command that - //! requires an answer. - void flushCommandList(); - -private: - list<Ultima2000Command*> commandQueue; - long long int time_between_commands; - long long int next_send_time; - long long int read_timeout_endtime; - int goto_commands_queued; -}; - -#endif //_ULTIMA_2000_CONNECTION_HPP_ |