From bfb06966de93ef724894d897148c595ab1c0376a Mon Sep 17 00:00:00 2001 From: Paulchen-Panther Date: Thu, 4 Aug 2016 13:10:53 +0200 Subject: [PATCH] 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 --- include/hyperion/Hyperion.h | 13 ++++++++ include/utils/Components.h | 30 +++++++++++++++++ libsrc/hyperion/CMakeLists.txt | 1 + libsrc/hyperion/Hyperion.cpp | 27 +++++++++++++++ libsrc/jsonserver/JsonClientConnection.cpp | 25 ++++++++++++++ libsrc/jsonserver/JsonClientConnection.h | 8 +++++ libsrc/jsonserver/JsonSchemas.qrc | 1 + .../schema/schema-componentstate.json | 33 +++++++++++++++++++ libsrc/jsonserver/schema/schema.json | 2 +- src/hyperion-remote/JsonConnection.cpp | 19 +++++++++++ src/hyperion-remote/JsonConnection.h | 8 +++++ src/hyperion-remote/hyperion-remote.cpp | 14 +++++++- 12 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 include/utils/Components.h create mode 100644 libsrc/jsonserver/schema/schema-componentstate.json diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index ec1e26b3..dedf43f1 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -12,6 +12,7 @@ #include #include #include +#include // Hyperion includes #include @@ -25,6 +26,9 @@ #include #include +// KodiVideoChecker includes +#include + // Forward class declaration class LedDevice; class ColorTransform; @@ -37,6 +41,7 @@ class RgbChannelAdjustment; class MultiColorTransform; class MultiColorCorrection; class MultiColorAdjustment; +class KODIVideoChecker; /// /// The main class of Hyperion. This gives other 'users' access to the attached LedDevice through /// the priority muxer. @@ -144,6 +149,14 @@ public: /// gets current state of automatic/priorized source selection /// @return the state 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: /// /// Writes a single color to all the leds for the given time and priority diff --git a/include/utils/Components.h b/include/utils/Components.h new file mode 100644 index 00000000..900b971a --- /dev/null +++ b/include/utils/Components.h @@ -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 ""; + } +} \ No newline at end of file diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index c41a54f3..3b3d9cde 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -54,6 +54,7 @@ add_library(hyperion ) target_link_libraries(hyperion + kodivideochecker blackborder hyperion-utils leddevice diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 09fc6546..df5b7936 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -669,6 +669,33 @@ bool Hyperion::setCurrentSourcePriority(int priority ) 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) { diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 58b7aa04..2bf6a49c 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -260,6 +260,8 @@ void JsonClientConnection::handleMessage(const std::string &messageString) handleSourceSelectCommand(message); else if (command == "configget") handleConfigGetCommand(message); + else if (command == "componentstate") + handleComponentStateCommand(message); else handleNotImplemented(); } @@ -815,6 +817,29 @@ void JsonClientConnection::handleConfigGetCommand(const Json::Value &) 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() { sendErrorReply("Command not implemented"); diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 19b70131..102b4112 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -16,6 +16,7 @@ // util includes #include #include +#include class ImageProcessor; @@ -140,6 +141,13 @@ private: /// @param message the incoming 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 diff --git a/libsrc/jsonserver/JsonSchemas.qrc b/libsrc/jsonserver/JsonSchemas.qrc index c7bbdf87..26129ddf 100644 --- a/libsrc/jsonserver/JsonSchemas.qrc +++ b/libsrc/jsonserver/JsonSchemas.qrc @@ -13,5 +13,6 @@ schema/schema-effect.json schema/schema-sourceselect.json schema/schema-configget.json + schema/schema-componentstate.json diff --git a/libsrc/jsonserver/schema/schema-componentstate.json b/libsrc/jsonserver/schema/schema-componentstate.json new file mode 100644 index 00000000..a4732714 --- /dev/null +++ b/libsrc/jsonserver/schema/schema-componentstate.json @@ -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 +} diff --git a/libsrc/jsonserver/schema/schema.json b/libsrc/jsonserver/schema/schema.json index 186c5843..c175990b 100644 --- a/libsrc/jsonserver/schema/schema.json +++ b/libsrc/jsonserver/schema/schema.json @@ -5,7 +5,7 @@ "command": { "type" : "string", "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"] } } } diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index b5fee9ad..fd5083bc 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -192,6 +192,25 @@ void JsonConnection::clearAll() 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) { // create command diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index e2d9febf..ac6877e8 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -82,6 +82,14 @@ public: /// Clear all priority channels /// 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 diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 828e092e..0e45b5f5 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -61,6 +61,8 @@ int main(int argc, char * argv[]) SwitchParameter<> & argServerInfo = parameters.add >('l', "list" , "List server info and active effects with priority and duration"); SwitchParameter<> & argClear = parameters.add >('x', "clear" , "Clear data for the priority channel provided by the -p option"); SwitchParameter<> & argClearAll = parameters.add >(0x0, "clearall" , "Clear data for all active priority channels"); + StringParameter & argEnableComponent = parameters.add ('E', "enable" , "Enable the Component with the given name. Available Components are [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]"); + StringParameter & argDisableComponent = parameters.add ('D', "disable" , "Disable the Component with the given name. Available Components are [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]"); StringParameter & argId = parameters.add ('q', "qualifier" , "Identifier(qualifier) of the transform to set"); DoubleParameter & argSaturation = parameters.add ('s', "saturation", "!DEPRECATED! Will be removed soon! Set the HSV saturation gain of the leds"); DoubleParameter & argValue = parameters.add ('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(); // 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) { 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 << " " << argClear.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 << " " << argSourceAuto.usageLine() << std::endl; std::cerr << " " << argConfigGet.usageLine() << std::endl; @@ -171,6 +175,14 @@ int main(int argc, char * argv[]) { connection.clearAll(); } + else if (argEnableComponent.isSet()) + { + connection.setComponentState(argEnableComponent.getValue(), true); + } + else if (argDisableComponent.isSet()) + { + connection.setComponentState(argDisableComponent.getValue(), false); + } else if (argSource.isSet()) { connection.setSource(argSource.getValue());