mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Troubleshooting and ...
- More i18n - Easy use of mutual exclusion in JsonAPI with QMutexLocker - Smoothing type "linear" hidden in the WebUI, because there is currently only one - Message forwarding implemented again - For compatibility to home assistants and other remote controls, "activeEffects" and "activeLedColor" has been added to the JSON-RPC - FlatBuffer clear now the Priority on disconnect - The information "available V4L2 devices" is now only displayed if the device list is not empty - LED device "PiBlaster" excluded from OSX build
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/hyperion)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperion)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../../libsrc/flatbufserver
|
||||
)
|
||||
|
||||
FILE ( GLOB Hyperion_SOURCES "${CURRENT_HEADER_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.cpp" )
|
||||
|
||||
SET(Hyperion_RESOURCES ${CURRENT_SOURCE_DIR}/resource.qrc)
|
||||
@@ -15,6 +19,8 @@ add_library(hyperion
|
||||
target_link_libraries(hyperion
|
||||
blackborder
|
||||
hyperion-utils
|
||||
flatbufserver
|
||||
flatbuffers
|
||||
leddevice
|
||||
bonjour
|
||||
boblightserver
|
||||
|
@@ -39,7 +39,6 @@ CaptureCont::CaptureCont(Hyperion* hyperion)
|
||||
|
||||
CaptureCont::~CaptureCont()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CaptureCont::handleV4lImage(const Image<ColorRgb> & image)
|
||||
@@ -54,7 +53,6 @@ void CaptureCont::handleSystemImage(const Image<ColorRgb>& image)
|
||||
_hyperion->setInputImage(_systemCaptPrio, image);
|
||||
}
|
||||
|
||||
|
||||
void CaptureCont::setSystemCaptureEnable(const bool& enable)
|
||||
{
|
||||
if(_systemCaptEnabled != enable)
|
||||
@@ -63,6 +61,7 @@ void CaptureCont::setSystemCaptureEnable(const bool& enable)
|
||||
{
|
||||
_hyperion->registerInput(_systemCaptPrio, hyperion::COMP_GRABBER);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setSystemImage, this, &CaptureCont::handleSystemImage);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setSystemImage, _hyperion, &Hyperion::forwardProtoMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -82,6 +81,7 @@ void CaptureCont::setV4LCaptureEnable(const bool& enable)
|
||||
{
|
||||
_hyperion->registerInput(_v4lCaptPrio, hyperion::COMP_V4L);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setV4lImage, this, &CaptureCont::handleV4lImage);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setSystemImage, _hyperion, &Hyperion::forwardProtoMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -68,11 +68,6 @@ Hyperion* Hyperion::getInstance()
|
||||
return Hyperion::_hyperion;
|
||||
}
|
||||
|
||||
MessageForwarder * Hyperion::getForwarder()
|
||||
{
|
||||
return _messageForwarder;
|
||||
}
|
||||
|
||||
Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString configFile, const QString rootPath)
|
||||
: _daemon(daemon)
|
||||
, _settingsManager(new SettingsManager(this, instance, configFile))
|
||||
@@ -83,7 +78,7 @@ Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString
|
||||
, _muxer(_ledString.leds().size())
|
||||
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(_ledString.leds().size(), getSetting(settings::COLOR).object()))
|
||||
, _effectEngine(nullptr)
|
||||
, _messageForwarder(new MessageForwarder(this, getSetting(settings::NETFORWARD)))
|
||||
, _messageForwarder(new MessageForwarder(this))
|
||||
, _configFile(configFile)
|
||||
, _rootPath(rootPath)
|
||||
, _log(Logger::getInstance("HYPERION"))
|
||||
@@ -408,9 +403,7 @@ const bool Hyperion::setInputImage(const int priority, const Image<ColorRgb>& im
|
||||
|
||||
// if this priority is visible, update immediately
|
||||
if(priority == _muxer.getCurrentPriority())
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
||||
}
|
||||
|
||||
// Clean up the old buffer and mapping
|
||||
delete _imageToLeds;
|
||||
_imageToLeds = 0;
|
||||
|
||||
// Construct a new buffer and mapping
|
||||
_imageToLeds = (width>0 && height>0) ? (new ImageToLedsMap(width, height, 0, 0, _ledString.leds())) : nullptr;
|
||||
@@ -85,7 +85,7 @@ void ImageProcessor::setLedString(const LedString& ledString)
|
||||
const unsigned height = _imageToLeds->height();
|
||||
|
||||
// Clean up the old buffer and mapping
|
||||
delete _imageToLeds;
|
||||
_imageToLeds = 0;
|
||||
|
||||
// Construct a new buffer and mapping
|
||||
_imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds());
|
||||
|
@@ -1,32 +1,58 @@
|
||||
// STL includes
|
||||
#include <stdexcept>
|
||||
|
||||
// project includes
|
||||
#include <hyperion/MessageForwarder.h>
|
||||
|
||||
#include <utils/Logger.h>
|
||||
// hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
MessageForwarder::MessageForwarder(Hyperion* hyperion, const QJsonDocument & config)
|
||||
// utils includes
|
||||
#include <utils/Logger.h>
|
||||
|
||||
// qt includes
|
||||
#include <QTcpServer>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <flatbufserver/FlatBufferConnection.h>
|
||||
|
||||
MessageForwarder::MessageForwarder(Hyperion *hyperion)
|
||||
: QObject()
|
||||
, _hyperion(hyperion)
|
||||
, _log(Logger::getInstance("NETFORWARDER"))
|
||||
, _muxer(_hyperion->getMuxerInstance())
|
||||
, _forwarder_enabled(true)
|
||||
, _priority(140)
|
||||
{
|
||||
handleSettingsUpdate(settings::NETFORWARD, config);
|
||||
// get settings updates
|
||||
connect(_hyperion, &Hyperion::settingsChanged, this, &MessageForwarder::handleSettingsUpdate);
|
||||
|
||||
// component changes
|
||||
connect(_hyperion, &Hyperion::componentStateChanged, this, &MessageForwarder::componentStateChanged);
|
||||
|
||||
// connect with Muxer visible priority changes
|
||||
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &MessageForwarder::handlePriorityChanges);
|
||||
|
||||
// init
|
||||
handleSettingsUpdate(settings::NETFORWARD, _hyperion->getSetting(settings::NETFORWARD));
|
||||
}
|
||||
|
||||
MessageForwarder::~MessageForwarder()
|
||||
{
|
||||
while (!_forwardClients.isEmpty())
|
||||
delete _forwardClients.takeFirst();
|
||||
}
|
||||
|
||||
void MessageForwarder::handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
|
||||
void MessageForwarder::handleSettingsUpdate(const settings::type &type, const QJsonDocument &config)
|
||||
{
|
||||
if(type == settings::NETFORWARD)
|
||||
{
|
||||
// clear the current targets
|
||||
_jsonSlaves.clear();
|
||||
_protoSlaves.clear();
|
||||
while (!_forwardClients.isEmpty())
|
||||
delete _forwardClients.takeFirst();
|
||||
|
||||
// build new one
|
||||
const QJsonObject &obj = config.object();
|
||||
if ( !obj["json"].isNull() )
|
||||
@@ -46,12 +72,64 @@ void MessageForwarder::handleSettingsUpdate(const settings::type& type, const QJ
|
||||
addProtoSlave(entry.toString());
|
||||
}
|
||||
}
|
||||
InfoIf(obj["enable"].toBool(true), _log, "Forward now to json targets '%s' and proto targets '%s'", QSTRING_CSTR(_jsonSlaves.join(", ")), QSTRING_CSTR(_protoSlaves.join(", ")))
|
||||
|
||||
if (!_jsonSlaves.isEmpty() && obj["enable"].toBool() && _forwarder_enabled)
|
||||
{
|
||||
InfoIf(obj["enable"].toBool(true), _log, "Forward now to json targets '%s'", QSTRING_CSTR(_jsonSlaves.join(", ")));
|
||||
connect(_hyperion, &Hyperion::forwardJsonMessage, this, &MessageForwarder::forwardJsonMessage, Qt::UniqueConnection);
|
||||
} else if (_jsonSlaves.isEmpty() || ! obj["enable"].toBool() || !_forwarder_enabled)
|
||||
disconnect(_hyperion, &Hyperion::forwardJsonMessage, 0, 0);
|
||||
|
||||
if (!_protoSlaves.isEmpty() && obj["enable"].toBool() && _forwarder_enabled)
|
||||
{
|
||||
InfoIf(obj["enable"].toBool(true), _log, "Forward now to proto targets '%s'", QSTRING_CSTR(_protoSlaves.join(", ")));
|
||||
connect(_hyperion, &Hyperion::forwardProtoMessage, this, &MessageForwarder::forwardProtoMessage, Qt::UniqueConnection);
|
||||
} else if ( _protoSlaves.isEmpty() || ! obj["enable"].toBool() || !_forwarder_enabled)
|
||||
disconnect(_hyperion, &Hyperion::forwardProtoMessage, 0, 0);
|
||||
|
||||
// update comp state
|
||||
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_FORWARDER, obj["enable"].toBool(true));
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::componentStateChanged(const hyperion::Components component, bool enable)
|
||||
{
|
||||
if (component == hyperion::COMP_FORWARDER && _forwarder_enabled != enable)
|
||||
{
|
||||
_forwarder_enabled = enable;
|
||||
handleSettingsUpdate(settings::NETFORWARD, _hyperion->getSetting(settings::NETFORWARD));
|
||||
Info(_log, "Message Forwarder change state to %s", (_forwarder_enabled ? "enabled" : "disabled"));
|
||||
_hyperion->getComponentRegister().componentStateChanged(component, _forwarder_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::handlePriorityChanges(const quint8 &priority)
|
||||
{
|
||||
const QJsonObject obj = _hyperion->getSetting(settings::NETFORWARD).object();
|
||||
if (priority != 0 && _forwarder_enabled && obj["enable"].toBool())
|
||||
{
|
||||
_protoSlaves.clear();
|
||||
while (!_forwardClients.isEmpty())
|
||||
delete _forwardClients.takeFirst();
|
||||
|
||||
hyperion::Components activePrio = _hyperion->getPriorityInfo(priority).componentId;
|
||||
if (activePrio == hyperion::COMP_GRABBER || activePrio == hyperion::COMP_V4L)
|
||||
{
|
||||
if ( !obj["proto"].isNull() )
|
||||
{
|
||||
const QJsonArray & addr = obj["proto"].toArray();
|
||||
for (const auto& entry : addr)
|
||||
{
|
||||
addProtoSlave(entry.toString());
|
||||
}
|
||||
}
|
||||
connect(_hyperion, &Hyperion::forwardProtoMessage, this, &MessageForwarder::forwardProtoMessage, Qt::UniqueConnection);
|
||||
}
|
||||
else
|
||||
disconnect(_hyperion, &Hyperion::forwardProtoMessage, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::addJsonSlave(QString slave)
|
||||
{
|
||||
QStringList parts = slave.split(":");
|
||||
@@ -70,14 +148,15 @@ void MessageForwarder::addJsonSlave(QString slave)
|
||||
}
|
||||
|
||||
// verify loop with jsonserver
|
||||
const QJsonObject& obj = _hyperion->getSetting(settings::JSONSERVER).object();
|
||||
const QJsonObject &obj = _hyperion->getSetting(settings::JSONSERVER).object();
|
||||
if(QHostAddress(parts[0]) == QHostAddress::LocalHost && parts[1].toInt() == obj["port"].toInt())
|
||||
{
|
||||
Error(_log, "Loop between JsonServer and Forwarder! (%s)",QSTRING_CSTR(slave));
|
||||
return;
|
||||
}
|
||||
|
||||
_jsonSlaves << slave;
|
||||
if (_forwarder_enabled)
|
||||
_jsonSlaves << slave;
|
||||
}
|
||||
|
||||
void MessageForwarder::addProtoSlave(QString slave)
|
||||
@@ -98,21 +177,91 @@ void MessageForwarder::addProtoSlave(QString slave)
|
||||
}
|
||||
|
||||
// verify loop with protoserver
|
||||
const QJsonObject& obj = _hyperion->getSetting(settings::FLATBUFSERVER).object();
|
||||
const QJsonObject &obj = _hyperion->getSetting(settings::FLATBUFSERVER).object();
|
||||
if(QHostAddress(parts[0]) == QHostAddress::LocalHost && parts[1].toInt() == obj["port"].toInt())
|
||||
{
|
||||
Error(_log, "Loop between ProtoServer and Forwarder! (%s)",QSTRING_CSTR(slave));
|
||||
return;
|
||||
}
|
||||
_protoSlaves << slave;
|
||||
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
_protoSlaves << slave;
|
||||
FlatBufferConnection* flatbuf = new FlatBufferConnection("Message Forwarder", slave.toLocal8Bit().constData(), _priority, true);
|
||||
_forwardClients << flatbuf;
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageForwarder::protoForwardingEnabled()
|
||||
void MessageForwarder::forwardJsonMessage(const QJsonObject &message)
|
||||
{
|
||||
return ! _protoSlaves.empty();
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
QTcpSocket client;
|
||||
for (int i=0; i<_jsonSlaves.size(); i++)
|
||||
{
|
||||
QStringList parts = _jsonSlaves.at(i).split(":");
|
||||
client.connectToHost(QHostAddress(parts[0]), parts[1].toUShort());
|
||||
if ( client.waitForConnected(500) )
|
||||
{
|
||||
sendJsonMessage(message,&client);
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageForwarder::jsonForwardingEnabled()
|
||||
void MessageForwarder::forwardProtoMessage(const Image<ColorRgb> &image)
|
||||
{
|
||||
return ! _jsonSlaves.empty();
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
for (int i=0; i < _forwardClients.size(); i++)
|
||||
{
|
||||
_forwardClients.at(i)->setRegister("Message Forwarder", _priority);
|
||||
_forwardClients.at(i)->setImage(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::sendJsonMessage(const QJsonObject &message, QTcpSocket *socket)
|
||||
{
|
||||
// for hyperion classic compatibility
|
||||
QJsonObject jsonMessage = message;
|
||||
if (jsonMessage.contains("tan") && jsonMessage["tan"].isNull())
|
||||
jsonMessage["tan"] = 100;
|
||||
|
||||
// serialize message
|
||||
QJsonDocument writer(jsonMessage);
|
||||
QByteArray serializedMessage = writer.toJson(QJsonDocument::Compact) + "\n";
|
||||
|
||||
// write message
|
||||
socket->write(serializedMessage);
|
||||
if (!socket->waitForBytesWritten())
|
||||
{
|
||||
Debug(_log, "Error while writing data to host");
|
||||
return;
|
||||
}
|
||||
|
||||
// read reply data
|
||||
QByteArray serializedReply;
|
||||
while (!serializedReply.contains('\n'))
|
||||
{
|
||||
// receive reply
|
||||
if (!socket->waitForReadyRead())
|
||||
{
|
||||
Debug(_log, "Error while writing data from host");
|
||||
return;
|
||||
}
|
||||
|
||||
serializedReply += socket->readAll();
|
||||
}
|
||||
|
||||
// parse reply data
|
||||
QJsonParseError error;
|
||||
QJsonDocument reply = QJsonDocument::fromJson(serializedReply ,&error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
Error(_log, "Error while parsing reply: invalid json");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -108,11 +108,6 @@ void PriorityMuxer::updateLedColorsLength(const int& ledCount)
|
||||
}
|
||||
}
|
||||
|
||||
int PriorityMuxer::getCurrentPriority() const
|
||||
{
|
||||
return _currentPriority;
|
||||
}
|
||||
|
||||
QList<int> PriorityMuxer::getPriorities() const
|
||||
{
|
||||
return _activeInputs.keys();
|
||||
@@ -299,7 +294,7 @@ void PriorityMuxer::setCurrentTime(void)
|
||||
else
|
||||
{
|
||||
// timeoutTime of -100 is awaiting data (inactive); skip
|
||||
if(infoIt->timeoutTime_ms >= -1)
|
||||
if(infoIt->timeoutTime_ms >= -100)
|
||||
newPriority = qMin(newPriority, infoIt->priority);
|
||||
|
||||
// call timeTrigger when effect or color is running with timeout > 0, blacklist prio 255
|
||||
|
@@ -17,7 +17,8 @@
|
||||
"enum" : ["linear"],
|
||||
"default" : "linear",
|
||||
"options" : {
|
||||
"enum_titles" : ["edt_conf_enum_linear"]
|
||||
"enum_titles" : ["edt_conf_enum_linear"],
|
||||
"hidden":true
|
||||
},
|
||||
"propertyOrder" : 2
|
||||
},
|
||||
|
Reference in New Issue
Block a user