11#include <KLocalizedString>
14#include <QNetworkReply>
33 sendCommand(GET_RA_DEC_DRIFT);
37bool LinGuider::Connect()
39 if (connection == DISCONNECTED)
42 connection = CONNECTING;
43 tcpSocket->
connectToHost(Options::linGuiderHost(), Options::linGuiderPort());
47 emit newStatus(GUIDE_CONNECTED);
52bool LinGuider::Disconnect()
55 connection = DISCONNECTED;
58 emit newStatus(GUIDE_DISCONNECTED);
70 emit newLog(
i18n(
"The host was not found. Please check the host name and port settings in Guide options."));
71 emit newStatus(GUIDE_DISCONNECTED);
74 emit newLog(
i18n(
"The connection was refused by the peer. Make sure the LinGuider is running, and check "
75 "that the host name and port settings are correct."));
76 emit newStatus(GUIDE_DISCONNECTED);
82 connection = DISCONNECTED;
85void LinGuider::readLinGuider()
87 while (tcpSocket->
atEnd() ==
false)
89 rawBuffer += tcpSocket->
readAll();
93 if (rawBuffer.
count() < 8)
96 if (Options::guideLogging())
99 qint16
magicNumber = *(
reinterpret_cast<qint16 *
>(rawBuffer.data()));
102 emit newLog(
i18n(
"Invalid response."));
103 rawBuffer = rawBuffer.mid(1);
107 qint16 command = *(
reinterpret_cast<qint16 *
>(rawBuffer.data() + 2));
110 emit newLog(
i18n(
"Invalid response."));
111 rawBuffer = rawBuffer.mid(1);
115 qint16
datalen = *(
reinterpret_cast<qint16 *
>(rawBuffer.data() + 4));
116 if (rawBuffer.count() <
datalen + 8)
120 processResponse(
static_cast<LinGuiderCommand
>(command), reply);
121 rawBuffer = rawBuffer.mid(8 +
datalen);
126void LinGuider::processResponse(LinGuiderCommand command,
const QString &reply)
128 if (reply ==
"Error: Guiding not started.")
131 emit newStatus(GUIDE_ABORTED);
132 deviationTimer.
stop();
139 emit newLog(
i18n(
"Connected to LinGuider %1", reply));
140 if (reply <
"v.4.1.0")
143 i18n(
"Only LinGuider v4.1.0 or higher is supported. Please upgrade LinGuider and try again."));
147 sendCommand(GET_GUIDER_STATE);
150 case GET_GUIDER_STATE:
151 if (reply ==
"GUIDING")
154 emit newStatus(GUIDE_GUIDING);
155 deviationTimer.
start();
160 deviationTimer.
stop();
166 emit newLog(
i18n(
"Auto star selected %1", reply));
168 if (pos.
count() == 2)
171 sendCommand(SET_GUIDER_RETICLE_POS, reply);
175 emit newLog(
i18n(
"Failed to process star position."));
176 emit newStatus(GUIDE_CALIBRATION_ERROR);
181 case SET_GUIDER_RETICLE_POS:
184 sendCommand(SET_GUIDER_SQUARE_POS, starCenter);
188 emit newLog(
i18n(
"Failed to set guider reticle position."));
189 emit newStatus(GUIDE_CALIBRATION_ERROR);
193 case SET_GUIDER_SQUARE_POS:
196 emit newStatus(GUIDE_CALIBRATION_SUCCESS);
200 emit newLog(
i18n(
"Failed to set guider square position."));
201 emit newStatus(GUIDE_CALIBRATION_ERROR);
210 emit newStatus(GUIDE_GUIDING);
213 deviationTimer.
start();
217 emit newStatus(GUIDE_IDLE);
220 deviationTimer.
stop();
226 emit newLog(
i18n(
"Failed to start guider."));
228 emit newLog(
i18n(
"Failed to stop guider."));
232 case GET_RA_DEC_DRIFT:
234 if (state != GUIDING)
237 emit newStatus(GUIDE_GUIDING);
241 if (pos.
count() == 2)
253 emit newLog(
i18n(
"Failed to get RA/DEC Drift."));
258 case SET_DITHERING_RANGE:
263 deviationTimer.
stop();
267 emit newLog(
i18n(
"Failed to set dither range."));
272 if (reply ==
"Long time cmd finished")
273 emit newStatus(GUIDE_DITHERING_SUCCESS);
275 emit newStatus(GUIDE_DITHERING_ERROR);
278 deviationTimer.
start();
286void LinGuider::onConnected()
288 connection = CONNECTED;
290 emit newStatus(GUIDE_CONNECTED);
293 sendCommand(GET_VER);
296void LinGuider::sendCommand(LinGuiderCommand command,
const QString &
args)
300 int size = 8 +
args.size();
317 if (
args.isEmpty() ==
false)
323bool LinGuider::calibrate()
326 emit newStatus(Ekos::GUIDE_CALIBRATING);
328 sendCommand(FIND_STAR);
333bool LinGuider::guide()
335 sendCommand(GUIDER,
"start");
339bool LinGuider::abort()
341 sendCommand(GUIDER,
"stop");
345bool LinGuider::suspend()
350bool LinGuider::resume()
355bool LinGuider::dither(
double pixels)
360 sendCommand(SET_DITHERING_RANGE,
args);
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void connectToHost(const QHostAddress &address, quint16 port, OpenMode openMode)
virtual void disconnectFromHost()
qsizetype count() const const
virtual bool atEnd() const const
QString errorString() const const
qint64 write(const QByteArray &data)
qsizetype count() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
void setInterval(int msec)