Changeset - 0894be6d3943
[Not reviewed]
default
0 8 0
Hasan Yavuz ÖZDERYA - 9 years ago 2017-02-06 16:42:50
hy@ozderya.net
improved api by replacing addChannelData function with addData that adds all channels data at the same time
8 files changed with 43 insertions and 41 deletions:
0 comments (0 inline, 0 general)
src/asciireader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -139,27 +139,30 @@ void AsciiReader::onDataReady()
 
        {
 
            numReadChannels = separatedValues.length();
 
            qWarning() << "Incoming data is missing data for some channels!";
 
        }
 

	
 
        // parse read line
 
        double* channelSamples = new double[_numOfChannels]();
 
        for (unsigned ci = 0; ci < numReadChannels; ci++)
 
        {
 
            bool ok;
 
            double channelSample = separatedValues[ci].toDouble(&ok);
 
            if (ok)
 
            {
 
                _channelMan->addChannelData(ci, &channelSample, 1);
 
                sampleCount++;
 
            }
 
            else
 
            channelSamples[ci] = separatedValues[ci].toDouble(&ok);
 
            if (!ok)
 
            {
 
                qWarning() << "Data parsing error for channel: " << ci;
 
                channelSamples[ci] = 0;
 
            }
 
        }
 

	
 
        // commit data
 
        _channelMan->addData(channelSamples, _numOfChannels);
 
        sampleCount += numReadChannels;
 
        emit dataAdded();
 

	
 
        delete[] channelSamples;
 
    }
 
}
 

	
 
void AsciiReader::saveSettings(QSettings* settings)
 
{
 
    _settingsWidget.saveSettings(settings);
src/binarystreamreader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -168,18 +168,14 @@ void BinaryStreamReader::onDataReady()
 
        {
 
            // channelSamples[ci].replace(i, (this->*readSample)());
 
            channelSamples[ci*numOfPackagesToRead+i] = (this->*readSample)();
 
        }
 
    }
 

	
 
    for (unsigned int ci = 0; ci < _numOfChannels; ci++)
 
    {
 
        addChannelData(ci,
 
                       channelSamples + ci*numOfPackagesToRead,
 
                       numOfPackagesToRead);
 
    }
 
    _channelMan->addData(channelSamples, numOfPackagesToRead*_numOfChannels);
 
    sampleCount += numOfPackagesToRead*_numOfChannels;
 
    emit dataAdded();
 

	
 
    delete[] channelSamples;
 
}
 

	
 
template<typename T> double BinaryStreamReader::readSampleAs()
 
@@ -197,19 +193,12 @@ template<typename T> double BinaryStream
 
        data = qFromBigEndian(data);
 
    }
 

	
 
    return double(data);
 
}
 

	
 
void BinaryStreamReader::addChannelData(unsigned int channel,
 
                                        double* data, unsigned size)
 
{
 
    _channelMan->addChannelData(channel, data, size);
 
    sampleCount += size;
 
}
 

	
 
void BinaryStreamReader::saveSettings(QSettings* settings)
 
{
 
    _settingsWidget.saveSettings(settings);
 
}
 

	
 
void BinaryStreamReader::loadSettings(QSettings* settings)
src/binarystreamreader.h
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -62,15 +62,12 @@ private:
 
     *
 
     * @note Device should already have enough bytes present before
 
     * calling this function.
 
     */
 
    template<typename T> double readSampleAs();
 

	
 
    // `data` contains i th channels data
 
    void addChannelData(unsigned int channel, double* data, unsigned size);
 

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

	
src/channelmanager.cpp
Show inline comments
 
@@ -158,15 +158,21 @@ void ChannelManager::onChannelInfoChange
 
            }
 
        }
 
        // emit channelNameChanged(i, channelName(i));
 
    }
 
}
 

	
 
void ChannelManager::addChannelData(unsigned channel, double* data, unsigned size)
 
void ChannelManager::addData(double* data, unsigned size)
 
