2013-11-19 07:39:52 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file flightlogmanager.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @addtogroup [Group]
|
|
|
|
* @{
|
|
|
|
* @addtogroup FlightLogManager
|
|
|
|
* @{
|
|
|
|
* @brief [Brief]
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "flightlogmanager.h"
|
2013-11-20 12:24:34 +01:00
|
|
|
#include "extensionsystem/pluginmanager.h"
|
2013-11-19 07:39:52 +01:00
|
|
|
|
2013-11-26 16:06:12 +01:00
|
|
|
#include <QApplication>
|
2013-11-26 23:45:38 +01:00
|
|
|
#include <QFileDialog>
|
2013-11-26 16:06:12 +01:00
|
|
|
|
2013-11-20 12:24:34 +01:00
|
|
|
#include "debuglogcontrol.h"
|
2013-11-24 17:50:07 +01:00
|
|
|
#include "uavobjecthelper.h"
|
2013-11-26 23:45:38 +01:00
|
|
|
#include "uavtalk/uavtalk.h"
|
2013-11-27 16:07:34 +01:00
|
|
|
#include "utils/logfile.h"
|
2014-03-08 12:14:19 +01:00
|
|
|
#include <uavobjectutil/uavobjectutilmanager.h>
|
2013-11-20 00:07:04 +01:00
|
|
|
|
|
|
|
FlightLogManager::FlightLogManager(QObject *parent) :
|
2013-12-01 21:22:58 +01:00
|
|
|
QObject(parent), m_disableControls(false),
|
|
|
|
m_disableExport(true), m_cancelDownload(false),
|
|
|
|
m_adjustExportedTimestamps(true)
|
2013-11-26 15:42:49 +01:00
|
|
|
{
|
2014-03-08 12:14:19 +01:00
|
|
|
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
|
2014-03-09 10:41:21 +01:00
|
|
|
|
2014-03-08 12:14:19 +01:00
|
|
|
Q_ASSERT(pluginManager);
|
2013-11-26 15:42:49 +01:00
|
|
|
|
2014-03-09 10:41:21 +01:00
|
|
|
m_objectManager = pluginManager->getObject<UAVObjectManager>();
|
2013-11-20 12:24:34 +01:00
|
|
|
Q_ASSERT(m_objectManager);
|
|
|
|
|
2014-03-08 12:14:19 +01:00
|
|
|
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();
|
|
|
|
|
2013-11-24 17:50:07 +01:00
|
|
|
m_flightLogControl = DebugLogControl::GetInstance(m_objectManager);
|
|
|
|
Q_ASSERT(m_flightLogControl);
|
|
|
|
|
2013-11-26 15:42:49 +01:00
|
|
|
m_flightLogStatus = DebugLogStatus::GetInstance(m_objectManager);
|
2013-11-20 12:24:34 +01:00
|
|
|
Q_ASSERT(m_flightLogStatus);
|
2013-11-26 22:52:24 +01:00
|
|
|
connect(m_flightLogStatus, SIGNAL(FlightChanged(quint16)), this, SLOT(updateFlightEntries(quint16)));
|
2013-11-20 12:24:34 +01:00
|
|
|
|
2014-03-09 10:41:21 +01:00
|
|
|
m_flightLogEntry = DebugLogEntry::GetInstance(m_objectManager);
|
2013-11-24 17:50:07 +01:00
|
|
|
Q_ASSERT(m_flightLogEntry);
|
2013-11-26 22:52:24 +01:00
|
|
|
|
2014-03-08 13:47:41 +01:00
|
|
|
m_flightLogSettings = DebugLogSettings::GetInstance(m_objectManager);
|
|
|
|
Q_ASSERT(m_flightLogSettings);
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
updateFlightEntries(m_flightLogStatus->getFlight());
|
2014-03-06 00:41:48 +01:00
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
setupUAVOWrappers();
|
|
|
|
setupLogSettings();
|
2014-03-08 13:47:41 +01:00
|
|
|
setupLogStatuses();
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 15:42:49 +01:00
|
|
|
FlightLogManager::~FlightLogManager()
|
|
|
|
{
|
2013-11-26 15:25:27 +01:00
|
|
|
while (!m_logEntries.isEmpty()) {
|
|
|
|
delete m_logEntries.takeFirst();
|
|
|
|
}
|
2014-03-08 17:28:46 +01:00
|
|
|
while (!m_uavoEntries.isEmpty()) {
|
|
|
|
delete m_uavoEntries.takeFirst();
|
|
|
|
}
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
void addLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list, ExtendedDebugLogEntry *entry)
|
2013-11-26 15:42:49 +01:00
|
|
|
{
|
2013-11-25 14:59:23 +01:00
|
|
|
Q_UNUSED(list);
|
|
|
|
Q_UNUSED(entry);
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
int countLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
|
2013-11-26 15:42:49 +01:00
|
|
|
{
|
2013-11-25 14:59:23 +01:00
|
|
|
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->size();
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
ExtendedDebugLogEntry *logEntryAt(QQmlListProperty<ExtendedDebugLogEntry> *list, int index)
|
2013-11-26 15:42:49 +01:00
|
|
|
{
|
2013-11-25 14:59:23 +01:00
|
|
|
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->at(index);
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
void clearLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
|
2013-11-26 15:42:49 +01:00
|
|
|
{
|
2013-11-25 14:59:23 +01:00
|
|
|
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->clear();
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 15:42:49 +01:00
|
|
|
QQmlListProperty<ExtendedDebugLogEntry> FlightLogManager::logEntries()
|
|
|
|
{
|
2013-11-26 22:52:24 +01:00
|
|
|
return QQmlListProperty<ExtendedDebugLogEntry>(this, &m_logEntries, &addLogEntries, &countLogEntries, &logEntryAt, &clearLogEntries);
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
void addUAVOEntries(QQmlListProperty<UAVOLogSettingsWrapper> *list, UAVOLogSettingsWrapper *entry)
|
2014-03-06 00:41:48 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(list);
|
|
|
|
Q_UNUSED(entry);
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
int countUAVOEntries(QQmlListProperty<UAVOLogSettingsWrapper> *list)
|
2014-03-06 00:41:48 +01:00
|
|
|
{
|
2014-03-06 23:30:55 +01:00
|
|
|
return static_cast< QList<UAVOLogSettingsWrapper *> *>(list->data)->size();
|
2014-03-06 00:41:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
UAVOLogSettingsWrapper *uavoEntryAt(QQmlListProperty<UAVOLogSettingsWrapper> *list, int index)
|
2014-03-06 00:41:48 +01:00
|
|
|
{
|
2014-03-06 23:30:55 +01:00
|
|
|
return static_cast< QList<UAVOLogSettingsWrapper *> *>(list->data)->at(index);
|
2014-03-06 00:41:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
void clearUAVOEntries(QQmlListProperty<UAVOLogSettingsWrapper> *list)
|
2014-03-06 00:41:48 +01:00
|
|
|
{
|
2014-03-06 23:30:55 +01:00
|
|
|
return static_cast< QList<UAVOLogSettingsWrapper *> *>(list->data)->clear();
|
2014-03-06 00:41:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
QQmlListProperty<UAVOLogSettingsWrapper> FlightLogManager::uavoEntries()
|
2014-03-06 00:41:48 +01:00
|
|
|
{
|
2014-03-06 23:30:55 +01:00
|
|
|
return QQmlListProperty<UAVOLogSettingsWrapper>(this, &m_uavoEntries, &addUAVOEntries, &countUAVOEntries, &uavoEntryAt, &clearUAVOEntries);
|
2014-03-06 00:41:48 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
QStringList FlightLogManager::flightEntries()
|
|
|
|
{
|
|
|
|
return m_flightEntries;
|
2013-11-20 16:24:57 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 15:42:49 +01:00
|
|
|
void FlightLogManager::clearAllLogs()
|
|
|
|
{
|
2013-11-26 17:00:01 +01:00
|
|
|
setDisableControls(true);
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
2013-11-26 15:42:49 +01:00
|
|
|
// Clear on flight side
|
2013-11-26 16:22:44 +01:00
|
|
|
UAVObjectUpdaterHelper updateHelper;
|
|
|
|
|
|
|
|
m_flightLogControl->setFlight(0);
|
|
|
|
m_flightLogControl->setEntry(0);
|
|
|
|
m_flightLogControl->setOperation(DebugLogControl::OPERATION_FORMATFLASH);
|
|
|
|
if (updateHelper.doObjectAndWait(m_flightLogControl, UAVTALK_TIMEOUT) == UAVObjectUpdaterHelper::SUCCESS) {
|
2013-11-26 22:52:24 +01:00
|
|
|
// Then empty locally
|
|
|
|
clearLogList();
|
2013-11-26 15:25:27 +01:00
|
|
|
}
|
2013-11-26 17:00:01 +01:00
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
setDisableControls(false);
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
void FlightLogManager::clearLogList()
|
|
|
|
{
|
2013-12-07 23:28:25 +01:00
|
|
|
QList<ExtendedDebugLogEntry *> tmpList(m_logEntries);
|
2013-11-26 22:52:24 +01:00
|
|
|
m_logEntries.clear();
|
|
|
|
|
|
|
|
emit logEntriesChanged();
|
2013-11-30 13:02:52 +01:00
|
|
|
setDisableExport(true);
|
2013-11-26 22:52:24 +01:00
|
|
|
|
|
|
|
while (!tmpList.isEmpty()) {
|
|
|
|
delete tmpList.takeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 15:42:49 +01:00
|
|
|
void FlightLogManager::retrieveLogs(int flightToRetrieve)
|
|
|
|
{
|
2013-11-26 17:00:01 +01:00
|
|
|
setDisableControls(true);
|
2013-11-26 16:06:12 +01:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2013-11-30 13:02:52 +01:00
|
|
|
m_cancelDownload = false;
|
2013-11-24 17:50:07 +01:00
|
|
|
UAVObjectUpdaterHelper updateHelper;
|
|
|
|
UAVObjectRequestHelper requestHelper;
|
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
clearLogList();
|
2013-11-24 17:50:07 +01:00
|
|
|
|
|
|
|
// Set up what to retrieve
|
|
|
|
int startFlight = (flightToRetrieve == -1) ? 0 : flightToRetrieve;
|
2013-11-26 15:42:49 +01:00
|
|
|
int endFlight = (flightToRetrieve == -1) ? m_flightLogStatus->getFlight() : flightToRetrieve;
|
2013-11-24 17:50:07 +01:00
|
|
|
|
|
|
|
// Prepare to send request for event retrieval
|
|
|
|
m_flightLogControl->setOperation(DebugLogControl::OPERATION_RETRIEVE);
|
2013-11-26 15:42:49 +01:00
|
|
|
for (int flight = startFlight; flight <= endFlight; flight++) {
|
2013-11-24 17:50:07 +01:00
|
|
|
m_flightLogControl->setFlight(flight);
|
|
|
|
bool gotLast = false;
|
2013-11-26 15:42:49 +01:00
|
|
|
int entry = 0;
|
|
|
|
while (!gotLast) {
|
2013-11-24 17:50:07 +01:00
|
|
|
// Send request for loading flight entry on flight side and wait for ack/nack
|
|
|
|
m_flightLogControl->setEntry(entry);
|
|
|
|
|
2013-11-26 16:06:12 +01:00
|
|
|
if (updateHelper.doObjectAndWait(m_flightLogControl, UAVTALK_TIMEOUT) == UAVObjectUpdaterHelper::SUCCESS &&
|
|
|
|
requestHelper.doObjectAndWait(m_flightLogEntry, UAVTALK_TIMEOUT) == UAVObjectUpdaterHelper::SUCCESS) {
|
|
|
|
if (m_flightLogEntry->getType() != DebugLogEntry::TYPE_EMPTY) {
|
|
|
|
// Ok, we retrieved the entry, and it was the correct one. clone it and add it to the list
|
|
|
|
ExtendedDebugLogEntry *logEntry = new ExtendedDebugLogEntry();
|
2013-11-27 16:07:34 +01:00
|
|
|
logEntry->setData(m_flightLogEntry->getData(), m_objectManager);
|
2013-11-26 16:06:12 +01:00
|
|
|
m_logEntries << logEntry;
|
|
|
|
|
|
|
|
// Increment to get next entry from flight side
|
|
|
|
entry++;
|
2013-11-24 17:50:07 +01:00
|
|
|
} else {
|
2013-11-26 16:06:12 +01:00
|
|
|
// We are done, not more entries on this flight
|
|
|
|
gotLast = true;
|
2013-11-24 17:50:07 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-11-26 16:06:12 +01:00
|
|
|
// We failed for some reason
|
2013-11-24 17:50:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-11-30 13:02:52 +01:00
|
|
|
if (m_cancelDownload) {
|
|
|
|
break;
|
|
|
|
}
|
2013-11-24 17:50:07 +01:00
|
|
|
}
|
2013-11-30 13:02:52 +01:00
|
|
|
if (m_cancelDownload) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_cancelDownload) {
|
|
|
|
clearLogList();
|
|
|
|
m_cancelDownload = false;
|
2013-11-24 17:50:07 +01:00
|
|
|
}
|
2013-11-30 13:02:52 +01:00
|
|
|
|
2013-11-25 14:59:23 +01:00
|
|
|
emit logEntriesChanged();
|
2013-11-30 13:02:52 +01:00
|
|
|
setDisableExport(m_logEntries.count() == 0);
|
|
|
|
|
2013-11-26 16:06:12 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
2013-11-26 17:00:01 +01:00
|
|
|
setDisableControls(false);
|
2013-11-20 00:07:04 +01:00
|
|
|
}
|
2013-11-20 21:08:26 +01:00
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
void FlightLogManager::exportToOPL(QString fileName)
|
|
|
|
{
|
|
|
|
// Fix the file name
|
|
|
|
fileName.replace(QString(".opl"), QString("%1.opl"));
|
|
|
|
|
|
|
|
// Loop and create a new file for each flight.
|
|
|
|
int currentEntry = 0;
|
|
|
|
int currentFlight = 0;
|
|
|
|
quint32 adjustedBaseTime = 0;
|
|
|
|
// Continue until all entries are exported
|
|
|
|
while (currentEntry < m_logEntries.count()) {
|
|
|
|
if (m_adjustExportedTimestamps) {
|
|
|
|
adjustedBaseTime = m_logEntries[currentEntry]->getFlightTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get current flight
|
|
|
|
currentFlight = m_logEntries[currentEntry]->getFlight();
|
|
|
|
|
|
|
|
LogFile logFile;
|
|
|
|
logFile.useProvidedTimeStamp(true);
|
|
|
|
|
|
|
|
// Set the file name to contain flight number
|
|
|
|
logFile.setFileName(fileName.arg(tr("_flight-%1").arg(currentFlight + 1)));
|
|
|
|
logFile.open(QIODevice::WriteOnly);
|
|
|
|
UAVTalk uavTalk(&logFile, m_objectManager);
|
|
|
|
|
|
|
|
// Export entries until no more available or flight changes
|
|
|
|
while (currentEntry < m_logEntries.count() && m_logEntries[currentEntry]->getFlight() == currentFlight) {
|
|
|
|
ExtendedDebugLogEntry *entry = m_logEntries[currentEntry];
|
|
|
|
|
|
|
|
// Only log uavobjects
|
|
|
|
if (entry->getType() == ExtendedDebugLogEntry::TYPE_UAVOBJECT) {
|
|
|
|
// Set timestamp that should be logged for this entry
|
|
|
|
logFile.setNextTimeStamp(entry->getFlightTime() - adjustedBaseTime);
|
|
|
|
|
|
|
|
// Use UAVTalk to log complete message to file
|
|
|
|
uavTalk.sendObject(entry->uavObject(), false, false);
|
|
|
|
qDebug() << entry->getFlightTime() - adjustedBaseTime << "=" << entry->toStringBrief();
|
|
|
|
}
|
|
|
|
currentEntry++;
|
|
|
|
}
|
|
|
|
|
|
|
|
logFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlightLogManager::exportToCSV(QString fileName)
|
|
|
|
{
|
|
|
|
QFile csvFile(fileName);
|
2014-03-09 10:41:21 +01:00
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
if (csvFile.open(QFile::WriteOnly | QFile::Truncate)) {
|
|
|
|
QTextStream csvStream(&csvFile);
|
|
|
|
quint32 baseTime = 0;
|
|
|
|
quint32 currentFlight = 0;
|
|
|
|
csvStream << "Flight" << '\t' << "Flight Time" << '\t' << "Entry" << '\t' << "Data" << '\n';
|
2014-03-09 10:41:21 +01:00
|
|
|
foreach(ExtendedDebugLogEntry * entry, m_logEntries) {
|
|
|
|
if (m_adjustExportedTimestamps && entry->getFlight() != currentFlight) {
|
2014-03-08 10:50:32 +01:00
|
|
|
currentFlight = entry->getFlight();
|
|
|
|
baseTime = entry->getFlightTime();
|
|
|
|
}
|
|
|
|
entry->toCSV(&csvStream, baseTime);
|
|
|
|
}
|
|
|
|
csvStream.flush();
|
|
|
|
csvFile.flush();
|
|
|
|
csvFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlightLogManager::exportToXML(QString fileName)
|
|
|
|
{
|
|
|
|
QFile xmlFile(fileName);
|
|
|
|
|
2014-03-09 10:41:21 +01:00
|
|
|
if (xmlFile.open(QFile::WriteOnly | QFile::Truncate)) {
|
2014-03-08 10:50:32 +01:00
|
|
|
QXmlStreamWriter xmlWriter(&xmlFile);
|
|
|
|
xmlWriter.setAutoFormatting(true);
|
|
|
|
xmlWriter.setAutoFormattingIndent(4);
|
|
|
|
|
|
|
|
xmlWriter.writeStartDocument("1.0", true);
|
|
|
|
xmlWriter.writeStartElement("logs");
|
|
|
|
xmlWriter.writeComment("This file was created by the flight log export in OpenPilot GCS.");
|
|
|
|
|
|
|
|
quint32 baseTime = 0;
|
|
|
|
quint32 currentFlight = 0;
|
2014-03-09 10:41:21 +01:00
|
|
|
foreach(ExtendedDebugLogEntry * entry, m_logEntries) {
|
|
|
|
if (m_adjustExportedTimestamps && entry->getFlight() != currentFlight) {
|
2014-03-08 10:50:32 +01:00
|
|
|
currentFlight = entry->getFlight();
|
|
|
|
baseTime = entry->getFlightTime();
|
|
|
|
}
|
|
|
|
entry->toXML(&xmlWriter, baseTime);
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
xmlWriter.writeEndDocument();
|
|
|
|
xmlFile.flush();
|
|
|
|
xmlFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 21:08:26 +01:00
|
|
|
void FlightLogManager::exportLogs()
|
2013-11-26 23:45:38 +01:00
|
|
|
{
|
2013-12-07 23:28:25 +01:00
|
|
|
if (m_logEntries.isEmpty()) {
|
2013-11-30 11:44:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-26 23:45:38 +01:00
|
|
|
setDisableControls(true);
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
QString oplFilter = tr("OpenPilot Log file %1").arg("(*.opl)");
|
|
|
|
QString csvFilter = tr("Text file %1").arg("(*.csv)");
|
|
|
|
QString xmlFilter = tr("XML file %1").arg("(*.xml)");
|
2013-11-30 11:44:55 +01:00
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
QString selectedFilter = csvFilter;
|
2013-11-30 11:44:55 +01:00
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save Log Entries"),
|
|
|
|
QString("OP-%1").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")),
|
|
|
|
QString("%1;;%2;;%3").arg(oplFilter, csvFilter, xmlFilter), &selectedFilter);
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
if (selectedFilter == oplFilter) {
|
|
|
|
if (!fileName.endsWith(".opl")) {
|
|
|
|
fileName.append(".opl");
|
2013-11-27 16:07:34 +01:00
|
|
|
}
|
2014-03-08 10:50:32 +01:00
|
|
|
exportToOPL(fileName);
|
|
|
|
} else if (selectedFilter == csvFilter) {
|
|
|
|
if (!fileName.endsWith(".csv")) {
|
|
|
|
fileName.append(".csv");
|
|
|
|
}
|
|
|
|
exportToCSV(fileName);
|
|
|
|
} else if (selectedFilter == xmlFilter) {
|
|
|
|
if (!fileName.endsWith(".xml")) {
|
|
|
|
fileName.append(".xml");
|
|
|
|
}
|
|
|
|
exportToXML(fileName);
|
2013-11-27 16:07:34 +01:00
|
|
|
}
|
2013-11-26 23:45:38 +01:00
|
|
|
}
|
2013-11-27 16:07:34 +01:00
|
|
|
|
2013-11-26 23:45:38 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
setDisableControls(false);
|
|
|
|
}
|
2013-11-25 17:58:29 +01:00
|
|
|
|
2013-11-30 13:02:52 +01:00
|
|
|
void FlightLogManager::cancelExportLogs()
|
|
|
|
{
|
|
|
|
m_cancelDownload = true;
|
|
|
|
}
|
|
|
|
|
2014-03-08 17:28:46 +01:00
|
|
|
void FlightLogManager::loadSettings()
|
2014-03-09 10:41:21 +01:00
|
|
|
{}
|
2014-03-08 17:28:46 +01:00
|
|
|
|
|
|
|
void FlightLogManager::saveSettings()
|
2014-03-09 13:15:17 +01:00
|
|
|
{
|
|
|
|
QString xmlFilter = tr("XML file %1").arg("(*.xml)");
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save Log Settings"),
|
|
|
|
QString("OP-FlightLogSettings"), QString("%1").arg(xmlFilter));
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
if (!fileName.endsWith(".xml")) {
|
|
|
|
fileName.append(".xml");
|
|
|
|
}
|
|
|
|
QFile xmlFile(fileName);
|
|
|
|
|
|
|
|
if (xmlFile.open(QFile::WriteOnly | QFile::Truncate)) {
|
|
|
|
QXmlStreamWriter xmlWriter(&xmlFile);
|
|
|
|
xmlWriter.setAutoFormatting(true);
|
|
|
|
xmlWriter.setAutoFormattingIndent(4);
|
|
|
|
|
|
|
|
xmlWriter.writeStartDocument("1.0", true);
|
|
|
|
xmlWriter.writeComment("This file was created by the flight log settings function in OpenPilot GCS.");
|
|
|
|
xmlWriter.writeStartElement("settings");
|
|
|
|
xmlWriter.writeAttribute("enabled", QString::number(m_loggingEnabled));
|
|
|
|
foreach(UAVOLogSettingsWrapper * wrapper, m_uavoEntries) {
|
|
|
|
xmlWriter.writeStartElement("setting");
|
|
|
|
xmlWriter.writeAttribute("name", wrapper->name());
|
|
|
|
xmlWriter.writeAttribute("level", QString::number(wrapper->setting()));
|
|
|
|
xmlWriter.writeAttribute("period", QString::number(wrapper->period()));
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
xmlWriter.writeEndDocument();
|
|
|
|
xmlFile.flush();
|
|
|
|
xmlFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 17:28:46 +01:00
|
|
|
|
|
|
|
void FlightLogManager::resetSettings()
|
|
|
|
{
|
2014-03-09 10:41:21 +01:00
|
|
|
foreach(UAVOLogSettingsWrapper * wrapper, m_uavoEntries) {
|
2014-03-08 17:28:46 +01:00
|
|
|
wrapper->setSetting(UAVOLogSettingsWrapper::DISABLED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlightLogManager::applySettingsToBoard()
|
2014-03-09 10:41:21 +01:00
|
|
|
{}
|
2014-03-08 17:28:46 +01:00
|
|
|
|
|
|
|
void FlightLogManager::saveSettingsToBoard()
|
2014-03-09 10:41:21 +01:00
|
|
|
{}
|
2014-03-08 17:28:46 +01:00
|
|
|
|
2013-11-26 22:52:24 +01:00
|
|
|
void FlightLogManager::updateFlightEntries(quint16 currentFlight)
|
|
|
|
{
|
|
|
|
Q_UNUSED(currentFlight);
|
|
|
|
|
|
|
|
int flights = m_flightLogStatus->getFlight();
|
|
|
|
if (m_flightEntries.count() == 0 || (m_flightEntries.count() - 1 != flights)) {
|
|
|
|
m_flightEntries.clear();
|
|
|
|
|
|
|
|
m_flightEntries << tr("All");
|
2013-12-07 23:28:25 +01:00
|
|
|
for (int i = 0; i <= flights; i++) {
|
2013-11-26 22:52:24 +01:00
|
|
|
m_flightEntries << QString::number(i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit flightEntriesChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
void FlightLogManager::setupUAVOWrappers()
|
2014-03-06 00:41:48 +01:00
|
|
|
{
|
2014-03-09 10:41:21 +01:00
|
|
|
foreach(QList<UAVObject *> objectList, m_objectManager->getObjects()) {
|
|
|
|
UAVObject *object = objectList.at(0);
|
|
|
|
|
2014-03-06 00:41:48 +01:00
|
|
|
if (!object->isMetaDataObject() && !object->isSettingsObject()) {
|
2014-03-06 23:30:55 +01:00
|
|
|
m_uavoEntries.append(new UAVOLogSettingsWrapper(object));
|
2014-03-06 00:41:48 +01:00
|
|
|
qDebug() << objectList.at(0)->getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit uavoEntriesChanged();
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:30:55 +01:00
|
|
|
void FlightLogManager::setupLogSettings()
|
|
|
|
{
|
2014-03-08 17:28:46 +01:00
|
|
|
m_logSettings << tr("Disabled") << tr("When updated") << tr("Throttled") << tr("Periodically");
|
2014-03-06 23:30:55 +01:00
|
|
|
}
|
|
|
|
|
2014-03-08 13:47:41 +01:00
|
|
|
void FlightLogManager::setupLogStatuses()
|
|
|
|
{
|
|
|
|
m_logStatuses << tr("Never") << tr("Only when Armed") << tr("Always");
|
|
|
|
}
|
|
|
|
|
2014-03-08 12:14:19 +01:00
|
|
|
void FlightLogManager::connectionStatusChanged()
|
|
|
|
{
|
|
|
|
if (m_telemtryManager->isConnected()) {
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
|
|
|
setBoardConnected(utilMngr->getBoardModel() == 0x0903);
|
|
|
|
} else {
|
|
|
|
setBoardConnected(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 17:58:29 +01:00
|
|
|
ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry(),
|
2013-11-27 16:07:34 +01:00
|
|
|
m_object(0)
|
2013-11-26 15:42:49 +01:00
|
|
|
{}
|
2013-11-25 17:58:29 +01:00
|
|
|
|
|
|
|
ExtendedDebugLogEntry::~ExtendedDebugLogEntry()
|
|
|
|
{
|
2013-11-26 15:42:49 +01:00
|
|
|
if (m_object) {
|
2013-11-25 17:58:29 +01:00
|
|
|
delete m_object;
|
|
|
|
m_object = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-11-20 21:08:26 +01:00
|
|
|
|
2013-11-25 17:58:29 +01:00
|
|
|
QString ExtendedDebugLogEntry::getLogString()
|
|
|
|
{
|
2013-11-26 15:42:49 +01:00
|
|
|
if (getType() == DebugLogEntry::TYPE_TEXT) {
|
|
|
|
return QString((const char *)getData().Data);
|
2013-11-25 17:58:29 +01:00
|
|
|
} else if (getType() == DebugLogEntry::TYPE_UAVOBJECT) {
|
2013-11-27 16:07:34 +01:00
|
|
|
return m_object->toString().replace("\n", " ").replace("\t", " ");
|
2013-11-25 17:58:29 +01:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2013-11-20 21:08:26 +01:00
|
|
|
}
|
2013-11-25 14:59:23 +01:00
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
void ExtendedDebugLogEntry::toXML(QXmlStreamWriter *xmlWriter, quint32 baseTime)
|
|
|
|
{
|
|
|
|
xmlWriter->writeStartElement("entry");
|
|
|
|
xmlWriter->writeAttribute("flight", QString::number(getFlight() + 1));
|
|
|
|
xmlWriter->writeAttribute("flighttime", QString::number(getFlightTime() - baseTime));
|
|
|
|
xmlWriter->writeAttribute("entry", QString::number(getEntry()));
|
|
|
|
if (getType() == DebugLogEntry::TYPE_TEXT) {
|
|
|
|
xmlWriter->writeAttribute("type", "text");
|
|
|
|
xmlWriter->writeTextElement("message", QString((const char *)getData().Data));
|
|
|
|
} else if (getType() == DebugLogEntry::TYPE_UAVOBJECT) {
|
|
|
|
xmlWriter->writeAttribute("type", "uavobject");
|
|
|
|
m_object->toXML(xmlWriter);
|
|
|
|
}
|
2014-03-09 10:41:21 +01:00
|
|
|
xmlWriter->writeEndElement(); // entry
|
2014-03-08 10:50:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtendedDebugLogEntry::toCSV(QTextStream *csvStream, quint32 baseTime)
|
|
|
|
{
|
|
|
|
QString data;
|
2014-03-09 10:41:21 +01:00
|
|
|
|
2014-03-08 10:50:32 +01:00
|
|
|
if (getType() == DebugLogEntry::TYPE_TEXT) {
|
|
|
|
data = QString((const char *)getData().Data);
|
|
|
|
} else if (getType() == DebugLogEntry::TYPE_UAVOBJECT) {
|
|
|
|
data = m_object->toString().replace("\n", "").replace("\t", "");
|
|
|
|
}
|
|
|
|
*csvStream << QString::number(getFlight() + 1) << '\t' << QString::number(getFlightTime() - baseTime) << '\t' << QString::number(getEntry()) << '\t' << data << '\n';
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:07:34 +01:00
|
|
|
void ExtendedDebugLogEntry::setData(const DebugLogEntry::DataFields &data, UAVObjectManager *objectManager)
|
2013-11-25 14:59:23 +01:00
|
|
|
{
|
2013-11-27 16:07:34 +01:00
|
|
|
DebugLogEntry::setData(data);
|
2013-12-07 23:28:25 +01:00
|
|
|
|
2013-11-27 16:07:34 +01:00
|
|
|
if (getType() == DebugLogEntry::TYPE_UAVOBJECT) {
|
|
|
|
UAVDataObject *object = (UAVDataObject *)objectManager->getObject(getObjectID(), getInstanceID());
|
|
|
|
Q_ASSERT(object);
|
2013-12-07 23:28:25 +01:00
|
|
|
m_object = object->clone(getInstanceID());
|
2013-11-27 16:07:34 +01:00
|
|
|
m_object->unpack(getData().Data);
|
|
|
|
}
|
2013-11-25 14:59:23 +01:00
|
|
|
}
|
2014-03-06 23:30:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper() : QObject()
|
|
|
|
{}
|
|
|
|
|
|
|
|
UAVOLogSettingsWrapper::UAVOLogSettingsWrapper(UAVObject *object) : QObject(),
|
2014-03-08 17:28:46 +01:00
|
|
|
m_object(object), m_setting(DISABLED), m_period(0)
|
2014-03-06 23:30:55 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
UAVOLogSettingsWrapper::~UAVOLogSettingsWrapper()
|
|
|
|
{}
|