Fix logger and led colors (#906)

This commit is contained in:
Murat Seker 2020-07-27 20:00:36 +02:00 committed by GitHub
parent 773b47bf53
commit d4b4158cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 41 deletions

View File

@ -1,13 +1,14 @@
var conf_editor = null; var conf_editor = null;
var createdCont = false; var createdCont = false;
performTranslation();
requestLoggingStart(); performTranslation();
requestLoggingStart();
$(document).ready(function() { $(document).ready(function() {
var messages; var messages;
var loguplmess = ""; var loguplmess = "";
var reportUrl = 'https://report.hyperion-project.org/#'; var reportUrl = 'https://report.hyperion-project.org/#';
$('#conf_cont').append(createOptPanel('fa-reorder', $.i18n("edt_conf_log_heading_title"), 'editor_container', 'btn_submit')); $('#conf_cont').append(createOptPanel('fa-reorder', $.i18n("edt_conf_log_heading_title"), 'editor_container', 'btn_submit'));
if(window.showOptHelp) if(window.showOptHelp)
{ {
@ -15,15 +16,15 @@ $(document).ready(function() {
createHintH("intro", $.i18n('conf_logging_label_intro'), "log_head"); createHintH("intro", $.i18n('conf_logging_label_intro'), "log_head");
} }
$("#log_upl_pol").append('<span style="color:grey;font-size:80%">'+$.i18n("conf_logging_uplpolicy")+' '+buildWL("user/support#report_privacy_policy",$.i18n("conf_logging_contpolicy"))); $("#log_upl_pol").append('<span style="color:grey;font-size:80%">'+$.i18n("conf_logging_uplpolicy")+' '+buildWL("user/support#report_privacy_policy",$.i18n("conf_logging_contpolicy")));
conf_editor = createJsonEditor('editor_container', { conf_editor = createJsonEditor('editor_container', {
logger : window.schema.logger logger : window.schema.logger
}, true, true); }, true, true);
conf_editor.on('change',function() { conf_editor.on('change',function() {
conf_editor.validate().length ? $('#btn_submit').attr('disabled', true) : $('#btn_submit').attr('disabled', false); conf_editor.validate().length ? $('#btn_submit').attr('disabled', true) : $('#btn_submit').attr('disabled', false);
}); });
$('#btn_submit').off().on('click',function() { $('#btn_submit').off().on('click',function() {
requestWriteConfig(conf_editor.getValue()); requestWriteConfig(conf_editor.getValue());
}); });
@ -33,7 +34,7 @@ $(document).ready(function() {
$(this).attr("disabled", true); $(this).attr("disabled", true);
$('#upl_link').html($.i18n('conf_logging_uploading')) $('#upl_link').html($.i18n('conf_logging_uploading'))
}); });
//show prev uploads //show prev uploads
var ent; var ent;
@ -48,7 +49,7 @@ $(document).ready(function() {
} }
else else
ent = []; ent = [];
function updateLastReports(id,time,title) function updateLastReports(id,time,title)
{ {
if(ent.length > 4) if(ent.length > 4)
@ -56,7 +57,7 @@ $(document).ready(function() {
ent.unshift({"id": id ,"time": time,"title": title}) ent.unshift({"id": id ,"time": time,"title": title})
setStorage("prev_reports",JSON.stringify(ent)); setStorage("prev_reports",JSON.stringify(ent));
} }
function uploadLog() function uploadLog()
{ {
var log = ""; var log = "";
@ -66,7 +67,7 @@ $(document).ready(function() {
var sys = window.sysInfo.system; var sys = window.sysInfo.system;
var shy = window.sysInfo.hyperion; var shy = window.sysInfo.hyperion;
var info; var info;
//create log //create log
log = (messages ? loguplmess : "Log was empty!"); log = (messages ? loguplmess : "Log was empty!");
@ -83,7 +84,7 @@ $(document).ready(function() {
info += 'Arch: '+sys.architecture+'\n'; info += 'Arch: '+sys.architecture+'\n';
info += 'Kernel: '+sys.kernelType+' ('+sys.kernelVersion+' (WS: '+sys.wordSize+'))\n'; info += 'Kernel: '+sys.kernelType+' ('+sys.kernelVersion+' (WS: '+sys.wordSize+'))\n';
info += 'Browser/OS: '+navigator.userAgent+'\n\n'; info += 'Browser/OS: '+navigator.userAgent+'\n\n';
//create prios //create prios
info += "### PRIORITIES ### \n"; info += "### PRIORITIES ### \n";
for(var i = 0; i<prios.length; i++) for(var i = 0; i<prios.length; i++)
@ -96,14 +97,14 @@ $(document).ready(function() {
info += ' ('+prios[i].component+') Owner: '+prios[i].owner+'\n'; info += ' ('+prios[i].component+') Owner: '+prios[i].owner+'\n';
} }
info += '\npriorities_autoselect: '+window.serverInfo.priorities_autoselect+'\n\n'; info += '\npriorities_autoselect: '+window.serverInfo.priorities_autoselect+'\n\n';
//create comps //create comps
info += '### COMPONENTS ### \n'; info += '### COMPONENTS ### \n';
for(var i = 0; i<comps.length; i++) for(var i = 0; i<comps.length; i++)
{ {
info += comps[i].enabled+' - '+comps[i].name+'\n'; info += comps[i].enabled+' - '+comps[i].name+'\n';
} }
//escape data //escape data
info = JSON.stringify(info); info = JSON.stringify(info);
log = JSON.stringify(log); log = JSON.stringify(log);
@ -143,24 +144,25 @@ $(document).ready(function() {
{ {
window.loggingHandlerInstalled = true; window.loggingHandlerInstalled = true;
$(window.hyperion).on("cmd-logging-update",function(event){ $(window.hyperion).on("cmd-logging-update",function(event){
if ($("#logmessages").length == 0 && window.loggingStreamActive) if ($("#logmessages").length == 0 && window.loggingStreamActive)
{ {
requestLoggingStop(); requestLoggingStop();
window.loggingStreamActive = false; window.loggingStreamActive = false;
} }
messages = (event.response.result.messages); messages = (event.response.result.messages);
if(messages.length != 0 && !createdCont) if(messages.length != 0 && !createdCont)
{ {
$('#log_content').html('<pre><div id="logmessages" style="overflow:scroll;max-height:400px"></div></pre><button class="btn btn-primary" id="btn_autoscroll"><i class="fa fa-long-arrow-down fa-fw"></i>'+$.i18n('conf_logging_btn_autoscroll')+'</button>'); $('#log_content').html('<pre><div id="logmessages" style="overflow:scroll;max-height:400px"></div></pre><button class="btn btn-primary" id="btn_autoscroll"><i class="fa fa-long-arrow-down fa-fw"></i>'+$.i18n('conf_logging_btn_autoscroll')+'</button>');
createdCont = true; createdCont = true;
$('#btn_autoscroll').off().on('click',function() { $('#btn_autoscroll').off().on('click',function() {
toggleClass('#btn_autoscroll', "btn-success", "btn-danger"); toggleClass('#btn_autoscroll', "btn-success", "btn-danger");
}); });
} }
for(var idx=0; idx<messages.length; idx++)
for(var idx = 0; idx < messages.length; idx++)
{ {
var app_name = messages[idx].appName; var app_name = messages[idx].appName;
var logger_name = messages[idx].loggerName; var logger_name = messages[idx].loggerName;
@ -169,23 +171,27 @@ $(document).ready(function() {
var file_name = messages[idx].fileName; var file_name = messages[idx].fileName;
var msg = messages[idx].message; var msg = messages[idx].message;
var level_string = messages[idx].levelString; var level_string = messages[idx].levelString;
var utime = messages[idx].utime;
var debug = ""; var debug = "";
if(level_string == "DEBUG") { if(level_string == "DEBUG") {
debug = "("+file_name+":"+line+":"+function_+"()) "; debug = "("+file_name+":"+line+":"+function_+"()) ";
} }
$("#logmessages").append("\n <code>"+"["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"</code>"); var date = new Date(parseInt(utime));
$("#logmessages").append("\n <code>"+date.toISOString()+" ["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"</code>");
loguplmess += "["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"\n"; loguplmess += "["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"\n";
} }
if($("#btn_autoscroll").hasClass('btn-success')){
if($("#btn_autoscroll").hasClass('btn-success'))
{
$('#logmessages').stop().animate({ $('#logmessages').stop().animate({
scrollTop: $('#logmessages')[0].scrollHeight scrollTop: $('#logmessages')[0].scrollHeight
}, 800); }, 800);
} }
}); });
} }
removeOverlay(); removeOverlay();
}); });

View File

@ -165,9 +165,9 @@ public:
/// ///
/// @param[out] image The image that buffers the output /// @param[out] image The image that buffers the output
/// ///
void toRgb(Image<ColorRgb>& image) void toRgb(Image<ColorRgb>& image) const
{ {
_d_ptr->toRgb(*(image.imageData())); _d_ptr->toRgb(*image._d_ptr);
} }
/// ///
@ -186,12 +186,10 @@ public:
_d_ptr->clear(); _d_ptr->clear();
} }
QSharedDataPointer<ImageData<Pixel_T>> imageData() const
{
return _d_ptr;
}
private: private:
template<class T>
friend class Image;
/// ///
/// Translate x and y coordinate to index of the underlying vector /// Translate x and y coordinate to index of the underlying vector
/// ///

View File

@ -134,7 +134,7 @@ public:
return _pixels; return _pixels;
} }
void toRgb(ImageData<ColorRgb>& image) void toRgb(ImageData<ColorRgb>& image) const
{ {
if (image.width() != _width || image.height() != _height) if (image.width() != _width || image.height() != _height)
image.resize(_width, _height); image.resize(_width, _height);

View File

@ -79,7 +79,7 @@ protected:
~Logger(); ~Logger();
private: private:
void write(const Logger::T_LOG_MESSAGE & message) const; void write(const Logger::T_LOG_MESSAGE & message);
static QMutex MapLock; static QMutex MapLock;
static QMap<QString,Logger*> LoggerMap; static QMap<QString,Logger*> LoggerMap;
@ -106,7 +106,7 @@ public slots:
void handleNewLogMessage(const Logger::T_LOG_MESSAGE&); void handleNewLogMessage(const Logger::T_LOG_MESSAGE&);
signals: signals:
void newLogMessage(Logger::T_LOG_MESSAGE); void newLogMessage(const Logger::T_LOG_MESSAGE&);
protected: protected:
LoggerManager(); LoggerManager();

View File

@ -1053,7 +1053,7 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co
if (!_streaming_logging_activated) if (!_streaming_logging_activated)
{ {
_streaming_logging_reply["command"] = command + "-update"; _streaming_logging_reply["command"] = command + "-update";
connect(LoggerManager::getInstance(), SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE))); connect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage);
Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); // needed to trigger log sending Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); // needed to trigger log sending
} }
} }
@ -1061,7 +1061,7 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co
{ {
if (_streaming_logging_activated) if (_streaming_logging_activated)
{ {
disconnect(LoggerManager::getInstance(), SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, 0); disconnect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage);
_streaming_logging_activated = false; _streaming_logging_activated = false;
Debug(_log, "log streaming deactivated for client %s", _peerAddress.toStdString().c_str()); Debug(_log, "log streaming deactivated for client %s", _peerAddress.toStdString().c_str());
} }
@ -1561,6 +1561,7 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
message["fileName"] = logBuffer->at(i).fileName; message["fileName"] = logBuffer->at(i).fileName;
message["message"] = logBuffer->at(i).message; message["message"] = logBuffer->at(i).message;
message["levelString"] = logBuffer->at(i).levelString; message["levelString"] = logBuffer->at(i).levelString;
message["utime"] = QString::number(logBuffer->at(i).utime);
messageArray.append(message); messageArray.append(message);
} }
@ -1574,6 +1575,7 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
message["fileName"] = msg.fileName; message["fileName"] = msg.fileName;
message["message"] = msg.message; message["message"] = msg.message;
message["levelString"] = msg.levelString; message["levelString"] = msg.levelString;
message["utime"] = QString::number(msg.utime);
messageArray.append(message); messageArray.append(message);
} }

View File

@ -379,8 +379,18 @@ void Hyperion::setColor(const int priority, const std::vector<ColorRgb> &ledColo
_effectEngine->channelCleared(priority); _effectEngine->channelCleared(priority);
// create full led vector from single/multiple colors // create full led vector from single/multiple colors
size_t size = _ledString.leds().size();
std::vector<ColorRgb> newLedColors; std::vector<ColorRgb> newLedColors;
std::copy_n(ledColors.begin(), _ledString.leds().size(), std::back_inserter(newLedColors)); while (true)
{
for (const auto &entry : ledColors)
{
newLedColors.emplace_back(entry);
if (newLedColors.size() == size)
goto end;
}
}
end:
if (getPriorityInfo(priority).componentId != hyperion::COMP_COLOR) if (getPriorityInfo(priority).componentId != hyperion::COMP_COLOR)
clear(priority); clear(priority);

View File

@ -243,9 +243,10 @@ QJsonObject LedDeviceWled::getProperties(const QJsonObject& params)
return properties; return properties;
} }
void LedDeviceWled::identify(const QJsonObject& params) void LedDeviceWled::identify(const QJsonObject& /*params*/)
{ {
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() ); #if 0
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
QJsonObject properties; QJsonObject properties;
// Get Nanoleaf device properties // Get Nanoleaf device properties
@ -281,6 +282,7 @@ void LedDeviceWled::identify(const QJsonObject& params)
// Warning (_log, "%s identification failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason())); // Warning (_log, "%s identification failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
// } // }
} }
#endif
} }
int LedDeviceWled::write(const std::vector<ColorRgb> &ledValues) int LedDeviceWled::write(const std::vector<ColorRgb> &ledValues)

