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
 
@@ -20,13 +20,13 @@
 
#include "abstractreader.h"
 

	
 
AbstractReader::AbstractReader(QIODevice* device, QObject* parent) :
 
    QObject(parent)
 
{
 
    _device = device;
 
    numBytesRead = 0;
 
    bytesRead = 0;
 
}
 

	
 
void AbstractReader::pause(bool enabled)
 
{
 
    paused = enabled;
 
}
 
@@ -44,8 +44,15 @@ void AbstractReader::enable(bool enabled
 
        disconnectSinks();
 
    }
 
}
 

	
 
void AbstractReader::onDataReady()
 
{
 
    numBytesRead += readData();
 
    bytesRead += readData();
 
}
 

	
 
unsigned AbstractReader::getBytesRead()
 
{
 
    unsigned r = bytesRead;
 
    bytesRead = 0;
 
    return r;
 
}
src/abstractreader.h
Show inline comments
 
@@ -46,12 +46,15 @@ public:
 
    /// 'disabled'.
 
    virtual void enable(bool enabled = true);
 

	
 
    /// 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);
 

	
 
public slots:
 
    /**
 
@@ -75,13 +78,13 @@ protected:
 
     * where the implementors should read the data and return the
 
     * exact number of bytes read from the device.
 
     */
 
    virtual unsigned readData() = 0;
 

	
 
private:
 
    unsigned numBytesRead;
 
    unsigned bytesRead;
 

	
 
private slots:
 
    void onDataReady();
 
};
 

	
 
#endif // ABSTRACTREADER_H
src/dataformatpanel.cpp
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 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
 
@@ -127,12 +127,17 @@ void DataFormatPanel::selectReader(Abstr
 
    reader->pause(paused);
 

	
 
    currentReader = reader;
 
    emit sourceChanged(currentReader);
 
}
 

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

	
 
void DataFormatPanel::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_DataFormat);
 

	
 
    // save selected data format (current reader)
 
    QString format;
src/dataformatpanel.h
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 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
 
@@ -19,13 +19,12 @@
 

	
 
#ifndef DATAFORMATPANEL_H
 
#define DATAFORMATPANEL_H
 

	
 
#include <QWidget>
 
#include <QButtonGroup>
 
#include <QTimer>
 
#include <QSerialPort>
 
#include <QList>
 
#include <QSettings>
 
#include <QtGlobal>
 

	
 
#include "binarystreamreader.h"
 
@@ -47,12 +46,14 @@ public:
 
    ~DataFormatPanel();
 

	
 
    /// Returns currently selected number of channels
 
    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`.
 
    void loadSettings(QSettings* settings);
 

	
 
public slots:
src/mainwindow.cpp
Show inline comments
 
@@ -228,15 +228,22 @@ MainWindow::MainWindow(QWidget *parent) 
 
                      plotControlPanel.yMin(), plotControlPanel.yMax());
 
    plotMan->setXAxis(plotControlPanel.xAxisAsIndex(),
 
                      plotControlPanel.xMin(), plotControlPanel.xMax());
 
    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);
 

	
 
    // init demo
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
@@ -352,12 +359,24 @@ void MainWindow::setupAboutDialog()
 

	
 
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)
 
{
 
    source->connectSink(&stream);
 
    source->connectSink(&sampleCounter);
 
@@ -379,12 +398,18 @@ void MainWindow::onNumOfSamplesChanged(i
 
void MainWindow::onSpsChanged(float sps)
 
{
 
    int precision = sps < 1. ? 3 : 0;
 
    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();
 
}
 

	
 
void MainWindow::enableDemo(bool enabled)
src/mainwindow.h
Show inline comments
 
@@ -80,14 +80,17 @@ private:
 
    // ChannelManager channelMan;
 
    Stream stream;
 
    PlotManager* plotMan;
 
    QWidget* secondaryPlot;
 
    SnapshotManager snapshotMan;
 
    SampleCounter sampleCounter;
 
    /// bit counter timer
 
    QTimer bpsTimer;
 

	
 
    QLabel spsLabel;
 
    QLabel bpsLabel;
 
    CommandPanel commandPanel;
 
    DataFormatPanel dataFormatPanel;
 
    RecordPanel recordPanel;
 
    PlotControlPanel plotControlPanel;
 
    PlotMenu plotMenu;
 
    DataTextView textView;
 
@@ -116,12 +119,13 @@ private slots:
 
    void onPortToggled(bool open);
 
    void onSourceChanged(Source* source);
 
    void onNumOfSamplesChanged(int value);
 

	
 
    void clearPlot();
 
    void onSpsChanged(float sps);
 
    void onBpsTimeout();
 
    void enableDemo(bool enabled);
 
    void showBarPlot(bool show);
 

	
 
    void onExportCsv();
 
    void onSaveSettings();
 
    void onLoadSettings();
0 comments (0 inline, 0 general)