Changeset - 87f05e438f7f
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-11-07 14:56:52
hy@ozderya.net
when paused preserve 'package' synchronization
1 file changed with 9 insertions and 9 deletions:
0 comments (0 inline, 0 general)
dataformatpanel.cpp
Show inline comments
 
@@ -202,46 +202,46 @@ void DataFormatPanel::demoTimerTimeout()
 
        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)*demoCount)/period)/((2*(ci+1))*M_PI);
 
            addChannelData(ci, &value, 1);
 
        }
 
        emit dataAdded();
 
    }
 
}
 

	
 
void DataFormatPanel::onDataReady()
 
{
 
    // TODO: discard data in the size of packageSize
 
    if (paused)
 
    {
 
        serialPort->clear(QSerialPort::Input);
 
        return;
 
    }
 

	
 
    // a package is a set of channel data like {CHAN0_SAMPLE, CHAN1_SAMPLE...}
 
    int packageSize = sampleSize * _numOfChannels;
 
    int bytesAvailable = serialPort->bytesAvailable();
 
    int numOfPackagesToRead =
 
        (bytesAvailable - (bytesAvailable % packageSize)) / packageSize;
 

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

	
 
    if (bytesAvailable > 0 && skipByteRequested)
 
    {
 
        serialPort->read(1);
 
        skipByteRequested = false;
 
        bytesAvailable--;
 
    }
 

	
 
    if (bytesAvailable < packageSize) return;
 

	
 
    int numOfPackagesToRead =
 
        (bytesAvailable - (bytesAvailable % packageSize)) / packageSize;
 
    double* channelSamples = new double[numOfPackagesToRead*_numOfChannels];
 

	
 
    for (int i = 0; i < numOfPackagesToRead; i++)
 
    {
 
        for (unsigned int ci = 0; ci < _numOfChannels; ci++)
 
        {
 
            // channelSamples[ci].replace(i, (this->*readSample)());
 
            channelSamples[ci*numOfPackagesToRead+i] = (this->*readSample)();
 
        }
 
    }
 

	
 
    for (unsigned int ci = 0; ci < _numOfChannels; ci++)
0 comments (0 inline, 0 general)