Changeset - a31b6ac829d6
[Not reviewed]
Merge default
0 18 2
Hasan Yavuz ÖZDERYA - 6 years ago 2019-04-17 15:36:18
hy@ozderya.net
Merge with reader-stat
20 files changed with 288 insertions and 49 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -133,12 +133,13 @@ add_executable(${PROGRAM_NAME} WIN32
 
  src/samplepack.cpp
 
  src/source.cpp
 
  src/sink.cpp
 
  src/samplecounter.cpp
 
  src/ledwidget.cpp
 
  src/datatextview.cpp
 
  src/bpslabel.cpp
 
  misc/windows_icon.rc
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  )
 

	
 
# Use the Widgets module from Qt 5.
serialplot.pro
Show inline comments
 
@@ -69,13 +69,14 @@ SOURCES += \
 
    src/plotmanager.cpp \
 
    src/numberformat.cpp \
 
    src/recordpanel.cpp \
 
    src/updatechecker.cpp \
 
    src/updatecheckdialog.cpp \
 
    src/demoreadersettings.cpp \
 
    src/datatextview.cpp
 
    src/datatextview.cpp \
 
    src/bpslabel.cpp
 

	
 
HEADERS += \
 
    src/mainwindow.h \
 
    src/utils.h \
 
    src/portcontrol.h \
 
    src/floatswap.h \
 
@@ -113,13 +114,14 @@ HEADERS += \
 
    src/setting_defines.h \
 
    src/numberformat.h \
 
    src/recordpanel.h \
 
    src/updatechecker.h \
 
    src/updatecheckdialog.h \
 
    src/demoreadersettings.h \
 
    src/datatextview.h
 
    src/datatextview.h \
 
    src/bpslabel.h
 

	
 
FORMS += \
 
    src/mainwindow.ui \
 
    src/about_dialog.ui \
 
    src/portcontrol.ui \
 
    src/snapshotview.ui \
src/abstractreader.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
 
@@ -20,12 +20,13 @@
 
#include "abstractreader.h"
 

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

	
 
void AbstractReader::pause(bool enabled)
 
{
 
    paused = enabled;
 
}
 
@@ -40,6 +41,18 @@ void AbstractReader::enable(bool enabled
 
    else
 
    {
 
        QObject::disconnect(_device, 0, this, 0);
 
        disconnectSinks();
 
    }
 
}
 

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

	
 
unsigned AbstractReader::getBytesRead()
 
{
 
    unsigned r = bytesRead;
 
    bytesRead = 0;
 
    return r;
 
}
src/abstractreader.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
 
@@ -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:
 
    /**
 
@@ -60,15 +63,28 @@ public slots:
 
     * Reader should actually continue reading to keep the
 
     * synchronization but shouldn't commit data.
 
     */
 
    void pause(bool enabled);
 

	
 
protected:
 
    /// Reader should read from this device in `readData()` function.
 
    QIODevice* _device;
 

	
 
    /// Reader should check this variable to determine if reading is
 
    /// paused in `readData()`
 
    bool paused;
 

	
 
protected slots:
 
    /// all derived readers has to override this function
 
    virtual void onDataReady() = 0;
 
    /**
 
     * Called when `readyRead` is signaled by the device. This is
 
     * where the implementors should read the data and return the
 
     * exact number of bytes read from the device.
 
     */
 
    virtual unsigned readData() = 0;
 

	
 
private:
 
    unsigned bytesRead;
 

	
 
private slots:
 
    void onDataReady();
 
};
 

	
 
#endif // ABSTRACTREADER_H
src/asciireader.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
 
@@ -67,27 +67,26 @@ unsigned AsciiReader::numChannels() cons
 

	
 
void AsciiReader::enable(bool enabled)
 
