1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-1245 Added code to read current log settings from uavos.

This commit is contained in:
m_thread 2014-03-19 17:08:33 +01:00
parent 1dae98a378
commit a327d49049
5 changed files with 96 additions and 23 deletions

View File

@ -187,6 +187,7 @@ Rectangle {
ComboBox {
enabled: !logManager.disableControls && logManager.boardConnected
model: logManager.logStatuses
Layout.preferredWidth: 200
currentIndex: logSettings.loggingEnabled
onCurrentIndexChanged: {
logManager.setLoggingEnabled(currentIndex);
@ -239,8 +240,9 @@ Rectangle {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
elide: styleData.elideMode
text: styleData.value !== undefined && (logManager.uavoEntries[styleData.row].setting > 1) ?
parseInt(logManager.uavoEntries[styleData.row].period) + " ms" : "-"
text: styleData.value !== undefined &&
(logManager.uavoEntries[styleData.row].setting === 1 || logManager.uavoEntries[styleData.row].setting === 3) ?
parseInt(logManager.uavoEntries[styleData.row].period) + " ms" : "-"
color: styleData.textColor
//visible: !styleData.selected && (logManager.uavoEntries[styleData.row].setting <= 1)
enabled: (logManager.uavoEntries[styleData.row].setting > 1)
@ -254,7 +256,8 @@ Rectangle {
logManager.uavoEntries[styleData.row].period = loaderEditor.item.value
}
}
sourceComponent: styleData.selected && (logManager.uavoEntries[styleData.row].setting > 1) ? editor : null
sourceComponent: styleData.selected &&
(logManager.uavoEntries[styleData.row].setting === 1 || logManager.uavoEntries[styleData.row].setting === 3) ? editor : null
Component {
id: editor
SpinBox {
@ -292,6 +295,7 @@ Rectangle {
Text {
verticalAlignment: Text.AlignVCenter
anchors.leftMargin: 5
color: logManager.uavoEntries[styleData.row].dirty ? "#f00" : "#000"
text: styleData.value
}
@ -331,7 +335,13 @@ Rectangle {
enabled: !logManager.disableControls && logManager.boardConnected
text: qsTr("Reset")
activeFocusOnPress: true
onClicked: logManager.resetSettings()
onClicked: logManager.resetSettings(false)
}
Button {
enabled: !logManager.disableControls && logManager.boardConnected
text: qsTr("Clear")
activeFocusOnPress: true
onClicked: logManager.resetSettings(true)
}
Rectangle {
Layout.fillWidth: true

View File

@ -38,6 +38,7 @@
#include "uavobjecthelper.h"
#include "uavtalk/uavtalk.h"
#include "utils/logfile.h"
#include "uavdataobject.h"
#include <uavobjectutil/uavobjectutilmanager.h>
FlightLogManager::FlightLogManager(QObject *parent) :
@ -55,10 +56,6 @@ FlightLogManager::FlightLogManager(QObject *parent) :
m_telemtryManager = pluginManager->getObject<TelemetryManager>();
Q_ASSERT(m_telemtryManager);
connect(m_telemtryManager, SIGNAL(connected()), this, SLOT(connectionStatusChanged()));
connect(m_telemtryManager, SIGNAL(disconnected()), this, SLOT(connectionStatusChanged()));
connectionStatusChanged();
m_flightLogControl = DebugLogControl::GetInstance(m_objectManager);
Q_ASSERT(m_flightLogControl);
@ -74,9 +71,12 @@ FlightLogManager::FlightLogManager(QObject *parent) :
updateFlightEntries(m_flightLogStatus->getFlight());
setupUAVOWrappers();
setupLogSettings();
setupLogStatuses();
setupUAVOWrappers();
connect(m_telemtryManager, SIGNAL(connected()), this, SLOT(connectionStatusChanged()));
connect(m_telemtryManager, SIGNAL(disconnected()), this, SLOT(connectionStatusChanged()));
}
FlightLogManager::~FlightLogManager()
@ -478,10 +478,11 @@ void FlightLogManager::saveSettings()
}
}
void FlightLogManager::resetSettings()
void FlightLogManager::resetSettings(bool clear)
{
setLoggingEnabled(clear ? 0 : m_flightLogSettings->getLoggingEnabled());
foreach(UAVOLogSettingsWrapper * wrapper, m_uavoEntries) {
wrapper->setSetting(UAVOLogSettingsWrapper::DISABLED);
wrapper->reset(clear);
}
}
@ -514,7 +515,7 @@ void FlightLogManager::setupUAVOWrappers()
UAVObject *object = objectList.at(0);
if (!object->isMetaDataObject() && !object->isSettingsObject()) {
UAVOLogSettingsWrapper *wrapper = new UAVOLogSettingsWrapper(object);
UAVOLogSettingsWrapper *wrapper = new UAVOLogSettingsWrapper(qobject_cast<UAVDataObject*>(object));
m_uavoEntries.append(wrapper);
m_uavoEntriesHash[wrapper->name()] = wrapper;
qDebug() << objectList.at(0)->getName();
@ -525,7 +526,15 @@ void FlightLogManager::setupUAVOWrappers()
void FlightLogManager::setupLogSettings()
{
m_logSettings << tr("Disabled") << tr("When updated") << tr("Throttled") << tr("Periodically");
// Corresponds to:
// typedef enum {
// UPDATEMODE_MANUAL = 0, /** Manually update object, by calling the updated() function */
// UPDATEMODE_PERIODIC = 1, /** Automatically update object at periodic intervals */
// UPDATEMODE_ONCHANGE = 2, /** Only update object when its data changes */
// UPDATEMODE_THROTTLED = 3 /** Object is updated on change, but not more often than the interval time */
// } UpdateMode;
m_logSettings << tr("Disabled") << tr("Periodically") << tr("When updated") << tr("Throttled");
}
void FlightLogManager::setupLogStatuses()
@ -542,6 +551,9 @@ void FlightLogManager::connectionStatusChanged()
} else {
setBoardConnected(false);
}
if(boardConnected()) {
resetSettings(false);
}
}
bool FlightLogManager::updateLogWrapper(QString name, int level, int period)
@ -623,9 +635,18 @@ void ExtendedDebugLogEntry::setData(const DebugLogEntry::DataFields &data, UAVOb
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper() : QObject()
{}
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper(UAVObject *object) : QObject(),
m_object(object), m_setting(DISABLED), m_period(0)
{}
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper(UAVDataObject *object) : QObject(),
m_object(object), m_setting(DISABLED), m_period(0), m_dirty(0)
{
reset(false);
}
UAVOLogSettingsWrapper::~UAVOLogSettingsWrapper()
{}
void UAVOLogSettingsWrapper::reset(bool clear)
{
setSetting(clear ? 0 : m_object->GetLoggingUpdateMode(m_object->getMetadata()));
setPeriod(clear ? 0 : m_object->getMetadata().loggingUpdatePeriod);
setDirty(false);
}

View File

@ -45,16 +45,17 @@
class UAVOLogSettingsWrapper : public QObject {
Q_OBJECT
Q_PROPERTY(UAVObject *object READ object NOTIFY objectChanged)
Q_PROPERTY(UAVDataObject *object READ object NOTIFY objectChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(int setting READ setting WRITE setSetting NOTIFY settingChanged)
Q_PROPERTY(int period READ period WRITE setPeriod NOTIFY periodChanged)
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
public:
enum UAVLogSetting { DISABLED = 0, ON_CHANGE, THROTTLED, PERIODICALLY };
explicit UAVOLogSettingsWrapper();
explicit UAVOLogSettingsWrapper(UAVObject *object);
explicit UAVOLogSettingsWrapper(UAVDataObject *object);
~UAVOLogSettingsWrapper();
QString name() const
@ -72,16 +73,22 @@ public:
return m_period;
}
UAVObject *object() const
UAVDataObject *object() const
{
return m_object;
}
bool dirty() const
{
return m_dirty;
}
public slots:
void setSetting(int setting)
{
if (m_setting != setting) {
m_setting = setting;
setDirty(true);
emit settingChanged(setting);
}
}
@ -90,20 +97,34 @@ public slots:
{
if (m_period != arg) {
m_period = arg;
setDirty(true);
emit periodChanged(arg);
}
}
void setDirty(bool arg)
{
if (m_dirty != arg) {
m_dirty = arg;
emit dirtyChanged(arg);
}
}
void reset(bool clear);
signals:
void settingChanged(int setting);
void nameChanged(QString name);
void periodChanged(int period);
void objectChanged(UAVObject * arg);
void objectChanged(UAVDataObject * arg);
void dirtyChanged(bool arg);
private:
UAVObject *m_object;
UAVDataObject *m_object;
int m_setting;
int m_period;
bool m_dirty;
};
class ExtendedDebugLogEntry : public DebugLogEntry {
@ -225,7 +246,6 @@ signals:
void boardConnectedChanged(bool arg);
void logStatusesChanged(QStringList arg);
void loggingEnabledChanged(int arg);
public slots:
@ -235,7 +255,7 @@ public slots:
void cancelExportLogs();
void loadSettings();
void saveSettings();
void resetSettings();
void resetSettings(bool clear);
void applySettingsToBoard();
void saveSettingsToBoard();

View File

@ -701,3 +701,23 @@ void UAVObject::SetGcsTelemetryUpdateMode(UAVObject::Metadata & metadata, UAVObj
{
SET_BITS(metadata.flags, UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT, val, UAVOBJ_UPDATE_MODE_MASK);
}
/**
* Get the UAVObject metadata logging update mode
* \param[in] metadata The metadata object
* \return the logging update mode
*/
UAVObject::UpdateMode UAVObject::GetLoggingUpdateMode(const UAVObject::Metadata & metadata)
{
return UAVObject::UpdateMode((metadata.flags >> UAVOBJ_LOGGING_UPDATE_MODE_SHIFT) & UAVOBJ_UPDATE_MODE_MASK);
}
/**
* Set the UAVObject metadata logging update mode member
* \param[in] metadata The metadata object
* \param[in] val The logging update mode
*/
void UAVObject::SetLoggingUpdateMode(UAVObject::Metadata & metadata, UAVObject::UpdateMode val)
{
SET_BITS(metadata.flags, UAVOBJ_LOGGING_UPDATE_MODE_SHIFT, val, UAVOBJ_UPDATE_MODE_MASK);
}

View File

@ -151,6 +151,8 @@ public:
static void SetFlightTelemetryUpdateMode(Metadata & meta, UpdateMode val);
static UpdateMode GetGcsTelemetryUpdateMode(const Metadata & meta);
static void SetGcsTelemetryUpdateMode(Metadata & meta, UpdateMode val);
static UpdateMode GetLoggingUpdateMode(const Metadata & meta);
static void SetLoggingUpdateMode(Metadata & meta, UpdateMode val);
public slots:
void requestUpdate();