Kstars

cloud.h
1 /*
2  SPDX-FileCopyrightText: 2018 Jasem Mutlaq <[email protected]>
3 
4  Cloud 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/manager.h"
16 
17 class FITSView;
18 
19 namespace EkosLive
20 {
21 class Cloud : public QObject
22 {
23  Q_OBJECT
24 
25  public:
26  explicit Cloud(Ekos::Manager * manager);
27  virtual ~Cloud() = 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  void registerCameras();
42 
43  // Ekos Cloud Message to User
44  void upload(const QString &filename, const QString &uuid);
45  void upload(const QSharedPointer<FITSData> &data, const QString &uuid);
46 
47  signals:
48  void connected();
49  void disconnected();
50 
51  void newMetadata(const QByteArray &metadata);
52  void newImage(const QByteArray &image);
53 
54  public slots:
55  void connectServer();
56  void disconnectServer();
57  void setOptions(QMap<int, bool> options);
58 
59  private slots:
60  // Connection
61  void onConnected();
62  void onDisconnected();
63  void onError(QAbstractSocket::SocketError error);
64 
65  // Communication
66  void onTextReceived(const QString &message);
67 
68  // Send image
69  void sendImage();
70 
71  // Metadata and Image upload
72  void uploadMetadata(const QByteArray &metadata);
73  void uploadImage(const QByteArray &image);
74 
75  private:
76  void asyncUpload();
77 
78  QWebSocket m_WebSocket;
79  QJsonObject m_AuthResponse;
80  uint16_t m_ReconnectTries {0};
81  Ekos::Manager * m_Manager { nullptr };
82  QUrl m_URL;
83  QString m_UUID;
84 
85  QSharedPointer<FITSData> m_ImageData;
86  QFutureWatcher<bool> watcher;
87 
88  QString extension;
89  QStringList temporaryFiles;
90 
91  bool m_isConnected {false};
92  bool m_sendBlobs {true};
93 
94  QMap<int, bool> m_Options;
95 
96  // Image width for high-bandwidth setting
97  static const uint16_t HB_WIDTH = 640;
98  // Image high bandwidth image quality (jpg)
99  static const uint8_t HB_IMAGE_QUALITY = 76;
100  // Video high bandwidth video quality (jpg)
101  static const uint8_t HB_VIDEO_QUALITY = 64;
102 
103  // Retry every 5 seconds in case remote server is down
104  static const uint16_t RECONNECT_INTERVAL = 5000;
105  // Retry for 1 hour before giving up
106  static const uint16_t RECONNECT_MAX_TRIES = 720;
107 };
108 }
Q_OBJECTQ_OBJECT
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 03:59:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.