{
 
    if (enabled)
 
    {
 
        firstReadAfterEnable = true;
 
        QObject::connect(_device, &QIODevice::readyRead,
 
                         this, &AsciiReader::onDataReady);
 
    }
 
    else
 
    {
 
        QObject::disconnect(_device, 0, this, 0);
 
        disconnectSinks();
 
    }
 

	
 
    AbstractReader::enable(enabled);
 
}
 

	
 
void AsciiReader::onDataReady()
 
unsigned AsciiReader::readData()
 
{
 
    unsigned numBytesRead = 0;
 

	
 
    while(_device->canReadLine())
 
    {
 
        QString line = QString(_device->readLine());
 
        QByteArray bytes = _device->readLine();
 
        QString line = QString(bytes);
 
        numBytesRead += bytes.size();
 

	
 
        // discard only once when we just started reading
 
        if (firstReadAfterEnable)
 
        {
 
            firstReadAfterEnable = false;
 
            continue;
 
@@ -127,12 +126,14 @@ void AsciiReader::onDataReady()
 

	
 
            // commit data
 
            feedOut(*samples);
 
            delete samples;
 
        }
 
    }
 

	
 
    return numBytesRead;
 
}
 

	
 
SamplePack* AsciiReader::parseLine(const QString& line) const
 
