# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2019-02-10 11:49:00 # Node ID a9a5e414ab5470d1231dd27d93fabd446ee76543 # Parent 233fe22d52afc86f8124c52399a19718c30fdf3e added bits per second display label diff --git a/src/abstractreader.cpp b/src/abstractreader.cpp --- a/src/abstractreader.cpp +++ b/src/abstractreader.cpp @@ -23,7 +23,7 @@ AbstractReader::AbstractReader(QIODevice QObject(parent) { _device = device; - numBytesRead = 0; + bytesRead = 0; } void AbstractReader::pause(bool enabled) @@ -47,5 +47,12 @@ void AbstractReader::enable(bool enabled void AbstractReader::onDataReady() { - numBytesRead += readData(); + bytesRead += readData(); } + +unsigned AbstractReader::getBytesRead() +{ + unsigned r = bytesRead; + bytesRead = 0; + return r; +} diff --git a/src/abstractreader.h b/src/abstractreader.h --- a/src/abstractreader.h +++ b/src/abstractreader.h @@ -49,6 +49,9 @@ public: /// None of the current readers support X channel at the moment bool hasX() const final { return false; }; + /// Read and 'zero' the byte counter + unsigned getBytesRead(); + signals: // TODO: should we keep this? void numOfChannelsChanged(unsigned); @@ -78,7 +81,7 @@ protected: virtual unsigned readData() = 0; private: - unsigned numBytesRead; + unsigned bytesRead; private slots: void onDataReady(); diff --git a/src/dataformatpanel.cpp b/src/dataformatpanel.cpp --- a/src/dataformatpanel.cpp +++ b/src/dataformatpanel.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2018 Hasan Yavuz Özderya + Copyright © 2019 Hasan Yavuz Özderya This file is part of serialplot. @@ -130,6 +130,11 @@ void DataFormatPanel::selectReader(Abstr emit sourceChanged(currentReader); } +unsigned DataFormatPanel::getBytesRead() +{ + return currentReader->getBytesRead(); +} + void DataFormatPanel::saveSettings(QSettings* settings) { settings->beginGroup(SettingGroup_DataFormat); diff --git a/src/dataformatpanel.h b/src/dataformatpanel.h --- a/src/dataformatpanel.h +++ b/src/dataformatpanel.h @@ -1,5 +1,5 @@ /* - Copyright © 2018 Hasan Yavuz Özderya + Copyright © 2019 Hasan Yavuz Özderya This file is part of serialplot. @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -50,6 +49,8 @@ public: unsigned numChannels() const; /// Returns active source (reader) Source* activeSource(); + /// Reads and 'zero's number of bytes read from current reader + unsigned getBytesRead(); /// Stores data format panel settings into a `QSettings` void saveSettings(QSettings* settings); /// Loads data format panel settings from a `QSettings`. diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -231,9 +231,16 @@ MainWindow::MainWindow(QWidget *parent) plotMan->setNumOfSamples(numOfSamples); plotMan->setPlotWidth(plotControlPanel.plotWidth()); + // init bps (bits per second) counter + bpsLabel.setText("0bps"); + bpsLabel.setToolTip(tr("bits per second")); + ui->statusBar->addPermanentWidget(&bpsLabel); + connect(&bpsTimer, &QTimer::timeout, + this, &MainWindow::onBpsTimeout); + // Init sps (sample per second) counter spsLabel.setText("0sps"); - spsLabel.setToolTip("samples per second (per channel)"); + spsLabel.setToolTip(tr("samples per second (per channel)")); ui->statusBar->addPermanentWidget(&spsLabel); connect(&sampleCounter, &SampleCounter::spsChanged, this, &MainWindow::onSpsChanged); @@ -355,6 +362,18 @@ void MainWindow::onPortToggled(bool open // make sure demo mode is disabled if (open && isDemoRunning()) enableDemo(false); ui->actionDemoMode->setEnabled(!open); + + if (open) + { + bpsTimer.start(1000); + } + else + { + bpsTimer.stop(); + // if not cleared last displayed value is stuck + bpsLabel.setText("0bps"); + spsLabel.setText("0sps"); + } } void MainWindow::onSourceChanged(Source* source) @@ -382,6 +401,12 @@ void MainWindow::onSpsChanged(float sps) spsLabel.setText(QString::number(sps, 'f', precision) + "sps"); } +void MainWindow::onBpsTimeout() +{ + unsigned bits = dataFormatPanel.getBytesRead() * 8; + bpsLabel.setText(QString("%1bps").arg(bits)); +} + bool MainWindow::isDemoRunning() { return ui->actionDemoMode->isChecked(); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -83,8 +83,11 @@ private: QWidget* secondaryPlot; SnapshotManager snapshotMan; SampleCounter sampleCounter; + /// bit counter timer + QTimer bpsTimer; QLabel spsLabel; + QLabel bpsLabel; CommandPanel commandPanel; DataFormatPanel dataFormatPanel; RecordPanel recordPanel; @@ -119,6 +122,7 @@ private slots: void clearPlot(); void onSpsChanged(float sps); + void onBpsTimeout(); void enableDemo(bool enabled); void showBarPlot(bool show);