{
 
    channelBuffer(channel)->addSamples(data, size);
 
    Q_ASSERT(size % _numOfChannels == 0);
 

	
 
    int n = size / _numOfChannels;
 
    for (unsigned ci = 0; ci < _numOfChannels; ci++)
 
    {
 
        channelBuffers[ci]->addSamples(&data[ci*n], n);
 
    }
 
}
 

	
 
void ChannelManager::saveSettings(QSettings* settings)
 
{
 
    _infoModel.saveSettings(settings);
 
}
src/channelmanager.h
Show inline comments
 
@@ -55,13 +55,24 @@ signals:
 
    void numOfSamplesChanged(unsigned value);
 
    void channelNameChanged(unsigned channel, QString name);
 

	
 
public slots:
 
    void setNumOfChannels(unsigned number);
 
    void setNumOfSamples(unsigned number);
 
    void addChannelData(unsigned channel, double* data, unsigned size);
 
    /**
 
     * Add data for all channels.
 
     *
 
     * All channels data is provided in a single array which contains equal
 
     * number of samples for all channels. Structure is as shown below:
 
     *
 
     * [CH0_SMP0, CH0_SMP1 ... CH0_SMPN, CH1_SMP0, CH1_SMP1, ... , CHN_SMPN]
 
     *
 
     * @param data samples for all channels
 
     * @param size size of `data`, must be multiple of `numOfChannels`
 
     */
 
    void addData(double* data, unsigned size);
 

	
 
private:
 
    unsigned _numOfChannels;
 
    unsigned _numOfSamples;
 
    QList<FrameBuffer*> channelBuffers;
 
    // QStringListModel _channelNames;
src/demoreader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -73,16 +73,18 @@ void DemoReader::demoTimerTimeout()
 
    const double period = 100;
 
    count++;
 
    if (count >= 100) count = 0;
 

	
 
    if (!paused)
 
    {
 
        double* samples = new double[_numOfChannels];
 
        for (unsigned ci = 0; ci < _numOfChannels; ci++)
 
        {
 
            // we are calculating the fourier components of square wave
 
            double value = 4*sin(2*M_PI*double((ci+1)*count)/period)/((2*(ci+1))*M_PI);
 
            _channelMan->addChannelData(ci, &value, 1);
 
            samples[ci] = 4*sin(2*M_PI*double((ci+1)*count)/period)/((2*(ci+1))*M_PI);
 
            sampleCount++;
 
        }
 
        _channelMan->addData(samples, _numOfChannels);
 
        delete[] samples;
 
        emit dataAdded();
 
    }
 
}
src/framedreader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 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
 
@@ -307,20 +307,13 @@ void FramedReader::readFrameDataAndCheck
 
        checksumPassed = (calcChecksum == rChecksum);
 
    }
 

	
 
    if (!checksumEnabled || checksumPassed)
 
    {
 
        // commit data
 
        for (unsigned int ci = 0; ci < _numOfChannels; ci++)
 
        {
 
            _channelMan->addChannelData(
 
                ci,
 
                channelSamples + ci*numOfPackagesToRead,
 
                numOfPackagesToRead);
 
            sampleCount += numOfPackagesToRead;
 
        }
 
        _channelMan->addData(channelSamples, numOfPackagesToRead * _numOfChannels);
 
        emit dataAdded();
 
    }
 
    else
 
    {
 
        qCritical() << "Checksum failed! Received:" << rChecksum << "Calculated:" << calcChecksum;
 
    }
src/mainwindow.cpp
Show inline comments
 
@@ -146,12 +146,13 @@ MainWindow::MainWindow(QWidget *parent) 
 
                     plotMan, &PlotManager::flashSnapshotOverlay);
 

	
 
    // init port signals
 
    QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)),
 
                     this, SLOT(onPortError(QSerialPort::SerialPortError)));
 

	
 
    // TODO: `replot` must be triggered from ChannelManager
 
    // init data format and reader
 
    QObject::connect(&dataFormatPanel, &DataFormatPanel::dataAdded,
 
                     plotMan, &PlotManager::replot);
 

	
 
    QObject::connect(ui->actionPause, &QAction::triggered,
 
                     &dataFormatPanel, &DataFormatPanel::pause);
0 comments (0 inline, 0 general)