IPv6 support (#1369)

* hyperion-remote - Support IPv6

* LEDDevices - Remove IPv6 limitations

* Separate JsonEditorHostValidation

* Standalone grabbers & JSON/Flatbuffer forwarder: IPv6 support

* remote: Fix setting multiple colors via Hex, add standard logging

* IPv6 Updates -Add db migration activities

* Addressing non-Windows compile issues

* Code cleanup, address clang feedback

* Update address (hostname, IPv4/IPv6) help text

* Apply migration steps to "old" configurations imported

* Show user the UI-Url, if hyperion is already running, address clang findings

* Windows Cmake OpenSLL output

* Minor Text update
This commit is contained in:
LordGrey 2021-11-17 20:30:43 +00:00 committed by GitHub
parent b33466d392
commit ad293b2fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 1714 additions and 926 deletions

View File

@ -10,10 +10,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- hyperion-remote & standalone grabbers: IPv6 support
### Changed ### Changed
- LED-Devices: Removed IPv6 limitations
- Philips-Hue Wizard optimizations
- JSON/Flatbuffer forwarder: Removed IPv6 limitations
- Allow to import configurations from previous versions
Note: Existing configurations are migrated to new structures automatically
### Fixed ### Fixed
- Fixed hyperion-remote when sending multiple Hex-Colors with "Set Color" option
### Removed ### Removed
## [2.0.0-alpha.11](https://github.com/hyperion-project/hyperion.ng/releases/tag/2.0.0-alpha.11) - 2021-10-06 ## [2.0.0-alpha.11](https://github.com/hyperion-project/hyperion.ng/releases/tag/2.0.0-alpha.11) - 2021-10-06

View File

@ -581,9 +581,9 @@
"edt_dev_spec_switchOffOnBlack_title": "Switch off on black", "edt_dev_spec_switchOffOnBlack_title": "Switch off on black",
"edt_dev_spec_switchOffOnbelowMinBrightness_title": "Switch-off, below minimum", "edt_dev_spec_switchOffOnbelowMinBrightness_title": "Switch-off, below minimum",
"edt_dev_spec_syncOverwrite_title": "Disable synchronisation", "edt_dev_spec_syncOverwrite_title": "Disable synchronisation",
"edt_dev_spec_targetIpHost_title": "Target Hostname/IP-address", "edt_dev_spec_targetIpHost_title": "Hostname/IP-address",
"edt_dev_spec_targetIpHost_title_info": "The device's hostname or IP-address", "edt_dev_spec_targetIpHost_title_info": "The device's hostname or IP-address",
"edt_dev_spec_targetIp_title": "Target IP-address", "edt_dev_spec_targetIp_title": "IP-address",
"edt_dev_spec_transeffect_title": "Transition effect", "edt_dev_spec_transeffect_title": "Transition effect",
"edt_dev_spec_transistionTimeExtra_title": "Extra time darkness", "edt_dev_spec_transistionTimeExtra_title": "Extra time darkness",
"edt_dev_spec_transistionTime_title": "Transition time", "edt_dev_spec_transistionTime_title": "Transition time",
@ -735,6 +735,10 @@
"edt_msg_error_disallow": "Value must not be of type $1", "edt_msg_error_disallow": "Value must not be of type $1",
"edt_msg_error_disallow_union": "Value must not be one of the provided disallowed types", "edt_msg_error_disallow_union": "Value must not be one of the provided disallowed types",
"edt_msg_error_enum": "Value must be one of the enumerated values", "edt_msg_error_enum": "Value must be one of the enumerated values",
"edt_msg_error_hostname": "The hostname has the wrong format",
"edt_msg_error_invalid_epoch": "Date must be greater than 1 January 1970",
"edt_msg_error_ipv4": "Value must be a valid IPv4 address in the form of 4 numbers between 0 and 255, separated by dots",
"edt_msg_error_ipv6": "Value must be a valid IPv6 address",
"edt_msg_error_maxItems": "Value must have at most $1 items", "edt_msg_error_maxItems": "Value must have at most $1 items",
"edt_msg_error_maxLength": "Value must be at most $1 characters long", "edt_msg_error_maxLength": "Value must be at most $1 characters long",
"edt_msg_error_maxProperties": "Object must have at most $1 properties", "edt_msg_error_maxProperties": "Object must have at most $1 properties",
@ -755,6 +759,8 @@
"edt_msg_error_type": "Value must be of type $1", "edt_msg_error_type": "Value must be of type $1",
"edt_msg_error_type_union": "Value must be one of the provided types", "edt_msg_error_type_union": "Value must be one of the provided types",
"edt_msg_error_uniqueItems": "Array must have unique items", "edt_msg_error_uniqueItems": "Array must have unique items",
"edt_msgcust_error_hostname_ip": "Not a valid Hostname nor IPv4 nor IPv6",
"edt_msgcust_error_hostname_ip4": "Not a valid Hostname nor IPv4",
"effectsconfigurator_button_conttest": "Continuous test", "effectsconfigurator_button_conttest": "Continuous test",
"effectsconfigurator_button_deleffect": "Delete Effect", "effectsconfigurator_button_deleffect": "Delete Effect",
"effectsconfigurator_button_editeffect": "Load Effect", "effectsconfigurator_button_editeffect": "Load Effect",
@ -979,15 +985,15 @@
"wiz_cololight_title": "Cololight Wizard", "wiz_cololight_title": "Cololight Wizard",
"wiz_guideyou": "The $1 will guide you through the settings. Just press the button!", "wiz_guideyou": "The $1 will guide you through the settings. Just press the button!",
"wiz_hue_blinkblue": "Let ID $1 light up blue", "wiz_hue_blinkblue": "Let ID $1 light up blue",
"wiz_hue_clientkey": "Clientkey:", "wiz_hue_clientkey": "Clientkey",
"wiz_hue_create_user": "Create new User", "wiz_hue_create_user": "Create new User",
"wiz_hue_desc1": "It searches automatically for a Hue-Bridge, in case it can't find one you need to provide the IP-address and push the reload button on the right. Now you need a user ID, if you don't have one create a new one.", "wiz_hue_desc1": "1. Hyperion searches automatically for a Hue-Bridge, in case it cannot find one you need to provide the hostname or IP-address and push the reload button. <br> 2. Provide a user ID, if you do not have one create a new one.",
"wiz_hue_desc2": "Now choose which lamps should be added. The position assigns the lamp to a specific position on your \"picture\". Disabled lamps won't be added. To identify single lamps press the button on the right.", "wiz_hue_desc2": "3. Now choose which lamps should be added. The position assigns the lamp to a specific position on your \"picture\". Disabled lamps won't be added. To identify single lamps press the button on the right.",
"wiz_hue_e_clientkey_needed": "A clientkey that matches the username is required to use the entertainment API. Please enter an existing one or use the button below to create a new one.", "wiz_hue_e_clientkey_needed": "A clientkey that matches the username is required to use the entertainment API. Please enter an existing one or use the button below to create a new one.",
"wiz_hue_e_create_user": "Create new User and clientkey", "wiz_hue_e_create_user": "Create new User and clientkey",
"wiz_hue_e_desc1": "It searches automatically for a hue bridge, in case it can't find one you need to provide the ip address and push the reload button on the right. Now you need a user id and the clientkey, if you don't have both, create a new one.", "wiz_hue_e_desc1": "1. Hyperion searches automatically for a Hue-Bridge, in case it cannot find one you need to provide the hostname or IP-address and push the reload button. <br> 2. Provide a user id and the clientkey, if you do not have both, create new ones.",
"wiz_hue_e_desc2": "Now choose your entertainment group, which has all your lights inside for use with Hyperion.", "wiz_hue_e_desc2": "3. Choose your entertainment group, which has all your lights inside for use with Hyperion.",
"wiz_hue_e_desc3": "Now you can choose in which position the respective lamp should be \"in the picture\". A preselection of the position was made based on the configured positions of the lights in the entertainment group. This is just a recommendation and can be customized as desired. You can therefore highlight them briefly by clicking on the right button to improve the selection.", "wiz_hue_e_desc3": "4. Choose in which position the respective lamp should be \"in the picture\". A preselection of the position was made based on the configured positions of the lights in the entertainment group. This is just a recommendation and can be customized as desired. You can therefore highlight them briefly by clicking on the right button to improve the selection.",
"wiz_hue_e_intro1": "This wizards configures Hyperion for the well known Philips Hue Entertainment system. Features are: Hue Bridge auto detection, user and clientkey creation, entertainment group selection, setting group lights to a specific position on your picture and optimise the Hyperion settings automatically! So in short: All you need are some clicks and you are done!", "wiz_hue_e_intro1": "This wizards configures Hyperion for the well known Philips Hue Entertainment system. Features are: Hue Bridge auto detection, user and clientkey creation, entertainment group selection, setting group lights to a specific position on your picture and optimise the Hyperion settings automatically! So in short: All you need are some clicks and you are done!",
"wiz_hue_e_noapisupport": "The Wizard has disabled entertainment API support and will continue in classic mode.", "wiz_hue_e_noapisupport": "The Wizard has disabled entertainment API support and will continue in classic mode.",
"wiz_hue_e_noapisupport_hint": "The option \"<b>Use Hue Entertainment API</b>\" was unchecked.", "wiz_hue_e_noapisupport_hint": "The option \"<b>Use Hue Entertainment API</b>\" was unchecked.",
@ -997,15 +1003,15 @@
"wiz_hue_e_use_group": "Use group", "wiz_hue_e_use_group": "Use group",
"wiz_hue_e_use_groupid": "Use group ID $1", "wiz_hue_e_use_groupid": "Use group ID $1",
"wiz_hue_failure_connection": "Timeout: Please press the bridge button within the period of 30 seconds", "wiz_hue_failure_connection": "Timeout: Please press the bridge button within the period of 30 seconds",
"wiz_hue_failure_ip": "No Bridge found, please type in a valid IP-Address", "wiz_hue_failure_ip": "No Bridge found, please provide a valid hostname or IP-address",
"wiz_hue_failure_user": "User not found, create a new one with the button below or input a valid user id and press the \"reload\" symbol.", "wiz_hue_failure_user": "User not found, create a new one with the button below or input a valid user id and press the \"reload\" symbol.",
"wiz_hue_intro1": "This wizards configures Hyperion for the well known Philips Hue system. Features are Hue Bridge auto detection, user creation, set each hue light to a specific position on your picture or disable it and tune the Hyperion settings automatically! So in short: All you need are some clicks and you are done!", "wiz_hue_intro1": "This wizards configures Hyperion for the well known Philips Hue system. Features are Hue Bridge auto detection, user creation, set each hue light to a specific position on your picture or disable it and tune the Hyperion settings automatically! So in short: All you need are some clicks and you are done!",
"wiz_hue_ip": "Hue Bridge IP:", "wiz_hue_ip": "Hostname or IP",
"wiz_hue_noids": "This Hue bridge has no bulbs/stripes, please pair them before with the Hue Apps", "wiz_hue_noids": "This Hue bridge has no bulbs/stripes, please pair them before with the Hue Apps",
"wiz_hue_press_link": "Please press link button on the Hue Bridge.", "wiz_hue_press_link": "Please press link button on the Hue Bridge.",
"wiz_hue_searchb": "Searching for bridge...", "wiz_hue_searchb": "Searching for bridge...",
"wiz_hue_title": "Philips Hue Wizard", "wiz_hue_title": "Philips Hue Wizard",
"wiz_hue_username": "User ID:", "wiz_hue_username": "User ID",
"wiz_identify": "Identify", "wiz_identify": "Identify",
"wiz_identify_tip": "Identify configured device by lighting it up", "wiz_identify_tip": "Identify configured device by lighting it up",
"wiz_identify_light": "Identify $1", "wiz_identify_light": "Identify $1",
@ -1021,6 +1027,7 @@
"wiz_rgb_qrend": "...red?", "wiz_rgb_qrend": "...red?",
"wiz_rgb_switchevery": "Switch color every...", "wiz_rgb_switchevery": "Switch color every...",
"wiz_rgb_title": "RGB Byte Order Wizard", "wiz_rgb_title": "RGB Byte Order Wizard",
"wiz_cc_try_connect": "Connecting...",
"wiz_wizavail": "Wizard available", "wiz_wizavail": "Wizard available",
"wiz_yeelight_desc2": "Now choose which lamps should be added. The position assigns the lamp to a specific position on your \"picture\". Disabled lamps won't be added. To identify single lamps press the button on the right.", "wiz_yeelight_desc2": "Now choose which lamps should be added. The position assigns the lamp to a specific position on your \"picture\". Disabled lamps won't be added. To identify single lamps press the button on the right.",
"wiz_yeelight_intro1": "This wizards configures Hyperion for the Yeelight system. Features are the Yeelighs' auto detection, setting each light to a specific position on your picture or disable it and tune the Hyperion settings automatically! So in short: All you need are some clicks and you are done!", "wiz_yeelight_intro1": "This wizards configures Hyperion for the Yeelight system. Features are the Yeelighs' auto detection, setting each light to a specific position on your picture or disable it and tune the Hyperion settings automatically! So in short: All you need are some clicks and you are done!",

View File

@ -144,7 +144,7 @@ $(document).ready(function () {
showInfoDialog('import', $.i18n('infoDialog_import_confirm_title'), $.i18n('infoDialog_import_confirm_text', confName)); showInfoDialog('import', $.i18n('infoDialog_import_confirm_title'), $.i18n('infoDialog_import_confirm_text', confName));
$('#id_btn_import').off().on('click', function () { $('#id_btn_import').off().on('click', function () {
requestWriteConfig(importedConf, true); requestRestoreConfig(importedConf);
setTimeout(initRestart, 100); setTimeout(initRestart, 100);
}); });
}); });

View File

