# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2018-06-25 13:14:49 # Node ID b2e9f1d04c4a48b0d54b82e5ac7ee521618b2813 # Parent 6acb6d6f037c668efab73c82d9be2f05f830c51d add timestamping support to recorder diff --git a/src/datarecorder.cpp b/src/datarecorder.cpp --- a/src/datarecorder.cpp +++ b/src/datarecorder.cpp @@ -19,6 +19,7 @@ #include "datarecorder.h" +#include #include DataRecorder::DataRecorder(QObject *parent) : @@ -28,12 +29,15 @@ DataRecorder::DataRecorder(QObject *pare lastNumChannels = 0; disableBuffering = false; windowsLE = false; + timestampEn = false; } -bool DataRecorder::startRecording(QString fileName, QString separator, QStringList channelNames) +bool DataRecorder::startRecording(QString fileName, QString separator, + QStringList channelNames, bool insertTime) { Q_ASSERT(!file.isOpen()); _sep = separator; + timestampEn = insertTime; // open file file.setFileName(fileName); @@ -47,6 +51,10 @@ bool DataRecorder::startRecording(QStrin // write header line if (!channelNames.isEmpty()) { + if (timestampEn) + { + fileStream << tr("timestamp") << _sep; + } fileStream << channelNames.join(_sep); fileStream << le(); lastNumChannels = channelNames.length(); @@ -70,9 +78,15 @@ void DataRecorder::feedIn(const SamplePa lastNumChannels = numChannels; // write data + qint64 timestamp; + if (timestampEn) timestamp = QDateTime::currentMSecsSinceEpoch(); unsigned numSamples = data.numSamples(); for (unsigned int i = 0; i < numSamples; i++) { + if (timestampEn) + { + fileStream << timestamp << _sep; + } for (unsigned ci = 0; ci < numChannels; ci++) { fileStream << data.data(ci)[i]; diff --git a/src/datarecorder.h b/src/datarecorder.h --- a/src/datarecorder.h +++ b/src/datarecorder.h @@ -58,9 +58,11 @@ public: * @param fileName name of the recording file * @param separator column separator * @param channelNames names of the channels for header line, if empty no header line is written + * @param insertTime enable inserting timestamp * @return false if file operation fails (read only etc.) */ - bool startRecording(QString fileName, QString separator, QStringList channelNames); + bool startRecording(QString fileName, QString separator, + QStringList channelNames, bool insertTime); /** * @brief Adds data to a channel. @@ -92,6 +94,7 @@ private: QFile file; QTextStream fileStream; QString _sep; + bool timestampEn; /// Returns the selected line ending. const char* le() const; diff --git a/src/recordpanel.cpp b/src/recordpanel.cpp --- a/src/recordpanel.cpp +++ b/src/recordpanel.cpp @@ -68,6 +68,7 @@ RecordPanel::RecordPanel(Stream* stream, }); connect(&recordAction, &QAction::toggled, ui->cbWindowsLE, &QWidget::setDisabled); + connect(&recordAction, &QAction::toggled, ui->cbTimestamp, &QWidget::setDisabled); } RecordPanel::~RecordPanel() @@ -233,7 +234,8 @@ void RecordPanel::startRecording(void) { channelNames = _stream->infoModel()->channelNames(); } - if (recorder.startRecording(selectedFile, getSeparator(), channelNames)) + if (recorder.startRecording(selectedFile, getSeparator(), + channelNames, ui->cbTimestamp->isChecked())) { _stream->connectFollower(&recorder); } diff --git a/src/recordpanel.ui b/src/recordpanel.ui --- a/src/recordpanel.ui +++ b/src/recordpanel.ui @@ -7,7 +7,7 @@ 0 0 627 - 261 + 207 @@ -45,6 +45,52 @@ + + + + Stop recording when port closed + + + true + + + + + + + Increments file name automatically everytime a new recording starts + + + Auto increment file name + + + true + + + + + + + Do not buffer when writing to file. Check this if you are using other software to open the file during recording. + + + Disable buffering + + + + + + + Use CR+LF as line endings. Some windows software may not show lines correctly otherwise. Can't be changed during recording. + + + Windows Style Line Endings + + + false + + + @@ -71,52 +117,6 @@ - - - - Do not buffer when writing to file. Check this if you are using other software to open the file during recording. - - - Disable buffering - - - - - - - Stop recording when port closed - - - true - - - - - - - Increments file name automatically everytime a new recording starts - - - Auto increment file name - - - true - - - - - - - Use CR+LF as line endings. Some windows software may not show lines correctly otherwise. Can't be changed during recording. - - - Windows Style Line Endings - - - false - - - @@ -130,6 +130,16 @@ + + + + Insert timestamp (milliseconds from epoch) as first column + + + Insert timestamp + + +