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
|
|
|
///
|
|
|
|
ProviderUdp();
|
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-02-10 15:21:58 +01:00
|
|
|
virtual ~ProviderUdp() override;
|
2016-05-30 23:58:31 +02:00
|
|
|
|
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-02-10 15:21:58 +01:00
|
|
|
virtual bool init(const QJsonObject &deviceConfig) override;
|
|
|
|
|
|
|
|
///
|
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-07-12 20:27:56 +02:00
|
|
|
virtual 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-07-12 20:27:56 +02:00
|
|
|
virtual int close() override;
|
2016-05-30 23:58:31 +02:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Writes the given bytes/bits to the UDP-device and sleeps the latch time to ensure that the
|
2016-05-30 23:58:31 +02:00
|
|
|
/// values are latched.
|
|
|
|
///
|
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
|
|
|
///
|
|
|
|
int writeBytes(const unsigned size, const uint8_t *data);
|
|
|
|
|
|
|
|
///
|
2016-08-14 10:46:44 +02:00
|
|
|
QUdpSocket * _udpSocket;
|
2016-05-30 23:58:31 +02:00
|
|
|
QHostAddress _address;
|
2019-07-12 16:54:26 +02:00
|
|
|
ushort _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
|