fix: Nanoleaf - Udp Network init was missing (#698)

* Fix Nanoleaf - Udp Network init was missing

* ProviderUdp - Add init error handling
This commit is contained in:
LordGrey 2020-02-23 23:18:34 +01:00 committed by GitHub
parent a2dbbcdd0d
commit f955af29fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 16 deletions

View File

@ -166,7 +166,7 @@ int LedDevice::updateLeds(const std::vector<ColorRgb>& ledValues)
int retval = 0;
if ( !_deviceReady || _deviceInError)
{
std::cout << "LedDevice::updateLeds(), LedDevice NOT ready!" << std::endl;
//std::cout << "LedDevice::updateLeds(), LedDevice NOT ready!" << std::endl;
return -1;
}
else

View File

@ -256,11 +256,18 @@ int LedDeviceNanoleaf::open()
if ( init(_devConfig) )
{
if ( initLeds() )
if ( !initNetwork() )
{
_deviceReady = true;
setEnable(true);
retval = 0;
this->setInError( "UDP Network error!" );
}
else
{
if ( initLeds() )
{
_deviceReady = true;
setEnable(true);
retval = 0;
}
}
}
return retval;

View File

@ -76,10 +76,21 @@ bool ProviderUdp::init(const QJsonObject &deviceConfig)
bool ProviderUdp::initNetwork()
{
bool isInitOK = true;
bool isInitOK = false;
_udpSocket =new QUdpSocket(this);
if ( _udpSocket != nullptr)
{
QHostAddress localAddress = QHostAddress::Any;
quint16 localPort = 0;
if ( !_udpSocket->bind(localAddress, localPort) )
{
Warning ( _log, "Could not bind local address: %s", strerror(errno));
}
isInitOK = true;
}
// TODO: Add Network-Error handling
_udpSocket = new QUdpSocket(this);
return isInitOK;
}
@ -93,17 +104,10 @@ int ProviderUdp::open()
{
if ( ! initNetwork())
{
this->setInError( "Network error!" );
this->setInError( "UDP Network error!" );
}
else
{
QHostAddress localAddress = QHostAddress::Any;
quint16 localPort = 0;
if ( !_udpSocket->bind(localAddress, localPort) )
{
Warning ( _log, "Could not bind local address: %s", strerror(errno));
}
// Everything is OK -> enable device
_deviceReady = true;
setEnable(true);