Changeset - 07ecd1b1fb2a
[Not reviewed]
new-reader
0 7 0
Hasan Yavuz ÖZDERYA - 9 years ago 2016-05-23 14:56:53
hy@ozderya.net
re-enabled sps counter
7 files changed with 37 insertions and 49 deletions:
0 comments (0 inline, 0 general)
src/abstractreader.cpp
Show inline comments
 
@@ -24,4 +24,23 @@ AbstractReader::AbstractReader(QIODevice
 
{
 
    _device = device;
 
    _channelMan = channelMan;
 

	
 
    // initialize sps counter
 
    sampleCount = 0;
 
    samplesPerSecond = 0;
 
    QObject::connect(&spsTimer, &QTimer::timeout,
 
                     this, &AbstractReader::spsTimerTimeout);
 
    // TODO: start sps timer when reader is enabled
 
    spsTimer.start(SPS_UPDATE_TIMEOUT * 1000);
 
}
 

	
 
void AbstractReader::spsTimerTimeout()
 
{
 
    unsigned currentSps = samplesPerSecond;
 
    samplesPerSecond = (sampleCount/numOfChannels())/SPS_UPDATE_TIMEOUT;
 
    if (currentSps != samplesPerSecond)
 
    {
 
        emit samplesPerSecondChanged(samplesPerSecond);
 
    }
 
    sampleCount = 0;
 
}
src/abstractreader.h
Show inline comments
 
@@ -23,6 +23,7 @@
 
#include <QObject>
 
#include <QIODevice>
 
#include <QWidget>
 
#include <QTimer>
 

	
 
#include "channelmanager.h"
 

	
 
@@ -72,6 +73,17 @@ public slots:
 
protected:
 
    QIODevice* _device;
 
    ChannelManager* _channelMan;
 

	
 
    /// Implementing class should simply increase this count as samples are read
 
    unsigned sampleCount;
 

	
 
private:
 
    const int SPS_UPDATE_TIMEOUT = 1;  // second
 
    unsigned samplesPerSecond;
 
    QTimer spsTimer;
 

	
 
private slots:
 
    void spsTimerTimeout();
 
};
 

	
 
#endif // ABSTRACTREADER_H
src/asciireader.h
Show inline comments
 
@@ -40,7 +40,6 @@ private:
 
    AsciiReaderSettings _settingsWidget;
 
    unsigned _numOfChannels;
 
    bool paused;
 
    unsigned sampleCount; ///< used for sps counter
 

	
 
private slots:
 
    void onDataReady();
src/binarystreamreader.cpp
Show inline comments
 
@@ -47,8 +47,6 @@ BinaryStreamReader::BinaryStreamReader(Q
 
            {
 
                skipByteRequested = true;
 
            });
 

	
 
    // TODO sps counter
 
}
 

	
 
QWidget* BinaryStreamReader::settingsWidget()
src/binarystreamreader.h
Show inline comments
 
@@ -46,7 +46,6 @@ private:
 
    unsigned sampleSize;
 
    bool paused;
 
    bool skipByteRequested;
 
    unsigned sampleCount; ///< used for sps counter
 

	
 
    /// points to the readSampleAs function for currently selected number format
 
    double (BinaryStreamReader::*readSample)();
src/dataformatpanel.cpp
Show inline comments
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 
  Copyright © 2016 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -49,6 +49,8 @@ DataFormatPanel::DataFormatPanel(QSerial
 
    connect(&bsReader, SIGNAL(dataAdded()), this, SIGNAL(dataAdded()));
 
    connect(&bsReader, SIGNAL(numOfChannelsChanged(unsigned)),
 
            this, SIGNAL(numOfChannelsChanged(unsigned)));
 
    connect(&bsReader, SIGNAL(samplesPerSecondChanged(unsigned)),
 
            this, SIGNAL(samplesPerSecondChanged(unsigned)));
 

	
 
    // initalize reader selection buttons
 
    connect(ui->rbBinary, &QRadioButton::toggled, [this](bool checked)
 
@@ -61,12 +63,6 @@ DataFormatPanel::DataFormatPanel(QSerial
 
                if (checked) selectReader(&asciiReader);
 
            });
 

	
 
    // Init sps (sample per second) counter
 
    // sampleCount = 0;
 
    // QObject::connect(&spsTimer, &QTimer::timeout,
 
    //                  this, &DataFormatPanel::spsTimerTimeout);
 
    // spsTimer.start(SPS_UPDATE_TIMEOUT * 1000);
 

	
 
    // Init demo mode
 
    demoCount = 0;
 
    demoTimer.setInterval(100);
 
@@ -79,23 +75,11 @@ DataFormatPanel::~DataFormatPanel()
 
    delete ui;
 
}
 

	
 
