Skip to content

Commit

Permalink
Add abort telescope slew signals to LX200 and NexStar telescopes (#2754)
Browse files Browse the repository at this point in the history
* Implement abortSlew command in LX200 and NexStar
* Make it clear in GUI whether abortSlew is supported.
* Docfix but questions to original dev or anybody interested
  • Loading branch information
gzotti authored Sep 7, 2024
1 parent 439b901 commit f653b90
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions plugins/TelescopeControl/src/Lx200/Lx200Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions plugins/TelescopeControl/src/Lx200/Lx200Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//======================================================================
Expand Down
40 changes: 40 additions & 0 deletions plugins/TelescopeControl/src/NexStar/NexStarCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions plugins/TelescopeControl/src/NexStar/NexStarCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
17 changes: 17 additions & 0 deletions plugins/TelescopeControl/src/NexStar/NexStarConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions plugins/TelescopeControl/src/NexStar/NexStarConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//======================================================================
Expand Down
8 changes: 8 additions & 0 deletions plugins/TelescopeControl/src/TelescopeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "INDI/TelescopeClientINDI.hpp"
#include "StelTranslator.hpp"
#include "StelCore.hpp"
#include "StelMainView.hpp"

#include <cmath>

Expand All @@ -41,6 +42,7 @@
#include <QString>
#include <QTcpSocket>
#include <QTextStream>
#include <QMessageBox>

#ifdef Q_OS_WIN
#include "ASCOM/TelescopeClientASCOM.hpp"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion plugins/TelescopeControl/src/TelescopeClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion plugins/TelescopeControl/src/TelescopeControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion plugins/TelescopeControl/src/common/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions plugins/TelescopeControl/src/common/Socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions plugins/TelescopeControl/src/gui/SlewDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f653b90

Please sign in to comment.