From cb6319142edfe9d6a5ceab5d211c6e718d842b56 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 17 Jul 2016 17:13:09 +0200 Subject: [PATCH 1/4] LP-361 - Don't lose notifications when more than an alarm is active , fix time between notifications condition, cleanup --- flight/modules/Notify/notify.c | 17 ++++++++++++----- flight/pios/common/pios_notify.c | 9 +++++---- flight/pios/inc/pios_notify.h | 3 ++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/flight/modules/Notify/notify.c b/flight/modules/Notify/notify.c index ef6aee552..ed3f7ded2 100644 --- a/flight/modules/Notify/notify.c +++ b/flight/modules/Notify/notify.c @@ -106,7 +106,7 @@ void onTimerCb(__attribute__((unused)) UAVObjEvent *ev) SystemAlarmsAlarmGet(&alarms); for (uint8_t i = 0; i < alarmsMapSize; i++) { - uint8_t alarm = ((uint8_t *)&alarms)[alarmsMap[i].alarmIndex]; + uint8_t alarm = SystemAlarmsAlarmToArray(alarms)[alarmsMap[i].alarmIndex]; checkAlarm(alarm, &alarmStatus[i].lastAlarm, &alarmStatus[i].lastAlarmTime, @@ -121,16 +121,23 @@ void checkAlarm(uint8_t alarm, uint8_t *last_alarm, uint32_t *last_alm_time, uin { if (alarm > SYSTEMALARMS_ALARM_OK) { uint32_t current_time = PIOS_DELAY_GetuS(); - if (*last_alarm < alarm || *last_alm_time + timeBetweenNotifications * 1000 > current_time) { + if (*last_alarm < alarm || (*last_alm_time + timeBetweenNotifications * 1000) < current_time) { uint8_t sequence = (alarm == SYSTEMALARMS_ALARM_WARNING) ? warn_sequence : ((alarm == SYSTEMALARMS_ALARM_CRITICAL) ? critical_sequence : error_sequence); + bool updated = true; if (sequence != NOTIFY_SEQUENCE_NULL) { - PIOS_NOTIFICATION_Default_Ext_Led_Play( + updated = PIOS_NOTIFICATION_Default_Ext_Led_Play( ¬ifications[sequence], alarm == SYSTEMALARMS_ALARM_WARNING ? NOTIFY_PRIORITY_REGULAR : NOTIFY_PRIORITY_CRITICAL); } - *last_alarm = alarm; - *last_alm_time = current_time; + if (updated) { + *last_alarm = alarm; + *last_alm_time = current_time; + } + } + // workaround timer overflow + if (*last_alm_time > current_time) { + *last_alm_time = 0; } } else { *last_alarm = SYSTEMALARMS_ALARM_OK; diff --git a/flight/pios/common/pios_notify.c b/flight/pios/common/pios_notify.c index 9b0a1fc67..1cf86a00d 100644 --- a/flight/pios/common/pios_notify.c +++ b/flight/pios/common/pios_notify.c @@ -56,18 +56,19 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear) * @param sequence Sequence to be played * @param priority Priority of the sequence being played */ -void PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority) +bool PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority) { - // alert and alarms are repeated if condition persists. bacground notification instead are set once, so try to prevent loosing any update + // alert and alarms are repeated if condition persists. background notification instead are set once, so try to prevent loosing any update if (newNotification && priority != NOTIFY_PRIORITY_BACKGROUND) { // prevent overwriting higher priority or background notifications - if (extLedNotification.priority == NOTIFY_PRIORITY_BACKGROUND || extLedNotification.priority > priority) { - return; + if (extLedNotification.priority == NOTIFY_PRIORITY_BACKGROUND || extLedNotification.priority >= priority) { + return false; } } extLedNotification.priority = priority; extLedNotification.sequence = *sequence; newNotification = true; + return true; } diff --git a/flight/pios/inc/pios_notify.h b/flight/pios/inc/pios_notify.h index 12daefdc2..3ee6a3dec 100644 --- a/flight/pios/inc/pios_notify.h +++ b/flight/pios/inc/pios_notify.h @@ -84,8 +84,9 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear); * are repeated only once if repeat = -1 * @param sequence Sequence to be played * @param priority Priority of the sequence being played + * @return true if sequence is enqueued, false otherwise */ -void PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority); +bool PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority); /* * Play a sequence on an external rgb led. Sequences with priority higher than NOTIFY_PRIORITY_LOW From 783bb836420b23e66c3338180107900234a7f1e0 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 17 Jul 2016 17:19:34 +0200 Subject: [PATCH 2/4] LP-361 - Cleanup sequences to make alarms easier to understand Error sequence: pause, RED, x 2, pause; warn sequence: pause, ORANGE, , pause; ITEM COLOR: - GPS = GREEN; - MAG = PURPLE; - CONFIG = RED; - RECEIVER = YELLOW. BATTERY ALARM: - warning 5x ORANGE blinks - critical 5x RED blinks DISARMED: short white blinks --- flight/libraries/inc/optypes.h | 7 +- flight/modules/Notify/inc/sequences.h | 103 +++++++++++++------------- 2 files changed, 58 insertions(+), 52 deletions(-) diff --git a/flight/libraries/inc/optypes.h b/flight/libraries/inc/optypes.h index 6b9080db7..677e8bf61 100644 --- a/flight/libraries/inc/optypes.h +++ b/flight/libraries/inc/optypes.h @@ -50,15 +50,18 @@ extern const Color_t Color_White; #define COLOR_BLACK { .R = 0x00, .G = 0x00, .B = 0x00 } #define COLOR_OFF COLOR_BLACK #define COLOR_RED { .R = 0xFF, .G = 0x00, .B = 0x00 } +#define COLOR_DARKRED { .R = 0x80, .G = 0x00, .B = 0x00 } #define COLOR_LIME { .R = 0x00, .G = 0xFF, .B = 0x00 } #define COLOR_BLUE { .R = 0x00, .G = 0x00, .B = 0xFF } -#define COLOR_YELLOW { .R = 0xFF, .G = 0xFF, .B = 0x00 } +#define COLOR_YELLOW { .R = 0xCC, .G = 0xCC, .B = 0x00 } #define COLOR_CIAN { .R = 0x00, .G = 0xFF, .B = 0xFF } #define COLOR_MAGENTA { .R = 0xFF, .G = 0x00, .B = 0xFF } #define COLOR_NAVY { .R = 0x00, .G = 0x00, .B = 0x80 } #define COLOR_GREEN { .R = 0x00, .G = 0x80, .B = 0x00 } #define COLOR_PURPLE { .R = 0x80, .G = 0x00, .B = 0x80 } #define COLOR_TEAL { .R = 0x00, .G = 0x80, .B = 0x80 } -#define COLOR_ORANGE { .R = 0xFF, .G = 0xA5, .B = 0x00 } +#define COLOR_ORANGE { .R = 0xAA, .G = 0x44, .B = 0x00 } #define COLOR_WHITE { .R = 0xAA, .G = 0xAA, .B = 0xAA } + + #endif /* UTIL_H */ diff --git a/flight/modules/Notify/inc/sequences.h b/flight/modules/Notify/inc/sequences.h index 3298d5ff0..72e99203a 100644 --- a/flight/modules/Notify/inc/sequences.h +++ b/flight/modules/Notify/inc/sequences.h @@ -35,25 +35,26 @@ // This represent the list of basic light sequences, defined later typedef enum { NOTIFY_SEQUENCE_ARMED_FM_MANUAL = 0, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1 = 1, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2 = 2, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3 = 3, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4 = 4, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5 = 5, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6 = 6, - NOTIFY_SEQUENCE_ARMED_FM_GPS = 8, - NOTIFY_SEQUENCE_ARMED_FM_RTH = 9, - NOTIFY_SEQUENCE_ARMED_FM_LAND = 10, - NOTIFY_SEQUENCE_ARMED_FM_AUTO = 11, - NOTIFY_SEQUENCE_ALM_WARN_GPS = 12, - NOTIFY_SEQUENCE_ALM_ERROR_GPS = 13, - NOTIFY_SEQUENCE_ALM_WARN_BATTERY = 14, - NOTIFY_SEQUENCE_ALM_ERROR_BATTERY = 15, - NOTIFY_SEQUENCE_ALM_MAG = 16, - NOTIFY_SEQUENCE_ALM_CONFIG = 17, - NOTIFY_SEQUENCE_ALM_RECEIVER = 18, - NOTIFY_SEQUENCE_DISARMED = 19, - NOTIFY_SEQUENCE_ALM_ATTITUDE = 20, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6, + NOTIFY_SEQUENCE_ARMED_FM_GPS, + NOTIFY_SEQUENCE_ARMED_FM_RTH, + NOTIFY_SEQUENCE_ARMED_FM_LAND, + NOTIFY_SEQUENCE_ARMED_FM_AUTO, + NOTIFY_SEQUENCE_ALM_WARN_GPS, + NOTIFY_SEQUENCE_ALM_ERROR_GPS, + NOTIFY_SEQUENCE_ALM_WARN_BATTERY, + NOTIFY_SEQUENCE_ALM_ERROR_BATTERY, + NOTIFY_SEQUENCE_ALM_WARN_MAG, + NOTIFY_SEQUENCE_ALM_ERROR_MAG, + NOTIFY_SEQUENCE_ALM_CONFIG, + NOTIFY_SEQUENCE_ALM_RECEIVER, + NOTIFY_SEQUENCE_DISARMED, + NOTIFY_SEQUENCE_ALM_ATTITUDE, NOTIFY_SEQUENCE_NULL = 255, // skips any signalling for this condition } NotifySequences; @@ -66,6 +67,21 @@ typedef struct { uint8_t errorNotification; // index of the sequence to be used when alarm is in error status(pick one from NotifySequences enum) } AlarmDefinition_t; +#define STANDARD_ERROR_SEQUENCE(alarm_color, alarm_repeats) \ + { .repeats = alarm_repeats, .steps = { \ + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = COLOR_DARKRED, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = alarm_color, .repeats = 2, }, \ + { .time_off = 100, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + }, } + +#define STANDARD_WARN_SEQUENCE(alarm_color, alarm_repeats) \ + { .repeats = alarm_repeats, .steps = { \ + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = COLOR_ORANGE, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = alarm_color, .repeats = 1, }, \ + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + }, } // This is the list of defined light sequences /* how each sequence is defined @@ -90,10 +106,12 @@ typedef struct { */ const LedSequence_t notifications[] = { [NOTIFY_SEQUENCE_DISARMED] = { .repeats = -1, .steps = { - { .time_off = 500, .time_on = 500, .color = COLOR_TEAL, .repeats = 1, }, + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, + { .time_off = 100, .time_on = 100, .color = COLOR_WHITE, .repeats = 1, }, + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, }, }, [NOTIFY_SEQUENCE_ARMED_FM_MANUAL] = { .repeats = -1, .steps = { - { .time_off = 900, .time_on = 100, .color = COLOR_YELLOW, .repeats = 1, }, + { .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, }, }, }, [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1] = { .repeats = -1, .steps = { { .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, }, @@ -132,34 +150,19 @@ const LedSequence_t notifications[] = { { .time_off = 100, .time_on = 200, .color = COLOR_GREEN, .repeats = 2, }, { .time_off = 500, .time_on = 200, .color = COLOR_GREEN, .repeats = 1, }, }, }, - - [NOTIFY_SEQUENCE_ALM_WARN_GPS] = { .repeats = 2, .steps = { - { .time_off = 300, .time_on = 300, .color = COLOR_ORANGE, .repeats = 2, }, - { .time_off = 300, .time_on = 300, .color = COLOR_GREEN, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_ERROR_GPS] = { .repeats = 2, .steps = { - { .time_off = 300, .time_on = 300, .color = COLOR_RED, .repeats = 2, }, - { .time_off = 300, .time_on = 300, .color = COLOR_GREEN, .repeats = 1, }, - }, }, + [NOTIFY_SEQUENCE_ALM_WARN_GPS] = STANDARD_WARN_SEQUENCE(COLOR_GREEN, 1), + [NOTIFY_SEQUENCE_ALM_ERROR_GPS] = STANDARD_ERROR_SEQUENCE(COLOR_GREEN, 1), [NOTIFY_SEQUENCE_ALM_WARN_BATTERY] = { .repeats = 1, .steps = { - { .time_off = 100, .time_on = 100, .color = COLOR_ORANGE, .repeats = 10, }, + { .time_off = 100, .time_on = 100, .color = COLOR_ORANGE, .repeats = 5, }, }, }, [NOTIFY_SEQUENCE_ALM_ERROR_BATTERY] = { .repeats = 1, .steps = { - { .time_off = 100, .time_on = 100, .color = COLOR_RED, .repeats = 10, }, + { .time_off = 100, .time_on = 100, .color = COLOR_RED, .repeats = 5, }, }, }, - [NOTIFY_SEQUENCE_ALM_MAG] = { .repeats = 1, .steps = { - { .time_off = 300, .time_on = 300, .color = COLOR_RED, .repeats = 2, }, - { .time_off = 300, .time_on = 300, .color = COLOR_PURPLE, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_CONFIG] = { .repeats = 1, .steps = { - { .time_off = 50, .time_on = 50, .color = COLOR_RED, .repeats = 9, }, - { .time_off = 500, .time_on = 50, .color = COLOR_RED, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_RECEIVER] = { .repeats = 1, .steps = { - { .time_off = 50, .time_on = 50, .color = COLOR_ORANGE, .repeats = 9, }, - { .time_off = 500, .time_on = 50, .color = COLOR_ORANGE, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_ATTITUDE] = { .repeats = 10, .steps = { + [NOTIFY_SEQUENCE_ALM_ERROR_MAG] = STANDARD_ERROR_SEQUENCE(COLOR_PURPLE, 1), + [NOTIFY_SEQUENCE_ALM_WARN_MAG] = STANDARD_WARN_SEQUENCE(COLOR_PURPLE, 1), + [NOTIFY_SEQUENCE_ALM_CONFIG] = STANDARD_ERROR_SEQUENCE(COLOR_RED, 2), + [NOTIFY_SEQUENCE_ALM_RECEIVER] = STANDARD_ERROR_SEQUENCE(COLOR_YELLOW, 1), + [NOTIFY_SEQUENCE_ALM_ATTITUDE] = { .repeats = 10, .steps = { { .time_off = 0, .time_on = 50, .color = COLOR_RED, .repeats = 1, }, { .time_off = 0, .time_on = 50, .color = COLOR_BLUE, .repeats = 1, }, }, }, @@ -193,7 +196,7 @@ const LedSequence_t *flightModeMap[] = { // List of alarms to show with attached sequences for each status const AlarmDefinition_t alarmsMap[] = { { - .timeBetweenNotifications = 10000, + .timeBetweenNotifications = 5000, .alarmIndex = SYSTEMALARMS_ALARM_GPS, .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_GPS, .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_GPS, @@ -202,9 +205,9 @@ const AlarmDefinition_t alarmsMap[] = { { .timeBetweenNotifications = 5000, .alarmIndex = SYSTEMALARMS_ALARM_MAGNETOMETER, - .warnNotification = NOTIFY_SEQUENCE_NULL, - .criticalNotification = NOTIFY_SEQUENCE_ALM_MAG, - .errorNotification = NOTIFY_SEQUENCE_ALM_MAG, + .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_MAG, + .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG, + .errorNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG, }, { .timeBetweenNotifications = 15000, @@ -221,7 +224,7 @@ const AlarmDefinition_t alarmsMap[] = { .errorNotification = NOTIFY_SEQUENCE_ALM_CONFIG, }, { - .timeBetweenNotifications = 2000, + .timeBetweenNotifications = 5000, .alarmIndex = SYSTEMALARMS_ALARM_RECEIVER, .warnNotification = NOTIFY_SEQUENCE_ALM_RECEIVER, .criticalNotification = NOTIFY_SEQUENCE_ALM_RECEIVER, From 54b33e0a077ad0059b755a3972ff96ed7be7d8cc Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 21 Jul 2016 01:51:08 +0200 Subject: [PATCH 3/4] LP-362 make file logging thread safe (and asynchronous) --- ground/gcs/src/app/main.cpp | 52 +++------ ground/gcs/src/libs/utils/filelogger.h | 141 +++++++++++++++++++++++++ ground/gcs/src/libs/utils/utils.pro | 3 +- 3 files changed, 158 insertions(+), 38 deletions(-) create mode 100644 ground/gcs/src/libs/utils/filelogger.h diff --git a/ground/gcs/src/app/main.cpp b/ground/gcs/src/app/main.cpp index fa1e946bb..9644bea5c 100644 --- a/ground/gcs/src/app/main.cpp +++ b/ground/gcs/src/app/main.cpp @@ -84,6 +84,7 @@ #include "qtsingleapplication.h" #include "utils/xmlconfig.h" #include "utils/pathutils.h" +#include "utils/filelogger.h" #include "gcssplashscreen.h" #include @@ -108,7 +109,6 @@ #include #include -namespace { typedef QList PluginSpecSet; typedef QMap AppOptions; typedef QMap AppOptionValues; @@ -286,48 +286,21 @@ void systemInit() QSurfaceFormat::setDefaultFormat(format); } -static QTextStream *logStream; +static FileLogger *logger; void mainMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { - Q_UNUSED(context); - - QTextStream &out = *logStream; - - // logStream << QTime::currentTime().toString("hh:mm:ss.zzz "); - - switch (type) { - case QtDebugMsg: - out << "DBG: "; - break; -#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) - case QtInfoMsg: - out << "INF: "; - break; -#endif - case QtWarningMsg: - out << "WRN: "; - break; - case QtCriticalMsg: - out << "CRT: "; - break; - case QtFatalMsg: - out << "FTL: "; - break; - } - - out << msg << '\n'; - out.flush(); + logger->log(type, context, msg); } +Q_DECLARE_METATYPE(QtMsgType) + void logInit(QString fileName) { - QFile *file = new QFile(fileName); - - if (file->open(QIODevice::WriteOnly | QIODevice::Text)) { - logStream = new QTextStream(file); - qInstallMessageHandler(mainMessageOutput); - } else { + qRegisterMetaType(); + qInstallMessageHandler(mainMessageOutput); + logger = new FileLogger(); + if (!logger->start(fileName)) { displayError(msgLogfileOpenFailed(fileName)); } } @@ -456,7 +429,6 @@ void loadTranslators(QString language, QTranslator &translator, QTranslator &qtT translator.load(QString()); } } -} // namespace anonymous int main(int argc, char * *argv) { @@ -494,6 +466,8 @@ int main(int argc, char * *argv) if (appOptionValues.contains(LOG_FILE_OPTION)) { QString logFileName = appOptionValues.value(LOG_FILE_OPTION); logInit(logFileName); + // relog command line arguments for the benefit of the file logger... + qDebug() << "Command line" << app.arguments(); } // load user settings @@ -644,5 +618,9 @@ int main(int argc, char * *argv) qDebug() << "main - GCS ran for" << timer.elapsed() << "ms"; + if (logger) { + delete logger; + } + return ret; } diff --git a/ground/gcs/src/libs/utils/filelogger.h b/ground/gcs/src/libs/utils/filelogger.h new file mode 100644 index 000000000..8c5b8d3b1 --- /dev/null +++ b/ground/gcs/src/libs/utils/filelogger.h @@ -0,0 +1,141 @@ +/** + ****************************************************************************** + * + * @file filelogger.h + * @author The LibrePilot Project, http://www.openpilot.org Copyright (C) 2016. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#pragma once + +#include "utils_global.h" + +#include +#include +#include +#include +#include + +class QTCREATOR_UTILS_EXPORT FileLogger : public QObject { + Q_OBJECT + +private: + QTextStream * logStream; + QThread *loggerThread; + bool started; + +public: + FileLogger() : QObject(), logStream(NULL), loggerThread(NULL), started(false) + {} + + virtual ~FileLogger() + { + stop(); + if (logStream) { + delete logStream; + } + } + +public: + bool start(const QString &fileName) + { + if (started) { + return false; + } + + QFile *file = new QFile(fileName); + if (!file->open(QIODevice::WriteOnly | QIODevice::Text)) { + return false; + } + + logStream = new QTextStream(file); + + loggerThread = new QThread(this); + moveToThread(loggerThread); + loggerThread->start(); + + started = true; + + return true; + } + + bool stop() + { + if (!started) { + return false; + } + // stop accepting messages + started = false; + + // make sure all messages are flushed by sending a blocking message + QtMsgType type = QtDebugMsg; + const QString msg = "stopping file logger"; + QMetaObject::invokeMethod(this, "doLog", Qt::BlockingQueuedConnection, + Q_ARG(QtMsgType, type), Q_ARG(const QString &, msg)); + + return true; + } + + void log(QtMsgType type, const QMessageLogContext &context, const QString &msg) + { + Q_UNUSED(context); + + if (!started) { + return; + } + + QMetaObject::invokeMethod(this, "doLog", Qt::QueuedConnection, + Q_ARG(QtMsgType, type), Q_ARG(const QString &, msg)); + } + +private slots: + void doLog(QtMsgType type, const QString &msg) + { + QTextStream &out = *logStream; + + // logStream << QTime::currentTime().toString("hh:mm:ss.zzz "); + + switch (type) { + case QtDebugMsg: + out << "DBG: "; + break; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) + case QtInfoMsg: + out << "INF: "; + break; +#endif + case QtWarningMsg: + out << "WRN: "; + break; + case QtCriticalMsg: + out << "CRT: "; + break; + case QtFatalMsg: + out << "FTL: "; + break; + } + + out << msg << '\n'; + out.flush(); + } +}; diff --git a/ground/gcs/src/libs/utils/utils.pro b/ground/gcs/src/libs/utils/utils.pro index 16701460f..4e291df1b 100644 --- a/ground/gcs/src/libs/utils/utils.pro +++ b/ground/gcs/src/libs/utils/utils.pro @@ -121,7 +121,8 @@ HEADERS += \ logfile.h \ crc.h \ mustache.h \ - textbubbleslider.h + textbubbleslider.h \ + filelogger.h HEADERS += xmlconfig.h From 026ef32f7381167f807437eee06ec7607fbaa572 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 21 Jul 2016 01:51:55 +0200 Subject: [PATCH 4/4] LP-362 enable osg log redirection to Qt --- ground/gcs/src/libs/osgearth/osgearth.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ground/gcs/src/libs/osgearth/osgearth.cpp b/ground/gcs/src/libs/osgearth/osgearth.cpp index 74864ef3b..ce1ab407a 100644 --- a/ground/gcs/src/libs/osgearth/osgearth.cpp +++ b/ground/gcs/src/libs/osgearth/osgearth.cpp @@ -71,9 +71,9 @@ void OsgEarth::registerQmlTypes() } registered = true; - // redirect osg logging to Qt (and export OSG_NOTIFY_LEVEL=DEBUG to enable osg logging) - // Note : enabling the notify handler seems to cause crashes (the notifier is probably not thread safe) - // osg::setNotifyHandler(new QtNotifyHandler()); + // use "export OSG_NOTIFY_LEVEL=DEBUG" on command line to enable osg logging + // redirect osg logging to Qt + osg::setNotifyHandler(new QtNotifyHandler()); // initialize();