2013-08-17 19:20:19 +02:00
|
|
|
// system includes
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <cassert>
|
2016-05-30 22:39:12 +02:00
|
|
|
#include <iomanip>
|
2013-08-17 19:20:19 +02:00
|
|
|
|
2013-08-17 15:39:29 +02:00
|
|
|
// stl includes
|
|
|
|
#include <iostream>
|
2013-08-17 19:20:19 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <iterator>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QResource>
|
2013-08-19 20:33:36 +02:00
|
|
|
#include <QDateTime>
|
2014-10-25 22:35:53 +02:00
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QHostInfo>
|
2016-08-06 08:28:42 +02:00
|
|
|
#include <QString>
|
2016-08-15 22:32:01 +02:00
|
|
|
#include <QFile>
|
2013-08-17 15:39:29 +02:00
|
|
|
|
2013-08-18 12:21:07 +02:00
|
|
|
// hyperion util includes
|
2013-11-22 11:48:10 +01:00
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
|
|
|
#include <hyperion/ImageProcessor.h>
|
2016-02-15 20:53:03 +01:00
|
|
|
#include <hyperion/MessageForwarder.h>
|
2013-11-22 11:48:10 +01:00
|
|
|
#include <hyperion/ColorTransform.h>
|
2016-03-13 11:59:36 +01:00
|
|
|
#include <hyperion/ColorCorrection.h>
|
2016-04-02 00:04:11 +02:00
|
|
|
#include <hyperion/ColorAdjustment.h>
|
2013-11-22 11:48:10 +01:00
|
|
|
#include <utils/ColorRgb.h>
|
2016-08-23 20:07:12 +02:00
|
|
|
#include <leddevice/LedDevice.h>
|
2016-06-10 18:32:50 +02:00
|
|
|
#include <HyperionConfig.h>
|
2016-08-14 20:17:12 +02:00
|
|
|
#include <utils/jsonschema/JsonFactory.h>
|
2013-08-18 12:21:07 +02:00
|
|
|
|
2013-08-17 19:20:19 +02:00
|
|
|
// project includes
|
2013-08-17 15:39:29 +02:00
|
|
|
#include "JsonClientConnection.h"
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
using namespace hyperion;
|
|
|
|
|
2016-07-31 22:21:35 +02:00
|
|
|
JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
|
|
|
|
: QObject()
|
|
|
|
, _socket(socket)
|
|
|
|
, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor())
|
|
|
|
, _hyperion(Hyperion::getInstance())
|
|
|
|
, _receiveBuffer()
|
|
|
|
, _webSocketHandshakeDone(false)
|
|
|
|
, _log(Logger::getInstance("JSONCLIENTCONNECTION"))
|
2016-08-11 07:13:55 +02:00
|
|
|
, _forwarder_enabled(true)
|
2013-08-17 15:39:29 +02:00
|
|
|
{
|
2013-08-17 19:20:19 +02:00
|
|
|
// connect internal signals and slots
|
2013-08-17 15:39:29 +02:00
|
|
|
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
|
|
|
|
connect(_socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
2016-09-07 20:10:37 +02:00
|
|
|
connect(_hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool)));
|
|
|
|
|
|
|
|
_timer_ledcolors.setSingleShot(false);
|
|
|
|
connect(&_timer_ledcolors, SIGNAL(timeout()), this, SLOT(streamLedcolorsUpdate()));
|
2013-08-17 15:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JsonClientConnection::~JsonClientConnection()
|
|
|
|
{
|
|
|
|
delete _socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonClientConnection::readData()
|
|
|
|
{
|
|
|
|
_receiveBuffer += _socket->readAll();
|
2014-10-25 22:35:53 +02:00
|
|
|
|
2014-11-08 21:01:46 +01:00
|
|
|
if (_webSocketHandshakeDone)
|
|
|
|
{
|
|
|
|
// websocket mode, data frame
|
|
|
|
handleWebSocketFrame();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// might be a handshake request or raw socket data
|
|
|
|
if(_receiveBuffer.contains("Upgrade: websocket"))
|
|
|
|
{
|
|
|
|
doWebSocketHandshake();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// raw socket data, handling as usual
|
2014-10-25 22:35:53 +02:00
|
|
|
int bytes = _receiveBuffer.indexOf('\n') + 1;
|
|
|
|
while(bytes > 0)
|
|
|
|
{
|
|
|
|
// create message string
|
|
|
|
std::string message(_receiveBuffer.data(), bytes);
|
|
|
|
|
|
|
|
// remove message data from buffer
|
|
|
|
_receiveBuffer = _receiveBuffer.mid(bytes);
|
|
|
|
|
|
|
|
// handle message
|
|
|
|
handleMessage(message);
|
|
|
|
|
|
|
|
// try too look up '\n' again
|
|
|
|
bytes = _receiveBuffer.indexOf('\n') + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-17 15:39:29 +02:00
|
|
|
}
|
|
|
|
|
2014-11-08 21:01:46 +01:00
|
|
|
void JsonClientConnection::handleWebSocketFrame()
|
|
|
|
{
|
|
|
|
if ((_receiveBuffer.at(0) & 0x80) == 0x80)
|
|
|
|
{
|
|
|
|
// final bit found, frame complete
|
|
|
|
quint8 * maskKey = NULL;
|
|
|
|
quint8 opCode = _receiveBuffer.at(0) & 0x0F;
|
|
|
|
bool isMasked = (_receiveBuffer.at(1) & 0x80) == 0x80;
|
|
|
|
quint64 payloadLength = _receiveBuffer.at(1) & 0x7F;
|
|
|
|
quint32 index = 2;
|
|
|
|
|
|
|
|
switch (payloadLength)
|
|
|
|
{
|
|
|
|
case 126:
|
|
|
|
payloadLength = ((_receiveBuffer.at(2) << 8) & 0xFF00) | (_receiveBuffer.at(3) & 0xFF);
|
|
|
|
index += 2;
|
|
|
|
break;
|
|
|
|
case 127:
|
|
|
|
payloadLength = 0;
|
|
|
|
for (uint i=0; i < 8; i++) {
|
|
|
|
payloadLength |= ((quint64)(_receiveBuffer.at(index+i) & 0xFF)) << (8*(7-i));
|
|
|
|
}
|
|
|
|
index += 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMasked)
|
|
|
|
{
|
|
|
|
// if the data is masked we need to get the key for unmasking
|
|
|
|
maskKey = new quint8[4];
|
|
|
|
for (uint i=0; i < 4; i++)
|
|
|
|
{
|
|
|
|
maskKey[i] = _receiveBuffer.at(index + i);
|
|
|
|
}
|
|
|
|
index += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the type of data frame
|
|
|
|
switch (opCode)
|
|
|
|
{
|
|
|
|
case 0x01:
|
|
|
|
{
|
|
|
|
// frame contains text, extract it
|
|
|
|
QByteArray result = _receiveBuffer.mid(index, payloadLength);
|
|
|
|
_receiveBuffer.clear();
|
|
|
|
|
|
|
|
// unmask data if necessary
|
|
|
|
if (isMasked)
|
|
|
|
{
|
|
|
|
for (uint i=0; i < payloadLength; i++)
|
|
|
|
{
|
|
|
|
result[i] = (result[i] ^ maskKey[i % 4]);
|
|
|
|
}
|
|
|
|
if (maskKey != NULL)
|
|
|
|
{
|
|
|
|
delete[] maskKey;
|
|
|
|
maskKey = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMessage(QString(result).toStdString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x08:
|
|
|
|
{
|
|
|
|
// close request, confirm
|
|
|
|
quint8 close[] = {0x88, 0};
|
|
|
|
_socket->write((const char*)close, 2);
|
|
|
|
_socket->flush();
|
|
|
|
_socket->close();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x09:
|
|
|
|
{
|
|
|
|
// ping received, send pong
|
|
|
|
quint8 pong[] = {0x0A, 0};
|
|
|
|
_socket->write((const char*)pong, 2);
|
|
|
|
_socket->flush();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Error(_log, "Someone is sending very big messages over several frames... it's not supported yet");
|
2014-11-08 21:01:46 +01:00
|
|
|
quint8 close[] = {0x88, 0};
|
|
|
|
_socket->write((const char*)close, 2);
|
|
|
|
_socket->flush();
|
|
|
|
_socket->close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonClientConnection::doWebSocketHandshake()
|
|
|
|
{
|
|
|
|
// http header, might not be a very reliable check...
|
2016-07-11 17:08:22 +02:00
|
|
|
Debug(_log, "Websocket handshake");
|
2014-11-08 21:01:46 +01:00
|
|
|
|
|
|
|
// get the key to prepare an answer
|
|
|
|
int start = _receiveBuffer.indexOf("Sec-WebSocket-Key") + 19;
|
|
|
|
std::string value(_receiveBuffer.mid(start, _receiveBuffer.indexOf("\r\n", start) - start).data());
|
|
|
|
_receiveBuffer.clear();
|
|
|
|
|
|
|
|
// must be always appended
|
|
|
|
value += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
|
|
|
|
|
|
// generate sha1 hash
|
|
|
|
QByteArray hash = QCryptographicHash::hash(value.c_str(), QCryptographicHash::Sha1);
|
|
|
|
|
|
|
|
// prepare an answer
|
|
|
|
std::ostringstream h;
|
|
|
|
h << "HTTP/1.1 101 Switching Protocols\r\n" <<
|
|
|
|
"Upgrade: websocket\r\n" <<
|
|
|
|
"Connection: Upgrade\r\n" <<
|
|
|
|
"Sec-WebSocket-Accept: " << QString(hash.toBase64()).toStdString() << "\r\n\r\n";
|
|
|
|
|
|
|
|
_socket->write(h.str().c_str());
|
|
|
|
_socket->flush();
|
|
|
|
// we are in WebSocket mode, data frames should follow next
|
|
|
|
_webSocketHandshakeDone = true;
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:39:29 +02:00
|
|
|
void JsonClientConnection::socketClosed()
|
|
|
|
{
|
2014-10-25 22:35:53 +02:00
|
|
|
_webSocketHandshakeDone = false;
|
2013-08-17 15:39:29 +02:00
|
|
|
emit connectionClosed(this);
|
|
|
|
}
|
|
|
|
|
2013-08-18 12:02:17 +02:00
|
|
|
void JsonClientConnection::handleMessage(const std::string &messageString)
|
2013-08-17 15:39:29 +02:00
|
|
|
{
|
|
|
|
Json::Reader reader;
|
2013-08-18 12:02:17 +02:00
|
|
|
Json::Value message;
|
|
|
|
std::string errors;
|
2016-08-10 19:53:53 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!reader.parse(messageString, message, false))
|
|
|
|
{
|
|
|
|
sendErrorReply("Error while parsing json: " + reader.getFormattedErrorMessages());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check basic message
|
|
|
|
if (!checkJson(message, ":schema", errors))
|
|
|
|
{
|
|
|
|
sendErrorReply("Error while validating json: " + errors);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check specific message
|
|
|
|
const std::string command = message["command"].asString();
|
|
|
|
if (!checkJson(message, QString(":schema-%1").arg(QString::fromStdString(command)), errors))
|
|
|
|
{
|
|
|
|
sendErrorReply("Error while validating json: " + errors);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
int tan = message.get("tan",0).asInt();
|
2016-08-10 19:53:53 +02:00
|
|
|
// switch over all possible commands and handle them
|
|
|
|
if (command == "color")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleColorCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "image")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleImageCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "effect")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleEffectCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "serverinfo")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleServerInfoCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "clear")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleClearCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "clearall")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleClearallCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "transform")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleTransformCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "temperature")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleTemperatureCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "adjustment")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleAdjustmentCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "sourceselect")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleSourceSelectCommand(message, command, tan);
|
2016-08-15 22:32:01 +02:00
|
|
|
else if (command == "config")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleConfigCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else if (command == "componentstate")
|
2016-08-17 11:46:36 +02:00
|
|
|
handleComponentStateCommand(message, command, tan);
|
2016-09-05 17:26:29 +02:00
|
|
|
else if (command == "ledcolors")
|
|
|
|
handleLedColorsCommand(message, command, tan);
|
2016-08-10 19:53:53 +02:00
|
|
|
else
|
|
|
|
handleNotImplemented();
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
sendErrorReply("Error while processing incoming json message: " + std::string(e.what()) + " " + errors );
|
|
|
|
Warning(_log, "Error while processing incoming json message: %s (%s)", e.what(), errors.c_str());
|
|
|
|
}
|
2013-08-18 12:02:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
void JsonClientConnection::componentStateChanged(const hyperion::Components component, bool enable)
|
|
|
|
{
|
|
|
|
if (component == COMP_FORWARDER && _forwarder_enabled != enable)
|
|
|
|
{
|
|
|
|
_forwarder_enabled = enable;
|
|
|
|
Info(_log, "forwarder change state to %s", (enable ? "enabled" : "disabled") );
|
|
|
|
}
|
|
|
|
}
|
2016-02-15 18:25:18 +01:00
|
|
|
|
|
|
|
void JsonClientConnection::forwardJsonMessage(const Json::Value & message)
|
|
|
|
{
|
2016-08-11 07:13:55 +02:00
|
|
|
if (_forwarder_enabled)
|
2016-02-15 18:25:18 +01:00
|
|
|
{
|
2016-08-11 07:13:55 +02:00
|
|
|
QTcpSocket client;
|
|
|
|
QList<MessageForwarder::JsonSlaveAddress> list = _hyperion->getForwarder()->getJsonSlaves();
|
|
|
|
|
|
|
|
for ( int i=0; i<list.size(); i++ )
|
2016-02-15 20:53:03 +01:00
|
|
|
{
|
2016-08-11 07:13:55 +02:00
|
|
|
client.connectToHost(list.at(i).addr, list.at(i).port);
|
|
|
|
if ( client.waitForConnected(500) )
|
|
|
|
{
|
|
|
|
sendMessage(message,&client);
|
|
|
|
client.close();
|
|
|
|
}
|
2016-02-15 20:53:03 +01:00
|
|
|
}
|
2016-02-15 18:25:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleColorCommand(const Json::Value &message, const std::string &command, const int tan)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
2016-02-15 18:25:18 +01:00
|
|
|
forwardJsonMessage(message);
|
|
|
|
|
2013-08-18 12:21:07 +02:00
|
|
|
// extract parameters
|
|
|
|
int priority = message["priority"].asInt();
|
|
|
|
int duration = message.get("duration", -1).asInt();
|
2013-12-12 23:39:17 +01:00
|
|
|
|
|
|
|
std::vector<ColorRgb> colorData(_hyperion->getLedCount());
|
|
|
|
const Json::Value & jsonColor = message["color"];
|
|
|
|
Json::UInt i = 0;
|
|
|
|
for (; i < jsonColor.size()/3 && i < _hyperion->getLedCount(); ++i)
|
|
|
|
{
|
|
|
|
colorData[i].red = uint8_t(message["color"][3u*i].asInt());
|
|
|
|
colorData[i].green = uint8_t(message["color"][3u*i+1u].asInt());
|
|
|
|
colorData[i].blue = uint8_t(message["color"][3u*i+2u].asInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy full blocks of led colors
|
|
|
|
unsigned size = i;
|
|
|
|
while (i + size < _hyperion->getLedCount())
|
|
|
|
{
|
|
|
|
memcpy(&(colorData[i]), colorData.data(), size * sizeof(ColorRgb));
|
|
|
|
i += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy remaining block of led colors
|
|
|
|
if (i < _hyperion->getLedCount())
|
|
|
|
{
|
|
|
|
memcpy(&(colorData[i]), colorData.data(), (_hyperion->getLedCount()-i) * sizeof(ColorRgb));
|
|
|
|
}
|
2013-08-18 12:21:07 +02:00
|
|
|
|
|
|
|
// set output
|
2013-12-12 23:39:17 +01:00
|
|
|
_hyperion->setColors(priority, colorData, duration);
|
2013-08-18 12:21:07 +02:00
|
|
|
|
|
|
|
// send reply
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2013-08-18 12:02:17 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleImageCommand(const Json::Value &message, const std::string &command, const int tan)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
2016-02-15 18:25:18 +01:00
|
|
|
forwardJsonMessage(message);
|
|
|
|
|
2013-08-18 20:55:59 +02:00
|
|
|
// extract parameters
|
|
|
|
int priority = message["priority"].asInt();
|
|
|
|
int duration = message.get("duration", -1).asInt();
|
|
|
|
int width = message["imagewidth"].asInt();
|
|
|
|
int height = message["imageheight"].asInt();
|
|
|
|
QByteArray data = QByteArray::fromBase64(QByteArray(message["imagedata"].asCString()));
|
|
|
|
|
|
|
|
// check consistency of the size of the received data
|
|
|
|
if (data.size() != width*height*3)
|
|
|
|
{
|
2016-08-17 11:46:36 +02:00
|
|
|
sendErrorReply("Size of image data does not match with the width and height", command, tan);
|
2013-08-18 20:55:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set width and height of the image processor
|
|
|
|
_imageProcessor->setSize(width, height);
|
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
// create ImageRgb
|
|
|
|
Image<ColorRgb> image(width, height);
|
2013-08-18 20:55:59 +02:00
|
|
|
memcpy(image.memptr(), data.data(), data.size());
|
|
|
|
|
|
|
|
// process the image
|
2013-11-11 10:00:37 +01:00
|
|
|
std::vector<ColorRgb> ledColors = _imageProcessor->process(image);
|
2013-08-18 20:55:59 +02:00
|
|
|
_hyperion->setColors(priority, ledColors, duration);
|
|
|
|
|
|
|
|
// send reply
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2013-08-17 15:39:29 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleEffectCommand(const Json::Value &message, const std::string &command, const int tan)
|
2013-11-24 16:10:48 +01:00
|
|
|
{
|
2016-02-15 18:25:18 +01:00
|
|
|
forwardJsonMessage(message);
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// extract parameters
|
|
|
|
int priority = message["priority"].asInt();
|
|
|
|
int duration = message.get("duration", -1).asInt();
|
|
|
|
const Json::Value & effect = message["effect"];
|
|
|
|
const std::string & effectName = effect["name"].asString();
|
|
|
|
|
|
|
|
// set output
|
2013-12-01 14:09:01 +01:00
|
|
|
if (effect.isMember("args"))
|
|
|
|
{
|
|
|
|
_hyperion->setEffect(effectName, effect["args"], priority, duration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_hyperion->setEffect(effectName, priority, duration);
|
|
|
|
}
|
2013-11-24 16:10:48 +01:00
|
|
|
|
|
|
|
// send reply
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2013-11-24 16:10:48 +01:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const std::string &command, const int tan)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
2013-08-19 20:33:36 +02:00
|
|
|
// create result
|
|
|
|
Json::Value result;
|
|
|
|
result["success"] = true;
|
2016-08-17 11:46:36 +02:00
|
|
|
result["command"] = command;
|
|
|
|
result["tan"] = tan;
|
2013-08-19 20:33:36 +02:00
|
|
|
Json::Value & info = result["info"];
|
2014-10-25 22:35:53 +02:00
|
|
|
|
|
|
|
// add host name for remote clients
|
|
|
|
info["hostname"] = QHostInfo::localHostName().toStdString();
|
2013-08-19 20:33:36 +02:00
|
|
|
|
|
|
|
// collect priority information
|
2013-11-30 12:42:08 +01:00
|
|
|
Json::Value & priorities = info["priorities"] = Json::Value(Json::arrayValue);
|
2013-08-19 20:33:36 +02:00
|
|
|
uint64_t now = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
QList<int> activePriorities = _hyperion->getActivePriorities();
|
2016-07-27 22:52:59 +02:00
|
|
|
Hyperion::PriorityRegister priorityRegister = _hyperion->getPriorityRegister();
|
2016-07-31 22:21:35 +02:00
|
|
|
int currentPriority = _hyperion->getCurrentPriority();
|
2013-08-19 20:33:36 +02:00
|
|
|
foreach (int priority, activePriorities) {
|
|
|
|
const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority);
|
|
|
|
Json::Value & item = priorities[priorities.size()];
|
|
|
|
item["priority"] = priority;
|
|
|
|
if (priorityInfo.timeoutTime_ms != -1)
|
|
|
|
{
|
2013-11-19 23:02:41 +01:00
|
|
|
item["duration_ms"] = Json::Value::UInt(priorityInfo.timeoutTime_ms - now);
|
2013-08-19 20:33:36 +02:00
|
|
|
}
|
2016-07-16 22:51:31 +02:00
|
|
|
|
|
|
|
item["owner"] = "unknown";
|
2016-07-31 22:21:35 +02:00
|
|
|
item["active"] = true;
|
|
|
|
item["visible"] = (priority == currentPriority);
|
2016-07-27 22:52:59 +02:00
|
|
|
foreach(auto const &entry, priorityRegister)
|
2016-07-16 22:51:31 +02:00
|
|
|
{
|
|
|
|
if (entry.second == priority)
|
|
|
|
{
|
|
|
|
item["owner"] = entry.first;
|
2016-07-27 22:52:59 +02:00
|
|
|
priorityRegister.erase(entry.first);
|
2016-07-16 22:51:31 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-19 20:33:36 +02:00
|
|
|
}
|
2016-07-27 22:52:59 +02:00
|
|
|
foreach(auto const &entry, priorityRegister)
|
|
|
|
{
|
|
|
|
Json::Value & item = priorities[priorities.size()];
|
|
|
|
item["priority"] = entry.second;
|
2016-07-31 22:21:35 +02:00
|
|
|
item["active"] = false;
|
|
|
|
item["visible"] = false;
|
2016-07-27 22:52:59 +02:00
|
|
|
item["owner"] = entry.first;
|
|
|
|
}
|
2016-03-21 17:04:02 +01:00
|
|
|
|
|
|
|
// collect temperature correction information
|
|
|
|
Json::Value & temperatureArray = info["temperature"];
|
|
|
|
for (const std::string& tempId : _hyperion->getTemperatureIds())
|
|
|
|
{
|
|
|
|
const ColorCorrection * colorTemp = _hyperion->getTemperature(tempId);
|
|
|
|
if (colorTemp == nullptr)
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Error(_log, "Incorrect color temperature correction id: %s", tempId.c_str());
|
2016-03-21 17:04:02 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Json::Value & temperature = temperatureArray.append(Json::Value());
|
|
|
|
temperature["id"] = tempId;
|
|
|
|
|
|
|
|
Json::Value & tempValues = temperature["correctionValues"];
|
2016-07-04 00:43:41 +02:00
|
|
|
tempValues.append(colorTemp->_rgbCorrection.getAdjustmentR());
|
|
|
|
tempValues.append(colorTemp->_rgbCorrection.getAdjustmentG());
|
|
|
|
tempValues.append(colorTemp->_rgbCorrection.getAdjustmentB());
|
2016-03-21 17:04:02 +01:00
|
|
|
}
|
|
|
|
|
2013-08-19 20:33:36 +02:00
|
|
|
|
|
|
|
// collect transform information
|
2013-11-22 11:48:10 +01:00
|
|
|
Json::Value & transformArray = info["transform"];
|
|
|
|
for (const std::string& transformId : _hyperion->getTransformIds())
|
|
|
|
{
|
|
|
|
const ColorTransform * colorTransform = _hyperion->getTransform(transformId);
|
|
|
|
if (colorTransform == nullptr)
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Error(_log, "Incorrect color transform id: %s", transformId.c_str());
|
2013-11-22 11:48:10 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Json::Value & transform = transformArray.append(Json::Value());
|
|
|
|
transform["id"] = transformId;
|
|
|
|
|
|
|
|
transform["saturationGain"] = colorTransform->_hsvTransform.getSaturationGain();
|
|
|
|
transform["valueGain"] = colorTransform->_hsvTransform.getValueGain();
|
2016-03-13 13:05:47 +01:00
|
|
|
transform["saturationLGain"] = colorTransform->_hslTransform.getSaturationGain();
|
|
|
|
transform["luminanceGain"] = colorTransform->_hslTransform.getLuminanceGain();
|
2016-05-23 00:00:48 +02:00
|
|
|
transform["luminanceMinimum"] = colorTransform->_hslTransform.getLuminanceMinimum();
|
2013-11-22 11:48:10 +01:00
|
|
|
|
|
|
|
Json::Value & threshold = transform["threshold"];
|
|
|
|
threshold.append(colorTransform->_rgbRedTransform.getThreshold());
|
|
|
|
threshold.append(colorTransform->_rgbGreenTransform.getThreshold());
|
|
|
|
threshold.append(colorTransform->_rgbBlueTransform.getThreshold());
|
|
|
|
Json::Value & gamma = transform["gamma"];
|
|
|
|
gamma.append(colorTransform->_rgbRedTransform.getGamma());
|
|
|
|
gamma.append(colorTransform->_rgbGreenTransform.getGamma());
|
|
|
|
gamma.append(colorTransform->_rgbBlueTransform.getGamma());
|
|
|
|
Json::Value & blacklevel = transform["blacklevel"];
|
|
|
|
blacklevel.append(colorTransform->_rgbRedTransform.getBlacklevel());
|
|
|
|
blacklevel.append(colorTransform->_rgbGreenTransform.getBlacklevel());
|
|
|
|
blacklevel.append(colorTransform->_rgbBlueTransform.getBlacklevel());
|
|
|
|
Json::Value & whitelevel = transform["whitelevel"];
|
|
|
|
whitelevel.append(colorTransform->_rgbRedTransform.getWhitelevel());
|
|
|
|
whitelevel.append(colorTransform->_rgbGreenTransform.getWhitelevel());
|
|
|
|
whitelevel.append(colorTransform->_rgbBlueTransform.getWhitelevel());
|
|
|
|
}
|
2016-04-02 00:04:11 +02:00
|
|
|
|
|
|
|
// collect adjustment information
|
|
|
|
Json::Value & adjustmentArray = info["adjustment"];
|
|
|
|
for (const std::string& adjustmentId : _hyperion->getAdjustmentIds())
|
|
|
|
{
|
|
|
|
const ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
|
|
|
if (colorAdjustment == nullptr)
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Error(_log, "Incorrect color adjustment id: %s", adjustmentId.c_str());
|
2016-04-02 00:04:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Json::Value & adjustment = adjustmentArray.append(Json::Value());
|
|
|
|
adjustment["id"] = adjustmentId;
|
|
|
|
|
|
|
|
Json::Value & redAdjust = adjustment["redAdjust"];
|
2016-07-02 14:00:48 +02:00
|
|
|
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentR());
|
|
|
|
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentG());
|
|
|
|
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentB());
|
2016-04-02 00:04:11 +02:00
|
|
|
Json::Value & greenAdjust = adjustment["greenAdjust"];
|
2016-07-02 14:00:48 +02:00
|
|
|
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentR());
|
|
|
|
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentG());
|
|
|
|
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentB());
|
2016-04-02 00:04:11 +02:00
|
|
|
Json::Value & blueAdjust = adjustment["blueAdjust"];
|
2016-07-02 14:00:48 +02:00
|
|
|
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentR());
|
|
|
|
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentG());
|
|
|
|
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentB());
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
2013-08-19 20:33:36 +02:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// collect effect info
|
2013-11-30 12:42:08 +01:00
|
|
|
Json::Value & effects = info["effects"] = Json::Value(Json::arrayValue);
|
2013-12-01 14:09:01 +01:00
|
|
|
const std::list<EffectDefinition> & effectsDefinitions = _hyperion->getEffects();
|
|
|
|
for (const EffectDefinition & effectDefinition : effectsDefinitions)
|
2013-11-24 16:10:48 +01:00
|
|
|
{
|
|
|
|
Json::Value effect;
|
2013-12-01 14:09:01 +01:00
|
|
|
effect["name"] = effectDefinition.name;
|
|
|
|
effect["script"] = effectDefinition.script;
|
|
|
|
effect["args"] = effectDefinition.args;
|
2013-11-24 16:10:48 +01:00
|
|
|
|
|
|
|
effects.append(effect);
|
|
|
|
}
|
2016-04-24 17:07:31 +02:00
|
|
|
|
|
|
|
// collect active effect info
|
|
|
|
Json::Value & activeEffects = info["activeEffects"] = Json::Value(Json::arrayValue);
|
|
|
|
const std::list<ActiveEffectDefinition> & activeEffectsDefinitions = _hyperion->getActiveEffects();
|
|
|
|
for (const ActiveEffectDefinition & activeEffectDefinition : activeEffectsDefinitions)
|
|
|
|
{
|
2016-08-25 13:52:31 +02:00
|
|
|
if (activeEffectDefinition.priority != PriorityMuxer::LOWEST_PRIORITY -1)
|
|
|
|
{
|
|
|
|
Json::Value activeEffect;
|
|
|
|
activeEffect["script"] = activeEffectDefinition.script;
|
|
|
|
activeEffect["priority"] = activeEffectDefinition.priority;
|
|
|
|
activeEffect["timeout"] = activeEffectDefinition.timeout;
|
|
|
|
activeEffect["args"] = activeEffectDefinition.args;
|
|
|
|
|
|
|
|
activeEffects.append(activeEffect);
|
|
|
|
}
|
2016-04-24 17:07:31 +02:00
|
|
|
}
|
2016-05-06 15:05:28 +02:00
|
|
|
|
2016-05-30 22:39:12 +02:00
|
|
|
////////////////////////////////////
|
|
|
|
// collect active static led color//
|
|
|
|
////////////////////////////////////
|
|
|
|
|
|
|
|
// create New JSON Array Value "activeLEDColor"
|
|
|
|
Json::Value & activeLedColors = info["activeLedColor"] = Json::Value(Json::arrayValue);
|
|
|
|
// get current Priority from Hyperion Muxer
|
|
|
|
const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
|
|
|
|
// check if current Priority exist
|
|
|
|
if (priorityInfo.priority != std::numeric_limits<int>::max())
|
|
|
|
{
|
2016-05-06 15:05:28 +02:00
|
|
|
Json::Value LEDcolor;
|
2016-05-30 22:39:12 +02:00
|
|
|
// check if all LEDs has the same Color
|
|
|
|
if (std::all_of(priorityInfo.ledColors.begin(), priorityInfo.ledColors.end(), [&](ColorRgb color)
|
|
|
|
{
|
|
|
|
return ((color.red == priorityInfo.ledColors.begin()->red) &&
|
|
|
|
(color.green == priorityInfo.ledColors.begin()->green) &&
|
|
|
|
(color.blue == priorityInfo.ledColors.begin()->blue));
|
|
|
|
} ))
|
|
|
|
{
|
|
|
|
// check if LED Color not Black (0,0,0)
|
2016-07-12 23:33:30 +02:00
|
|
|
if ((priorityInfo.ledColors.begin()->red +
|
|
|
|
priorityInfo.ledColors.begin()->green +
|
|
|
|
priorityInfo.ledColors.begin()->blue != 0))
|
2016-05-30 22:39:12 +02:00
|
|
|
{
|
|
|
|
// add RGB Value to Array
|
|
|
|
LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->red);
|
|
|
|
LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->green);
|
|
|
|
LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->blue);
|
|
|
|
|
|
|
|
uint16_t Hue;
|
|
|
|
float Saturation, Luminace;
|
|
|
|
|
|
|
|
// add HSL Value to Array
|
|
|
|
HslTransform::rgb2hsl(priorityInfo.ledColors.begin()->red,
|
|
|
|
priorityInfo.ledColors.begin()->green,
|
|
|
|
priorityInfo.ledColors.begin()->blue,
|
|
|
|
Hue, Saturation, Luminace);
|
|
|
|
|
|
|
|
LEDcolor["HSL Value"].append(Hue);
|
|
|
|
LEDcolor["HSL Value"].append(Saturation);
|
|
|
|
LEDcolor["HSL Value"].append(Luminace);
|
|
|
|
|
|
|
|
// add HEX Value to Array
|
|
|
|
std::stringstream hex;
|
|
|
|
hex << "0x"
|
|
|
|
<< std::uppercase << std::setw(2) << std::setfill('0')
|
|
|
|
<< std::hex << unsigned(priorityInfo.ledColors.begin()->red)
|
|
|
|
<< std::uppercase << std::setw(2) << std::setfill('0')
|
|
|
|
<< std::hex << unsigned(priorityInfo.ledColors.begin()->green)
|
|
|
|
<< std::uppercase << std::setw(2) << std::setfill('0')
|
|
|
|
<< std::hex << unsigned(priorityInfo.ledColors.begin()->blue);
|
|
|
|
|
|
|
|
LEDcolor["HEX Value"].append(hex.str());
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2016-05-30 22:39:12 +02:00
|
|
|
activeLedColors.append(LEDcolor);
|
|
|
|
}
|
2016-05-06 15:05:28 +02:00
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:10:48 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
// get available led devices
|
|
|
|
info["ledDevices"]["active"] = LedDevice::activeDevice();
|
|
|
|
info["ledDevices"]["available"] = Json::Value(Json::arrayValue);
|
|
|
|
for ( auto dev: LedDevice::getDeviceMap())
|
|
|
|
{
|
|
|
|
info["ledDevices"]["available"].append(dev.first);
|
|
|
|
}
|
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
// get components
|
|
|
|
info["components"] = Json::Value(Json::arrayValue);
|
|
|
|
std::map<hyperion::Components, bool> components = _hyperion->getComponentRegister().getRegister();
|
|
|
|
for(auto comp : components)
|
|
|
|
{
|
|
|
|
Json::Value item;
|
|
|
|
item["id"] = comp.first;
|
|
|
|
item["name"] = hyperion::componentToIdString(comp.first);
|
|
|
|
item["title"] = hyperion::componentToString(comp.first);
|
|
|
|
item["enabled"] = comp.second;
|
|
|
|
info["components"].append(item);
|
|
|
|
}
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2016-06-10 18:32:50 +02:00
|
|
|
// Add Hyperion Version, build time
|
2016-08-23 20:07:12 +02:00
|
|
|
//Json::Value & version =
|
|
|
|
info["hyperion"] = Json::Value(Json::arrayValue);
|
2016-06-10 18:32:50 +02:00
|
|
|
Json::Value ver;
|
2016-06-24 23:22:31 +02:00
|
|
|
ver["jsonrpc_version"] = HYPERION_JSON_VERSION;
|
|
|
|
ver["version"] = HYPERION_VERSION;
|
2016-08-23 20:07:12 +02:00
|
|
|
ver["build"] = HYPERION_BUILD_ID;
|
|
|
|
ver["time"] = __DATE__ " " __TIME__;
|
2016-06-10 18:32:50 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
info["hyperion"].append(ver);
|
2016-06-10 18:32:50 +02:00
|
|
|
|
2013-08-19 20:33:36 +02:00
|
|
|
// send the result
|
|
|
|
sendMessage(result);
|
2013-08-18 12:02:17 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleClearCommand(const Json::Value &message, const std::string &command, const int tan)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
2016-02-15 18:25:18 +01:00
|
|
|
forwardJsonMessage(message);
|
|
|
|
|
2013-08-18 13:33:56 +02:00
|
|
|
// extract parameters
|
|
|
|
int priority = message["priority"].asInt();
|
|
|
|
|
|
|
|
// clear priority
|
|
|
|
_hyperion->clear(priority);
|
|
|
|
|
|
|
|
// send reply
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2013-08-18 12:02:17 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleClearallCommand(const Json::Value & message, const std::string &command, const int tan)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
2016-02-15 18:25:18 +01:00
|
|
|
forwardJsonMessage(message);
|
|
|
|
|
2013-08-18 13:33:56 +02:00
|
|
|
// clear priority
|
|
|
|
_hyperion->clearall();
|
|
|
|
|
|
|
|
// send reply
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2013-08-18 12:02:17 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleTransformCommand(const Json::Value &message, const std::string &command, const int tan)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
2013-08-19 19:57:35 +02:00
|
|
|
const Json::Value & transform = message["transform"];
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
const std::string transformId = transform.get("id", _hyperion->getTransformIds().front()).asString();
|
|
|
|
ColorTransform * colorTransform = _hyperion->getTransform(transformId);
|
|
|
|
if (colorTransform == nullptr)
|
|
|
|
{
|
|
|
|
//sendErrorReply(std::string("Incorrect transform identifier: ") + transformId);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-13 21:14:22 +01:00
|
|
|
|
2013-08-21 21:50:17 +02:00
|
|
|
if (transform.isMember("saturationGain"))
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
colorTransform->_hsvTransform.setSaturationGain(transform["saturationGain"].asDouble());
|
2013-08-21 21:50:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.isMember("valueGain"))
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
colorTransform->_hsvTransform.setValueGain(transform["valueGain"].asDouble());
|
2013-08-21 21:50:17 +02:00
|
|
|
}
|
2016-03-11 12:46:09 +01:00
|
|
|
|
|
|
|
if (transform.isMember("saturationLGain"))
|
|
|
|
{
|
|
|
|
colorTransform->_hslTransform.setSaturationGain(transform["saturationLGain"].asDouble());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.isMember("luminanceGain"))
|
|
|
|
{
|
|
|
|
colorTransform->_hslTransform.setLuminanceGain(transform["luminanceGain"].asDouble());
|
|
|
|
}
|
2013-08-21 21:50:17 +02:00
|
|
|
|
2016-05-23 00:00:48 +02:00
|
|
|
if (transform.isMember("luminanceMinimum"))
|
|
|
|
{
|
|
|
|
colorTransform->_hslTransform.setLuminanceMinimum(transform["luminanceMinimum"].asDouble());
|
|
|
|
}
|
|
|
|
|
2013-08-19 19:57:35 +02:00
|
|
|
if (transform.isMember("threshold"))
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
const Json::Value & values = transform["threshold"];
|
|
|
|
colorTransform->_rgbRedTransform .setThreshold(values[0u].asDouble());
|
|
|
|
colorTransform->_rgbGreenTransform.setThreshold(values[1u].asDouble());
|
|
|
|
colorTransform->_rgbBlueTransform .setThreshold(values[2u].asDouble());
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.isMember("gamma"))
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
const Json::Value & values = transform["gamma"];
|
|
|
|
colorTransform->_rgbRedTransform .setGamma(values[0u].asDouble());
|
|
|
|
colorTransform->_rgbGreenTransform.setGamma(values[1u].asDouble());
|
|
|
|
colorTransform->_rgbBlueTransform .setGamma(values[2u].asDouble());
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.isMember("blacklevel"))
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
const Json::Value & values = transform["blacklevel"];
|
|
|
|
colorTransform->_rgbRedTransform .setBlacklevel(values[0u].asDouble());
|
|
|
|
colorTransform->_rgbGreenTransform.setBlacklevel(values[1u].asDouble());
|
|
|
|
colorTransform->_rgbBlueTransform .setBlacklevel(values[2u].asDouble());
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (transform.isMember("whitelevel"))
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
const Json::Value & values = transform["whitelevel"];
|
|
|
|
colorTransform->_rgbRedTransform .setWhitelevel(values[0u].asDouble());
|
|
|
|
colorTransform->_rgbGreenTransform.setWhitelevel(values[1u].asDouble());
|
|
|
|
colorTransform->_rgbBlueTransform .setWhitelevel(values[2u].asDouble());
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
2016-03-13 21:14:22 +01:00
|
|
|
|
2013-12-03 22:56:46 +01:00
|
|
|
// commit the changes
|
|
|
|
_hyperion->transformsUpdated();
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2013-08-18 12:02:17 +02:00
|
|
|
}
|
|
|
|
|
2016-03-11 12:46:09 +01:00
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleTemperatureCommand(const Json::Value &message, const std::string &command, const int tan)
|
2016-03-11 12:46:09 +01:00
|
|
|
{
|
|
|
|
const Json::Value & temperature = message["temperature"];
|
|
|
|
|
|
|
|
const std::string tempId = temperature.get("id", _hyperion->getTemperatureIds().front()).asString();
|
2016-03-13 11:59:36 +01:00
|
|
|
ColorCorrection * colorTemperature = _hyperion->getTemperature(tempId);
|
2016-03-11 12:46:09 +01:00
|
|
|
if (colorTemperature == nullptr)
|
|
|
|
{
|
2016-03-13 11:59:36 +01:00
|
|
|
//sendErrorReply(std::string("Incorrect temperature identifier: ") + tempId);
|
2016-03-11 12:46:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:07:02 +01:00
|
|
|
if (temperature.isMember("correctionValues"))
|
2016-03-11 12:46:09 +01:00
|
|
|
{
|
2016-03-21 17:07:02 +01:00
|
|
|
const Json::Value & values = temperature["correctionValues"];
|
2016-07-04 00:43:41 +02:00
|
|
|
colorTemperature->_rgbCorrection.setAdjustmentR(values[0u].asInt());
|
|
|
|
colorTemperature->_rgbCorrection.setAdjustmentG(values[1u].asInt());
|
|
|
|
colorTemperature->_rgbCorrection.setAdjustmentB(values[2u].asInt());
|
2016-03-21 17:42:13 +01:00
|
|
|
}
|
2016-03-11 12:46:09 +01:00
|
|
|
|
|
|
|
// commit the changes
|
|
|
|
_hyperion->temperaturesUpdated();
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2016-03-11 12:46:09 +01:00
|
|
|
}
|
2016-04-02 00:04:11 +02:00
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message, const std::string &command, const int tan)
|
2016-04-02 00:04:11 +02:00
|
|
|
{
|
|
|
|
const Json::Value & adjustment = message["adjustment"];
|
|
|
|
|
|
|
|
const std::string adjustmentId = adjustment.get("id", _hyperion->getAdjustmentIds().front()).asString();
|
|
|
|
ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
|
|
|
if (colorAdjustment == nullptr)
|
|
|
|
{
|
|
|
|
//sendErrorReply(std::string("Incorrect transform identifier: ") + transformId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adjustment.isMember("redAdjust"))
|
|
|
|
{
|
|
|
|
const Json::Value & values = adjustment["redAdjust"];
|
2016-07-02 14:00:48 +02:00
|
|
|
colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].asInt());
|
|
|
|
colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].asInt());
|
|
|
|
colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].asInt());
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (adjustment.isMember("greenAdjust"))
|
|
|
|
{
|
|
|
|
const Json::Value & values = adjustment["greenAdjust"];
|
2016-07-02 14:00:48 +02:00
|
|
|
colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].asInt());
|
|
|
|
colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].asInt());
|
|
|
|
colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].asInt());
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (adjustment.isMember("blueAdjust"))
|
|
|
|
{
|
|
|
|
const Json::Value & values = adjustment["blueAdjust"];
|
2016-07-02 14:00:48 +02:00
|
|
|
colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].asInt());
|
|
|
|
colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].asInt());
|
|
|
|
colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].asInt());
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
|
|
|
// commit the changes
|
|
|
|
_hyperion->adjustmentsUpdated();
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2016-04-02 00:04:11 +02:00
|
|
|
}
|
2016-07-31 22:21:35 +02:00
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleSourceSelectCommand(const Json::Value & message, const std::string &command, const int tan)
|
2016-07-31 22:21:35 +02:00
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
if (message.get("auto",false).asBool())
|
|
|
|
{
|
|
|
|
_hyperion->setSourceAutoSelectEnabled(true);
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
else if (message.isMember("priority"))
|
|
|
|
{
|
2016-08-17 11:46:36 +02:00
|
|
|
success = _hyperion->setCurrentSourcePriority(message["priority"].asInt());
|
2016-07-31 22:21:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2016-07-31 22:21:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-17 11:46:36 +02:00
|
|
|
sendErrorReply("setting current priority failed", command, tan);
|
2016-07-31 22:21:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleConfigCommand(const Json::Value & message, const std::string &command, const int tan)
|
2016-08-15 22:32:01 +02:00
|
|
|
{
|
|
|
|
std::string subcommand = message.get("subcommand","").asString();
|
2016-09-03 15:54:33 +02:00
|
|
|
std::string full_command = command + "-" + subcommand;
|
2016-08-15 22:32:01 +02:00
|
|
|
if (subcommand == "getschema")
|
|
|
|
{
|
2016-09-03 15:54:33 +02:00
|
|
|
handleSchemaGetCommand(message, full_command, tan);
|
2016-08-15 22:32:01 +02:00
|
|
|
}
|
|
|
|
else if (subcommand == "getconfig")
|
|
|
|
{
|
2016-09-03 15:54:33 +02:00
|
|
|
handleConfigGetCommand(message, full_command, tan);
|
2016-08-15 22:32:01 +02:00
|
|
|
}
|
|
|
|
else if (subcommand == "setconfig")
|
|
|
|
{
|
2016-09-03 15:54:33 +02:00
|
|
|
handleConfigSetCommand(message, full_command, tan);
|
2016-08-15 22:32:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-03 15:54:33 +02:00
|
|
|
sendErrorReply("unknown or missing subcommand", full_command, tan);
|
2016-08-15 22:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleConfigGetCommand(const Json::Value & message, const std::string &command, const int tan)
|
2016-08-03 22:03:19 +02:00
|
|
|
{
|
|
|
|
// create result
|
|
|
|
Json::Value result;
|
|
|
|
result["success"] = true;
|
2016-08-17 11:46:36 +02:00
|
|
|
result["command"] = command;
|
|
|
|
result["tan"] = tan;
|
2016-08-03 22:03:19 +02:00
|
|
|
Json::Value & config = result["result"];
|
|
|
|
config = _hyperion->getJsonConfig();
|
|
|
|
|
|
|
|
// send the result
|
|
|
|
sendMessage(result);
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleSchemaGetCommand(const Json::Value & message, const std::string &command, const int tan)
|
2016-08-15 22:32:01 +02:00
|
|
|
{
|
|
|
|
// create result
|
|
|
|
Json::Value result;
|
|
|
|
result["success"] = true;
|
2016-08-17 11:46:36 +02:00
|
|
|
result["command"] = command;
|
|
|
|
result["tan"] = tan;
|
2016-08-15 22:32:01 +02:00
|
|
|
Json::Value & schemaJson = result["result"];
|
|
|
|
|
|
|
|
// make sure the resources are loaded (they may be left out after static linking)
|
|
|
|
Q_INIT_RESOURCE(resource);
|
|
|
|
|
|
|
|
// read the json schema from the resource
|
|
|
|
QResource schemaData(":/hyperion-schema");
|
|
|
|
assert(schemaData.isValid());
|
|
|
|
|
|
|
|
Json::Reader jsonReader;
|
|
|
|
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send the result
|
|
|
|
sendMessage(result);
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleConfigSetCommand(const Json::Value &message, const std::string &command, const int tan)
|
2016-08-14 20:17:12 +02:00
|
|
|
{
|
|
|
|
struct nested
|
|
|
|
{
|
|
|
|
static void configSetCommand(const Json::Value& message, Json::Value& config, bool& create)
|
|
|
|
{
|
|
|
|
if (!config.isObject() || !message.isObject())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (const auto& key : message.getMemberNames()) {
|
|
|
|
if ((config.isObject() && config.isMember(key)) || create)
|
|
|
|
{
|
|
|
|
if (config[key].type() == Json::objectValue && message[key].type() == Json::objectValue)
|
|
|
|
{
|
|
|
|
configSetCommand(message[key], config[key], create);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( !config[key].empty() || create)
|
|
|
|
config[key] = message[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(message.size() > 0)
|
|
|
|
{
|
2016-08-15 22:32:01 +02:00
|
|
|
if (message.isObject() && message.isMember("config"))
|
2016-08-14 20:17:12 +02:00
|
|
|
{
|
|
|
|
std::string errors;
|
2016-08-15 22:32:01 +02:00
|
|
|
if (!checkJson(message["config"], ":/hyperion-schema", errors, true))
|
2016-08-14 20:17:12 +02:00
|
|
|
{
|
2016-08-17 11:46:36 +02:00
|
|
|
sendErrorReply("Error while validating json: " + errors, command, tan);
|
2016-08-14 20:17:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-18 21:11:21 +02:00
|
|
|
bool createKey = message["create"].asBool();
|
|
|
|
Json::Value hyperionConfig;
|
|
|
|
message["overwrite"].asBool() ? createKey = true : hyperionConfig = _hyperion->getJsonConfig();
|
2016-08-15 22:32:01 +02:00
|
|
|
nested::configSetCommand(message["config"], hyperionConfig, createKey);
|
2016-08-14 20:17:12 +02:00
|
|
|
|
|
|
|
JsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfig);
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2016-08-14 20:17:12 +02:00
|
|
|
}
|
|
|
|
} else
|
2016-08-23 20:07:12 +02:00
|
|
|
sendErrorReply("Error while parsing json: Message size " + std::to_string(message.size()), command, tan);
|
2016-08-14 20:17:12 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::handleComponentStateCommand(const Json::Value& message, const std::string &command, const int tan)
|
2016-08-04 13:10:53 +02:00
|
|
|
{
|
|
|
|
const Json::Value & componentState = message["componentstate"];
|
2016-08-11 07:13:55 +02:00
|
|
|
Components component = stringToComponent(QString::fromStdString(componentState.get("component", "invalid").asString()));
|
2016-08-04 13:10:53 +02:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
if (component != COMP_INVALID)
|
|
|
|
{
|
|
|
|
_hyperion->setComponentState(component, componentState.get("state", true).asBool());
|
2016-08-17 11:46:36 +02:00
|
|
|
sendSuccessReply(command, tan);
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-17 11:46:36 +02:00
|
|
|
sendErrorReply("invalid component name", command, tan);
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
2016-08-04 13:10:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
void JsonClientConnection::handleLedColorsCommand(const Json::Value& message, const std::string &command, const int tan)
|
2016-09-05 17:26:29 +02:00
|
|
|
{
|
|
|
|
// create result
|
2016-09-07 20:10:37 +02:00
|
|
|
std::string subcommand = message.get("subcommand","").asString();
|
|
|
|
_streaming_leds_reply["success"] = true;
|
|
|
|
_streaming_leds_reply["command"] = command;
|
|
|
|
_streaming_leds_reply["tan"] = tan;
|
2016-09-05 17:26:29 +02:00
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
if (subcommand == "ledstream-start")
|
2016-09-05 17:26:29 +02:00
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
_streaming_leds_reply["command"] = command+"-ledstream-update";
|
|
|
|
_timer_ledcolors.start(125);
|
2016-09-05 17:26:29 +02:00
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
else if (subcommand == "ledstream-stop")
|
|
|
|
{
|
|
|
|
_timer_ledcolors.stop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendErrorReply("unknown subcommand",command,tan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendSuccessReply(command+"-"+subcommand,tan);
|
2016-09-05 17:26:29 +02:00
|
|
|
}
|
|
|
|
|
2013-08-18 12:02:17 +02:00
|
|
|
void JsonClientConnection::handleNotImplemented()
|
2013-08-17 15:39:29 +02:00
|
|
|
{
|
|
|
|
sendErrorReply("Command not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonClientConnection::sendMessage(const Json::Value &message)
|
|
|
|
{
|
|
|
|
Json::FastWriter writer;
|
|
|
|
std::string serializedReply = writer.write(message);
|
2014-10-25 22:35:53 +02:00
|
|
|
|
2014-11-08 21:01:46 +01:00
|
|
|
if (!_webSocketHandshakeDone)
|
|
|
|
{
|
|
|
|
// raw tcp socket mode
|
2014-10-25 22:35:53 +02:00
|
|
|
_socket->write(serializedReply.data(), serializedReply.length());
|
2014-11-08 21:01:46 +01:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
// websocket mode
|
2014-10-25 22:35:53 +02:00
|
|
|
quint32 size = serializedReply.length();
|
|
|
|
|
|
|
|
// prepare data frame
|
|
|
|
QByteArray response;
|
|
|
|
response.append(0x81);
|
2014-11-08 21:01:46 +01:00
|
|
|
if (size > 125)
|
|
|
|
{
|
2014-10-25 22:35:53 +02:00
|
|
|
response.append(0x7E);
|
|
|
|
response.append((size >> 8) & 0xFF);
|
|
|
|
response.append(size & 0xFF);
|
|
|
|
} else {
|
|
|
|
response.append(size);
|
|
|
|
}
|
|
|
|
|
2014-11-08 21:01:46 +01:00
|
|
|
response.append(serializedReply.c_str(), serializedReply.length());
|
2014-10-25 22:35:53 +02:00
|
|
|
|
2016-02-15 18:25:18 +01:00
|
|
|
_socket->write(response.data(), response.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket * socket)
|
|
|
|
{
|
|
|
|
// serialize message (FastWriter already appends a newline)
|
|
|
|
std::string serializedMessage = Json::FastWriter().write(message);
|
|
|
|
|
|
|
|
// write message
|
|
|
|
socket->write(serializedMessage.c_str());
|
|
|
|
if (!socket->waitForBytesWritten())
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Debug(_log, "Error while writing data to host");
|
2016-02-15 18:25:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read reply data
|
|
|
|
QByteArray serializedReply;
|
|
|
|
while (!serializedReply.contains('\n'))
|
|
|
|
{
|
|
|
|
// receive reply
|
|
|
|
if (!socket->waitForReadyRead())
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Debug(_log, "Error while writing data from host");
|
2016-02-15 18:25:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
serializedReply += socket->readAll();
|
|
|
|
}
|
|
|
|
int bytes = serializedReply.indexOf('\n') + 1; // Find the end of message
|
|
|
|
|
|
|
|
// parse reply data
|
|
|
|
Json::Reader jsonReader;
|
|
|
|
Json::Value reply;
|
|
|
|
if (!jsonReader.parse(serializedReply.constData(), serializedReply.constData() + bytes, reply))
|
|
|
|
{
|
2016-07-11 17:08:22 +02:00
|
|
|
Error(_log, "Error while parsing reply: invalid json");
|
2016-02-15 18:25:18 +01:00
|
|
|
return;
|
2014-10-25 22:35:53 +02:00
|
|
|
}
|
2016-02-15 18:25:18 +01:00
|
|
|
|
2013-08-17 15:39:29 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::sendSuccessReply(const std::string &command, const int tan)
|
2013-08-18 12:21:07 +02:00
|
|
|
{
|
|
|
|
// create reply
|
|
|
|
Json::Value reply;
|
|
|
|
reply["success"] = true;
|
2016-08-17 11:46:36 +02:00
|
|
|
reply["command"] = command;
|
|
|
|
reply["tan"] = tan;
|
2013-08-18 12:21:07 +02:00
|
|
|
|
|
|
|
// send reply
|
|
|
|
sendMessage(reply);
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:46:36 +02:00
|
|
|
void JsonClientConnection::sendErrorReply(const std::string &error, const std::string &command, const int tan)
|
2013-08-17 15:39:29 +02:00
|
|
|
{
|
|
|
|
// create reply
|
|
|
|
Json::Value reply;
|
|
|
|
reply["success"] = false;
|
|
|
|
reply["error"] = error;
|
2016-08-17 11:46:36 +02:00
|
|
|
reply["command"] = command;
|
|
|
|
reply["tan"] = tan;
|
2013-08-17 15:39:29 +02:00
|
|
|
|
|
|
|
// send reply
|
|
|
|
sendMessage(reply);
|
|
|
|
}
|
2013-08-18 12:02:17 +02:00
|
|
|
|
2016-08-14 20:17:12 +02:00
|
|
|
bool JsonClientConnection::checkJson(const Json::Value & message, const QString & schemaResource, std::string & errorMessage, bool ignoreRequired)
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
|
|
|
// read the json schema from the resource
|
|
|
|
QResource schemaData(schemaResource);
|
|
|
|
assert(schemaData.isValid());
|
|
|
|
Json::Reader jsonReader;
|
|
|
|
Json::Value schemaJson;
|
|
|
|
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
|
|
|
{
|
2016-08-10 19:53:53 +02:00
|
|
|
errorMessage = "Schema error: " + jsonReader.getFormattedErrorMessages();
|
|
|
|
return false;
|
2013-08-18 12:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// create schema checker
|
|
|
|
JsonSchemaChecker schema;
|
|
|
|
schema.setSchema(schemaJson);
|
|
|
|
|
|
|
|
// check the message
|
2016-08-14 20:17:12 +02:00
|
|
|
if (!schema.validate(message, ignoreRequired))
|
2013-08-18 12:02:17 +02:00
|
|
|
{
|
|
|
|
const std::list<std::string> & errors = schema.getMessages();
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "{";
|
|
|
|
foreach (const std::string & error, errors) {
|
|
|
|
ss << error << " ";
|
|
|
|
}
|
|
|
|
ss << "}";
|
|
|
|
errorMessage = ss.str();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
void JsonClientConnection::streamLedcolorsUpdate()
|
|
|
|
{
|
2016-09-08 16:32:42 +02:00
|
|
|
Json::Value & leds = _streaming_leds_reply["result"]["leds"] = Json::Value(Json::arrayValue);
|
|
|
|
//QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
|
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
|
|
|
|
std::vector<ColorRgb> ledBuffer = priorityInfo.ledColors;
|
|
|
|
|
|
|
|
for (ColorRgb& color : ledBuffer)
|
|
|
|
{
|
|
|
|
int idx = leds.size();
|
|
|
|
Json::Value & item = leds[idx];
|
|
|
|
item["index"] = idx;
|
|
|
|
item["red"] = color.red;
|
|
|
|
item["green"] = color.green;
|
|
|
|
item["blue"] = color.blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send the result
|
|
|
|
sendMessage(_streaming_leds_reply);
|
|
|
|
|
|
|
|
}
|
|
|
|
|