Changeset - b2e9f1d04c4a
[Not reviewed]
default
0 4 0
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-06-25 13:14:49
hy@ozderya.net
add timestamping support to recorder
4 files changed with 79 insertions and 50 deletions:
0 comments (0 inline, 0 general)
src/datarecorder.cpp
Show inline comments
 
@@ -19,6 +19,7 @@
 

	
 
#include "datarecorder.h"
 

	
 
#include <QDateTime>
 
#include <QtDebug>
 

	
 
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];
src/datarecorder.h
Show inline comments
 
@@ -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;
src/recordpanel.cpp
Show inline comments
 
@@ -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);
 
    }
src/recordpanel.ui
Show inline comments
 
@@ -7,7 +7,7 @@
 
    <x>0</x>
 
    <y>0</y>
 
    <width>627</width>
 
    <height>261</height>
 
    <height>207</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
@@ -45,6 +45,52 @@
 
     </item>
 
     <item>
 
      <layout class="QGridLayout" name="gridLayout">
 
       <item row="2" column="1">
 
        <widget class="QCheckBox" name="cbStopOnClose">
 
         <property name="text">
 
          <string>Stop recording when port closed</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="1" column="0">
 
        <widget class="QCheckBox" name="cbAutoIncrement">
 
         <property name="toolTip">
 
          <string>Increments file name automatically everytime a new recording starts</string>
 
         </property>
 
         <property name="text">
 
          <string>Auto increment file name</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="3" column="0">
 
        <widget class="QCheckBox" name="cbDisableBuffering">
 
         <property name="toolTip">
 
          <string>Do not buffer when writing to file. Check this if you are using other software to open the file during recording.</string>
 
         </property>
 
         <property name="text">
 
          <string>Disable buffering</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="3" column="1">
 
        <widget class="QCheckBox" name="cbWindowsLE">
 
         <property name="toolTip">
 
          <string>Use CR+LF as line endings. Some windows software may not show lines correctly otherwise. Can't be changed during recording.</string>
 
         </property>
 
         <property name="text">
 
          <string>Windows Style Line Endings</string>
 
         </property>
 
         <property name="checked">
 
          <bool>false</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="1" column="1">
 
        <widget class="QCheckBox" name="cbHeader">
 
         <property name="toolTip">
 
@@ -71,52 +117,6 @@
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="3" column="0">
 
        <widget class="QCheckBox" name="cbDisableBuffering">
 
         <property name="toolTip">
 
          <string>Do not buffer when writing to file. Check this if you are using other software to open the file during recording.</string>
 
         </property>
 
         <property name="text">
 
          <string>Disable buffering</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="2" column="1">
 
        <widget class="QCheckBox" name="cbStopOnClose">
 
         <property name="text">
 
          <string>Stop recording when port closed</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="1" column="0">
 
        <widget class="QCheckBox" name="cbAutoIncrement">
 
         <property name="toolTip">
 
          <string>Increments file name automatically everytime a new recording starts</string>
 
         </property>
 
         <property name="text">
 
          <string>Auto increment file name</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="3" column="1">
 
        <widget class="QCheckBox" name="cbWindowsLE">
 
         <property name="toolTip">
 
          <string>Use CR+LF as line endings. Some windows software may not show lines correctly otherwise. Can't be changed during recording.</string>
 
         </property>
 
         <property name="text">
 
          <string>Windows Style Line Endings</string>
 
         </property>
 
         <property name="checked">
 
          <bool>false</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="1" column="2">
 
        <spacer name="horizontalSpacer_2">
 
         <property name="orientation">
 
@@ -130,6 +130,16 @@
 
         </property>
 
        </spacer>
 
       </item>
 
       <item row="4" column="0">
 
        <widget class="QCheckBox" name="cbTimestamp">
 
         <property name="toolTip">
 
          <string>Insert timestamp (milliseconds from epoch) as first column</string>
 
         </property>
 
         <property name="text">
 
          <string>Insert timestamp</string>
 
         </property>
 
        </widget>
 
       </item>
 
      </layout>
 
     </item>
 
     <item>
0 comments (0 inline, 0 general)