2016-05-30 23:58:31 +02:00
|
|
|
#include "LedDeviceUdpRaw.h"
|
|
|
|
|
2021-09-20 09:36:59 +02:00
|
|
|
// Constants
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const bool verbose = false;
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
const ushort RAW_DEFAULT_PORT=5568;
|
2021-09-20 09:36:59 +02:00
|
|
|
const int UDP_MAX_LED_NUM = 490;
|
|
|
|
|
|
|
|
} //End of constants
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceUdpRaw::LedDeviceUdpRaw(const QJsonObject &deviceConfig)
|
2020-08-08 00:21:19 +02:00
|
|
|
: ProviderUdp(deviceConfig)
|
2016-05-30 23:58:31 +02:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceUdpRaw::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceUdpRaw(deviceConfig);
|
2016-05-30 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
bool LedDeviceUdpRaw::init(const QJsonObject &deviceConfig)
|
|
|
|
{
|
|
|
|
_port = RAW_DEFAULT_PORT;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2021-09-20 09:36:59 +02:00
|
|
|
bool isInitOK = false;
|
|
|
|
if ( LedDevice::init(deviceConfig) )
|
|
|
|
{
|
|
|
|
// Initialise LedDevice configuration and execution environment
|
|
|
|
int configuredLedCount = this->getLedCount();
|
|
|
|
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
|
|
|
Debug(_log, "LedCount : %d", configuredLedCount);
|
|
|
|
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
|
|
|
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
|
|
|
|
|
|
|
if (configuredLedCount > UDP_MAX_LED_NUM)
|
|
|
|
{
|
|
|
|
QString errorReason = QString("Device type %1 can only be run with maximum %2 LEDs!").arg(this->getActiveDeviceType()).arg(UDP_MAX_LED_NUM);
|
|
|
|
this->setInError ( errorReason );
|
|
|
|
isInitOK = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialise sub-class
|
|
|
|
isInitOK = ProviderUdp::init(deviceConfig);
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
return isInitOK;
|
|
|
|
}
|
|
|
|
|
2016-05-30 23:58:31 +02:00
|
|
|
int LedDeviceUdpRaw::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
|
|
|
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
return writeBytes(_ledRGBCount, dataPtr);
|
2016-05-30 23:58:31 +02:00
|
|
|
}
|
2021-09-20 09:36:59 +02:00
|
|
|
|
|
|
|
QJsonObject LedDeviceUdpRaw::getProperties(const QJsonObject& params)
|
|
|
|
{
|
|
|
|
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
|
|
|
QJsonObject properties;
|
|
|
|
|
|
|
|
QJsonObject propertiesDetails;
|
|
|
|
propertiesDetails.insert("maxLedCount", UDP_MAX_LED_NUM);
|
|
|
|
|
|
|
|
properties.insert("properties", propertiesDetails);
|
|
|
|
|
|
|
|
DebugIf(verbose, _log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|