mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
add ability for default values in providerudp (#251)
* add ability for default values in providerudp * udp: move switchOff into baseclass * udp: more code cleanups
This commit is contained in:
@@ -15,11 +15,11 @@
|
||||
// Local Hyperion includes
|
||||
#include "ProviderUdp.h"
|
||||
|
||||
ProviderUdp::ProviderUdp(const Json::Value &deviceConfig)
|
||||
ProviderUdp::ProviderUdp()
|
||||
: LedDevice()
|
||||
, _LatchTime_ns(-1)
|
||||
, _port(0)
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
_udpSocket = new QUdpSocket();
|
||||
}
|
||||
|
||||
@@ -28,16 +28,18 @@ ProviderUdp::~ProviderUdp()
|
||||
_udpSocket->close();
|
||||
}
|
||||
|
||||
bool ProviderUdp::setConfig(const Json::Value &deviceConfig)
|
||||
bool ProviderUdp::setConfig(const Json::Value &deviceConfig, int defaultLatchTime, int defaultPort, std::string defaultHost)
|
||||
{
|
||||
if (_address.setAddress( QString::fromStdString(deviceConfig["host"].asString()) ) )
|
||||
QString host = QString::fromStdString(deviceConfig.get("host",defaultHost).asString());
|
||||
|
||||
if (_address.setAddress(host) )
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["host"].asString()) );
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if (info.addresses().isEmpty())
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
@@ -46,9 +48,17 @@ bool ProviderUdp::setConfig(const Json::Value &deviceConfig)
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
_address = info.addresses().first();
|
||||
}
|
||||
_port = deviceConfig["port"].asUInt();
|
||||
|
||||
_port = deviceConfig.get("port", defaultPort).asUInt();
|
||||
if ( _port<=0 || _port > 65535)
|
||||
{
|
||||
throw std::runtime_error("invalid target port");
|
||||
}
|
||||
|
||||
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||
|
||||
_LatchTime_ns = deviceConfig.get("latchtime", defaultLatchTime).asInt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -84,3 +94,9 @@ int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int ProviderUdp::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user