Changeset - b3c780eb9ede
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-07-27 16:07:51
hy@ozderya.net
remove code duplication in onDataReadyASCII
1 file changed with 11 insertions and 19 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -300,15 +300,25 @@ void MainWindow::onDataReadyASCII()
 
            return;
 
        }
 

	
 
        line = line.trimmed();
 
        auto separatedValues = line.split(',');
 

	
 
        int numReadChannels; // effective number of channels to read
 
        if (separatedValues.length() >= int(numOfChannels))
 
        {
 
            for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
            numReadChannels = numOfChannels;
 
        }
 
        else // there is missing channel data
 
        {
 
            numReadChannels = separatedValues.length();
 
            qWarning() << "Incoming data is missing data for some channels!";
 
        }
 

	
 
        // parse read line
 
        for (int ci = 0; ci < numReadChannels; ci++)
 
            {
 
                bool ok;
 
                double channelSample = separatedValues[ci].toDouble(&ok);
 
                if (ok)
 
                {
 
                    addChannelData(ci, DataArray({channelSample}));
 
@@ -316,30 +326,12 @@ void MainWindow::onDataReadyASCII()
 
                else
 
                {
 
                    qWarning() << "Data parsing error for channel: " << ci;
 
                }
 
            }
 
        }
 
        else // there is missing channel data
 
        {
 
            qWarning() << "Incoming data is missing data for some channels!";
 
            for (int ci = 0; ci < separatedValues.length(); ci++)
 
            {
 
                bool ok;
 
                double channelSample = separatedValues[ci].toDouble(&ok);
 
                if (ok)
 
                {
 
                    addChannelData(ci, DataArray({channelSample}));
 
                }
 
                else
 
                {
 
                    qWarning() << "Data parsing error for channel: " << ci;
 
                }
 
            }
 
        }
 
    }
 
}
 

	
 
void MainWindow::onPortError(QSerialPort::SerialPortError error)
 
{
 
    switch(error)
 
    {
0 comments (0 inline, 0 general)