View File

@ -9,6 +9,10 @@
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QNetworkConfigurationManager> #include <QNetworkConfigurationManager>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QRandomGenerator>
#endif
static const QString SSDP_HYPERION_ST("urn:hyperion-project.org:device:basic:1"); static const QString SSDP_HYPERION_ST("urn:hyperion-project.org:device:basic:1");
SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, const quint16& jsonServerPort, const QString& name, QObject * parent) SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, const quint16& jsonServerPort, const QString& name, QObject * parent)
@ -162,7 +166,11 @@ void SSDPHandler::handleMSearchRequest(const QString& target, const QString& mx,
if (ok) if (ok)
{ {
/* Pick a random delay between 0 and MX seconds */ /* Pick a random delay between 0 and MX seconds */
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
int randomDelay = QRandomGenerator::global()->generate() % (maxDelay * 1000);
#else
int randomDelay = qrand() % (maxDelay * 1000); int randomDelay = qrand() % (maxDelay * 1000);
#endif
QTimer::singleShot(randomDelay, respond); QTimer::singleShot(randomDelay, respond);
} }
else else

View File

@ -155,7 +155,7 @@ Logger::~Logger()
} }
} }
void Logger::write(const Logger::T_LOG_MESSAGE & message) const void Logger::write(const Logger::T_LOG_MESSAGE & message)
{ {
QString location; QString location;
if (message.level == Logger::DEBUG) if (message.level == Logger::DEBUG)
@ -179,6 +179,8 @@ void Logger::write(const Logger::T_LOG_MESSAGE & message) const
.arg(message.message) .arg(message.message)
.toStdString() .toStdString()
<< std::endl; << std::endl;
newLogMessage(message);
} }
void Logger::Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...) void Logger::Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...)