[Companion][Simulator] Add custom qDebug message handler/formatter (#4475)

* [Companion][Simulator] Add custom qDebug message handler/formatter as an option. Keeps support for QT_MESSAGE_PATTERN env. var.

* [Simulator] Show system messages of level qInfo and above in debug console.

* [Simulator] Still capture screenshot to clipboard if path is not accessible (and screenshot results now print to simulator debug console).

* Fix for older CMake.

* [Companion] Do not start debug message handler if app is shutting down, and add null checks before using it; Increase backtrace report depth; Add OTx headers; Add Companion exit status debug; Clean up unused code.

* [Simulator] Add asynchronous FIFO buffer for handling debug output/display more efficiently. (#4488)
(cherry-picked from b12bd7d7be)
This commit is contained in:
Max Paperno
2017-03-02 18:35:00 +01:00
committed by Bertrand Songis
parent 620094e358
commit 00b2799427
14 changed files with 352 additions and 72 deletions
+14
View File
@@ -21,6 +21,7 @@
#include "debugoutput.h"
#include "ui_debugoutput.h"
#include "appdebugmessagehandler.h"
#include "appdata.h"
#include "filteredtextbuffer.h"
@@ -100,6 +101,9 @@ DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator):
connect(ui->actionToggleFilter, &QAction::toggled, this, &DebugOutput::onFilterToggled);
connect(ui->filterText, &QComboBox::currentTextChanged, this, &DebugOutput::onFilterTextChanged);
if (AppDebugMessageHandler::instance())
connect(AppDebugMessageHandler::instance(), &AppDebugMessageHandler::messageOutput, this, &DebugOutput::onAppDebugMessage);
// send firmware TRACE events to our data collector
m_simulator->installTraceHook(firmwareTraceCb);
}
@@ -108,6 +112,8 @@ DebugOutput::~DebugOutput()
{
saveState();
if (AppDebugMessageHandler::instance())
disconnect(AppDebugMessageHandler::instance(), 0, this, 0);
if (m_dataBufferDevice) {
disconnect(m_dataBufferDevice, 0, this, 0);
@@ -198,6 +204,14 @@ void DebugOutput::onDataBufferOverflow(const qint64 len)
}
}
void DebugOutput::onAppDebugMessage(quint8 level, const QString & msg, const QMessageLogContext & context)
{
if (level > 0) {
firmwareTraceCb(qPrintable(msg));
firmwareTraceCb("\n");
}
}
/*
* UI handlers
*/
+2
View File
@@ -44,6 +44,7 @@ namespace Ui {
}
class QAbstractButton;
class QMessageLogContext;
class FilteredTextBuffer;
using namespace Simulator;
@@ -71,6 +72,7 @@ class DebugOutput : public QWidget
void restoreState();
void processBytesReceived();
void onDataBufferOverflow(const qint64 len);
void onAppDebugMessage(quint8 level, const QString & msg, const QMessageLogContext & context);
void onFilterStateChanged();
void onFilterTextChanged(const QString &);
void onFilterToggled(bool enable);
@@ -122,16 +122,16 @@ void SimulatedUIWidget::captureScreenshot()
if (path.isEmpty())
path = "./";
QDir dir(path);
if (!dir.exists() || !dir.isReadable()) {
// m_simulator->traceCallback("SIMULATOR ERROR - Cannot open screenshot folder, check your settings.\n");
qDebug() << "SIMULATOR ERROR - Cannot open screenshot folder, check your settings.";
return;
if (dir.exists() && dir.isReadable()) {
QStringList fwid = getCurrentFirmware()->getId().split("-", QString::SkipEmptyParts);
QString flavor = fwid.at(qMin(1, fwid.size()));
QString fnpfx = tr("screenshot", "Simulator LCD screenshot file name prefix");
fileName = "%1/%2_%3_%4.png";
fileName = fileName.arg(dir.absolutePath(), fnpfx, flavor, QDateTime::currentDateTime().toString("yy-MM-dd_HH-mm-ss"));
}
else {
qWarning() << "SIMULATOR ERROR - Cannot open screenshot folder, check your settings.";
}
QStringList fwid = getCurrentFirmware()->getId().split("-", QString::SkipEmptyParts);
QString flavor = fwid.at(qMin(1, fwid.size()));
QString fnpfx = tr("screenshot", "Simulator LCD screenshot file name prefix");
fileName = "%1/%2_%3_%4.png";
fileName = fileName.arg(dir.absolutePath(), fnpfx, flavor, QDateTime::currentDateTime().toString("yy-MM-dd_HH-mm-ss"));
}
m_lcd->makeScreenshot(fileName);
}
+5 -5
View File
@@ -22,6 +22,7 @@
#include "ui_simulatorwidget.h"
#include "appdata.h"
#include "appdebugmessagehandler.h"
#include "radiofaderwidget.h"
#include "radioknobwidget.h"
#include "radioswitchwidget.h"
@@ -36,7 +37,6 @@
#include "joystickdialog.h"
#endif
#include <QDebug>
#include <QFile>
#include <iostream>
@@ -332,11 +332,11 @@ bool SimulatorWidget::useTempDataPath(bool deleteOnClose)
setDataPath(tmpDir.path());
tmpDir.setAutoRemove(false);
deleteTempRadioData = deleteOnClose;
qDebug() << __FILE__ << __LINE__ << "Created temporary settings directory" << radioDataPath << "with delteOnClose:" << deleteOnClose;
qDebug() << "Created temporary settings directory" << radioDataPath << "with delteOnClose:" << deleteOnClose;
return true;
}
else {
qDebug() << __FILE__ << __LINE__ << "ERROR : Failed to create temporary settings directory" << radioDataPath;
qCritical() << "ERROR : Failed to create temporary settings directory" << radioDataPath;
return false;
}
}
@@ -381,7 +381,7 @@ bool SimulatorWidget::saveTempData()
if (!(ret = store.write(radioData)))
error = store.error();
else
qDebug() << __FILE__ << __LINE__ << "Saved radio data to file" << file;
qInfo() << "Saved radio data to file" << file;
}
}
@@ -398,7 +398,7 @@ void SimulatorWidget::deleteTempData()
{
if (!radioDataPath.isEmpty()) {
QDir tpath(radioDataPath);
qDebug() << __FILE__ << __LINE__ << "Deleting temporary settings directory" << tpath.absolutePath();
qDebug() << "Deleting temporary settings directory" << tpath.absolutePath();
tpath.removeRecursively();
tpath.rmdir(radioDataPath); // for some reason this is necessary to remove the base folder
}
+4 -3
View File
@@ -26,8 +26,9 @@
#include <QPainter>
#include <QClipboard>
#include <QDir>
#include <QDebug>
#include "appdata.h"
#include "appdebugmessagehandler.h"
class LcdWidget : public QWidget
{
@@ -90,12 +91,12 @@ class LcdWidget : public QWidget
QPainter p(&buffer);
doPaint(p);
if (fileName.isEmpty()) {
qDebug() << "Screenshot saved to clipboard";
QApplication::clipboard()->setPixmap( buffer );
qInfo() << "Screenshot saved to clipboard";
}
else {
qDebug() << "Screenshot" << fileName;
buffer.toImage().save(fileName);
qInfo() << "Screenshot saved to:" << fileName;
}
}