2018-12-28 17:55:49 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QString>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
// hyperion util
|
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
|
|
|
#include <utils/VideoMode.h>
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
2020-07-21 19:35:25 +02:00
|
|
|
#include <flatbuffers/flatbuffers.h>
|
|
|
|
|
|
|
|
namespace hyperionnet
|
|
|
|
{
|
|
|
|
class Reply;
|
|
|
|
}
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
2018-12-28 18:12:45 +01:00
|
|
|
/// Connection class to setup an connection to the hyperion server and execute commands.
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
|
|
|
class FlatBufferConnection : public QObject
|
|
|
|
{
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Constructor
|
2018-12-28 17:55:49 +01:00
|
|
|
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444)
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @param skipReply If true skip reply
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
FlatBufferConnection(const QString& origin, const QString & address, const int& priority, const bool& skipReply);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Destructor
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
|
|
|
~FlatBufferConnection();
|
|
|
|
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Do not read reply messages from Hyperion if set to true
|
2018-12-28 18:12:45 +01:00
|
|
|
void setSkipReply(const bool& skip);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Register a new priority with given origin
|
|
|
|
/// @param origin The user friendly origin string
|
|
|
|
/// @param priority The priority to register
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
void setRegister(const QString& origin, int priority);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Set all leds to the specified color
|
|
|
|
/// @param color The color
|
2018-12-28 17:55:49 +01:00
|
|
|
/// @param priority The priority
|
|
|
|
/// @param duration The duration in milliseconds
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
void setColor(const ColorRgb & color, int priority, int duration = 1);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Clear the given priority channel
|
2018-12-28 17:55:49 +01:00
|
|
|
/// @param priority The priority
|
|
|
|
///
|
|
|
|
void clear(int priority);
|
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Clear all priority channels
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
|
|
|
void clearAll();
|
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Send a command message and receive its reply
|
2018-12-28 17:55:49 +01:00
|
|
|
/// @param message The message to send
|
|
|
|
///
|
|
|
|
void sendMessage(const uint8_t* buffer, uint32_t size);
|
|
|
|
|
2018-12-30 22:07:53 +01:00
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// @brief Set the leds according to the given image
|
|
|
|
/// @param image The image
|
|
|
|
///
|
|
|
|
void setImage(const Image<ColorRgb> &image);
|
|
|
|
|
2018-12-28 17:55:49 +01:00
|
|
|
private slots:
|
2018-12-30 22:07:53 +01:00
|
|
|
///
|
|
|
|
/// @brief Try to connect to the Hyperion host
|
|
|
|
///
|
2018-12-28 17:55:49 +01:00
|
|
|
void connectToHost();
|
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Slot called when new data has arrived
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
|
|
|
void readData();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief emits when a new videoMode was requested from flatbuf client
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
|
|
|
void setVideoMode(const VideoMode videoMode);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @brief Parse a reply message
|
2018-12-28 17:55:49 +01:00
|
|
|
/// @param reply The received reply
|
|
|
|
/// @return true if the reply indicates success
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
bool parseReply(const hyperionnet::Reply *reply);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// The TCP-Socket with the connection to the server
|
|
|
|
QTcpSocket _socket;
|
|
|
|
|
2018-12-30 22:07:53 +01:00
|
|
|
QString _origin;
|
|
|
|
int _priority;
|
|
|
|
|
2018-12-28 17:55:49 +01:00
|
|
|
/// Host address
|
|
|
|
QString _host;
|
|
|
|
|
|
|
|
/// Host port
|
|
|
|
uint16_t _port;
|
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
/// buffer for reply
|
|
|
|
QByteArray _receiveBuffer;
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
QTimer _timer;
|
|
|
|
QAbstractSocket::SocketState _prevSocketState;
|
|
|
|
|
|
|
|
Logger * _log;
|
|
|
|
flatbuffers::FlatBufferBuilder _builder;
|
2018-12-30 22:07:53 +01:00
|
|
|
|
|
|
|
bool _registered;
|
2018-12-28 17:55:49 +01:00
|
|
|
};
|