Changeset - a9a5e414ab54
[Not reviewed]
reader-stat
0 6 0
Hasan Yavuz ÖZDERYA - 7 years ago 2019-02-10 11:49:00
hy@ozderya.net
added bits per second display label
6 files changed with 52 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/abstractreader.cpp
Show inline comments
 
@@ -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;
 
}
src/abstractreader.h
Show inline comments
 
@@ -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();
src/dataformatpanel.cpp
Show inline comments
 
/*
 
  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);
src/dataformatpanel.h
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -22,7 +22,6 @@
 

	
 
#include <QWidget>
 
#include <QButtonGroup>
 
#include <QTimer>
 
#include <QSerialPort>
 
#include <QList>
 
#include <QSettings>
 
@@ -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`.
src/mainwindow.cpp
Show inline comments
 
@@ -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();
src/mainwindow.h
Show inline comments
 
@@ -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);
 

	
0 comments (0 inline, 0 general)