From 2ce3365861e63a3e805bd25284d1b3b0a33430a0 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 26 Nov 2011 22:51:20 +0100 Subject: [PATCH] GVS/Scope: Bugfix: Export all known data points into CSV not just one per screen redraw --- .../src/plugins/scope/scopegadgetwidget.cpp | 78 +++++++++++-------- .../src/plugins/scope/scopegadgetwidget.h | 2 + 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp index fe322f06b..12f6974b8 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.cpp @@ -447,6 +447,7 @@ void ScopeGadgetWidget::uavObjectReceived(UAVObject* obj) foreach(PlotData* plotData, m_curvesData.values()) { if (plotData->append(obj)) m_csvLoggingDataUpdated=1; } + csvLoggingAddData(); } void ScopeGadgetWidget::replotNewData() @@ -610,6 +611,7 @@ int ScopeGadgetWidget::csvLoggingStart() m_csvLoggingStartTime = NOW; m_csvLoggingHeaderSaved=0; m_csvLoggingDataSaved=0; + m_csvLoggingBuffer.clear(); QDir PathCheck(m_csvLoggingPath); if (!PathCheck.exists()) { @@ -677,13 +679,50 @@ int ScopeGadgetWidget::csvLoggingInsertHeader() return 0; } +int ScopeGadgetWidget::csvLoggingAddData() +{ + if (!m_csvLoggingStarted) return -1; + m_csvLoggingDataValid=0; + QDateTime NOW = QDateTime::currentDateTime(); + QString tempString; + + QTextStream ss( &tempString ); + ss << NOW.toString("yyyy-MM-dd") << ", " << NOW.toString("hh:mm:ss.z") << ", " ; + +#if QT_VERSION >= 0x040700 + ss <<(NOW.toMSecsSinceEpoch() - m_csvLoggingStartTime.toMSecsSinceEpoch())/1000.00; +#else + ss <<(NOW.toTime_t() - m_csvLoggingStartTime.toTime_t()); +#endif + ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated; + m_csvLoggingDataUpdated=0; + + foreach(PlotData* plotData2, m_curvesData.values()) + { + ss << ", "; + if (plotData2->xData->isEmpty ()) + { + } + else + { + ss << QString().sprintf("%3.6g",plotData2->yDataHistory->last()/pow(10,plotData2->scalePower)); + m_csvLoggingDataValid=1; + } + } + ss << endl; + if (m_csvLoggingDataValid) + { + QTextStream ts( &m_csvLoggingBuffer ); + ts << tempString; + } + + return 0; +} + int ScopeGadgetWidget::csvLoggingInsertData() { if (!m_csvLoggingStarted) return -1; m_csvLoggingDataSaved=1; - m_csvLoggingDataValid=0; - QDateTime NOW = QDateTime::currentDateTime(); - QString tempString; if(m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append)== FALSE) { @@ -691,38 +730,11 @@ int ScopeGadgetWidget::csvLoggingInsertData() } else { - QTextStream ss( &tempString ); - ss << NOW.toString("yyyy-MM-dd") << ", " << NOW.toString("hh:mm:ss.z") << ", " ; - -#if QT_VERSION >= 0x040700 - ss <<(NOW.toMSecsSinceEpoch() - m_csvLoggingStartTime.toMSecsSinceEpoch())/1000.00; -#else - ss <<(NOW.toTime_t() - m_csvLoggingStartTime.toTime_t()); -#endif - ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated; - m_csvLoggingDataUpdated=0; - - foreach(PlotData* plotData2, m_curvesData.values()) - { - ss << ", "; - if (plotData2->xData->isEmpty ()) - { - } - else - { - ss << QString().sprintf("%3.6g",plotData2->yDataHistory->last()/pow(10,plotData2->scalePower)); - m_csvLoggingDataValid=1; - } - } - ss << endl; - if (m_csvLoggingDataValid) - { - QTextStream ts( &m_csvLoggingFile ); - ts << tempString; - } + QTextStream ts( &m_csvLoggingFile ); + ts << m_csvLoggingBuffer; m_csvLoggingFile.close(); } - + m_csvLoggingBuffer.clear(); return 0; } diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h index 09e79d6b0..98da3beb6 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetwidget.h @@ -166,11 +166,13 @@ private: QString m_csvLoggingName; QString m_csvLoggingPath; + QString m_csvLoggingBuffer; QFile m_csvLoggingFile; QMutex mutex; int csvLoggingInsertHeader(); + int csvLoggingAddData(); int csvLoggingInsertData(); void deleteLegend();