Kstars

message.h
1 /*
2  SPDX-FileCopyrightText: 2018 Jasem Mutlaq <[email protected]>
3 
4  Message Channel
5 
6  SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include <QtWebSockets/QWebSocket>
12 #include <memory>
13 
14 #include "ekos/ekos.h"
15 #include "ekos/align/polaralignmentassistant.h"
16 #include "ekos/manager.h"
17 #include "catalogsdb.h"
18 
19 namespace EkosLive
20 {
21 class Message : public QObject
22 {
23  Q_OBJECT
24 
25  public:
26  explicit Message(Ekos::Manager *manager);
27  virtual ~Message() = default;
28 
29  void sendResponse(const QString &command, const QJsonObject &payload);
30  void sendResponse(const QString &command, const QJsonArray &payload);
31 
32  void setAuthResponse(const QJsonObject &response)
33  {
34  m_AuthResponse = response;
35  }
36  void setURL(const QUrl &url)
37  {
38  m_URL = url;
39  }
40 
41  // Module Status Updates
42  void updateMountStatus(const QJsonObject &status, bool throttle = false);
43  void updateCaptureStatus(const QJsonObject &status);
44  void updateFocusStatus(const QJsonObject &status);
45  void updateGuideStatus(const QJsonObject &status);
46  void updateDomeStatus(const QJsonObject &status);
47  void updateCapStatus(const QJsonObject &status);
48 
49  // Send devices as they come
50  void sendEvent(const QString &message, KSNotification::EventType event);
51  void sendCameras();
52  void sendMounts();
53  void sendScopes();
54  void sendFilterWheels();
55  void sendDomes();
56  void sendCaps();
57  void sendDrivers();
58  void sendDevices();
59  void sendSchedulerJobList(QJsonArray jobsList);
60 
61  // Scheduler
62  void sendSchedulerJobs();
63 
64  signals:
65  void connected();
66  void disconnected();
67  void expired();
68  void optionsChanged(QMap<int, bool> options);
69  // This is forward signal from INDI::CCD
70  //void previewJPEGGenerated(const QString &previewJPEG, QJsonObject metadata);
71 
72  void resetPolarView();
73 
74  public slots:
75  void connectServer();
76  void disconnectServer();
77 
78  // Connection
79  void sendConnection();
80  void sendModuleState(const QString &name);
81 
82  // Ekos
83  void setEkosStatingStatus(Ekos::CommunicationStatus status);
84 
85  // Alignment
86  void setAlignStatus(Ekos::AlignState newState);
87  void setAlignSolution(const QVariantMap &solution);
88  void sendAlignSettings(const QJsonObject &settings);
89 
90  // Guide
91  void sendGuideSettings(const QJsonObject &settings);
92 
93  // Focus
94  void sendFocusSettings(const QJsonObject &settings);
95 
96  //Scheduler
97  void sendSchedulerSettings(const QJsonObject &settings);
98 
99  // Polar
100  void setPAHStage(Ekos::PolarAlignmentAssistant::PAHStage stage);
101  void setPAHMessage(const QString &message);
102  void setPolarResults(QLineF correctionVector, double polarError, double azError, double altError);
103  void setUpdatedErrors(double total, double az, double alt);
104  void setPAHEnabled(bool enabled);
105  void setBoundingRect(QRect rect, QSize view, double currentZoom);
106  // Capture
107  void sendCaptureSequence(const QJsonArray &sequenceArray);
108  void sendCaptureSettings(const QJsonObject &settings);
109 
110  // DSLR
111  void requestDSLRInfo(const QString &cameraName);
112 
113  // Port Selection
114  void requestPortSelection(bool show);
115 
116  // Dialogs
117  void sendDialog(const QJsonObject &message);
118  void processDialogResponse(const QJsonObject &payload);
119 
120  // Process properties
121  void processNewNumber(INumberVectorProperty *nvp);
122  void processNewText(ITextVectorProperty *tvp);
123  void processNewSwitch(ISwitchVectorProperty *svp);
124  void processNewLight(ILightVectorProperty *lvp);
125  void processNewProperty(INDI::Property prop);
126  void processDeleteProperty(const QString &device, const QString &name);
127 
128  // StellarSolver
129  void sendStellarSolverProfiles();
130 
131  void sendManualRotatorStatus(double currentPA, double targetPA, double threshold);
132 
133  private slots:
134 
135  // Connection
136  void onConnected();
137  void onDisconnected();
138  void onError(QAbstractSocket::SocketError error);
139 
140  // Communication
141  void onTextReceived(const QString &);
142 
143  private:
144  // Profiles
145  void sendProfiles();
146  void setProfileMapping(const QJsonObject &payload);
147  void sendStates();
148 
149  // Capture
150  void processCaptureCommands(const QString &command, const QJsonObject &payload);
151  void setCapturePresetSettings(const QJsonObject &settings);
152  void sendTemperature(double value);
153 
154  // Mount
155  void processMountCommands(const QString &command, const QJsonObject &payload);
156 
157  // Focus
158  void processFocusCommands(const QString &command, const QJsonObject &payload);
159 
160  // Guide
161  void processGuideCommands(const QString &command, const QJsonObject &payload);
162 
163  // Align
164  void processAlignCommands(const QString &command, const QJsonObject &payload);
165 
166  // Scheduler
167  void processSchedulerCommands(const QString &command, const QJsonObject &payload);
168 
169  // Polar
170  void processPolarCommands(const QString &command, const QJsonObject &payload);
171 
172  // Profile
173  void processProfileCommands(const QString &command, const QJsonObject &payload);
174 
175  // Options
176  void processOptionsCommands(const QString &command, const QJsonObject &payload);
177 
178  // Scopes
179  void processScopeCommands(const QString &command, const QJsonObject &payload);
180 
181  // DSLRs
182  void processDSLRCommands(const QString &command, const QJsonObject &payload);
183 
184  // Filter Manager commands
185  void processFilterManagerCommands(const QString &command, const QJsonObject &payload);
186 
187  // Dark Library commands
188  void processDarkLibraryCommands(const QString &command, const QJsonObject &payload);
189 
190  // Low-level Device commands
191  void processDeviceCommands(const QString &command, const QJsonObject &payload);
192 
193  // Process Astronomy Library command
194  void processAstronomyCommands(const QString &command, const QJsonObject &payload);
195  KStarsDateTime getNextDawn();
196 
197  QWebSocket m_WebSocket;
198  QJsonObject m_AuthResponse;
199  uint16_t m_ReconnectTries {0};
200  Ekos::Manager *m_Manager { nullptr };
201  QUrl m_URL;
202 
203  bool m_isConnected { false };
204  bool m_sendBlobs { true};
205 
206  QMap<int, bool> m_Options;
207  QMap<QString, QSet<QString>> m_PropertySubscriptions;
208  QLineF correctionVector;
209  QRect m_BoundingRect;
210  QSize m_ViewSize;
211  double m_CurrentZoom {100};
212 
213  QDateTime m_ThrottleTS;
214  CatalogsDB::DBManager m_DSOManager;
215  QCache<QString, QJsonObject> m_PropertyCache;
216 
217  typedef enum
218  {
219  North,
220  East,
221  South,
222  West,
223  All
224  } Direction;
225 
226  // Retry every 5 seconds in case remote server is down
227  static const uint16_t RECONNECT_INTERVAL = 5000;
228  // Retry for 1 hour before giving up
229  static const uint16_t RECONNECT_MAX_TRIES = 720;
230  // Throttle interval
231  static const uint16_t THROTTLE_INTERVAL = 1000;
232 };
233 }
Q_OBJECTQ_OBJECT
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
Direction
Manages the catalog database and provides an interface to provide an interface to query and modify th...
Definition: catalogsdb.h:181
Generic record interfaces and implementations.
Definition: cloud.cpp:23
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.