mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Various Cleanups (#1075)
* LedDevice - Address clang findings * Fix Windows Warnings * Ensure newInput is initialised * Clean-up unused elements for Plaform Capture * Fix initialization problem and spellings * Address clang findings and spelling corrections * LedDevice clean-ups * Cleanups * Align that getLedCount is int * Have "display" as default for Grabbers * Fix config during start-up for missing elements * Framegrabber Clean-up - Remove non supported grabbers from selection, filter valid options * Typo * Framegrabber.json - Fix property numbering * Preselect active Grabbertype * Sort Grabbernames * Align options with selected element * Fix deletion of pointer to incomplete type 'BonjourBrowserWrapper' * Address macOS compile warnings * Have default layout = 1 LED only to avoid errors as in #673 * Address lgtm findings * Address finding that params passed to LedDevice discovery were not considered * Cleanups after merging with latest master * Update Changelog * Address lgtm findings * Fix comment * Test Fix * Fix Python Warning * Handle Dummy Device assignment correctly * Address delete called on non-final 'commandline::Option' that has virtual functions but non-virtual destructor * Correct that QTimer.start accepts only int * Have Release Python GIL & reset threat state chnage downward compatible * Correct format specifier * LedDevice - add assertions * Readonly DB - Fix merge issue * Smoothing - Fix wrong defaults * LedDevice - correct assertion * Show smoothing config set# in debug and related values. * Suppress error on windows, if default file is "/dev/null" * CMAKE - Allow to define QT_BASE_DIR dynamically via environment-variable * Ignore Visual Studio specific files Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -55,7 +55,7 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
QStringList orbIds = QStringUtils::split(deviceConfig["orbIds"].toString().simplified().remove(" "),",", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
|
||||
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
||||
Debug(_log, "LedCount : %u", this->getLedCount());
|
||||
Debug(_log, "LedCount : %d", this->getLedCount());
|
||||
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
||||
Debug(_log, "RefreshTime : %d", _refreshTimerInterval_ms);
|
||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||
@@ -89,8 +89,8 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
}
|
||||
}
|
||||
|
||||
uint numberOrbs = _orbIds.size();
|
||||
uint configuredLedCount = this->getLedCount();
|
||||
int numberOrbs = _orbIds.size();
|
||||
int configuredLedCount = this->getLedCount();
|
||||
|
||||
if ( _orbIds.empty() )
|
||||
{
|
||||
@@ -111,7 +111,7 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
if ( numberOrbs > configuredLedCount )
|
||||
{
|
||||
Info(_log, "%s: More Orbs [%u] than configured LEDs [%u].", QSTRING_CSTR(this->getActiveDeviceType()), numberOrbs, configuredLedCount );
|
||||
Info(_log, "%s: More Orbs [%d] than configured LEDs [%d].", QSTRING_CSTR(this->getActiveDeviceType()), numberOrbs, configuredLedCount );
|
||||
}
|
||||
|
||||
isInitOK = true;
|
||||
@@ -276,16 +276,21 @@ void LedDeviceAtmoOrb::sendCommand(const QByteArray &bytes)
|
||||
_udpSocket->writeDatagram(bytes.data(), bytes.size(), _groupAddress, _multiCastGroupPort);
|
||||
}
|
||||
|
||||
QJsonObject LedDeviceAtmoOrb::discover()
|
||||
QJsonObject LedDeviceAtmoOrb::discover(const QJsonObject& params)
|
||||
{
|
||||
//Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
QJsonObject devicesDiscovered;
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
||||
|
||||
QJsonArray deviceList;
|
||||
|
||||
_multicastGroup = params["multiCastGroup"].toString(MULTICAST_GROUP_DEFAULT_ADDRESS);
|
||||
_multiCastGroupPort = static_cast<quint16>(params["multiCastPort"].toInt(MULTICAST_GROUP_DEFAULT_PORT));
|
||||
|
||||
if ( open() == 0 )
|
||||
{
|
||||
Debug ( _log, "Send discovery requests to all AtmoOrbs" );
|
||||
Debug ( _log, "Send discovery requests to all AtmoOrbs listening to %s:%d", QSTRING_CSTR(_multicastGroup),_multiCastGroupPort );
|
||||
setColor(0, ColorRgb::BLACK, 8);
|
||||
|
||||
if ( _udpSocket->waitForReadyRead(DEFAULT_DISCOVERY_TIMEOUT.count()) )
|
||||
|
@@ -43,9 +43,11 @@ public:
|
||||
///
|
||||
/// @brief Discover AtmoOrb devices available (for configuration).
|
||||
///
|
||||
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
||||
///
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
virtual QJsonObject discover() override;
|
||||
QJsonObject discover(const QJsonObject& params) override;
|
||||
|
||||
///
|
||||
/// @brief Send an update to the AtmoOrb device to identify it.
|
||||
|
@@ -38,67 +38,6 @@ const char COLOLIGHT_MODEL_IDENTIFIER[] = "OD_WE_QUAN";
|
||||
const int COLOLIGHT_BEADS_PER_MODULE = 19;
|
||||
const int COLOLIGHT_MIN_STRIP_SEGMENT_SIZE = 30;
|
||||
|
||||
enum verbs {
|
||||
GET = 0x03,
|
||||
SET = 0x04,
|
||||
SETEEPROM = 0x07,
|
||||
SETVAR = 0x0b
|
||||
};
|
||||
|
||||
enum commandTypes {
|
||||
STATE_OFF = 0x80,
|
||||
STATE_ON = 0x81,
|
||||
BRIGTHNESS = 0xCF,
|
||||
SETCOLOR = 0xFF
|
||||
};
|
||||
|
||||
enum idxTypes {
|
||||
BRIGTHNESS_CONTROL = 0x01,
|
||||
COLOR_CONTROL = 0x02,
|
||||
COLOR_DIRECT_CONTROL = 0x81,
|
||||
READ_INFO_FROM_STORAGE = 0x86
|
||||
};
|
||||
|
||||
enum bufferMode {
|
||||
MONOCROME = 0x01,
|
||||
LIGHTBEAD = 0x02,
|
||||
};
|
||||
|
||||
enum ledLayout {
|
||||
STRIP_LAYOUT,
|
||||
MODLUE_LAYOUT
|
||||
};
|
||||
|
||||
enum modelType {
|
||||
STRIP,
|
||||
PLUS
|
||||
};
|
||||
|
||||
const uint8_t PACKET_HEADER[] =
|
||||
{
|
||||
'S', 'Z', // Tag "SZ"
|
||||
0x30, 0x30, // Version "00"
|
||||
0x00, 0x00, // AppID, 0x0000 = TL1 command mode
|
||||
0x00, 0x00, 0x00, 0x00 // Size
|
||||
};
|
||||
|
||||
const uint8_t PACKET_SECU[] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, // Dict
|
||||
0x00, 0x00, 0x00, 0x00, // Sum
|
||||
0x00, 0x00, 0x00, 0x00, // Salt
|
||||
0x00, 0x00, 0x00, 0x00 // SN
|
||||
};
|
||||
|
||||
const uint8_t TL1_CMD_FIXED_PART[] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, // DISTID
|
||||
0x00, 0x00, 0x00, 0x00, // SRCID
|
||||
0x00, // SECU
|
||||
0x00, // VERB
|
||||
0x00, // CTAG
|
||||
0x00 // LENGTH
|
||||
};
|
||||
} //End of constants
|
||||
|
||||
LedDeviceCololight::LedDeviceCololight(const QJsonObject& deviceConfig)
|
||||
@@ -174,7 +113,7 @@ bool LedDeviceCololight::initLedsConfiguration()
|
||||
|
||||
if (getLedCount() == 0)
|
||||
{
|
||||
setLedCount(static_cast<uint>(_devConfig[CONFIG_HW_LED_COUNT].toInt(0)));
|
||||
setLedCount(_devConfig[CONFIG_HW_LED_COUNT].toInt(0));
|
||||
}
|
||||
|
||||
if (_modelType == STRIP && (getLedCount() % COLOLIGHT_MIN_STRIP_SEGMENT_SIZE != 0))
|
||||
@@ -187,7 +126,7 @@ bool LedDeviceCololight::initLedsConfiguration()
|
||||
{
|
||||
Debug(_log, "LedCount : %d", getLedCount());
|
||||
|
||||
uint configuredLedCount = static_cast<uint>(_devConfig["currentLedCount"].toInt(1));
|
||||
int configuredLedCount = _devConfig["currentLedCount"].toInt(1);
|
||||
|
||||
if (getLedCount() < configuredLedCount)
|
||||
{
|
||||
@@ -200,7 +139,7 @@ bool LedDeviceCololight::initLedsConfiguration()
|
||||
{
|
||||
if (getLedCount() > configuredLedCount)
|
||||
{
|
||||
Info(_log, "%s: More LEDs [%u] than configured LEDs in layout [%u].", QSTRING_CSTR(this->getActiveDeviceType()), getLedCount(), configuredLedCount);
|
||||
Info(_log, "%s: More LEDs [%d] than configured LEDs in layout [%d].", QSTRING_CSTR(this->getActiveDeviceType()), getLedCount(), configuredLedCount);
|
||||
}
|
||||
isInitOK = true;
|
||||
}
|
||||
@@ -269,7 +208,7 @@ bool LedDeviceCololight::getInfo()
|
||||
{
|
||||
_modelType = MODLUE_LAYOUT;
|
||||
_distance = ledNum / COLOLIGHT_BEADS_PER_MODULE;
|
||||
setLedCount(static_cast<uint>(_distance));
|
||||
setLedCount(_distance);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -455,7 +394,7 @@ bool LedDeviceCololight::sendRequest(const appID appID, const QByteArray& comman
|
||||
packet.append(static_cast<char>(_sequenceNumber));
|
||||
packet.append(command);
|
||||
|
||||
quint32 size = sizeof(PACKET_SECU) + 1 + command.size();
|
||||
quint32 size = static_cast<quint32>(static_cast<int>(sizeof(PACKET_SECU)) + 1 + command.size());
|
||||
|
||||
qToBigEndian<quint16>(appID, packet.data() + 4);
|
||||
|
||||
@@ -606,7 +545,7 @@ bool LedDeviceCololight::powerOff()
|
||||
return off;
|
||||
}
|
||||
|
||||
QJsonObject LedDeviceCololight::discover()
|
||||
QJsonObject LedDeviceCololight::discover(const QJsonObject& /*params*/)
|
||||
{
|
||||
QJsonObject devicesDiscovered;
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType);
|
||||
|
@@ -29,6 +29,68 @@ enum effect : uint32_t {
|
||||
CHRISTMAS = 0x068b0900
|
||||
};
|
||||
|
||||
enum verbs {
|
||||
GET = 0x03,
|
||||
SET = 0x04,
|
||||
SETEEPROM = 0x07,
|
||||
SETVAR = 0x0b
|
||||
};
|
||||
|
||||
enum commandTypes {
|
||||
STATE_OFF = 0x80,
|
||||
STATE_ON = 0x81,
|
||||
BRIGTHNESS = 0xCF,
|
||||
SETCOLOR = 0xFF
|
||||
};
|
||||
|
||||
enum idxTypes {
|
||||
BRIGTHNESS_CONTROL = 0x01,
|
||||
COLOR_CONTROL = 0x02,
|
||||
COLOR_DIRECT_CONTROL = 0x81,
|
||||
READ_INFO_FROM_STORAGE = 0x86
|
||||
};
|
||||
|
||||
enum bufferMode {
|
||||
MONOCROME = 0x01,
|
||||
LIGHTBEAD = 0x02,
|
||||
};
|
||||
|
||||
enum ledLayout {
|
||||
STRIP_LAYOUT,
|
||||
MODLUE_LAYOUT
|
||||
};
|
||||
|
||||
enum modelType {
|
||||
STRIP,
|
||||
PLUS
|
||||
};
|
||||
|
||||
const uint8_t PACKET_HEADER[] =
|
||||
{
|
||||
'S', 'Z', // Tag "SZ"
|
||||
0x30, 0x30, // Version "00"
|
||||
0x00, 0x00, // AppID, 0x0000 = TL1 command mode
|
||||
0x00, 0x00, 0x00, 0x00 // Size
|
||||
};
|
||||
|
||||
const uint8_t PACKET_SECU[] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, // Dict
|
||||
0x00, 0x00, 0x00, 0x00, // Sum
|
||||
0x00, 0x00, 0x00, 0x00, // Salt
|
||||
0x00, 0x00, 0x00, 0x00 // SN
|
||||
};
|
||||
|
||||
const uint8_t TL1_CMD_FIXED_PART[] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, // DISTID
|
||||
0x00, 0x00, 0x00, 0x00, // SRCID
|
||||
0x00, // SECU
|
||||
0x00, // VERB
|
||||
0x00, // CTAG
|
||||
0x00 // LENGTH
|
||||
};
|
||||
|
||||
///
|
||||
/// Implementation of a Cololight LedDevice
|
||||
///
|
||||
@@ -54,9 +116,11 @@ public:
|
||||
///
|
||||
/// @brief Discover Cololight devices available (for configuration).
|
||||
///
|
||||
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
||||
///
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
QJsonObject discover() override;
|
||||
QJsonObject discover(const QJsonObject& params) override;
|
||||
|
||||
///
|
||||
/// @brief Get a Cololight device's resource properties
|
||||
|
@@ -1,5 +1,9 @@
|
||||
#include "LedDeviceFadeCandy.h"
|
||||
|
||||
#include <QtEndian>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#ssize-t
|
||||
#if defined(_MSC_VER)
|
||||
#include <BaseTsd.h>
|
||||
@@ -8,22 +12,22 @@ typedef SSIZE_T ssize_t;
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
constexpr std::chrono::milliseconds CONNECT_TIMEOUT{1000};
|
||||
|
||||
const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 LEDs - in theory, fadecandy device should handle 10000 LEDs
|
||||
const unsigned OPC_SET_PIXELS = 0; // OPC command codes
|
||||
const unsigned OPC_SYS_EX = 255; // OPC command codes
|
||||
const unsigned OPC_HEADER_SIZE = 4; // OPC header size
|
||||
|
||||
const int MAX_NUM_LEDS = 10000; // OPC can handle 21845 LEDs - in theory, fadecandy device should handle 10000 LEDs
|
||||
const int OPC_SET_PIXELS = 0; // OPC command codes
|
||||
const int OPC_SYS_EX = 255; // OPC command codes
|
||||
const int OPC_HEADER_SIZE = 4; // OPC header size
|
||||
} //End of constants
|
||||
|
||||
// TCP elements
|
||||
const quint16 STREAM_DEFAULT_PORT = 7890;
|
||||
const int STREAM_DEFAULT_PORT = 7890;
|
||||
|
||||
LedDeviceFadeCandy::LedDeviceFadeCandy(const QJsonObject &deviceConfig)
|
||||
LedDeviceFadeCandy::LedDeviceFadeCandy(const QJsonObject& deviceConfig)
|
||||
: LedDevice(deviceConfig)
|
||||
, _client(nullptr)
|
||||
,_host()
|
||||
,_port(STREAM_DEFAULT_PORT)
|
||||
, _host()
|
||||
, _port(STREAM_DEFAULT_PORT)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -32,20 +36,20 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy()
|
||||
delete _client;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceFadeCandy::construct(const QJsonObject &deviceConfig)
|
||||
LedDevice* LedDeviceFadeCandy::construct(const QJsonObject& deviceConfig)
|
||||
{
|
||||
return new LedDeviceFadeCandy(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
|
||||
bool LedDeviceFadeCandy::init(const QJsonObject& deviceConfig)
|
||||
{
|
||||
bool isInitOK = false;
|
||||
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
if (LedDevice::init(deviceConfig))
|
||||
{
|
||||
if (getLedCount() > MAX_NUM_LEDS)
|
||||
{
|
||||
QString errortext = QString ("More LED configured than allowed (%1)").arg(MAX_NUM_LEDS);
|
||||
QString errortext = QString("More LED configured than allowed (%1)").arg(MAX_NUM_LEDS);
|
||||
this->setInError(errortext);
|
||||
isInitOK = false;
|
||||
}
|
||||
@@ -55,18 +59,18 @@ bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
|
||||
_port = deviceConfig["port"].toInt(STREAM_DEFAULT_PORT);
|
||||
|
||||
//If host not configured the init fails
|
||||
if ( _host.isEmpty() )
|
||||
if (_host.isEmpty())
|
||||
{
|
||||
this->setInError("No target hostname nor IP defined");
|
||||
}
|
||||
else
|
||||
{
|
||||
_channel = deviceConfig["channel"].toInt(0);
|
||||
_gamma = deviceConfig["gamma"].toDouble(1.0);
|
||||
_noDither = ! deviceConfig["dither"].toBool(false);
|
||||
_noInterp = ! deviceConfig["interpolation"].toBool(false);
|
||||
_manualLED = deviceConfig["manualLed"].toBool(false);
|
||||
_ledOnOff = deviceConfig["ledOn"].toBool(false);
|
||||
_channel = deviceConfig["channel"].toInt(0);
|
||||
_gamma = deviceConfig["gamma"].toDouble(1.0);
|
||||
_noDither = !deviceConfig["dither"].toBool(false);
|
||||
_noInterp = !deviceConfig["interpolation"].toBool(false);
|
||||
_manualLED = deviceConfig["manualLed"].toBool(false);
|
||||
_ledOnOff = deviceConfig["ledOn"].toBool(false);
|
||||
_setFcConfig = deviceConfig["setFcConfig"].toBool(false);
|
||||
|
||||
_whitePoint_r = 1.0;
|
||||
@@ -74,20 +78,19 @@ bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
|
||||
_whitePoint_b = 1.0;
|
||||
|
||||
const QJsonArray whitePointConfig = deviceConfig["whitePoint"].toArray();
|
||||
if ( !whitePointConfig.isEmpty() && whitePointConfig.size() == 3 )
|
||||
if (!whitePointConfig.isEmpty() && whitePointConfig.size() == 3)
|
||||
{
|
||||
_whitePoint_r = whitePointConfig[0].toDouble() / 255.0;
|
||||
_whitePoint_g = whitePointConfig[1].toDouble() / 255.0;
|
||||
_whitePoint_b = whitePointConfig[2].toDouble() / 255.0;
|
||||
}
|
||||
|
||||
_opc_data.resize( _ledRGBCount + OPC_HEADER_SIZE );
|
||||
_opc_data[0] = _channel;
|
||||
_opc_data.resize(static_cast<int>(_ledRGBCount) + OPC_HEADER_SIZE);
|
||||
_opc_data[0] = static_cast<char>(_channel);
|
||||
_opc_data[1] = OPC_SET_PIXELS;
|
||||
_opc_data[2] = _ledRGBCount >> 8;
|
||||
_opc_data[3] = _ledRGBCount & 0xff;
|
||||
qToBigEndian<quint16>(static_cast<quint16>(_ledRGBCount), _opc_data.data() + 2);
|
||||
|
||||
if ( initNetwork() )
|
||||
if (initNetwork())
|
||||
{
|
||||
isInitOK = true;
|
||||
}
|
||||
@@ -101,7 +104,7 @@ bool LedDeviceFadeCandy::initNetwork()
|
||||
{
|
||||
bool isInitOK = false;
|
||||
|
||||
if ( _client == nullptr )
|
||||
if (_client == nullptr)
|
||||
{
|
||||
_client = new QTcpSocket(this);
|
||||
isInitOK = true;
|
||||
@@ -116,10 +119,10 @@ int LedDeviceFadeCandy::open()
|
||||
_isDeviceReady = false;
|
||||
|
||||
// Try to open the LedDevice
|
||||
if ( !tryConnect() )
|
||||
if (!tryConnect())
|
||||
{
|
||||
errortext = QString ("Failed to open device.");
|
||||
this->setInError( errortext );
|
||||
errortext = QString("Failed to open device.");
|
||||
this->setInError(errortext);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -136,7 +139,7 @@ int LedDeviceFadeCandy::close()
|
||||
_isDeviceReady = false;
|
||||
|
||||
// LedDevice specific closing activities
|
||||
if ( _client != nullptr )
|
||||
if (_client != nullptr)
|
||||
{
|
||||
_client->close();
|
||||
// Everything is OK -> device is closed
|
||||
@@ -147,7 +150,7 @@ int LedDeviceFadeCandy::close()
|
||||
bool LedDeviceFadeCandy::isConnected() const
|
||||
{
|
||||
bool connected = false;
|
||||
if ( _client != nullptr )
|
||||
if (_client != nullptr)
|
||||
{
|
||||
connected = _client->state() == QAbstractSocket::ConnectedState;
|
||||
}
|
||||
@@ -156,13 +159,13 @@ bool LedDeviceFadeCandy::isConnected() const
|
||||
|
||||
bool LedDeviceFadeCandy::tryConnect()
|
||||
{
|
||||
if ( _client != nullptr )
|
||||
if (_client != nullptr)
|
||||
{
|
||||
if ( _client->state() == QAbstractSocket::UnconnectedState ) {
|
||||
_client->connectToHost( _host, _port);
|
||||
if ( _client->waitForConnected(1000) )
|
||||
if (_client->state() == QAbstractSocket::UnconnectedState) {
|
||||
_client->connectToHost(_host, static_cast<quint16>(_port));
|
||||
if (_client->waitForConnected(CONNECT_TIMEOUT.count()))
|
||||
{
|
||||
Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", QSTRING_CSTR(_host), _port, _channel);
|
||||
Info(_log, "fadecandy/opc: connected to %s:%d on channel %d", QSTRING_CSTR(_host), _port, _channel);
|
||||
if (_setFcConfig)
|
||||
{
|
||||
sendFadeCandyConfiguration();
|
||||
@@ -173,50 +176,48 @@ bool LedDeviceFadeCandy::tryConnect()
|
||||
return isConnected();
|
||||
}
|
||||
|
||||
int LedDeviceFadeCandy::write( const std::vector<ColorRgb> & ledValues )
|
||||
int LedDeviceFadeCandy::write(const std::vector<ColorRgb>& ledValues)
|
||||
{
|
||||
uint idx = OPC_HEADER_SIZE;
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
_opc_data[idx ] = unsigned( color.red );
|
||||
_opc_data[idx+1] = unsigned( color.green );
|
||||
_opc_data[idx+2] = unsigned( color.blue );
|
||||
_opc_data[idx] = static_cast<char>(color.red);
|
||||
_opc_data[idx + 1] = static_cast<char>(color.green);
|
||||
_opc_data[idx + 2] = static_cast<char>(color.blue);
|
||||
idx += 3;
|
||||
}
|
||||
|
||||
int retval = transferData()<0 ? -1 : 0;
|
||||
int retval = transferData() < 0 ? -1 : 0;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int LedDeviceFadeCandy::transferData()
|
||||
qint64 LedDeviceFadeCandy::transferData()
|
||||
{
|
||||
if ( isConnected() || tryConnect() )
|
||||
if (isConnected() || tryConnect())
|
||||
{
|
||||
return _client->write( _opc_data, _opc_data.size() );
|
||||
return _client->write(_opc_data);
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
int LedDeviceFadeCandy::sendSysEx(uint8_t systemId, uint8_t commandId, const QByteArray& msg)
|
||||
qint64 LedDeviceFadeCandy::sendSysEx(uint8_t systemId, uint8_t commandId, const QByteArray& msg)
|
||||
{
|
||||
if ( isConnected() )
|
||||
if (isConnected())
|
||||
{
|
||||
QByteArray sysExData;
|
||||
uint data_size = msg.size() + 4;
|
||||
sysExData.resize( 4 + OPC_HEADER_SIZE );
|
||||
int data_size = msg.size() + 4;
|
||||
sysExData.resize(4 + OPC_HEADER_SIZE);
|
||||
|
||||
sysExData[0] = 0;
|
||||
sysExData[1] = OPC_SYS_EX;
|
||||
sysExData[2] = data_size >>8;
|
||||
sysExData[3] = data_size &0xff;
|
||||
sysExData[4] = systemId >>8;
|
||||
sysExData[5] = systemId &0xff;
|
||||
sysExData[6] = commandId >>8;
|
||||
sysExData[7] = commandId &0xff;
|
||||
sysExData[1] = static_cast<char>(OPC_SYS_EX);
|
||||
|
||||
qToBigEndian<quint16>(static_cast<quint16>(data_size), sysExData.data() + 2);
|
||||
qToBigEndian<quint16>(static_cast<quint16>(systemId), sysExData.data() + 4);
|
||||
qToBigEndian<quint16>(static_cast<quint16>(commandId), sysExData.data() + 6);
|
||||
|
||||
sysExData += msg;
|
||||
|
||||
return _client->write( sysExData, sysExData.size() );
|
||||
return _client->write(sysExData, sysExData.size());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -224,9 +225,9 @@ int LedDeviceFadeCandy::sendSysEx(uint8_t systemId, uint8_t commandId, const QBy
|
||||
void LedDeviceFadeCandy::sendFadeCandyConfiguration()
|
||||
{
|
||||
Debug(_log, "send configuration to fadecandy");
|
||||
QString data = "{\"gamma\": "+QString::number(_gamma,'g',4)+", \"whitepoint\": ["+QString::number(_whitePoint_r,'g',4)+", "+QString::number(_whitePoint_g,'g',4)+", "+QString::number(_whitePoint_b,'g',4)+"]}";
|
||||
sendSysEx(1, 1, data.toLocal8Bit() );
|
||||
QString data = "{\"gamma\": " + QString::number(_gamma, 'g', 4) + ", \"whitepoint\": [" + QString::number(_whitePoint_r, 'g', 4) + ", " + QString::number(_whitePoint_g, 'g', 4) + ", " + QString::number(_whitePoint_b, 'g', 4) + "]}";
|
||||
sendSysEx(1, 1, data.toLocal8Bit());
|
||||
|
||||
char firmware_data = ((uint8_t)_noDither | ((uint8_t)_noInterp << 1) | ((uint8_t)_manualLED << 2) | ((uint8_t)_ledOnOff << 3) );
|
||||
sendSysEx(1, 2, QByteArray(1,firmware_data) );
|
||||
char firmware_data = static_cast<char>(static_cast<uint8_t>(_noDither) | (static_cast<uint8_t>(_noInterp) << 1) | (static_cast<uint8_t>(_manualLED) << 2) | (static_cast<uint8_t>(_ledOnOff) << 3));
|
||||
sendSysEx(1, 2, QByteArray(1, firmware_data));
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig Device's configuration as JSON-Object
|
||||
///
|
||||
explicit LedDeviceFadeCandy(const QJsonObject &deviceConfig);
|
||||
explicit LedDeviceFadeCandy(const QJsonObject& deviceConfig);
|
||||
|
||||
///
|
||||
/// @brief Destructor of the LedDevice
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
///
|
||||
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
||||
/// @return LedDevice constructed
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject& deviceConfig);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -62,7 +62,7 @@ protected:
|
||||
/// @param[in] deviceConfig the JSON device configuration
|
||||
/// @return True, if success
|
||||
///
|
||||
bool init(const QJsonObject &deviceConfig) override;
|
||||
bool init(const QJsonObject& deviceConfig) override;
|
||||
|
||||
///
|
||||
/// @brief Opens the output device.
|
||||
@@ -84,7 +84,7 @@ protected:
|
||||
/// @param[in] ledValues The RGB-color per LED
|
||||
/// @return Zero on success, else negative
|
||||
///
|
||||
int write(const std::vector<ColorRgb> & ledValues) override;
|
||||
int write(const std::vector<ColorRgb>& ledValues) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -113,7 +113,7 @@ private:
|
||||
///
|
||||
/// @return amount of transferred bytes. -1 error while transferring, -2 error while connecting
|
||||
///
|
||||
int transferData();
|
||||
qint64 transferData();
|
||||
|
||||
///
|
||||
/// @brief Send system exclusive commands
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
/// @param[in] commandId id of command
|
||||
/// @param[in] msg the sysEx message
|
||||
/// @return amount bytes written, -1 if failed
|
||||
int sendSysEx(uint8_t systemId, uint8_t commandId, const QByteArray& msg);
|
||||
qint64 sendSysEx(uint8_t systemId, uint8_t commandId, const QByteArray& msg);
|
||||
|
||||
///
|
||||
/// @brief Sends the configuration to fadecandy cserver
|
||||
@@ -131,8 +131,8 @@ private:
|
||||
|
||||
QTcpSocket* _client;
|
||||
QString _host;
|
||||
uint16_t _port;
|
||||
unsigned _channel;
|
||||
int _port;
|
||||
int _channel;
|
||||
QByteArray _opc_data;
|
||||
|
||||
// fadecandy sysEx
|
||||
@@ -145,7 +145,6 @@ private:
|
||||
bool _noInterp;
|
||||
bool _manualLED;
|
||||
bool _ledOnOff;
|
||||
|
||||
};
|
||||
|
||||
#endif // LEDEVICEFADECANDY_H
|
||||
|
@@ -7,6 +7,7 @@
|
||||
// Qt includes
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkReply>
|
||||
#include <QtEndian>
|
||||
|
||||
//std includes
|
||||
#include <sstream>
|
||||
@@ -14,18 +15,17 @@
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
|
||||
const bool verbose = false;
|
||||
const bool verbose = false;
|
||||
const bool verbose3 = false;
|
||||
|
||||
// Configuration settings
|
||||
const char CONFIG_ADDRESS[] = "host";
|
||||
//const char CONFIG_PORT[] = "port";
|
||||
const char CONFIG_AUTH_TOKEN[] ="token";
|
||||
const char CONFIG_AUTH_TOKEN[] = "token";
|
||||
|
||||
const char CONFIG_PANEL_ORDER_TOP_DOWN[] ="panelOrderTopDown";
|
||||
const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] ="panelOrderLeftRight";
|
||||
const char CONFIG_PANEL_START_POS[] ="panelStartPos";
|
||||
const char CONFIG_PANEL_ORDER_TOP_DOWN[] = "panelOrderTopDown";
|
||||
const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] = "panelOrderLeftRight";
|
||||
const char CONFIG_PANEL_START_POS[] = "panelStartPos";
|
||||
|
||||
// Panel configuration settings
|
||||
const char PANEL_LAYOUT[] = "layout";
|
||||
@@ -61,16 +61,19 @@ const char API_BASE_PATH[] = "/api/v1/%1/";
|
||||
const char API_ROOT[] = "";
|
||||
//const char API_EXT_MODE_STRING_V1[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\"}}";
|
||||
const char API_EXT_MODE_STRING_V2[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\", \"extControlVersion\" : \"v2\"}}";
|
||||
const char API_STATE[] ="state";
|
||||
const char API_STATE[] = "state";
|
||||
const char API_PANELLAYOUT[] = "panelLayout";
|
||||
const char API_EFFECT[] = "effects";
|
||||
|
||||
//Nanoleaf Control data stream
|
||||
const int STREAM_FRAME_PANEL_NUM_SIZE = 2;
|
||||
const int STREAM_FRAME_PANEL_INFO_SIZE = 8;
|
||||
|
||||
// Nanoleaf ssdp services
|
||||
const char SSDP_ID[] = "ssdp:all";
|
||||
const char SSDP_FILTER_HEADER[] = "ST";
|
||||
const char SSDP_CANVAS[] = "nanoleaf:nl29";
|
||||
const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light";
|
||||
|
||||
} //End of constants
|
||||
|
||||
// Nanoleaf Panel Shapetypes
|
||||
@@ -81,7 +84,7 @@ enum SHAPETYPES {
|
||||
CONTROL_SQUARE_PRIMARY,
|
||||
CONTROL_SQUARE_PASSIVE,
|
||||
POWER_SUPPLY,
|
||||
};
|
||||
};
|
||||
|
||||
// Nanoleaf external control versions
|
||||
enum EXTCONTROLVERSIONS {
|
||||
@@ -89,20 +92,20 @@ enum EXTCONTROLVERSIONS {
|
||||
EXTCTRLVER_V2
|
||||
};
|
||||
|
||||
LedDeviceNanoleaf::LedDeviceNanoleaf(const QJsonObject &deviceConfig)
|
||||
LedDeviceNanoleaf::LedDeviceNanoleaf(const QJsonObject& deviceConfig)
|
||||
: ProviderUdp(deviceConfig)
|
||||
,_restApi(nullptr)
|
||||
,_apiPort(API_DEFAULT_PORT)
|
||||
,_topDown(true)
|
||||
,_leftRight(true)
|
||||
,_startPos(0)
|
||||
,_endPos(0)
|
||||
,_extControlVersion (EXTCTRLVER_V2),
|
||||
, _restApi(nullptr)
|
||||
, _apiPort(API_DEFAULT_PORT)
|
||||
, _topDown(true)
|
||||
, _leftRight(true)
|
||||
, _startPos(0)
|
||||
, _endPos(0)
|
||||
, _extControlVersion(EXTCTRLVER_V2),
|
||||
_panelLedCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceNanoleaf::construct(const QJsonObject &deviceConfig)
|
||||
LedDevice* LedDeviceNanoleaf::construct(const QJsonObject& deviceConfig)
|
||||
{
|
||||
return new LedDeviceNanoleaf(deviceConfig);
|
||||
}
|
||||
@@ -113,7 +116,7 @@ LedDeviceNanoleaf::~LedDeviceNanoleaf()
|
||||
_restApi = nullptr;
|
||||
}
|
||||
|
||||
bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)
|
||||
bool LedDeviceNanoleaf::init(const QJsonObject& deviceConfig)
|
||||
{
|
||||
// Overwrite non supported/required features
|
||||
setLatchTime(0);
|
||||
@@ -121,69 +124,69 @@ bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)
|
||||
|
||||
if (deviceConfig["rewriteTime"].toInt(0) > 0)
|
||||
{
|
||||
Info (_log, "Device Nanoleaf does not require rewrites. Refresh time is ignored.");
|
||||
Info(_log, "Device Nanoleaf does not require rewrites. Refresh time is ignored.");
|
||||
}
|
||||
|
||||
DebugIf(verbose, _log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||
DebugIf(verbose, _log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
bool isInitOK = false;
|
||||
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
if (LedDevice::init(deviceConfig))
|
||||
{
|
||||
uint configuredLedCount = this->getLedCount();
|
||||
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
||||
Debug(_log, "LedCount : %u", configuredLedCount);
|
||||
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
||||
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, "RewriteTime : %d", this->getRewriteTime());
|
||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||
|
||||
// Read panel organisation configuration
|
||||
if ( deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].isString() )
|
||||
if (deviceConfig[CONFIG_PANEL_ORDER_TOP_DOWN].isString())
|
||||
{
|
||||
_topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toString().toInt() == 0;
|
||||
_topDown = deviceConfig[CONFIG_PANEL_ORDER_TOP_DOWN].toString().toInt() == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toInt() == 0;
|
||||
_topDown = deviceConfig[CONFIG_PANEL_ORDER_TOP_DOWN].toInt() == 0;
|
||||
}
|
||||
|
||||
if ( deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].isString() )
|
||||
if (deviceConfig[CONFIG_PANEL_ORDER_LEFT_RIGHT].isString())
|
||||
{
|
||||
_leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toString().toInt() == 0;
|
||||
_leftRight = deviceConfig[CONFIG_PANEL_ORDER_LEFT_RIGHT].toString().toInt() == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toInt() == 0;
|
||||
_leftRight = deviceConfig[CONFIG_PANEL_ORDER_LEFT_RIGHT].toInt() == 0;
|
||||
}
|
||||
|
||||
_startPos = static_cast<uint>( deviceConfig[ CONFIG_PANEL_START_POS ].toInt(0) );
|
||||
_startPos = deviceConfig[CONFIG_PANEL_START_POS].toInt(0);
|
||||
|
||||
// TODO: Allow to handle port dynamically
|
||||
|
||||
//Set hostname as per configuration and_defaultHost default port
|
||||
_hostname = deviceConfig[ CONFIG_ADDRESS ].toString();
|
||||
_apiPort = API_DEFAULT_PORT;
|
||||
_authToken = deviceConfig[ CONFIG_AUTH_TOKEN ].toString();
|
||||
_hostname = deviceConfig[CONFIG_ADDRESS].toString();
|
||||
_apiPort = API_DEFAULT_PORT;
|
||||
_authToken = deviceConfig[CONFIG_AUTH_TOKEN].toString();
|
||||
|
||||
//If host not configured the init failed
|
||||
if ( _hostname.isEmpty() )
|
||||
if (_hostname.isEmpty())
|
||||
{
|
||||
this->setInError("No target hostname nor IP defined");
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( initRestAPI( _hostname, _apiPort, _authToken ) )
|
||||
if (initRestAPI(_hostname, _apiPort, _authToken))
|
||||
{
|
||||
// Read LedDevice configuration and validate against device configuration
|
||||
if ( initLedsConfiguration() )
|
||||
if (initLedsConfiguration())
|
||||
{
|
||||
// Set UDP streaming host and port
|
||||
_devConfig["host"] = _hostname;
|
||||
_devConfig["port"] = STREAM_CONTROL_DEFAULT_PORT;
|
||||
|
||||
isInitOK = ProviderUdp::init(_devConfig);
|
||||
Debug(_log, "Hostname/IP : %s", QSTRING_CSTR( _hostname ));
|
||||
Debug(_log, "Hostname/IP : %s", QSTRING_CSTR(_hostname));
|
||||
Debug(_log, "Port : %d", _port);
|
||||
}
|
||||
}
|
||||
@@ -201,9 +204,9 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
// Read Panel count and panel Ids
|
||||
_restApi->setPath(API_ROOT);
|
||||
httpResponse response = _restApi->get();
|
||||
if ( response.error() )
|
||||
if (response.error())
|
||||
{
|
||||
this->setInError ( response.getErrorReason() );
|
||||
this->setInError(response.getErrorReason());
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
@@ -215,35 +218,35 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
QString deviceManufacturer = jsonAllPanelInfo[DEV_DATA_MANUFACTURER].toString();
|
||||
_deviceFirmwareVersion = jsonAllPanelInfo[DEV_DATA_FIRMWAREVERSION].toString();
|
||||
|
||||
Debug(_log, "Name : %s", QSTRING_CSTR( deviceName ));
|
||||
Debug(_log, "Model : %s", QSTRING_CSTR( _deviceModel ));
|
||||
Debug(_log, "Manufacturer : %s", QSTRING_CSTR( deviceManufacturer ));
|
||||
Debug(_log, "FirmwareVersion: %s", QSTRING_CSTR( _deviceFirmwareVersion));
|
||||
Debug(_log, "Name : %s", QSTRING_CSTR(deviceName));
|
||||
Debug(_log, "Model : %s", QSTRING_CSTR(_deviceModel));
|
||||
Debug(_log, "Manufacturer : %s", QSTRING_CSTR(deviceManufacturer));
|
||||
Debug(_log, "FirmwareVersion: %s", QSTRING_CSTR(_deviceFirmwareVersion));
|
||||
|
||||
// Get panel details from /panelLayout/layout
|
||||
QJsonObject jsonPanelLayout = jsonAllPanelInfo[API_PANELLAYOUT].toObject();
|
||||
QJsonObject jsonLayout = jsonPanelLayout[PANEL_LAYOUT].toObject();
|
||||
|
||||
uint panelNum = static_cast<uint>(jsonLayout[PANEL_NUM].toInt());
|
||||
int panelNum = jsonLayout[PANEL_NUM].toInt();
|
||||
QJsonArray positionData = jsonLayout[PANEL_POSITIONDATA].toArray();
|
||||
|
||||
std::map<uint, std::map<uint, uint>> panelMap;
|
||||
std::map<int, std::map<int, int>> panelMap;
|
||||
|
||||
// Loop over all children.
|
||||
for (const QJsonValue value : positionData)
|
||||
foreach(const QJsonValue & value, positionData)
|
||||
{
|
||||
QJsonObject panelObj = value.toObject();
|
||||
|
||||
uint panelId = static_cast<uint>(panelObj[PANEL_ID].toInt());
|
||||
uint panelX = static_cast<uint>(panelObj[PANEL_POS_X].toInt());
|
||||
uint panelY = static_cast<uint>(panelObj[PANEL_POS_Y].toInt());
|
||||
uint panelshapeType = static_cast<uint>(panelObj[PANEL_SHAPE_TYPE].toInt());
|
||||
//uint panelOrientation = static_cast<uint>(panelObj[PANEL_ORIENTATION].toInt());
|
||||
int panelId = panelObj[PANEL_ID].toInt();
|
||||
int panelX = panelObj[PANEL_POS_X].toInt();
|
||||
int panelY = panelObj[PANEL_POS_Y].toInt();
|
||||
int panelshapeType = panelObj[PANEL_SHAPE_TYPE].toInt();
|
||||
//int panelOrientation = panelObj[PANEL_ORIENTATION].toInt();
|
||||
|
||||
DebugIf(verbose, _log, "Panel [%u] (%u,%u) - Type: [%u]", panelId, panelX, panelY, panelshapeType );
|
||||
DebugIf(verbose, _log, "Panel [%d] (%d,%d) - Type: [%d]", panelId, panelX, panelY, panelshapeType);
|
||||
|
||||
// Skip Rhythm panels
|
||||
if ( panelshapeType != RHYTM )
|
||||
if (panelshapeType != RHYTM)
|
||||
{
|
||||
panelMap[panelY][panelX] = panelId;
|
||||
}
|
||||
@@ -254,16 +257,16 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
}
|
||||
|
||||
// Travers panels top down
|
||||
for(auto posY = panelMap.crbegin(); posY != panelMap.crend(); ++posY)
|
||||
for (auto posY = panelMap.crbegin(); posY != panelMap.crend(); ++posY)
|
||||
{
|
||||
// Sort panels left to right
|
||||
if ( _leftRight )
|
||||
if (_leftRight)
|
||||
{
|
||||
for( auto posX = posY->second.cbegin(); posX != posY->second.cend(); ++posX)
|
||||
for (auto posX = posY->second.cbegin(); posX != posY->second.cend(); ++posX)
|
||||
{
|
||||
DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX->first, posX->second );
|
||||
DebugIf(verbose3, _log, "panelMap[%d][%d]=%d", posY->first, posX->first, posX->second);
|
||||
|
||||
if ( _topDown )
|
||||
if (_topDown)
|
||||
{
|
||||
_panelIds.push_back(posX->second);
|
||||
}
|
||||
@@ -276,11 +279,11 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
else
|
||||
{
|
||||
// Sort panels right to left
|
||||
for( auto posX = posY->second.crbegin(); posX != posY->second.crend(); ++posX)
|
||||
for (auto posX = posY->second.crbegin(); posX != posY->second.crend(); ++posX)
|
||||
{
|
||||
DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX->first, posX->second );
|
||||
DebugIf(verbose3, _log, "panelMap[%d][%d]=%d", posY->first, posX->first, posX->second);
|
||||
|
||||
if ( _topDown )
|
||||
if (_topDown)
|
||||
{
|
||||
_panelIds.push_back(posX->second);
|
||||
}
|
||||
@@ -292,22 +295,22 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
this->_panelLedCount = static_cast<uint>(_panelIds.size());
|
||||
_devConfig["hardwareLedCount"] = static_cast<int>(_panelLedCount);
|
||||
this->_panelLedCount = _panelIds.size();
|
||||
_devConfig["hardwareLedCount"] = _panelLedCount;
|
||||
|
||||
Debug(_log, "PanelsNum : %u", panelNum);
|
||||
Debug(_log, "PanelLedCount : %u", _panelLedCount);
|
||||
Debug(_log, "PanelsNum : %d", panelNum);
|
||||
Debug(_log, "PanelLedCount : %d", _panelLedCount);
|
||||
|
||||
// Check. if enough panels were found.
|
||||
uint configuredLedCount = this->getLedCount();
|
||||
int configuredLedCount = this->getLedCount();
|
||||
_endPos = _startPos + configuredLedCount - 1;
|
||||
|
||||
Debug(_log, "Sort Top>Down : %d", _topDown);
|
||||
Debug(_log, "Sort Left>Right: %d", _leftRight);
|
||||
Debug(_log, "Start Panel Pos: %u", _startPos);
|
||||
Debug(_log, "End Panel Pos : %u", _endPos);
|
||||
Debug(_log, "Start Panel Pos: %d", _startPos);
|
||||
Debug(_log, "End Panel Pos : %d", _endPos);
|
||||
|
||||
if (_panelLedCount < configuredLedCount )
|
||||
if (_panelLedCount < configuredLedCount)
|
||||
{
|
||||
QString errorReason = QString("Not enough panels [%1] for configured LEDs [%2] found!")
|
||||
.arg(_panelLedCount)
|
||||
@@ -317,16 +320,16 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _panelLedCount > this->getLedCount() )
|
||||
if (_panelLedCount > this->getLedCount())
|
||||
{
|
||||
Info(_log, "%s: More panels [%u] than configured LEDs [%u].", QSTRING_CSTR(this->getActiveDeviceType()), _panelLedCount, configuredLedCount );
|
||||
Info(_log, "%s: More panels [%d] than configured LEDs [%d].", QSTRING_CSTR(this->getActiveDeviceType()), _panelLedCount, configuredLedCount);
|
||||
}
|
||||
|
||||
// Check, if start position + number of configured LEDs is greater than number of panels available
|
||||
if ( _endPos >= _panelLedCount )
|
||||
if (_endPos >= _panelLedCount)
|
||||
{
|
||||
QString errorReason = QString("Start panel [%1] out of range. Start panel position can be max [%2] given [%3] panel available!")
|
||||
.arg(_startPos).arg(_panelLedCount-configuredLedCount).arg(_panelLedCount);
|
||||
.arg(_startPos).arg(_panelLedCount - configuredLedCount).arg(_panelLedCount);
|
||||
|
||||
this->setInError(errorReason);
|
||||
isInitOK = false;
|
||||
@@ -336,16 +339,16 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
bool LedDeviceNanoleaf::initRestAPI(const QString &hostname, int port, const QString &token )
|
||||
bool LedDeviceNanoleaf::initRestAPI(const QString& hostname, int port, const QString& token)
|
||||
{
|
||||
bool isInitOK = false;
|
||||
|
||||
if ( _restApi == nullptr )
|
||||
if (_restApi == nullptr)
|
||||
{
|
||||
_restApi = new ProviderRestApi(hostname, port );
|
||||
_restApi = new ProviderRestApi(hostname, port);
|
||||
|
||||
//Base-path is api-path + authentication token
|
||||
_restApi->setBasePath( QString(API_BASE_PATH).arg(token) );
|
||||
_restApi->setBasePath(QString(API_BASE_PATH).arg(token));
|
||||
|
||||
isInitOK = true;
|
||||
}
|
||||
@@ -360,13 +363,13 @@ int LedDeviceNanoleaf::open()
|
||||
QJsonDocument responseDoc = changeToExternalControlMode();
|
||||
// Resolve port for Light Panels
|
||||
QJsonObject jsonStreamControllInfo = responseDoc.object();
|
||||
if ( ! jsonStreamControllInfo.isEmpty() )
|
||||
if (!jsonStreamControllInfo.isEmpty())
|
||||
{
|
||||
//Set default streaming port
|
||||
_port = static_cast<uchar>(jsonStreamControllInfo[STREAM_CONTROL_PORT].toInt());
|
||||
}
|
||||
|
||||
if ( ProviderUdp::open() == 0 )
|
||||
if (ProviderUdp::open() == 0)
|
||||
{
|
||||
// Everything is OK, device is ready
|
||||
_isDeviceReady = true;
|
||||
@@ -375,10 +378,10 @@ int LedDeviceNanoleaf::open()
|
||||
return retval;
|
||||
}
|
||||
|
||||
QJsonObject LedDeviceNanoleaf::discover()
|
||||
QJsonObject LedDeviceNanoleaf::discover(const QJsonObject& /*params*/)
|
||||
{
|
||||
QJsonObject devicesDiscovered;
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType);
|
||||
|
||||
QJsonArray deviceList;
|
||||
|
||||
@@ -391,41 +394,41 @@ QJsonObject LedDeviceNanoleaf::discover()
|
||||
discover.setSearchFilter(searchTargetFilter, SSDP_FILTER_HEADER);
|
||||
QString searchTarget = SSDP_ID;
|
||||
|
||||
if ( discover.discoverServices(searchTarget) > 0 )
|
||||
if (discover.discoverServices(searchTarget) > 0)
|
||||
{
|
||||
deviceList = discover.getServicesDiscoveredJson();
|
||||
}
|
||||
|
||||
devicesDiscovered.insert("devices", deviceList);
|
||||
Debug(_log, "devicesDiscovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||
Debug(_log, "devicesDiscovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
return devicesDiscovered;
|
||||
}
|
||||
|
||||
QJsonObject LedDeviceNanoleaf::getProperties(const QJsonObject& params)
|
||||
{
|
||||
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
QJsonObject properties;
|
||||
|
||||
// Get Nanoleaf device properties
|
||||
QString host = params["host"].toString("");
|
||||
if ( !host.isEmpty() )
|
||||
if (!host.isEmpty())
|
||||
{
|
||||
QString authToken = params["token"].toString("");
|
||||
QString filter = params["filter"].toString("");
|
||||
|
||||
// Resolve hostname and port (or use default API port)
|
||||
QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QStringList addressparts = QStringUtils::split(host, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString apiHost = addressparts[0];
|
||||
int apiPort;
|
||||
|
||||
if ( addressparts.size() > 1)
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
apiPort = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
apiPort = API_DEFAULT_PORT;
|
||||
apiPort = API_DEFAULT_PORT;
|
||||
}
|
||||
|
||||
initRestAPI(apiHost, apiPort, authToken);
|
||||
@@ -433,40 +436,39 @@ QJsonObject LedDeviceNanoleaf::getProperties(const QJsonObject& params)
|
||||
|
||||
// Perform request
|
||||
httpResponse response = _restApi->get();
|
||||
if ( response.error() )
|
||||
if (response.error())
|
||||
{
|
||||
Warning (_log, "%s get properties failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
|
||||
Warning(_log, "%s get properties failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
|
||||
}
|
||||
|
||||
properties.insert("properties", response.getBody().object());
|
||||
|
||||
Debug(_log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||
|
||||
Debug(_log, "properties: [%s]", QString(QJsonDocument(properties).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
void LedDeviceNanoleaf::identify(const QJsonObject& params)
|
||||
{
|
||||
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
||||
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
QString host = params["host"].toString("");
|
||||
if ( !host.isEmpty() )
|
||||
if (!host.isEmpty())
|
||||
{
|
||||
QString authToken = params["token"].toString("");
|
||||
|
||||
// Resolve hostname and port (or use default API port)
|
||||
QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QStringList addressparts = QStringUtils::split(host, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString apiHost = addressparts[0];
|
||||
int apiPort;
|
||||
|
||||
if ( addressparts.size() > 1)
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
apiPort = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
apiPort = API_DEFAULT_PORT;
|
||||
apiPort = API_DEFAULT_PORT;
|
||||
}
|
||||
|
||||
initRestAPI(apiHost, apiPort, authToken);
|
||||
@@ -474,33 +476,33 @@ void LedDeviceNanoleaf::identify(const QJsonObject& params)
|
||||
|
||||
// Perform request
|
||||
httpResponse response = _restApi->put();
|
||||
if ( response.error() )
|
||||
if (response.error())
|
||||
{
|
||||
Warning (_log, "%s identification failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
|
||||
Warning(_log, "%s identification failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LedDeviceNanoleaf::powerOn()
|
||||
{
|
||||
if ( _isDeviceReady)
|
||||
if (_isDeviceReady)
|
||||
{
|
||||
changeToExternalControlMode();
|
||||
|
||||
//Power-on Nanoleaf device
|
||||
_restApi->setPath(API_STATE);
|
||||
_restApi->put( getOnOffRequest(true) );
|
||||
_restApi->put(getOnOffRequest(true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedDeviceNanoleaf::powerOff()
|
||||
{
|
||||
if ( _isDeviceReady)
|
||||
if (_isDeviceReady)
|
||||
{
|
||||
//Power-off the Nanoleaf device physically
|
||||
_restApi->setPath(API_STATE);
|
||||
_restApi->put( getOnOffRequest(false) );
|
||||
_restApi->put(getOnOffRequest(false));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -508,7 +510,7 @@ bool LedDeviceNanoleaf::powerOff()
|
||||
QString LedDeviceNanoleaf::getOnOffRequest(bool isOn) const
|
||||
{
|
||||
QString state = isOn ? STATE_VALUE_TRUE : STATE_VALUE_FALSE;
|
||||
return QString( "{\"%1\":{\"%2\":%3}}" ).arg(STATE_ON, STATE_ONOFF_VALUE, state);
|
||||
return QString("{\"%1\":{\"%2\":%3}}").arg(STATE_ON, STATE_ONOFF_VALUE, state);
|
||||
}
|
||||
|
||||
QJsonDocument LedDeviceNanoleaf::changeToExternalControlMode()
|
||||
@@ -518,15 +520,14 @@ QJsonDocument LedDeviceNanoleaf::changeToExternalControlMode()
|
||||
//Enable UDP Mode v2
|
||||
|
||||
_restApi->setPath(API_EFFECT);
|
||||
httpResponse response =_restApi->put(API_EXT_MODE_STRING_V2);
|
||||
httpResponse response = _restApi->put(API_EXT_MODE_STRING_V2);
|
||||
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
int LedDeviceNanoleaf::write(const std::vector<ColorRgb> & ledValues)
|
||||
int LedDeviceNanoleaf::write(const std::vector<ColorRgb>& ledValues)
|
||||
{
|
||||
int retVal = 0;
|
||||
uint udpBufferSize;
|
||||
|
||||
//
|
||||
// nPanels 2B
|
||||
@@ -537,35 +538,27 @@ int LedDeviceNanoleaf::write(const std::vector<ColorRgb> & ledValues)
|
||||
//
|
||||
// Note: Nanoleaf Light Panels (Aurora) now support External Control V2 (tested with FW 3.2.0)
|
||||
|
||||
udpBufferSize = _panelLedCount * 8 + 2;
|
||||
std::vector<uint8_t> udpbuffer;
|
||||
int udpBufferSize = STREAM_FRAME_PANEL_NUM_SIZE + _panelLedCount * STREAM_FRAME_PANEL_INFO_SIZE;
|
||||
|
||||
QByteArray udpbuffer;
|
||||
udpbuffer.resize(udpBufferSize);
|
||||
|
||||
uchar lowByte; // lower byte
|
||||
uchar highByte; // upper byte
|
||||
|
||||
uint i=0;
|
||||
int i = 0;
|
||||
|
||||
// Set number of panels
|
||||
highByte = static_cast<uchar>(_panelLedCount >>8 );
|
||||
lowByte = static_cast<uchar>(_panelLedCount & 0xFF);
|
||||
|
||||
udpbuffer[i++] = highByte;
|
||||
udpbuffer[i++] = lowByte;
|
||||
qToBigEndian<quint16>(static_cast<quint16>(_panelLedCount), udpbuffer.data() + i);
|
||||
i += 2;
|
||||
|
||||
ColorRgb color;
|
||||
|
||||
//Maintain LED counter independent from PanelCounter
|
||||
uint ledCounter = 0;
|
||||
for ( uint panelCounter=0; panelCounter < _panelLedCount; panelCounter++ )
|
||||
int ledCounter = 0;
|
||||
for (int panelCounter = 0; panelCounter < _panelLedCount; panelCounter++)
|
||||
{
|
||||
uint panelID = _panelIds[panelCounter];
|
||||
|
||||
highByte = static_cast<uchar>(panelID >>8 );
|
||||
lowByte = static_cast<uchar>(panelID & 0xFF);
|
||||
int panelID = _panelIds[panelCounter];
|
||||
|
||||
// Set panels configured
|
||||
if( panelCounter >= _startPos && panelCounter <= _endPos ) {
|
||||
if (panelCounter >= _startPos && panelCounter <= _endPos) {
|
||||
color = static_cast<ColorRgb>(ledValues.at(ledCounter));
|
||||
++ledCounter;
|
||||
}
|
||||
@@ -573,49 +566,35 @@ int LedDeviceNanoleaf::write(const std::vector<ColorRgb> & ledValues)
|
||||
{
|
||||
// Set panels not configured to black;
|
||||
color = ColorRgb::BLACK;
|
||||
DebugIf(verbose3, _log, "[%u] >= panelLedCount [%u] => Set to BLACK", panelCounter, _panelLedCount );
|
||||
DebugIf(verbose3, _log, "[%d] >= panelLedCount [%d] => Set to BLACK", panelCounter, _panelLedCount);
|
||||
}
|
||||
|
||||
// Set panelID
|
||||
udpbuffer[i++] = highByte;
|
||||
udpbuffer[i++] = lowByte;
|
||||
qToBigEndian<quint16>(static_cast<quint16>(panelID), udpbuffer.data() + i);
|
||||
i += 2;
|
||||
|
||||
// Set panel's color LEDs
|
||||
udpbuffer[i++] = color.red;
|
||||
udpbuffer[i++] = color.green;
|
||||
udpbuffer[i++] = color.blue;
|
||||
udpbuffer[i++] = static_cast<char>(color.red);
|
||||
udpbuffer[i++] = static_cast<char>(color.green);
|
||||
udpbuffer[i++] = static_cast<char>(color.blue);
|
||||
|
||||
// Set white LED
|
||||
udpbuffer[i++] = 0; // W not set manually
|
||||
|
||||
// Set transition time
|
||||
unsigned char tranitionTime = 1; // currently fixed at value 1 which corresponds to 100ms
|
||||
qToBigEndian<quint16>(static_cast<quint16>(tranitionTime), udpbuffer.data() + i);
|
||||
i += 2;
|
||||
|
||||
highByte = static_cast<uchar>(tranitionTime >>8 );
|
||||
lowByte = static_cast<uchar>(tranitionTime & 0xFF);
|
||||
|
||||
udpbuffer[i++] = highByte;
|
||||
udpbuffer[i++] = lowByte;
|
||||
DebugIf(verbose3, _log, "[%u] Color: {%u,%u,%u}", panelCounter, color.red, color.green, color.blue );
|
||||
|
||||
DebugIf(verbose3, _log, "[%u] Color: {%u,%u,%u}", panelCounter, color.red, color.green, color.blue);
|
||||
}
|
||||
DebugIf(verbose3, _log, "UDP-Address [%s], UDP-Port [%u], udpBufferSize[%u], Bytes to send [%u]", QSTRING_CSTR(_address.toString()), _port, udpBufferSize, i);
|
||||
DebugIf(verbose3, _log, "[%s]", uint8_vector_to_hex_string(udpbuffer).c_str() );
|
||||
|
||||
retVal &= writeBytes( i , udpbuffer.data());
|
||||
DebugIf(verbose3, _log, "writeBytes(): [%d]",retVal);
|
||||
if (verbose3)
|
||||
{
|
||||
Debug(_log, "UDP-Address [%s], UDP-Port [%u], udpBufferSize[%d], Bytes to send [%d]", QSTRING_CSTR(_address.toString()), _port, udpBufferSize, i);
|
||||
Debug( _log, "packet: [%s]", QSTRING_CSTR(toHex(udpbuffer, 64)));
|
||||
}
|
||||
|
||||
retVal = writeBytes(udpbuffer);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
std::string LedDeviceNanoleaf::uint8_vector_to_hex_string(const std::vector<uint8_t>& buffer) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::hex << std::setfill('0');
|
||||
std::vector<uint8_t>::const_iterator it;
|
||||
|
||||
for (it = buffer.begin(); it != buffer.end(); ++it)
|
||||
{
|
||||
ss << " " << std::setw(2) << static_cast<unsigned>(*it);
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig Device's configuration as JSON-Object
|
||||
///
|
||||
explicit LedDeviceNanoleaf(const QJsonObject &deviceConfig);
|
||||
explicit LedDeviceNanoleaf(const QJsonObject& deviceConfig);
|
||||
|
||||
///
|
||||
/// @brief Destructor of the LED-device
|
||||
@@ -44,14 +44,16 @@ public:
|
||||
///
|
||||
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
||||
/// @return LedDevice constructed
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject& deviceConfig);
|
||||
|
||||
///
|
||||
/// @brief Discover Nanoleaf devices available (for configuration).
|
||||
///
|
||||
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
||||
///
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
QJsonObject discover() override;
|
||||
QJsonObject discover(const QJsonObject& params) override;
|
||||
|
||||
///
|
||||
/// @brief Get the Nanoleaf device's resource properties
|
||||
@@ -93,7 +95,7 @@ protected:
|
||||
/// @param[in] deviceConfig the JSON device configuration
|
||||
/// @return True, if success
|
||||
///
|
||||
bool init(const QJsonObject &deviceConfig) override;
|
||||
bool init(const QJsonObject& deviceConfig) override;
|
||||
|
||||
///
|
||||
/// @brief Opens the output device.
|
||||
@@ -108,7 +110,7 @@ protected:
|
||||
/// @param[in] ledValues The RGB-color per LED
|
||||
/// @return Zero on success, else negative
|
||||
//////
|
||||
int write(const std::vector<ColorRgb> & ledValues) override;
|
||||
int write(const std::vector<ColorRgb>& ledValues) override;
|
||||
|
||||
///
|
||||
/// @brief Power-/turn on the Nanoleaf device.
|
||||
@@ -135,7 +137,7 @@ private:
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
bool initRestAPI(const QString &hostname, int port, const QString &token );
|
||||
bool initRestAPI(const QString& hostname, int port, const QString& token);
|
||||
|
||||
///
|
||||
/// @brief Get Nanoleaf device details and configuration
|
||||
@@ -157,14 +159,7 @@ private:
|
||||
/// @param isOn True, if to switch on device
|
||||
/// @return Command to switch device on/off
|
||||
///
|
||||
QString getOnOffRequest (bool isOn ) const;
|
||||
|
||||
///
|
||||
/// @brief Convert vector to hex string
|
||||
///
|
||||
/// @param uint8_t vector
|
||||
/// @return vector as string of hex values
|
||||
std::string uint8_vector_to_hex_string( const std::vector<uint8_t>& buffer ) const;
|
||||
QString getOnOffRequest(bool isOn) const;
|
||||
|
||||
///REST-API wrapper
|
||||
ProviderRestApi* _restApi;
|
||||
@@ -175,8 +170,8 @@ private:
|
||||
|
||||
bool _topDown;
|
||||
bool _leftRight;
|
||||
uint _startPos;
|
||||
uint _endPos;
|
||||
int _startPos;
|
||||
int _endPos;
|
||||
|
||||
//Nanoleaf device details
|
||||
QString _deviceModel;
|
||||
@@ -184,11 +179,10 @@ private:
|
||||
ushort _extControlVersion;
|
||||
|
||||
/// The number of panels with LEDs
|
||||
uint _panelLedCount;
|
||||
int _panelLedCount;
|
||||
|
||||
/// Array of the panel ids.
|
||||
QVector<uint> _panelIds;
|
||||
|
||||
QVector<int> _panelIds;
|
||||
};
|
||||
|
||||
#endif // LEDEVICENANOLEAF_H
|
||||
|
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
bool verbose = false;
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
|
||||
bool verbose = false;
|
||||
|
||||
// Configuration settings
|
||||
const char CONFIG_ADDRESS[] = "output";
|
||||
//const char CONFIG_PORT[] = "port";
|
||||
@@ -97,31 +97,6 @@ const int STREAM_SSL_HANDSHAKE_ATTEMPTS = 5;
|
||||
constexpr std::chrono::milliseconds STREAM_REWRITE_TIME{20};
|
||||
const int SSL_CIPHERSUITES[2] = { MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256, 0 };
|
||||
|
||||
//Streaming message header and payload definition
|
||||
const uint8_t HEADER[] =
|
||||
{
|
||||
'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol
|
||||
0x01, 0x00, //version 1.0
|
||||
0x01, //sequence number 1
|
||||
0x00, 0x00, //Reserved write 0’s
|
||||
0x01, //xy Brightness
|
||||
0x00, // Reserved, write 0’s
|
||||
};
|
||||
|
||||
const uint8_t PAYLOAD_PER_LIGHT[] =
|
||||
{
|
||||
0x01, 0x00, 0x06, //light ID
|
||||
//color: 16 bpc
|
||||
0xff, 0xff,
|
||||
0xff, 0xff,
|
||||
0xff, 0xff,
|
||||
/*
|
||||
(message.R >> 8) & 0xff, message.R & 0xff,
|
||||
(message.G >> 8) & 0xff, message.G & 0xff,
|
||||
(message.B >> 8) & 0xff, message.B & 0xff
|
||||
*/
|
||||
};
|
||||
|
||||
} //End of constants
|
||||
|
||||
bool operator ==(const CiColor& p1, const CiColor& p2)
|
||||
@@ -301,7 +276,7 @@ bool LedDevicePhilipsHueBridge::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
|
||||
log( "DeviceType", "%s", QSTRING_CSTR( this->getActiveDeviceType() ) );
|
||||
log( "LedCount", "%u", this->getLedCount() );
|
||||
log( "LedCount", "%d", this->getLedCount() );
|
||||
log( "ColorOrder", "%s", QSTRING_CSTR( this->getColorOrder() ) );
|
||||
log( "RefreshTime", "%d", _refreshTimerInterval_ms );
|
||||
log( "LatchTime", "%d", this->getLatchTime() );
|
||||
@@ -313,7 +288,7 @@ bool LedDevicePhilipsHueBridge::init(const QJsonObject &deviceConfig)
|
||||
if ( address.isEmpty() )
|
||||
{
|
||||
this->setInError("No target hostname nor IP defined");
|
||||
return false;
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -485,7 +460,7 @@ void LedDevicePhilipsHueBridge::setBridgeConfig(const QJsonDocument &doc)
|
||||
log( "Bridge-ID", "%s", QSTRING_CSTR( deviceBridgeID ));
|
||||
log( "SoftwareVersion", "%s", QSTRING_CSTR( _deviceFirmwareVersion ));
|
||||
log( "API-Version", "%u.%u.%u", _api_major, _api_minor, _api_patch );
|
||||
log( "EntertainmentReady", "%d", _isHueEntertainmentReady );
|
||||
log( "EntertainmentReady", "%d", static_cast<int>(_isHueEntertainmentReady) );
|
||||
}
|
||||
|
||||
void LedDevicePhilipsHueBridge::setLightsMap(const QJsonDocument &doc)
|
||||
@@ -511,7 +486,7 @@ void LedDevicePhilipsHueBridge::setLightsMap(const QJsonDocument &doc)
|
||||
}
|
||||
else
|
||||
{
|
||||
log( "Lights in Bridge found", "%u", getLedCount() );
|
||||
log( "Lights in Bridge found", "%d", getLedCount() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -922,7 +897,7 @@ bool LedDevicePhilipsHue::setLights()
|
||||
|
||||
if( !lArray.empty() )
|
||||
{
|
||||
for (const auto id : lArray)
|
||||
for (const QJsonValueRef id : lArray)
|
||||
{
|
||||
unsigned int lightId = id.toString().toUInt();
|
||||
if( lightId > 0 )
|
||||
@@ -1253,7 +1228,7 @@ QByteArray LedDevicePhilipsHue::prepareStreamData() const
|
||||
{
|
||||
QByteArray msg;
|
||||
msg.reserve(static_cast<int>(sizeof(HEADER) + sizeof(PAYLOAD_PER_LIGHT) * _lights.size()));
|
||||
msg.append((const char*)HEADER, sizeof(HEADER));
|
||||
msg.append(reinterpret_cast<const char*>(HEADER), sizeof(HEADER));
|
||||
|
||||
for (const PhilipsHueLight& light : _lights)
|
||||
{
|
||||
@@ -1268,7 +1243,7 @@ QByteArray LedDevicePhilipsHue::prepareStreamData() const
|
||||
static_cast<uint8_t>((G >> 8) & 0xff), static_cast<uint8_t>(G & 0xff),
|
||||
static_cast<uint8_t>((B >> 8) & 0xff), static_cast<uint8_t>(B & 0xff)
|
||||
};
|
||||
msg.append((char*)payload, sizeof(payload));
|
||||
msg.append(reinterpret_cast<const char *>(payload), sizeof(payload));
|
||||
}
|
||||
|
||||
return msg;
|
||||
@@ -1298,17 +1273,17 @@ int LedDevicePhilipsHue::close()
|
||||
}
|
||||
|
||||
bool LedDevicePhilipsHue::switchOn()
|
||||
{
|
||||
{
|
||||
Debug(_log, "");
|
||||
|
||||
bool rc = false;
|
||||
|
||||
if ( _isOn )
|
||||
{
|
||||
{
|
||||
rc = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _isEnabled && _isDeviceInitialised )
|
||||
{
|
||||
storeState();
|
||||
@@ -1319,15 +1294,15 @@ bool LedDevicePhilipsHue::switchOn()
|
||||
{
|
||||
_isOn = true;
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( powerOn() )
|
||||
{
|
||||
{
|
||||
_isOn = true;
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1388,7 +1363,7 @@ void LedDevicePhilipsHue::stopBlackTimeoutTimer()
|
||||
|
||||
bool LedDevicePhilipsHue::noSignalDetection()
|
||||
{
|
||||
if( _allLightsBlack )
|
||||
if( _allLightsBlack && _switchOffOnBlack)
|
||||
{
|
||||
if( !_stopConnection && _isInitLeds )
|
||||
{
|
||||
@@ -1614,7 +1589,7 @@ bool LedDevicePhilipsHue::restoreState()
|
||||
return rc;
|
||||
}
|
||||
|
||||
QJsonObject LedDevicePhilipsHue::discover()
|
||||
QJsonObject LedDevicePhilipsHue::discover(const QJsonObject& /*params*/)
|
||||
{
|
||||
QJsonObject devicesDiscovered;
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
||||
|
@@ -17,6 +17,31 @@
|
||||
#include "ProviderRestApi.h"
|
||||
#include "ProviderUdpSSL.h"
|
||||
|
||||
//Streaming message header and payload definition
|
||||
const uint8_t HEADER[] =
|
||||
{
|
||||
'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol
|
||||
0x01, 0x00, //version 1.0
|
||||
0x01, //sequence number 1
|
||||
0x00, 0x00, //Reserved write 0’s
|
||||
0x01, //xy Brightness
|
||||
0x00, // Reserved, write 0’s
|
||||
};
|
||||
|
||||
const uint8_t PAYLOAD_PER_LIGHT[] =
|
||||
{
|
||||
0x01, 0x00, 0x06, //light ID
|
||||
//color: 16 bpc
|
||||
0xff, 0xff,
|
||||
0xff, 0xff,
|
||||
0xff, 0xff,
|
||||
/*
|
||||
(message.R >> 8) & 0xff, message.R & 0xff,
|
||||
(message.G >> 8) & 0xff, message.G & 0xff,
|
||||
(message.B >> 8) & 0xff, message.B & 0xff
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* A XY color point in the color space of the hue system without brightness.
|
||||
*/
|
||||
@@ -326,7 +351,7 @@ public:
|
||||
///
|
||||
/// @brief Destructor of the LED-device
|
||||
///
|
||||
~LedDevicePhilipsHue();
|
||||
~LedDevicePhilipsHue() override;
|
||||
|
||||
///
|
||||
/// @brief Constructs the LED-device
|
||||
@@ -339,9 +364,11 @@ public:
|
||||
/// @brief Discover devices of this type available (for configuration).
|
||||
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
||||
///
|
||||
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
||||
///
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
QJsonObject discover() override;
|
||||
QJsonObject discover(const QJsonObject& params) override;
|
||||
|
||||
///
|
||||
/// @brief Get the Hue Bridge device's resource properties
|
||||
|
@@ -17,7 +17,7 @@ const quint16 STREAM_DEFAULT_PORT = 19446;
|
||||
const int API_DEFAULT_PORT = -1; //Use default port per communication scheme
|
||||
|
||||
const char API_BASE_PATH[] = "/json/";
|
||||
const char API_PATH_INFO[] = "info";
|
||||
//const char API_PATH_INFO[] = "info";
|
||||
const char API_PATH_STATE[] = "state";
|
||||
|
||||
// List of State Information
|
||||
@@ -60,9 +60,9 @@ bool LedDeviceWled::init(const QJsonObject &deviceConfig)
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
{
|
||||
// Initialise LedDevice configuration and execution environment
|
||||
uint configuredLedCount = this->getLedCount();
|
||||
int configuredLedCount = this->getLedCount();
|
||||
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
||||
Debug(_log, "LedCount : %u", configuredLedCount);
|
||||
Debug(_log, "LedCount : %d", configuredLedCount);
|
||||
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||
|
||||
@@ -166,7 +166,7 @@ bool LedDeviceWled::powerOff()
|
||||
return off;
|
||||
}
|
||||
|
||||
QJsonObject LedDeviceWled::discover()
|
||||
QJsonObject LedDeviceWled::discover(const QJsonObject& /*params*/)
|
||||
{
|
||||
QJsonObject devicesDiscovered;
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
||||
|
@@ -37,9 +37,11 @@ public:
|
||||
///
|
||||
/// @brief Discover WLED devices available (for configuration).
|
||||
///
|
||||
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
||||
///
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
QJsonObject discover() override;
|
||||
QJsonObject discover(const QJsonObject& params) override;
|
||||
|
||||
///
|
||||
/// @brief Get the WLED device's resource properties
|
||||
|
@@ -247,7 +247,7 @@ int YeelightLight::writeCommand( const QJsonDocument &command, QJsonArray &resul
|
||||
if ( elapsedTime < _waitTimeQuota )
|
||||
{
|
||||
int waitTime = _waitTimeQuota;
|
||||
log ( 1, "writeCommand():", "Wait %dms, elapsedTime: %dms < quotaTime: %dms", waitTime, elapsedTime, _waitTimeQuota);
|
||||
log ( 1, "writeCommand():", "Wait %dms, elapsedTime: %dms < quotaTime: %dms", waitTime, static_cast<int>(elapsedTime), _waitTimeQuota);
|
||||
|
||||
// Wait time (in ms) before doing next write to not overrun Yeelight command quota
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(_waitTimeQuota));
|
||||
@@ -452,7 +452,7 @@ YeelightResponse YeelightLight::handleResponse(int correlationID, QByteArray con
|
||||
// Debug output
|
||||
if(!yeeResponse.getResult().empty())
|
||||
{
|
||||
for(const auto item : yeeResponse.getResult())
|
||||
for(const QJsonValueRef item : yeeResponse.getResult())
|
||||
{
|
||||
log ( 3, "Result:", "%s", QSTRING_CSTR( item.toString() ));
|
||||
}
|
||||
@@ -524,7 +524,7 @@ QJsonObject YeelightLight::getProperties()
|
||||
if( !result.empty())
|
||||
{
|
||||
int i = 0;
|
||||
for(const auto item : result)
|
||||
for(const QJsonValueRef item : result)
|
||||
{
|
||||
log (1,"Property:", "%s = %s", QSTRING_CSTR( propertyList.at(i).toString() ), QSTRING_CSTR( item.toString() ));
|
||||
properties.insert( propertyList.at(i).toString(), item );
|
||||
@@ -1008,7 +1008,7 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
{
|
||||
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
||||
Debug(_log, "LedCount : %u", this->getLedCount());
|
||||
Debug(_log, "LedCount : %d", this->getLedCount());
|
||||
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
||||
Debug(_log, "RewriteTime : %d", this->getRewriteTime());
|
||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||
@@ -1073,8 +1073,8 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
||||
Debug(_log, "Debuglevel : %d", _debuglevel);
|
||||
|
||||
QJsonArray configuredYeelightLights = _devConfig[CONFIG_LIGHTS].toArray();
|
||||
uint configuredYeelightsCount = 0;
|
||||
for (const QJsonValue light : configuredYeelightLights)
|
||||
int configuredYeelightsCount = 0;
|
||||
for (const QJsonValueRef light : configuredYeelightLights)
|
||||
{
|
||||
QString host = light.toObject().value("host").toString();
|
||||
int port = light.toObject().value("port").toInt(API_DEFAULT_PORT);
|
||||
@@ -1085,9 +1085,9 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
||||
++configuredYeelightsCount;
|
||||
}
|
||||
}
|
||||
Debug(_log, "Light configured : %u", configuredYeelightsCount );
|
||||
Debug(_log, "Light configured : %d", configuredYeelightsCount );
|
||||
|
||||
uint configuredLedCount = this->getLedCount();
|
||||
int configuredLedCount = this->getLedCount();
|
||||
if (configuredYeelightsCount < configuredLedCount )
|
||||
{
|
||||
QString errorReason = QString("Not enough Yeelights [%1] for configured LEDs [%2] found!")
|
||||
@@ -1101,7 +1101,7 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
|
||||
|
||||
if ( configuredYeelightsCount > configuredLedCount )
|
||||
{
|
||||
Warning(_log, "More Yeelights defined [%u] than configured LEDs [%u].", configuredYeelightsCount, configuredLedCount );
|
||||
Warning(_log, "More Yeelights defined [%d] than configured LEDs [%d].", configuredYeelightsCount, configuredLedCount );
|
||||
}
|
||||
|
||||
_lightsAddressList.clear();
|
||||
@@ -1347,7 +1347,7 @@ bool LedDeviceYeelight::restoreState()
|
||||
return rc;
|
||||
}
|
||||
|
||||
QJsonObject LedDeviceYeelight::discover()
|
||||
QJsonObject LedDeviceYeelight::discover(const QJsonObject& /*params*/)
|
||||
{
|
||||
QJsonObject devicesDiscovered;
|
||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
||||
|
@@ -435,12 +435,11 @@ public:
|
||||
///
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// @brief Discover Yeelight devices available (for configuration).
|
||||
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
||||
///
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
QJsonObject discover() override;
|
||||
QJsonObject discover(const QJsonObject& params) override;
|
||||
|
||||
///
|
||||
/// @brief Get a Yeelight device's resource properties
|
||||
|
@@ -1,4 +1,3 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
@@ -16,9 +15,9 @@
|
||||
|
||||
const ushort MAX_PORT = 65535;
|
||||
|
||||
ProviderUdp::ProviderUdp(const QJsonObject &deviceConfig)
|
||||
ProviderUdp::ProviderUdp(const QJsonObject& deviceConfig)
|
||||
: LedDevice(deviceConfig)
|
||||
, _udpSocket (nullptr)
|
||||
, _udpSocket(nullptr)
|
||||
, _port(1)
|
||||
, _defaultHost("127.0.0.1")
|
||||
{
|
||||
@@ -30,48 +29,48 @@ ProviderUdp::~ProviderUdp()
|
||||
delete _udpSocket;
|
||||
}
|
||||
|
||||
bool ProviderUdp::init(const QJsonObject &deviceConfig)
|
||||
bool ProviderUdp::init(const QJsonObject& deviceConfig)
|
||||
{
|
||||
bool isInitOK = false;
|
||||
|
||||
// Initialise sub-class
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
if (LedDevice::init(deviceConfig))
|
||||
{
|
||||
QString host = deviceConfig["host"].toString(_defaultHost);
|
||||
|
||||
if (_address.setAddress(host) )
|
||||
if (_address.setAddress(host))
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an IP-address.", QSTRING_CSTR(_address.toString()));
|
||||
Debug(_log, "Successfully parsed %s as an IP-address.", QSTRING_CSTR(_address.toString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QHostInfo hostInfo = QHostInfo::fromName(host);
|
||||
if ( hostInfo.error() == QHostInfo::NoError )
|
||||
if (hostInfo.error() == QHostInfo::NoError)
|
||||
{
|
||||
_address = hostInfo.addresses().first();
|
||||
Debug( _log, "Successfully resolved IP-address (%s) for hostname (%s).", QSTRING_CSTR(_address.toString()), QSTRING_CSTR(host));
|
||||
Debug(_log, "Successfully resolved IP-address (%s) for hostname (%s).", QSTRING_CSTR(_address.toString()), QSTRING_CSTR(host));
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errortext = QString ("Failed resolving IP-address for [%1], (%2) %3").arg(host).arg(hostInfo.error()).arg(hostInfo.errorString());
|
||||
this->setInError ( errortext );
|
||||
QString errortext = QString("Failed resolving IP-address for [%1], (%2) %3").arg(host).arg(hostInfo.error()).arg(hostInfo.errorString());
|
||||
this->setInError(errortext);
|
||||
isInitOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !_isDeviceInError )
|
||||
if (!_isDeviceInError)
|
||||
{
|
||||
int config_port = deviceConfig["port"].toInt(_port);
|
||||
if ( config_port <= 0 || config_port > MAX_PORT )
|
||||
if (config_port <= 0 || config_port > MAX_PORT)
|
||||
{
|
||||
QString errortext = QString ("Invalid target port [%1]!").arg(config_port);
|
||||
this->setInError ( errortext );
|
||||
QString errortext = QString("Invalid target port [%1]!").arg(config_port);
|
||||
this->setInError(errortext);
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_port = static_cast<int>(config_port);
|
||||
Debug( _log, "UDP socket will write to %s:%u", QSTRING_CSTR(_address.toString()) , _port );
|
||||
_port = static_cast<quint16>(config_port);
|
||||
Debug(_log, "UDP socket will write to %s:%u", QSTRING_CSTR(_address.toString()), _port);
|
||||
|
||||
_udpSocket = new QUdpSocket(this);
|
||||
|
||||
@@ -88,16 +87,16 @@ int ProviderUdp::open()
|
||||
_isDeviceReady = false;
|
||||
|
||||
// Try to bind the UDP-Socket
|
||||
if ( _udpSocket != nullptr )
|
||||
if (_udpSocket != nullptr)
|
||||
{
|
||||
if ( _udpSocket->state() != QAbstractSocket::BoundState )
|
||||
if (_udpSocket->state() != QAbstractSocket::BoundState)
|
||||
{
|
||||
QHostAddress localAddress = QHostAddress::Any;
|
||||
quint16 localPort = 0;
|
||||
if ( !_udpSocket->bind(localAddress, localPort) )
|
||||
if (!_udpSocket->bind(localAddress, localPort))
|
||||
{
|
||||
QString warntext = QString ("Could not bind local address: %1, (%2) %3").arg(localAddress.toString()).arg(_udpSocket->error()).arg(_udpSocket->errorString());
|
||||
Warning ( _log, "%s", QSTRING_CSTR(warntext));
|
||||
QString warntext = QString("Could not bind local address: %1, (%2) %3").arg(localAddress.toString()).arg(_udpSocket->error()).arg(_udpSocket->errorString());
|
||||
Warning(_log, "%s", QSTRING_CSTR(warntext));
|
||||
}
|
||||
}
|
||||
// Everything is OK, device is ready
|
||||
@@ -106,7 +105,7 @@ int ProviderUdp::open()
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setInError( " Open error. UDP Socket not initialised!" );
|
||||
this->setInError(" Open error. UDP Socket not initialised!");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -116,12 +115,12 @@ int ProviderUdp::close()
|
||||
int retval = 0;
|
||||
_isDeviceReady = false;
|
||||
|
||||
if ( _udpSocket != nullptr )
|
||||
if (_udpSocket != nullptr)
|
||||
{
|
||||
// Test, if device requires closing
|
||||
if ( _udpSocket->isOpen() )
|
||||
if (_udpSocket->isOpen())
|
||||
{
|
||||
Debug(_log,"Close UDP-device: %s", QSTRING_CSTR( this->getActiveDeviceType() ) );
|
||||
Debug(_log, "Close UDP-device: %s", QSTRING_CSTR(this->getActiveDeviceType()));
|
||||
_udpSocket->close();
|
||||
// Everything is OK -> device is closed
|
||||
}
|
||||
@@ -129,22 +128,28 @@ int ProviderUdp::close()
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
int ProviderUdp::writeBytes(const unsigned size, const uint8_t* data)
|
||||
{
|
||||
qint64 retVal = _udpSocket->writeDatagram((const char *)data,size,_address,_port);
|
||||
int rc = 0;
|
||||
qint64 bytesWritten = _udpSocket->writeDatagram(reinterpret_cast<const char*>(data), size, _address, _port);
|
||||
|
||||
WarningIf((retVal<0), _log, "&s", QSTRING_CSTR(QString
|
||||
("(%1:%2) Write Error: (%3) %4").arg(_address.toString()).arg(_port).arg(_udpSocket->error()).arg(_udpSocket->errorString())));
|
||||
|
||||
return retVal;
|
||||
if (bytesWritten == -1 || bytesWritten != size)
|
||||
{
|
||||
Warning(_log, "%s", QSTRING_CSTR(QString("(%1:%2) Write Error: (%3) %4").arg(_address.toString()).arg(_port).arg(_udpSocket->error()).arg(_udpSocket->errorString())));
|
||||
rc = -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ProviderUdp::writeBytes(const QByteArray &bytes)
|
||||
int ProviderUdp::writeBytes(const QByteArray& bytes)
|
||||
{
|
||||
qint64 retVal = _udpSocket->writeDatagram(bytes,_address,_port);
|
||||
int rc = 0;
|
||||
qint64 bytesWritten = _udpSocket->writeDatagram(bytes, _address, _port);
|
||||
|
||||
WarningIf((retVal<0), _log, "&s", QSTRING_CSTR(QString
|
||||
("(%1:%2) Write Error: (%3) %4").arg(_address.toString()).arg(_port).arg(_udpSocket->error()).arg(_udpSocket->errorString())));
|
||||
|
||||
return retVal;
|
||||
if (bytesWritten == -1 || bytesWritten != bytes.size())
|
||||
{
|
||||
Warning(_log, "%s", QSTRING_CSTR(QString("(%1:%2) Write Error: (%3) %4").arg(_address.toString()).arg(_port).arg(_udpSocket->error()).arg(_udpSocket->errorString())));
|
||||
rc = -1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
///
|
||||
/// @brief Constructs an UDP LED-device
|
||||
///
|
||||
ProviderUdp(const QJsonObject &deviceConfig);
|
||||
ProviderUdp(const QJsonObject& deviceConfig);
|
||||
|
||||
///
|
||||
/// @brief Destructor of the UDP LED-device
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
/// @param[in] deviceConfig the JSON device configuration
|
||||
/// @return True, if success
|
||||
///
|
||||
bool init(const QJsonObject &deviceConfig) override;
|
||||
bool init(const QJsonObject& deviceConfig) override;
|
||||
|
||||
///
|
||||
/// @brief Opens the output device.
|
||||
@@ -62,7 +62,7 @@ protected:
|
||||
///
|
||||
/// @return Zero on success, else negative
|
||||
///
|
||||
int writeBytes(const unsigned size, const uint8_t *data);
|
||||
int writeBytes(const unsigned size, const uint8_t* data);
|
||||
|
||||
///
|
||||
/// @brief Writes the given bytes to the UDP-device
|
||||
@@ -71,10 +71,10 @@ protected:
|
||||
///
|
||||
/// @return Zero on success, else negative
|
||||
///
|
||||
int writeBytes(const QByteArray &bytes);
|
||||
int writeBytes(const QByteArray& bytes);
|
||||
|
||||
///
|
||||
QUdpSocket * _udpSocket;
|
||||
QUdpSocket* _udpSocket;
|
||||
QHostAddress _address;
|
||||
quint16 _port;
|
||||
QString _defaultHost;
|
||||
|
Reference in New Issue
Block a user