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