1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-22 12:54:14 +01:00

OP-1119 Fixed support for saving multiple flights when saving logs to .opl format.

This commit is contained in:
Fredrik Arvidsson 2013-11-30 11:44:55 +01:00
parent d14044431e
commit a3c555f8bb

View File

@ -178,6 +178,10 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
void FlightLogManager::exportLogs() void FlightLogManager::exportLogs()
{ {
if(m_flightEntries.isEmpty()) {
return;
}
setDisableControls(true); setDisableControls(true);
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
@ -185,20 +189,42 @@ void FlightLogManager::exportLogs()
tr("OP-%0.opl").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")), tr("OP-%0.opl").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")),
tr("OpenPilot Log (*.opl)")); tr("OpenPilot Log (*.opl)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
LogFile logFile; // Loop and create a new file for each flight.
logFile.useProvidedTimeStamp(true); fileName = fileName.replace(QString(".opl"), QString("%1.opl"));
logFile.setFileName(fileName); int currentEntry = 0;
logFile.open(QIODevice::WriteOnly); int currentFlight = 0;
UAVTalk uavTalk(&logFile, m_objectManager); // Continue until all entries are exported
while(currentEntry < m_logEntries.count()) {
foreach (ExtendedDebugLogEntry* entry, m_logEntries) { // Get current flight
if (entry->getType() == ExtendedDebugLogEntry::TYPE_UAVOBJECT) { currentFlight = m_logEntries[currentEntry]->getFlight();
logFile.setNextTimeStamp(entry->getFlightTime());
uavTalk.sendObject(entry->uavObject(), false, false); 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());
// Use UAVTalk to log complete message to file
uavTalk.sendObject(entry->uavObject(), false, false);
}
currentEntry++;
} }
logFile.close();
} }
logFile.close();
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();