2 ******************************************************************************
4 * @file flightlogmanager.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
8 * @addtogroup FlightLogManager
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "flightlogmanager.h"
29 #include "extensionsystem/pluginmanager.h"
31 #include <QApplication>
32 #include <QFileDialog>
33 #include <QXmlStreamReader>
34 #include <QMessageBox>
37 #include "debuglogcontrol.h"
38 #include "uavobjecthelper.h"
39 #include "uavtalk/uavtalk.h"
40 #include "utils/logfile.h"
41 #include "uavdataobject.h"
42 #include <uavobjectutil/uavobjectutilmanager.h>
44 FlightLogManager::FlightLogManager(QObject
*parent
) :
45 QObject(parent
), m_disableControls(false),
46 m_disableExport(true), m_cancelDownload(false),
47 m_adjustExportedTimestamps(true)
49 ExtensionSystem::PluginManager
*pluginManager
= ExtensionSystem::PluginManager::instance();
51 Q_ASSERT(pluginManager
);
53 m_objectManager
= pluginManager
->getObject
<UAVObjectManager
>();
54 Q_ASSERT(m_objectManager
);
56 m_telemtryManager
= pluginManager
->getObject
<TelemetryManager
>();
57 Q_ASSERT(m_telemtryManager
);
59 m_objectUtilManager
= pluginManager
->getObject
<UAVObjectUtilManager
>();
60 Q_ASSERT(m_objectUtilManager
);
62 m_flightLogControl
= DebugLogControl::GetInstance(m_objectManager
);
63 Q_ASSERT(m_flightLogControl
);
65 m_flightLogStatus
= DebugLogStatus::GetInstance(m_objectManager
);
66 Q_ASSERT(m_flightLogStatus
);
67 connect(m_flightLogStatus
, SIGNAL(FlightChanged(quint16
)), this, SLOT(updateFlightEntries(quint16
)));
69 m_flightLogEntry
= DebugLogEntry::GetInstance(m_objectManager
);
70 Q_ASSERT(m_flightLogEntry
);
72 m_flightLogSettings
= DebugLogSettings::GetInstance(m_objectManager
);
73 Q_ASSERT(m_flightLogSettings
);
75 m_objectPersistence
= ObjectPersistence::GetInstance(m_objectManager
);
76 Q_ASSERT(m_objectPersistence
);
78 updateFlightEntries(m_flightLogStatus
->getFlight());
84 connect(m_telemtryManager
, SIGNAL(connected()), this, SLOT(connectionStatusChanged()));
85 connect(m_telemtryManager
, SIGNAL(disconnected()), this, SLOT(connectionStatusChanged()));
86 connectionStatusChanged();
89 FlightLogManager::~FlightLogManager()
91 while (!m_logEntries
.isEmpty()) {
92 delete m_logEntries
.takeFirst();
94 while (!m_uavoEntries
.isEmpty()) {
95 delete m_uavoEntries
.takeFirst();
99 void addLogEntries(QQmlListProperty
<ExtendedDebugLogEntry
> *list
, ExtendedDebugLogEntry
*entry
)
105 int countLogEntries(QQmlListProperty
<ExtendedDebugLogEntry
> *list
)
107 return static_cast< QList
<ExtendedDebugLogEntry
*> *>(list
->data
)->size();
110 ExtendedDebugLogEntry
*logEntryAt(QQmlListProperty
<ExtendedDebugLogEntry
> *list
, int index
)
112 return static_cast< QList
<ExtendedDebugLogEntry
*> *>(list
->data
)->at(index
);
115 void clearLogEntries(QQmlListProperty
<ExtendedDebugLogEntry
> *list
)
117 return static_cast< QList
<ExtendedDebugLogEntry
*> *>(list
->data
)->clear();
120 QQmlListProperty
<ExtendedDebugLogEntry
> FlightLogManager::logEntries()
122 return QQmlListProperty
<ExtendedDebugLogEntry
>(this, &m_logEntries
, &addLogEntries
, &countLogEntries
, &logEntryAt
, &clearLogEntries
);
125 void addUAVOEntries(QQmlListProperty
<UAVOLogSettingsWrapper
> *list
, UAVOLogSettingsWrapper
*entry
)
131 int countUAVOEntries(QQmlListProperty
<UAVOLogSettingsWrapper
> *list
)
133 return static_cast< QList
<UAVOLogSettingsWrapper
*> *>(list
->data
)->size();
136 UAVOLogSettingsWrapper
*uavoEntryAt(QQmlListProperty
<UAVOLogSettingsWrapper
> *list
, int index
)
138 return static_cast< QList
<UAVOLogSettingsWrapper
*> *>(list
->data
)->at(index
);
141 void clearUAVOEntries(QQmlListProperty
<UAVOLogSettingsWrapper
> *list
)
143 return static_cast< QList
<UAVOLogSettingsWrapper
*> *>(list
->data
)->clear();
146 QQmlListProperty
<UAVOLogSettingsWrapper
> FlightLogManager::uavoEntries()
148 return QQmlListProperty
<UAVOLogSettingsWrapper
>(this, &m_uavoEntries
, &addUAVOEntries
, &countUAVOEntries
, &uavoEntryAt
, &clearUAVOEntries
);
151 QStringList
FlightLogManager::flightEntries()
153 return m_flightEntries
;
156 void FlightLogManager::clearAllLogs()
158 setDisableControls(true);
159 QApplication::setOverrideCursor(Qt::WaitCursor
);
161 // Clear on flight side
162 UAVObjectUpdaterHelper updateHelper
;
164 m_flightLogControl
->setFlight(0);
165 m_flightLogControl
->setEntry(0);
166 m_flightLogControl
->setOperation(DebugLogControl::OPERATION_FORMATFLASH
);
167 if (updateHelper
.doObjectAndWait(m_flightLogControl
, UAVTALK_TIMEOUT
) == UAVObjectUpdaterHelper::SUCCESS
) {
168 // Then empty locally
172 QApplication::restoreOverrideCursor();
173 setDisableControls(false);
176 void FlightLogManager::clearLogList()
178 QList
<ExtendedDebugLogEntry
*> tmpList(m_logEntries
);
179 m_logEntries
.clear();
181 emit
logEntriesChanged();
182 setDisableExport(true);
184 while (!tmpList
.isEmpty()) {
185 delete tmpList
.takeFirst();
189 void FlightLogManager::retrieveLogs(int flightToRetrieve
)
191 setDisableControls(true);
192 QApplication::setOverrideCursor(Qt::WaitCursor
);
193 m_cancelDownload
= false;
194 UAVObjectUpdaterHelper updateHelper
;
195 UAVObjectRequestHelper requestHelper
;
199 // Set up what to retrieve
200 int startFlight
= (flightToRetrieve
== -1) ? 0 : flightToRetrieve
;
201 int endFlight
= (flightToRetrieve
== -1) ? m_flightLogStatus
->getFlight() : flightToRetrieve
;
203 // Prepare to send request for event retrieval
204 m_flightLogControl
->setOperation(DebugLogControl::OPERATION_RETRIEVE
);
205 for (int flight
= startFlight
; flight
<= endFlight
; flight
++) {
206 m_flightLogControl
->setFlight(flight
);
207 bool gotLast
= false;
210 // Send request for loading flight entry on flight side and wait for ack/nack
211 m_flightLogControl
->setEntry(slot
);
213 if (updateHelper
.doObjectAndWait(m_flightLogControl
, UAVTALK_TIMEOUT
) == UAVObjectUpdaterHelper::SUCCESS
&&
214 requestHelper
.doObjectAndWait(m_flightLogEntry
, UAVTALK_TIMEOUT
) == UAVObjectUpdaterHelper::SUCCESS
) {
215 if (m_flightLogEntry
->getType() != DebugLogEntry::TYPE_EMPTY
) {
216 // Ok, we retrieved the entry, and it was the correct one. clone it and add it to the list
217 ExtendedDebugLogEntry
*logEntry
= new ExtendedDebugLogEntry();
219 logEntry
->setData(m_flightLogEntry
->getData(), m_objectManager
);
220 m_logEntries
<< logEntry
;
221 if (logEntry
->getData().Type
== DebugLogEntry::TYPE_MULTIPLEUAVOBJECTS
) {
222 const quint32 total_len
= sizeof(DebugLogEntry::DataFields
);
223 const quint32 data_len
= sizeof(((DebugLogEntry::DataFields
*)0)->Data
);
224 const quint32 header_len
= total_len
- data_len
;
226 DebugLogEntry::DataFields fields
;
227 quint32 start
= logEntry
->getData().Size
;
229 // cycle until there is space for another object
230 while (start
+ header_len
+ 1 < data_len
) {
231 memset(&fields
, 0xFF, total_len
);
232 memcpy(&fields
, &logEntry
->getData().Data
[start
], header_len
);
233 // check wether a packed object is found
234 // note that empty data blocks are set as 0xFF in flight side to minimize flash wearing
235 // thus as soon as this read outside of used area, the test will fail as lenght would be 0xFFFF
236 quint32 toread
= header_len
+ fields
.Size
;
237 if (!(toread
+ start
> data_len
)) {
238 memcpy(&fields
, &logEntry
->getData().Data
[start
], toread
);
239 ExtendedDebugLogEntry
*subEntry
= new ExtendedDebugLogEntry();
240 subEntry
->setData(fields
, m_objectManager
);
241 m_logEntries
<< subEntry
;
247 // Increment to get next entry from flight side
250 // We are done, not more entries on this flight
254 // We failed for some reason
257 if (m_cancelDownload
) {
261 if (m_cancelDownload
) {
266 if (m_cancelDownload
) {
268 m_cancelDownload
= false;
271 emit
logEntriesChanged();
272 setDisableExport(m_logEntries
.count() == 0);
274 QApplication::restoreOverrideCursor();
275 setDisableControls(false);
278 void FlightLogManager::exportToOPL(QString fileName
)
281 fileName
.replace(QString(".opl"), QString("%1.opl"));
283 // Loop and create a new file for each flight.
284 int currentEntry
= 0;
285 int currentFlight
= 0;
286 quint32 adjustedBaseTime
= 0;
287 // Continue until all entries are exported
288 while (currentEntry
< m_logEntries
.count()) {
289 if (m_adjustExportedTimestamps
) {
290 adjustedBaseTime
= m_logEntries
[currentEntry
]->getFlightTime();
293 // Get current flight
294 currentFlight
= m_logEntries
[currentEntry
]->getFlight();
297 logFile
.useProvidedTimeStamp(true);
299 // Set the file name to contain flight number
300 logFile
.setFileName(fileName
.arg(tr("_flight-%1").arg(currentFlight
+ 1)));
301 logFile
.open(QIODevice::WriteOnly
);
302 UAVTalk
uavTalk(&logFile
, m_objectManager
);
304 // Export entries until no more available or flight changes
305 while (currentEntry
< m_logEntries
.count() && m_logEntries
[currentEntry
]->getFlight() == currentFlight
) {
306 ExtendedDebugLogEntry
*entry
= m_logEntries
[currentEntry
];
308 // Only log uavobjects
309 if (entry
->getType() == ExtendedDebugLogEntry::TYPE_UAVOBJECT
|| entry
->getType() == ExtendedDebugLogEntry::TYPE_MULTIPLEUAVOBJECTS
) {
310 // Set timestamp that should be logged for this entry
311 logFile
.setNextTimeStamp(entry
->getFlightTime() - adjustedBaseTime
);
313 // Use UAVTalk to log complete message to file
314 uavTalk
.sendObject(entry
->uavObject(), false, false);
315 qDebug() << entry
->getFlightTime() - adjustedBaseTime
<< "=" << entry
->toStringBrief();
324 void FlightLogManager::exportToCSV(QString fileName
)
326 QFile
csvFile(fileName
);
328 if (csvFile
.open(QFile::WriteOnly
| QFile::Truncate
)) {
329 QTextStream
csvStream(&csvFile
);
330 quint32 baseTime
= 0;
331 quint32 currentFlight
= 0;
332 csvStream
<< "Flight" << '\t' << "Flight Time" << '\t' << "Entry" << '\t' << "Data" << '\n';
333 foreach(ExtendedDebugLogEntry
* entry
, m_logEntries
) {
334 if (m_adjustExportedTimestamps
&& entry
->getFlight() != currentFlight
) {
335 currentFlight
= entry
->getFlight();
336 baseTime
= entry
->getFlightTime();
338 entry
->toCSV(&csvStream
, baseTime
);
346 void FlightLogManager::exportToXML(QString fileName
)
348 QFile
xmlFile(fileName
);
350 if (xmlFile
.open(QFile::WriteOnly
| QFile::Truncate
)) {
351 QXmlStreamWriter
xmlWriter(&xmlFile
);
352 xmlWriter
.setAutoFormatting(true);
353 xmlWriter
.setAutoFormattingIndent(4);
355 xmlWriter
.writeStartDocument("1.0", true);
356 xmlWriter
.writeStartElement("logs");
357 xmlWriter
.writeComment("This file was created by the flight log export in OpenPilot GCS.");
359 quint32 baseTime
= 0;
360 quint32 currentFlight
= 0;
361 foreach(ExtendedDebugLogEntry
* entry
, m_logEntries
) {
362 if (m_adjustExportedTimestamps
&& entry
->getFlight() != currentFlight
) {
363 currentFlight
= entry
->getFlight();
364 baseTime
= entry
->getFlightTime();
366 entry
->toXML(&xmlWriter
, baseTime
);
368 xmlWriter
.writeEndElement();
369 xmlWriter
.writeEndDocument();
375 void FlightLogManager::exportLogs()
377 if (m_logEntries
.isEmpty()) {
381 setDisableControls(true);
382 QApplication::setOverrideCursor(Qt::WaitCursor
);
384 QString oplFilter
= tr("OpenPilot Log file %1").arg("(*.opl)");
385 QString csvFilter
= tr("Text file %1").arg("(*.csv)");
386 QString xmlFilter
= tr("XML file %1").arg("(*.xml)");
388 QString selectedFilter
= csvFilter
;
390 QString fileName
= QFileDialog::getSaveFileName(NULL
, tr("Save Log Entries"), QDir::homePath(),
391 QString("%1;;%2;;%3").arg(oplFilter
, csvFilter
, xmlFilter
), &selectedFilter
);
392 if (!fileName
.isEmpty()) {
393 if (selectedFilter
== oplFilter
) {
394 if (!fileName
.endsWith(".opl")) {
395 fileName
.append(".opl");
397 exportToOPL(fileName
);
398 } else if (selectedFilter
== csvFilter
) {
399 if (!fileName
.endsWith(".csv")) {
400 fileName
.append(".csv");
402 exportToCSV(fileName
);
403 } else if (selectedFilter
== xmlFilter
) {
404 if (!fileName
.endsWith(".xml")) {
405 fileName
.append(".xml");
407 exportToXML(fileName
);
411 QApplication::restoreOverrideCursor();
412 setDisableControls(false);
415 void FlightLogManager::cancelExportLogs()
417 m_cancelDownload
= true;
420 void FlightLogManager::loadSettings()
422 QString xmlFilter
= tr("XML file %1").arg("(*.xml)");
423 QString fileName
= QFileDialog::getOpenFileName(NULL
, tr("Load Log Settings"), QDir::homePath(), QString("%1").arg(xmlFilter
));
425 if (!fileName
.isEmpty()) {
426 if (!fileName
.endsWith(".xml")) {
427 fileName
.append(".xml");
429 QFile
xmlFile(fileName
);
431 if (xmlFile
.open(QFile::ReadOnly
)) {
432 QXmlStreamReader
xmlReader(&xmlFile
);
433 while (xmlReader
.readNextStartElement() && xmlReader
.name() == "settings") {
436 int version
= xmlReader
.attributes().value("version").toInt(&ok
);
437 if (!ok
|| version
!= LOG_SETTINGS_FILE_VERSION
) {
438 errorString
= tr("The file has the wrong version or could not parse version information.");
442 setLoggingEnabled(xmlReader
.attributes().value("enabled").toInt(&ok
));
444 errorString
= tr("Could not parse enabled attribute.");
448 while (xmlReader
.readNextStartElement()) {
449 if (xmlReader
.name() == "setting") {
450 QString name
= xmlReader
.attributes().value("name").toString();
451 int level
= xmlReader
.attributes().value("level").toInt(&ok
);
453 int period
= xmlReader
.attributes().value("period").toInt(&ok
);
454 if (ok
&& updateLogWrapper(name
, level
, period
)) {} else {
455 errorString
= tr("Could not parse period attribute, or object with name '%1' could not be found.").arg(name
);
459 errorString
= tr("Could not parse level attribute on setting '%1'").arg(name
);
463 xmlReader
.skipCurrentElement();
465 xmlReader
.skipCurrentElement();
467 if (!xmlReader
.atEnd() && (xmlReader
.hasError() || !errorString
.isEmpty())) {
468 QMessageBox::warning(NULL
, tr("Settings file corrupt."),
469 tr("The file loaded is not in the correct format.\nPlease check the file.\n%1")
470 .arg(xmlReader
.hasError() ? xmlReader
.errorString() : errorString
),
478 void FlightLogManager::saveSettings()
480 QString xmlFilter
= tr("XML file %1").arg("(*.xml)");
481 QString fileName
= QFileDialog::getSaveFileName(NULL
, tr("Save Log Settings"),
482 QDir::homePath(), QString("%1").arg(xmlFilter
));
484 if (!fileName
.isEmpty()) {
485 if (!fileName
.endsWith(".xml")) {
486 fileName
.append(".xml");
488 QFile
xmlFile(fileName
);
490 if (xmlFile
.open(QFile::WriteOnly
| QFile::Truncate
)) {
491 QXmlStreamWriter
xmlWriter(&xmlFile
);
492 xmlWriter
.setAutoFormatting(true);
493 xmlWriter
.setAutoFormattingIndent(4);
495 xmlWriter
.writeStartDocument("1.0", true);
496 xmlWriter
.writeComment("This file was created by the flight log settings function in OpenPilot GCS.");
497 xmlWriter
.writeStartElement("settings");
498 xmlWriter
.writeAttribute("version", QString::number(LOG_SETTINGS_FILE_VERSION
));
499 xmlWriter
.writeAttribute("enabled", QString::number(m_loggingEnabled
));
500 foreach(UAVOLogSettingsWrapper
* wrapper
, m_uavoEntries
) {
501 xmlWriter
.writeStartElement("setting");
502 xmlWriter
.writeAttribute("name", wrapper
->name());
503 xmlWriter
.writeAttribute("level", QString::number(wrapper
->setting()));
504 xmlWriter
.writeAttribute("period", QString::number(wrapper
->period()));
505 xmlWriter
.writeEndElement();
507 xmlWriter
.writeEndElement();
508 xmlWriter
.writeEndDocument();
515 void FlightLogManager::resetSettings(bool clear
)
517 setLoggingEnabled(clear
? 0 : m_flightLogSettings
->getLoggingEnabled());
518 foreach(UAVOLogSettingsWrapper
* wrapper
, m_uavoEntries
) {
519 wrapper
->reset(clear
);
523 void FlightLogManager::saveSettingsToBoard()
525 m_flightLogSettings
->setLoggingEnabled(m_loggingEnabled
);
526 m_flightLogSettings
->updated();
527 saveUAVObjectToFlash(m_flightLogSettings
);
529 foreach(UAVOLogSettingsWrapper
* wrapper
, m_uavoEntries
) {
530 if (wrapper
->dirty()) {
531 UAVObject::Metadata meta
= wrapper
->object()->getMetadata();
532 wrapper
->object()->SetLoggingUpdateMode(meta
, wrapper
->settingAsUpdateMode());
533 meta
.loggingUpdatePeriod
= wrapper
->period();
535 // As metadata are set up to update via telemetry on change
536 // this call will send the update to the board.
537 wrapper
->object()->setMetadata(meta
);
539 if (saveUAVObjectToFlash(wrapper
->object()->getMetaObject())) {
540 wrapper
->setDirty(false);
546 bool FlightLogManager::saveUAVObjectToFlash(UAVObject
*object
)
548 m_objectUtilManager
->saveObjectToSD(object
);
552 void FlightLogManager::updateFlightEntries(quint16 currentFlight
)
554 Q_UNUSED(currentFlight
);
556 int flights
= m_flightLogStatus
->getFlight();
557 if (m_flightEntries
.count() == 0 || (m_flightEntries
.count() - 1 != flights
)) {
558 m_flightEntries
.clear();
560 m_flightEntries
<< tr("All");
561 for (int i
= 0; i
<= flights
; i
++) {
562 m_flightEntries
<< QString::number(i
+ 1);
565 emit
flightEntriesChanged();
569 void FlightLogManager::setupUAVOWrappers()
571 foreach(QList
<UAVObject
*> objectList
, m_objectManager
->getObjects()) {
572 UAVObject
*object
= objectList
.at(0);
574 if (!object
->isMetaDataObject() && !object
->isSettingsObject()) {
575 UAVOLogSettingsWrapper
*wrapper
= new UAVOLogSettingsWrapper(qobject_cast
<UAVDataObject
*>(object
));
576 m_uavoEntries
.append(wrapper
);
577 m_uavoEntriesHash
[wrapper
->name()] = wrapper
;
580 emit
uavoEntriesChanged();
583 void FlightLogManager::setupLogSettings()
587 // UPDATEMODE_MANUAL = 0, /** Manually update object, by calling the updated() function */
588 // UPDATEMODE_PERIODIC = 1, /** Automatically update object at periodic intervals */
589 // UPDATEMODE_ONCHANGE = 2, /** Only update object when its data changes */
590 // UPDATEMODE_THROTTLED = 3 /** Object is updated on change, but not more often than the interval time */
593 m_logSettings
<< tr("Disabled") << tr("Periodically") << tr("When updated") << tr("Throttled");
596 void FlightLogManager::setupLogStatuses()
598 m_logStatuses
<< tr("Never") << tr("Only when Armed") << tr("Always");
601 void FlightLogManager::connectionStatusChanged()
603 if (m_telemtryManager
->isConnected()) {
604 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
605 UAVObjectUtilManager
*utilMngr
= pm
->getObject
<UAVObjectUtilManager
>();
606 setBoardConnected(utilMngr
->getBoardModel() == 0x0903);
608 setBoardConnected(false);
610 if (boardConnected()) {
611 resetSettings(false);
615 bool FlightLogManager::updateLogWrapper(QString name
, int level
, int period
)
617 UAVOLogSettingsWrapper
*wrapper
= m_uavoEntriesHash
[name
];
620 wrapper
->setSetting(level
);
621 wrapper
->setPeriod(period
);
622 qDebug() << "Wrapper" << name
<< ", level" << level
<< ", period" << period
;
628 ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry(),
632 ExtendedDebugLogEntry::~ExtendedDebugLogEntry()
640 QString
ExtendedDebugLogEntry::getLogString()
642 if (getType() == DebugLogEntry::TYPE_TEXT
) {
643 return QString((const char *)getData().Data
);
644 } else if (getType() == DebugLogEntry::TYPE_UAVOBJECT
|| getType() == DebugLogEntry::TYPE_MULTIPLEUAVOBJECTS
) {
645 return m_object
->toString().replace("\n", " ").replace("\t", " ");
651 void ExtendedDebugLogEntry::toXML(QXmlStreamWriter
*xmlWriter
, quint32 baseTime
)
653 xmlWriter
->writeStartElement("entry");
654 xmlWriter
->writeAttribute("flight", QString::number(getFlight() + 1));
655 xmlWriter
->writeAttribute("flighttime", QString::number(getFlightTime() - baseTime
));
656 xmlWriter
->writeAttribute("entry", QString::number(getEntry()));
657 if (getType() == DebugLogEntry::TYPE_TEXT
) {
658 xmlWriter
->writeAttribute("type", "text");
659 xmlWriter
->writeTextElement("message", QString((const char *)getData().Data
));
660 } else if (getType() == DebugLogEntry::TYPE_UAVOBJECT
|| getType() == DebugLogEntry::TYPE_MULTIPLEUAVOBJECTS
) {
661 xmlWriter
->writeAttribute("type", "uavobject");
662 m_object
->toXML(xmlWriter
);
664 xmlWriter
->writeEndElement(); // entry
667 void ExtendedDebugLogEntry::toCSV(QTextStream
*csvStream
, quint32 baseTime
)
671 if (getType() == DebugLogEntry::TYPE_TEXT
) {
672 data
= QString((const char *)getData().Data
);
673 } else if (getType() == DebugLogEntry::TYPE_UAVOBJECT
|| getType() == DebugLogEntry::TYPE_MULTIPLEUAVOBJECTS
) {
674 data
= m_object
->toString().replace("\n", "").replace("\t", "");
676 *csvStream
<< QString::number(getFlight() + 1) << '\t' << QString::number(getFlightTime() - baseTime
) << '\t' << QString::number(getEntry()) << '\t' << data
<< '\n';
679 void ExtendedDebugLogEntry::setData(const DebugLogEntry::DataFields
&data
, UAVObjectManager
*objectManager
)
681 DebugLogEntry::setData(data
);
683 if (getType() == DebugLogEntry::TYPE_UAVOBJECT
|| getType() == DebugLogEntry::TYPE_MULTIPLEUAVOBJECTS
) {
684 UAVDataObject
*object
= (UAVDataObject
*)objectManager
->getObject(getObjectID(), getInstanceID());
686 m_object
= object
->clone(getInstanceID());
687 m_object
->unpack(getData().Data
);
692 UAVOLogSettingsWrapper::UAVOLogSettingsWrapper() : QObject()
695 UAVOLogSettingsWrapper::UAVOLogSettingsWrapper(UAVDataObject
*object
) : QObject(),
696 m_object(object
), m_setting(DISABLED
), m_period(0), m_dirty(0)
701 UAVOLogSettingsWrapper::~UAVOLogSettingsWrapper()
704 void UAVOLogSettingsWrapper::reset(bool clear
)
706 setSetting(m_object
->GetLoggingUpdateMode(m_object
->getMetadata()));
707 setPeriod(m_object
->getMetadata().loggingUpdatePeriod
);
709 int oldSetting
= setting();
710 int oldPeriod
= period();
713 setDirty(oldSetting
!= setting() || oldPeriod
!= period());
719 UAVObject::UpdateMode
UAVOLogSettingsWrapper::settingAsUpdateMode()
723 return UAVObject::UPDATEMODE_MANUAL
;
726 return UAVObject::UPDATEMODE_PERIODIC
;
729 return UAVObject::UPDATEMODE_ONCHANGE
;
732 return UAVObject::UPDATEMODE_THROTTLED
;
735 return UAVObject::UPDATEMODE_MANUAL
;