Commit fb582986 authored by Lorenz Meier's avatar Lorenz Meier

Fixed logging

parent 12cdc471
...@@ -28,6 +28,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -28,6 +28,8 @@ This file is part of the QGROUNDCONTROL project
*/ */
#include <QFile> #include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QTextStream> #include <QTextStream>
#include <QStringList> #include <QStringList>
...@@ -64,14 +66,15 @@ void LogCompressor::run() ...@@ -64,14 +66,15 @@ void LogCompressor::run()
QString outFileName; QString outFileName;
QStringList parts = QFileInfo(infile.fileName()).absoluteFilePath().split(".", QString::SkipEmptyParts); QStringList parts = QFileInfo(infile.fileName()).absoluteFilePath().split(".", QString::SkipEmptyParts);
parts.replace(parts.size()-2, "compressed." + parts.last()); parts.replace(0, parts.first() + "_compressed");
parts.replace(parts.size()-1, "txt");
outFileName = parts.join("."); outFileName = parts.join(".");
// Verify that the output file is useable // Verify that the output file is useable
QFile outTmpFile(outFileName); QFile outTmpFile(outFileName);
if (!outTmpFile.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!outTmpFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
emit logProcessingStatusChanged(tr("Log Compressor: Cannot start/compress log file, since output file %1 is not writable").arg(QFileInfo(outTmpFile.fileName()).absoluteFilePath())); emit logProcessingStatusChanged(tr("Log Compressor: Cannot start/compress log file, since output file %1 is not writable").arg(QFileInfo(outTmpFile.fileName()).absoluteFilePath()));
return; return;
} }
......
...@@ -47,7 +47,7 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval): Qwt ...@@ -47,7 +47,7 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval): Qwt
this->plotid = plotid; this->plotid = plotid;
this->plotInterval = interval; this->plotInterval = interval;
maxValue = DBL_MIN; maxValue = -DBL_MAX;
minValue = DBL_MAX; minValue = DBL_MAX;
//lastMaxTimeAdded = QTime(); //lastMaxTimeAdded = QTime();
......
...@@ -548,13 +548,13 @@ void LinechartWidget::startLogging() ...@@ -548,13 +548,13 @@ void LinechartWidget::startLogging()
// Let user select the log file name // Let user select the log file name
//QDate date(QDate::currentDate()); //QDate date(QDate::currentDate());
// QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log") // QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log")
QString fileName = QFileDialog::getSaveFileName(this, tr("Specify log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Logfile (*.csv *.txt);;")); QString fileName = QFileDialog::getSaveFileName(this, tr("Specify log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Logfile (*.log);;"));
while (!(fileName.endsWith(".txt") || fileName.endsWith(".csv")) && !abort && fileName != "") { while (!(fileName.endsWith(".log")) && !abort && fileName != "") {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Unsuitable file extension for logfile"); msgBox.setText("Unsuitable file extension for logfile");
msgBox.setInformativeText("Please choose .txt or .csv as file extension. Click OK to change the file extension, cancel to not start logging."); msgBox.setInformativeText("Please choose .log as file extension. Click OK to change the file extension, cancel to not start logging.");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
if(msgBox.exec() != QMessageBox::Ok) if(msgBox.exec() != QMessageBox::Ok)
...@@ -562,7 +562,7 @@ void LinechartWidget::startLogging() ...@@ -562,7 +562,7 @@ void LinechartWidget::startLogging()
abort = true; abort = true;
break; break;
} }
fileName = QFileDialog::getSaveFileName(this, tr("Specify log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Logfile (*.txt *.csv);;")); fileName = QFileDialog::getSaveFileName(this, tr("Specify log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Logfile (*.log);;"));
} }
qDebug() << "SAVE FILE" << fileName; qDebug() << "SAVE FILE" << fileName;
...@@ -570,7 +570,7 @@ void LinechartWidget::startLogging() ...@@ -570,7 +570,7 @@ void LinechartWidget::startLogging()
// Check if the user did not abort the file save dialog // Check if the user did not abort the file save dialog
if (!abort && fileName != "") { if (!abort && fileName != "") {
logFile = new QFile(fileName); logFile = new QFile(fileName);
if (logFile->open(QIODevice::WriteOnly | QIODevice::Text)) { if (logFile->open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)) {
logging = true; logging = true;
logStartTime = 0; logStartTime = 0;
curvesWidget->setEnabled(false); curvesWidget->setEnabled(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment