diff --git a/kstars/ekos/guide/externalguide/phd2.h b/kstars/ekos/guide/externalguide/phd2.h --- a/kstars/ekos/guide/externalguide/phd2.h +++ b/kstars/ekos/guide/externalguide/phd2.h @@ -98,7 +98,7 @@ //flip_calibration //get_algo_param_names //get_algo_param - //get_app_state + APP_STATE_RECEIVED, //get_app_state //get_calibrated //get_calibration_data IS_EQUIPMENT_CONNECTED, //get_connected @@ -155,7 +155,7 @@ //flip_calibration //get_algo_param_names //get_algo_param - //get_app_state + void requestAppState(); //get_app_state //get_calibrated //get_calibration_data void checkIfEquipmentConnected(); //get_connected @@ -202,7 +202,7 @@ bool isCurrentCameraNotInEkos(){ return currentCameraIsNotInEkos; } void setCurrentCameraIsNotInEkos(bool enable) {currentCameraIsNotInEkos = enable;} - private slots: +private slots: void readPHD2(); void displayError(QAbstractSocket::SocketError socketError); @@ -220,6 +220,7 @@ void processPHD2Result(const QJsonObject &jsonObj, const QByteArray &rawResult); void processStarImage(const QJsonObject &jsonStarFrame); void processPHD2State(const QString &phd2State); + void handlePHD2AppState(PHD2State state); void processPHD2Error(const QJsonObject &jsonError, const QByteArray &rawResult); PHD2ResultType takeRequestFromList(const QJsonObject &response); diff --git a/kstars/ekos/guide/externalguide/phd2.cpp b/kstars/ekos/guide/externalguide/phd2.cpp --- a/kstars/ekos/guide/externalguide/phd2.cpp +++ b/kstars/ekos/guide/externalguide/phd2.cpp @@ -74,7 +74,7 @@ //flip_calibration //get_algo_param_names //get_algo_param - //get_app_state + methodResults["get_app_state"] = APP_STATE_RECEIVED; //get_calibrated //get_calibration_data methodResults["get_connected"] = IS_EQUIPMENT_CONNECTED; @@ -321,8 +321,7 @@ break; case LoopingExposures: - state = LOOPING; - //emit newLog(i18n("PHD2: Looping Exposures.")); + handlePHD2AppState(LOOPING); break; case LoopingExposuresStopped: @@ -385,23 +384,15 @@ break; case StarSelected: - emit newLog(i18n("PHD2: Star Selected.")); + handlePHD2AppState(SELECTED); break; case StarLost: - emit newLog(i18n("PHD2: Star Lost. Trying to reacquire.")); - if (state != LOSTLOCK) - { - state = LOSTLOCK; - abortTimer->start(Options::guideLostStarTimeout() * 1000); - qCDebug(KSTARS_EKOS_GUIDE) << "PHD2: Lost star timeout started (" << Options::guideLostStarTimeout() << " sec)"; - } + handlePHD2AppState(LOSTLOCK); break; case GuidingStopped: - state = STOPPED; - emit newLog(i18n("PHD2: Guiding Stopped.")); - emit newStatus(Ekos::GUIDE_ABORTED); + handlePHD2AppState(STOPPED); break; case Resumed: @@ -416,6 +407,11 @@ emit newLog(i18n("PHD2: Star found, guiding resumed.")); abortTimer->stop(); state = GUIDING; + } else if (state != GUIDING) + { + // It's unclear why we receive a guiding step although we are not in the guiding state. + // So let's reaquire the current state directly and let's not guess. + requestAppState(); } // JM 2018-08-05: GuideStep does not necessary mean we're guiding // It could be that we're settling. This needs to be double-checked. @@ -518,19 +514,61 @@ void PHD2::processPHD2State(const QString &phd2State) { if (phd2State == "Stopped") - state = STOPPED; + handlePHD2AppState(STOPPED); else if (phd2State == "Selected") - state = SELECTED; + handlePHD2AppState(SELECTED); else if (phd2State == "Calibrating") - state = CALIBRATING; + handlePHD2AppState(CALIBRATING); else if (phd2State == "Guiding") - state = GUIDING; + handlePHD2AppState(GUIDING); else if (phd2State == "LostLock") - state = LOSTLOCK; + handlePHD2AppState(LOSTLOCK); else if (phd2State == "Paused") - state = PAUSED; + handlePHD2AppState(PAUSED); else if (phd2State == "Looping") - state = LOOPING; + handlePHD2AppState(LOOPING); +} + +void PHD2::handlePHD2AppState(PHD2State newstate) +{ + // do not handle the same state twice + if (state == newstate) + return; + + switch (newstate) + { + case STOPPED: + emit newLog(i18n("PHD2: Guiding Stopped.")); + emit newStatus(Ekos::GUIDE_ABORTED); + break; + case SELECTED: + emit newLog(i18n("PHD2: Star Selected.")); + emit newStatus(GUIDE_STAR_SELECT); + break; + case GUIDING: + emit newLog(i18n("PHD2: Guiding.")); + emit newStatus(GUIDE_GUIDING); + break; + case LOSTLOCK: + emit newLog(i18n("PHD2: Star Lost. Trying to reacquire.")); + abortTimer->start(static_cast(Options::guideLostStarTimeout()) * 1000); + qCDebug(KSTARS_EKOS_GUIDE) << "PHD2: Lost star timeout started (" << Options::guideLostStarTimeout() << " sec)"; + // TODO: there is no matching EKOS guiding state + break; + case PAUSED: + emit newLog(i18n("PHD2: Paused.")); + emit newStatus(GUIDE_SUSPENDED); + break; + case CALIBRATING: + emit newLog(i18n("PHD2: Calibrating.")); + emit newStatus(GUIDE_CALIBRATING); + break; + case LOOPING: + //emit newLog(i18n("PHD2: Looping Exposures.")); + break; + } + + state = newstate; } void PHD2::processPHD2Result(const QJsonObject &jsonObj, const QByteArray &line) @@ -562,7 +600,11 @@ //flip_calibration //get_algo_param_names //get_algo_param - //get_app_state + + case APP_STATE_RECEIVED: //get_app_state + processPHD2State(jsonObj["State"].toString()); + break; + //get_calibrated //get_calibration_data @@ -955,7 +997,13 @@ //flip_calibration //get_algo_param_names //get_algo_param + //get_app_state +void PHD2::requestAppState() +{ + sendPHD2Request("get_app_state"); +} + //get_calibrated //get_calibration_data diff --git a/kstars/ekos/guide/guide.cpp b/kstars/ekos/guide/guide.cpp --- a/kstars/ekos/guide/guide.cpp +++ b/kstars/ekos/guide/guide.cpp @@ -2497,8 +2497,9 @@ { //If PHD2 starts guiding because somebody pusted the button remotely, we want to set the state to guiding. //If guide pulses start coming in, it must be guiding. - if(guiderType == GUIDE_PHD2 && state != GUIDE_GUIDING) - setStatus(GUIDE_GUIDING); + // 2020-04-10 sterne-jaeger: Will be resolved inside EKOS phd guiding. + // if(guiderType == GUIDE_PHD2 && state != GUIDE_GUIDING) + // setStatus(GUIDE_GUIDING); // Time since timer started. double key = guideTimer.elapsed() / 1000.0;