# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2016-05-23 14:56:53 # Node ID 07ecd1b1fb2a2b16c59d3cb9e7baf24ea743debe # Parent 45644f64ec758796da0f6ce7b62fd2144f84e847 re-enabled sps counter diff --git a/src/abstractreader.cpp b/src/abstractreader.cpp --- a/src/abstractreader.cpp +++ b/src/abstractreader.cpp @@ -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; +} diff --git a/src/abstractreader.h b/src/abstractreader.h --- a/src/abstractreader.h +++ b/src/abstractreader.h @@ -23,6 +23,7 @@ #include #include #include +#include #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 diff --git a/src/asciireader.h b/src/asciireader.h --- a/src/asciireader.h +++ b/src/asciireader.h @@ -40,7 +40,6 @@ private: AsciiReaderSettings _settingsWidget; unsigned _numOfChannels; bool paused; - unsigned sampleCount; ///< used for sps counter private slots: void onDataReady(); diff --git a/src/binarystreamreader.cpp b/src/binarystreamreader.cpp --- a/src/binarystreamreader.cpp +++ b/src/binarystreamreader.cpp @@ -47,8 +47,6 @@ BinaryStreamReader::BinaryStreamReader(Q { skipByteRequested = true; }); - - // TODO sps counter } QWidget* BinaryStreamReader::settingsWidget() diff --git a/src/binarystreamreader.h b/src/binarystreamreader.h --- a/src/binarystreamreader.h +++ b/src/binarystreamreader.h @@ -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)(); diff --git a/src/dataformatpanel.cpp b/src/dataformatpanel.cpp --- a/src/dataformatpanel.cpp +++ b/src/dataformatpanel.cpp @@ -1,5 +1,5 @@ /* - 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()); diff --git a/src/dataformatpanel.h b/src/dataformatpanel.h --- a/src/dataformatpanel.h +++ b/src/dataformatpanel.h @@ -1,5 +1,5 @@ /* - 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(); };