Added config file settings for XBMCVideoChecker

This commit is contained in:
johan 2013-08-24 11:51:52 +02:00
parent 026937d5e1
commit 213545afe7
7 changed files with 537 additions and 508 deletions

View File

@ -294,5 +294,10 @@
"hscan" : { "minimum" : 52.9412, "maximum" : 58.8235 }, "hscan" : { "minimum" : 52.9412, "maximum" : 58.8235 },
"vscan" : { "minimum" : 0, "maximum" : 10 } "vscan" : { "minimum" : 0, "maximum" : 10 }
} }
] ],
"xbmcVideoChecker" : {
"enable" : true,
"xbmcAddress" : "127.0.0.1",
"xbmcTcpPort" : 9090
}
} }

View File

@ -35,11 +35,6 @@ public:
SATURATION_GAIN, VALUE_GAIN, THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL SATURATION_GAIN, VALUE_GAIN, THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL
}; };
static LedString createLedString(const Json::Value& ledsConfig);
static Json::Value loadConfig(const std::string& configFile);
Hyperion(const std::string& configFile);
Hyperion(const Json::Value& jsonConfig); Hyperion(const Json::Value& jsonConfig);
~Hyperion(); ~Hyperion();
@ -62,6 +57,11 @@ public:
const InputInfo& getPriorityInfo(const int priority) const; const InputInfo& getPriorityInfo(const int priority) const;
static LedDevice* constructDevice(const Json::Value & deviceConfig);
static LedString createLedString(const Json::Value & ledsConfig);
static HsvTransform * createHsvTransform(const Json::Value & hsvConfig);
static ColorTransform* createColorTransform(const Json::Value & colorConfig);
private slots: private slots:
void update(); void update();

View File

@ -23,7 +23,7 @@ class XBMCVideoChecker : public QObject
Q_OBJECT Q_OBJECT
public: public:
XBMCVideoChecker(QString address, uint16_t port, uint64_t interval, Hyperion * hyperion, int priority); XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval, Hyperion * hyperion, int priority);
void start(); void start();

View File

@ -1,7 +1,6 @@
// QT includes // QT includes
#include <QDateTime> #include <QDateTime>
#include <QResource>
// JsonSchema include // JsonSchema include
#include <utils/jsonschema/JsonFactory.h> #include <utils/jsonschema/JsonFactory.h>
@ -17,7 +16,7 @@
#include <utils/ColorTransform.h> #include <utils/ColorTransform.h>
#include <utils/HsvTransform.h> #include <utils/HsvTransform.h>
LedDevice* constructDevice(const Json::Value& deviceConfig) LedDevice* Hyperion::constructDevice(const Json::Value& deviceConfig)
{ {
std::cout << "Device configuration: " << deviceConfig << std::endl; std::cout << "Device configuration: " << deviceConfig << std::endl;
LedDevice* device = nullptr; LedDevice* device = nullptr;
@ -44,12 +43,12 @@ LedDevice* constructDevice(const Json::Value& deviceConfig)
return device; return device;
} }
HsvTransform * createHsvTransform(const Json::Value & hsvConfig) HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig)
{ {
return new HsvTransform(hsvConfig["saturationGain"].asDouble(), hsvConfig["valueGain"].asDouble()); return new HsvTransform(hsvConfig["saturationGain"].asDouble(), hsvConfig["valueGain"].asDouble());
} }
ColorTransform* createColorTransform(const Json::Value& colorConfig) ColorTransform* Hyperion::createColorTransform(const Json::Value& colorConfig)
{ {
const double threshold = colorConfig["threshold"].asDouble(); const double threshold = colorConfig["threshold"].asDouble();
const double gamma = colorConfig["gamma"].asDouble(); const double gamma = colorConfig["gamma"].asDouble();
@ -79,36 +78,6 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig)
return ledString; return ledString;
} }
Json::Value Hyperion::loadConfig(const std::string& configFile)
{
// 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;
Json::Value schemaJson;
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
{
throw std::runtime_error("Schema error: " + jsonReader.getFormattedErrorMessages()) ;
}
JsonSchemaChecker schemaChecker;
schemaChecker.setSchema(schemaJson);
const Json::Value jsonConfig = JsonFactory::readJson(configFile);
schemaChecker.validate(jsonConfig);
return jsonConfig;
}
Hyperion::Hyperion(const std::string& configFile) :
Hyperion(loadConfig(configFile))
{
// empty
}
Hyperion::Hyperion(const Json::Value &jsonConfig) : Hyperion::Hyperion(const Json::Value &jsonConfig) :
_ledString(createLedString(jsonConfig["leds"])), _ledString(createLedString(jsonConfig["leds"])),
_muxer(_ledString.leds().size()), _muxer(_ledString.leds().size()),

