2014-11-21 21:24:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Qt includes
|
2017-03-04 22:17:42 +01:00
|
|
|
#include <QString>
|
2014-11-21 21:24:33 +01:00
|
|
|
#include <QColor>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QTcpSocket>
|
2016-02-25 15:21:25 +01:00
|
|
|
#include <QTimer>
|
2014-11-21 21:24:33 +01:00
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
// hyperion util
|
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
2016-06-07 23:12:18 +02:00
|
|
|
#include <utils/VideoMode.h>
|
2016-07-11 17:08:22 +02:00
|
|
|
#include <utils/Logger.h>
|
2014-11-21 21:24:33 +01:00
|
|
|
|
|
|
|
#include <message.pb.h>
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Connection class to setup an connection to the hyperion server and execute commands
|
|
|
|
///
|
2016-02-25 15:21:25 +01:00
|
|
|
class ProtoConnection : public QObject
|
2014-11-21 21:24:33 +01:00
|
|
|
{
|
2016-02-25 15:21:25 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
Q_OBJECT
|
2016-02-25 15:21:25 +01:00
|
|
|
|
2014-11-21 21:24:33 +01:00
|
|
|
public:
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444)
|
|
|
|
///
|
2017-03-04 22:17:42 +01:00
|
|
|
ProtoConnection(const QString & address);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor
|
|
|
|
///
|
|
|
|
~ProtoConnection();
|
|
|
|
|
|
|
|
/// Do not read reply messages from Hyperion if set to true
|
|
|
|
void setSkipReply(bool skip);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Set all leds to the specified color
|
|
|
|
///
|
|
|
|
/// @param color The color
|
|
|
|
/// @param priority The priority
|
|
|
|
/// @param duration The duration in milliseconds
|
|
|
|
///
|
|
|
|
void setColor(const ColorRgb & color, int priority, int duration = 1);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Set the leds according to the given image (assume the image is stretched to the display size)
|
|
|
|
///
|
|
|
|
/// @param image The image
|
|
|
|
/// @param priority The priority
|
|
|
|
/// @param duration The duration in milliseconds
|
|
|
|
///
|
|
|
|
void setImage(const Image<ColorRgb> & image, int priority, int duration = -1);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Clear the given priority channel
|
|
|
|
///
|
|
|
|
/// @param priority The priority
|
|
|
|
///
|
|
|
|
void clear(int priority);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Clear all priority channels
|
|
|
|
///
|
|
|
|
void clearAll();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Send a command message and receive its reply
|
|
|
|
///
|
|
|
|
/// @param message The message to send
|
|
|
|
///
|
|
|
|
void sendMessage(const proto::HyperionRequest & message);
|
2014-11-21 21:24:33 +01:00
|
|
|
|
2016-02-25 15:21:25 +01:00
|
|
|
private slots:
|
2016-05-26 23:44:27 +02:00
|
|
|
/// Try to connect to the Hyperion host
|
|
|
|
void connectToHost();
|
2016-02-08 16:56:23 +01:00
|
|
|
|
2016-06-07 23:12:18 +02:00
|
|
|
///
|
|
|
|
/// Slot called when new data has arrived
|
|
|
|
///
|
|
|
|
void readData();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
///
|
2017-11-22 00:52:55 +01:00
|
|
|
/// emits when a new videoMode was requested from proto client
|
2016-06-07 23:12:18 +02:00
|
|
|
///
|
|
|
|
void setVideoMode(const VideoMode videoMode);
|
2016-02-25 15:21:25 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
|
|
|
/// Parse a reply message
|
|
|
|
///
|
|
|
|
/// @param reply The received reply
|
|
|
|
///
|
|
|
|
/// @return true if the reply indicates success
|
|
|
|
///
|
|
|
|
bool parseReply(const proto::HyperionReply & reply);
|
2014-11-21 21:24:33 +01:00
|
|
|
|
|
|
|
private:
|
2016-05-26 23:44:27 +02:00
|
|
|
/// The TCP-Socket with the connection to the server
|
|
|
|
QTcpSocket _socket;
|
2014-11-21 21:24:33 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
/// Host address
|
|
|
|
QString _host;
|
2014-11-21 21:24:33 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
/// Host port
|
|
|
|
uint16_t _port;
|
2014-11-21 21:24:33 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
/// Skip receiving reply messages from Hyperion if set
|
|
|
|
bool _skipReply;
|
2016-02-25 15:21:25 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
QTimer _timer;
|
|
|
|
QAbstractSocket::SocketState _prevSocketState;
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2016-06-07 23:12:18 +02:00
|
|
|
/// The buffer used for reading data from the socket
|
|
|
|
QByteArray _receiveBuffer;
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2016-07-11 17:08:22 +02:00
|
|
|
Logger * _log;
|
2014-11-21 21:24:33 +01:00
|
|
|
};
|