Changeset - 538d40c57b2b
[Not reviewed]
recording
0 6 0
Hasan Yavuz ÖZDERYA - 9 years ago 2017-02-14 05:58:51
hy@ozderya.net
moved buffer access to abstract reader class
6 files changed with 17 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/abstractreader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -41,6 +41,13 @@ void AbstractReader::spsTimerTimeout()
 
    if (currentSps != samplesPerSecond)
 
    {
 
        emit samplesPerSecondChanged(samplesPerSecond);
 
    }
 
    sampleCount = 0;
 
}
 

	
 
void AbstractReader::addData(double* samples, unsigned length)
 
{
 
    _channelMan->addData(samples, length);
 
    sampleCount += length;
 
    emit dataAdded();
 
}
src/abstractreader.h
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -69,19 +69,20 @@ public slots:
 
     * synchronization but shouldn't commit data.
 
     */
 
    virtual void pause(bool) = 0;
 

	
 
protected:
 
    QIODevice* _device;
 
    ChannelManager* _channelMan;
 

	
 
    /// Implementing class should simply increase this count as samples are read
 
    unsigned sampleCount;
 
    /// Should be called with read data
 
    void addData(double* samples, unsigned length);
 

	
 
private:
 
    const int SPS_UPDATE_TIMEOUT = 1;  // second
 
    ChannelManager* _channelMan;
 
    unsigned sampleCount;
 
    unsigned samplesPerSecond;
 
    QTimer spsTimer;
 

	
 
private slots:
 
    void spsTimerTimeout();
 
};
src/asciireader.cpp
Show inline comments
 
@@ -26,13 +26,12 @@
 

	
 
AsciiReader::AsciiReader(QIODevice* device, ChannelManager* channelMan, QObject *parent) :
 
    AbstractReader(device, channelMan, parent)
 
{
 
    paused = false;
 
    discardFirstLine = true;
 
    sampleCount = 0;
 

	
 
    _numOfChannels = _settingsWidget.numOfChannels();
 
    autoNumOfChannels = (_numOfChannels == NUMOFCHANNELS_AUTO);
 

	
 
    connect(&_settingsWidget, &AsciiReaderSettings::numOfChannelsChanged,
 
            [this](unsigned value)
 
@@ -152,15 +151,13 @@ void AsciiReader::onDataReady()
 
                qWarning() << "Data parsing error for channel: " << ci;
 
                channelSamples[ci] = 0;
 
            }
 
        }
 

	
 
        // commit data
 
        _channelMan->addData(channelSamples, _numOfChannels);
 
        sampleCount += numReadChannels;
 
        emit dataAdded();
 
        addData(channelSamples, _numOfChannels);
 

	
 
        delete[] channelSamples;
 
    }
 
}
 

	
 
void AsciiReader::saveSettings(QSettings* settings)
src/binarystreamreader.cpp
Show inline comments
 
@@ -26,13 +26,12 @@
 
BinaryStreamReader::BinaryStreamReader(QIODevice* device, ChannelManager* channelMan, QObject *parent) :
 
    AbstractReader(device, channelMan, parent)
 
{
 
    paused = false;
 
    skipByteRequested = false;
 
    skipSampleRequested = false;
 
    sampleCount = 0;
 

	
 
    _numOfChannels = _settingsWidget.numOfChannels();
 
    connect(&_settingsWidget, &BinaryStreamReaderSettings::numOfChannelsChanged,
 
            this, &BinaryStreamReader::numOfChannelsChanged);
 
    connect(&_settingsWidget, &BinaryStreamReaderSettings::numOfChannelsChanged,
 
            this, &BinaryStreamReader::onNumOfChannelsChanged);
 
@@ -168,15 +167,13 @@ void BinaryStreamReader::onDataReady()
 
        {
 
            // channelSamples[ci].replace(i, (this->*readSample)());
 
            channelSamples[ci*numOfPackagesToRead+i] = (this->*readSample)();
 
        }
 
    }
 

	
 
    _channelMan->addData(channelSamples, numOfPackagesToRead*_numOfChannels);
 
    sampleCount += numOfPackagesToRead*_numOfChannels;
 
    emit dataAdded();
 
    addData(channelSamples, numOfPackagesToRead*_numOfChannels);
 

	
 
    delete[] channelSamples;
 
}
 

	
 
template<typename T> double BinaryStreamReader::readSampleAs()
 
{
src/demoreader.cpp
Show inline comments
 
@@ -78,13 +78,11 @@ void DemoReader::demoTimerTimeout()
 
    {
 
        double* samples = new double[_numOfChannels];
 
        for (unsigned ci = 0; ci < _numOfChannels; ci++)
 
        {
 
            // we are calculating the fourier components of square wave
 
            samples[ci] = 4*sin(2*M_PI*double((ci+1)*count)/period)/((2*(ci+1))*M_PI);
 
            sampleCount++;
 
        }
 
        _channelMan->addData(samples, _numOfChannels);
 
        addData(samples, _numOfChannels);
 
        delete[] samples;
 
        emit dataAdded();
 
    }
 
}
src/framedreader.cpp
Show inline comments
 
@@ -307,14 +307,13 @@ void FramedReader::readFrameDataAndCheck
 
        checksumPassed = (calcChecksum == rChecksum);
 
    }
 

	
 
    if (!checksumEnabled || checksumPassed)
 
    {
 
        // commit data
 
        _channelMan->addData(channelSamples, numOfPackagesToRead * _numOfChannels);
 
        emit dataAdded();
 
        addData(channelSamples, numOfPackagesToRead*_numOfChannels);
 
    }
 
    else
 
    {
 
        qCritical() << "Checksum failed! Received:" << rChecksum << "Calculated:" << calcChecksum;
 
    }
 

	
0 comments (0 inline, 0 general)