Kstars

phd2.h
1/*
2 SPDX-FileCopyrightText: 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "../guideinterface.h"
10
11#include <QAbstractSocket>
12#include <QJsonArray>
13#include <QJsonObject>
14#include <QPointer>
15#include <QTimer>
16
17class FITSView;
18class QTcpSocket;
19
20namespace Ekos
21{
22/**
23 * @class PHD2
24 * Uses external PHD2 for guiding.
25 *
26 * @author Jasem Mutlaq
27 * @version 1.1
28 */
29class PHD2 : public GuideInterface
30{
32
33 public:
34 enum PHD2Event
35 {
36 Version,
37 LockPositionSet,
38 Calibrating,
39 CalibrationComplete,
40 StarSelected,
41 StartGuiding,
42 Paused,
43 StartCalibration,
44 AppState,
45 CalibrationFailed,
46 CalibrationDataFlipped,
47 LoopingExposures,
48 LoopingExposuresStopped,
49 SettleBegin,
50 Settling,
51 SettleDone,
52 StarLost,
53 GuidingStopped,
54 Resumed,
55 GuideStep,
56 GuidingDithered,
57 LockPositionLost,
58 Alert,
59 GuideParamChange,
60 ConfigurationChange
61
62 };
63 enum PHD2State
64 {
65 // these are the states exposed by phd2
66 STOPPED,
67 SELECTED,
68 CALIBRATING,
69 GUIDING,
70 LOSTLOCK,
71 PAUSED,
72 LOOPING,
73 DITHERING,
74 };
75 enum PHD2Connection
76 {
77 DISCONNECTED,
78 CONNECTED,
79 EQUIPMENT_DISCONNECTED,
80 EQUIPMENT_CONNECTED,
81 CONNECTING,
82 DISCONNECTING,
83 };
84 enum PHD2MessageType
85 {
86 PHD2_UNKNOWN,
87 PHD2_RESULT,
88 PHD2_EVENT,
89 PHD2_ERROR,
90 };
91
92 // These are the PHD2 Results and the commands they are associated with
93 enum PHD2ResultType
94 {
95 NO_RESULT,
96 CAPTURE_SINGLE_FRAME, //capture_single_frame
97 CLEAR_CALIBRATION_COMMAND_RECEIVED, //clear_calibration
98 DITHER_COMMAND_RECEIVED, //dither
99 //find_star
100 //flip_calibration
101 //get_algo_param_names
102 //get_algo_param
103 APP_STATE_RECEIVED, //get_app_state
104 //get_calibrated
105 //get_calibration_data
106 IS_EQUIPMENT_CONNECTED, //get_connected
107 //get_cooler_status
108 GET_CURRENT_EQUIPMENT, //get_current_equipment
109 DEC_GUIDE_MODE, //get_dec_guide_mode
110 EXPOSURE_TIME, //get_exposure
111 EXPOSURE_DURATIONS, //get_exposure_durations
112 LOCK_POSITION, //get_lock_position
113 //get_lock_shift_enabled
114 //get_lock_shift_params
115 //get_paused
116 PIXEL_SCALE, //get_pixel_scale
117 //get_profile
118 //get_profiles
119 //get_search_region
120 //get_sensor_temperature
121 STAR_IMAGE, //get_star_image
122 //get_use_subframes
123 GUIDE_COMMAND_RECEIVED, //guide
124 //guide_pulse
125 LOOP, //loop
126 //save_image
127 //set_algo_param
128 CONNECTION_RESULT, //set_connected
129 SET_DEC_GUIDE_MODE_COMMAND_RECEIVED, //set_dec_guide_mode
130 SET_EXPOSURE_COMMAND_RECEIVED, //set_exposure
131 SET_LOCK_POSITION, //set_lock_position
132 //set_lock_shift_enabled
133 //set_lock_shift_params
134 SET_PAUSED_COMMAND_RECEIVED, //set_paused
135 //set_profile
136 //shutdown
137 STOP_CAPTURE_COMMAND_RECEIVED //stop_capture
138 };
139
140 PHD2();
141 ~PHD2();
142
143 //These are the connection methods to connect the external guide program PHD2
144 bool Connect() override;
145 bool Disconnect() override;
146 bool isConnected() override
147 {
148 return (connection == CONNECTED || connection == EQUIPMENT_CONNECTED);
149 }
150
151 //These are the PHD2 Methods. Only some are implemented in Ekos.
152
153 void captureSingleFrame(); //capture_single_frame
154 bool clearCalibration() override; //clear_calibration
155 bool dither(double pixels) override; //dither
156 //find_star
157 //flip_calibration
158 //get_algo_param_names
159 //get_algo_param
160 void requestAppState(); //get_app_state
161 //get_calibrated
162 //get_calibration_data
163 void checkIfEquipmentConnected(); //get_connected
164 //get_cooler_status
165 void requestCurrentEquipmentUpdate(); //get_current_equipment
166 void checkDEGuideMode(); //get_dec_guide_mode
167 void requestExposureTime(); //get_exposure
168 void requestExposureDurations(); //get_exposure_durations
169 void requestLockPosition(); //get_lock_position
170 //get_lock_shift_enabled
171 //get_lock_shift_params
172 //get_paused
173 void requestPixelScale(); //get_pixel_scale
174 //get_profile
175 //get_profiles
176 //get_search_region
177 //get_sensor_temperature
178 void requestStarImage(int size); //get_star_image
179 //get_use_subframes
180 bool guide() override; //guide
181 //guide_pulse
182 void loop(); //loop
183 //save_image
184 //set_algo_param
185 void connectEquipment(bool enable);//set_connected
186 void requestSetDEGuideMode(bool deEnabled, bool nEnabled, bool sEnabled); //set_dec_guide_mode
187 void requestSetExposureTime(int time); //set_exposure
188 void setLockPosition(double x, double y); //set_lock_position
189 //set_lock_shift_enabled
190 //set_lock_shift_params
191 bool suspend() override; //set_paused
192 bool resume() override; //set_paused
193 //set_profile
194 //shutdown
195 bool abort() override; //stop_capture
196
197 bool calibrate() override; //Note PHD2 does not have a separate calibrate command. This is unused.
198 void setGuideView(const QSharedPointer<FITSView> &guideView);
199
200 QString getCurrentCamera()
201 {
202 return currentCamera;
203 }
204 QString getCurrentMount()
205 {
206 return currentMount;
207 }
208 QString getCurrentAuxMount()
209 {
210 return currentAuxMount;
211 }
212
213 bool isCurrentCameraNotInEkos()
214 {
215 return currentCameraIsNotInEkos;
216 }
217 void setCurrentCameraIsNotInEkos(bool enable)
218 {
219 currentCameraIsNotInEkos = enable;
220 }
221
222 private slots:
223
224 void readPHD2();
225 void displayError(QAbstractSocket::SocketError socketError);
226
227 private:
228 QSharedPointer<FITSView> m_GuideFrame;
229
230 QVector<QPointF> errorLog;
231
232 void sendPHD2Request(const QString &method, const QJsonArray &args = QJsonArray());
233 void sendRpcCall(QJsonObject &call, PHD2ResultType resultType);
234 void sendNextRpcCall();
235
236 void processPHD2Event(const QJsonObject &jsonEvent, const QByteArray &rawResult);
237 void processPHD2Result(const QJsonObject &jsonObj, const QByteArray &rawResult);
238 void processStarImage(const QJsonObject &jsonStarFrame);
239 void processPHD2State(const QString &phd2State);
240 void handlePHD2AppState(PHD2State state);
241 void processPHD2Error(const QJsonObject &jsonError, const QByteArray &rawResult);
242
243 PHD2ResultType takeRequestFromList(const QJsonObject &response);
244
245 QPointer<QTcpSocket> tcpSocket;
246 int nextRpcId { 1 };
247
248 QHash<QString, PHD2Event> events; // maps event name to event type
249 QHash<QString, PHD2ResultType> methodResults; // maps method name to result type
250
251 int pendingRpcId; // ID of outstanding RPC call
252 PHD2ResultType pendingRpcResultType { NO_RESULT }; // result type of outstanding RPC call
253 bool starImageRequested { false }; // true when there is an outstanding star image request
254
255 struct RpcCall
256 {
257 QJsonObject call;
258 PHD2ResultType resultType;
259 RpcCall() = default;
260 RpcCall(const QJsonObject &call_, PHD2ResultType resultType_) : call(call_), resultType(resultType_) { }
261 };
262 QVector<RpcCall> rpcRequestQueue;
263
264 PHD2State state { STOPPED };
265 bool isDitherActive { false };
266 bool isSettling { false };
267 PHD2Connection connection { DISCONNECTED };
268 PHD2Event event { Alert };
269 uint8_t setConnectedRetries { 0 };
270
271 void setEquipmentConnected();
272 void updateGuideParameters();
273 void ResetConnectionState();
274
275 QTimer *abortTimer;
276 QTimer *ditherTimer;
277 QTimer *stateTimer;
278
279 double pixelScale = 0;
280
281 QString logValidExposureTimes;
282
283 QString currentCamera;
284 QString currentMount;
285 QString currentAuxMount;
286 bool currentCameraIsNotInEkos;
287
288 uint8_t m_PHD2ReconnectCounter {0};
289
290 // Wait this many milliseconds before trying to reconnect again to PHD2
291 static const uint32_t PHD2_RECONNECT_TIMEOUT {3000};
292 // Try to connect this many times before giving up.
293 static const uint8_t PHD2_RECONNECT_THRESHOLD {10};
294
295};
296
297}
Interface skeleton for implementation of different guiding applications and/or routines.
Uses external PHD2 for guiding.
Definition phd2.h:30
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.