@ -641,6 +641,8 @@ $(document).ready(function () {
// External properties properties, 2-dimensional arry of [ledType][key] // External properties properties, 2-dimensional arry of [ledType][key]
devicesProperties = {}; devicesProperties = {};
addJsonEditorHostValidation();
$("#leddevices").off().on("change", function () { $("#leddevices").off().on("change", function () {
var generalOptions = window.serverSchema.properties.device; var generalOptions = window.serverSchema.properties.device;
@ -1629,8 +1631,7 @@ function updateElements(ledType, key) {
if (ledProperties && ledProperties.leds && ledProperties.maxLedCount) { if (ledProperties && ledProperties.leds && ledProperties.maxLedCount) {
hardwareLedCount = ledProperties.leds.count; hardwareLedCount = ledProperties.leds.count;
var maxLedCount = ledProperties.maxLedCount var maxLedCount = ledProperties.maxLedCount
if (hardwareLedCount > maxLedCount) if (hardwareLedCount > maxLedCount) {
{
showInfoDialog('warning', $.i18n("conf_leds_config_warning"), $.i18n('conf_leds_error_hwled_gt_maxled', hardwareLedCount, maxLedCount, maxLedCount)); showInfoDialog('warning', $.i18n("conf_leds_config_warning"), $.i18n('conf_leds_error_hwled_gt_maxled', hardwareLedCount, maxLedCount, maxLedCount));
hardwareLedCount = maxLedCount; hardwareLedCount = maxLedCount;
} }
@ -1661,8 +1662,7 @@ function updateElements(ledType, key) {
if (ledProperties && ledProperties.maxLedCount) { if (ledProperties && ledProperties.maxLedCount) {
hardwareLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount").getValue(); hardwareLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount").getValue();
var maxLedCount = ledProperties.maxLedCount var maxLedCount = ledProperties.maxLedCount
if (hardwareLedCount > maxLedCount) if (hardwareLedCount > maxLedCount) {
{
showInfoDialog('warning', $.i18n("conf_leds_config_warning"), $.i18n('conf_leds_error_hwled_gt_maxled', hardwareLedCount, maxLedCount, maxLedCount)); showInfoDialog('warning', $.i18n("conf_leds_config_warning"), $.i18n('conf_leds_error_hwled_gt_maxled', hardwareLedCount, maxLedCount, maxLedCount));
hardwareLedCount = maxLedCount; hardwareLedCount = maxLedCount;
} }

View File

@ -10,6 +10,8 @@ $(document).ready(function () {
var conf_editor_bobl = null; var conf_editor_bobl = null;
var conf_editor_forw = null; var conf_editor_forw = null;
addJsonEditorHostValidation();
if (window.showOptHelp) { if (window.showOptHelp) {
//network //network
$('#conf_cont').append(createRow('conf_cont_net')) $('#conf_cont').append(createRow('conf_cont_net'))

View File

@ -410,6 +410,10 @@ function requestWriteConfig(config, full)
sendToHyperion("config","setconfig", '"config":'+JSON.stringify(window.serverConfig)); sendToHyperion("config","setconfig", '"config":'+JSON.stringify(window.serverConfig));
} }
function requestRestoreConfig(config) {
sendToHyperion("config", "restoreconfig", '"config":' + JSON.stringify(config));
}
function requestWriteEffect(effectName,effectPy,effectArgs,data) function requestWriteEffect(effectName,effectPy,effectArgs,data)
{ {
var cutArgs = effectArgs.slice(1, -1); var cutArgs = effectArgs.slice(1, -1);

View File

@ -681,6 +681,68 @@ function updateJsonEditorRange(rootEditor, path, key, minimum, maximum, defaultV
rootEditor.getEditor(path + "." + key).setValue(currentValue); rootEditor.getEditor(path + "." + key).setValue(currentValue);
} }
function addJsonEditorHostValidation() {
JSONEditor.defaults.custom_validators.push(function (schema, value, path) {
var errors = [];
if (!jQuery.isEmptyObject(value)) {
switch (schema.format) {
case "hostname_or_ip":
if (!isValidHostnameOrIP(value)) {
errors.push({
path: path,
property: 'format',
message: $.i18n('edt_msgcust_error_hostname_ip')
});
}
break;
case "hostname_or_ip4":
if (!isValidHostnameOrIP4(value)) {
errors.push({
path: path,
property: 'format',
message: $.i18n('edt_msgcust_error_hostname_ip4')
});
}
break;
//Remove, when new json-editor 2.x is used
case "ipv4":
if (!isValidIPv4(value)) {
errors.push({
path: path,
property: 'format',
message: $.i18n('edt_msg_error_ipv4')
});
}
break;
case "ipv6":
if (!isValidIPv6(value)) {
errors.push({
path: path,
property: 'format',
message: $.i18n('edt_msg_error_ipv6')
});
}
break;
case "hostname":
if (!isValidHostname(value)) {
errors.push({
path: path,
property: 'format',
message: $.i18n('edt_msg_error_hostname')
});
}
break;
default:
}
}
return errors;
});
}
function buildWL(link, linkt, cl) { function buildWL(link, linkt, cl) {
var baseLink = "https://docs.hyperion-project.org/"; var baseLink = "https://docs.hyperion-project.org/";
var lang; var lang;
@ -1246,3 +1308,42 @@ function showInputOptionsForKey(editor, item, showForKeys, state) {
function encodeHTML(s) { function encodeHTML(s) {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;'); return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
} }
function isValidIPv4(value) {
const parts = value.split('.')
if (parts.length !== 4) {
return false;
}
for (let part of parts) {
if (isNaN(part) || part < 0 || part > 255) {
return false;
}
}
return true;
}
function isValidIPv6(value) {
if (value.match(
'^(?:(?:(?:[a-fA-F0-9]{1,4}:){6}|(?=(?:[a-fA-F0-9]{0,4}:){2,6}(?:[0-9]{1,3}.){3}[0-9]{1,3}$)(([0-9a-fA-F]{1,4}:){1,5}|:)((:[0-9a-fA-F]{1,4}){1,5}:|:)|::(?:[a-fA-F0-9]{1,4}:){5})(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]).){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}|(?=(?:[a-fA-F0-9]{0,4}:){0,7}[a-fA-F0-9]{0,4}$)(([0-9a-fA-F]{1,4}:){1,7}|:)((:[0-9a-fA-F]{1,4}){1,7}|:)|(?:[a-fA-F0-9]{1,4}:){7}:|:(:[a-fA-F0-9]{1,4}){7})$'
))
return true;
else
return false;
}
function isValidHostname(value) {
if (value.match(
'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9].)+[a-zA-Z]{2,63}$)'
))
return true;
else
return false;
}
function isValidHostnameOrIP4(value) {
return (isValidHostname(value) || isValidIPv4(value));
}
function isValidHostnameOrIP(value) {
return (isValidHostnameOrIP4(value) || isValidIPv6(value));
}

View File

@ -5,6 +5,10 @@ $(window.hyperion).one("ready", function (event) {
setStorage("wizardactive", false); setStorage("wizardactive", false);
if (getStorage("kodiAddress") != null) { if (getStorage("kodiAddress") != null) {
kodiAddress = getStorage("kodiAddress"); kodiAddress = getStorage("kodiAddress");
if (getStorage("kodiPort") != null) {
kodiPort = getStorage("kodiPort");
}
sendToKodi("stop"); sendToKodi("stop");
} }
} }
@ -156,9 +160,14 @@ $('#btn_wizard_byteorder').off().on('click', startWizardRGB);
//color calibration wizard //color calibration wizard
var kodiHost = document.location.hostname; const defaultKodiPort = 9090;
var kodiPort = 9090;
var kodiAddress = kodiHost; var kodiAddress = document.location.hostname;
var kodiPort = defaultKodiPort;
var kodiUrl = new URL("ws://" + kodiAddress);
kodiUrl.port = kodiPort;
kodiUrl.pathname = "/jsonrpc/websocket";
var wiz_editor; var wiz_editor;
var colorLength; var colorLength;
@ -175,14 +184,12 @@ var availVideos = ["Sweet_Cocoon", "Caminandes_2_GranDillama", "Caminandes_3_Lla
if (getStorage("kodiAddress") != null) { if (getStorage("kodiAddress") != null) {
kodiAddress = getStorage("kodiAddress"); kodiAddress = getStorage("kodiAddress");
[kodiHost, kodiPort] = kodiAddress.split(":", 2); kodiUrl.host = kodiAddress;
// Ensure that Kodi's default REST-API port is not used, as now the Web-Socket port is used
if (kodiPort === "8080") {
kodiAddress = kodiHost;
kodiPort = undefined;
setStorage("kodiAddress", kodiAddress);
} }
if (getStorage("kodiPort") != null) {
kodiPort = getStorage("kodiPort");
kodiUrl.port = kodiPort;
} }
function switchPicture(pictures) { function switchPicture(pictures) {
@ -221,12 +228,11 @@ function sendToKodi(type, content, cb) {
} }
if ("WebSocket" in window) { if ("WebSocket" in window) {
//Add kodi default web-socket port, in case port has been explicitly provided
if (kodiPort == undefined) {
kodiPort = 9090;
}
var ws = new WebSocket("ws://" + kodiHost + ":" + kodiPort + "/jsonrpc/websocket"); if (kodiUrl.port === '') {
kodiUrl.port = defaultKodiPort;
}
var ws = new WebSocket(kodiUrl);
ws.onopen = function () { ws.onopen = function () {
ws.send(JSON.stringify(command)); ws.send(JSON.stringify(command));
@ -234,13 +240,18 @@ function sendToKodi(type, content, cb) {
ws.onmessage = function (evt) { ws.onmessage = function (evt) {
var response = JSON.parse(evt.data); var response = JSON.parse(evt.data);
if (response.method === "System.OnQuit") {
ws.close();
} else {
if (cb != undefined) { if (cb != undefined) {
if (response.result != undefined) { if (response.result != undefined) {
if (response.result === "OK") { if (response.result === "OK") {
cb("success"); cb("success");
ws.close();
} else { } else {
cb("error"); cb("error");
ws.close();
}
} }
} }
} }
@ -249,8 +260,13 @@ function sendToKodi(type, content, cb) {
ws.onerror = function (evt) { ws.onerror = function (evt) {
if (cb != undefined) { if (cb != undefined) {
cb("error"); cb("error");
ws.close();
} }
}; };
ws.onclose = function (evt) {
};
} }
else { else {
console.log("Kodi Access: WebSocket NOT supported by this browser"); console.log("Kodi Access: WebSocket NOT supported by this browser");
@ -419,18 +435,24 @@ function updateWEditor(el, all) {
function startWizardCC() { function startWizardCC() {
// Ensure that Kodi's default REST-API port is not used, as now the Web-Socket port is used
[kodiHost, kodiPort] = kodiAddress.split(":", 2);
if (kodiPort === "8080") {
kodiAddress = kodiHost;
kodiPort = undefined;
}
//create html //create html
$('#wiz_header').html('<i class="fa fa-magic fa-fw"></i>' + $.i18n('wiz_cc_title')); $('#wiz_header').html('<i class="fa fa-magic fa-fw"></i>' + $.i18n('wiz_cc_title'));
$('#wizp1_body').html('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n('wiz_cc_title') + '</h4><p>' + $.i18n('wiz_cc_intro1') + '</p><label>' + $.i18n('wiz_cc_kwebs') + '</label><input class="form-control" style="width:170px;margin:auto" id="wiz_cc_kodiip" type="text" placeholder="' + kodiAddress + '" value="' + kodiAddress + '" /><span id="kodi_status"></span><span id="multi_cali"></span>'); $('#wizp1_body').html('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n('wiz_cc_title') + '</h4>' +
$('#wizp1_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_cont" disabled="disabled"><i class="fa fa-fw fa-check"></i>' + $.i18n('general_btn_continue') + '</button><button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>'); '<p>' + $.i18n('wiz_cc_intro1') + '</p>' +
$('#wizp2_body').html('<div id="wiz_cc_desc" style="font-weight:bold"></div><div id="editor_container_wiz"></div>'); '<label>' + $.i18n('wiz_cc_kwebs') + '</label>' +
$('#wizp2_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_back"><i class="fa fa-fw fa-chevron-left"></i>' + $.i18n('general_btn_back') + '</button><button type="button" class="btn btn-primary" id="btn_wiz_next">' + $.i18n('general_btn_next') + '<i style="margin-left:4px;"class="fa fa-fw fa-chevron-right"></i></button><button type="button" class="btn btn-warning" id="btn_wiz_save" style="display:none"><i class="fa fa-fw fa-save"></i>' + $.i18n('general_btn_save') + '</button><button type="button" class="btn btn-danger" id="btn_wiz_abort"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>'); '<input class="form-control" style="width:280px;margin:auto" id="wiz_cc_kodiip" type="text" placeholder="' + kodiAddress + '" value="' + kodiAddress + '" />' +
'<span id="kodi_status"></span><span id="multi_cali"></span>'
);
$('#wizp1_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_cont" disabled="disabled">' + '<i class="fa fa-fw fa-check"></i>' + $.i18n('general_btn_continue') + '</button>' +
'<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>'
);
$('#wizp2_body').html('<div id="wiz_cc_desc" style="font-weight:bold"></div><div id="editor_container_wiz"></div>'
);
$('#wizp2_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_back">' + '<i class="fa fa-fw fa-chevron-left"></i>' + $.i18n('general_btn_back') + '</button>' +
'<button type="button" class="btn btn-primary" id="btn_wiz_next">' + $.i18n('general_btn_next') + '<i style="margin-left:4px;"class="fa fa-fw fa-chevron-right"></i>' + '</button>' +
'<button type="button" class="btn btn-warning" id="btn_wiz_save" style="display:none"><i class="fa fa-fw fa-save"></i>' + $.i18n('general_btn_save') + '</button>' +
'<button type="button" class="btn btn-danger" id="btn_wiz_abort"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>'
);
if (getStorage("darkMode", false) == "on") if (getStorage("darkMode", false) == "on")
$('#wizard_logo').attr("src", 'img/hyperion/logo_negativ.png'); $('#wizard_logo').attr("src", 'img/hyperion/logo_negativ.png');
@ -443,18 +465,28 @@ function startWizardCC() {
}); });
$('#wiz_cc_kodiip').off().on('change', function () { $('#wiz_cc_kodiip').off().on('change', function () {
kodiAddress = $(this).val().trim(); kodiAddress = $(this).val().trim();
$('#wizp1_body').find("kodiAddress").val(kodiAddress);
$('#kodi_status').html(''); $('#kodi_status').html('');
// Remove Kodi's default Web-Socket port (9090) from display and ensure Kodi's default REST-API port (8080) is mapped to web-socket port to ease migration
if (kodiAddress !== "") { if (kodiAddress !== "") {
[kodiHost, kodiPort] = kodiAddress.split(":", 2);
if (kodiPort === "9090" || kodiPort === "8080") { if (!isValidHostnameOrIP(kodiAddress)) {
kodiAddress = kodiHost;
kodiPort = undefined; $('#kodi_status').html('<p style="color:red;font-weight:bold;margin-top:5px">' + $.i18n('edt_msgcust_error_hostname_ip') + '</p>');
withKodi = false;
} else {
if (isValidIPv6(kodiAddress)) {
kodiUrl.hostname = "[" + kodiAddress + "]";
} else {
kodiUrl.hostname = kodiAddress;
} }
$('#kodi_status').html('<p style="font-weight:bold;margin-top:5px">' + $.i18n('wiz_cc_try_connect') + '</p>');
$('#btn_wiz_cont').attr('disabled', true);
sendToKodi("msg", $.i18n('wiz_cc_kodimsg_start'), function (cb) { sendToKodi("msg", $.i18n('wiz_cc_kodimsg_start'), function (cb) {
if (cb == "error") { if (cb == "error") {
$('#kodi_status').html('<p style="color:red;font-weight:bold;margin-top:5px">' + $.i18n('wiz_cc_kodidiscon') + '</p><p>' + $.i18n('wiz_cc_kodidisconlink') + ' <a href="https://sourceforge.net/projects/hyperion-project/files/resources/Hyperion_calibration_pictures.zip/download" target="_blank">' + $.i18n('wiz_cc_link') + '</p>'); $('#kodi_status').html('<p style="color:red;font-weight:bold;margin-top:5px">' + $.i18n('wiz_cc_kodidiscon') + '</p><p>' + $.i18n('wiz_cc_kodidisconlink') + ' <a href="https://sourceforge.net/projects/hyperion-project/files/resources/Hyperion_calibration_pictures.zip/download" target="_blank">' + $.i18n('wiz_cc_link') + '</p>');
@ -462,6 +494,7 @@ function startWizardCC() {
} }
else { else {
setStorage("kodiAddress", kodiAddress); setStorage("kodiAddress", kodiAddress);
setStorage("kodiPort", defaultKodiPort);
$('#kodi_status').html('<p style="color:green;font-weight:bold;margin-top:5px">' + $.i18n('wiz_cc_kodicon') + '</p>'); $('#kodi_status').html('<p style="color:green;font-weight:bold;margin-top:5px">' + $.i18n('wiz_cc_kodicon') + '</p>');
withKodi = true; withKodi = true;
@ -470,6 +503,7 @@ function startWizardCC() {
$('#btn_wiz_cont').attr('disabled', false); $('#btn_wiz_cont').attr('disabled', false);
}); });
} }
}
}); });
//listen for continue //listen for continue
@ -632,6 +666,8 @@ var groupLights = [];
var groupLightsLocations = []; var groupLightsLocations = [];
var hueType = "philipshue"; var hueType = "philipshue";
let hueUrl = new URL('http://dummy');
function startWizardPhilipsHue(e) { function startWizardPhilipsHue(e) {
if (typeof e.data.type != "undefined") hueType = e.data.type; if (typeof e.data.type != "undefined") hueType = e.data.type;
@ -651,24 +687,52 @@ function startWizardPhilipsHue(e) {
$('#wizp1_body').html('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n(hue_title) + '</h4><p>' + $.i18n(hue_intro1) + '</p>'); $('#wizp1_body').html('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n(hue_title) + '</h4><p>' + $.i18n(hue_intro1) + '</p>');
$('#wizp1_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_cont"><i class="fa fa-fw fa-check"></i>' + $.i18n('general_btn_continue') + '</button><button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>'); $('#wizp1_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_cont"><i class="fa fa-fw fa-check"></i>' + $.i18n('general_btn_continue') + '</button><button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>');
$('#wizp2_body').html('<div id="wh_topcontainer"></div>'); $('#wizp2_body').html('<div id="wh_topcontainer"></div>');
$('#wh_topcontainer').append('<p style="font-weight:bold">' + $.i18n(hue_desc1) + '</p><div class="form-group"><label>' + $.i18n('wiz_hue_ip') + '</label><div class="input-group" style="width:175px"><input type="text" class="input-group form-control" id="ip"><span class="input-group-addon" id="retry_bridge" style="cursor:pointer"><i class="fa fa-refresh"></i></span></div></div><span style="font-weight:bold;color:red" id="wiz_hue_ipstate"></span><span style="font-weight:bold;" class="component-on" id="wiz_hue_discovered"></span>');
var hidePort = "hidden-lg";
if (storedAccess === 'expert') {
hidePort = "";
}
$('#wh_topcontainer').append('<p class="text-left" style="font-weight:bold">' + $.i18n(hue_desc1) + '</p>' +
'<div class="row">' +
'<div class="col-md-2">' +
' <p class="text-left">' + $.i18n('wiz_hue_ip') + '</p></div>' +
' <div class="col-md-7"><div class="input-group">' +
' <span class="input-group-addon" id="retry_bridge" style="cursor:pointer"><i class="fa fa-refresh"></i></span>' +
' <input type="text" class="input-group form-control" id="host" placeholder="' + $.i18n('wiz_hue_ip') + '"></div></div>' +
' <div class="col-md-3 ' + hidePort + '"><div class="input-group">' +
' <span class="input-group-addon">:</span>' +
' <input type="text" class="input-group form-control" id="port" placeholder="' + $.i18n('edt_conf_general_port_title') + '"></div></div>' +
'</div><p><span style="font-weight:bold;color:red" id="wiz_hue_ipstate"></span><span style="font-weight:bold;" id="wiz_hue_discovered"></span></p>'
);
$('#wh_topcontainer').append(); $('#wh_topcontainer').append();
$('#wh_topcontainer').append('<div class="form-group" id="usrcont" style="display:none"></div>'); $('#wh_topcontainer').append('<div class="form-group" id="usrcont" style="display:none"></div>');
if (hueType == 'philipshue') {
$('#usrcont').append('<label>' + $.i18n('wiz_hue_username') + '</label><div class="input-group" style="width:250px"><input type="text" class="form-control" id="user"><span class="input-group-addon" id="retry_usr" style="cursor:pointer"><i class="fa fa-refresh"></i></span></div>'); $('#usrcont').append('<div class="row"><div class="col-md-2"><p class="text-left">' + $.i18n('wiz_hue_username') + '</p ></div>' +
} '<div class="col-md-7">' +
'<div class="input-group">' +
' <span class="input-group-addon" id="retry_usr" style="cursor:pointer"><i class="fa fa-refresh"></i></span>' +
' <input type="text" class="input-group form-control" id="user">' +
'</div></div></div><br>' +
'</div><input type="hidden" id="groupId">'
);
if (hueType == 'philipshueentertainment') { if (hueType == 'philipshueentertainment') {
$('#usrcont').append('<label>' + $.i18n('wiz_hue_username') + '</label><div class="input-group" style="width:250px"><input type="text" class="form-control" id="user"></div><label>' + $.i18n('wiz_hue_clientkey') + '</label><div class="input-group" style="width:250px"><input type="text" class="form-control" id="clientkey"><span class="input-group-addon" id="retry_usr" style="cursor:pointer"><i class="fa fa-refresh"></i></span></div><input type="hidden" id="groupId">'); $('#usrcont').append('<div class="row"><div class="col-md-2"><p class="text-left">' + $.i18n('wiz_hue_clientkey') +
'</p></div><div class="col-md-7"><input class="form-control" id="clientkey" type="text"></div></div><br>');
} }
$('#usrcont').append('<span style="font-weight:bold;color:red" id="wiz_hue_usrstate"></span><br><button type="button" class="btn btn-primary" style="display:none" id="wiz_hue_create_user"> <i class="fa fa-fw fa-plus"></i>' + $.i18n(hue_create_user) + '</button>');
$('#usrcont').append('<p><span style="font-weight:bold;color:red" id="wiz_hue_usrstate"></span><\p>' +
'<button type="button" class="btn btn-primary" style="display:none" id="wiz_hue_create_user"> <i class="fa fa-fw fa-plus"></i>' + $.i18n(hue_create_user) + '</button>');
if (hueType == 'philipshueentertainment') { if (hueType == 'philipshueentertainment') {
$('#wizp2_body').append('<div id="hue_grp_ids_t" style="display:none"><p style="font-weight:bold">' + $.i18n('wiz_hue_e_desc2') + '</p></div>'); $('#wizp2_body').append('<div id="hue_grp_ids_t" style="display:none"><p class="text-left" style="font-weight:bold">' + $.i18n('wiz_hue_e_desc2') + '</p></div>');
createTable("gidsh", "gidsb", "hue_grp_ids_t"); createTable("gidsh", "gidsb", "hue_grp_ids_t");
$('.gidsh').append(createTableRow([$.i18n('edt_dev_spec_groupId_title'), $.i18n('wiz_hue_e_use_group')], true)); $('.gidsh').append(createTableRow([$.i18n('edt_dev_spec_groupId_title'), $.i18n('wiz_hue_e_use_group')], true));
$('#wizp2_body').append('<div id="hue_ids_t" style="display:none"><p style="font-weight:bold" id="hue_id_headline">' + $.i18n('wiz_hue_e_desc3') + '</p></div>'); $('#wizp2_body').append('<div id="hue_ids_t" style="display:none"><p class="text-left" style="font-weight:bold" id="hue_id_headline">' + $.i18n('wiz_hue_e_desc3') + '</p></div>');
} }
else { else {
$('#wizp2_body').append('<div id="hue_ids_t" style="display:none"><p style="font-weight:bold" id="hue_id_headline">' + $.i18n('wiz_hue_desc2') + '</p></div>'); $('#wizp2_body').append('<div id="hue_ids_t" style="display:none"><p class="text-left" style="font-weight:bold" id="hue_id_headline">' + $.i18n('wiz_hue_desc2') + '</p></div>');
} }
createTable("lidsh", "lidsb", "hue_ids_t"); createTable("lidsh", "lidsb", "hue_ids_t");
$('.lidsh').append(createTableRow([$.i18n('edt_dev_spec_lightid_title'), $.i18n('wiz_pos'), $.i18n('wiz_identify')], true)); $('.lidsh').append(createTableRow([$.i18n('edt_dev_spec_lightid_title'), $.i18n('wiz_pos'), $.i18n('wiz_identify')], true));
@ -698,19 +762,37 @@ function checkHueBridge(cb, hueUser) {
if (usr == 'config') $('#wiz_hue_discovered').html(""); if (usr == 'config') $('#wiz_hue_discovered').html("");
if (hueIPs[hueIPsinc]) { if (hueIPs[hueIPsinc]) {
hueUrl.hostname = "dummy";
var host = hueIPs[hueIPsinc].host;
if (isValidIPv6(host)) {
hueUrl.hostname = "[" + host + "]";
} else {
hueUrl.hostname = host;
}
var port = hueIPs[hueIPsinc].port;
if (port > 0) {
hueUrl.port = port;
}
hueUrl.pathname = '/api/' + usr;
$.ajax({ $.ajax({
url: 'http://' + hueIPs[hueIPsinc].internalipaddress + '/api/' + usr, url: hueUrl,
type: "GET", type: "GET",
dataType: "json", dataType: "json",
success: function (json) { success: function (json) {
if (json.config) { if (json.config) {
cb(true, usr); cb(true, usr);
} else if (json.name && json.bridgeid && json.modelid) { } else {
if (json.name && json.bridgeid && json.modelid) {
$('#wiz_hue_discovered').html("Bridge: " + json.name + ", Modelid: " + json.modelid + ", API-Version: " + json.apiversion); $('#wiz_hue_discovered').html("Bridge: " + json.name + ", Modelid: " + json.modelid + ", API-Version: " + json.apiversion);
cb(true); cb(true);
} else { } else {
cb(false); cb(false);
} }
}
}, },
timeout: 2500 timeout: 2500
}).fail(function () { }).fail(function () {
@ -723,7 +805,8 @@ function checkBridgeResult(reply, usr) {
if (reply) { if (reply) {
//abort checking, first reachable result is used //abort checking, first reachable result is used
$('#wiz_hue_ipstate').html(""); $('#wiz_hue_ipstate').html("");
$('#ip').val(hueIPs[hueIPsinc].internalipaddress) $('#host').val(hueIPs[hueIPsinc].host)
$('#port').val(hueIPs[hueIPsinc].port)
//now check hue user on this bridge //now check hue user on this bridge
$('#usrcont').toggle(true); $('#usrcont').toggle(true);
@ -743,10 +826,11 @@ function checkBridgeResult(reply, usr) {
}; };
function checkUserResult(reply, usr) { function checkUserResult(reply, usr) {
$('#usrcont').toggle(true);
if (reply) { if (reply) {
$('#user').val(usr); $('#user').val(usr);
if (hueType == 'philipshueentertainment' && $('#clientkey').val() == "") { if (hueType == 'philipshueentertainment' && $('#clientkey').val() == "") {
$('#usrcont').toggle(true);
$('#wiz_hue_usrstate').html($.i18n('wiz_hue_e_clientkey_needed')); $('#wiz_hue_usrstate').html($.i18n('wiz_hue_e_clientkey_needed'));
$('#wiz_hue_create_user').toggle(true); $('#wiz_hue_create_user').toggle(true);
} else { } else {
@ -761,6 +845,7 @@ function checkUserResult(reply, usr) {
} }
} }
else { else {
//abort checking, first reachable result is used
$('#wiz_hue_usrstate').html($.i18n('wiz_hue_failure_user')); $('#wiz_hue_usrstate').html($.i18n('wiz_hue_failure_user'));
$('#wiz_hue_create_user').toggle(true); $('#wiz_hue_create_user').toggle(true);
} }
@ -775,8 +860,9 @@ function identHueId(id, off, oState) {
var put_data = '{"on":' + oState.on + ',"bri":' + oState.bri + ',"hue":' + oState.hue + ',"sat":' + oState.sat + '}'; var put_data = '{"on":' + oState.on + ',"bri":' + oState.bri + ',"hue":' + oState.hue + ',"sat":' + oState.sat + '}';
} }
hueUrl.pathname = '/api/' + $('#user').val() + '/lights/' + id + '/state',
$.ajax({ $.ajax({
url: 'http://' + $('#ip').val() + '/api/' + $('#user').val() + '/lights/' + id + '/state', url: hueUrl,
type: 'PUT', type: 'PUT',
timeout: 2000, timeout: 2000,
data: put_data data: put_data
@ -806,25 +892,32 @@ async function discover_hue_bridges() {
$('#wiz_hue_discovered').html("") $('#wiz_hue_discovered').html("")
} }
else { else {
hueIPs = [];
hueIPsinc = 0;
for (const device of r.devices) { for (const device of r.devices) {
//console.log("Device:", device);
if (device && device.ip && device.port) { if (device && device.ip && device.port) {
var host;
var ip; var port;
if (device.hostname && device.domain) { if (device.hostname && device.domain) {
ip = device.hostname + "." + device.domain + ":" + device.port; host = device.hostname + "." + device.domain;
port = device.port;
} else { } else {
ip = device.ip + ":" + device.port; host = device.ip;
port = device.port;
} }
if (ip) { if (host) {
if (!hueIPs.some(item => item.internalipaddress === ip)) { if (!hueIPs.some(item => item.host === host)) {
hueIPs.push({ internalipaddress: ip }); hueIPs.push({ host: host, port: port });
} }
} }
} }
} }
$('#wiz_hue_ipstate').html("");
$('#host').val(hueIPs[hueIPsinc].host)
$('#port').val(hueIPs[hueIPsinc].port)
var usr = $('#user').val(); var usr = $('#user').val();
if (usr != "") { if (usr != "") {
@ -836,8 +929,11 @@ async function discover_hue_bridges() {
} }
} }
async function getProperties_hue_bridge(hostAddress, username, resourceFilter) { async function getProperties_hue_bridge(hostAddress, port, username, resourceFilter) {
let params = { host: hostAddress, user: username, filter: resourceFilter }; let params = { host: hostAddress, user: username, filter: resourceFilter };
if (port !== 'undefined') {
params.port = port;
}
const res = await requestLedDeviceProperties('philipshue', params); const res = await requestLedDeviceProperties('philipshue', params);
@ -851,12 +947,15 @@ async function getProperties_hue_bridge(hostAddress, username, resourceFilter) {
} }
} }
async function identify_hue_device(hostAddress, username, id) { async function identify_hue_device(hostAddress, port, username, id) {
// Take care that new record cannot be save during background process // Take care that new record cannot be save during background process
$('#btn_wiz_save').attr('disabled', true); $('#btn_wiz_save').attr('disabled', true);
let params = { host: hostAddress, user: username, lightId: id }; let params = { host: hostAddress, user: username, lightId: id };
if (port !== 'undefined') {
params.port = port;
}
await requestLedDeviceIdentification('philipshue', params); await requestLedDeviceIdentification('philipshue', params);
if (!window.readOnlyMode) { if (!window.readOnlyMode) {
@ -866,6 +965,7 @@ async function identify_hue_device(hostAddress, username, id) {
function getHueIPs() { function getHueIPs() {
$('#wiz_hue_ipstate').html($.i18n('wiz_hue_searchb')); $('#wiz_hue_ipstate').html($.i18n('wiz_hue_searchb'));
$.ajax({ $.ajax({
url: 'https://discovery.meethue.com', url: 'https://discovery.meethue.com',
crossDomain: true, crossDomain: true,
@ -902,15 +1002,28 @@ function beginWizardHue() {
$('#clientkey').val(clkey); $('#clientkey').val(clkey);
} }
} }
//check if ip is empty/reachable/search for bridge
//check if host is empty/reachable/search for bridge
if (eV("host") == "") { if (eV("host") == "") {
hueIPs = [];
hueIPsinc = 0;
//getHueIPs(); //getHueIPs();
discover_hue_bridges(); discover_hue_bridges();
} }
else { else {
var ip = eV("host"); var host = eV("host");
$('#ip').val(ip); $('#host').val(host);
hueIPs.unshift({ internalipaddress: ip });
var port = eV("port");
if (port > 0) {
$('#port').val(port);
}
else {
$('#port').val('');
}
hueIPs.unshift({ host: host, port: port });
if (usr != "") { if (usr != "") {
checkHueBridge(checkUserResult, usr); checkHueBridge(checkUserResult, usr);
} else { } else {
@ -919,11 +1032,16 @@ function beginWizardHue() {
} }
$('#retry_bridge').off().on('click', function () { $('#retry_bridge').off().on('click', function () {
if ($('#ip').val() != "") {
hueIPs.unshift({ internalipaddress: $('#ip').val() }) if ($('#host').val() != "") {
hueIPs = [];
hueIPsinc = 0; hueIPsinc = 0;
hueIPs.push({ host: $('#host').val(), port: $('#port').val() });
}
else {
discover_hue_bridges();
} }
else discover_hue_bridges();
var usr = $('#user').val(); var usr = $('#user').val();
if (usr != "") { if (usr != "") {
@ -938,7 +1056,9 @@ function beginWizardHue() {
}); });
$('#wiz_hue_create_user').off().on('click', function () { $('#wiz_hue_create_user').off().on('click', function () {
if ($('#ip').val() != "") hueIPs.unshift({ internalipaddress: $('#ip').val() }); if ($('#host').val() != "") {
hueIPs.unshift({ host: $('#host').val(), port: $('#port').val() });
}
createHueUser(); createHueUser();
}); });
@ -973,12 +1093,12 @@ function beginWizardHue() {
//Start with a clean configuration //Start with a clean configuration
var d = {}; var d = {};
d.host = $('#ip').val(); d.host = $('#host').val();
d.port = parseInt($('#port').val());
d.username = $('#user').val(); d.username = $('#user').val();
d.type = 'philipshue'; d.type = 'philipshue';
d.colorOrder = 'rgb'; d.colorOrder = 'rgb';
d.lightIds = finalLightIds; d.lightIds = finalLightIds;
d.latchTime = 0;
d.transitiontime = parseInt(eV("transitiontime")); d.transitiontime = parseInt(eV("transitiontime"));
d.restoreOriginalState = (eV("restoreOriginalState") == true); d.restoreOriginalState = (eV("restoreOriginalState") == true);
d.switchOffOnBlack = (eV("switchOffOnBlack") == true); d.switchOffOnBlack = (eV("switchOffOnBlack") == true);
@ -1000,7 +1120,6 @@ function beginWizardHue() {
if (hueType == 'philipshue') { if (hueType == 'philipshue') {
d.useEntertainmentAPI = false; d.useEntertainmentAPI = false;
d.hardwareLedCount = finalLightIds.length; d.hardwareLedCount = finalLightIds.length;
d.rewriteTime = 0;
d.verbose = false; d.verbose = false;
//smoothing off //smoothing off
sc.smoothing.enable = false; sc.smoothing.enable = false;
@ -1030,9 +1149,11 @@ function createHueUser() {
data = { "devicetype": "hyperion#" + Date.now(), "generateclientkey": true } data = { "devicetype": "hyperion#" + Date.now(), "generateclientkey": true }
} }
var UserInterval = setInterval(function () { var UserInterval = setInterval(function () {
hueUrl.pathname = '/api/';
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: 'http://' + $("#ip").val() + '/api', url: hueUrl,
processData: false, processData: false,
timeout: 1000, timeout: 1000,
contentType: 'application/json', contentType: 'application/json',
@ -1081,9 +1202,10 @@ function createHueUser() {
} }
function get_hue_groups() { function get_hue_groups() {
hueUrl.pathname = '/api/' + $("#user").val() + '/groups';
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: 'http://' + $("#ip").val() + '/api/' + $("#user").val() + '/groups', url: hueUrl,
processData: false, processData: false,
contentType: 'application/json', contentType: 'application/json',
success: function (r) { success: function (r) {
@ -1125,9 +1247,10 @@ function noAPISupport(txt) {
} }
function get_light_state(id) { function get_light_state(id) {
hueUrl.pathname = '/api/' + $("#user").val() + '/lights/' + id;
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: 'http://' + $("#ip").val() + '/api/' + $("#user").val() + '/lights/' + id, url: hueUrl,
processData: false, processData: false,
contentType: 'application/json', contentType: 'application/json',
success: function (r) { success: function (r) {
@ -1139,9 +1262,10 @@ function get_light_state(id) {
} }
function get_hue_lights() { function get_hue_lights() {
hueUrl.pathname = '/api/' + $("#user").val() + '/lights';
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: 'http://' + $("#ip").val() + '/api/' + $("#user").val() + '/lights', url: hueUrl,
processData: false, processData: false,
contentType: 'application/json', contentType: 'application/json',
success: function (r) { success: function (r) {
@ -1199,7 +1323,7 @@ function get_hue_lights() {
} }
$('.lidsb').append(createTableRow([lightid + ' (' + r[lightid].name + ')', '<select id="hue_' + lightid + '" class="hue_sel_watch form-control">' $('.lidsb').append(createTableRow([lightid + ' (' + r[lightid].name + ')', '<select id="hue_' + lightid + '" class="hue_sel_watch form-control">'
+ options + options
+ '</select>', '<button class="btn btn-sm btn-primary" onClick=identify_hue_device("' + $("#ip").val() + '","' + $("#user").val() + '",' + lightid + ')>' + $.i18n('wiz_hue_blinkblue', lightid) + '</button>'])); + '</select>', '<button class="btn btn-sm btn-primary" onClick=identify_hue_device("' + $("#host").val() + '","' + $("#port").val() + '","' + $("#user").val() + '",' + lightid + ')>' + $.i18n('wiz_hue_blinkblue', lightid) + '</button>']));
} }
if (hueType != 'philipshueentertainment') { if (hueType != 'philipshueentertainment') {
@ -1356,8 +1480,6 @@ async function discover_yeelight_lights() {
// Process devices returned by discovery // Process devices returned by discovery
for (const device of r.devices) { for (const device of r.devices) {
//console.log("Device:", device);
if (device.hostname !== "") { if (device.hostname !== "") {
if (getHostInLights(device.hostname).length === 0) { if (getHostInLights(device.hostname).length === 0) {
var light = {}; var light = {};
@ -1381,7 +1503,7 @@ async function discover_yeelight_lights() {
// Add additional items from configuration // Add additional items from configuration
for (var keyConfig in configuredLights) { for (var keyConfig in configuredLights) {
var [host, port] = configuredLights[keyConfig].host.split(":", 2); var host = configuredLights[keyConfig].host;
//In case port has been explicitly provided, overwrite port given as part of hostname //In case port has been explicitly provided, overwrite port given as part of hostname
if (configuredLights[keyConfig].port !== 0) if (configuredLights[keyConfig].port !== 0)

View File

@ -139,8 +139,8 @@
"forwarder" : "forwarder" :
{ {
"enable" : false, "enable" : false,
"json" : ["127.0.0.1:19446"], "json" : [],
"flat" : ["127.0.0.1:19401"] "flat" : []
}, },
"jsonServer" : "jsonServer" :

View File

@ -233,6 +233,12 @@ protected:
/// ///
bool saveSettings(const QJsonObject &data); bool saveSettings(const QJsonObject &data);
///
/// @brief Restore settings object. Requires ADMIN ACCESS
/// @param data The data object
///
bool restoreSettings(const QJsonObject &data);
/// ///
/// @brief Test if we are authorized to use the interface /// @brief Test if we are authorized to use the interface
/// @return The result /// @return The result

View File

@ -229,6 +229,12 @@ private:
/// ///
void handleConfigSetCommand(const QJsonObject &message, const QString &command, int tan); void handleConfigSetCommand(const QJsonObject &message, const QString &command, int tan);
/// Handle an incoming JSON RestoreConfig message from handleConfigCommand()
///
/// @param message the incoming message
///
void handleConfigRestoreCommand(const QJsonObject &message, const QString &command, int tan);
/// ///
/// Handle an incoming JSON Component State message /// Handle an incoming JSON Component State message
/// ///

View File

@ -7,6 +7,7 @@
#include <QTcpSocket> #include <QTcpSocket>
#include <QTimer> #include <QTimer>
#include <QMap> #include <QMap>
#include <QHostAddress>
// hyperion util // hyperion util
#include <utils/Image.h> #include <utils/Image.h>
@ -16,6 +17,8 @@
#include <flatbuffers/flatbuffers.h> #include <flatbuffers/flatbuffers.h>
const int FLATBUFFER_DEFAULT_PORT = 19400;
namespace hyperionnet namespace hyperionnet
{ {
struct Reply; struct Reply;
@ -32,10 +35,11 @@ class FlatBufferConnection : public QObject
public: public:
/// ///
/// @brief Constructor /// @brief Constructor
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444) /// @param host The hostname or IP-address of the Hyperion Flatbuffer server (for example "192.168.0.32")
/// @param port The port of the Hyperion Flatpuffer server (default is 19400)
/// @param skipReply If true skip reply /// @param skipReply If true skip reply
/// ///
FlatBufferConnection(const QString& origin, const QString & address, int priority, bool skipReply); FlatBufferConnection(const QString& origin, const QString& host, int priority, bool skipReply, quint16 port = FLATBUFFER_DEFAULT_PORT);
/// ///
/// @brief Destructor /// @brief Destructor

View File

@ -324,6 +324,14 @@ public slots:
/// ///
bool saveSettings(const QJsonObject& config, bool correct = false); bool saveSettings(const QJsonObject& config, bool correct = false);
///
/// @brief Restore a complete json config
/// @param config The entire config object
/// @param correct If true will correct json against schema before save
/// @return True on success else false
///
bool restoreSettings(const QJsonObject& config, bool correct = false);
/// ############ /// ############
/// COMPONENTREGISTER /// COMPONENTREGISTER
/// ///

View File

@ -36,8 +36,8 @@ public:
MessageForwarder(Hyperion* hyperion); MessageForwarder(Hyperion* hyperion);
~MessageForwarder() override; ~MessageForwarder() override;
void addJsonSlave(const QString& slave); void addJsonTarget(const QJsonObject& targetConfig);
void addFlatbufferSlave(const QString& slave); void addFlatbufferTarget(const QJsonObject& targetConfig);
private slots: private slots:
/// ///
@ -61,25 +61,36 @@ private slots:
void handlePriorityChanges(quint8 priority); void handlePriorityChanges(quint8 priority);
/// ///
/// @brief Forward message to all json slaves /// @brief Forward message to all json target hosts
/// @param message The JSON message to send /// @param message The JSON message to send
/// ///
void forwardJsonMessage(const QJsonObject &message); void forwardJsonMessage(const QJsonObject &message);
/// ///
/// @brief Forward image to all flatbuffer slaves /// @brief Forward image to all flatbuffer target hosts
/// @param image The flatbuffer image to send /// @param image The flatbuffer image to send
/// ///
void forwardFlatbufferMessage(const QString& name, const Image<ColorRgb> &image); void forwardFlatbufferMessage(const QString& name, const Image<ColorRgb> &image);
/// ///
/// @brief Forward message to a single json slave /// @brief Forward message to a single json target host
/// @param message The JSON message to send /// @param message The JSON message to send
/// @param socket The TCP-Socket with the connection to the slave /// @param socket The TCP-Socket with the connection to the target host
/// ///
void sendJsonMessage(const QJsonObject &message, QTcpSocket *socket); void sendJsonMessage(const QJsonObject &message, QTcpSocket *socket);
private: private:
struct TargetHost {
QHostAddress host;
quint16 port;
bool operator == (TargetHost const& a) const
{
return ((host == a.host) && (port == a.port));
}
};
/// Hyperion instance /// Hyperion instance
Hyperion *_hyperion; Hyperion *_hyperion;
@ -89,11 +100,11 @@ private:
/// Muxer instance /// Muxer instance
PriorityMuxer *_muxer; PriorityMuxer *_muxer;
// JSON connection for forwarding // JSON connections for forwarding
QStringList _jsonSlaves; QList<TargetHost> _jsonTargets;
/// Proto connection for forwarding /// Flatbuffer connection for forwarding
QStringList _flatSlaves; QList<TargetHost> _flatbufferTargets;
QList<FlatBufferConnection*> _forwardClients; QList<FlatBufferConnection*> _forwardClients;
/// Flag if forwarder is enabled /// Flag if forwarder is enabled

View File

@ -36,6 +36,14 @@ public:
/// ///
bool saveSettings(QJsonObject config, bool correct = false); bool saveSettings(QJsonObject config, bool correct = false);
///
/// @brief Restore a complete json configuration
/// @param config The entire config object
/// @param correct If true will correct json against schema before save
/// @return True on success else false
///
bool restoreSettings(QJsonObject config, bool correct = false);
/// ///
/// @brief get a single setting json from configuration /// @brief get a single setting json from configuration
/// @param type The settings::type from enum /// @param type The settings::type from enum

View File

@ -3,15 +3,21 @@
#include <utils/Logger.h> #include <utils/Logger.h>
#include <QTcpServer> #include <QTcpServer>
#include <QUrl>
#include <QHostAddress>
#include <QHostInfo>
namespace NetUtils { namespace NetUtils {
const int MAX_PORT = 65535;
/// ///
/// @brief Check if the port is available for listening /// @brief Check if the port is available for listening
/// @param[in/out] port The port to test, will be incremented if port is in use /// @param[in/out] port The port to test, will be incremented if port is in use
/// @param log The logger of the caller to print /// @param log The logger of the caller to print
/// @return True on success else false /// @return True on success else false
/// ///
static bool portAvailable(quint16& port, Logger* log) inline bool portAvailable(quint16& port, Logger* log)
{ {
const quint16 prevPort = port; const quint16 prevPort = port;
QTcpServer server; QTcpServer server;
@ -29,4 +35,89 @@ namespace NetUtils {
return true; return true;
} }
///
/// @brief Check if the port is in the valid range
/// @param log The logger of the caller to print///
/// @param[in] port The port to be tested
/// @param[in] host A hostname/IP-address to make reference to during logging
/// @return True on success else false
///
inline bool isValidPort(Logger* log, int port, const QString& host)
{
if (port <= 0 || port > MAX_PORT)
{
Error(log, "Invalid port [%d] for host: %s!", port, QSTRING_CSTR(host));
return false;
}
return true;
}
///
/// @brief Get host and port from an host address
/// @param[in] address Hostname or IP-address with or without port (e.g. 192.168.1.100:4711, 2003:e4:c73a:8e00:d5bb:dc3c:50cb:c76e, hyperion.fritz.box)
/// @param[in/out] host The resolved hostname or IP-address
/// @param[in/out] port The resolved port, if available.
/// @return True on success else false
///
inline bool resolveHostPort(const QString& address, QString& host, quint16& port)
{
QString testUrl;
if (address.at(0) != '[' && address.count(':') > 1)
{
testUrl = QString("http://[%1]").arg(address);
}
else
{
testUrl = QString("http://%1").arg(address);
}
QUrl url(testUrl);
if (!url.isValid())
{
return false;
}
host = url.host();
if (url.port() != -1)
{
port = url.port();
}
return true;
}
///
/// @brief Check if the port is in the valid range
/// @param log The logger of the caller to print
/// @param[in] address The port to be tested
/// @param[out] hostAddress A hostname to make reference to during logging
/// @return True on success else false
///
inline bool resolveHostAddress(Logger* log, const QString& address, QHostAddress& hostAddress)
{
bool isHostAddressOK{ false };
if (hostAddress.setAddress(address))
{
Debug(log, "Successfully parsed %s as an IP-address.", QSTRING_CSTR(hostAddress.toString()));
isHostAddressOK = true;
}
else
{
QHostInfo hostInfo = QHostInfo::fromName(address);
if (hostInfo.error() == QHostInfo::NoError)
{
hostAddress = hostInfo.addresses().first();
Debug(log, "Successfully resolved IP-address (%s) for hostname (%s).", QSTRING_CSTR(hostAddress.toString()), QSTRING_CSTR(address));
isHostAddressOK = true;
}
else
{
QString errortext = QString("Failed resolving IP-address for [%1], (%2) %3").arg(address).arg(hostInfo.error()).arg(hostInfo.errorString());
Error(log, "%s", QSTRING_CSTR(errortext));
isHostAddressOK = false;
}
}
return isHostAddressOK;
}
} }

View File

@ -392,6 +392,20 @@ bool API::saveSettings(const QJsonObject &data)
return rc; return rc;
} }
bool API::restoreSettings(const QJsonObject &data)
{
bool rc = true;
if (!_adminAuthorized)
{
rc = false;
}
else
{
QMetaObject::invokeMethod(_hyperion, "restoreSettings", Qt::DirectConnection, Q_RETURN_ARG(bool, rc), Q_ARG(QJsonObject, data), Q_ARG(bool, true));
}
return rc;
}
bool API::updateHyperionPassword(const QString &password, const QString &newPassword) bool API::updateHyperionPassword(const QString &password, const QString &newPassword)
{ {
if (!_adminAuthorized) if (!_adminAuthorized)

View File

@ -10,7 +10,7 @@
"subcommand": { "subcommand": {
"type" : "string", "type" : "string",
"required" : true, "required" : true,
"enum" : ["setconfig","getconfig","getschema","reload"] "enum" : ["getconfig","getschema","setconfig","restoreconfig","reload"]
}, },
"tan" : { "tan" : {
"type" : "integer" "type" : "integer"

View File

@ -860,6 +860,13 @@ void JsonAPI::handleConfigCommand(const QJsonObject &message, const QString &com
{ {
handleSchemaGetCommand(message, full_command, tan); handleSchemaGetCommand(message, full_command, tan);
} }
else if (subcommand == "getconfig")
{
if (_adminAuthorized)
sendSuccessDataReply(QJsonDocument(_hyperion->getQJsonConfig()), full_command, tan);
else
sendErrorReply("No Authorization", command, tan);
}
else if (subcommand == "setconfig") else if (subcommand == "setconfig")
{ {
if (_adminAuthorized) if (_adminAuthorized)
@ -867,10 +874,10 @@ void JsonAPI::handleConfigCommand(const QJsonObject &message, const QString &com
else else
sendErrorReply("No Authorization", command, tan); sendErrorReply("No Authorization", command, tan);
} }
else if (subcommand == "getconfig") else if (subcommand == "restoreconfig")
{ {
if (_adminAuthorized) if (_adminAuthorized)
sendSuccessDataReply(QJsonDocument(_hyperion->getQJsonConfig()), full_command, tan); handleConfigRestoreCommand(message, full_command, tan);
else else
sendErrorReply("No Authorization", command, tan); sendErrorReply("No Authorization", command, tan);
} }
@ -916,6 +923,27 @@ void JsonAPI::handleConfigSetCommand(const QJsonObject &message, const QString &
} }
} }
void JsonAPI::handleConfigRestoreCommand(const QJsonObject &message, const QString &command, int tan)
{
if (message.contains("config"))
{
QJsonObject config = message["config"].toObject();
if (API::isHyperionEnabled())
{
if ( API::restoreSettings(config) )
{
sendSuccessReply(command, tan);
}
else
{
sendErrorReply("Restore settings failed", command, tan);
}
}
else
sendErrorReply("Restoring configuration while Hyperion is disabled isn't possible", command, tan);
}
}
void JsonAPI::handleSchemaGetCommand(const QJsonObject &message, const QString &command, int tan) void JsonAPI::handleSchemaGetCommand(const QJsonObject &message, const QString &command, int tan)
{ {
// create result // create result

View File

@ -17,15 +17,18 @@ bool ColorsOption::validate(Parser & parser, QString & value)
return true; return true;
} }
// check if we can create the color by hex RRGGBB getColors // check if we can create the colors by hex RRGGBB getColors
QRegularExpression hexRe("^([0-9A-F]{6})+$", QRegularExpression::CaseInsensitiveOption); QRegularExpression re("(([A-F0-9]){6})(?=(?:..)*)");
QRegularExpressionMatch match = hexRe.match(value); QRegularExpressionMatchIterator i = re.globalMatch(value);
if(match.hasMatch())
{ while (i.hasNext()) {
for(const QString & m : match.capturedTexts()) QRegularExpressionMatch match = i.next();
{ QString captured = match.captured(1);
_colors.push_back(QColor(QString("#%1").arg(m))); _colors.push_back(QColor(QString("#%1").arg(captured)));
} }
if (!_colors.isEmpty() && (_colors.size() * 6) == value.length())
{
return true; return true;
} }

View File

@ -11,33 +11,21 @@
#include "hyperion_reply_generated.h" #include "hyperion_reply_generated.h"
#include "hyperion_request_generated.h" #include "hyperion_request_generated.h"
FlatBufferConnection::FlatBufferConnection(const QString& origin, const QString & address, int priority, bool skipReply) FlatBufferConnection::FlatBufferConnection(const QString& origin, const QString& host, int priority, bool skipReply, quint16 port)
: _socket() : _socket()
, _origin(origin) , _origin(origin)
, _priority(priority) , _priority(priority)
, _host(host)
, _port(port)
, _prevSocketState(QAbstractSocket::UnconnectedState) , _prevSocketState(QAbstractSocket::UnconnectedState)
, _log(Logger::getInstance("FLATBUFCONN")) , _log(Logger::getInstance("FLATBUFCONN"))
, _registered(false) , _registered(false)
{ {
QStringList parts = address.split(":");
if (parts.size() != 2)
{
throw std::runtime_error(QString("FLATBUFCONNECTION ERROR: Unable to parse address (%1)").arg(address).toStdString());
}
_host = parts[0];
bool ok;
_port = parts[1].toUShort(&ok);
if (!ok)
{
throw std::runtime_error(QString("FLATBUFCONNECTION ERROR: Unable to parse the port (%1)").arg(parts[1]).toStdString());
}
if(!skipReply) if(!skipReply)
connect(&_socket, &QTcpSocket::readyRead, this, &FlatBufferConnection::readData, Qt::UniqueConnection); connect(&_socket, &QTcpSocket::readyRead, this, &FlatBufferConnection::readData, Qt::UniqueConnection);
// init connect // init connect
Info(_log, "Connecting to Hyperion: %s:%d", _host.toStdString().c_str(), _port); Info(_log, "Connecting to Hyperion: %s:%u", QSTRING_CSTR(_host), _port);
connectToHost(); connectToHost();
// start the connection timer // start the connection timer
@ -167,13 +155,13 @@ void FlatBufferConnection::sendMessage(const uint8_t* buffer, uint32_t size)
switch (_socket.state() ) switch (_socket.state() )
{ {
case QAbstractSocket::UnconnectedState: case QAbstractSocket::UnconnectedState:
Info(_log, "No connection to Hyperion: %s:%d", _host.toStdString().c_str(), _port); Info(_log, "No connection to Hyperion: %s:%u", QSTRING_CSTR(_host), _port);
break; break;
case QAbstractSocket::ConnectedState: case QAbstractSocket::ConnectedState:
Info(_log, "Connected to Hyperion: %s:%d", _host.toStdString().c_str(), _port); Info(_log, "Connected to Hyperion: %s:%u", QSTRING_CSTR(_host), _port);
break; break;
default: default:
Debug(_log, "Connecting to Hyperion: %s:%d", _host.toStdString().c_str(), _port); Debug(_log, "Connecting to Hyperion: %s:%u", QSTRING_CSTR(_host), _port);
break; break;
} }
_prevSocketState = _socket.state(); _prevSocketState = _socket.state();

View File

@ -279,6 +279,11 @@ bool Hyperion::saveSettings(const QJsonObject& config, bool correct)
return _settingsManager->saveSettings(config, correct); return _settingsManager->saveSettings(config, correct);
} }
bool Hyperion::restoreSettings(const QJsonObject& config, bool correct)
{
return _settingsManager->restoreSettings(config, correct);
}
int Hyperion::getLatchTime() const int Hyperion::getLatchTime() const
{ {
return _ledDeviceWrapper->getLatchTime(); return _ledDeviceWrapper->getLatchTime();

View File

@ -9,16 +9,18 @@
// utils includes // utils includes
#include <utils/Logger.h> #include <utils/Logger.h>
#include <utils/NetUtils.h>
// qt includes // qt includes
#include <QTcpServer> #include <QTcpServer>
#include <QTcpSocket> #include <QTcpSocket>
#include <QHostInfo>
#include <QNetworkInterface>
#include <flatbufserver/FlatBufferConnection.h> #include <flatbufserver/FlatBufferConnection.h>
MessageForwarder::MessageForwarder(Hyperion* hyperion) MessageForwarder::MessageForwarder(Hyperion* hyperion)
: QObject() : _hyperion(hyperion)
, _hyperion(hyperion)
, _log(Logger::getInstance("NETFORWARDER")) , _log(Logger::getInstance("NETFORWARDER"))
, _muxer(_hyperion->getMuxerInstance()) , _muxer(_hyperion->getMuxerInstance())
, _forwarder_enabled(true) , _forwarder_enabled(true)
@ -40,18 +42,22 @@ MessageForwarder::MessageForwarder(Hyperion *hyperion)
MessageForwarder::~MessageForwarder() MessageForwarder::~MessageForwarder()
{ {
while (!_forwardClients.isEmpty()) while (!_forwardClients.isEmpty())
{
delete _forwardClients.takeFirst(); delete _forwardClients.takeFirst();
} }
}
void MessageForwarder::handleSettingsUpdate(settings::type type, const QJsonDocument& config) void MessageForwarder::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
{ {
if (type == settings::NETFORWARD) if (type == settings::NETFORWARD)
{ {
// clear the current targets // clear the current targets
_jsonSlaves.clear(); _jsonTargets.clear();
_flatSlaves.clear(); _flatbufferTargets.clear();
while (!_forwardClients.isEmpty()) while (!_forwardClients.isEmpty())
{
delete _forwardClients.takeFirst(); delete _forwardClients.takeFirst();
}
// build new one // build new one
const QJsonObject& obj = config.object(); const QJsonObject& obj = config.object();
@ -60,7 +66,7 @@ void MessageForwarder::handleSettingsUpdate(settings::type type, const QJsonDocu
const QJsonArray& addr = obj["json"].toArray(); const QJsonArray& addr = obj["json"].toArray();
for (const auto& entry : addr) for (const auto& entry : addr)
{ {
addJsonSlave(entry.toString()); addJsonTarget(entry.toObject());
} }
} }
@ -69,29 +75,41 @@ void MessageForwarder::handleSettingsUpdate(settings::type type, const QJsonDocu
const QJsonArray& addr = obj["flat"].toArray(); const QJsonArray& addr = obj["flat"].toArray();
for (const auto& entry : addr) for (const auto& entry : addr)
{ {
addFlatbufferSlave(entry.toString()); addFlatbufferTarget(entry.toObject());
} }
} }
if (!_jsonSlaves.isEmpty() && obj["enable"].toBool() && _forwarder_enabled) bool isForwarderEnabledinSettings = obj["enable"].toBool(false);
if (!_jsonTargets.isEmpty() && isForwarderEnabledinSettings && _forwarder_enabled)
{ {
InfoIf(obj["enable"].toBool(true), _log, "Forward now to json targets '%s'", QSTRING_CSTR(_jsonSlaves.join(", "))); for (const auto& targetHost : qAsConst(_jsonTargets))
{
InfoIf(isForwarderEnabledinSettings, _log, "Forwarding now to JSON-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
}
connect(_hyperion, &Hyperion::forwardJsonMessage, this, &MessageForwarder::forwardJsonMessage, Qt::UniqueConnection); 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 (!_flatSlaves.isEmpty() && obj["enable"].toBool() && _forwarder_enabled)
{
InfoIf(obj["enable"].toBool(true), _log, "Forward now to flatbuffer targets '%s'", QSTRING_CSTR(_flatSlaves.join(", ")));
} }
else if ( _flatSlaves.isEmpty() || ! obj["enable"].toBool() || !_forwarder_enabled) else if (_jsonTargets.isEmpty() || !isForwarderEnabledinSettings || !_forwarder_enabled)
{ {
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardJsonMessage, nullptr, nullptr);
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0); }
if (!_flatbufferTargets.isEmpty() && isForwarderEnabledinSettings && _forwarder_enabled)
{
for (const auto& targetHost : qAsConst(_flatbufferTargets))
{
InfoIf(isForwarderEnabledinSettings, _log, "Forwarding now to Flatbuffer-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
}
}
else if (_flatbufferTargets.isEmpty() || !isForwarderEnabledinSettings || !_forwarder_enabled)
{
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
} }
// update comp state // update comp state
_hyperion->setNewComponentState(hyperion::COMP_FORWARDER, obj["enable"].toBool(true)); _hyperion->setNewComponentState(hyperion::COMP_FORWARDER, isForwarderEnabledinSettings);
} }
} }
@ -111,10 +129,6 @@ void MessageForwarder::handlePriorityChanges(quint8 priority)
const QJsonObject obj = _hyperion->getSetting(settings::NETFORWARD).object(); const QJsonObject obj = _hyperion->getSetting(settings::NETFORWARD).object();
if (priority != 0 && _forwarder_enabled && obj["enable"].toBool()) if (priority != 0 && _forwarder_enabled && obj["enable"].toBool())
{ {
//_flatSlaves.clear();
//while (!_forwardClients.isEmpty())
// delete _forwardClients.takeFirst();
hyperion::Components activeCompId = _hyperion->getPriorityInfo(priority).componentId; hyperion::Components activeCompId = _hyperion->getPriorityInfo(priority).componentId;
if (activeCompId == hyperion::COMP_GRABBER || activeCompId == hyperion::COMP_V4L) if (activeCompId == hyperion::COMP_GRABBER || activeCompId == hyperion::COMP_V4L)
{ {
@ -123,7 +137,7 @@ void MessageForwarder::handlePriorityChanges(quint8 priority)
const QJsonArray& addr = obj["flat"].toArray(); const QJsonArray& addr = obj["flat"].toArray();
for (const auto& entry : addr) for (const auto& entry : addr)
{ {
addFlatbufferSlave(entry.toString()); addFlatbufferTarget(entry.toObject());
} }
} }
@ -131,91 +145,107 @@ void MessageForwarder::handlePriorityChanges(quint8 priority)
{ {
case hyperion::COMP_GRABBER: case hyperion::COMP_GRABBER:
{ {
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
connect(_hyperion, &Hyperion::forwardSystemProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection); connect(_hyperion, &Hyperion::forwardSystemProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection);
} }
break; break;
case hyperion::COMP_V4L: case hyperion::COMP_V4L:
{ {
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
connect(_hyperion, &Hyperion::forwardV4lProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection); connect(_hyperion, &Hyperion::forwardV4lProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection);
} }
break; break;
default: default:
{ {
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
} }
} }
} }
else else
{ {
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0); disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
} }
} }
} }
void MessageForwarder::addJsonSlave(const QString& slave) void MessageForwarder::addJsonTarget(const QJsonObject& targetConfig)
{ {
QStringList parts = slave.split(":"); TargetHost targetHost;
if (parts.size() != 2)
{
Error(_log, "Unable to parse address (%s)",QSTRING_CSTR(slave));
return;
}
bool ok; QString config_host = targetConfig["host"].toString();
parts[1].toUShort(&ok); if (NetUtils::resolveHostAddress(_log, config_host, targetHost.host))
if (!ok)
{ {
Error(_log, "Unable to parse port number (%s)",QSTRING_CSTR(parts[1])); int config_port = targetConfig["port"].toInt();
return; if (NetUtils::isValidPort(_log, config_port, config_host))
} {
targetHost.port = static_cast<quint16>(config_port);
// verify loop with jsonserver // verify loop with JSON-server
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()) if ((QNetworkInterface::allAddresses().indexOf(targetHost.host) != -1) && targetHost.port == static_cast<quint16>(obj["port"].toInt()))
{ {
Error(_log, "Loop between JsonServer and Forwarder! (%s)",QSTRING_CSTR(slave)); Error(_log, "Loop between JSON-Server and Forwarder! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(config_host), config_port);
return; }
else
{
if (_forwarder_enabled)
{
if (_jsonTargets.indexOf(targetHost) == -1)
{
Info(_log, "JSON-Forwarder settings: Adding target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
_jsonTargets << targetHost;
}
else
{
Warning(_log, "JSON Forwarder settings: Duplicate target host configuration! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
}
} }
if (_forwarder_enabled && !_jsonSlaves.contains(slave)) }
_jsonSlaves << slave; }
}
} }
void MessageForwarder::addFlatbufferSlave(const QString& slave) void MessageForwarder::addFlatbufferTarget(const QJsonObject& targetConfig)
{ {
QStringList parts = slave.split(":"); TargetHost targetHost;
if (parts.size() != 2)
{
Error(_log, "Unable to parse address (%s)",QSTRING_CSTR(slave));
return;
}
bool ok; QString config_host = targetConfig["host"].toString();
parts[1].toUShort(&ok); if (NetUtils::resolveHostAddress(_log, config_host, targetHost.host))
if (!ok)
{ {
Error(_log, "Unable to parse port number (%s)",QSTRING_CSTR(parts[1])); int config_port = targetConfig["port"].toInt();
return; if (NetUtils::isValidPort(_log, config_port, config_host))
} {
targetHost.port = static_cast<quint16>(config_port);
// verify loop with flatbufserver // verify loop with Flatbuffer-server
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()) if ((QNetworkInterface::allAddresses().indexOf(targetHost.host) != -1) && targetHost.port == static_cast<quint16>(obj["port"].toInt()))
{ {
Error(_log, "Loop between Flatbuffer Server and Forwarder! (%s)",QSTRING_CSTR(slave)); Error(_log, "Loop between Flatbuffer-Server and Forwarder! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(config_host), config_port);
return;
} }
else
if (_forwarder_enabled && !_flatSlaves.contains(slave))
{ {
_flatSlaves << slave; if (_forwarder_enabled)
FlatBufferConnection* flatbuf = new FlatBufferConnection("Forwarder", slave.toLocal8Bit().constData(), _priority, false); {
if (_flatbufferTargets.indexOf(targetHost) == -1)
{
Info(_log, "Flatbuffer-Forwarder settings: Adding target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
_flatbufferTargets << targetHost;
FlatBufferConnection* flatbuf = new FlatBufferConnection("Forwarder", targetHost.host.toString(), _priority, false, targetHost.port);
_forwardClients << flatbuf; _forwardClients << flatbuf;
} }
else
{
Warning(_log, "Flatbuffer Forwarder settings: Duplicate target host configuration! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
}
}
}
}
}
} }
void MessageForwarder::forwardJsonMessage(const QJsonObject& message) void MessageForwarder::forwardJsonMessage(const QJsonObject& message)
@ -223,10 +253,9 @@ void MessageForwarder::forwardJsonMessage(const QJsonObject &message)
if (_forwarder_enabled) if (_forwarder_enabled)
{ {
QTcpSocket client; QTcpSocket client;
for (int i=0; i<_jsonSlaves.size(); i++) for (const auto& targetHost : qAsConst(_jsonTargets))
{ {
QStringList parts = _jsonSlaves.at(i).split(":"); client.connectToHost(targetHost.host, targetHost.port);
client.connectToHost(QHostAddress(parts[0]), parts[1].toUShort());
if (client.waitForConnected(500)) if (client.waitForConnected(500))
{ {
sendJsonMessage(message, &client); sendJsonMessage(message, &client);
@ -236,21 +265,25 @@ void MessageForwarder::forwardJsonMessage(const QJsonObject &message)
} }
} }
void MessageForwarder::forwardFlatbufferMessage(const QString& name, const Image<ColorRgb> &image) void MessageForwarder::forwardFlatbufferMessage(const QString& /*name*/, const Image<ColorRgb>& image)
{ {
if (_forwarder_enabled) if (_forwarder_enabled)
{ {
for (int i = 0; i < _forwardClients.size(); i++) for (int i = 0; i < _forwardClients.size(); i++)
{
_forwardClients.at(i)->setImage(image); _forwardClients.at(i)->setImage(image);
} }
} }
}
void MessageForwarder::sendJsonMessage(const QJsonObject& message, QTcpSocket* socket) void MessageForwarder::sendJsonMessage(const QJsonObject& message, QTcpSocket* socket)
{ {
// for hyperion classic compatibility // for hyperion classic compatibility
QJsonObject jsonMessage = message; QJsonObject jsonMessage = message;
if (jsonMessage.contains("tan") && jsonMessage["tan"].isNull()) if (jsonMessage.contains("tan") && jsonMessage["tan"].isNull())
{
jsonMessage["tan"] = 100; jsonMessage["tan"] = 100;
}
// serialize message // serialize message
QJsonDocument writer(jsonMessage); QJsonDocument writer(jsonMessage);
@ -280,7 +313,7 @@ void MessageForwarder::sendJsonMessage(const QJsonObject &message, QTcpSocket *s
// parse reply data // parse reply data
QJsonParseError error; QJsonParseError error;
QJsonDocument reply = QJsonDocument::fromJson(serializedReply ,&error); QJsonDocument::fromJson(serializedReply, &error);
if (error.error != QJsonParseError::NoError) if (error.error != QJsonParseError::NoError)
{ {
@ -288,3 +321,4 @@ void MessageForwarder::sendJsonMessage(const QJsonObject &message, QTcpSocket *s
return; return;
} }
} }

View File

@ -3,6 +3,8 @@
// util // util
#include <utils/JsonUtils.h> #include <utils/JsonUtils.h>
#include <utils/QStringUtils.h>
#include <db/SettingsTable.h> #include <db/SettingsTable.h>
#include "HyperionConfig.h" #include "HyperionConfig.h"
@ -14,6 +16,7 @@
#include <utils/JsonUtils.h> #include <utils/JsonUtils.h>
#include <utils/version.hpp> #include <utils/version.hpp>
using namespace semver; using namespace semver;
// Constants // Constants
@ -57,7 +60,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
// transform json to string lists // transform json to string lists
QStringList keyList = defaultConfig.keys(); QStringList keyList = defaultConfig.keys();
QStringList defValueList; QStringList defValueList;
for(const auto & key : keyList) for (const auto& key : qAsConst(keyList))
{ {
if (defaultConfig[key].isObject()) if (defaultConfig[key].isObject())
{ {
@ -70,30 +73,36 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
} }
// fill database with default data if required // fill database with default data if required
for(const auto & key : keyList) for (const auto& key : qAsConst(keyList))
{ {
QString val = defValueList.takeFirst(); QString val = defValueList.takeFirst();
// prevent overwrite // prevent overwrite
if (!_sTable->recordExist(key)) if (!_sTable->recordExist(key))
{
_sTable->createSettingsRecord(key, val); _sTable->createSettingsRecord(key, val);
} }
}
// need to validate all data in database construct the entire data object // need to validate all data in database construct the entire data object
// TODO refactor schemaChecker to accept QJsonArray in validate(); QJsonDocument container? To validate them per entry... // TODO refactor schemaChecker to accept QJsonArray in validate(); QJsonDocument container? To validate them per entry...
QJsonObject dbConfig; QJsonObject dbConfig;
for(const auto & key : keyList) for (const auto& key : qAsConst(keyList))
{ {
QJsonDocument doc = _sTable->getSettingsRecord(key); QJsonDocument doc = _sTable->getSettingsRecord(key);
if (doc.isArray()) if (doc.isArray())
{
dbConfig[key] = doc.array(); dbConfig[key] = doc.array();
}
else else
{
dbConfig[key] = doc.object(); dbConfig[key] = doc.object();
} }
}
//Check, if database requires migration //Check, if database requires migration
bool isNewRelease = false; bool isNewRelease = false;
// Use instance independent SettingsManager to track migration status // Use instance independent SettingsManager to track migration status
if ( instance == GLOABL_INSTANCE_ID) if (_instance == GLOABL_INSTANCE_ID)
{ {
if (resolveConfigVersion(dbConfig)) if (resolveConfigVersion(dbConfig))
{ {
@ -152,7 +161,9 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
if (!valid.second) if (!valid.second)
{ {
for (auto& schemaError : schemaChecker.getMessages()) for (auto& schemaError : schemaChecker.getMessages())
{
Error(_log, "Schema Syntax Error: %s", QSTRING_CSTR(schemaError)); Error(_log, "Schema Syntax Error: %s", QSTRING_CSTR(schemaError));
}
throw std::runtime_error("The config schema has invalid syntax. This should never happen! Go fix it!"); throw std::runtime_error("The config schema has invalid syntax. This should never happen! Go fix it!");
} }
if (!valid.first) if (!valid.first)
@ -161,12 +172,16 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
dbConfig = schemaChecker.getAutoCorrectedConfig(dbConfig); dbConfig = schemaChecker.getAutoCorrectedConfig(dbConfig);
for (auto& schemaError : schemaChecker.getMessages()) for (auto& schemaError : schemaChecker.getMessages())
{
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError)); Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
}
saveSettings(dbConfig, true); saveSettings(dbConfig, true);
} }
else else
{
_qconfig = dbConfig; _qconfig = dbConfig;
}
Debug(_log, "Settings database initialized"); Debug(_log, "Settings database initialized");
} }
@ -195,11 +210,15 @@ QJsonObject SettingsManager::getSettings() const
return config; return config;
} }
bool SettingsManager::saveSettings(QJsonObject config, bool correct) bool SettingsManager::restoreSettings(QJsonObject config, bool correct)
{ {
// optional data upgrades e.g. imported legacy/older configs // optional data upgrades e.g. imported legacy/older configs
// handleConfigUpgrade(config); handleConfigUpgrade(config);
return saveSettings(config, correct);
}
bool SettingsManager::saveSettings(QJsonObject config, bool correct)
{
// we need to validate data against schema // we need to validate data against schema
QJsonSchemaChecker schemaChecker; QJsonSchemaChecker schemaChecker;
schemaChecker.setSchema(schemaJson); schemaChecker.setSchema(schemaJson);
@ -214,8 +233,10 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct)
config = schemaChecker.getAutoCorrectedConfig(config); config = schemaChecker.getAutoCorrectedConfig(config);
for (const auto& schemaError : schemaChecker.getMessages()) for (const auto& schemaError : schemaChecker.getMessages())
{
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError)); Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
} }
}
// store the new config // store the new config
_qconfig = config; _qconfig = config;
@ -223,7 +244,7 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct)
// extract keys and data // extract keys and data
QStringList keyList = config.keys(); QStringList keyList = config.keys();
QStringList newValueList; QStringList newValueList;
for(const auto & key : keyList) for (const auto& key : qAsConst(keyList))
{ {
if (config[key].isObject()) if (config[key].isObject())
{ {
@ -235,9 +256,9 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct)
} }
} }
int rc = true; bool rc = true;
// compare database data with new data to emit/save changes accordingly // compare database data with new data to emit/save changes accordingly
for(const auto & key : keyList) for (const auto& key : qAsConst(keyList))
{ {
QString data = newValueList.takeFirst(); QString data = newValueList.takeFirst();
if (_sTable->getSettingsRecordString(key) != data) if (_sTable->getSettingsRecordString(key) != data)
@ -293,7 +314,6 @@ bool SettingsManager::resolveConfigVersion(QJsonObject& config)
} }
else else
{ {
_configVersion.setVersion(DEFAULT_VERSION);
isValid = true; isValid = true;
} }
@ -336,7 +356,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
semver::version targetVersion{ "2.0.0-alpha.9" }; semver::version targetVersion{ "2.0.0-alpha.9" };
if (_previousVersion <= targetVersion) if (_previousVersion <= targetVersion)
{ {
Info(_log, "Instance [%u]: Migrate LED Layout from current version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str()); Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
// LED LAYOUT UPGRADE // LED LAYOUT UPGRADE
// from { hscan: { minimum: 0.2, maximum: 0.3 }, vscan: { minimum: 0.2, maximum: 0.3 } } // from { hscan: { minimum: 0.2, maximum: 0.3 }, vscan: { minimum: 0.2, maximum: 0.3 } }
@ -520,8 +540,150 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
Debug(_log, "Framegrabber records migrated"); Debug(_log, "Framegrabber records migrated");
} }
} }
//Migration steps for versions <= 2.0.12
_previousVersion = targetVersion;
targetVersion.setVersion("2.0.12");
if (_previousVersion <= targetVersion)
{
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
// Have Hostname/IP-address separate from port for LED-Devices
if (config.contains("device"))
{
QJsonObject newDeviceConfig = config["device"].toObject();
if (newDeviceConfig.contains("host"))
{
QString oldHost = newDeviceConfig["host"].toString();
// Resolve hostname and port
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
newDeviceConfig["host"] = addressparts[0];
if (addressparts.size() > 1)
{
if (!newDeviceConfig.contains("port"))
{
newDeviceConfig["port"] = addressparts[1].toInt();
}
migrated = true;
}
if (migrated)
{
config["device"] = newDeviceConfig;
Debug(_log, "LED-Device records migrated");
}
} }
} }
// Have Hostname/IP-address separate from port for Forwarder
if (config.contains("forwarder"))
{
QJsonObject newForwarderConfig = config["forwarder"].toObject();
QJsonArray json;
if (newForwarderConfig.contains("json"))
{
QJsonArray oldJson = newForwarderConfig["json"].toArray();
QJsonObject newJsonConfig;
for (const QJsonValue& value : qAsConst(oldJson))
{
if (value.isString())
{
QString oldHost = value.toString();
// Resolve hostname and port
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString host = addressparts[0];
if (host != "127.0.0.1")
{
newJsonConfig["host"] = host;
if (addressparts.size() > 1)
{
newJsonConfig["port"] = addressparts[1].toInt();
}
else
{
newJsonConfig["port"] = 19444;
}
json.append(newJsonConfig);
migrated = true;
}
}
}
if (!json.isEmpty())
{
newForwarderConfig["json"] = json;
}
else
{
newForwarderConfig.remove("json");
}
}
QJsonArray flatbuffer;
if (newForwarderConfig.contains("flat"))
{
QJsonArray oldFlatbuffer = newForwarderConfig["flat"].toArray();
QJsonObject newFlattbufferConfig;
for (const QJsonValue& value : qAsConst(oldFlatbuffer))
{
if (value.isString())
{
QString oldHost = value.toString();
// Resolve hostname and port
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString host = addressparts[0];
if (host != "127.0.0.1")
{
newFlattbufferConfig["host"] = host;
if (addressparts.size() > 1)
{
newFlattbufferConfig["port"] = addressparts[1].toInt();
}
else
{
newFlattbufferConfig["port"] = 19400;
}
flatbuffer.append(newFlattbufferConfig);
migrated = true;
}
}
if (!flatbuffer.isEmpty())
{
newForwarderConfig["flat"] = flatbuffer;
}
else
{
newForwarderConfig.remove("flat");
}
}
}
if (json.isEmpty() && flatbuffer.isEmpty())
{
newForwarderConfig["enable"] = false;
}
if (migrated)
{
config["forwarder"] = newForwarderConfig;
Debug(_log, "Forwarder records migrated");
}
}
}
}
}
return migrated; return migrated;
} }

View File

@ -2,39 +2,75 @@
"type" : "object", "type" : "object",
"title" : "edt_conf_fw_heading_title", "title" : "edt_conf_fw_heading_title",
"required" : true, "required" : true,
"properties" : "properties": {
{ "enable": {
"enable" :
{
"type": "boolean", "type": "boolean",
"title": "edt_conf_general_enable_title", "title": "edt_conf_general_enable_title",
"required": true, "required": true,
"default": false, "default": false,
"propertyOrder": 1 "propertyOrder": 1
}, },
"json" : "json": {
{
"type": "array", "type": "array",
"title": "edt_conf_fw_json_title", "title": "edt_conf_fw_json_title",
"required" : true, "propertyOrder": 2,
"default" : ["127.0.0.1:19446"], "uniqueItems": true,
"items": { "items": {
"type": "object",
"title": "edt_conf_fw_json_itemtitle",
"required": true,
"properties": {
"host": {
"type": "string", "type": "string",
"title" : "edt_conf_fw_json_itemtitle" "format": "hostname_or_ip",
"minLength": 7,
"title": "edt_dev_spec_targetIpHost_title",
"required": true,
"propertyOrder": 1
}, },
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535,
"default": 19444,
"title": "edt_dev_spec_port_title",
"required": true,
"access": "expert",
"propertyOrder": 2 "propertyOrder": 2
}
}
}
}, },
"flat" : "flat": {
{
"type": "array", "type": "array",
"title": "edt_conf_fw_flat_title", "title": "edt_conf_fw_flat_title",
"required" : true, "propertyOrder": 3,
"default" : ["127.0.0.1:19401"], "uniqueItems": true,
"items": { "items": {
"type": "object",
"title": "edt_conf_fw_flat_itemtitle",
"required": true,
"properties": {
"host": {
"type": "string", "type": "string",
"title" : "edt_conf_fw_flat_itemtitle" "format": "hostname_or_ip",
"minLength": 7,
"title": "edt_dev_spec_targetIpHost_title",
"required": true,
"propertyOrder": 1
}, },
"propertyOrder" : 3 "port": {
"type": "integer",
"minimum": 1,
"maximum": 65535,
"default": 19400,
"title": "edt_dev_spec_port_title",
"required": true,
"access": "expert",
"propertyOrder": 2
}
}
}
} }
}, },
"additionalProperties": false "additionalProperties": false

View File

@ -27,6 +27,7 @@
"hidden": true "hidden": true
}, },
"required": true, "required": true,
"default": "",
"comment": "The 'available_devices' settings are dynamically inserted into the WebUI under PropertyOrder '2'.", "comment": "The 'available_devices' settings are dynamically inserted into the WebUI under PropertyOrder '2'.",
"propertyOrder": 3 "propertyOrder": 3
}, },

View File

@ -19,7 +19,6 @@ const bool verbose3 = false;
// Configuration settings // Configuration settings
const char CONFIG_ADDRESS[] = "host"; const char CONFIG_ADDRESS[] = "host";
//const char CONFIG_PORT[] = "port";
const char CONFIG_AUTH_TOKEN[] = "token"; const char CONFIG_AUTH_TOKEN[] = "token";
const char CONFIG_RESTORE_STATE[] = "restoreOriginalState"; const char CONFIG_RESTORE_STATE[] = "restoreOriginalState";
const char CONFIG_BRIGHTNESS[] = "brightness"; const char CONFIG_BRIGHTNESS[] = "brightness";
@ -182,8 +181,6 @@ bool LedDeviceNanoleaf::init(const QJsonObject& deviceConfig)
_startPos = deviceConfig[CONFIG_PANEL_START_POS].toInt(0); _startPos = deviceConfig[CONFIG_PANEL_START_POS].toInt(0);
// TODO: Allow to handle port dynamically
//Set hostname as per configuration and_defaultHost default port //Set hostname as per configuration and_defaultHost default port
_hostName = deviceConfig[CONFIG_ADDRESS].toString(); _hostName = deviceConfig[CONFIG_ADDRESS].toString();
_apiPort = API_DEFAULT_PORT; _apiPort = API_DEFAULT_PORT;
@ -442,21 +439,7 @@ QJsonObject LedDeviceNanoleaf::getProperties(const QJsonObject& params)
QString authToken = params["token"].toString(""); QString authToken = params["token"].toString("");
QString filter = params["filter"].toString(""); QString filter = params["filter"].toString("");
// Resolve hostname and port (or use default API port) initRestAPI(hostName, API_DEFAULT_PORT, authToken);
QStringList addressparts = QStringUtils::split(hostName, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString apiHost = addressparts[0];
int apiPort;
if (addressparts.size() > 1)
{
apiPort = addressparts[1].toInt();
}
else
{
apiPort = API_DEFAULT_PORT;
}
initRestAPI(apiHost, apiPort, authToken);
_restApi->setPath(filter); _restApi->setPath(filter);
// Perform request // Perform request
@ -482,21 +465,7 @@ void LedDeviceNanoleaf::identify(const QJsonObject& params)
{ {
QString authToken = params["token"].toString(""); QString authToken = params["token"].toString("");
// Resolve hostname and port (or use default API port) initRestAPI(hostName, API_DEFAULT_PORT, authToken);
QStringList addressparts = QStringUtils::split(hostName, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString apiHost = addressparts[0];
int apiPort;
if (addressparts.size() > 1)
{
apiPort = addressparts[1].toInt();
}
else
{
apiPort = API_DEFAULT_PORT;
}
initRestAPI(apiHost, apiPort, authToken);
_restApi->setPath("identify"); _restApi->setPath("identify");
// Perform request // Perform request

View File

@ -61,7 +61,7 @@ public:
/// Following parameters are required /// Following parameters are required
/// @code /// @code
/// { /// {
/// "host" : "hostname or IP [:port]", /// "host" : "hostname or IP",
/// "token" : "authentication token", /// "token" : "authentication token",
/// "filter": "resource to query", root "/" is used, if empty /// "filter": "resource to query", root "/" is used, if empty
/// } /// }
@ -78,7 +78,7 @@ public:
/// Following parameters are required /// Following parameters are required
/// @code /// @code
/// { /// {
/// "host" : "hostname or IP [:port]", /// "host" : "hostname or IP",
/// "token" : "authentication token", /// "token" : "authentication token",
/// } /// }
///@endcode ///@endcode

View File

@ -12,8 +12,8 @@ namespace {
bool verbose = false; bool verbose = false;
// Configuration settings // Configuration settings
const char CONFIG_ADDRESS[] = "host"; const char CONFIG_HOST[] = "host";
//const char CONFIG_PORT[] = "port"; const char CONFIG_PORT[] = "port";
const char CONFIG_USERNAME[] = "username"; const char CONFIG_USERNAME[] = "username";
const char CONFIG_CLIENTKEY[] = "clientkey"; const char CONFIG_CLIENTKEY[] = "clientkey";
const char CONFIG_BRIGHTNESSFACTOR[] = "brightnessFactor"; const char CONFIG_BRIGHTNESSFACTOR[] = "brightnessFactor";
@ -282,25 +282,24 @@ bool LedDevicePhilipsHueBridge::init(const QJsonObject &deviceConfig)
log( "LatchTime", "%d", this->getLatchTime() ); log( "LatchTime", "%d", this->getLatchTime() );
//Set hostname as per configuration and_defaultHost default port //Set hostname as per configuration and_defaultHost default port
QString address = deviceConfig[ CONFIG_ADDRESS ].toString(); _hostname = deviceConfig[CONFIG_HOST].toString();
//If host not configured the init failed //If host not configured the init failed
if ( address.isEmpty() ) if (_hostname.isEmpty())
{ {
this->setInError("No target hostname nor IP defined"); this->setInError("No target hostname defined");
isInitOK = false; isInitOK = false;
} }
else else
{ {
QStringList addressparts = QStringUtils::split(address,":", QStringUtils::SplitBehavior::SkipEmptyParts); log("Hostname", "%s", QSTRING_CSTR(_hostname));
_hostname = addressparts[0];
log( "Hostname/IP", "%s", QSTRING_CSTR( _hostname ) );
if ( addressparts.size() > 1 ) int _apiPort = deviceConfig[CONFIG_PORT].toInt();
if (_apiPort == 0)
{ {
_apiPort = addressparts[1].toInt(); _apiPort = API_DEFAULT_PORT;
log( "Port", "%u", _apiPort );
} }
log("Port", "%d", _apiPort);
_username = deviceConfig[CONFIG_USERNAME].toString(); _username = deviceConfig[CONFIG_USERNAME].toString();
@ -1602,7 +1601,7 @@ QJsonObject LedDevicePhilipsHue::discover(const QJsonObject& /*params*/)
// Discover Devices // Discover Devices
SSDPDiscover discover; SSDPDiscover discover;
discover.skipDuplicateKeys(false); discover.skipDuplicateKeys(true);
discover.setSearchFilter(SSDP_FILTER, SSDP_FILTER_HEADER); discover.setSearchFilter(SSDP_FILTER, SSDP_FILTER_HEADER);
QString searchTarget = SSDP_ID; QString searchTarget = SSDP_ID;
@ -1619,30 +1618,32 @@ QJsonObject LedDevicePhilipsHue::discover(const QJsonObject& /*params*/)
QJsonObject LedDevicePhilipsHue::getProperties(const QJsonObject& params) QJsonObject LedDevicePhilipsHue::getProperties(const QJsonObject& params)
{ {
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
QJsonObject properties; QJsonObject properties;
// Get Phillips-Bridge device properties // Get Phillips-Bridge device properties
QString host = params["host"].toString(""); QString hostName = params[CONFIG_HOST].toString("");
if ( !host.isEmpty() ) if (!hostName.isEmpty())
{ {
QString username = params["user"].toString(""); QString username = params["user"].toString("");
QString filter = params["filter"].toString(""); QString filter = params["filter"].toString("");
// Resolve hostname and port (or use default API port)
QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString apiHost = addressparts[0];
int apiPort; int apiPort;
if (params[CONFIG_PORT].isString())
if ( addressparts.size() > 1 )
{ {
apiPort = addressparts[1].toInt(); apiPort = params[CONFIG_PORT].toString().toInt();
} }
else else
{
apiPort = params[CONFIG_PORT].toInt();
}
if (apiPort == 0)
{ {
apiPort = API_DEFAULT_PORT; apiPort = API_DEFAULT_PORT;
} }
initRestAPI(apiHost, apiPort, username); initRestAPI(hostName, apiPort, username);
_restApi->setPath(filter); _restApi->setPath(filter);
// Perform request // Perform request
@ -1660,31 +1661,32 @@ QJsonObject LedDevicePhilipsHue::getProperties(const QJsonObject& params)
void LedDevicePhilipsHue::identify(const QJsonObject& params) void LedDevicePhilipsHue::identify(const QJsonObject& params)
{ {
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() ); DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
QJsonObject properties; QJsonObject properties;
// Identify Phillips-Bridge device // Identify Phillips-Bridge device
QString host = params["host"].toString(""); QString hostName = params[CONFIG_HOST].toString("");
if ( !host.isEmpty() ) if (!hostName.isEmpty())
{ {
QString username = params["user"].toString(""); QString username = params["user"].toString("");
int lightId = params["lightId"].toInt(0); int lightId = params["lightId"].toInt(0);
// Resolve hostname and port (or use default API port)
QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString apiHost = addressparts[0];
int apiPort; int apiPort;
if (params[CONFIG_PORT].isString())
if ( addressparts.size() > 1 )
{ {
apiPort = addressparts[1].toInt(); apiPort = params[CONFIG_PORT].toString().toInt();
} }
else else
{
apiPort = params[CONFIG_PORT].toInt();
}
if (apiPort == 0)
{ {
apiPort = API_DEFAULT_PORT; apiPort = API_DEFAULT_PORT;
} }
initRestAPI(apiHost, apiPort, username); initRestAPI(hostName, apiPort, username);
QString resource = QString("%1/%2/%3").arg(API_LIGHTS).arg(lightId).arg(API_STATE); QString resource = QString("%1/%2/%3").arg(API_LIGHTS).arg(lightId).arg(API_STATE);
_restApi->setPath(resource); _restApi->setPath(resource);

View File

@ -376,7 +376,8 @@ public:
/// Following parameters are required /// Following parameters are required
/// @code /// @code
/// { /// {
/// "host" : "hostname or IP [:port]", /// "host" : "hostname or IP
/// "port" : port
/// "user" : "username", /// "user" : "username",
/// "filter": "resource to query", root "/" is used, if empty /// "filter": "resource to query", root "/" is used, if empty
/// } /// }
@ -390,7 +391,15 @@ public:
/// ///
/// @brief Send an update to the device to identify it. /// @brief Send an update to the device to identify it.
/// ///
/// Used in context of a set of devices of the same type. /// Following parameters are required
/// @code
/// {
/// "host" : "hostname or IP
/// "port" : port
/// "user" : "username",
/// "filter": "resource to query", root "/" is used, if empty
/// }
///@endcode
/// ///
/// @param[in] params Parameters to address device /// @param[in] params Parameters to address device
/// ///

View File

@ -47,7 +47,7 @@ public:
/// Following parameters are required /// Following parameters are required
/// @code /// @code
/// { /// {
/// "host" : "hostname or IP [:port]", /// "host" : "hostname or IP",
/// "filter": "resource to query", root "/" is used, if empty /// "filter": "resource to query", root "/" is used, if empty
/// } /// }
///@endcode ///@endcode
@ -63,7 +63,7 @@ public:
/// Following parameters are required /// Following parameters are required
/// @code /// @code
/// { /// {
/// "host" : "hostname or IP [:port]", /// "host" : "hostname or IP",
/// } /// }
///@endcode ///@endcode
/// ///

View File

@ -1112,11 +1112,7 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig)
QString hostName = configuredYeelightLights[j].toObject().value("host").toString(); QString hostName = configuredYeelightLights[j].toObject().value("host").toString();
int port = configuredYeelightLights[j].toObject().value("port").toInt(API_DEFAULT_PORT); int port = configuredYeelightLights[j].toObject().value("port").toInt(API_DEFAULT_PORT);
QStringList addressparts = QStringUtils::split(hostName,":", QStringUtils::SplitBehavior::SkipEmptyParts); _lightsAddressList.append( { hostName, port} );
QString apiHost = addressparts[0];
int apiPort = port;
_lightsAddressList.append( {apiHost, apiPort} );
} }
if ( updateLights(_lightsAddressList) ) if ( updateLights(_lightsAddressList) )
@ -1150,13 +1146,13 @@ bool LedDeviceYeelight::startMusicModeServer()
} }
else else
{ {
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address, IPv6 are not supported by Yeelight currently
// use the first non-localhost IPv4 address for (const auto& address : QNetworkInterface::allAddresses())
for (int i = 0; i < ipAddressesList.size(); ++i) {
if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
(ipAddressesList.at(i).toIPv4Address() != 0U))
{ {
_musicModeServerAddress = ipAddressesList.at(i); // is valid when, no loopback, IPv4
if (!address.isLoopback() && (address.protocol() == QAbstractSocket::IPv4Protocol))
{
_musicModeServerAddress = address;
break; break;
} }
} }

View File

@ -70,7 +70,7 @@ bool ProviderUdp::init(const QJsonObject& deviceConfig)
else else
{ {
_port = static_cast<quint16>(config_port); _port = static_cast<quint16>(config_port);
Debug(_log, "UDP socket will write to %s:%u", QSTRING_CSTR(_address.toString()), _port); Debug(_log, "UDP socket will write to %s port: %u", QSTRING_CSTR(_address.toString()), _port);
_udpSocket = new QUdpSocket(this); _udpSocket = new QUdpSocket(this);

View File

@ -74,9 +74,6 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig)
if( deviceConfig.contains("hs_attempts") ) _handshake_attempts = deviceConfig["hs_attempts"].toInt(5); if( deviceConfig.contains("hs_attempts") ) _handshake_attempts = deviceConfig["hs_attempts"].toInt(5);
QString host = deviceConfig["host"].toString(_defaultHost); QString host = deviceConfig["host"].toString(_defaultHost);
//Split hostname from API-port in case given
QStringList addressparts = QStringUtils::split(host, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString udpHost = addressparts[0];
QStringList debugLevels = QStringList() << "No Debug" << "Error" << "State Change" << "Informational" << "Verbose"; QStringList debugLevels = QStringList() << "No Debug" << "Error" << "State Change" << "Informational" << "Verbose";
@ -96,25 +93,24 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig)
configLog( "SSL Handshake Timeout max", "%d", _handshake_timeout_max ); configLog( "SSL Handshake Timeout max", "%d", _handshake_timeout_max );
configLog( "SSL Handshake attempts", "%d", _handshake_attempts ); configLog( "SSL Handshake attempts", "%d", _handshake_attempts );
if ( _address.setAddress(udpHost) ) if (_address.setAddress(host))
{ {
Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR(udpHost) ); Debug(_log, "Successfully parsed %s as an IP-address.", QSTRING_CSTR(_address.toString()));
} }
else else
{ {
Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR(udpHost) ); QHostInfo hostInfo = QHostInfo::fromName(host);
QHostInfo info = QHostInfo::fromName(udpHost); if (hostInfo.error() == QHostInfo::NoError)
if ( info.addresses().isEmpty() )
{ {
Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR(udpHost) ); _address = hostInfo.addresses().first();
QString errortext = QString("Invalid target address [%1]!").arg(host); Debug(_log, "Successfully resolved IP-address (%s) for hostname (%s).", QSTRING_CSTR(_address.toString()), QSTRING_CSTR(host));
}
else
{
QString errortext = QString("Failed resolving IP-address for [%1], (%2) %3").arg(host).arg(hostInfo.error()).arg(hostInfo.errorString());
this->setInError(errortext); this->setInError(errortext);
isInitOK = false; isInitOK = false;
} return isInitOK;
else
{
Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR(udpHost) );
_address = info.addresses().first();
} }
} }
@ -129,7 +125,7 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig)
else else
{ {
_ssl_port = config_port; _ssl_port = config_port;
Debug( _log, "UDP SSL using %s:%u", QSTRING_CSTR( _address.toString() ), _ssl_port ); Debug(_log, "UDP SSL will write to %s port: %u", QSTRING_CSTR(_address.toString()), _ssl_port);
isInitOK = true; isInitOK = true;
} }
} }
@ -250,17 +246,20 @@ bool ProviderUdpSSL::initConnection()
bool ProviderUdpSSL::seedingRNG() bool ProviderUdpSSL::seedingRNG()
{ {
int ret = 0;
sslLog("Seeding the random number generator..."); sslLog("Seeding the random number generator...");
mbedtls_entropy_init(&entropy); mbedtls_entropy_init(&entropy);
sslLog("Set mbedtls_ctr_drbg_seed..."); sslLog("Set mbedtls_ctr_drbg_seed...");
const char* custom = QSTRING_CSTR( _custom ); QByteArray customDataArray = _custom.toLocal8Bit();
const char* customData = customDataArray.constData();
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, reinterpret_cast<const unsigned char *>(custom), strlen(custom))) != 0) int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
&entropy, reinterpret_cast<const unsigned char*>(customData),
std::min(strlen(customData), (size_t)MBEDTLS_CTR_DRBG_MAX_SEED_INPUT));
if (ret != 0)
{ {
sslLog(QString("mbedtls_ctr_drbg_seed FAILED %1").arg(errorMsg(ret)), "error"); sslLog(QString("mbedtls_ctr_drbg_seed FAILED %1").arg(errorMsg(ret)), "error");
return false; return false;

View File

@ -4,7 +4,8 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"title":"edt_dev_spec_targetIp_title", "format": "hostname_or_ip",
"title": "edt_dev_spec_targetIpHost_title",
"propertyOrder": 1 "propertyOrder": 1
}, },
"port": { "port": {

View File

@ -18,6 +18,7 @@
}, },
"host": { "host": {
"type": "string", "type": "string",
"format": "ipv4",
"title": "edt_dev_spec_multicastGroup_title", "title": "edt_dev_spec_multicastGroup_title",
"default": "239.255.255.250", "default": "239.255.255.250",
"propertyOrder": 3 "propertyOrder": 3

View File

@ -15,6 +15,7 @@
}, },
"host": { "host": {
"type": "string", "type": "string",
"format": "hostname_or_ip4",
"title": "edt_dev_spec_targetIpHost_title", "title": "edt_dev_spec_targetIpHost_title",
"options": { "options": {
"infoText": "edt_dev_spec_targetIpHost_title_info" "infoText": "edt_dev_spec_targetIpHost_title_info"

View File

@ -4,7 +4,8 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"title":"edt_dev_spec_targetIp_title", "format": "hostname_or_ip",
"title": "edt_dev_spec_targetIpHost_title",
"propertyOrder": 1 "propertyOrder": 1
}, },
"port": { "port": {

View File

@ -4,7 +4,8 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"title": "edt_dev_spec_targetIp_title", "format": "hostname_or_ip4",
"title": "edt_dev_spec_targetIpHost_title",
"default": "127.0.0.1", "default": "127.0.0.1",
"propertyOrder": 1 "propertyOrder": 1
}, },
@ -110,4 +111,3 @@
}, },
"additionalProperties": true "additionalProperties": true
} }

View File

@ -4,6 +4,7 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"format": "ipv4",
"title": "edt_dev_spec_targetIp_title", "title": "edt_dev_spec_targetIp_title",
"default": "255.255.255.255", "default": "255.255.255.255",
"propertyOrder": 1 "propertyOrder": 1

View File

@ -15,6 +15,7 @@
}, },
"host": { "host": {
"type": "string", "type": "string",
"format": "hostname_or_ip",
"title": "edt_dev_spec_targetIpHost_title", "title": "edt_dev_spec_targetIpHost_title",
"options": { "options": {
"infoText": "edt_dev_spec_targetIpHost_title_info" "infoText": "edt_dev_spec_targetIpHost_title_info"

View File

@ -4,15 +4,25 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"title": "edt_dev_spec_targetIp_title", "format": "hostname_or_ip",
"title": "edt_dev_spec_targetIpHost_title",
"default": "", "default": "",
"propertyOrder": 1 "propertyOrder": 1
}, },
"port": {
"type": "integer",
"title": "edt_dev_spec_port_title",
"default": 0,
"minimum": 0,
"maximum": 65535,
"access": "expert",
"propertyOrder": 2
},
"username": { "username": {
"type": "string", "type": "string",
"title": "edt_dev_spec_username_title", "title": "edt_dev_spec_username_title",
"default": "", "default": "",
"propertyOrder": 2 "propertyOrder": 3
}, },
"clientkey": { "clientkey": {
"type": "string", "type": "string",
@ -23,13 +33,13 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 3 "propertyOrder": 4
}, },
"useEntertainmentAPI": { "useEntertainmentAPI": {
"type": "boolean", "type": "boolean",
"title": "edt_dev_spec_useEntertainmentAPI_title", "title": "edt_dev_spec_useEntertainmentAPI_title",
"default": true, "default": true,
"propertyOrder": 4 "propertyOrder": 5
}, },
"transitiontime": { "transitiontime": {
"type": "number", "type": "number",
@ -41,19 +51,19 @@
"useEntertainmentAPI": false "useEntertainmentAPI": false
} }
}, },
"propertyOrder": 5 "propertyOrder": 6
}, },
"switchOffOnBlack": { "switchOffOnBlack": {
"type": "boolean", "type": "boolean",
"title": "edt_dev_spec_switchOffOnBlack_title", "title": "edt_dev_spec_switchOffOnBlack_title",
"default": false, "default": false,
"propertyOrder": 6 "propertyOrder": 7
}, },
"restoreOriginalState": { "restoreOriginalState": {
"type": "boolean", "type": "boolean",
"title": "edt_dev_spec_restoreOriginalState_title", "title": "edt_dev_spec_restoreOriginalState_title",
"default": true, "default": true,
"propertyOrder": 7 "propertyOrder": 8
}, },
"lightIds": { "lightIds": {
"type": "array", "type": "array",
@ -71,7 +81,7 @@
"useEntertainmentAPI": false "useEntertainmentAPI": false
} }
}, },
"propertyOrder": 8 "propertyOrder": 9
}, },
"groupId": { "groupId": {
"type": "number", "type": "number",
@ -82,7 +92,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 9 "propertyOrder": 10
}, },
"blackLightsTimeout": { "blackLightsTimeout": {
"type": "number", "type": "number",
@ -98,7 +108,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 10 "propertyOrder": 11
}, },
"brightnessThreshold": { "brightnessThreshold": {
"type": "number", "type": "number",
@ -113,7 +123,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 11 "propertyOrder": 12
}, },
"brightnessFactor": { "brightnessFactor": {
"type": "number", "type": "number",
@ -123,7 +133,7 @@
"minimum": 0.5, "minimum": 0.5,
"maximum": 10.0, "maximum": 10.0,
"access": "advanced", "access": "advanced",
"propertyOrder": 12 "propertyOrder": 13
}, },
"brightnessMin": { "brightnessMin": {
"type": "number", "type": "number",
@ -138,7 +148,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 13 "propertyOrder": 14
}, },
"brightnessMax": { "brightnessMax": {
"type": "number", "type": "number",
@ -153,7 +163,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 14 "propertyOrder": 15
}, },
"sslReadTimeout": { "sslReadTimeout": {
"type": "number", "type": "number",
@ -169,7 +179,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 15 "propertyOrder": 16
}, },
"sslHSTimeoutMin": { "sslHSTimeoutMin": {
"type": "number", "type": "number",
@ -185,7 +195,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 16 "propertyOrder": 17
}, },
"sslHSTimeoutMax": { "sslHSTimeoutMax": {
"type": "number", "type": "number",
@ -201,14 +211,14 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 17 "propertyOrder": 18
}, },
"verbose": { "verbose": {
"type": "boolean", "type": "boolean",
"title": "edt_dev_spec_verbose_title", "title": "edt_dev_spec_verbose_title",
"default": false, "default": false,
"access": "expert", "access": "expert",
"propertyOrder": 18 "propertyOrder": 19
}, },
"debugStreamer": { "debugStreamer": {
"type": "boolean", "type": "boolean",
@ -220,7 +230,7 @@
"useEntertainmentAPI": true "useEntertainmentAPI": true
} }
}, },
"propertyOrder": 19 "propertyOrder": 20
}, },
"debugLevel": { "debugLevel": {
"type": "string", "type": "string",
@ -236,7 +246,7 @@
"minimum": 0, "minimum": 0,
"maximum": 4, "maximum": 4,
"access": "expert", "access": "expert",
"propertyOrder": 20 "propertyOrder": 21
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -2,9 +2,10 @@
"type":"object", "type":"object",
"required":true, "required":true,
"properties":{ "properties":{
"output": { "host": {
"type": "string", "type": "string",
"title":"edt_dev_spec_targetIp_title", "format": "hostname_or_ip",
"title": "edt_dev_spec_targetIpHost_title",
"default": "127.0.0.1", "default": "127.0.0.1",
"propertyOrder": 1 "propertyOrder": 1
}, },

View File

@ -4,6 +4,7 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"format": "hostname_or_ip",
"title": "edt_dev_spec_targetIpHost_title", "title": "edt_dev_spec_targetIpHost_title",
"propertyOrder": 1 "propertyOrder": 1
}, },

View File

@ -4,7 +4,8 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"title":"edt_dev_spec_targetIp_title", "title": "edt_dev_spec_targetIpHost_title",
"format": "hostname_or_ip",
"propertyOrder": 1 "propertyOrder": 1
}, },
"port": { "port": {

View File

@ -16,6 +16,7 @@
}, },
"host": { "host": {
"type": "string", "type": "string",
"format": "hostname_or_ip4",
"title": "edt_dev_spec_targetIpHost_title", "title": "edt_dev_spec_targetIpHost_title",
"options": { "options": {
"infoText": "edt_dev_spec_targetIpHost_title_info" "infoText": "edt_dev_spec_targetIpHost_title_info"

View File

@ -112,8 +112,9 @@
"properties": { "properties": {
"host": { "host": {
"type": "string", "type": "string",
"format": "hostname_or_ip",
"minLength": 7, "minLength": 7,
"title": "edt_dev_spec_networkDeviceName_title", "title": "edt_dev_spec_targetIpHost_title",
"required": true, "required": true,
"propertyOrder": 1 "propertyOrder": 1
}, },
@ -122,7 +123,7 @@
"minimum": 0, "minimum": 0,
"maximum": 65535, "maximum": 65535,
"default": 55443, "default": 55443,
"title": "edt_dev_spec_networkDevicePort_title", "title": "edt_dev_spec_port_title",
"required": false, "required": false,
"access": "expert", "access": "expert",
"propertyOrder": 2 "propertyOrder": 2

View File

@ -56,7 +56,8 @@ void WebServer::onServerStarted (quint16 port)
{ {
_inited = true; _inited = true;
Info(_log, "Started on port %d name '%s'", port ,_server->getServerName().toStdString().c_str()); Info(_log, "'%s' started on port %d",_server->getServerName().toStdString().c_str(), port);
#ifdef ENABLE_AVAHI #ifdef ENABLE_AVAHI
if(_serviceRegister == nullptr) if(_serviceRegister == nullptr)
{ {

View File

@ -11,6 +11,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
#include <utils/DefaultSignalHandler.h> #include <utils/DefaultSignalHandler.h>
@ -53,7 +54,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -122,8 +123,17 @@ int main(int argc, char ** argv)
} }
} }
// Resolve hostname and port (or use default port)
QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection // Create the Flabuf-connection
FlatBufferConnection flatbuf("AML Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); FlatBufferConnection flatbuf("AML Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&amlWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&amlWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -12,6 +12,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
#include <utils/DefaultSignalHandler.h> #include <utils/DefaultSignalHandler.h>
@ -54,7 +55,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -124,8 +125,18 @@ int main(int argc, char ** argv)
address = argAddress.value(parser); address = argAddress.value(parser);
} }
} }
// Resolve hostname and port (or use default port)
QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection // Create the Flabuf-connection
FlatBufferConnection flatbuf("Dispmanx Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); FlatBufferConnection flatbuf("Dispmanx Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&dispmanxWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&dispmanxWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -11,6 +11,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
#include <utils/DefaultSignalHandler.h> #include <utils/DefaultSignalHandler.h>
@ -55,7 +56,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -125,8 +126,17 @@ int main(int argc, char ** argv)
} }
} }
// Resolve hostname and port (or use default port)
QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection // Create the Flabuf-connection
FlatBufferConnection flatbuf("Framebuffer Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); FlatBufferConnection flatbuf("Framebuffer Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&fbWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&fbWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -10,6 +10,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
#include <utils/DefaultSignalHandler.h> #include <utils/DefaultSignalHandler.h>
@ -49,7 +50,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -119,8 +120,17 @@ int main(int argc, char ** argv)
} }
} }
// Resolve hostname and port (or use default port)
QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection // Create the Flabuf-connection
FlatBufferConnection flatbuf("OSX Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); FlatBufferConnection flatbuf("OSX Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&osxWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&osxWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -15,6 +15,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
using namespace commandline; using namespace commandline;
@ -56,7 +57,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -126,8 +127,17 @@ int main(int argc, char ** argv)
} }
} }
// Resolve hostname and port (or use default port)
QString host;
quint16 port { FLATBUFFER_DEFAULT_PORT };
if ( !NetUtils::resolveHostPort(address, host, port) )
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection // Create the Flabuf-connection
FlatBufferConnection flatbuf("Qt Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); FlatBufferConnection flatbuf("Qt Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&qtWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&qtWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -10,6 +10,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QHostInfo> #include <QHostInfo>
#include <QUrl>
// hyperion-remote includes // hyperion-remote includes
#include "JsonConnection.h" #include "JsonConnection.h"
@ -17,31 +18,17 @@
// util includes // util includes
#include <utils/JsonUtils.h> #include <utils/JsonUtils.h>
JsonConnection::JsonConnection(const QString & address, bool printJson) JsonConnection::JsonConnection(const QString & host, bool printJson , quint16 port)
: _printJson(printJson) : _printJson(printJson)
, _log(Logger::getInstance("REMOTE")) , _log(Logger::getInstance("REMOTE"))
, _socket()
{ {
QStringList parts = address.split(":"); _socket.connectToHost(host, port);
if (parts.size() != 2)
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
bool ok;
uint16_t port = parts[1].toUShort(&ok);
if (!ok)
{
throw std::runtime_error(QString("Wrong address: Unable to parse the port number (%1)").arg(parts[1]).toStdString());
}
_socket.connectToHost(parts[0], port);
if (!_socket.waitForConnected()) if (!_socket.waitForConnected())
{ {
throw std::runtime_error("Unable to connect to host"); throw std::runtime_error(QString("Unable to connect to host (%1), port (%2)").arg(host).arg(port).toStdString());
} }
qDebug() << "Connected to:" << address; Debug(_log, "Connected to: %s, port: %u", QSTRING_CSTR(host), port);
} }
JsonConnection::~JsonConnection() JsonConnection::~JsonConnection()
@ -51,7 +38,7 @@ JsonConnection::~JsonConnection()
void JsonConnection::setColor(std::vector<QColor> colors, int priority, int duration) void JsonConnection::setColor(std::vector<QColor> colors, int priority, int duration)
{ {
qDebug() << "Set color to " << colors[0].red() << " " << colors[0].green() << " " << colors[0].blue() << (colors.size() > 1 ? " + ..." : ""); Debug(_log, "Set color to [%d,%d,%d] %s", colors[0].red(), colors[0].green(), colors[0].blue(), (colors.size() > 1 ? " + ..." : ""));
// create command // create command
QJsonObject command; QJsonObject command;
@ -81,7 +68,7 @@ void JsonConnection::setColor(std::vector<QColor> colors, int priority, int dura
void JsonConnection::setImage(QImage &image, int priority, int duration) void JsonConnection::setImage(QImage &image, int priority, int duration)
{ {
qDebug() << "Set image has size: " << image.width() << "x" << image.height(); Debug(_log, "Set image has size: %dx%d", image.width(), image.height());
// ensure the image has RGB888 format // ensure the image has RGB888 format
image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
@ -121,7 +108,7 @@ void JsonConnection::setImage(QImage &image, int priority, int duration)
void JsonConnection::setEffect(const QString &effectName, const QString & effectArgs, int priority, int duration) void JsonConnection::setEffect(const QString &effectName, const QString & effectArgs, int priority, int duration)
{ {
qDebug() << "Start effect " << effectName; Debug(_log, "Start effect: %s", QSTRING_CSTR(effectName));
// create command // create command
QJsonObject command, effect; QJsonObject command, effect;
@ -157,7 +144,7 @@ void JsonConnection::setEffect(const QString &effectName, const QString & effect
void JsonConnection::createEffect(const QString &effectName, const QString &effectScript, const QString & effectArgs) void JsonConnection::createEffect(const QString &effectName, const QString &effectScript, const QString & effectArgs)
{ {
qDebug() << "Create effect " << effectName; Debug(_log, "Create effect: %s", QSTRING_CSTR(effectName));
// create command // create command
QJsonObject effect; QJsonObject effect;
@ -185,7 +172,7 @@ void JsonConnection::createEffect(const QString &effectName, const QString &effe
void JsonConnection::deleteEffect(const QString &effectName) void JsonConnection::deleteEffect(const QString &effectName)
{ {
qDebug() << "Delete effect configuration" << effectName; Debug(_log, "Delete effect configuration: %s", QSTRING_CSTR(effectName));
// create command // create command
QJsonObject effect; QJsonObject effect;
@ -208,7 +195,7 @@ QString JsonConnection::getServerInfoString()
QJsonObject JsonConnection::getServerInfo() QJsonObject JsonConnection::getServerInfo()
{ {
qDebug() << "Get server info"; Debug(_log, "Get server info");
// create command // create command
QJsonObject command; QJsonObject command;
@ -233,7 +220,7 @@ QJsonObject JsonConnection::getServerInfo()
QString JsonConnection::getSysInfo() QString JsonConnection::getSysInfo()
{ {
qDebug() << "Get system info"; Debug(_log, "Get system info");
// create command // create command
QJsonObject command; QJsonObject command;
@ -260,7 +247,7 @@ QString JsonConnection::getSysInfo()
void JsonConnection::clear(int priority) void JsonConnection::clear(int priority)
{ {
qDebug() << "Clear priority channel " << priority; Debug(_log, "Clear priority channel [%d]", priority);
// create command // create command
QJsonObject command; QJsonObject command;
@ -276,7 +263,7 @@ void JsonConnection::clear(int priority)
void JsonConnection::clearAll() void JsonConnection::clearAll()
{ {
qDebug() << "Clear all priority channels"; Debug(_log, "Clear all priority channels");
// create command // create command
QJsonObject command; QJsonObject command;
@ -292,7 +279,7 @@ void JsonConnection::clearAll()
void JsonConnection::setComponentState(const QString & component, bool state) void JsonConnection::setComponentState(const QString & component, bool state)
{ {
qDebug() << (state ? "Enable" : "Disable") << "Component" << component; Debug(_log, "%s Component: %s", (state ? "Enable" : "Disable"), QSTRING_CSTR(component));
// create command // create command
QJsonObject command, parameter; QJsonObject command, parameter;
@ -339,7 +326,7 @@ void JsonConnection::setSourceAutoSelect()
QString JsonConnection::getConfig(std::string type) QString JsonConnection::getConfig(std::string type)
{ {
assert( type == "schema" || type == "config" ); assert( type == "schema" || type == "config" );
qDebug() << "Get configuration file from Hyperion Server"; Debug(_log, "Get configuration file from Hyperion Server");
// create command // create command
QJsonObject command; QJsonObject command;
@ -408,7 +395,7 @@ void JsonConnection::setAdjustment(
int *brightness, int *brightness,
int *brightnessC) int *brightnessC)
{ {
qDebug() << "Set color adjustments"; Debug(_log, "Set color adjustments");
// create command // create command
QJsonObject command, adjust; QJsonObject command, adjust;

View File

@ -9,6 +9,8 @@
//forward class decl //forward class decl
class Logger; class Logger;
const int JSON_DEFAULT_PORT = 19444;
/// ///
/// Connection class to setup an connection to the hyperion server and execute commands /// Connection class to setup an connection to the hyperion server and execute commands
/// ///
@ -18,10 +20,11 @@ public:
/// ///
/// Constructor /// Constructor
/// ///
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444) /// @param address The hostname or IP-address of the Hyperion JSON-server (for example "192.168.0.32")
/// @param address The port of the Hyperion JSON-server (default port = 19444)
/// @param printJson Boolean indicating if the sent and received json is written to stdout /// @param printJson Boolean indicating if the sent and received json is written to stdout
/// ///
JsonConnection(const QString & address, bool printJson); JsonConnection(const QString& host, bool printJson, quint16 port = JSON_DEFAULT_PORT);
/// ///
/// Destructor /// Destructor

View File

@ -9,14 +9,16 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QLocale> #include <QLocale>
#include "HyperionConfig.h"
#include <commandline/Parser.h>
// hyperion-remote include // hyperion-remote include
#include "JsonConnection.h" #include "JsonConnection.h"
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
#include "HyperionConfig.h"
#include <commandline/Parser.h>
#include <utils/DefaultSignalHandler.h> #include <utils/DefaultSignalHandler.h>
using namespace commandline; using namespace commandline;
@ -66,6 +68,10 @@ int main(int argc, char * argv[])
#ifndef _WIN32 #ifndef _WIN32
setenv("AVAHI_COMPAT_NOWARN", "1", 1); setenv("AVAHI_COMPAT_NOWARN", "1", 1);
#endif #endif
Logger* log = Logger::getInstance("REMOTE");
Logger::setLogLevel(Logger::INFO);
std::cout std::cout
<< "hyperion-remote:" << std::endl << "hyperion-remote:" << std::endl
<< "\tVersion : " << HYPERION_VERSION << " (" << HYPERION_BUILD_ID << ")" << std::endl << "\tVersion : " << HYPERION_VERSION << " (" << HYPERION_BUILD_ID << ")" << std::endl
@ -87,7 +93,7 @@ int main(int argc, char * argv[])
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// art variable definition append art to Parser short-, long option description, optional default value // // art variable definition append art to Parser short-, long option description, optional default value //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Option & argAddress = parser.add<Option> ('a', "address" , "Set the address of the hyperion server [default: %1]", "127.0.0.1:19444"); Option & argAddress = parser.add<Option> ('a', "address" , "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
Option & argToken = parser.add<Option> ('t', "token" , "If authorization tokens are required, this token is used"); Option & argToken = parser.add<Option> ('t', "token" , "If authorization tokens are required, this token is used");
Option & argInstance = parser.add<Option> ('I', "instance" , "Select a specific target instance by name for your command. By default it uses always the first instance"); Option & argInstance = parser.add<Option> ('I', "instance" , "Select a specific target instance by name for your command. By default it uses always the first instance");
IntOption & argPriority = parser.add<IntOption> ('p', "priority" , "Used to the provided priority channel (suggested 2-99) [default: %1]", "50"); IntOption & argPriority = parser.add<IntOption> ('p', "priority" , "Used to the provided priority channel (suggested 2-99) [default: %1]", "50");
@ -111,8 +117,6 @@ int main(int argc, char * argv[])
IntOption & argBacklightThreshold = parser.add<IntOption> ('n', "backlightThreshold" , "threshold for activating backlight (minimum brightness)"); IntOption & argBacklightThreshold = parser.add<IntOption> ('n', "backlightThreshold" , "threshold for activating backlight (minimum brightness)");
IntOption & argBacklightColored = parser.add<IntOption> (0x0, "backlightColored" , "0 = white backlight; 1 = colored backlight"); IntOption & argBacklightColored = parser.add<IntOption> (0x0, "backlightColored" , "0 = white backlight; 1 = colored backlight");
DoubleOption & argGamma = parser.add<DoubleOption> ('g', "gamma" , "Set the overall gamma of the LEDs"); DoubleOption & argGamma = parser.add<DoubleOption> ('g', "gamma" , "Set the overall gamma of the LEDs");
BooleanOption & argPrint = parser.add<BooleanOption>(0x0, "print" , "Print the JSON input and output messages on stdout");
BooleanOption & argHelp = parser.add<BooleanOption>('h', "help" , "Show this help message and exit");
ColorOption & argRAdjust = parser.add<ColorOption> ('R', "redAdjustment" , "Set the adjustment of the red color (requires colors in hex format as RRGGBB)"); ColorOption & argRAdjust = parser.add<ColorOption> ('R', "redAdjustment" , "Set the adjustment of the red color (requires colors in hex format as RRGGBB)");
ColorOption & argGAdjust = parser.add<ColorOption> ('G', "greenAdjustment" , "Set the adjustment of the green color (requires colors in hex format as RRGGBB)"); ColorOption & argGAdjust = parser.add<ColorOption> ('G', "greenAdjustment" , "Set the adjustment of the green color (requires colors in hex format as RRGGBB)");
ColorOption & argBAdjust = parser.add<ColorOption> ('B', "blueAdjustment" , "Set the adjustment of the blue color (requires colors in hex format as RRGGBB)"); ColorOption & argBAdjust = parser.add<ColorOption> ('B', "blueAdjustment" , "Set the adjustment of the blue color (requires colors in hex format as RRGGBB)");
@ -131,9 +135,19 @@ int main(int argc, char * argv[])
BooleanOption & argSchemaGet = parser.add<BooleanOption>(0x0, "schemaGet" , "Print the JSON schema for Hyperion configuration"); BooleanOption & argSchemaGet = parser.add<BooleanOption>(0x0, "schemaGet" , "Print the JSON schema for Hyperion configuration");
Option & argConfigSet = parser.add<Option> (0x0, "configSet" , "Write to the actual loaded configuration file. Should be a JSON object string."); Option & argConfigSet = parser.add<Option> (0x0, "configSet" , "Write to the actual loaded configuration file. Should be a JSON object string.");
BooleanOption & argPrint = parser.add<BooleanOption>(0x0, "print", "Print the JSON input and output messages on stdout");
BooleanOption & argDebug = parser.add<BooleanOption>(0x0, "debug", "Enable debug logging");
BooleanOption & argHelp = parser.add<BooleanOption>('h', "help", "Show this help message and exit");
// parse all _options // parse all _options
parser.process(app); parser.process(app);
// check if debug logging is required
if (parser.isSet(argDebug))
{
Logger::setLogLevel(Logger::DEBUG);
}
// check if we need to display the usage. exit if we do. // check if we need to display the usage. exit if we do.
if (parser.isSet(argHelp)) if (parser.isSet(argHelp))
{ {
@ -196,8 +210,17 @@ int main(int argc, char * argv[])
} }
} }
// Resolve hostname and port (or use default port)
QString host;
quint16 port{ JSON_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// create the connection to the hyperion server // create the connection to the hyperion server
JsonConnection connection(address, parser.isSet(argPrint)); JsonConnection connection(host, parser.isSet(argPrint), port);
// authorization token specified. Use it first // authorization token specified. Use it first
if (parser.isSet(argToken)) if (parser.isSet(argToken))
@ -323,7 +346,7 @@ int main(int argc, char * argv[])
catch (const std::runtime_error & e) catch (const std::runtime_error & e)
{ {
// An error occurred. Display error and quit // An error occurred. Display error and quit
std::cerr << e.what() << std::endl; Error(log, "%s", e.what());
return 1; return 1;
} }

View File

@ -23,6 +23,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
#include <utils/DefaultSignalHandler.h> #include <utils/DefaultSignalHandler.h>
@ -81,7 +82,7 @@ int main(int argc, char** argv)
DoubleOption & argSignalHorizontalMax = parser.add<DoubleOption> (0x0, "signal-horizontal-max", "area for signal detection - horizontal maximum offset value. Values between 0.0 and 1.0"); DoubleOption & argSignalHorizontalMax = parser.add<DoubleOption> (0x0, "signal-horizontal-max", "area for signal detection - horizontal maximum offset value. Values between 0.0 and 1.0");
DoubleOption & argSignalVerticalMax = parser.add<DoubleOption> (0x0, "signal-vertical-max" , "area for signal detection - vertical maximum offset value. Values between 0.0 and 1.0"); DoubleOption & argSignalVerticalMax = parser.add<DoubleOption> (0x0, "signal-vertical-max" , "area for signal detection - vertical maximum offset value. Values between 0.0 and 1.0");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -241,8 +242,17 @@ int main(int argc, char** argv)
} }
} }
// Create the Flatbuf-connection // Resolve hostname and port (or use default port)
FlatBufferConnection flatbuf("V4L2 Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection
FlatBufferConnection flatbuf("V4L2 Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&grabber, SIGNAL(newFrame(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&grabber, SIGNAL(newFrame(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -11,6 +11,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
using namespace commandline; using namespace commandline;
@ -52,7 +53,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -121,8 +122,18 @@ int main(int argc, char ** argv)
address = argAddress.value(parser); address = argAddress.value(parser);
} }
} }
// Create the Flatbuf-connection
FlatBufferConnection flatbuf("X11 Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); // Resolve hostname and port (or use default port)
QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection
FlatBufferConnection flatbuf("X11 Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&x11Wrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&x11Wrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -11,6 +11,7 @@
// ssdp discover // ssdp discover
#include <ssdp/SSDPDiscover.h> #include <ssdp/SSDPDiscover.h>
#include <utils/NetUtils.h>
using namespace commandline; using namespace commandline;
@ -52,7 +53,7 @@ int main(int argc, char ** argv)
BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DSBS = parser.add<BooleanOption>(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); BooleanOption & arg3DTAB = parser.add<BooleanOption>(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
Option & argAddress = parser.add<Option> ('a', "address", "Set the address of the hyperion server [default: %1]", "127.0.0.1:19400"); Option & argAddress = parser.add<Option> ('a', "address", "The hostname or IP-address (IPv4 or IPv6) of the hyperion server.\nDefault port: 19444.\nSample addresses:\nHost : hyperion.fritz.box\nIPv4 : 127.0.0.1:19444\nIPv6 : [2001:1:2:3:4:5:6:7]");
IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150"); IntOption & argPriority = parser.add<IntOption> ('p', "priority", "Use the provided priority channel (suggested 100-199) [default: %1]", "150");
BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); BooleanOption & argSkipReply = parser.add<BooleanOption>(0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
@ -121,8 +122,18 @@ int main(int argc, char ** argv)
address = argAddress.value(parser); address = argAddress.value(parser);
} }
} }
// Create the Flatbuf-connection
FlatBufferConnection flatbuf("XCB Standalone", address, argPriority.getInt(parser), parser.isSet(argSkipReply)); // Resolve hostname and port (or use default port)
QString host;
quint16 port{ FLATBUFFER_DEFAULT_PORT };
if (!NetUtils::resolveHostPort(address, host, port))
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
// Create the Flabuf-connection
FlatBufferConnection flatbuf("XCB Standalone", host, argPriority.getInt(parser), parser.isSet(argSkipReply), port);
// Connect the screen capturing to flatbuf connection processing // Connect the screen capturing to flatbuf connection processing
QObject::connect(&xcbWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>))); QObject::connect(&xcbWrapper, SIGNAL(sig_screenshot(const Image<ColorRgb> &)), &flatbuf, SLOT(setImage(Image<ColorRgb>)));

View File

@ -181,6 +181,7 @@ if (WIN32)
get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION) get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXECUTABLE}" DIRECTORY) get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${QT_BIN_DIR}") find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${QT_BIN_DIR}")
if (NOT WINDEPLOYQT_EXECUTABLE) if (NOT WINDEPLOYQT_EXECUTABLE)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt) find_program(WINDEPLOYQT_EXECUTABLE windeployqt)
endif() endif()
@ -190,6 +191,37 @@ if (WIN32)
message(STATUS "Found windeployqt: ${WINDEPLOYQT_EXECUTABLE} PATH_HINT:${QT_BIN_DIR}") message(STATUS "Found windeployqt: ${WINDEPLOYQT_EXECUTABLE} PATH_HINT:${QT_BIN_DIR}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${WINDEPLOYQT_EXECUTABLE} ${WINDEPLOYQT_PARAMS_RUNTIME} "$<TARGET_FILE:${PROJECT_NAME}>") add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${WINDEPLOYQT_EXECUTABLE} ${WINDEPLOYQT_PARAMS_RUNTIME} "$<TARGET_FILE:${PROJECT_NAME}>")
endif() endif()
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
string(REGEX MATCHALL "[0-9]+" openssl_versions "${OPENSSL_VERSION}")
list(GET openssl_versions 0 openssl_version_major)
list(GET openssl_versions 1 openssl_version_minor)
set(library_suffix "-${openssl_version_major}_${openssl_version_minor}")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
string(APPEND library_suffix "-x64")
endif()
find_file(OPENSSL_SSL
NAMES "libssl${library_suffix}.dll"
PATHS ${OPENSSL_INCLUDE_DIR}/.. ${OPENSSL_INCLUDE_DIR}/../bin
NO_DEFAULT_PATH
)
find_file(OPENSSL_CRYPTO
NAMES "libcrypto${library_suffix}.dll"
PATHS ${OPENSSL_INCLUDE_DIR}/.. ${OPENSSL_INCLUDE_DIR}/../bin
NO_DEFAULT_PATH
)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${OPENSSL_SSL} ${OPENSSL_CRYPTO}
$<TARGET_FILE_DIR:${PROJECT_NAME}>
)
endif(OPENSSL_FOUND)
endif(WIN32) endif(WIN32)
if(ENABLE_DEPLOY_DEPENDENCIES) if(ENABLE_DEPLOY_DEPENDENCIES)

View File

@ -26,6 +26,8 @@
#include <QDir> #include <QDir>
#include <QStringList> #include <QStringList>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QNetworkInterface>
#include <QHostInfo>
#include "HyperionConfig.h" #include "HyperionConfig.h"
@ -47,7 +49,7 @@
using namespace commandline; using namespace commandline;
#define PERM0664 QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther | QFileDevice::WriteOwner | QFileDevice::WriteGroup #define PERM0664 (QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther | QFileDevice::WriteOwner | QFileDevice::WriteGroup)
#ifndef _WIN32 #ifndef _WIN32
void signal_handler(int signum) void signal_handler(int signum)
@ -59,7 +61,6 @@ void signal_handler(int signum)
{ {
// only quit when a registered child process is gone // only quit when a registered child process is gone
// currently this feature is not active ... // currently this feature is not active ...
return;
} }
else if (signum == SIGUSR1) else if (signum == SIGUSR1)
{ {
@ -67,7 +68,6 @@ void signal_handler(int signum)
{ {
_hyperion->toggleStateAllInstances(false); _hyperion->toggleStateAllInstances(false);
} }
return;
} }
else if (signum == SIGUSR2) else if (signum == SIGUSR2)
{ {
@ -75,7 +75,6 @@ void signal_handler(int signum)
{ {
_hyperion->toggleStateAllInstances(true); _hyperion->toggleStateAllInstances(true);
} }
return;
} }
} }
#endif #endif
@ -106,8 +105,8 @@ QCoreApplication* createApplication(int &argc, char *argv[])
{ {
// if x11, then test if xserver is available // if x11, then test if xserver is available
#if defined(ENABLE_X11) #if defined(ENABLE_X11)
Display* dpy = XOpenDisplay(NULL); Display* dpy = XOpenDisplay(nullptr);
if (dpy != NULL) if (dpy != nullptr)
{ {
XCloseDisplay(dpy); XCloseDisplay(dpy);
isGuiApp = true; isGuiApp = true;
@ -165,7 +164,7 @@ int main(int argc, char** argv)
// Initialising QCoreApplication // Initialising QCoreApplication
QScopedPointer<QCoreApplication> app(createApplication(argc, argv)); QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
bool isGuiApp = (qobject_cast<QApplication *>(app.data()) != 0 && QSystemTrayIcon::isSystemTrayAvailable()); bool isGuiApp = (qobject_cast<QApplication *>(app.data()) != nullptr && QSystemTrayIcon::isSystemTrayAvailable());
DefaultSignalHandler::install(); DefaultSignalHandler::install();
@ -200,6 +199,13 @@ int main(int argc, char** argv)
parser.process(*qApp); parser.process(*qApp);
#ifdef WIN32
if (parser.isSet(consoleOption))
{
CreateConsole();
}
#endif
if (parser.isSet(versionOption)) if (parser.isSet(versionOption))
{ {
std::cout std::cout
@ -215,6 +221,24 @@ int main(int argc, char** argv)
if (getProcessIdsByProcessName(processName).size() > 1) if (getProcessIdsByProcessName(processName).size() > 1)
{ {
Error(log, "The Hyperion Daemon is already running, abort start"); Error(log, "The Hyperion Daemon is already running, abort start");
// use the first non-localhost IPv4 address, IPv6 are not supported by Yeelight currently
for (const auto& address : QNetworkInterface::allAddresses())
{
if (!address.isLoopback() && (address.protocol() == QAbstractSocket::IPv4Protocol))
{
std::cout << "Access the Hyperion User-Interface for configuration and control via:" << std::endl;
std::cout << "http:://" << address.toString().toStdString() << ":8090" << std::endl;
QHostInfo hostInfo = QHostInfo::fromName(address.toString());
if (hostInfo.error() == QHostInfo::NoError)
{
QString hostname = hostInfo.hostName();
std::cout << "http:://" << hostname.toStdString() << ":8090" << std::endl;
}
break;
}
}
return 0; return 0;
} }
} }
@ -226,13 +250,6 @@ int main(int argc, char** argv)
} }
} }
#ifdef WIN32
if (parser.isSet(consoleOption))
{
CreateConsole();
}
#endif
int logLevelCheck = 0; int logLevelCheck = 0;
if (parser.isSet(silentOption)) if (parser.isSet(silentOption))
{ {
@ -268,11 +285,13 @@ int main(int argc, char** argv)
std::cout << "Extract to folder: " << destDir.absolutePath().toStdString() << std::endl; std::cout << "Extract to folder: " << destDir.absolutePath().toStdString() << std::endl;
QStringList filenames = directory.entryList(QStringList() << "*", QDir::Files, QDir::Name | QDir::IgnoreCase); QStringList filenames = directory.entryList(QStringList() << "*", QDir::Files, QDir::Name | QDir::IgnoreCase);
QString destFileName; QString destFileName;
for (const QString & filename : filenames) for (const QString & filename : qAsConst(filenames))
{ {
destFileName = destDir.dirName()+"/"+filename; destFileName = destDir.dirName()+"/"+filename;
if (QFile::exists(destFileName)) if (QFile::exists(destFileName))
{
QFile::remove(destFileName); QFile::remove(destFileName);
}
std::cout << "Extract: " << filename.toStdString() << " ... "; std::cout << "Extract: " << filename.toStdString() << " ... ";
if (QFile::copy(QString(":/effects/")+filename, destFileName)) if (QFile::copy(QString(":/effects/")+filename, destFileName))
@ -303,22 +322,18 @@ int main(int argc, char** argv)
try try
{ {
if (dbFile.exists()) if (dbFile.exists())
{ {
if (!dbFile.isReadable()) if (!dbFile.isReadable())
{ {
throw std::runtime_error("Configuration database '" + dbFile.absoluteFilePath().toStdString() + "' is not readable. Please setup permissions correctly!"); throw std::runtime_error("Configuration database '" + dbFile.absoluteFilePath().toStdString() + "' is not readable. Please setup permissions correctly!");
} }
else
{
if (!dbFile.isWritable()) if (!dbFile.isWritable())
{ {
readonlyMode = true; readonlyMode = true;
} }
} }
}
else else
{ {
if (!userDataDirectory.mkpath(dbFile.absolutePath())) if (!userDataDirectory.mkpath(dbFile.absolutePath()))
@ -338,8 +353,7 @@ int main(int argc, char** argv)
Error(log,"Password reset is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(userDataDirectory.absolutePath())); Error(log,"Password reset is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(userDataDirectory.absolutePath()));
throw std::runtime_error("Password reset failed"); throw std::runtime_error("Password reset failed");
} }
else
{
AuthTable* table = new AuthTable(userDataDirectory.absolutePath()); AuthTable* table = new AuthTable(userDataDirectory.absolutePath());
if(table->resetHyperionUser()){ if(table->resetHyperionUser()){
Info(log,"Password reset successful"); Info(log,"Password reset successful");
@ -351,7 +365,6 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
} }
}
// delete database before start // delete database before start
if(parser.isSet(deleteDB)) if(parser.isSet(deleteDB))
@ -361,8 +374,7 @@ int main(int argc, char** argv)
Error(log,"Deleting the configuration database is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath())); Error(log,"Deleting the configuration database is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath()));
throw std::runtime_error("Deleting the configuration database failed"); throw std::runtime_error("Deleting the configuration database failed");
} }
else
{
if (QFile::exists(dbFile.absoluteFilePath())) if (QFile::exists(dbFile.absoluteFilePath()))
{ {
if (!QFile::remove(dbFile.absoluteFilePath())) if (!QFile::remove(dbFile.absoluteFilePath()))
@ -380,7 +392,6 @@ int main(int argc, char** argv)
Warning(log,"Configuration database [%s] does not exist!", QSTRING_CSTR(dbFile.absoluteFilePath())); Warning(log,"Configuration database [%s] does not exist!", QSTRING_CSTR(dbFile.absoluteFilePath()));
} }
} }
}
Info(log,"Starting Hyperion - %s, %s, built: %s:%s", HYPERION_VERSION, HYPERION_BUILD_ID, __DATE__, __TIME__); Info(log,"Starting Hyperion - %s, %s, built: %s:%s", HYPERION_VERSION, HYPERION_BUILD_ID, __DATE__, __TIME__);
Debug(log,"QtVersion [%s]", QT_VERSION_STR); Debug(log,"QtVersion [%s]", QT_VERSION_STR);