{
 
    auto separatedValues = line.split(delimiter, QString::SkipEmptyParts);
 
    unsigned numComingChannels = separatedValues.length();
src/asciireader.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
 
@@ -47,14 +47,16 @@ private:
 
    /// number of channels will be determined from incoming data
 
    unsigned autoNumOfChannels;
 
    QChar delimiter; ///< selected column delimiter
 

	
 
    bool firstReadAfterEnable = false;
 

	
 
    unsigned readData() override;
 

	
 
private slots:
 
    void onDataReady() override;
 

	
 
    /**
 
     * Parses given line and returns sample pack.
 
     *
 
     * Returns `nullptr` in case of error.
 
     */
 
    SamplePack* parseLine(const QString& line) const;
src/binarystreamreader.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
 
@@ -104,56 +104,64 @@ void BinaryStreamReader::onNumOfChannels
 
{
 
    _numChannels = value;
 
    updateNumChannels();
 
    emit numOfChannelsChanged(value);
 
}
 

	
 
void BinaryStreamReader::onDataReady()
 
unsigned BinaryStreamReader::readData()
 
{
 
    // a package is a set of channel data like {CHAN0_SAMPLE, CHAN1_SAMPLE...}
 
    int packageSize = sampleSize * _numChannels;
 
    int bytesAvailable = _device->bytesAvailable();
 
    unsigned packageSize = sampleSize * _numChannels;
 
    unsigned bytesAvailable = _device->bytesAvailable();
 
    unsigned totalRead = 0;
 

	
 
    // skip 1 byte if requested
 
    if (skipByteRequested && bytesAvailable > 0)
 
    {
 
        _device->read(1);
 
        totalRead++;
 
        skipByteRequested = false;
 
        bytesAvailable--;
 
    }
 

	
 
    // skip 1 sample (channel) if requested
 
    if (skipSampleRequested && bytesAvailable >= (int) sampleSize)
 
    if (skipSampleRequested && bytesAvailable >= sampleSize)
 
    {
 
        _device->read(sampleSize);
 
        totalRead += sampleSize;
 
        skipSampleRequested = false;
 
        bytesAvailable -= sampleSize;
 
    }
 

	
 
    if (bytesAvailable < packageSize) return;
 
    if (bytesAvailable < packageSize) return totalRead;
 

	
 
    int numOfPackagesToRead =
 
    unsigned numOfPackagesToRead =
 
        (bytesAvailable - (bytesAvailable % packageSize)) / packageSize;
 
    unsigned numBytesToRead = numOfPackagesToRead * packageSize;
 

	
 
    totalRead += numBytesToRead;
 

	
 
    if (paused)
 
    {
 
        // read and discard data
 
        _device->read(numOfPackagesToRead*packageSize);
 
        return;
 
        _device->read(numBytesToRead);
 
        return totalRead;
 
    }
 

	
 
    // actual reading
 
    SamplePack samples(numOfPackagesToRead, _numChannels);
 
    for (int i = 0; i < numOfPackagesToRead; i++)
 
    for (unsigned i = 0; i < numOfPackagesToRead; i++)
 
    {
 
        for (unsigned int ci = 0; ci < _numChannels; ci++)
 
        for (unsigned ci = 0; ci < _numChannels; ci++)
 
        {
 
            samples.data(ci)[i] = (this->*readSample)();
 
        }
 
    }
 
    feedOut(samples);
 

	
 
    return totalRead;
 
}
 

	
 
template<typename T> double BinaryStreamReader::readSampleAs()
 
{
 
    T data;
 

	
src/binarystreamreader.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
 
@@ -57,13 +57,14 @@ private:
 
     *
 
     * @note Device should already have enough bytes present before
 
     * calling this function.
 
     */
 
    template<typename T> double readSampleAs();
 

	
 
    unsigned readData() override;
 

	
 
private slots:
 
    void onNumberFormatChanged(NumberFormat numberFormat);
 
    void onNumOfChannelsChanged(unsigned value);
 
    void onDataReady() override;
 
};
 

	
 
#endif // BINARYSTREAMREADER_H
src/bpslabel.cpp
Show inline comments
 
new file 100644
 
/*
 
  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
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "bpslabel.h"
 

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

	
 
BPSLabel::BPSLabel(PortControl* portControl,
 
                   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);
 

	
 
    connect(portControl, &PortControl::portToggled,
 
            this, &BPSLabel::onPortToggled);
 
}
 

	
 
void BPSLabel::onBpsTimeout()
 
{
 
    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);
 
        setToolTip(tr(BPS_TOOLTIP_ERR));
 
    }
 
    else
 
    {
 
        str = QString(tr("%1bps")).arg(bits);
 
        setToolTip(tr(BPS_TOOLTIP));
 
    }
 
    setText(str);
 
}
 

	
 
void BPSLabel::onPortToggled(bool open)
 
{
 
    if (open)
 
    {
 
        bpsTimer.start(1000);
 
    }
 
    else
 
    {
 
        bpsTimer.stop();
 
        // if not cleared last displayed value is stuck
 
        setText("0bps");
 
        setToolTip(tr(BPS_TOOLTIP));
 
    }
 
}
src/bpslabel.h
Show inline comments
 
new file 100644
 
/*
 
  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
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef BPSLABEL_H
 
#define BPSLABEL_H
 

	
 
#include <QLabel>
 
#include <QTimer>
 

	
 
#include "portcontrol.h"
 
#include "dataformatpanel.h"
 

	
 
/**
 
 * Displays bits per second read from device.
 
 *
 
 * Displays a warning if maximum bit rate is reached.
 
 */
 
class BPSLabel : public QLabel
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit BPSLabel(PortControl* portControl,
 
                      DataFormatPanel* dataFormatPanel,
 
                      QWidget *parent = 0);
 

	
 
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
 
/*
 
  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
 
@@ -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,12 +128,18 @@ void DataFormatPanel::selectReader(Abstr
 
    reader->pause(paused);
 

	
 
    currentReader = reader;
 
    emit sourceChanged(currentReader);
 
}
 

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

	
 
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
 
@@ -17,15 +17,15 @@
 
  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 <QTimer>
 
#include <QSerialPort>
 
#include <QList>
 
#include <QSettings>
 
#include <QtGlobal>
 

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

	
 
    /// Returns currently selected number of channels
 
    unsigned numChannels() const;
 
    /// Returns active source (reader)
 
    Source* activeSource();
 
    /// 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:
 
@@ -74,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;
 
};
src/demoreader.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
 
@@ -50,14 +50,15 @@ void DemoReader::enable(bool enabled)
 
    {
 
        timer.start();
 
    }
 
    else
 
    {
 
        timer.stop();
 
        disconnectSinks();
 
    }
 

	
 
    AbstractReader::enable(enabled);
 
}
 

	
 
unsigned DemoReader::numChannels() const
 
{
 
    return _numChannels;
 
}
 
@@ -88,10 +89,11 @@ void DemoReader::demoTimerTimeout()
 
void DemoReader::onNumChannelsChanged(unsigned value)
 
{
 
    _numChannels = value;
 
    updateNumChannels();
 
}
 

	
 
void DemoReader::onDataReady()
 
unsigned DemoReader::readData()
 
{
 
    // intentionally empty, required by AbstractReader
 
    return 0;
 
}
src/demoreader.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
 
@@ -52,13 +52,14 @@ private:
 
    DemoReaderSettings _settingsWidget;
 

	
 
    unsigned _numChannels;
 
    QTimer timer;
 
    int count;
 

	
 
    unsigned readData() override;
 

	
 
private slots:
 
    void demoTimerTimeout();
 
    void onNumChannelsChanged(unsigned value);
 
    void onDataReady() override;
 
};
 

	
 
#endif // DEMOREADER_H
src/framedreader.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
 
@@ -181,24 +181,27 @@ void FramedReader::onFrameSizeChanged(un
 
        frameSize = value;
 
    }
 
    checkSettings();
 
    reset();
 
}
 

	
 
void FramedReader::onDataReady()
 
unsigned FramedReader::readData()
 
{
 
    if (settingsInvalid) return;
 
    unsigned numBytesRead = 0;
 

	
 
    if (settingsInvalid) return numBytesRead;
 

	
 
    // loop until we run out of bytes or more bytes is required
 
    unsigned bytesAvailable;
 
    while ((bytesAvailable = _device->bytesAvailable()))
 
    {
 
        if (!gotSync) // read sync word
 
        {
 
            char c;
 
            _device->getChar(&c);
 
            numBytesRead++;
 
            if (c == syncWord[sync_i]) // correct sync byte?
 
            {
 
                sync_i++;
 
                if (sync_i == (unsigned) syncWord.length())
 
                {
 
                    gotSync = true;
 
@@ -210,12 +213,13 @@ void FramedReader::onDataReady()
 
            }
 
        }
 
        else if (hasSizeByte && !gotSize) // skipped if fixed frame size
 
        {
 
            frameSize = 0;
 
            _device->getChar((char*) &frameSize);
 
            numBytesRead++;
 

	
 
            if (frameSize == 0) // check size
 
            {
 
                qCritical() << "Frame size is 0!";
 
                reset();
 
            }
 
@@ -239,16 +243,19 @@ void FramedReader::onDataReady()
 
            {
 
                break;
 
            }
 
            else // read data bytes and checksum
 
            {
 
                readFrameDataAndCheck();
 
                numBytesRead += checksumEnabled ? frameSize+1 : frameSize;
 
                reset();
 
            }
 
        }
 
    }
 

	
 
    return numBytesRead;
 
}
 

	
 
void FramedReader::reset()
 
{
 
    sync_i = 0;
 
    gotSync = false;
 
@@ -260,13 +267,13 @@ void FramedReader::reset()
 
// Important: this function assumes device has enough bytes to read a full frames data and checksum
 
void FramedReader::readFrameDataAndCheck()
 
{
 
    // if paused just read and waste data
 
    if (paused)
 
    {
 
        _device->read((checksumEnabled ? frameSize+1 : frameSize));
 
        _device->read(checksumEnabled ? frameSize+1 : frameSize);
 
        return;
 
    }
 

	
 
    // a package is 1 set of samples for all channels
 
    unsigned numOfPackagesToRead = frameSize / (_numChannels * sampleSize);
 
    SamplePack samples(numOfPackagesToRead, _numChannels);
src/framedreader.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
 
@@ -76,14 +76,15 @@ private:
 
    double (FramedReader::*readSample)();
 
    template<typename T> double readSampleAs();
 
    /// reads payload portion of the frame, calculates checksum and commits data
 
    /// @note should be called only if there are enough bytes on device
 
    void readFrameDataAndCheck();
 

	
 
    unsigned readData() override;
 

	
 
private slots:
 
    void onDataReady() override;
 

	
 
    void onNumberFormatChanged(NumberFormat numberFormat);
 
    void onNumOfChannelsChanged(unsigned value);
 
    void onSyncWordChanged(QByteArray);
 
    void onFrameSizeChanged(unsigned);
 
};
src/mainwindow.cpp
Show inline comments
 
@@ -70,13 +70,14 @@ MainWindow::MainWindow(QWidget *parent) 
 
    secondaryPlot(NULL),
 
    snapshotMan(this, &stream),
 
    commandPanel(&serialPort),
 
    dataFormatPanel(&serialPort),
 
    recordPanel(&stream),
 
    textView(&stream),
 
    updateCheckDialog(this)
 
    updateCheckDialog(this),
 
    bpsLabel(&portControl, &dataFormatPanel, this)
 
{
 
    ui->setupUi(this);
 

	
 
    plotMan = new PlotManager(ui->plotArea, &plotMenu, &stream);
 

	
 
    ui->tabWidget->insertTab(0, &portControl, "Port");
 
@@ -231,19 +232,27 @@ 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
 
    ui->statusBar->addPermanentWidget(&bpsLabel);
 

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

	
 
    bpsLabel.setMinimumWidth(70);
 
    bpsLabel.setAlignment(Qt::AlignRight);
 
    spsLabel.setMinimumWidth(70);
 
    spsLabel.setAlignment(Qt::AlignRight);
 

	
 
    // init demo
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     this, &MainWindow::enableDemo);
 

	
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     plotMan, &PlotManager::showDemoIndicator);
 
@@ -357,12 +366,17 @@ 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)
 
    {
 
        spsLabel.setText("0sps");
 
    }
 
}
 

	
 
void MainWindow::onSourceChanged(Source* source)
 
{
 
    source->connectSink(&stream);
 
    source->connectSink(&sampleCounter);
src/mainwindow.h
Show inline comments
 
@@ -44,12 +44,13 @@
 
#include "snapshotmanager.h"
 
#include "plotmanager.h"
 
#include "plotmenu.h"
 
#include "updatecheckdialog.h"
 
#include "samplecounter.h"
 
#include "datatextview.h"
 
#include "bpslabel.h"
 

	
 
namespace Ui {
 
class MainWindow;
 
}
 

	
 
class MainWindow : public QMainWindow
 
@@ -88,12 +89,13 @@ private:
 
    DataFormatPanel dataFormatPanel;
 
    RecordPanel recordPanel;
 
    PlotControlPanel plotControlPanel;
 
    PlotMenu plotMenu;
 
    DataTextView textView;
 
    UpdateCheckDialog updateCheckDialog;
 
    BPSLabel bpsLabel;
 

	
 
    void handleCommandLineOptions(const QCoreApplication &app);
 

	
 
    /// Returns true if demo is running
 
    bool isDemoRunning();
 
    /// Display a secondary plot in the splitter, removing and
src/portcontrol.cpp
Show inline comments
 
@@ -511,12 +511,33 @@ void PortControl::openPort()
 
    if (!serialPort->isOpen())
 
    {
 
        openAction.trigger();
 
    }
 
}
 

	
 
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
 
@@ -47,12 +47,14 @@ public:
 
    QSerialPort* serialPort;
 
    QToolBar* toolBar();
 

	
 
    void selectPort(QString portName);
 
    void selectBaudrate(QString baudRate);
 
    void openPort();
 
    /// 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);
 

	
0 comments (0 inline, 0 general)