Changeset - 50d42af49411
[Not reviewed]
default
0 2 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-06-14 15:40:59
hy@ozderya.net
discard the very first line when reading ascii data since it may be incomplete
2 files changed with 16 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/asciireader.cpp
Show inline comments
 
@@ -25,6 +25,7 @@ AsciiReader::AsciiReader(QIODevice* devi
 
    AbstractReader(device, channelMan, parent)
 
{
 
    paused = false;
 
    discardFirstLine = true;
 
    sampleCount = 0;
 

	
 
    _numOfChannels = _settingsWidget.numOfChannels();
 
@@ -32,6 +33,8 @@ AsciiReader::AsciiReader(QIODevice* devi
 
            this, &AsciiReader::numOfChannelsChanged);
 
    connect(&_settingsWidget, &AsciiReaderSettings::numOfChannelsChanged,
 
            [this](unsigned value){_numOfChannels = value;});
 

	
 
    connect(device, &QIODevice::aboutToClose, [this](){discardFirstLine=true;});
 
}
 

	
 
QWidget* AsciiReader::settingsWidget()
 
@@ -49,6 +52,7 @@ void AsciiReader::enable(bool enabled)
 
{
 
    if (enabled)
 
    {
 
        discardFirstLine = true;
 
        QObject::connect(_device, &QIODevice::readyRead,
 
                         this, &AsciiReader::onDataReady);
 
    }
 
@@ -69,12 +73,20 @@ void AsciiReader::onDataReady()
 
    {
 
        QByteArray line = _device->readLine();
 

	
 
        // discard only once when we just started reading
 
        if (discardFirstLine)
 
        {
 
            discardFirstLine = false;
 
            continue;
 
        }
 

	
 
        // discard data if paused
 
        if (paused)
 
        {
 
            return;
 
        }
 

	
 
        // parse data
 
        line = line.trimmed();
 
        auto separatedValues = line.split(',');
 

	
src/asciireader.h
Show inline comments
 
@@ -41,6 +41,10 @@ private:
 
    unsigned _numOfChannels;
 
    bool paused;
 

	
 
    // We may have (usually true) started reading in the middle of a
 
    // line, so its a better idea to just discard first line.
 
    bool discardFirstLine;
 

	
 
private slots:
 
    void onDataReady();
 
};
0 comments (0 inline, 0 general)