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.
 

	
 
@@ -142,21 +142,24 @@ void AsciiReader::onDataReady()
 
        }
 

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

	
src/binarystreamreader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -171,12 +171,8 @@ void BinaryStreamReader::onDataReady()
 
        }
 
    }
 

	
 
    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;
 
@@ -200,13 +196,6 @@ template<typename T> double BinaryStream
 
    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);
src/binarystreamreader.h
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -65,9 +65,6 @@ private:
 
     */
 
    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);
src/channelmanager.cpp
Show inline comments
 
@@ -161,9 +161,15 @@ void ChannelManager::onChannelInfoChange
 
    }
 
}
 

	
 
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)
src/channelmanager.h
Show inline comments
 
@@ -58,7 +58,18 @@ signals:
 
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;
src/demoreader.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -76,13 +76,15 @@ void DemoReader::demoTimerTimeout()
 

	
 
    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.
 

	
 
@@ -310,14 +310,7 @@ void FramedReader::readFrameDataAndCheck
 
    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
src/mainwindow.cpp
Show inline comments
 
@@ -149,6 +149,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
    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);
0 comments (0 inline, 0 general)