Update Json Interface (Enable/Disable components during runtime) (#150)

* Update Hyperion.h

* Add files via upload

* Update CMakeLists.txt

* Update Hyperion.cpp

* Update JsonClientConnection.cpp

* Update JsonClientConnection.h

* Update JsonSchemas.qrc

* Add files via upload

* Update schema.json

* Update JsonConnection.cpp

* Update JsonConnection.h

* Update hyperion-remote.cpp
This commit is contained in:
Paulchen-Panther 2016-08-04 13:10:53 +02:00 committed by brindosch
parent f183032270
commit bfb06966de
12 changed files with 179 additions and 2 deletions

View File

@ -12,6 +12,7 @@
#include <utils/Image.h> #include <utils/Image.h>
#include <utils/ColorRgb.h> #include <utils/ColorRgb.h>
#include <utils/Logger.h> #include <utils/Logger.h>
#include <utils/Components.h>
// Hyperion includes // Hyperion includes
#include <hyperion/LedString.h> #include <hyperion/LedString.h>
@ -25,6 +26,9 @@
#include <effectengine/EffectDefinition.h> #include <effectengine/EffectDefinition.h>
#include <effectengine/ActiveEffectDefinition.h> #include <effectengine/ActiveEffectDefinition.h>
// KodiVideoChecker includes
#include <kodivideochecker/KODIVideoChecker.h>
// Forward class declaration // Forward class declaration
class LedDevice; class LedDevice;
class ColorTransform; class ColorTransform;
@ -37,6 +41,7 @@ class RgbChannelAdjustment;
class MultiColorTransform; class MultiColorTransform;
class MultiColorCorrection; class MultiColorCorrection;
class MultiColorAdjustment; class MultiColorAdjustment;
class KODIVideoChecker;
/// ///
/// The main class of Hyperion. This gives other 'users' access to the attached LedDevice through /// The main class of Hyperion. This gives other 'users' access to the attached LedDevice through
/// the priority muxer. /// the priority muxer.
@ -144,6 +149,14 @@ public:
/// gets current state of automatic/priorized source selection /// gets current state of automatic/priorized source selection
/// @return the state /// @return the state
bool sourceAutoSelectEnabled() { return _sourceAutoSelectEnabled; }; bool sourceAutoSelectEnabled() { return _sourceAutoSelectEnabled; };
///
/// Enable/Disable components during runtime
///
/// @param component The component [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]
/// @param state The state of the component [true | false]
///
void setComponentState(const Components component, const bool state);
public slots: public slots:
/// ///
/// Writes a single color to all the leds for the given time and priority /// Writes a single color to all the leds for the given time and priority

View File

@ -0,0 +1,30 @@
#pragma once
/**
* Enumeration of components in Hyperion.
*/
enum Components
{
SMOOTHING,
BLACKBORDER,
KODICHECKER,
FORWARDER,
UDPLISTENER,
BOBLIGHTSERVER,
GRABBER
};
inline const char* componentToString(Components c)
{
switch (c)
{
case SMOOTHING: return "Smoothing option";
case BLACKBORDER: return "Blackborder detector";
case KODICHECKER: return "KodiVideoChecker";
case FORWARDER: return "Json/Proto forwarder";
case UDPLISTENER: return "UDP listener";
case BOBLIGHTSERVER: return "Boblight server";
case GRABBER: return "Framegrabber";
default: return "";
}
}

View File

@ -54,6 +54,7 @@ add_library(hyperion
) )
target_link_libraries(hyperion target_link_libraries(hyperion
kodivideochecker
blackborder blackborder
hyperion-utils hyperion-utils
leddevice leddevice

View File

@ -669,6 +669,33 @@ bool Hyperion::setCurrentSourcePriority(int priority )
return priorityValid; return priorityValid;
} }
void Hyperion::setComponentState(const Components component, const bool state)
{
switch(component)
{
case SMOOTHING:
break;
case BLACKBORDER:
break;
case KODICHECKER:
{
KODIVideoChecker* _kodiVideoChecker = KODIVideoChecker::getInstance();
if (_kodiVideoChecker != nullptr)
state ? _kodiVideoChecker->start() : _kodiVideoChecker->stop();
else
Debug(_log, "Can't get instance from: '%s'", componentToString(component));
break;
}
case FORWARDER:
break;
case UDPLISTENER:
break;
case BOBLIGHTSERVER:
break;
case GRABBER:
break;
}
}
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects) void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects)
{ {

View File

@ -260,6 +260,8 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
handleSourceSelectCommand(message); handleSourceSelectCommand(message);
else if (command == "configget") else if (command == "configget")
handleConfigGetCommand(message); handleConfigGetCommand(message);
else if (command == "componentstate")
handleComponentStateCommand(message);
else else
handleNotImplemented(); handleNotImplemented();
} }
@ -815,6 +817,29 @@ void JsonClientConnection::handleConfigGetCommand(const Json::Value &)
sendMessage(result); sendMessage(result);
} }
void JsonClientConnection::handleComponentStateCommand(const Json::Value& message)
{
const Json::Value & componentState = message["componentstate"];
std::string component = componentState.get("component", "").asString();
if (component == "SMOOTHING")
_hyperion->setComponentState((Components)0, componentState.get("state", true).asBool());
else if (component == "BLACKBORDER")
_hyperion->setComponentState((Components)1, componentState.get("state", true).asBool());
else if (component == "KODICHECKER")
_hyperion->setComponentState((Components)2, componentState.get("state", true).asBool());
else if (component == "FORWARDER")
_hyperion->setComponentState((Components)3, componentState.get("state", true).asBool());
else if (component == "UDPLISTENER")
_hyperion->setComponentState((Components)4, componentState.get("state", true).asBool());
else if (component == "BOBLIGHTSERVER")
_hyperion->setComponentState((Components)5, componentState.get("state", true).asBool());
else if (component == "GRABBER")
_hyperion->setComponentState((Components)6, componentState.get("state", true).asBool());
sendSuccessReply();
}
void JsonClientConnection::handleNotImplemented() void JsonClientConnection::handleNotImplemented()
{ {
sendErrorReply("Command not implemented"); sendErrorReply("Command not implemented");

View File

@ -16,6 +16,7 @@
// util includes // util includes
#include <utils/jsonschema/JsonSchemaChecker.h> #include <utils/jsonschema/JsonSchemaChecker.h>
#include <utils/Logger.h> #include <utils/Logger.h>
#include <utils/Components.h>
class ImageProcessor; class ImageProcessor;
@ -141,6 +142,13 @@ private:
/// ///
void handleConfigGetCommand(const Json::Value & message); void handleConfigGetCommand(const Json::Value & message);
///
/// Handle an incoming JSON Component State message
///
/// @param message the incoming message
///
void handleComponentStateCommand(const Json::Value & message);
/// ///
/// Handle an incoming JSON message of unknown type /// Handle an incoming JSON message of unknown type
/// ///

View File

@ -13,5 +13,6 @@
<file alias="schema-effect">schema/schema-effect.json</file> <file alias="schema-effect">schema/schema-effect.json</file>
<file alias="schema-sourceselect">schema/schema-sourceselect.json</file> <file alias="schema-sourceselect">schema/schema-sourceselect.json</file>
<file alias="schema-configget">schema/schema-configget.json</file> <file alias="schema-configget">schema/schema-configget.json</file>
<file alias="schema-componentstate">schema/schema-componentstate.json</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1,33 @@
{
"type":"object",
"required":true,
"properties":
{
"command":
{
"type" : "string",
"required" : true,
"enum" : ["componentstate"]
},
"componentstate":
{
"type": "object",
"required": true,
"properties":
{
"component":
{
"enum" : ["SMOOTHING", "BLACKBORDER", "KODICHECKER", "FORWARDER", "UDPLISTENER", "BOBLIGHTSERVER", "GRABBER"],
"required": true
},
"state":
{
"type": "bool",
"required": true
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}

View File

@ -5,7 +5,7 @@
"command": { "command": {
"type" : "string", "type" : "string",
"required" : true, "required" : true,
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "configget"] "enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "configget", "componentstate"]
} }
} }
} }

View File

@ -192,6 +192,25 @@ void JsonConnection::clearAll()
parseReply(reply); parseReply(reply);
} }
void JsonConnection::setComponentState(const std::string& component, const bool state)
{
state ? std::cout << "Enable Component " : std::cout << "Disable Component ";
std::cout << component << std::endl;
// create command
Json::Value command;
command["command"] = "componentstate";
Json::Value & parameter = command["componentstate"];
parameter["component"] = component;
parameter["state"] = state;
// send command message
Json::Value reply = sendMessage(command);
// parse reply message
parseReply(reply);
}
void JsonConnection::setSource(int priority) void JsonConnection::setSource(int priority)
{ {
// create command // create command

View File

@ -83,6 +83,14 @@ public:
/// ///
void clearAll(); void clearAll();
///
/// Enable/Disable components during runtime
///
/// @param component The component [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]
/// @param state The state of the component [true | false]
///
void setComponentState(const std::string & component, const bool state);
/// ///
/// Set current active priority channel and deactivate auto source switching /// Set current active priority channel and deactivate auto source switching
/// ///

View File

@ -61,6 +61,8 @@ int main(int argc, char * argv[])
SwitchParameter<> & argServerInfo = parameters.add<SwitchParameter<> >('l', "list" , "List server info and active effects with priority and duration"); SwitchParameter<> & argServerInfo = parameters.add<SwitchParameter<> >('l', "list" , "List server info and active effects with priority and duration");
SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option"); SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option");
SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clearall" , "Clear data for all active priority channels"); SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clearall" , "Clear data for all active priority channels");
StringParameter & argEnableComponent = parameters.add<StringParameter> ('E', "enable" , "Enable the Component with the given name. Available Components are [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]");
StringParameter & argDisableComponent = parameters.add<StringParameter> ('D', "disable" , "Disable the Component with the given name. Available Components are [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]");
StringParameter & argId = parameters.add<StringParameter> ('q', "qualifier" , "Identifier(qualifier) of the transform to set"); StringParameter & argId = parameters.add<StringParameter> ('q', "qualifier" , "Identifier(qualifier) of the transform to set");
DoubleParameter & argSaturation = parameters.add<DoubleParameter> ('s', "saturation", "!DEPRECATED! Will be removed soon! Set the HSV saturation gain of the leds"); DoubleParameter & argSaturation = parameters.add<DoubleParameter> ('s', "saturation", "!DEPRECATED! Will be removed soon! Set the HSV saturation gain of the leds");
DoubleParameter & argValue = parameters.add<DoubleParameter> ('v', "value" , "!DEPRECATED! Will be removed soon! Set the HSV value gain of the leds"); DoubleParameter & argValue = parameters.add<DoubleParameter> ('v', "value" , "!DEPRECATED! Will be removed soon! Set the HSV value gain of the leds");
@ -107,7 +109,7 @@ int main(int argc, char * argv[])
bool colorModding = colorTransform || colorAdjust || argCorrection.isSet() || argTemperature.isSet(); bool colorModding = colorTransform || colorAdjust || argCorrection.isSet() || argTemperature.isSet();
// check that exactly one command was given // check that exactly one command was given
int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), colorModding, argSource.isSet(), argSourceAuto.isSet(), argConfigGet.isSet()}); int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), argEnableComponent.isSet(), argDisableComponent.isSet(), colorModding, argSource.isSet(), argSourceAuto.isSet(), argConfigGet.isSet()});
if (commandCount != 1) if (commandCount != 1)
{ {
std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl; std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl;
@ -117,6 +119,8 @@ int main(int argc, char * argv[])
std::cerr << " " << argServerInfo.usageLine() << std::endl; std::cerr << " " << argServerInfo.usageLine() << std::endl;
std::cerr << " " << argClear.usageLine() << std::endl; std::cerr << " " << argClear.usageLine() << std::endl;
std::cerr << " " << argClearAll.usageLine() << std::endl; std::cerr << " " << argClearAll.usageLine() << std::endl;
std::cerr << " " << argEnableComponent.usageLine() << std::endl;
std::cerr << " " << argDisableComponent.usageLine() << std::endl;
std::cerr << " " << argSource.usageLine() << std::endl; std::cerr << " " << argSource.usageLine() << std::endl;
std::cerr << " " << argSourceAuto.usageLine() << std::endl; std::cerr << " " << argSourceAuto.usageLine() << std::endl;
std::cerr << " " << argConfigGet.usageLine() << std::endl; std::cerr << " " << argConfigGet.usageLine() << std::endl;
@ -171,6 +175,14 @@ int main(int argc, char * argv[])
{ {
connection.clearAll(); connection.clearAll();
} }
else if (argEnableComponent.isSet())
{
connection.setComponentState(argEnableComponent.getValue(), true);
}
else if (argDisableComponent.isSet())
{
connection.setComponentState(argDisableComponent.getValue(), false);
}
else if (argSource.isSet()) else if (argSource.isSet())
{ {
connection.setSource(argSource.getValue()); connection.setSource(argSource.getValue());