Changeset - 151c8a6430b7
[Not reviewed]
reader-stat
0 4 0
Hasan Yavuz Ă–ZDERYA - 6 years ago 2019-04-17 15:19:34
hy@ozderya.net
improve dataformatpanel api
4 files changed with 16 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/bpslabel.cpp
Show inline comments
 
@@ -26,12 +26,13 @@ BPSLabel::BPSLabel(PortControl* portCont
 
                   DataFormatPanel* dataFormatPanel,
 
                   QWidget *parent) :
 
    QLabel(parent)
 
{
 
    _portControl = portControl;
 
    _dataFormatPanel = dataFormatPanel;
 
    prevBytesRead = 0;
 

	
 
    setText("0bps");
 
    setToolTip(tr(BPS_TOOLTIP));
 

	
 
    connect(&bpsTimer, &QTimer::timeout,
 
            this, &BPSLabel::onBpsTimeout);
 
@@ -39,13 +40,17 @@ BPSLabel::BPSLabel(PortControl* portCont
 
    connect(portControl, &PortControl::portToggled,
 
            this, &BPSLabel::onPortToggled);
 
}
 

	
 
void BPSLabel::onBpsTimeout()
 
{
 
    unsigned bits = _dataFormatPanel->getBytesRead() * 8;
 
    uint64_t curBytesRead = _dataFormatPanel->bytesRead();
 
    uint64_t bytesRead = curBytesRead - prevBytesRead;
 
    prevBytesRead = curBytesRead;
 

	
 
    unsigned bits = bytesRead * 8;
 
    unsigned maxBps = _portControl->maxBitRate();
 
    QString str;
 
    if (bits >= maxBps)
 
    {
 
        // TODO: an icon for bps warning
 
        str = QString(tr("!%1/%2bps")).arg(bits).arg(maxBps);
src/bpslabel.h
Show inline comments
 
@@ -42,12 +42,14 @@ public:
 

	
 
private:
 
    PortControl* _portControl;
 
    DataFormatPanel* _dataFormatPanel;
 
    QTimer bpsTimer;
 

	
 
    uint64_t prevBytesRead;
 

	
 
private slots:
 
    void onBpsTimeout();
 
    void onPortToggled(bool open);
 
};
 

	
 
#endif // BPSLABEL_H
src/dataformatpanel.cpp
Show inline comments
 
@@ -36,12 +36,13 @@ DataFormatPanel::DataFormatPanel(QSerial
 
{
 
    ui->setupUi(this);
 

	
 
    serialPort = port;
 
    paused = false;
 
    readerBeforeDemo = nullptr;
 
    _bytesRead = 0;
 

	
 
    // initalize default reader
 
    currentReader = &bsReader;
 
    bsReader.enable();
 
    ui->rbBinary->setChecked(true);
 
    ui->horizontalLayout->addWidget(bsReader.settingsWidget(), 1);
 
@@ -127,15 +128,16 @@ void DataFormatPanel::selectReader(Abstr
 
    reader->pause(paused);
 

	
 
    currentReader = reader;
 
    emit sourceChanged(currentReader);
 
}
 

	
 
unsigned DataFormatPanel::getBytesRead()
 
uint64_t DataFormatPanel::bytesRead()
 
{
 
    return currentReader->getBytesRead();
 
    _bytesRead += currentReader->getBytesRead();
 
    return _bytesRead;
 
}
 

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

	
src/dataformatpanel.h
Show inline comments
 
@@ -17,12 +17,13 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef DATAFORMATPANEL_H
 
#define DATAFORMATPANEL_H
 

	
 
#include <stdint.h>
 
#include <QWidget>
 
#include <QButtonGroup>
 
#include <QSerialPort>
 
#include <QList>
 
#include <QSettings>
 
#include <QtGlobal>
 
@@ -46,14 +47,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();
 
    /// Returns total number of bytes read
 
    uint64_t bytesRead();
 
    /// 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:
 
@@ -75,12 +76,13 @@ private:
 
    /// Currently selected reader
 
    AbstractReader* currentReader;
 
    /// Disable current reader and enable a another one
 
    void selectReader(AbstractReader* reader);
 

	
 
    bool paused;
 
    uint64_t _bytesRead;
 

	
 
    DemoReader demoReader;
 
    AbstractReader* readerBeforeDemo;
 

	
 
    bool isDemoEnabled() const;
 
};
0 comments (0 inline, 0 general)