Changeset - a5247fcab715
[Not reviewed]
recording
0 5 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-02-16 06:24:53
hy@ozderya.net
added column separator option
5 files changed with 62 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/datarecorder.cpp
Show inline comments
 
@@ -26,15 +26,16 @@ DataRecorder::DataRecorder(QObject *pare
 
    fileStream(&file)
 
{
 
    lastNumChannels = 0;
 
    disableBuffering = false;
 
}
 

	
 
bool DataRecorder::startRecording(QString fileName, QStringList channelNames)
 
bool DataRecorder::startRecording(QString fileName, QString separator, QStringList channelNames)
 
{
 
    Q_ASSERT(!file.isOpen());
 
    _sep =  separator;
 

	
 
    // open file
 
    file.setFileName(fileName);
 
    if (!file.open(QIODevice::WriteOnly))
 
    {
 
        qCritical() << "Opening file " << fileName
 
@@ -42,13 +43,13 @@ bool DataRecorder::startRecording(QStrin
 
        return false;
 
    }
 

	
 
    // write header line
 
    if (!channelNames.isEmpty())
 
    {
 
        fileStream << channelNames.join(",");
 
        fileStream << channelNames.join(_sep);
 
        fileStream << "\n";
 
        lastNumChannels = channelNames.length();
 
    }
 
    return true;
 
}
 

	
 
@@ -68,13 +69,13 @@ void DataRecorder::addData(double* data,
 
    unsigned numOfSamples = length / numOfChannels; // per channel
 
    for (unsigned int i = 0; i < numOfSamples; i++)
 
    {
 
        for (unsigned ci = 0; ci < numOfChannels; ci++)
 
        {
 
            fileStream << data[ci * numOfSamples + i];
 
            if (ci != numOfChannels-1) fileStream << ",";
 
            if (ci != numOfChannels-1) fileStream << _sep;
 
        }
 
        fileStream << '\n';
 
    }
 

	
 
    if (disableBuffering) fileStream.flush();
 
}
src/datarecorder.h
Show inline comments
 
@@ -36,16 +36,17 @@ public:
 
    /**
 
     * @brief Starts recording data to a file in CSV format.
 
     *
 
     * File is opened and header line (names of channels) is written.
 
     *
 
     * @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
 
     * @return false if file operation fails (read only etc.)
 
     */
 
    bool startRecording(QString fileName, QStringList channelNames);
 
    bool startRecording(QString fileName, QString separator, QStringList channelNames);
 

	
 
    /**
 
     * @brief Adds data to a channel.
 
     *
 
     * Multiple rows of data can be added at a time. Each channels
 
     * data should be ordered consecutively in the `data` array:
 
@@ -67,9 +68,10 @@ public:
 
    void stopRecording();
 

	
 
private:
 
    unsigned lastNumChannels;   ///< used for error message only
 
    QFile file;
 
    QTextStream fileStream;
 
    QString _sep;
 
};
 

	
 
#endif // DATARECORDER_H
src/recordpanel.cpp
Show inline comments
 
@@ -219,13 +219,13 @@ void RecordPanel::startRecording(void)
 
{
 
    QStringList channelNames;
 
    if (ui->cbHeader->isChecked())
 
    {
 
        channelNames = _channelMan->infoModel()->channelNames();
 
    }
 
    _recorder->startRecording(selectedFile, channelNames);
 
    _recorder->startRecording(selectedFile, getSeparator(), channelNames);
 
    emit recordStarted();
 
}
 

	
 
void RecordPanel::stopRecording(void)
 
{
 
    emit recordStopped();
 
@@ -237,6 +237,13 @@ void RecordPanel::onPortClose()
 
    if (recordAction.isChecked() && ui->cbStopOnClose->isChecked())
 
    {
 
        stopRecording();
 
        recordAction.setChecked(false);
 
    }
 
}
 

	
 
QString RecordPanel::getSeparator() const
 
{
 
    QString sep = ui->leSeparator->text();
 
    sep.replace("\\t", "\t");
 
    return sep;
 
}
src/recordpanel.h
Show inline comments
 
@@ -87,12 +87,16 @@ private:
 
     */
 
    bool confirmOverwrite(QString fileName);
 

	
 
    void startRecording(void);
 
    void stopRecording(void);
 

	
 
    /// Returns separator text from ui. "\t" is converted to TAB
 
    /// character.
 
    QString getSeparator() const;
 

	
 
private slots:
 
    /**
 
     * @brief Opens up the file select dialog
 
     *
 
     * If you cancel the selection operation, currently selected file is not
 
     * changed.
src/recordpanel.ui
Show inline comments
 
@@ -4,13 +4,13 @@
 
 <widget class="QWidget" name="RecordPanel">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>532</width>
 
    <height>169</height>
 
    <height>261</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
   <string>Form</string>
 
  </property>
 
  <layout class="QHBoxLayout" name="horizontalLayout_2">
 
@@ -90,12 +90,52 @@
 
       <property name="checked">
 
        <bool>true</bool>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <layout class="QHBoxLayout" name="horizontalLayout_3">
 
       <item>
 
        <widget class="QLabel" name="label">
 
         <property name="text">
 
          <string>Column Separator:</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item>
 
        <widget class="QLineEdit" name="leSeparator">
 
         <property name="maximumSize">
 
          <size>
 
           <width>30</width>
 
           <height>16777215</height>
 
          </size>
 
         </property>
 
         <property name="toolTip">
 
          <string>For TAB character enter \t</string>
 
         </property>
 
         <property name="text">
 
          <string>,</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item>
 
        <spacer name="horizontalSpacer">
 
         <property name="orientation">
 
          <enum>Qt::Horizontal</enum>
 
         </property>
 
         <property name="sizeHint" stdset="0">
 
          <size>
 
           <width>40</width>
 
           <height>20</height>
 
          </size>
 
         </property>
 
        </spacer>
 
       </item>
 
      </layout>
 
     </item>
 
     <item>
 
      <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>
 
@@ -107,13 +147,13 @@
 
       <property name="orientation">
 
        <enum>Qt::Vertical</enum>
 
       </property>
 
       <property name="sizeHint" stdset="0">
 
        <size>
 
         <width>20</width>
 
         <height>40</height>
 
         <height>1</height>
 
        </size>
 
       </property>
 
      </spacer>
 
     </item>
 
    </layout>
 
   </item>
 
@@ -140,13 +180,13 @@
 
       <property name="orientation">
 
        <enum>Qt::Vertical</enum>
 
       </property>
 
       <property name="sizeHint" stdset="0">
 
        <size>
 
         <width>20</width>
 
         <height>40</height>
 
         <height>1</height>
 
        </size>
 
       </property>
 
      </spacer>
 
     </item>
 
    </layout>
 
   </item>
0 comments (0 inline, 0 general)