File indexing completed on 2024-04-21 14:45:01

0001 /*
0002     SPDX-FileCopyrightText: 2018 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     Cloud Channel
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <QtWebSockets/QWebSocket>
0012 #include <memory>
0013 
0014 #include "ekos/manager.h"
0015 #include "nodemanager.h"
0016 
0017 class FITSView;
0018 
0019 namespace EkosLive
0020 {
0021 class Cloud : public QObject
0022 {
0023         Q_OBJECT
0024 
0025     public:
0026         explicit Cloud(Ekos::Manager * manager, QVector<QSharedPointer<NodeManager>> &nodeManagers);
0027         virtual ~Cloud() = default;
0028 
0029         bool isConnected() const;
0030         void registerCameras();
0031 
0032         // Ekos Cloud Message to User
0033         void upload(const QString &filename, const QString &uuid);
0034         void upload(const QSharedPointer<FITSData> &data, const QString &uuid);
0035 
0036     signals:
0037         void connected();
0038         void disconnected();
0039         void newImage(const QByteArray &image);
0040 
0041     public slots:
0042         void updateOptions();
0043 
0044     private slots:
0045         // Connection
0046         void onConnected();
0047         void onDisconnected();        
0048 
0049         // Communication
0050         void onTextReceived(const QString &message);
0051 
0052         // Send image
0053         void sendImage();
0054 
0055         void uploadImage(const QByteArray &image);
0056 
0057     private:
0058         void asyncUpload();
0059 
0060         Ekos::Manager * m_Manager { nullptr };
0061         QVector<QSharedPointer<NodeManager>> m_NodeManagers;
0062         QString m_UUID;
0063 
0064         QSharedPointer<FITSData> m_ImageData;
0065         QFutureWatcher<bool> watcher;
0066 
0067         QString extension;
0068         QStringList temporaryFiles;
0069 
0070         bool m_sendBlobs {true};
0071 
0072         // Image width for high-bandwidth setting
0073         static const uint16_t HB_WIDTH = 640;
0074         // Image high bandwidth image quality (jpg)
0075         static const uint8_t HB_IMAGE_QUALITY = 76;
0076         // Video high bandwidth video quality (jpg)
0077         static const uint8_t HB_VIDEO_QUALITY = 64;
0078 
0079         // Binary Metadata Size
0080         static const uint16_t METADATA_PACKET = 2048;
0081 
0082         // Retry every 5 seconds in case remote server is down
0083         static const uint16_t RECONNECT_INTERVAL = 5000;
0084         // Retry for 1 hour before giving up
0085         static const uint16_t RECONNECT_MAX_TRIES = 720;
0086 };
0087 }