Files
@ 12603d48a708
Branch filter:
Location: tempo-plotter/src/datarecorder.h
12603d48a708
3.3 KiB
text/plain
fix symbol show settings not loaded at startup
'toggled' is emitted for 'setChecked', 'triggered' is only emitted when user
actually clicks something
'toggled' is emitted for 'setChecked', 'triggered' is only emitted when user
actually clicks something
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | /*
Copyright © 2018 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATARECORDER_H
#define DATARECORDER_H
#include <QObject>
#include <QFile>
#include <QTextStream>
#include "sink.h"
/**
* Implemented as a `Sink` that writes incoming data to a file. Before
* connecting a `Source` recording must be started with the `startRecording`
* method. Also before calling `stopRecording`, recorder should be disconnected
* from source.
*/
class DataRecorder : public QObject, public Sink
{
Q_OBJECT
public:
explicit DataRecorder(QObject *parent = 0);
/// Disables file buffering
bool disableBuffering;
/**
* Use CR+LF as line ending. `false` by default.
*
* @note Toggling this variable during a recording will result in
* a corrupted file. Care must be taken at higher (UI) levels.
*/
bool windowsLE;
/**
* @brief Starts recording data to a file in CSV format.
*
* File is opened and header line (names of channels) is written. After
* calling this function recorder should be connected to a `Source`.
*
* @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 insertTime);
/**
* @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:
*
* [CH0_SMP0, CH0_SMP1 ... CH0_SMPN, CH1_SMP0, CH1_SMP1, ... , CHN_SMPN]
*
* If `numOfChannels` changes during recording, no data will be
* lost (ie. it will be written to the file) but this will produce
* an invalid CSV file. An error message will be written to the
* console.
*
* @param data samples array
* @param length number of samples in `data`, must be multiple of `numOfChannels`
* @param numOfChannels how many channels samples this data carries
*/
void addData(double* data, unsigned length, unsigned numOfChannels);
/// Stops recording, closes file.
void stopRecording();
protected:
virtual void feedIn(const SamplePack& data);
private:
unsigned lastNumChannels; ///< used for error message only
QFile file;
QTextStream fileStream;
QString _sep;
bool timestampEn;
/// Returns the selected line ending.
const char* le() const;
};
#endif // DATARECORDER_H
|