mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge remote-tracking branch 'refs/remotes/hyperion-project/master' into weba
This commit is contained in:
commit
0578cda79a
@ -9,10 +9,11 @@
|
||||
set following values to your needs
|
||||
**************************************/
|
||||
|
||||
#define INITAL_LED_TEST_ENABLED true
|
||||
#define INITIAL_LED_TEST_ENABLED true
|
||||
#define INITIAL_LED_TEST_BRIGHTNESS 32 // 0..255
|
||||
|
||||
// Number of leds in your strip. set to "1" and ANALOG_OUTPUT_ENABLED to "true" to activate analog only
|
||||
#define NUM_LEDS 100
|
||||
#define MAX_LEDS 100
|
||||
|
||||
// type of your led controller, possible values, see below
|
||||
#define LED_TYPE WS2812B
|
||||
@ -54,8 +55,9 @@
|
||||
#define COLOR_CORRECTION TypicalLEDStrip // predefined fastled color correction
|
||||
//#define COLOR_CORRECTION CRGB(255,255,255) // or RGB value describing the color correction
|
||||
|
||||
// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
|
||||
// Baudrate, higher rate allows faster refresh rate and more LEDs
|
||||
#define serialRate 460800 // use 115200 for ftdi based boards
|
||||
//#define serialRate 115200 // use 115200 for ftdi based boards
|
||||
|
||||
|
||||
/**************************************
|
||||
@ -70,7 +72,7 @@ uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
|
||||
unsigned long endTime;
|
||||
|
||||
// Define the array of leds
|
||||
CRGB leds[NUM_LEDS];
|
||||
CRGB leds[MAX_LEDS];
|
||||
|
||||
// set rgb to analog led stripe
|
||||
void showAnalogRGB(const CRGB& led) {
|
||||
@ -86,7 +88,7 @@ void showAnalogRGB(const CRGB& led) {
|
||||
|
||||
// set color to all leds
|
||||
void showColor(const CRGB& led) {
|
||||
#if NUM_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
#if MAX_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
LEDS.showColor(led);
|
||||
#endif
|
||||
showAnalogRGB(led);
|
||||
@ -94,8 +96,8 @@ void showColor(const CRGB& led) {
|
||||
|
||||
// switch of digital and analog leds
|
||||
void switchOff() {
|
||||
#if NUM_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
|
||||
#if MAX_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
memset(leds, 0, MAX_LEDS * sizeof(struct CRGB));
|
||||
FastLED.show();
|
||||
#endif
|
||||
showAnalogRGB(leds[0]);
|
||||
@ -118,25 +120,25 @@ bool checkIncommingData() {
|
||||
|
||||
// main function that setups and runs the code
|
||||
void setup() {
|
||||
|
||||
// additional ground pin to make wiring a bit easier
|
||||
pinMode(ANALOG_GROUND_PIN, OUTPUT);
|
||||
digitalWrite(ANALOG_GROUND_PIN, LOW);
|
||||
Serial.begin(serialRate);
|
||||
|
||||
// analog output
|
||||
if (ANALOG_OUTPUT_ENABLED) {
|
||||
// additional ground pin to make wiring a bit easier
|
||||
pinMode(ANALOG_GROUND_PIN, OUTPUT);
|
||||
digitalWrite(ANALOG_GROUND_PIN, LOW);
|
||||
pinMode(ANALOG_BLUE_PIN , OUTPUT);
|
||||
pinMode(ANALOG_RED_PIN , OUTPUT);
|
||||
pinMode(ANALOG_GREEN_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
// Uncomment/edit one of the following lines for your leds arrangement.
|
||||
int ledCount = NUM_LEDS;
|
||||
int ledCount = MAX_LEDS;
|
||||
if (ANALOG_MODE == ANALOG_MODE_LAST_LED) {
|
||||
ledCount--;
|
||||
}
|
||||
|
||||
#if NUM_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
#if MAX_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
FastLED.addLeds<LED_TYPE, LED_PINS, COLOR_ORDER>(leds, ledCount);
|
||||
#endif
|
||||
|
||||
@ -147,14 +149,14 @@ void setup() {
|
||||
FastLED.setDither ( DITHER_MODE );
|
||||
|
||||
// initial RGB flash
|
||||
#if INITAL_LED_TEST_ENABLED == true
|
||||
showColor(CRGB(255, 0, 0)); delay(400);
|
||||
showColor(CRGB(0, 255, 0)); delay(400);
|
||||
showColor(CRGB(0, 0, 255)); delay(400);
|
||||
#if INITIAL_LED_TEST_ENABLED == true
|
||||
Serial.println("initial test");
|
||||
showColor(CRGB(INITIAL_LED_TEST_BRIGHTNESS, 0, 0)); delay(400);
|
||||
showColor(CRGB(0, INITIAL_LED_TEST_BRIGHTNESS, 0)); delay(400);
|
||||
showColor(CRGB(0, 0, INITIAL_LED_TEST_BRIGHTNESS )); delay(400);
|
||||
#endif
|
||||
showColor(CRGB(0, 0, 0));
|
||||
|
||||
Serial.begin(serialRate);
|
||||
Serial.print("Ada\n"); // Send "Magic Word" string to host
|
||||
|
||||
|
||||
@ -183,14 +185,16 @@ void setup() {
|
||||
// if checksum does not match go back to wait
|
||||
if (chk != (hi ^ lo ^ 0x55)) continue;
|
||||
|
||||
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
|
||||
memset(leds, 0, MAX_LEDS * sizeof(struct CRGB));
|
||||
transmissionSuccess = true;
|
||||
sum_r = 0;
|
||||
sum_g = 0;
|
||||
sum_b = 0;
|
||||
|
||||
int num_leds = (hi<<8) + lo + 1;
|
||||
|
||||
// read the transmission data and set LED values
|
||||
for (uint8_t idx = 0; idx < NUM_LEDS; idx++) {
|
||||
for (uint8_t idx = 0; idx < min(num_leds,MAX_LEDS); idx++) {
|
||||
byte r, g, b;
|
||||
if (!checkIncommingData()) {
|
||||
transmissionSuccess = false;
|
||||
@ -220,22 +224,22 @@ void setup() {
|
||||
// shows new values
|
||||
if (transmissionSuccess) {
|
||||
endTime = millis() + OFF_TIMEOUT;
|
||||
#if NUM_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
#if MAX_LEDS > 1 || ANALOG_OUTPUT_ENABLED == false
|
||||
FastLED.show();
|
||||
#endif
|
||||
|
||||
#if ANALOG_OUTPUT_ENABLED == true
|
||||
#if ANALOG_MODE == ANALOG_MODE_LAST_LED
|
||||
showAnalogRGB(leds[NUM_LEDS-1]);
|
||||
showAnalogRGB(leds[MAX_LEDS-1]);
|
||||
#else
|
||||
showAnalogRGB(CRGB(sum_r/NUM_LEDS, sum_g/NUM_LEDS, sum_b/NUM_LEDS));
|
||||
showAnalogRGB(CRGB(sum_r/MAX_LEDS, sum_g/MAX_LEDS, sum_b/MAX_LEDS));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // end of setup
|
||||
|
||||
|
||||
void loop() {
|
||||
// Not used. See note in setup() function.
|
||||
}
|
||||
|
||||
|
197
assets/firmware/arduino/network_bridge/udpraw_serialadalight.py
Executable file
197
assets/firmware/arduino/network_bridge/udpraw_serialadalight.py
Executable file
@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
|
||||
# Simple UDP to Serial redirector.
|
||||
# Author: https://github.com/penfold42
|
||||
|
||||
# raw udp packets to raw serial:
|
||||
# python.exe udp_adalight.py -P 2801 COM4 115200
|
||||
|
||||
# raw udp packets to adalight serial protocol:
|
||||
# python.exe udp_adalight.py -a -P 2801 COM4 115200
|
||||
|
||||
# Derived from: https://github.com/pyserial/pyserial/blob/master/examples/tcp_serial_redirect.py
|
||||
#
|
||||
# (C) 2002-2016 Chris Liechti <cliechti@gmx.net>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import sys
|
||||
import socket
|
||||
import serial
|
||||
import serial.threaded
|
||||
import time
|
||||
|
||||
|
||||
class SerialToNet(serial.threaded.Protocol):
|
||||
"""serial->socket"""
|
||||
|
||||
def __init__(self):
|
||||
self.socket = None
|
||||
|
||||
def __call__(self):
|
||||
return self
|
||||
|
||||
def data_received(self, data):
|
||||
if self.socket is not None:
|
||||
self.socket.sendall(data)
|
||||
|
||||
|
||||
if __name__ == '__main__': # noqa
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Simple UDP to Serial redirector.',
|
||||
epilog="""\
|
||||
NOTE: no security measures are implemented. Anyone can remotely connect
|
||||
to this service over the network.
|
||||
""")
|
||||
|
||||
parser.add_argument(
|
||||
'SERIALPORT',
|
||||
help="serial port name")
|
||||
|
||||
parser.add_argument(
|
||||
'BAUDRATE',
|
||||
type=int,
|
||||
nargs='?',
|
||||
help='set baud rate, default: %(default)s',
|
||||
default=115200)
|
||||
|
||||
parser.add_argument(
|
||||
'-q', '--quiet',
|
||||
action='store_true',
|
||||
help='suppress non error messages',
|
||||
default=False)
|
||||
|
||||
parser.add_argument(
|
||||
'-a', '--ada',
|
||||
action='store_true',
|
||||
help='prepend adalight header to serial packets',
|
||||
default=False)
|
||||
|
||||
parser.add_argument(
|
||||
'--develop',
|
||||
action='store_true',
|
||||
help='Development mode, prints Python internals on errors',
|
||||
default=False)
|
||||
|
||||
group = parser.add_argument_group('serial port')
|
||||
|
||||
group.add_argument(
|
||||
"--parity",
|
||||
choices=['N', 'E', 'O', 'S', 'M'],
|
||||
type=lambda c: c.upper(),
|
||||
help="set parity, one of {N E O S M}, default: N",
|
||||
default='N')
|
||||
|
||||
group.add_argument(
|
||||
'--rtscts',
|
||||
action='store_true',
|
||||
help='enable RTS/CTS flow control (default off)',
|
||||
default=False)
|
||||
|
||||
group.add_argument(
|
||||
'--xonxoff',
|
||||
action='store_true',
|
||||
help='enable software flow control (default off)',
|
||||
default=False)
|
||||
|
||||
group.add_argument(
|
||||
'--rts',
|
||||
type=int,
|
||||
help='set initial RTS line state (possible values: 0, 1)',
|
||||
default=None)
|
||||
|
||||
group.add_argument(
|
||||
'--dtr',
|
||||
type=int,
|
||||
help='set initial DTR line state (possible values: 0, 1)',
|
||||
default=None)
|
||||
|
||||
group = parser.add_argument_group('network settings')
|
||||
|
||||
exclusive_group = group.add_mutually_exclusive_group()
|
||||
|
||||
exclusive_group.add_argument(
|
||||
'-P', '--localport',
|
||||
type=int,
|
||||
help='local UDP port',
|
||||
default=2801)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# connect to serial port
|
||||
ser = serial.serial_for_url(args.SERIALPORT, do_not_open=True)
|
||||
ser.baudrate = args.BAUDRATE
|
||||
ser.parity = args.parity
|
||||
ser.rtscts = args.rtscts
|
||||
ser.xonxoff = args.xonxoff
|
||||
|
||||
if args.rts is not None:
|
||||
ser.rts = args.rts
|
||||
|
||||
if args.dtr is not None:
|
||||
ser.dtr = args.dtr
|
||||
|
||||
if not args.quiet:
|
||||
sys.stderr.write(
|
||||
'--- UDP to Serial redirector\n'
|
||||
'--- listening on udp port {a.localport}\n'
|
||||
'--- sending to {p.name} {p.baudrate},{p.bytesize}{p.parity}{p.stopbits}\n'
|
||||
'--- type Ctrl-C / BREAK to quit\n'.format(p=ser, a=args))
|
||||
|
||||
try:
|
||||
ser.open()
|
||||
except serial.SerialException as e:
|
||||
sys.stderr.write('Could not open serial port {}: {}\n'.format(ser.name, e))
|
||||
sys.exit(1)
|
||||
|
||||
ser_to_net = SerialToNet()
|
||||
serial_worker = serial.threaded.ReaderThread(ser, ser_to_net)
|
||||
serial_worker.start()
|
||||
|
||||
srv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind(('', args.localport))
|
||||
|
||||
try:
|
||||
intentional_exit = False
|
||||
while True:
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
data,addr = srv.recvfrom(1024)
|
||||
if not data:
|
||||
break
|
||||
|
||||
if args.ada:
|
||||
numleds = len(data)/3
|
||||
hi = (numleds-1)/256
|
||||
lo = (numleds-1)&255
|
||||
sum = hi^lo^0x55
|
||||
ser.write ("Ada"+ chr(hi) + chr(lo) + chr(sum))
|
||||
|
||||
ser.write(data) # get a bunch of bytes and send them
|
||||
except socket.error as msg:
|
||||
if args.develop:
|
||||
raise
|
||||
sys.stderr.write('ERROR: {}\n'.format(msg))
|
||||
# probably got disconnected
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
intentional_exit = True
|
||||
raise
|
||||
except socket.error as msg:
|
||||
if args.develop:
|
||||
raise
|
||||
sys.stderr.write('ERROR: {}\n'.format(msg))
|
||||
finally:
|
||||
ser_to_net.socket = None
|
||||
sys.stderr.write('Disconnected\n')
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
sys.stderr.write('\n--- exit ---\n')
|
||||
serial_worker.stop()
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
///
|
||||
/// free all alocated objects, should be called only from constructor or before restarting hyperion
|
||||
///
|
||||
void freeObjects();
|
||||
void freeObjects(bool emitCloseSignal=false);
|
||||
|
||||
static Hyperion* initInstance(const QJsonObject& qjsonConfig, const QString configFile);
|
||||
static Hyperion* getInstance();
|
||||
@ -289,6 +289,7 @@ signals:
|
||||
|
||||
void imageToLedsMappingChanged(int mappingType);
|
||||
void emitImage(int priority, const Image<ColorRgb> & image, const int timeout_ms);
|
||||
void closing();
|
||||
|
||||
private slots:
|
||||
///
|
||||
|
@ -21,8 +21,8 @@ public:
|
||||
static int load(const QString& schema, const QString& config, QJsonObject& json)
|
||||
{
|
||||
// Load the schema and the config trees
|
||||
QJsonObject schemaTree = readJson(schema);
|
||||
QJsonObject configTree = readJson(config);
|
||||
QJsonObject schemaTree = readSchema(schema);
|
||||
QJsonObject configTree = readConfig(config);
|
||||
|
||||
// create the validator
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
@ -45,15 +45,15 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QJsonObject readJson(const QString& path)
|
||||
static QJsonObject readConfig(const QString& path)
|
||||
{
|
||||
QFile file(path);
|
||||
QJsonParseError error;
|
||||
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::stringstream sstream;
|
||||
sstream << "Configuration file not found: " << file.errorString().toStdString();
|
||||
sstream << "Configuration file not found: '" << path.toStdString() << "' (" << file.errorString().toStdString() << ")";
|
||||
throw std::runtime_error(sstream.str());
|
||||
}
|
||||
|
||||
@ -61,12 +61,13 @@ public:
|
||||
config.remove(QRegularExpression("([^:]?\\/\\/.*)"));
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(config.toUtf8(), &error);
|
||||
|
||||
file.close();
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// report to the user the failure and their locations in the document.
|
||||
int errorLine(0), errorColumn(0);
|
||||
|
||||
|
||||
for( int i=0, count=qMin( error.offset,config.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
@ -76,13 +77,51 @@ public:
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "Failed to parse configuration: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
throw std::runtime_error(sstream.str());
|
||||
}
|
||||
|
||||
return doc.object();
|
||||
}
|
||||
|
||||
static QJsonObject readSchema(const QString& path)
|
||||
{
|
||||
QFile schemaData(path);
|
||||
QJsonParseError error;
|
||||
|
||||
if (!schemaData.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::stringstream sstream;
|
||||
sstream << "Schema not found: '" << path.toStdString() << "' (" << schemaData.errorString().toStdString() << ")";
|
||||
throw std::runtime_error(sstream.str());
|
||||
}
|
||||
|
||||
QByteArray schema = schemaData.readAll();
|
||||
QJsonDocument doc = QJsonDocument::fromJson(schema, &error);
|
||||
schemaData.close();
|
||||
|
||||
file.close();
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// report to the user the failure and their locations in the document.
|
||||
int errorLine(0), errorColumn(0);
|
||||
|
||||
for( int i=0, count=qMin( error.offset,schema.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(schema.at(i) == '\n' )
|
||||
{
|
||||
errorColumn = 0;
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "ERROR: Json schema wrong: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
throw std::runtime_error(sstream.str());
|
||||
}
|
||||
|
||||
return doc.object();
|
||||
}
|
||||
|
||||
|
@ -67,14 +67,6 @@ private:
|
||||
///
|
||||
void setMessage(const std::string & message);
|
||||
|
||||
///
|
||||
/// Retrieves all references from the json-value as specified by the schema
|
||||
///
|
||||
/// @param[in] value The json-value
|
||||
/// @param[in] schema The schema
|
||||
///
|
||||
void collectDependencies(const QJsonValue & value, const QJsonObject &schema);
|
||||
|
||||
private:
|
||||
// attribute check functions
|
||||
///
|
||||
@ -106,15 +98,6 @@ private:
|
||||
///
|
||||
void checkAdditionalProperties(const QJsonObject & value, const QJsonValue & schema, const QStringList & ignoredProperties);
|
||||
|
||||
///
|
||||
/// Checks if references are configued and used correctly. If this is not the case _error is set
|
||||
/// to true and an error-message is added to the message-queue.
|
||||
///
|
||||
/// @param value The given json-object
|
||||
/// @param schemaLink The schema of the json-object
|
||||
///
|
||||
void checkDependencies(const QJsonValue & value, const QJsonValue & schemaLink);
|
||||
|
||||
///
|
||||
/// Checks if the given value is larger or equal to the specified value. If this is not the case
|
||||
/// _error is set to true and an error-message is added to the message-queue.
|
||||
|
@ -74,6 +74,7 @@ V4L2Grabber::~V4L2Grabber()
|
||||
|
||||
void V4L2Grabber::uninit()
|
||||
{
|
||||
Debug(_log,"uninit grabber: %s", _deviceName.c_str());
|
||||
// stop if the grabber was not stopped
|
||||
if (_initialized)
|
||||
{
|
||||
|
@ -27,6 +27,8 @@ GrabberWrapper::GrabberWrapper(std::string grabberName, const int priority, hype
|
||||
|
||||
GrabberWrapper::~GrabberWrapper()
|
||||
{
|
||||
stop();
|
||||
Debug(_log,"Close grabber: %s", _grabberName.c_str());
|
||||
delete _processor;
|
||||
}
|
||||
|
||||
|
@ -447,8 +447,13 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
|
||||
}
|
||||
|
||||
|
||||
void Hyperion::freeObjects()
|
||||
void Hyperion::freeObjects(bool emitCloseSignal)
|
||||
{
|
||||
if (emitCloseSignal)
|
||||
{
|
||||
emit closing();
|
||||
}
|
||||
|
||||
// switch off all leds
|
||||
clearall();
|
||||
_device->switchOff();
|
||||
@ -462,7 +467,7 @@ void Hyperion::freeObjects()
|
||||
|
||||
Hyperion::~Hyperion()
|
||||
{
|
||||
freeObjects();
|
||||
freeObjects(false);
|
||||
}
|
||||
|
||||
unsigned Hyperion::getLedCount() const
|
||||
|
@ -892,7 +892,7 @@ void JsonClientConnection::handleConfigCommand(const QJsonObject& message, const
|
||||
}
|
||||
else if (subcommand == "reload")
|
||||
{
|
||||
_hyperion->freeObjects();
|
||||
_hyperion->freeObjects(true);
|
||||
Process::restartHyperion();
|
||||
sendErrorReply("failed to restart hyperion", full_command, tan);
|
||||
}
|
||||
@ -912,7 +912,7 @@ void JsonClientConnection::handleConfigGetCommand(const QJsonObject& message, co
|
||||
|
||||
try
|
||||
{
|
||||
result["result"] = QJsonFactory::readJson(QString::fromStdString(_hyperion->getConfigFileName()));
|
||||
result["result"] = QJsonFactory::readConfig(QString::fromStdString(_hyperion->getConfigFileName()));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -115,6 +115,7 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s
|
||||
else
|
||||
{
|
||||
// no check function defined for this attribute
|
||||
_error = true;
|
||||
setMessage(std::string("No check function defined for attribute ") + attribute.toStdString());
|
||||
continue;
|
||||
}
|
||||
|
@ -73,6 +73,13 @@ static inline void printErrorToReply (QtHttpReply * reply, QString errorMessage)
|
||||
reply->appendRawData (errorMessage.toLocal8Bit ());
|
||||
}
|
||||
|
||||
static inline void printError404ToReply (QtHttpReply * reply, QString errorMessage)
|
||||
{
|
||||
reply->setStatusCode(QtHttpReply::NotFound);
|
||||
reply->addHeader ("Content-Type", QByteArrayLiteral ("text/plain"));
|
||||
reply->appendRawData (errorMessage.toLocal8Bit ());
|
||||
}
|
||||
|
||||
void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpReply * reply)
|
||||
{
|
||||
QString command = request->getCommand ();
|
||||
@ -103,7 +110,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
Q_INIT_RESOURCE(WebConfig);
|
||||
|
||||
QFileInfo info(_baseUrl % "/" % path);
|
||||
if ( path == "/" || path.isEmpty() || ! info.exists() )
|
||||
if ( path == "/" || path.isEmpty() )
|
||||
{
|
||||
path = "index.html";
|
||||
}
|
||||
@ -134,7 +141,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
}
|
||||
else
|
||||
{
|
||||
printErrorToReply (reply, "Requested file " % path % " couldn't be found !");
|
||||
printError404ToReply (reply, "404 Not Found\n" % path % " couldn't be found !");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -23,7 +23,7 @@ WebConfig::WebConfig(QObject * parent)
|
||||
_baseUrl = webconfigConfig["document_root"].toString(_baseUrl);
|
||||
}
|
||||
|
||||
if (_baseUrl != ":/webconfig")
|
||||
if ( (_baseUrl != ":/webconfig") && !_baseUrl.trimmed().isEmpty())
|
||||
{
|
||||
QFileInfo info(_baseUrl);
|
||||
if (!info.exists() || !info.isDir())
|
||||
@ -32,6 +32,8 @@ WebConfig::WebConfig(QObject * parent)
|
||||
_baseUrl = WEBCONFIG_DEFAULT_PATH;
|
||||
}
|
||||
}
|
||||
else
|
||||
_baseUrl = WEBCONFIG_DEFAULT_PATH;
|
||||
|
||||
Debug(log, "WebUI initialized, document root: %s", _baseUrl.toUtf8().constData());
|
||||
if ( webconfigEnable )
|
||||
|
@ -1,11 +1,18 @@
|
||||
|
||||
SET(Hyperiond_QT_HEADERS
|
||||
hyperiond.h
|
||||
)
|
||||
|
||||
QT5_WRAP_CPP(Hyperiond_HEADERS_MOC ${Hyperiond_QT_HEADERS})
|
||||
|
||||
add_executable(hyperiond
|
||||
${Hyperiond_QT_HEADERS}
|
||||
${Hyperiond_HEADERS_MOC}
|
||||
configMigratorBase.cpp
|
||||
configMigratorBase.h
|
||||
configMigrator.cpp
|
||||
configMigrator.h
|
||||
hyperiond.cpp
|
||||
hyperiond.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
@ -79,6 +79,13 @@ HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
|
||||
|
||||
HyperionDaemon::~HyperionDaemon()
|
||||
{
|
||||
freeObjects();
|
||||
delete _hyperion;
|
||||
}
|
||||
|
||||
void HyperionDaemon::freeObjects()
|
||||
{
|
||||
Debug(_log, "destroy grabbers and network stuff");
|
||||
delete _amlGrabber;
|
||||
delete _dispmanx;
|
||||
delete _fbGrabber;
|
||||
@ -92,8 +99,17 @@ HyperionDaemon::~HyperionDaemon()
|
||||
delete _protoServer;
|
||||
delete _boblightServer;
|
||||
delete _udpListener;
|
||||
delete _hyperion;
|
||||
|
||||
_v4l2Grabbers.clear();
|
||||
_amlGrabber = nullptr;
|
||||
_dispmanx = nullptr;
|
||||
_fbGrabber = nullptr;
|
||||
_osxGrabber = nullptr;
|
||||
_kodiVideoChecker = nullptr;
|
||||
_jsonServer = nullptr;
|
||||
_protoServer = nullptr;
|
||||
_boblightServer = nullptr;
|
||||
_udpListener = nullptr;
|
||||
}
|
||||
|
||||
void HyperionDaemon::run()
|
||||
@ -113,56 +129,33 @@ void HyperionDaemon::run()
|
||||
#endif
|
||||
Info(_log, "Hyperion started");
|
||||
|
||||
|
||||
connect(_hyperion,SIGNAL(closing()),this,SLOT(freeObjects()));
|
||||
}
|
||||
|
||||
int HyperionDaemon::tryLoadConfig(const QString & configFile, const int schemaVersion)
|
||||
{
|
||||
// make sure the resources are loaded (they may be left out after static linking)
|
||||
Q_INIT_RESOURCE(resource);
|
||||
QJsonParseError error;
|
||||
|
||||
// read the json schema from the resource
|
||||
QString schemaFile = ":/hyperion-schema";
|
||||
if (schemaVersion > 0)
|
||||
schemaFile += "-" + QString::number(schemaVersion);
|
||||
QFile schemaData(schemaFile);
|
||||
if (!schemaData.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Schema not found or not supported: " << schemaData.errorString().toStdString();
|
||||
throw std::runtime_error(error.str());
|
||||
}
|
||||
|
||||
QByteArray schema = schemaData.readAll();
|
||||
QJsonDocument schemaJson = QJsonDocument::fromJson(schema, &error);
|
||||
schemaData.close();
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// report to the user the failure and their locations in the document.
|
||||
int errorLine(0), errorColumn(0);
|
||||
|
||||
for( int i=0, count=qMin( error.offset,schema.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(schema.at(i) == '\n' )
|
||||
{
|
||||
errorColumn = 0;
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "ERROR: Json schema wrong: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
schemaFile += "-" + QString::number(schemaVersion);
|
||||
|
||||
throw std::runtime_error(sstream.str());
|
||||
QJsonObject schemaJson;
|
||||
try
|
||||
{
|
||||
schemaJson = QJsonFactory::readSchema(schemaFile);
|
||||
}
|
||||
catch(const std::runtime_error& error)
|
||||
{
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaJson.object());
|
||||
schemaChecker.setSchema(schemaJson);
|
||||
|
||||
_qconfig = QJsonFactory::readJson(configFile);
|
||||
_qconfig = QJsonFactory::readConfig(configFile);
|
||||
if (!schemaChecker.validate(_qconfig))
|
||||
{
|
||||
for (std::list<std::string>::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i)
|
||||
@ -177,7 +170,6 @@ int HyperionDaemon::tryLoadConfig(const QString & configFile, const int schemaVe
|
||||
return generalConfig["configVersion"].toInt(-1);
|
||||
}
|
||||
|
||||
|
||||
void HyperionDaemon::loadConfig(const QString & configFile, const int neededConfigVersion)
|
||||
{
|
||||
Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData());
|
||||
@ -472,7 +464,7 @@ void HyperionDaemon::createSystemFrameGrabber()
|
||||
else if (type == "x11") createGrabberX11(grabberConfig);
|
||||
else { Warning( _log, "unknown framegrabber type '%s'", type.toUtf8().constData()); grabberCompState = false; }
|
||||
|
||||
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_GRABBER, grabberCompState);
|
||||
// _hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_GRABBER, grabberCompState);
|
||||
_hyperion->setComponentState(hyperion::COMP_GRABBER, grabberCompState );
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
class HyperionDaemon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HyperionDaemon(QString configFile, QObject *parent=nullptr);
|
||||
~HyperionDaemon();
|
||||
@ -65,6 +66,9 @@ public:
|
||||
void createGrabberV4L2();
|
||||
void createSystemFrameGrabber();
|
||||
|
||||
public slots:
|
||||
void freeObjects();
|
||||
|
||||
private:
|
||||
void createGrabberDispmanx();
|
||||
void createGrabberAmlogic();
|
||||
|
@ -16,53 +16,30 @@ bool loadConfig(const QString & configFile)
|
||||
{
|
||||
// make sure the resources are loaded (they may be left out after static linking)
|
||||
Q_INIT_RESOURCE(resource);
|
||||
QJsonParseError error;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// read and set the json schema from the resource
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
QFile schemaData(":/hyperion-schema-"+QString::number(CURRENT_CONFIG_VERSION));
|
||||
|
||||
if (!schemaData.open(QIODevice::ReadOnly))
|
||||
QJsonObject schemaJson;
|
||||
|
||||
try
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Schema not found: " << schemaData.errorString().toStdString();
|
||||
throw std::runtime_error(error.str());
|
||||
schemaJson = QJsonFactory::readSchema(":/hyperion-schema");
|
||||
}
|
||||
|
||||
QByteArray schema = schemaData.readAll();
|
||||
QJsonDocument schemaJson = QJsonDocument::fromJson(schema, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
catch(const std::runtime_error& error)
|
||||
{
|
||||
// report to the user the failure and their locations in the document.
|
||||
int errorLine(0), errorColumn(0);
|
||||
|
||||
for( int i=0, count=qMin( error.offset,schema.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(schema.at(i) == '\n' )
|
||||
{
|
||||
errorColumn = 0;
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "Schema error: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
|
||||
throw std::runtime_error(sstream.str());
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaJson.object());
|
||||
schemaChecker.setSchema(schemaJson);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// read and validate the configuration file from the command line
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
const QJsonObject jsonConfig = QJsonFactory::readJson(configFile);
|
||||
const QJsonObject jsonConfig = QJsonFactory::readConfig(configFile);
|
||||
|
||||
if (!schemaChecker.validate(jsonConfig))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user