mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
OP-1244 Added basic support for multiple export format.
This commit is contained in:
parent
14f2894464
commit
905e6a8eda
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QXmlStreamWriter>
|
||||||
|
|
||||||
#include "debuglogcontrol.h"
|
#include "debuglogcontrol.h"
|
||||||
#include "uavobjecthelper.h"
|
#include "uavobjecthelper.h"
|
||||||
@ -193,6 +194,60 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
|
|||||||
setDisableControls(false);
|
setDisableControls(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlightLogManager::exportToXML(QString fileName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void FlightLogManager::exportLogs()
|
void FlightLogManager::exportLogs()
|
||||||
{
|
{
|
||||||
if (m_logEntries.isEmpty()) {
|
if (m_logEntries.isEmpty()) {
|
||||||
@ -202,49 +257,31 @@ void FlightLogManager::exportLogs()
|
|||||||
setDisableControls(true);
|
setDisableControls(true);
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save Log"),
|
QString oplFilter = tr("OpenPilot Log file %1").arg("(*.opl)");
|
||||||
tr("OP-%0.opl").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")),
|
QString csvFilter = tr("Text file %1").arg("(*.csv)");
|
||||||
tr("OpenPilot Log (*.opl)"));
|
QString xmlFilter = tr("XML file %1").arg("(*.xml)");
|
||||||
|
|
||||||
|
QString selectedFilter = csvFilter;
|
||||||
|
|
||||||
|
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 (!fileName.isEmpty()) {
|
||||||
// Loop and create a new file for each flight.
|
if (selectedFilter == oplFilter) {
|
||||||
fileName = fileName.replace(QString(".opl"), QString("%1.opl"));
|
if (!fileName.endsWith(".opl")) {
|
||||||
int currentEntry = 0;
|
fileName.append(".opl");
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
exportToOPL(fileName);
|
||||||
// Get current flight
|
} else if (selectedFilter == csvFilter) {
|
||||||
currentFlight = m_logEntries[currentEntry]->getFlight();
|
if (!fileName.endsWith(".csv")) {
|
||||||
|
fileName.append(".csv");
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
exportToCSV(fileName);
|
||||||
logFile.close();
|
} else if (selectedFilter == xmlFilter) {
|
||||||
|
if (!fileName.endsWith(".xml")) {
|
||||||
|
fileName.append(".xml");
|
||||||
|
}
|
||||||
|
exportToXML(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +157,11 @@ private:
|
|||||||
bool m_disableExport;
|
bool m_disableExport;
|
||||||
bool m_cancelDownload;
|
bool m_cancelDownload;
|
||||||
bool m_adjustExportedTimestamps;
|
bool m_adjustExportedTimestamps;
|
||||||
|
|
||||||
|
void exportToOPL(QString fileName);
|
||||||
|
void exportToCSV(QString fileName);
|
||||||
|
void exportToXML(QString fileName);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLIGHTLOGMANAGER_H
|
#endif // FLIGHTLOGMANAGER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user