Commit e45ffc80 authored by lm's avatar lm

Fixed logging time base

parent 58a71b67
......@@ -1375,23 +1375,8 @@ void MainWindow::loadWidgets()
//loadPilotView();
}
void MainWindow::loadDataView()
{
clearView();
// DATAPLOT
if (dataplotWidget)
{
QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
if (centerStack)
centerStack->setCurrentWidget(dataplotWidget);
}
}
void MainWindow::loadDataView(QString fileName)
{
clearView();
// DATAPLOT
if (dataplotWidget)
{
......
......@@ -150,8 +150,6 @@ public slots:
void loadWidgets();
/** @brief Load data view, allowing to plot flight data */
void loadDataView();
/** @brief Load data view, allowing to plot flight data */
void loadDataView(QString fileName);
......
......@@ -126,6 +126,13 @@ void QGCDataPlot2D::savePlot()
fileName = QFileDialog::getSaveFileName(
this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation),
"PDF Documents (*.pdf);;SVG Images (*.svg)");
if (!fileName.contains("."))
{
// .csv is default extension
fileName.append(".pdf");
}
while(!(fileName.endsWith(".svg") || fileName.endsWith(".pdf")))
{
QMessageBox msgBox;
......
......@@ -57,7 +57,7 @@ maxTime(QUINT64_MIN),
maxInterval(MAX_STORAGE_INTERVAL),
timeScaleStep(DEFAULT_SCALE_INTERVAL), // 10 seconds
automaticScrollActive(false),
m_active(true),
m_active(false),
m_groundTime(true),
d_data(NULL),
d_curve(NULL)
......@@ -286,6 +286,14 @@ void LinechartPlot::enforceGroundTime(bool enforce)
m_groundTime = enforce;
}
/**
* @return True if the data points are stamped with the packet receive time
*/
bool LinechartPlot::groundTime()
{
return m_groundTime;
}
void LinechartPlot::addCurve(QString id)
{
QColor currentColor = getNextColor();
......@@ -468,6 +476,23 @@ bool LinechartPlot::isVisible(QString id)
return curves.value(id)->isVisible();
}
/**
* @return The visibility, true if it is visible, false otherwise
**/
bool LinechartPlot::anyCurveVisible()
{
bool visible = false;
foreach (QString key, curves.keys())
{
if (curves.value(key)->isVisible())
{
visible = true;
}
}
return visible;
}
/**
* @brief Allows to block interference of the automatic scrolling with user interaction
* When the plot is updated very fast (at 1 ms for example) with new data, it might
......
......@@ -190,6 +190,8 @@ public:
QList<QwtPlotCurve*> getCurves();
bool isVisible(QString id);
/** @brief Check if any curve is visible */
bool anyCurveVisible();
int getPlotId();
/** @brief Get the number of values to average over */
......@@ -243,6 +245,8 @@ public slots:
/** @brief Enforce the use of the receive timestamp */
void enforceGroundTime(bool enforce);
/** @brief Check if the receive timestamp is enforced */
bool groundTime();
// General interaction
void setWindowPosition(quint64 end);
......
......@@ -48,6 +48,7 @@ This file is part of the PIXHAWK project
#include "LinechartWidget.h"
#include "LinechartPlot.h"
#include "LogCompressor.h"
#include "QGC.h"
#include "MG.h"
......@@ -225,7 +226,18 @@ void LinechartWidget::appendData(int uasId, QString curve, double value, quint64
{
if (activePlot->isVisible(curve))
{
logFile->write(QString(QString::number(usec) + "\t" + QString::number(uasId) + "\t" + curve + "\t" + QString::number(value) + "\n").toLatin1());
quint64 time = 0;
// Adjust time
if (activePlot->groundTime())
{
time = QGC::groundTimeUsecs() - logStartTime;
}
else
{
time = usec - logStartTime;
}
logFile->write(QString(QString::number(time) + "\t" + QString::number(uasId) + "\t" + curve + "\t" + QString::number(value) + "\n").toLatin1());
logFile->flush();
}
}
......@@ -261,14 +273,35 @@ void LinechartWidget::refresh()
void LinechartWidget::startLogging()
{
// Let user select the log file name
QDate date(QDate::currentDate());
// 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 (*.txt, *.csv);;"));
// Store reference to file
// Append correct file ending if needed
bool abort = false;
while (!(fileName.endsWith(".txt") || fileName.endsWith(".csv")))
// Check if any curve is enabled
if (!activePlot->anyCurveVisible())
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("No curves selected for logging.");
msgBox.setInformativeText("Please check all curves you want to log. Currently no data would be logged, aborting the logging.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
return;
}
// Let user select the log file name
QDate date(QDate::currentDate());
// 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);;"));
if (!fileName.contains("."))
{
// .csv is default extension
fileName.append(".csv");
}
while (!(fileName.endsWith(".txt") || fileName.endsWith(".csv")) && !abort)
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
......@@ -292,6 +325,7 @@ void LinechartWidget::startLogging()
if (logFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
logging = true;
logStartTime = QGC::groundTimeUsecs();
logindex++;
logButton->setText(tr("Stop logging"));
disconnect(logButton, SIGNAL(clicked()), this, SLOT(startLogging()));
......
......@@ -131,6 +131,7 @@ protected:
bool logging;
QTimer* updateTimer;
LogCompressor* compressor;
quint64 logStartTime;
static const int MAX_CURVE_MENUITEM_NUMBER = 8;
static const int PAGESTEP_TIME_SCROLLBAR_VALUE = (MAX_TIME_SCROLLBAR_VALUE - MIN_TIME_SCROLLBAR_VALUE) / 10;
......
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