2020-07-12 20:27:56 +02:00
|
|
|
#ifndef PROVIDERUDP_H
|
|
|
|
#define PROVIDERUDP_H
|
2016-05-30 23:58:31 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// LedDevice includes
|
2016-05-30 23:58:31 +02:00
|
|
|
#include <leddevice/LedDevice.h>
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
// Hyperion includes
|
2016-06-24 17:46:23 +02:00
|
|
|
#include <utils/Logger.h>
|
2016-05-30 23:58:31 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// Qt includes
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <QHostAddress>
|
2020-07-12 20:27:56 +02:00
|
|
|
#include <QUdpSocket>
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2016-10-08 13:52:22 +02:00
|
|
|
/// The ProviderUdp implements an abstract base-class for LedDevices using UDP packets.
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
class ProviderUdp : public LedDevice
|
2016-05-30 23:58:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2016-09-22 00:18:46 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs an UDP LED-device
|
2016-09-22 00:18:46 +02:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
ProviderUdp(const QJsonObject& deviceConfig);
|
2016-05-30 23:58:31 +02:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the UDP LED-device
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~ProviderUdp() override;
|
2016-05-30 23:58:31 +02:00
|
|
|
|
2020-11-01 21:56:19 +01:00
|
|
|
QHostAddress getAddress() const { return _address; }
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
protected:
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Initialise the UDP device's configuration and network address details
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
bool init(const QJsonObject& deviceConfig) override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Opens the output device.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success (i.e. device is ready), else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int open() override;
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Closes the UDP device.
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int close() override;
|
2016-05-30 23:58:31 +02:00
|
|
|
|
|
|
|
///
|
2020-11-01 21:56:19 +01:00
|
|
|
/// @brief Writes the given bytes to the UDP-device
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2016-08-14 10:46:44 +02:00
|
|
|
/// @param[in] size The length of the data
|
2016-05-30 23:58:31 +02:00
|
|
|
/// @param[in] data The data
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success, else negative
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
int writeBytes(const unsigned size, const uint8_t* data);
|
2016-05-30 23:58:31 +02:00
|
|
|
|
2020-11-01 21:56:19 +01:00
|
|
|
///
|
|
|
|
/// @brief Writes the given bytes to the UDP-device
|
|
|
|
///
|
|
|
|
/// @param[in] data The data
|
|
|
|
///
|
|
|
|
/// @return Zero on success, else negative
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
int writeBytes(const QByteArray& bytes);
|
2020-11-01 21:56:19 +01:00
|
|
|
|
2016-05-30 23:58:31 +02:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
QUdpSocket* _udpSocket;
|
2016-05-30 23:58:31 +02:00
|
|
|
QHostAddress _address;
|
2020-08-09 17:43:23 +02:00
|
|
|
quint16 _port;
|
2017-02-11 22:52:47 +01:00
|
|
|
QString _defaultHost;
|
2016-05-30 23:58:31 +02:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // PROVIDERUDP_H
|