Changeset - f5f0a29e6433
[Not reviewed]
reader-stat
0 3 0
Hasan Yavuz ÖZDERYA - 7 years ago 2019-03-07 15:07:14
hy@ozderya.net
display baud rate warning tooltip and max bit rate in case its hit
3 files changed with 45 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -56,12 +56,15 @@ const QMap<int, QString> panelSettingMap
 
        {3, "Commands"},
 
        {4, "Record"},
 
        {5, "TextView"},
 
        {6, "Log"}
 
    });
 

	
 
const char* BPS_TOOLTIP = "bits per second";
 
const char* BPS_TOOLTIP_ERR = "Maximum baud rate may be reached!";
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow),
 
    aboutDialog(this),
 
    portControl(&serialPort),
 
    secondaryPlot(NULL),
 
@@ -230,13 +233,13 @@ MainWindow::MainWindow(QWidget *parent) 
 
                      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"));
 
    bpsLabel.setToolTip(tr(BPS_TOOLTIP));
 
    ui->statusBar->addPermanentWidget(&bpsLabel);
 
    connect(&bpsTimer, &QTimer::timeout,
 
            this, &MainWindow::onBpsTimeout);
 

	
 
    // Init sps (sample per second) counter
 
    spsLabel.setText("0sps");
 
@@ -369,12 +372,13 @@ void MainWindow::onPortToggled(bool open
 
    }
 
    else
 
    {
 
        bpsTimer.stop();
 
        // if not cleared last displayed value is stuck
 
        bpsLabel.setText("0bps");
 
        bpsLabel.setToolTip(tr(BPS_TOOLTIP));
 
        spsLabel.setText("0sps");
 
    }
 
}
 

	
 
void MainWindow::onSourceChanged(Source* source)
 
{
 
@@ -401,13 +405,26 @@ 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));
 
    unsigned maxBps = portControl.maxBitRate();
 
    QString str;
 
    if (bits >= maxBps)
 
    {
 
        // TODO: an icon for bps warning
 
        str = QString(tr("!%1/%2bps")).arg(bits).arg(maxBps);
 
        bpsLabel.setToolTip(tr(BPS_TOOLTIP_ERR));
 
    }
 
    else
 
    {
 
        str = QString(tr("%1bps")).arg(bits);
 
        bpsLabel.setToolTip(tr(BPS_TOOLTIP));
 
    }
 
    bpsLabel.setText(str);
 
}
 

	
 
bool MainWindow::isDemoRunning()
 
{
 
    return ui->actionDemoMode->isChecked();
 
}
src/portcontrol.cpp
Show inline comments
 
/*
 
  Copyright © 2017 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
 
@@ -450,12 +450,33 @@ QString PortControl::currentFlowControlT
 
    else // no parity
 
    {
 
        return "none";
 
    }
 
}
 

	
 
unsigned PortControl::maxBitRate() const
 
{
 
    float baud = serialPort->baudRate();
 
    float dataBits = serialPort->dataBits();
 
    float parityBits = serialPort->parity() == QSerialPort::NoParity ? 0 : 1;
 

	
 
    float stopBits;
 
    if (serialPort->stopBits() == QSerialPort::OneAndHalfStop)
 
    {
 
        stopBits = 1.5;
 
    }
 
    else
 
    {
 
        stopBits = serialPort->stopBits();
 
    }
 

	
 
    float frame_size = 1 /* start bit */ + dataBits + parityBits + stopBits;
 

	
 
    return float(baud) / frame_size;
 
}
 

	
 
void PortControl::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Port);
 
    settings->setValue(SG_Port_SelectedPort, selectedPortName());
 
    settings->setValue(SG_Port_BaudRate, ui->cbBaudRate->currentText());
 
    settings->setValue(SG_Port_Parity, currentParityText());
src/portcontrol.h
Show inline comments
 
/*
 
  Copyright © 2017 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
 
@@ -44,12 +44,15 @@ public:
 
    explicit PortControl(QSerialPort* port, QWidget* parent = 0);
 
    ~PortControl();
 

	
 
    QSerialPort* serialPort;
 
    QToolBar* toolBar();
 

	
 
    /// Returns maximum bit rate for current baud rate
 
    unsigned maxBitRate() const;
 

	
 
    /// Stores port settings into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads port settings from a `QSettings`. If open serial port is closed.
 
    void loadSettings(QSettings* settings);
 

	
 
private:
0 comments (0 inline, 0 general)