summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-09 15:12:54 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-09 15:12:54 (GMT)
commitde269d387142b6b6bae6c6820df7f7b5462ebb6b (patch)
tree123a6481c9aeda0d2c22ac59cf19674c891dc8a4
parentdeaf6c7335520547334c598b33bf73c6423eeca3 (diff)
LinGuider is now supported. Needs more testing of course
-rw-r--r--kstars/ekos/guide/externalguide/linguider.cpp119
-rw-r--r--kstars/ekos/guide/guide.cpp26
-rw-r--r--kstars/ekos/guide/guide.h2
3 files changed, 122 insertions, 25 deletions
diff --git a/kstars/ekos/guide/externalguide/linguider.cpp b/kstars/ekos/guide/externalguide/linguider.cpp
index 7534098..9ae83df 100644
--- a/kstars/ekos/guide/externalguide/linguider.cpp
+++ b/kstars/ekos/guide/externalguide/linguider.cpp
@@ -35,6 +35,9 @@ LinGuider::LinGuider()
state = IDLE;
connection = DISCONNECTED;
+
+ deviationTimer.setInterval(1000);
+ connect(&deviationTimer, &QTimer::timeout, this, [&](){sendCommand(GET_RA_DEC_DRIFT);});
}
LinGuider::~LinGuider()
@@ -92,14 +95,16 @@ void LinGuider::readLinGuider()
{
QTextStream stream(tcpSocket);
+ QString rawString;
+
while (stream.atEnd() == false)
{
- QString rawString = stream.readLine();
+ rawString += stream.readLine();
- if (rawString.isEmpty())
+ if (rawString.count() < 8)
continue;
- if (Options::verboseLogging())
+ if (Options::guideLogging())
emit newLog(rawString);
qint16 magicNumber = *(reinterpret_cast<qint16*>(rawString.toLatin1().data()));
@@ -119,6 +124,8 @@ void LinGuider::readLinGuider()
QString reply = rawString.mid(8);
processResponse(static_cast<LinGuiderCommand>(command), reply);
+
+ rawString.clear();
}
}
@@ -155,7 +162,7 @@ void LinGuider::processResponse(LinGuiderCommand command, const QString &reply)
case SET_GUIDER_RETICLE_POS:
if (reply == "OK")
{
- sendCommand(SET_GUIDER_OVLS_POS, starCenter);
+ sendCommand(SET_GUIDER_SQUARE_POS, starCenter);
}
else
{
@@ -163,6 +170,89 @@ void LinGuider::processResponse(LinGuiderCommand command, const QString &reply)
emit newStatus(GUIDE_CALIBRATION_ERROR);
}
break;
+
+ case SET_GUIDER_SQUARE_POS:
+ if (reply == "OK")
+ {
+ emit newStatus(GUIDE_CALIBRATION_SUCESS);
+ }
+ else
+ {
+ emit newLog(i18n("Failed to set guider square position."));
+ emit newStatus(GUIDE_CALIBRATION_ERROR);
+ }
+ break;
+
+ case GUIDER:
+ if (reply == "OK")
+ {
+ if (state == IDLE)
+ {
+ emit newStatus(GUIDE_GUIDING);
+ state = GUIDING;
+
+ deviationTimer.start();
+ }
+ else
+ {
+ emit newStatus(GUIDE_IDLE);
+ state = IDLE;
+
+ deviationTimer.stop();
+ }
+ }
+ else
+ {
+ if (state == IDLE)
+ emit newLog(i18n("Failed to start guider."));
+ else
+ emit newLog(i18n("Failed to stop guider."));
+ }
+ break;
+
+ case GET_RA_DEC_DRIFT:
+ {
+ QStringList pos = reply.split(' ');
+ if (pos.count() == 2)
+ {
+ bool raOK=false, deOK=false;
+
+ double raDev = pos[0].toDouble(&raOK);
+ double deDev = pos[1].toDouble(&deOK);
+
+ if (raDev && deDev)
+ emit newAxisDelta(raDev, deDev);
+ }
+ else
+ {
+ emit newLog(i18n("Failed to get RA/DEC Drift."));
+ }
+ }
+ break;
+
+ case SET_DITHERING_RANGE:
+ if (reply == "OK")
+ {
+ sendCommand(DITHER);
+
+ deviationTimer.stop();
+ }
+ else
+ {
+ emit newLog(i18n("Failed to set dither range."));
+ }
+ break;
+
+ case DITHER:
+ if (reply == "OK")
+ emit newStatus(GUIDE_DITHERING_SUCCESS);
+ else
+ emit newStatus(GUIDE_DITHERING_ERROR);
+
+ state = GUIDING;
+ deviationTimer.start();
+ break;
+
default:
break;
}
@@ -178,10 +268,6 @@ void LinGuider::onConnected()
void LinGuider::sendCommand(LinGuiderCommand command, const QString &args)
{
- //emit newLog(json_doc.toJson(QJsonDocument::Compact));
-
- //tcpSocket->write(json_doc.toJson(QJsonDocument::Compact));
-
// Command format: Magic Number (0x00 0x02), cmd (2 bytes), len_of_param (4 bytes), param (ascii)
int size = 8 + args.size();
@@ -219,35 +305,32 @@ bool LinGuider::calibrate()
bool LinGuider::guide()
{
-
- //
-
+ sendCommand(GUIDER, "start");
return true;
}
bool LinGuider::abort()
{
-
+ sendCommand(GUIDER, "stop");
return true;
}
bool LinGuider::suspend()
{
-
- return true;
-
+ return abort();
}
bool LinGuider::resume()
{
-
- return true;
-
+ return guide();
}
bool LinGuider::dither(double pixels)
{
+ QString pixelsString = QString::number(pixels, 'f', 2);
+ QString args = QString("%1 %2").arg(pixelsString).arg(pixelsString);
+ sendCommand(SET_DITHERING_RANGE, args);
return true;
}
diff --git a/kstars/ekos/guide/guide.cpp b/kstars/ekos/guide/guide.cpp
index 2045d6d..424b9b2 100644
--- a/kstars/ekos/guide/guide.cpp
+++ b/kstars/ekos/guide/guide.cpp
@@ -244,11 +244,8 @@ Guide::Guide() : QWidget()
internalGuider->setGuideView(guideView);
- // Get current saved type
- guiderType = static_cast<GuiderType>(Options::guiderType());
-
// Set current guide type
- setGuiderType(guiderType);
+ setGuiderType(-1);
state = GUIDE_IDLE;
}
@@ -764,7 +761,6 @@ void Guide::setCaptureComplete()
case GUIDE_CALIBRATION_SUCESS:
case GUIDE_CALIBRATION_ERROR:
case GUIDE_DITHERING_ERROR:
- case GUIDE_DITHERING_SUCCESS:
setBusy(false);
break;
@@ -1138,6 +1134,12 @@ void Guide::setStatus(Ekos::GuideState newState)
case GUIDE_DITHERING_ERROR:
appendLogText(i18n("Dithering failed!"));
+ // LinGuider guide continue after dithering failure
+ if (guiderType != GUIDE_LINGUIDER)
+ {
+ state = GUIDE_IDLE;
+ setBusy(false);
+ }
break;
case GUIDE_DITHERING_SUCCESS:
@@ -1250,7 +1252,19 @@ void Guide::syncTrackingBoxPosition()
}
bool Guide::setGuiderType(int type)
-{
+{
+ // Use default guider option
+ if (type == -1)
+ type = Options::guiderType();
+ else if (type == guiderType)
+ return true;
+
+ if (state > GUIDE_ABORTED)
+ {
+ appendLogText(i18n("Cannot change guider type while active."));
+ return false;
+ }
+
if (guider)
guider->disconnect(this);
diff --git a/kstars/ekos/guide/guide.h b/kstars/ekos/guide/guide.h
index 6724af6..83b1ba5 100644
--- a/kstars/ekos/guide/guide.h
+++ b/kstars/ekos/guide/guide.h
@@ -266,7 +266,7 @@ public slots:
/** DBUS interface function.
* Selects which guiding process to utilize for calibration & guiding.
- * @param type Type of guider process to use. 0 for internal guider, 1 for external PHD2, 2 for external lin_guider
+ * @param type Type of guider process to use. 0 for internal guider, 1 for external PHD2, 2 for external lin_guider. Pass -1 to select default guider in options.
* @return True if guiding is switched to the new requested type. False otherwise.
*/
Q_SCRIPTABLE bool setGuiderType(int type);