View File

@ -164,6 +164,27 @@
} }
} }
} }
},
"xbmcVideoChecker" :
{
"type" : "object",
"required" : true,
"properties" : {
"enable" : {
"type" : "boolean",
"required" : true
},
"xbmcAddress" : {
"type" : "string",
"required" : true
},
"xbmcTcpPort" : {
"type" : "integer",
"required" : true
} }
},
"additionalProperties" : false
} }
},
"additionalProperties" : false
} }

View File

@ -3,9 +3,9 @@
#include <xbmcvideochecker/XBMCVideoChecker.h> #include <xbmcvideochecker/XBMCVideoChecker.h>
XBMCVideoChecker::XBMCVideoChecker(QString address, uint16_t port, uint64_t interval_ms, Hyperion * hyperion, int priority) : XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval_ms, Hyperion * hyperion, int priority) :
QObject(), QObject(),
_address(address), _address(QString::fromStdString(address)),
_port(port), _port(port),
_request("{\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}"), _request("{\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}"),
_timer(), _timer(),
@ -48,7 +48,7 @@ void XBMCVideoChecker::sendRequest()
void XBMCVideoChecker::receiveReply() void XBMCVideoChecker::receiveReply()
{ {
// expect that the reply is received as a single message. Probaly oke considering the size of the expected reply // expect that the reply is received as a single message. Probably oke considering the size of the expected reply
QString reply(_socket.readAll()); QString reply(_socket.readAll());
if (reply.contains("playerid")) if (reply.contains("playerid"))

View File

@ -4,6 +4,7 @@
// QT includes // QT includes
#include <QCoreApplication> #include <QCoreApplication>
#include <QResource>
// Json-Schema includes // Json-Schema includes
#include <utils/jsonschema/JsonFactory.h> #include <utils/jsonschema/JsonFactory.h>
@ -26,6 +27,30 @@ void signal_handler(const int signum)
QCoreApplication::quit(); QCoreApplication::quit();
} }
Json::Value loadConfig(const std::string & configFile)
{
// 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;
Json::Value schemaJson;
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
{
throw std::runtime_error("Schema error: " + jsonReader.getFormattedErrorMessages()) ;
}
JsonSchemaChecker schemaChecker;
schemaChecker.setSchema(schemaJson);
const Json::Value jsonConfig = JsonFactory::readJson(configFile);
schemaChecker.validate(jsonConfig);
return jsonConfig;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// Initialising QCoreApplication // Initialising QCoreApplication
@ -44,15 +69,21 @@ int main(int argc, char** argv)
const std::string configFile = argv[1]; const std::string configFile = argv[1];
std::cout << "Selected configuration file: " << configFile.c_str() << std::endl; std::cout << "Selected configuration file: " << configFile.c_str() << std::endl;
const Json::Value config = loadConfig(configFile);
Hyperion hyperion(configFile); Hyperion hyperion(config);
std::cout << "Hyperion created and initialised" << std::endl; std::cout << "Hyperion created and initialised" << std::endl;
RainbowBootSequence bootSequence(&hyperion); RainbowBootSequence bootSequence(&hyperion);
bootSequence.start(); bootSequence.start();
XBMCVideoChecker xbmcVideoChecker("127.0.0.1", 9090, 1000, &hyperion, 999); const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"];
XBMCVideoChecker xbmcVideoChecker(videoCheckerConfig["xbmcAddress"].asString(), videoCheckerConfig["xbmcTcpPort"].asUInt(), 1000, &hyperion, 999);
if (videoCheckerConfig["enable"].asBool())
{
xbmcVideoChecker.start(); xbmcVideoChecker.start();
std::cout << "XBMC video checker created and started" << std::endl;
}
DispmanxWrapper dispmanx(64, 64, 10, &hyperion); DispmanxWrapper dispmanx(64, 64, 10, &hyperion);
dispmanx.start(); dispmanx.start();
@ -61,11 +92,14 @@ int main(int argc, char** argv)
JsonServer jsonServer(&hyperion); JsonServer jsonServer(&hyperion);
std::cout << "Json server created and started on port " << jsonServer.getPort() << std::endl; std::cout << "Json server created and started on port " << jsonServer.getPort() << std::endl;
app.exec(); // run the application
std::cout << "Application closed" << std::endl; int rc = app.exec();
std::cout << "Application closed" << std::endl;
// Stop the frame grabber // Stop the frame grabber
dispmanx.stop(); dispmanx.stop();
// Clear all colors (switchting off all leds) // Clear all colors (switchting off all leds)
hyperion.clearall(); hyperion.clearall();
return rc;
} }