1 /*
2     SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <KLocalizedString>
10 
11 #include <QMetaType>
12 #include <QDBusArgument>
13 #include <QStringList>
14 #include <QString>
15 
16 #include <vector>
17 
18 namespace Ekos
19 {
20 // Guide States
21 static const QStringList guideStates = { I18N_NOOP("Idle"),
22                                          I18N_NOOP("Aborted"),
23                                          I18N_NOOP("Connected"),
24                                          I18N_NOOP("Disconnected"),
25                                          I18N_NOOP("Capturing"),
26                                          I18N_NOOP("Looping"),
27                                          I18N_NOOP("Subtracting"),
28                                          I18N_NOOP("Subframing"),
29                                          I18N_NOOP("Selecting star"),
30                                          I18N_NOOP("Calibrating"),
31                                          I18N_NOOP("Calibration error"),
32                                          I18N_NOOP("Calibrated"),
33                                          I18N_NOOP("Guiding"),
34                                          I18N_NOOP("Suspended"),
35                                          I18N_NOOP("Reacquiring"),
36                                          I18N_NOOP("Dithering"),
37                                          I18N_NOOP("Manual Dithering"),
38                                          I18N_NOOP("Dithering error"),
39                                          I18N_NOOP("Dithering successful"),
40                                          I18N_NOOP("Settling")
41                                        };
42 
43 typedef enum
44 {
45     GUIDE_IDLE,
46     GUIDE_ABORTED,
47     GUIDE_CONNECTED,
48     GUIDE_DISCONNECTED,
49     GUIDE_CAPTURE,
50     GUIDE_LOOPING,
51     GUIDE_DARK,
52     GUIDE_SUBFRAME,
53     GUIDE_STAR_SELECT,
54     GUIDE_CALIBRATING,
55     GUIDE_CALIBRATION_ERROR,
56     GUIDE_CALIBRATION_SUCESS,
57     GUIDE_GUIDING,
58     GUIDE_SUSPENDED,
59     GUIDE_REACQUIRE,
60     GUIDE_DITHERING,
61     GUIDE_MANUAL_DITHERING,
62     GUIDE_DITHERING_ERROR,
63     GUIDE_DITHERING_SUCCESS,
64     GUIDE_DITHERING_SETTLE
65 } GuideState;
66 
67 const QString &getGuideStatusString(GuideState state);
68 
69 // Capture States
70 static const QStringList captureStates =
71 {
72     I18N_NOOP("Idle"), I18N_NOOP("In Progress"), I18N_NOOP("Capturing"), I18N_NOOP("Pause Planned"), I18N_NOOP("Paused"),
73     I18N_NOOP("Suspended"), I18N_NOOP("Aborted"), I18N_NOOP("Waiting"), I18N_NOOP("Image Received"),
74     I18N_NOOP("Dithering"), I18N_NOOP("Focusing"), I18N_NOOP("Filter Focus"), I18N_NOOP("Changing Filter"), I18N_NOOP("Guider Settling"),
75     I18N_NOOP("Setting Temperature"), I18N_NOOP("Setting Rotator"), I18N_NOOP("Aligning"), I18N_NOOP("Calibrating"),
76     I18N_NOOP("Meridian Flip"), I18N_NOOP("Complete")
77 };
78 
79 /**
80   * @brief Capture states
81   *
82   * They can be divided into several stages:
83   * - No capturing is running (@see CAPTURE_IDLE, @see CAPTURE_COMPLETE or @see CAPTURE_ABORTED)
84   * - A capture sequence job is in preparation (@see CAPTURE_PROGRESS as state and @see CAPTURE_SETTING_TEMPERATURE,
85   *   @see CAPTURE_SETTING_ROTATOR and @see CAPTURE_CHANGING_FILTER as state events signaled to
86   *   @see Capture::updatePrepareState(Ekos::CaptureState))
87   * - Calibration activities to initialize the execution of a sequence job (@see CAPTURE_DITHERING, @see CAPTURE_FOCUSING,
88   *   @see CAPTURE_ALIGNING and @see CAPTURE_CALIBRATING)
89   * - Waiting for start of capturing (@see CAPTURE_PAUSE_PLANNED, @see CAPTURE_PAUSED, @see CAPTURE_SUSPENDED and @see CAPTURE_WAITING)
90   * - Capturing (@see CAPTURE_CAPTURING and @see CAPTURE_IMAGE_RECEIVED)
91   */
92 typedef enum
93 {
94     CAPTURE_IDLE,                /*!< no capture job active */
95     CAPTURE_PROGRESS,            /*!< capture job sequence in preparation (temperature, filter, rotator) */
96     CAPTURE_CAPTURING,           /*!< CCD capture running */
97     CAPTURE_PAUSE_PLANNED,       /*!< user has requested to pause the capture sequence */
98     CAPTURE_PAUSED,              /*!< paused capture sequence due to a user request */
99     CAPTURE_SUSPENDED,           /*!< capture stopped since some limits are not met, but may be continued if all limits are met again */
100     CAPTURE_ABORTED,             /*!< capture stopped by the user or aborted due to guiding problems etc. */
101     CAPTURE_WAITING,             /*!< waiting for settling of the mount before start of capturing */
102     CAPTURE_IMAGE_RECEIVED,      /*!< image received from the CDD device */
103     CAPTURE_DITHERING,           /*!< dithering before starting to capture */
104     CAPTURE_FOCUSING,            /*!< focusing before starting to capture */
105     CAPTURE_FILTER_FOCUS,        /*!< not used */
106     CAPTURE_CHANGING_FILTER,     /*!< preparation event changing the filter */
107     CAPTURE_GUIDER_DRIFT,        /*!< preparation event waiting for the guider to settle */
108     CAPTURE_SETTING_TEMPERATURE, /*!< preparation event setting the camera temperature */
109     CAPTURE_SETTING_ROTATOR,     /*!< preparation event setting the camera rotator */
110     CAPTURE_ALIGNING,            /*!< aligning before starting to capture */
111     CAPTURE_CALIBRATING,         /*!< startup of guiding running before starting to capture */
112     CAPTURE_MERIDIAN_FLIP,       /*!< only used as signal that a meridian flip is ongoing */
113     CAPTURE_COMPLETE             /*!< capture job sequence completed successfully */
114 } CaptureState;
115 
116 const QString &getCaptureStatusString(CaptureState state);
117 
118 // Focus States
119 static const QStringList focusStates = { I18N_NOOP("Idle"),    I18N_NOOP("Complete"),       I18N_NOOP("Failed"),
120                                          I18N_NOOP("Aborted"), I18N_NOOP("User Input"),     I18N_NOOP("In Progress"),
121                                          I18N_NOOP("Framing"), I18N_NOOP("Changing Filter")
122                                        };
123 
124 typedef enum
125 {
126     FOCUS_IDLE,
127     FOCUS_COMPLETE,
128     FOCUS_FAILED,
129     FOCUS_ABORTED,
130     FOCUS_WAITING,
131     FOCUS_PROGRESS,
132     FOCUS_FRAMING,
133     FOCUS_CHANGING_FILTER
134 } FocusState;
135 
136 const QString &getFocusStatusString(FocusState state);
137 
138 // Align States
139 static const QStringList alignStates = { I18N_NOOP("Idle"),    I18N_NOOP("Complete"),  I18N_NOOP("Failed"),
140                                          I18N_NOOP("Aborted"), I18N_NOOP("In Progress"), I18N_NOOP("Syncing"),
141                                          I18N_NOOP("Slewing"), I18N_NOOP("Suspended")
142                                        };
143 
144 typedef enum
145 {
146     ALIGN_IDLE,
147     ALIGN_COMPLETE,
148     ALIGN_FAILED,
149     ALIGN_ABORTED,
150     ALIGN_PROGRESS,
151     ALIGN_SYNCING,
152     ALIGN_SLEWING,
153     ALIGN_SUSPENDED
154 } AlignState;
155 
156 const QString &getAlignStatusString(AlignState state);
157 
158 // Filter Manager States
159 static const QStringList filterStates = { I18N_NOOP("Idle"), I18N_NOOP("Changing Filter"), I18N_NOOP("Focus Offset"),
160                                           I18N_NOOP("Auto Focus")
161                                         };
162 typedef enum
163 {
164     FILTER_IDLE,
165     FILTER_CHANGE,
166     FILTER_OFFSET,
167     FILTER_AUTOFOCUS
168 } FilterState;
169 
170 typedef enum
171 {
172     SCRIPT_PRE_JOB,     /**< Script to run before a sequence job is started */
173     SCRIPT_PRE_CAPTURE, /**< Script to run before a sequence capture is started */
174     SCRIPT_POST_CAPTURE,/**< Script to run after a sequence capture is completed */
175     SCRIPT_POST_JOB,    /**< Script to run after a sequence job is completed */
176     SCRIPT_N
177 } ScriptTypes;
178 
179 const QString &getFilterStatusString(FilterState state);
180 
181 // Scheduler states
182 
183 const QString &getSchedulerStatusString(AlignState state);
184 
185 static const QStringList schedulerStates = { I18N_NOOP("Idle"), I18N_NOOP("Startup"), I18N_NOOP("Running"),
186                                              I18N_NOOP("Paused"), I18N_NOOP("Shutdown"), I18N_NOOP("Aborted")
187                                            };
188 
189 typedef enum
190 {
191     SCHEDULER_IDLE,     /*< Scheduler is stopped. */
192     SCHEDULER_STARTUP,  /*< Scheduler is starting the observatory up. */
193     SCHEDULER_RUNNING,  /*< Scheduler is running. */
194     SCHEDULER_PAUSED,   /*< Scheduler is paused by the end-user. */
195     SCHEDULER_SHUTDOWN, /*< Scheduler is shutting the observatory down. */
196     SCHEDULER_ABORTED,  /*< Scheduler is stopped in error. */
197     SCHEDULER_LOADING   /*< Scheduler is loading a schedule. */
198 } SchedulerState;
199 
200 typedef enum
201 {
202     Idle,
203     Pending,
204     Success,
205     Error
206 } CommunicationStatus;
207 
208 std::vector<double> gsl_polynomial_fit(const double *const data_x, const double *const data_y, const int n,
209                                        const int order, double &chisq);
210 
211 // Invalid value
212 const int INVALID_VALUE = -1e6;
213 }
214 
215 // Communication Status
216 Q_DECLARE_METATYPE(Ekos::CommunicationStatus)
217 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CommunicationStatus &source);
218 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CommunicationStatus &dest);
219 
220 // Capture Status
221 // FIXME is there a way to avoid unnecessary duplicating code? The solution suggested in KDE WiKi is to use Boost
222 // which we do not have to add as dependency
223 Q_DECLARE_METATYPE(Ekos::CaptureState)
224 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::CaptureState &source);
225 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::CaptureState &dest);
226 
227 // Focus
228 Q_DECLARE_METATYPE(Ekos::FocusState)
229 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::FocusState &source);
230 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::FocusState &dest);
231 
232 // Guide
233 Q_DECLARE_METATYPE(Ekos::GuideState)
234 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::GuideState &source);
235 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::GuideState &dest);
236 
237 // Align
238 Q_DECLARE_METATYPE(Ekos::AlignState)
239 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::AlignState &source);
240 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::AlignState &dest);
241 
242 // Scheduler
243 Q_DECLARE_METATYPE(Ekos::SchedulerState)
244 QDBusArgument &operator<<(QDBusArgument &argument, const Ekos::SchedulerState &source);
245 const QDBusArgument &operator>>(const QDBusArgument &argument, Ekos::SchedulerState &dest);
246