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; int retval = 0;
if ( !_deviceReady || _deviceInError) if ( !_deviceReady || _deviceInError)
{ {
std::cout << "LedDevice::updateLeds(), LedDevice NOT ready!" << std::endl; //std::cout << "LedDevice::updateLeds(), LedDevice NOT ready!" << std::endl;
return -1; return -1;
} }
else else

View File

@ -255,6 +255,12 @@ int LedDeviceNanoleaf::open()
_deviceReady = false; _deviceReady = false;
if ( init(_devConfig) ) if ( init(_devConfig) )
{
if ( !initNetwork() )
{
this->setInError( "UDP Network error!" );
}
else
{ {
if ( initLeds() ) if ( initLeds() )
{ {
@ -263,6 +269,7 @@ int LedDeviceNanoleaf::open()
retval = 0; retval = 0;
} }
} }
}
return retval; return retval;
} }

View File

@ -76,10 +76,21 @@ bool ProviderUdp::init(const QJsonObject &deviceConfig)
bool ProviderUdp::initNetwork() bool ProviderUdp::initNetwork()
{ {
bool isInitOK = true; bool isInitOK = false;
// TODO: Add Network-Error handling
_udpSocket =new QUdpSocket(this); _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;
}
return isInitOK; return isInitOK;
} }
@ -93,17 +104,10 @@ int ProviderUdp::open()
{ {
if ( ! initNetwork()) if ( ! initNetwork())
{ {
this->setInError( "Network error!" ); this->setInError( "UDP Network error!" );
} }
else 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 // Everything is OK -> enable device
_deviceReady = true; _deviceReady = true;
setEnable(true); setEnable(true);