File indexing completed on 2024-04-21 03:43:39

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <KLocalizedString>
0010 
0011 #include <QMetaType>
0012 #include <QDBusArgument>
0013 #include <QString>
0014 
0015 #include <vector>
0016 
0017 namespace Ekos
0018 {
0019 // Guide States
0020 static const QList<const char *> guideStates = { I18N_NOOP("Idle"),
0021                                                  I18N_NOOP("Aborted"),
0022                                                  I18N_NOOP("Connected"),
0023                                                  I18N_NOOP("Disconnected"),
0024                                                  I18N_NOOP("Capturing"),
0025                                                  I18N_NOOP("Looping"),
0026                                                  I18N_NOOP("Subtracting"),
0027                                                  I18N_NOOP("Subframing"),
0028                                                  I18N_NOOP("Selecting star"),
0029                                                  I18N_NOOP("Calibrating"),
0030                                                  I18N_NOOP("Calibration error"),
0031                                                  I18N_NOOP("Calibrated"),
0032                                                  I18N_NOOP("Guiding"),
0033                                                  I18N_NOOP("Suspended"),
0034                                                  I18N_NOOP("Reacquiring"),
0035                                                  I18N_NOOP("Dithering"),
0036                                                  I18N_NOOP("Manual Dithering"),
0037                                                  I18N_NOOP("Dithering error"),
0038                                                  I18N_NOOP("Dithering successful"),
0039                                                  I18N_NOOP("Settling")
0040                                                };
0041 
0042 typedef enum
0043 {
0044     GUIDE_IDLE,
0045     GUIDE_ABORTED,
0046     GUIDE_CONNECTED,
0047     GUIDE_DISCONNECTED,
0048     GUIDE_CAPTURE,
0049     GUIDE_LOOPING,
0050     GUIDE_DARK,
0051     GUIDE_SUBFRAME,
0052     GUIDE_STAR_SELECT,
0053     GUIDE_CALIBRATING,
0054     GUIDE_CALIBRATION_ERROR,
0055     GUIDE_CALIBRATION_SUCCESS,
0056     GUIDE_GUIDING,
0057     GUIDE_SUSPENDED,
0058     GUIDE_REACQUIRE,
0059     GUIDE_DITHERING,
0060     GUIDE_MANUAL_DITHERING,
0061     GUIDE_DITHERING_ERROR,
0062     GUIDE_DITHERING_SUCCESS,
0063     GUIDE_DITHERING_SETTLE
0064 } GuideState;
0065 
0066 const QString getGuideStatusString(GuideState state, bool translated = true);
0067 
0068 // Capture States
0069 static const QList<const char *> captureStates =
0070 {
0071     I18N_NOOP("Idle"), I18N_NOOP("In Progress"), I18N_NOOP("Capturing"), I18N_NOOP("Pause Planned"), I18N_NOOP("Paused"),
0072     I18N_NOOP("Suspended"), I18N_NOOP("Aborted"), I18N_NOOP("Waiting"), I18N_NOOP("Image Received"),
0073     I18N_NOOP("Dithering"), I18N_NOOP("Focusing"), I18N_NOOP("Filter Focus"), I18N_NOOP("Changing Filter"), I18N_NOOP("Guider Settling"),
0074     I18N_NOOP("Setting Temperature"), I18N_NOOP("Setting Rotator"), I18N_NOOP("Aligning"), I18N_NOOP("Calibrating"),
0075     I18N_NOOP("Meridian Flip"), I18N_NOOP("Complete")
0076 };
0077 
0078 /**
0079   * @brief Capture states
0080   *
0081   * They can be divided into several stages:
0082   * - No capturing is running (@see CAPTURE_IDLE, @see CAPTURE_COMPLETE or @see CAPTURE_ABORTED)
0083   * - A capture sequence job is in preparation (@see CAPTURE_PROGRESS as state and @see CAPTURE_SETTING_TEMPERATURE,
0084   *   @see CAPTURE_SETTING_ROTATOR and @see CAPTURE_CHANGING_FILTER as state events signaled to
0085   *   @see Capture::updatePrepareState(Ekos::CaptureState))
0086   * - Calibration activities to initialize the execution of a sequence job (@see CAPTURE_DITHERING, @see CAPTURE_FOCUSING,
0087   *   @see CAPTURE_ALIGNING and @see CAPTURE_CALIBRATING)
0088   * - Waiting for start of capturing (@see CAPTURE_PAUSE_PLANNED, @see CAPTURE_PAUSED, @see CAPTURE_SUSPENDED and @see CAPTURE_WAITING)
0089   * - Capturing (@see CAPTURE_CAPTURING and @see CAPTURE_IMAGE_RECEIVED)
0090   */
0091 typedef enum
0092 {
0093     CAPTURE_IDLE,                /*!< no capture job active */
0094     CAPTURE_PROGRESS,            /*!< capture job sequence in preparation (temperature, filter, rotator) */
0095     CAPTURE_CAPTURING,           /*!< CCD capture running */
0096     CAPTURE_PAUSE_PLANNED,       /*!< user has requested to pause the capture sequence */
0097     CAPTURE_PAUSED,              /*!< paused capture sequence due to a user request */
0098     CAPTURE_SUSPENDED,           /*!< capture stopped since some limits are not met, but may be continued if all limits are met again */
0099     CAPTURE_ABORTED,             /*!< capture stopped by the user or aborted due to guiding problems etc. */
0100     CAPTURE_WAITING,             /*!< waiting for settling of the mount before start of capturing */
0101     CAPTURE_IMAGE_RECEIVED,      /*!< image received from the CDD device */
0102     CAPTURE_DITHERING,           /*!< dithering before starting to capture */
0103     CAPTURE_FOCUSING,            /*!< focusing before starting to capture */
0104     CAPTURE_FILTER_FOCUS,        /*!< not used */
0105     CAPTURE_CHANGING_FILTER,     /*!< preparation event changing the filter */
0106     CAPTURE_GUIDER_DRIFT,        /*!< preparation event waiting for the guider to settle */
0107     CAPTURE_SETTING_TEMPERATURE, /*!< preparation event setting the camera temperature */
0108     CAPTURE_SETTING_ROTATOR,     /*!< preparation event setting the camera rotator */
0109     CAPTURE_ALIGNING,            /*!< aligning before starting to capture */
0110     CAPTURE_CALIBRATING,         /*!< startup of guiding running before starting to capture */
0111     CAPTURE_MERIDIAN_FLIP,       /*!< only used as signal that a meridian flip is ongoing */
0112     CAPTURE_COMPLETE             /*!< capture job sequence completed successfully */
0113 } CaptureState;
0114 
0115 const QString getCaptureStatusString(CaptureState state, bool translated = true);
0116 
0117 // Focus States
0118 static const QList<const char *> focusStates = { I18N_NOOP("Idle"),    I18N_NOOP("Complete"),       I18N_NOOP("Failed"),
0119                                                  I18N_NOOP("Aborted"), I18N_NOOP("User Input"),     I18N_NOOP("In Progress"),
0120                                                  I18N_NOOP("Framing"), I18N_NOOP("Changing Filter")
0121                                                };
0122 
0123 typedef enum
0124 {
0125     FOCUS_IDLE,
0126     FOCUS_COMPLETE,
0127     FOCUS_FAILED,
0128     FOCUS_ABORTED,
0129     FOCUS_WAITING,
0130     FOCUS_PROGRESS,
0131     FOCUS_FRAMING,
0132     FOCUS_CHANGING_FILTER
0133 } FocusState;
0134 
0135 const QString getFocusStatusString(FocusState state, bool translated = true);
0136 
0137 // Align States
0138 static const QList<const char *> alignStates = { I18N_NOOP("Idle"),    I18N_NOOP("Complete"),  I18N_NOOP("Failed"),
0139                                                  I18N_NOOP("Aborted"), I18N_NOOP("In Progress"), I18N_NOOP("Successful"),
0140                                                  I18N_NOOP("Syncing"), I18N_NOOP("Slewing"), I18N_NOOP("Rotating"),
0141                                                  I18N_NOOP("Suspended")
0142                                                };
0143 
0144 typedef enum
0145 {
0146     ALIGN_IDLE,                 /**< No ongoing operations */
0147     ALIGN_COMPLETE,             /**< Alignment successfully completed. No operations pending. */
0148     ALIGN_FAILED,               /**< Alignment failed. No operations pending. */
0149     ALIGN_ABORTED,              /**< Alignment aborted by user or agent. */
0150     ALIGN_PROGRESS,             /**< Alignment operation in progress. This include capture and sovling. */
0151     ALIGN_SUCCESSFUL,           /**< Alignment Astrometry solver successfully solved the image. */
0152     ALIGN_SYNCING,              /**< Syncing mount to solution coordinates. */
0153     ALIGN_SLEWING,              /**< Slewing mount to target coordinates.  */
0154     ALIGN_ROTATING,             /**< Rotating (Automatic or Manual) to target position angle. */
0155     ALIGN_SUSPENDED             /**< Alignment operations suspended. */
0156 } AlignState;
0157 
0158 const QString getAlignStatusString(AlignState state, bool translated = true);
0159 
0160 // Filter Manager States
0161 static const QList<const char *> filterStates = { I18N_NOOP("Idle"), I18N_NOOP("Changing Filter"), I18N_NOOP("Focus Offset"),
0162                                                   I18N_NOOP("Auto Focus")
0163                                                 };
0164 typedef enum
0165 {
0166     FILTER_IDLE,
0167     FILTER_CHANGE,
0168     FILTER_OFFSET,
0169     FILTER_AUTOFOCUS
0170 } FilterState;
0171 
0172 typedef enum
0173 {
0174     SCRIPT_PRE_JOB,     /**< Script to run before a sequence job is started */
0175     SCRIPT_PRE_CAPTURE, /**< Script to run before a sequence capture is started */
0176     SCRIPT_POST_CAPTURE,/**< Script to run after a sequence capture is completed */
0177     SCRIPT_POST_JOB,    /**< Script to run after a sequence job is completed */
0178     SCRIPT_N
0179 } ScriptTypes;
0180 
0181 const QString getFilterStatusString(FilterState state, bool translated = true);
0182 
0183 // Scheduler states
0184 
0185 typedef enum
0186 {
0187     SCHEDULER_IDLE,     /*< Scheduler is stopped. */
0188     SCHEDULER_STARTUP,  /*< Scheduler is starting the observatory up. */
0189     SCHEDULER_RUNNING,  /*< Scheduler is running. */
0190     SCHEDULER_PAUSED,   /*< Scheduler is paused by the end-user. */
0191     SCHEDULER_SHUTDOWN, /*< Scheduler is shutting the observatory down. */
0192     SCHEDULER_ABORTED,  /*< Scheduler is stopped in error. */
0193     SCHEDULER_LOADING   /*< Scheduler is loading a schedule. */
0194 } SchedulerState;
0195 
0196 const QString getSchedulerStatusString(SchedulerState state, bool translated = true);
0197 
0198 static const QList<const char *> schedulerStates = { I18N_NOOP("Idle"), I18N_NOOP("Startup"), I18N_NOOP("Running"),
0199                                                      I18N_NOOP("Paused"), I18N_NOOP("Shutdown"), I18N_NOOP("Aborted"),
0200                                                      I18N_NOOP("Loading")
0201                                                    };
0202 typedef enum
0203 {
0204     Idle,
0205     Pending,
0206     Success,
0207     Error
0208 } CommunicationStatus;
0209 
0210 std::vector<double> gsl_polynomial_fit(const double *const data_x, const double *const data_y, const int n,
0211                                        const int order, double &chisq);
0212 
0213 // Invalid value
0214 const int INVALID_VALUE = -1e6;
0215 // Invalid star HFR, FWHM result
0216 static double constexpr INVALID_STAR_MEASURE = -1.0;
0217 
0218 }
0219 
0220 // Communication Status
0221 Q_DECLARE_METATYPE(Ekos::CommunicationStatus)
0222 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CommunicationStatus &source);
0223 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CommunicationStatus &dest);
0224 
0225 // Capture Status
0226 // FIXME is there a way to avoid unnecessary duplicating code? The solution suggested in KDE WiKi is to use Boost
0227 // which we do not have to add as dependency
0228 Q_DECLARE_METATYPE(Ekos::CaptureState)
0229 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CaptureState &source);
0230 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CaptureState &dest);
0231 
0232 // Focus
0233 Q_DECLARE_METATYPE(Ekos::FocusState)
0234 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::FocusState &source);
0235 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::FocusState &dest);
0236 
0237 // Guide
0238 Q_DECLARE_METATYPE(Ekos::GuideState)
0239 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::GuideState &source);
0240 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::GuideState &dest);
0241 
0242 // Align
0243 Q_DECLARE_METATYPE(Ekos::AlignState)
0244 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::AlignState &source);
0245 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::AlignState &dest);
0246 
0247 // Scheduler
0248 Q_DECLARE_METATYPE(Ekos::SchedulerState)
0249 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::SchedulerState &source);
0250 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::SchedulerState &dest);