// TODO: remove
 
bool DataFormatPanel::skipByteEnabled()
 
{
 
    return false;
 
}
 

	
 
unsigned DataFormatPanel::numOfChannels()
 
{
 
    return currentReader->numOfChannels();
 
}
 

	
 
// TODO: remove
 
void DataFormatPanel::requestSkipByte()
 
{
 
    skipByteRequested = true;
 
}
 

	
 
void DataFormatPanel::pause(bool enabled)
 
{
 
    currentReader->pause(enabled);
 
@@ -113,17 +97,6 @@ void DataFormatPanel::enableDemo(bool en
 
    }
 
}
 

	
 
void DataFormatPanel::spsTimerTimeout()
 
{
 
    // unsigned currentSps = _samplesPerSecond;
 
    // _samplesPerSecond = (sampleCount/_numOfChannels)/SPS_UPDATE_TIMEOUT;
 
    // if (currentSps != _samplesPerSecond)
 
    // {
 
    //     emit samplesPerSecondChanged(_samplesPerSecond);
 
    // }
 
    // sampleCount = 0;
 
}
 

	
 
void DataFormatPanel::demoTimerTimeout()
 
{
 
    const double period = 100;
 
@@ -146,7 +119,6 @@ void DataFormatPanel::addChannelData(uns
 
                                     double* data, unsigned size)
 
{
 
    _channelMan->addChannelData(channel, data, size);
 
    sampleCount += size;
 
}
 

	
 
void DataFormatPanel::selectReader(AbstractReader* reader)
 
@@ -159,6 +131,8 @@ void DataFormatPanel::selectReader(Abstr
 
    connect(reader, SIGNAL(dataAdded()), this, SIGNAL(dataAdded()));
 
    connect(reader, SIGNAL(numOfChannelsChanged(unsigned)),
 
            this, SIGNAL(numOfChannelsChanged(unsigned)));
 
    connect(reader, SIGNAL(samplesPerSecondChanged(unsigned)),
 
            this, SIGNAL(samplesPerSecondChanged(unsigned)));
 

	
 
    // switch the settings widget
 
    ui->horizontalLayout->removeWidget(currentReader->settingsWidget());
src/dataformatpanel.h
Show inline comments
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 
  Copyright © 2016 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -47,20 +47,14 @@ public:
 
    ~DataFormatPanel();
 

	
 
    unsigned numOfChannels();
 
    unsigned samplesPerSecond();
 
    bool skipByteEnabled(void); // true for binary formats
 

	
 
public slots:
 
    // during next read operation reader will skip 1 byte,
 
    // requests are not accumulated
 
    void requestSkipByte();
 
    void pause(bool);
 
    void enableDemo(bool); // demo shouldn't be enabled when port is open
 

	
 
signals:
 
    void numOfChannelsChanged(unsigned);
 
    void samplesPerSecondChanged(unsigned);
 
    void skipByteEnabledChanged(bool); // remove
 
    void dataAdded();
 

	
 
private:
 
@@ -76,14 +70,8 @@ private:
 
    /// Disable current reader and enable a another one
 
    void selectReader(AbstractReader* reader);
 

	
 
    bool skipByteRequested; // remove
 
    bool paused; // remove
 

	
 
    const int SPS_UPDATE_TIMEOUT = 1;  // second
 
    unsigned _samplesPerSecond;
 
    unsigned int sampleCount;
 
    QTimer spsTimer;
 

	
 
    // demo
 
    QTimer demoTimer;
 
    int demoCount;
 
@@ -92,7 +80,6 @@ private:
 
    void addChannelData(unsigned int channel, double* data, unsigned size);
 

	
 
private slots:
 
    void spsTimerTimeout();
 
    void demoTimerTimeout();
 
};
 

	
0 comments (0 inline, 0 general)