diff --git a/plugins/TelescopeControl/src/ASCOM/TelescopeClientASCOM.hpp b/plugins/TelescopeControl/src/ASCOM/TelescopeClientASCOM.hpp index 75c6eea5fb9c7..445071555dff6 100644 --- a/plugins/TelescopeControl/src/ASCOM/TelescopeClientASCOM.hpp +++ b/plugins/TelescopeControl/src/ASCOM/TelescopeClientASCOM.hpp @@ -37,6 +37,7 @@ class TelescopeClientASCOM : public TelescopeClient void telescopeSync(const Vec3d& j2000Pos, StelObjectP selectObject) override; bool isTelescopeSyncSupported() const override {return true;} void telescopeAbortSlew() override; + bool isAbortSlewSupported() const override {return true;} bool isConnected() const override; bool hasKnownPosition() const override; static bool useJNow(ASCOMDevice::ASCOMEquatorialCoordinateType coordinateType, bool ascomUseDeviceEqCoordType, TelescopeControl::Equinox equinox); diff --git a/plugins/TelescopeControl/src/Lx200/Lx200Connection.cpp b/plugins/TelescopeControl/src/Lx200/Lx200Connection.cpp index 1d4f194d646ec..62ebc468e8b55 100644 --- a/plugins/TelescopeControl/src/Lx200/Lx200Connection.cpp +++ b/plugins/TelescopeControl/src/Lx200/Lx200Connection.cpp @@ -350,3 +350,24 @@ void Lx200Connection::sendCommand(Lx200Command *command) } } +void Lx200Connection::sendAbort() +{ +#ifdef DEBUG4 + *log_file << Now() + << "Lx200Connection::sendAbort()" + << StelUtils::getEndLineChar(); +#endif + // Remove queued commands (pointers, so delete their objects!) + while (!command_list.empty()) + { + delete command_list.front(); + command_list.pop_front(); + } + + read_buff_end = read_buff; + write_buff_end = write_buff; + command_list.push_back(new Lx200CommandStopSlew(server)); + flushCommandList(); + //*log_file << Now() << "Lx200Connection::sendAbort() end" + // << StelUtils::getEndLineChar(); +} diff --git a/plugins/TelescopeControl/src/Lx200/Lx200Connection.hpp b/plugins/TelescopeControl/src/Lx200/Lx200Connection.hpp index c4e85aa464ece..d78d48fdb77a2 100644 --- a/plugins/TelescopeControl/src/Lx200/Lx200Connection.hpp +++ b/plugins/TelescopeControl/src/Lx200/Lx200Connection.hpp @@ -39,6 +39,8 @@ class Lx200Connection : public SerialPort void sendGoto(unsigned int ra_int, int dec_int); void sendSync(unsigned int ra_int, int dec_int); void sendCommand(Lx200Command * command); + //! Delete pending commands and send abort signal. + void sendAbort(); void setTimeBetweenCommands(long long int micro_seconds) { time_between_commands = micro_seconds; diff --git a/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.cpp b/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.cpp index f8395ffa6f492..e9c267a0de426 100644 --- a/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.cpp +++ b/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.cpp @@ -93,6 +93,7 @@ TelescopeClientDirectLx200::TelescopeClientDirectLx200 (const QString &name, con } // lx200 will be deleted in the destructor of Server + // TODO: GZ2024: Server destructor is empty. Who deletes lx200 in version 24.2? Someone please clarify and fix documentation, then delete this note. addConnection(lx200); long_format_used = false; // unknown @@ -151,6 +152,13 @@ void TelescopeClientDirectLx200::telescopeSync(const Vec3d &j2000Pos, StelObject syncReceived(ra_int, dec_int); } +void TelescopeClientDirectLx200::telescopeAbortSlew() +{ + if (!isConnected()) + return; + lx200->sendAbort(); +} + void TelescopeClientDirectLx200::gotoReceived(unsigned int ra_int, int dec_int) { lx200->sendGoto(ra_int, dec_int); diff --git a/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.hpp b/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.hpp index d4ec166b03b86..41ad6aea645b7 100644 --- a/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.hpp +++ b/plugins/TelescopeControl/src/Lx200/TelescopeClientDirectLx200.hpp @@ -72,6 +72,8 @@ class TelescopeClientDirectLx200 : public TelescopeClient, public Server void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) override; void telescopeSync(const Vec3d &j2000Pos, StelObjectP selectObject) override; bool isTelescopeSyncSupported() const override {return true;} + void telescopeAbortSlew() override; + bool isAbortSlewSupported() const override {return true;} bool isInitialized(void) const override; //====================================================================== diff --git a/plugins/TelescopeControl/src/NexStar/NexStarCommand.cpp b/plugins/TelescopeControl/src/NexStar/NexStarCommand.cpp index cfbd45d8c1ad3..21fc338afe0dc 100644 --- a/plugins/TelescopeControl/src/NexStar/NexStarCommand.cpp +++ b/plugins/TelescopeControl/src/NexStar/NexStarCommand.cpp @@ -192,6 +192,46 @@ void NexStarCommandSync::print(QTextStream &o) const << ra << "," << dec <<')'; } +bool NexStarCommandAbort::writeCommandToBuffer(char *&p,char *end) +{ + #ifdef DEBUG5 + char *b = p; + #endif + + if (end-p < 1) + return false; + // Only one char: + *p = 'M'; + + has_been_written_to_buffer = true; + #ifdef DEBUG5 + *log_file << Now() << "NexStarCommandAbort::writeCommandToBuffer:" + << b << StelUtils::getEndLineChar(); + #endif + + return true; +} + +int NexStarCommandAbort::readAnswerFromBuffer(const char *&buff, const char *end) const +{ + if (buff >= end) + return 0; + +#ifdef DEBUG4 + if (*buff=='#') + *log_file << Now() << "NexStarCommandAbort::readAnswerFromBuffer: answer ok" << StelUtils::getEndLineChar(); + else + *log_file << Now() << "NexStarCommandSync::readAnswerFromBuffer: abort failed." << StelUtils::getEndLineChar(); +#endif + buff++; + return 1; +} + +void NexStarCommandAbort::print(QTextStream &o) const +{ + o << "NexStarCommandAbort()"; +} + bool NexStarCommandGetRaDec::writeCommandToBuffer(char *&p, char *end) { if (end-p < 1) diff --git a/plugins/TelescopeControl/src/NexStar/NexStarCommand.hpp b/plugins/TelescopeControl/src/NexStar/NexStarCommand.hpp index 7076600c5cd79..f75b7f52730c2 100644 --- a/plugins/TelescopeControl/src/NexStar/NexStarCommand.hpp +++ b/plugins/TelescopeControl/src/NexStar/NexStarCommand.hpp @@ -80,6 +80,16 @@ class NexStarCommandSync : public NexStarCommand int ra, dec; }; +//! Celestron NexStar command: abort a slew. +class NexStarCommandAbort : public NexStarCommand +{ +public: + NexStarCommandAbort(Server &server) : NexStarCommand(server){}; + bool writeCommandToBuffer(char *&buff, char *end) override; + int readAnswerFromBuffer(const char *&buff, const char *end) const override; + void print(QTextStream &o) const override; +}; + //! Celestron NexStar command: Get the current position. class NexStarCommandGetRaDec : public NexStarCommand { diff --git a/plugins/TelescopeControl/src/NexStar/NexStarConnection.cpp b/plugins/TelescopeControl/src/NexStar/NexStarConnection.cpp index 3b84edc8272d3..72d008bbe61ad 100644 --- a/plugins/TelescopeControl/src/NexStar/NexStarConnection.cpp +++ b/plugins/TelescopeControl/src/NexStar/NexStarConnection.cpp @@ -59,6 +59,23 @@ void NexStarConnection::sendSync(unsigned int ra_int, int dec_int) sendCommand(new NexStarCommandSync(server, ra_int, dec_int)); } +void NexStarConnection::sendAbort() +{ +#ifdef DEBUG4 + *log_file << Now() + << "NexStarConnection::sendAbort()" + << StelUtils::getEndLineChar(); +#endif + // Remove queued commands (pointers, so delete their objects!) + while (!command_list.empty()) + { + delete command_list.front(); + command_list.pop_front(); + } + + sendCommand(new NexStarCommandAbort(server)); +} + void NexStarConnection::dataReceived(const char *&p,const char *read_buff_end) { if (isClosed()) diff --git a/plugins/TelescopeControl/src/NexStar/NexStarConnection.hpp b/plugins/TelescopeControl/src/NexStar/NexStarConnection.hpp index b61cf9513bc9f..17bded1eada3f 100644 --- a/plugins/TelescopeControl/src/NexStar/NexStarConnection.hpp +++ b/plugins/TelescopeControl/src/NexStar/NexStarConnection.hpp @@ -39,6 +39,8 @@ class NexStarConnection : public SerialPort ~NexStarConnection(void) override { resetCommunication(); } void sendGoto(unsigned int ra_int, int dec_int); void sendSync(unsigned int ra_int, int dec_int); + //! Delete pending commands and send abort signal. + void sendAbort(); void sendCommand(NexStarCommand * command); private: diff --git a/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.cpp b/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.cpp index 916ddac4396fb..1fa6c6a1c3a78 100644 --- a/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.cpp +++ b/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.cpp @@ -90,6 +90,7 @@ TelescopeClientDirectNexStar::TelescopeClientDirectNexStar(const QString &name, } //This connection will be deleted in the destructor of Server + // TODO: GZ2024: Server destructor is empty. Who deletes nexstar in version 24.2? Someone please clarify and fix documentation, then delete this note. addConnection(nexstar); last_ra = 0; @@ -146,6 +147,10 @@ void TelescopeClientDirectNexStar::telescopeSync(const Vec3d &j2000Pos, StelObje syncReceived(ra_int, dec_int); } +void TelescopeClientDirectNexStar::telescopeAbortSlew() +{ + nexstar->sendAbort(); +} void TelescopeClientDirectNexStar::gotoReceived(unsigned int ra_int, int dec_int) { diff --git a/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.hpp b/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.hpp index f9ad26d789bf6..823a6f5bff0b4 100644 --- a/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.hpp +++ b/plugins/TelescopeControl/src/NexStar/TelescopeClientDirectNexStar.hpp @@ -71,6 +71,8 @@ class TelescopeClientDirectNexStar : public TelescopeClient, public Server void telescopeGoto(const Vec3d &j2000Pos, StelObjectP selectObject) override; void telescopeSync(const Vec3d &j2000Pos, StelObjectP selectObject) override; bool isTelescopeSyncSupported() const override {return true;} + void telescopeAbortSlew() override; + bool isAbortSlewSupported() const override {return true;} bool isInitialized(void) const override; //====================================================================== diff --git a/plugins/TelescopeControl/src/TelescopeClient.cpp b/plugins/TelescopeControl/src/TelescopeClient.cpp index ee82c71a3a4e9..1da714a735f64 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.cpp +++ b/plugins/TelescopeControl/src/TelescopeClient.cpp @@ -31,6 +31,7 @@ #include "INDI/TelescopeClientINDI.hpp" #include "StelTranslator.hpp" #include "StelCore.hpp" +#include "StelMainView.hpp" #include @@ -41,6 +42,7 @@ #include #include #include +#include #ifdef Q_OS_WIN #include "ASCOM/TelescopeClientASCOM.hpp" @@ -142,6 +144,12 @@ QString TelescopeClient::getInfoString(const StelCore* core, const InfoStringGro return str; } +void TelescopeClient::telescopeAbortSlew() +{ + qWarning() << "Telescope" << getID() << "does not support AbortSlew()!"; + QMessageBox::critical(&StelMainView::getInstance(), q_("QUICK!"), q_("This Telescope does not support Abort command!")); +} + void TelescopeClient::move(double angle, double speed) { Q_UNUSED(angle) diff --git a/plugins/TelescopeControl/src/TelescopeClient.hpp b/plugins/TelescopeControl/src/TelescopeClient.hpp index 59348d4db0bf2..e8a767fb21c3f 100644 --- a/plugins/TelescopeControl/src/TelescopeClient.hpp +++ b/plugins/TelescopeControl/src/TelescopeClient.hpp @@ -92,7 +92,12 @@ class TelescopeClient : public QObject, public StelObject //! report whether this client can respond to sync commands. //! Can be used for GUI tweaks virtual bool isTelescopeSyncSupported() const {return false;} - virtual void telescopeAbortSlew() { qWarning() << "Telescope" << getID() << "does not support AbortSlew()!"; } + //! Send command to abort slew. Not all telescopes support this, base implementation only gives a warning. + //! After abort, the current position should be retrieved and displayed. + virtual void telescopeAbortSlew(); + //! report whether this client can abort a running slew. + //! Can be used for GUI tweaks + virtual bool isAbortSlewSupported() const {return false;} //! //! \brief move @@ -175,6 +180,7 @@ class TelescopeClientDummy : public TelescopeClient desired_pos=XYZ; qDebug() << "Telescope" << getID() << "Slew aborted"; } + bool isAbortSlewSupported() const override {return true;} bool hasKnownPosition(void) const override { return true; diff --git a/plugins/TelescopeControl/src/TelescopeControl.hpp b/plugins/TelescopeControl/src/TelescopeControl.hpp index 7a0100cfd7d49..17bface3870c1 100644 --- a/plugins/TelescopeControl/src/TelescopeControl.hpp +++ b/plugins/TelescopeControl/src/TelescopeControl.hpp @@ -361,9 +361,10 @@ public slots: void slewTelescopeToViewDirection(const int idx); //! abort the current slew command of a telescope at slot idx. + //! @note ATTENTION! Not all telescopes support this call! A warning panel may be shown instead. Then it's jump and run to prevent damage. //! @code //! // example of usage in scripts - //! TelescopeControl.syncTelescopeToSelectedObject(1); + //! TelescopeControl.abortTelescopeSlew(1); //! @endcode void abortTelescopeSlew(const int idx); diff --git a/plugins/TelescopeControl/src/common/Socket.cpp b/plugins/TelescopeControl/src/common/Socket.cpp index ff84346d24ed0..1689283a17a6c 100644 --- a/plugins/TelescopeControl/src/common/Socket.cpp +++ b/plugins/TelescopeControl/src/common/Socket.cpp @@ -40,7 +40,7 @@ long long int GetNow(void) qint64 t; } tmp; GetSystemTimeAsFileTime(&tmp.file_time); - t = (tmp.t/10) - 86400000000LL*(369*365+89); + t = (tmp.t/10) - 86400000000LL*(369*365+89); // TODO: Explain this magic please! #else struct timeval tv; gettimeofday(&tv, 0); diff --git a/plugins/TelescopeControl/src/common/Socket.hpp b/plugins/TelescopeControl/src/common/Socket.hpp index 3504fabeed232..11898e22273a8 100644 --- a/plugins/TelescopeControl/src/common/Socket.hpp +++ b/plugins/TelescopeControl/src/common/Socket.hpp @@ -77,6 +77,8 @@ static inline int SetNonblocking(int s) #endif //Q_OS_WIN +// retrieve system time in milliseconds +// TODO: Specify epoch? long long int GetNow(void); class Server; diff --git a/plugins/TelescopeControl/src/gui/SlewDialog.cpp b/plugins/TelescopeControl/src/gui/SlewDialog.cpp index 81508852a1364..ea16fc6f99bb8 100644 --- a/plugins/TelescopeControl/src/gui/SlewDialog.cpp +++ b/plugins/TelescopeControl/src/gui/SlewDialog.cpp @@ -367,6 +367,7 @@ void SlewDialog::onCurrentTelescopeChanged() return; ui->pushButtonSync->setEnabled(telescope->isTelescopeSyncSupported()); + ui->pushButtonAbort->setEnabled(telescope->isAbortSlewSupported()); auto controlWidget = telescope->createControlWidget(telescope); if (!controlWidget) return;