diff options
author | Alexander Wolf <alex.v.wolf@gmail.com> | 2019-11-05 20:13:32 +0700 |
---|---|---|
committer | Alexander Wolf <alex.v.wolf@gmail.com> | 2019-11-05 20:13:32 +0700 |
commit | 8dc7381f076140a0cd34b24c7d6b4fe1c18a8105 (patch) | |
tree | e25267fd068796d9ced6d2859e655a6b7597b57d | |
parent | b0271220c80959700731d8ff63c761946ad20004 (diff) |
Added support original Celestron NexStar 5/8 protocolnextstar5
13 files changed, 815 insertions, 3 deletions
diff --git a/plugins/TelescopeControl/CMakeLists.txt b/plugins/TelescopeControl/CMakeLists.txt index d5614531e7..ed973129e0 100644 --- a/plugins/TelescopeControl/CMakeLists.txt +++ b/plugins/TelescopeControl/CMakeLists.txt @@ -3,7 +3,7 @@ # otherwise the local copy will be overwritten each time Stellarium is started. SET(TELESCOPE_CONTROL_MAJOR "0") SET(TELESCOPE_CONTROL_MINOR "3") -SET(TELESCOPE_CONTROL_PATCH "1") +SET(TELESCOPE_CONTROL_PATCH "2") SET(TELESCOPE_CONTROL_VERSION "${TELESCOPE_CONTROL_MAJOR}.${TELESCOPE_CONTROL_MINOR}.${TELESCOPE_CONTROL_PATCH}") SET(CMAKE_INSTALL_PREFIX $HDATALOC) diff --git a/plugins/TelescopeControl/resources/device_models.json b/plugins/TelescopeControl/resources/device_models.json index 417b70a9e3..2c5f46fe86 100644 --- a/plugins/TelescopeControl/resources/device_models.json +++ b/plugins/TelescopeControl/resources/device_models.json @@ -1,5 +1,5 @@ { - "version": "0.3.1", + "version": "0.3.2", "list" : [ { @@ -39,6 +39,12 @@ "default_delay" : 500000 }, { + "name" : "Celestron NexStar 5/8 (compatible)", + "description" : "Any telescope or telescope mount compatible with Celestron NexStar 5/8.", + "server" : "TelescopeServerNexStar5", + "default_delay" : 500000 + }, + { "name" : "Sky-Watcher SynScan (version 3 or later)", "description" : "Any Sky-Watcher mount that uses version 3 or later of the SynScan hand controller.", "server" : "TelescopeServerNexStar", diff --git a/plugins/TelescopeControl/src/CMakeLists.txt b/plugins/TelescopeControl/src/CMakeLists.txt index 34586b7528..d65489bfe3 100644 --- a/plugins/TelescopeControl/src/CMakeLists.txt +++ b/plugins/TelescopeControl/src/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(common) add_subdirectory(gui) add_subdirectory(Lx200) add_subdirectory(NexStar) +add_subdirectory(NexStar5) add_subdirectory(Rts2) add_subdirectory(INDI) @@ -26,6 +27,7 @@ TARGET_LINK_LIBRARIES(TelescopeControl-static TelescopeControl_Lx200 TelescopeControl_INDI TelescopeControl_NexStar + TelescopeControl_NexStar5 TelescopeControl_Rts2 TelescopeControl_common Qt5::Core diff --git a/plugins/TelescopeControl/src/NexStar5/CMakeLists.txt b/plugins/TelescopeControl/src/NexStar5/CMakeLists.txt new file mode 100644 index 0000000000..26251a131c --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/CMakeLists.txt @@ -0,0 +1,20 @@ +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +add_library(TelescopeControl_NexStar5 STATIC + NexStar5Command.hpp + NexStar5Command.cpp + NexStar5Connection.hpp + NexStar5Connection.cpp + TelescopeClientDirectNexStar5.hpp + TelescopeClientDirectNexStar5.cpp + ) + +target_link_libraries(TelescopeControl_NexStar5 + Qt5::Core + Qt5::Network + Qt5::Gui + TelescopeControl_common + ) + +SET_TARGET_PROPERTIES(TelescopeControl_NexStar5 PROPERTIES FOLDER "plugins/TelescopeControl") diff --git a/plugins/TelescopeControl/src/NexStar5/NexStar5Command.cpp b/plugins/TelescopeControl/src/NexStar5/NexStar5Command.cpp new file mode 100644 index 0000000000..faced5490b --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/NexStar5Command.cpp @@ -0,0 +1,169 @@ +/* +The stellarium telescope library helps building +telescope server programs, that can communicate with stellarium +by means of the stellarium TCP telescope protocol. +It also contains smaple server classes (dummy, Meade LX200). + +Author and Copyright of this file and of the stellarium telescope library: +Johannes Gajdosik, 2006, modified for NexStar telescopes by Michael Heinz. + +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, Suite 500, Boston, MA 02110-1335, USA. +*/ + +#include "NexStar5Command.hpp" +#include "TelescopeClientDirectNexStar5.hpp" +#include "common/LogFile.hpp" + +#include <cmath> + +using namespace std; + +NexStar5Command::NexStar5Command(Server &server) : server(*static_cast<TelescopeClientDirectNexStar5*>(&server)), has_been_written_to_buffer(false) +{ +} + +NexStar5CommandGotoPosition::NexStar5CommandGotoPosition(Server &server, unsigned int ra_int, int dec_int) : NexStar5Command(server) +{ + dec = dec_int; + ra = static_cast<int>(ra_int); +} + +#define NIBTOASCII(x) (((x)<10)?('0'+(x)):('A'+(x)-10)) +#define ASCIITONIB(x) (((x)<'A')?((x)-'0'):((x)-'A'+10)) + +bool NexStar5CommandGotoPosition::writeCommandToBuffer(char *&p,char *end) +{ + #ifdef DEBUG5 + char *b = p; + #endif + + if (end-p < 6) + return false; + + *p++ = 'R'; + + // set the RA + int x = ra; + *p++ = NIBTOASCII ((x>>4) & 0x0f); + *p++ = NIBTOASCII (x & 0x0f); + *p++ = ','; + + // set object dec: + x = dec; + *p++ = NIBTOASCII ((x>>4) & 0x0f); + *p++ = NIBTOASCII (x & 0x0f); + *p = 0; + + has_been_written_to_buffer = true; + #ifdef DEBUG5 + *log_file << Now() << "NexStar5CommandGotoPosition::writeCommandToBuffer:" + << b << endl; + #endif + + return true; +} + +int NexStar5CommandGotoPosition::readAnswerFromBuffer(const char *&buff, const char *end) const +{ + if (buff >= end) + return 0; + + if (*buff=='@') + { + #ifdef DEBUG4 + *log_file << Now() << "NexStar5CommandGotoPosition::readAnswerFromBuffer: slew ok" + << endl; + #endif + } + else + { + #ifdef DEBUG4 + *log_file << Now() << "NexStar5CommandGotoPosition::readAnswerFromBuffer: slew failed." << endl; + #endif + } + buff++; + return 1; +} + +void NexStar5CommandGotoPosition::print(QTextStream &o) const +{ + o << "NexStar5CommandGotoPosition(" + << ra << "," << dec <<')'; +} + +bool NexStar5CommandGetRaDec::writeCommandToBuffer(char *&p, char *end) +{ + if (end-p < 1) + return false; + // get RA: + *p++ = 'E'; + has_been_written_to_buffer = true; + return true; +} + +int NexStar5CommandGetRaDec::readAnswerFromBuffer(const char *&buff, const char *end) const +{ + if (end-buff < 6) + return 0; + + int ra, dec; + const char *p = buff; + + // Next 2 bytes are RA. + ra = 0; + ra += ASCIITONIB(*p); ra <<= 4; p++; + ra += ASCIITONIB(*p); p++; + + if (*p++ != ',') + { + #ifdef DEBUG4 + *log_file << Now() << "NexStar5CommandGetRaDec::readAnswerFromBuffer: " + "error: ',' expected" << endl; + #endif + return -1; + } + + // Next 2 bytes are DEC. + dec = 0; + dec += ASCIITONIB(*p); dec <<= 4; p++; + dec += ASCIITONIB(*p); p++; + + if (*p++ != '@') + { + #ifdef DEBUG4 + *log_file << Now() << "NexStar5CommandGetRaDec::readAnswerFromBuffer: " + "error: '#' expected" << endl; + #endif + return -1; + } + + + #ifdef DEBUG4 + *log_file << Now() << "NexStar5CommandGetRaDec::readAnswerFromBuffer: " + "ra = " << ra << ", dec = " << dec + << endl; + #endif + buff = p; + + server.raReceived(static_cast<unsigned int>(ra)); + server.decReceived(static_cast<unsigned int>(dec)); + return 1; +} + +void NexStar5CommandGetRaDec::print(QTextStream &o) const +{ + o << "NexStar5CommandGetRaDec"; +} + diff --git a/plugins/TelescopeControl/src/NexStar5/NexStar5Command.hpp b/plugins/TelescopeControl/src/NexStar5/NexStar5Command.hpp new file mode 100644 index 0000000000..85da70b074 --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/NexStar5Command.hpp @@ -0,0 +1,81 @@ +/* +The stellarium telescope library helps building +telescope server programs, that can communicate with stellarium +by means of the stellarium TCP telescope protocol. +It also contains smaple server classes (dummy, Meade LX200). + +Author and Copyright of this file and of the stellarium telescope library: +Johannes Gajdosik, 2006, modified for NexStar telescopes by Michael Heinz. + +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, Suite 500, Boston, MA 02110-1335, USA. +*/ + +#ifndef NEXSTAR5COMMAND_HPP +#define NEXSTAR5COMMAND_HPP + +#include <QTextStream> +using namespace std; + +class Server; +class TelescopeClientDirectNexStar5; + +//! Abstract base class for Celestron NexStar (and compatible) commands. +class NexStar5Command +{ +public: + virtual ~NexStar5Command(void) {} + virtual bool writeCommandToBuffer(char *&buff, char *end) = 0; + bool hasBeenWrittenToBuffer(void) const { return has_been_written_to_buffer; } + virtual int readAnswerFromBuffer(const char *&buff, const char *end) const = 0; + virtual bool needsNoAnswer(void) const { return false; } + virtual void print(QTextStream &o) const = 0; + // returns true when reading is finished + +protected: + NexStar5Command(Server &server); + TelescopeClientDirectNexStar5 &server; + bool has_been_written_to_buffer; +}; + +inline QTextStream &operator<<(QTextStream &o, const NexStar5Command &c) +{ + c.print(o); + return o; +} + +//! Celestron NexStar command: Slew to a given position. +class NexStar5CommandGotoPosition : public NexStar5Command +{ +public: + NexStar5CommandGotoPosition(Server &server, unsigned int ra_int, int dec_int); + bool writeCommandToBuffer(char *&buff, char *end); + int readAnswerFromBuffer(const char *&buff, const char *end) const; + void print(QTextStream &o) const; + +private: + int ra, dec; +}; + +//! Celestron NexStar command: Get the current position. +class NexStar5CommandGetRaDec : public NexStar5Command +{ +public: + NexStar5CommandGetRaDec(Server &server) : NexStar5Command(server) {} + bool writeCommandToBuffer(char *&buff, char *end); + int readAnswerFromBuffer(const char *&buff, const char *end) const; + void print(QTextStream &o) const; +}; + +#endif diff --git a/plugins/TelescopeControl/src/NexStar5/NexStar5Connection.cpp b/plugins/TelescopeControl/src/NexStar5/NexStar5Connection.cpp new file mode 100644 index 0000000000..f07e9df7e7 --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/NexStar5Connection.cpp @@ -0,0 +1,143 @@ +/* +The stellarium telescope library helps building +telescope server programs, that can communicate with stellarium +by means of the stellarium TCP telescope protocol. +It also contains smaple server classes (dummy, Meade LX200). + +Author and Copyright of this file and of the stellarium telescope library: +Johannes Gajdosik, 2006, modified for NexStar telescopes by Michael Heinz. + +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, Suite 500, Boston, MA 02110-1335, USA. +*/ + +#include "NexStar5Connection.hpp" +#include "NexStar5Command.hpp" +#include "TelescopeClientDirectNexStar5.hpp" +#include "common/LogFile.hpp" + +#include <iostream> +using namespace std; + +NexStar5Connection::NexStar5Connection(Server &server, const char *serial_device) : SerialPort(server, serial_device) +{ +} + +void NexStar5Connection::resetCommunication(void) +{ + while (!command_list.empty()) + { + delete command_list.front(); + command_list.pop_front(); + } + + read_buff_end = read_buff; + write_buff_end = write_buff; +#ifdef DEBUG4 + *log_file << Now() << "NexStar5Connection::resetCommunication" << endl; +#endif +} + +void NexStar5Connection::sendGoto(unsigned int ra_int, int dec_int) +{ + sendCommand(new NexStar5CommandGotoPosition(server, ra_int, dec_int)); +} + +void NexStar5Connection::sendSync(unsigned int ra_int, int dec_int) +{ + return; +} + +void NexStar5Connection::dataReceived(const char *&p,const char *read_buff_end) +{ + if (isClosed()) + { + *log_file << Now() << "NexStar5Connection::dataReceived: strange: fd is closed" << endl; + } + else if (command_list.empty()) + { + #ifdef DEBUG4 + *log_file << Now() << "NexStar5Connection::dataReceived: " + "error: command_list is empty" << endl; + #endif + resetCommunication(); + static_cast<TelescopeClientDirectNexStar5*>(&server)->communicationResetReceived(); + } + else if (command_list.front()->needsNoAnswer()) + { + *log_file << Now() << "NexStar5Connection::dataReceived: " + "strange: command(" << *command_list.front() + << ") needs no answer" << endl; + } + else + { + while(true) + { + const int rc=command_list.front()->readAnswerFromBuffer(p, read_buff_end); + //*log_file << Now() << "NexStar5Connection::dataReceived: " + // << *command_list.front() << "->readAnswerFromBuffer returned " + // << rc << endl; + if (rc <= 0) + { + if (rc < 0) + { + resetCommunication(); + static_cast<TelescopeClientDirectNexStar5*>(&server)->communicationResetReceived(); + } + break; + } + delete command_list.front(); + command_list.pop_front(); + if (command_list.empty()) + break; + if (!command_list.front()->writeCommandToBuffer( + write_buff_end, + write_buff+sizeof(write_buff))) + break; + } + } +} + +void NexStar5Connection::sendCommand(NexStar5Command *command) +{ + if (command) + { + #ifdef DEBUG4 + *log_file << Now() << "NexStar5Connection::sendCommand(" << *command + << ")" << endl; + #endif + command_list.push_back(command); + while (!command_list.front()->hasBeenWrittenToBuffer()) + { + if (command_list.front()->writeCommandToBuffer(write_buff_end, write_buff+sizeof(write_buff))) + { + //*log_file << Now() << "NexStar5Connection::sendCommand: " + // << (*command_list.front()) + // << "::writeCommandToBuffer ok" << endl; + if (command_list.front()->needsNoAnswer()) + { + delete command_list.front(); + command_list.pop_front(); + if (command_list.empty()) + break; + } + else + break; + } + else + break; + } + } +} + diff --git a/plugins/TelescopeControl/src/NexStar5/NexStar5Connection.hpp b/plugins/TelescopeControl/src/NexStar5/NexStar5Connection.hpp new file mode 100644 index 0000000000..a730ade9bc --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/NexStar5Connection.hpp @@ -0,0 +1,54 @@ +/* +The stellarium telescope library helps building +telescope server programs, that can communicate with stellarium +by means of the stellarium TCP telescope protocol. +It also contains smaple server classes (dummy, Meade LX200). + +Author and Copyright of this file and of the stellarium telescope library: +Johannes Gajdosik, 2006, modified for NexStar telescopes by Michael Heinz. + +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, Suite 500, Boston, MA 02110-1335, USA. +*/ + +#ifndef NEXSTAR5CONNECTION_HPP +#define NEXSTAR5CONNECTION_HPP + +#include "common/SerialPort.hpp" + +#include <list> +using namespace std; + +class NexStar5Command; + +//! Serial port connection to a Celestron NexStar 5/8 or a compatible telescope. +class NexStar5Connection : public SerialPort +{ +public: + NexStar5Connection(Server &server, const char *serial_device); + ~NexStar5Connection(void) { resetCommunication(); } + void sendGoto(unsigned int ra_int, int dec_int); + void sendSync(unsigned int ra_int, int dec_int); + void sendCommand(NexStar5Command * command); + +private: + void dataReceived(const char *&p, const char *read_buff_end); + 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); + +private: + list<NexStar5Command*> command_list; +}; + +#endif // NEXSTAR5CONNECTION_HPP diff --git a/plugins/TelescopeControl/src/NexStar5/TelescopeClientDirectNexStar5.cpp b/plugins/TelescopeControl/src/NexStar5/TelescopeClientDirectNexStar5.cpp new file mode 100644 index 0000000000..db39d0efa7 --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/TelescopeClientDirectNexStar5.cpp @@ -0,0 +1,228 @@ +/* + * Stellarium Telescope Control Plug-in + * + * Copyright (C) 2019 Alexander Wolf + * + * 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#include "TelescopeClientDirectNexStar5.hpp" + +#include "NexStar5Connection.hpp" +#include "NexStar5Command.hpp" +#include "common/LogFile.hpp" +#include "StelCore.hpp" + +#include <QRegExp> +#include <QStringList> + +TelescopeClientDirectNexStar5::TelescopeClientDirectNexStar5(const QString &name, const QString ¶meters, Equinox eq) + : TelescopeClient(name) + , time_delay(0) + , equinox(eq) + , nexstar5(Q_NULLPTR) + , last_ra(0) + , queue_get_position(true) + , next_pos_time(0) +{ + 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 TelescopeClientDirectNexStar: invalid parameters."; + return; + } + + qDebug() << "TelescopeClientDirectNexStar parameters: port, time_delay:" << serialDeviceName << time_delay; + + //Validation: Time delay + if (time_delay <= 0 || time_delay > 10000000) + { + qWarning() << "ERROR creating TelescopeClientDirectNexStar: time_delay not valid (should be less than 10000000)"; + return; + } + + //end_of_timeout = -0x8000000000000000LL; + + #ifdef Q_OS_WIN + if(serialDeviceName.right(serialDeviceName.size() - 3).toInt() > 9) + serialDeviceName = "\\\\.\\" + serialDeviceName; // "\\.\COMxx", not sure if it will work + #endif //Q_OS_WIN + + //Try to establish a connection to the telescope + nexstar5 = new NexStar5Connection(*this, qPrintable(serialDeviceName)); + if (nexstar5->isClosed()) + { + qWarning() << "ERROR creating TelescopeClientDirectNexStar: cannot open serial device" << serialDeviceName; + return; + } + + //This connection will be deleted in the destructor of Server + //addConnection(nexstar5); + + last_ra = 0; + queue_get_position = true; + next_pos_time = -0x8000000000000000LL; +} + +//! queues a GOTO command +void TelescopeClientDirectNexStar5::telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) +{ + Q_UNUSED(selectObject) + + if (!isConnected()) + return; + + Vec3d position = j2000Pos; + if (equinox == EquinoxJNow) + { + const StelCore* core = StelApp::getInstance().getCore(); + position = core->j2000ToEquinoxEqu(j2000Pos, StelCore::RefractionOff); + } + + 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], std::sqrt(position[0]*position[0]+position[1]*position[1])); + unsigned int ra_int = static_cast<unsigned int>(floor(0.5 + ra*(static_cast<unsigned int>(0x80000000)/M_PI))); + int dec_int = static_cast<int>(floor(0.5 + dec*(static_cast<unsigned int>(0x80000000)/M_PI))); + + gotoReceived(ra_int, dec_int); +} + +void TelescopeClientDirectNexStar5::telescopeSync(const Vec3d &j2000Pos, StelObjectP selectObject) +{ + Q_UNUSED(selectObject) + Q_UNUSED(j2000Pos) + return; +} + + +void TelescopeClientDirectNexStar5::gotoReceived(unsigned int ra_int, int dec_int) +{ + nexstar5->sendGoto(ra_int, dec_int); +} + +void TelescopeClientDirectNexStar5::syncReceived(unsigned int ra_int, int dec_int) +{ + Q_UNUSED(ra_int) + Q_UNUSED(dec_int) + return; +} + +//! estimates where the telescope is by interpolation in the stored +//! telescope positions: +Vec3d TelescopeClientDirectNexStar5::getJ2000EquatorialPos(const StelCore*) const +{ + const qint64 now = getNow() - time_delay; + return interpolatedPosition.get(now); +} + +bool TelescopeClientDirectNexStar5::prepareCommunication() +{ + //TODO: Nothing to prepare? + return true; +} + +void TelescopeClientDirectNexStar5::performCommunication() +{ + step(10000); +} + +void TelescopeClientDirectNexStar5::communicationResetReceived(void) +{ + queue_get_position = true; + next_pos_time = -0x8000000000000000LL; + +#ifndef QT_NO_DEBUG + *log_file << Now() << "TelescopeClientDirectNexStar::communicationResetReceived" << endl; +#endif +} + +//! Called by NexStarCommandGetRaDec::readAnswerFromBuffer(). +void TelescopeClientDirectNexStar5::raReceived(unsigned int ra_int) +{ + last_ra = ra_int; +#ifndef QT_NO_DEBUG + *log_file << Now() << "TelescopeClientDirectNexStar::raReceived: " << ra_int << endl; +#endif +} + +//! Called by NexStarCommandGetRaDec::readAnswerFromBuffer(). +//! Should be called after raReceived(), as it contains a call to sendPosition(). +void TelescopeClientDirectNexStar5::decReceived(unsigned int dec_int) +{ +#ifndef QT_NO_DEBUG + *log_file << Now() << "TelescopeClientDirectNexStar::decReceived: " << dec_int << endl; +#endif + const int nexstar_status = 0; + sendPosition(last_ra, static_cast<int>(dec_int), nexstar_status); + queue_get_position = true; +} + +void TelescopeClientDirectNexStar5::step(long long int timeout_micros) +{ + long long int now = GetNow(); + if (queue_get_position && now >= next_pos_time) + { + nexstar5->sendCommand(new NexStar5CommandGetRaDec(*this)); + queue_get_position = false; + next_pos_time = now + 500000; + } + Server::step(timeout_micros); +} + +bool TelescopeClientDirectNexStar5::isConnected(void) const +{ + return (!nexstar5->isClosed());//TODO +} + +bool TelescopeClientDirectNexStar5::isInitialized(void) const +{ + return (!nexstar5->isClosed()); +} + +//Merged from Connection::sendPosition() and TelescopeTCP::performReading() +void TelescopeClientDirectNexStar5::sendPosition(unsigned int ra_int, int dec_int, int status) +{ + //Server time is "now", because this class is the server + const qint64 server_micros = static_cast<qint64>(GetNow()); + const double ra = ra_int * (M_PI/0x80000000u); + const double dec = dec_int * (M_PI/0x80000000u); + 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, StelCore::RefractionOff); + } + interpolatedPosition.add(j2000Position, getNow(), server_micros, status); +} diff --git a/plugins/TelescopeControl/src/NexStar5/TelescopeClientDirectNexStar5.hpp b/plugins/TelescopeControl/src/NexStar5/TelescopeClientDirectNexStar5.hpp new file mode 100644 index 0000000000..0ab4222735 --- /dev/null +++ b/plugins/TelescopeControl/src/NexStar5/TelescopeClientDirectNexStar5.hpp @@ -0,0 +1,102 @@ +/* + * Stellarium Telescope Control Plug-in + * + * Copyright (C) 2019 Alexander Wolf + * + * 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#ifndef TELESCOPECLIENTDIRECTNEXSTAR5_HPP +#define TELESCOPECLIENTDIRECTNEXSTAR5_HPP + +#include <QObject> +#include <QString> + +#include "StelApp.hpp" +#include "StelObject.hpp" + +#include "common/Server.hpp" //from the telescope server source tree +#include "TelescopeClient.hpp" //from the plug-in's source tree +#include "common/InterpolatedPosition.hpp" + +class NexStar5Connection; + +//! Telescope client that connects directly to a Celestron NexStar through a serial port. +//! This class has been created by merging the code of TelescopeTCP and ServerNexStar. +class TelescopeClientDirectNexStar5 : public TelescopeClient, public Server +{ + Q_OBJECT +public: + TelescopeClientDirectNexStar5(const QString &name, const QString ¶meters, Equinox eq = EquinoxJ2000); + ~TelescopeClientDirectNexStar5(void) + { + //hangup(); + } + + //====================================================================== + // Methods inherited from TelescopeClient + bool isConnected(void) const; + + //====================================================================== + // Methods inherited from Server + virtual void step(long long int timeout_micros); + void communicationResetReceived(void); + void raReceived(unsigned int ra_int); + void decReceived(unsigned int dec_int); + +private: + //====================================================================== + // Methods inherited from TelescopeClient + Vec3d getJ2000EquatorialPos(const StelCore* core=Q_NULLPTR) const; + bool prepareCommunication(); + void performCommunication(); + void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject); + void telescopeSync(const Vec3d &j2000Pos, StelObjectP selectObject); + bool isInitialized(void) const; + + //====================================================================== + // Methods inherited from Server + void sendPosition(unsigned int ra_int, int dec_int, int status); + //TODO: Find out if this method is needed. It's called by Connection. + void gotoReceived(unsigned int ra_int, int dec_int); + void syncReceived(unsigned int ra_int, int dec_int); + +private: + void hangup(void); + int time_delay; + + InterpolatedPosition interpolatedPosition; + virtual bool hasKnownPosition(void) const + { + return interpolatedPosition.isKnown(); + } + + Equinox equinox; + + //====================================================================== + // Members taken from ServerNexStar5 + NexStar5Connection* nexstar5; + + unsigned int last_ra; + bool queue_get_position; + long long int next_pos_time; +}; + +#endif // TELESCOPECLIENTDIRECTLX200_HPP diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index ad19596be0..8391085164 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -27,6 +27,7 @@ #include "Rts2/TelescopeClientJsonRts2.hpp" #include "Lx200/TelescopeClientDirectLx200.hpp" #include "NexStar/TelescopeClientDirectNexStar.hpp" +#include "NexStar5/TelescopeClientDirectNexStar5.hpp" #include "INDI/TelescopeClientINDI.hpp" #include "StelUtils.hpp" #include "StelTranslator.hpp" @@ -108,6 +109,10 @@ TelescopeClient *TelescopeClient::create(const QString &url) { newTelescope= new TelescopeClientDirectNexStar(name, params, eq); } + else if (type == "TelescopeServerNexStar5") + { + newTelescope= new TelescopeClientDirectNexStar5(name, params, eq); + } else if (type == "INDI") { newTelescope = new TelescopeClientINDI(name, params); diff --git a/plugins/TelescopeControl/src/TelescopeControl.cpp b/plugins/TelescopeControl/src/TelescopeControl.cpp index 80e050c436..9a867d9052 100644 --- a/plugins/TelescopeControl/src/TelescopeControl.cpp +++ b/plugins/TelescopeControl/src/TelescopeControl.cpp @@ -1729,6 +1729,8 @@ void TelescopeControl::translations() N_("Wildcard Innovations' Argo Navis DTC in Meade LX200 emulation mode.") // TRANSLATORS: Description for Celestron NexStar (compatible) mounts N_("Any telescope or telescope mount compatible with Celestron NexStar.") + // TRANSLATORS: Description for Celestron NexStar 5/8 (compatible) mounts + N_("Any telescope or telescope mount compatible with Celestron NexStar 5/8.") // TRANSLATORS: Description for Sky-Watcher SynScan (version 3 or later) mounts N_("Any Sky-Watcher mount that uses version 3 or later of the SynScan hand controller.") // TRANSLATORS: Description for Sky-Watcher SynScan AZ GOTO mounts diff --git a/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp b/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp index 913921140a..2617ee03d5 100644 --- a/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp +++ b/plugins/TelescopeControl/src/TelescopeControlGlobals.hpp @@ -67,7 +67,7 @@ namespace TelescopeControlGlobals { }; //! List of the telescope servers that don't need external executables - const QStringList EMBEDDED_TELESCOPE_SERVERS = QString("TelescopeServerDummy TelescopeServerLx200 TelescopeServerNexStar").split(' ', QString::SkipEmptyParts); + const QStringList EMBEDDED_TELESCOPE_SERVERS = QString("TelescopeServerDummy TelescopeServerLx200 TelescopeServerNexStar TelescopeServerNexStar5").split(' ', QString::SkipEmptyParts); }; #endif // TELESCOPECONTROLGLOBALS_HPP |