Git commit cba4e74c20acb1f14410d115fb44a92ae4aad9b0 by Stefan Gerlach. Committed on 30/06/2018 at 22:08. Pushed by sgerlach into branch 'master'. [live data] fix periodically reading UDP and more debugging M +1 -1 src/backend/datasources/LiveDataSource.cpp M +45 -19 src/backend/datasources/filters/AsciiFilter.cpp https://commits.kde.org/labplot/cba4e74c20acb1f14410d115fb44a92ae4aad9b0 diff --git a/src/backend/datasources/LiveDataSource.cpp b/src/backend/datas= ources/LiveDataSource.cpp index 813a37c3..f07b57cd 100644 --- a/src/backend/datasources/LiveDataSource.cpp +++ b/src/backend/datasources/LiveDataSource.cpp @@ -503,7 +503,7 @@ QMenu* LiveDataSource::createContextMenu() { * called periodically or on new data changes (file changed, new data in t= he socket, etc.) */ void LiveDataSource::read() { - DEBUG("LiveDataSource::read()"); + DEBUG("\nLiveDataSource::read()"); if (m_filter =3D=3D nullptr) return; = diff --git a/src/backend/datasources/filters/AsciiFilter.cpp b/src/backend/= datasources/filters/AsciiFilter.cpp index cb25f9b4..2df2e50f 100644 --- a/src/backend/datasources/filters/AsciiFilter.cpp +++ b/src/backend/datasources/filters/AsciiFilter.cpp @@ -613,7 +613,7 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevice= & device, AbstractDataSou return 0; = if (!m_prepared) { - DEBUG(" Preparing .."); + DEBUG("Preparing .."); = switch (spreadsheet->sourceType()) { case LiveDataSource::SourceType::FileOrPipe: { @@ -701,7 +701,7 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevice= & device, AbstractDataSou } } = - DEBUG("prepared!"); + DEBUG("Prepared!"); } = qint64 bytesread =3D 0; @@ -724,12 +724,13 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevi= ce& device, AbstractDataSou else readingType =3D spreadsheet->readingType(); } + DEBUG(" reading type =3D " << ENUM_TO_STRING(LiveDataSource, ReadingType,= readingType)); = //move to the last read position, from =3D=3D total bytes read //since the other source types are sequencial we cannot seek on them if (spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::FileOrPi= pe) device.seek(from); - DEBUG(" bytes available: " << device.bytesAvailable()); + DEBUG(" bytes available =3D " << device.bytesAvailable()); = //count the new lines, increase actualrows on each //now we read all the new lines, if we want to use sample rate @@ -745,27 +746,37 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevi= ce& device, AbstractDataSou #ifdef PERFTRACE_LIVE_IMPORT PERFTRACE("AsciiLiveDataImportReadingFromFile: "); #endif - while (!device.atEnd()) { DEBUG(" reading type =3D " << ENUM_TO_STRING(LiveDataSource, ReadingTyp= e, readingType)); DEBUG(" source type =3D " << ENUM_TO_STRING(LiveDataSource, SourceType,= spreadsheet->sourceType())); if (readingType !=3D LiveDataSource::ReadingType::TillEnd) { - // local socket needs readAll(), UDP socket needs read(), all other ne= ed readLine() - //TODO: check serial port - if (spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::Local= Socket) + switch (spreadsheet->sourceType()) { // different sources need differe= nt read methods + case LiveDataSource::SourceType::LocalSocket: newData[newDataIdx++] =3D device.readAll(); - else if (spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::= NetworkUdpSocket) + break; + case LiveDataSource::SourceType::NetworkUdpSocket: newData[newDataIdx++] =3D device.read(device.bytesAvailable()); - else { + break; + case LiveDataSource::SourceType::FileOrPipe: + case LiveDataSource::SourceType::NetworkTcpSocket: + //TODO: check serial port + case LiveDataSource::SourceType::SerialPort: if (!device.canReadLine()) DEBUG("WARNING in AsciiFilterPrivate::readFromLiveDevice(): device c= annot 'readLine()' but using it anyway."); newData[newDataIdx++] =3D device.readLine(); } } else { // ReadingType::TillEnd - if (spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::Local= Socket - || spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::Netwo= rkUdpSocket) + switch (spreadsheet->sourceType()) { // different sources need differe= nt read methods + case LiveDataSource::SourceType::LocalSocket: newData.push_back(device.readAll()); - else { + break; + case LiveDataSource::SourceType::NetworkUdpSocket: + newData.push_back(device.read(device.bytesAvailable())); + break; + case LiveDataSource::SourceType::FileOrPipe: + case LiveDataSource::SourceType::NetworkTcpSocket: + //TODO: check serial port + case LiveDataSource::SourceType::SerialPort: if (!device.canReadLine()) DEBUG("WARNING in AsciiFilterPrivate::readFromLiveDevice(): device c= annot 'readLine()' but using it anyway."); newData.push_back(device.readLine()); @@ -787,10 +798,9 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevic= e& device, AbstractDataSou if (spreadsheet->readingType() =3D=3D LiveDataSource::ReadingType::FromEn= d) readingType =3D spreadsheet->readingType(); = - //we had less new lines than the sample rate specified + //we had less new lines than the sample size specified if (readingType !=3D LiveDataSource::ReadingType::TillEnd) - qDebug() << "Removed empty lines: " << newData.removeAll(""); - + QDEBUG("Removed empty lines: " << newData.removeAll("")); = //back to the last read position before counting when reading from files if (spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::FileOrPi= pe) @@ -801,6 +811,7 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevice= & device, AbstractDataSou int currentRow =3D 0; // indexes the position in the vector(column) int linesToRead =3D 0; = + DEBUG("Increase row count"); if (m_prepared) { //increase row count if we don't have a fixed size //but only after the preparation step @@ -815,6 +826,7 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevice= & device, AbstractDataSou m_actualRows =3D newData.size(); } } + DEBUG(" actual row =3D " << m_actualRows); = //fixed size if (spreadsheet->keepLastValues()) { @@ -846,7 +858,15 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevic= e& device, AbstractDataSou if (headerEnabled) --m_actualRows; } + DEBUG(" lines to read =3D " << linesToRead); = + //TODO: check other source types + if (spreadsheet->sourceType() =3D=3D LiveDataSource::SourceType::NetworkU= dpSocket) { + if (m_actualRows < linesToRead) { + DEBUG(" SET actual rows to " << linesToRead); + m_actualRows =3D linesToRead; + } + } = //new rows/resize columns if we don't have a fixed size //TODO if the user changes this value..m_resizedToFixedSize..setResizedTo= FixedSize @@ -1027,7 +1047,6 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevi= ce& device, AbstractDataSou } = //qDebug() << "line bytes: " << line.size() << " line: " << line; - //qDebug() << "reading in row: " << currentRow; if (simplifyWhitespacesEnabled) line =3D line.simplified(); = @@ -1051,24 +1070,30 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODe= vice& device, AbstractDataSou lineStringList.prepend(QString::number(currentRow)); } = + QDEBUG(" column modes =3D " << columnModes); for (int n =3D 0; n < m_actualCols; ++n) { + DEBUG(" actual col =3D " << n); if (n < lineStringList.size()) { QString valueString =3D lineStringList.at(n); + DEBUG(" value string =3D " << valueString.toStdString()); = // set value depending on data type switch (columnModes[n]) { case AbstractColumn::Numeric: { + DEBUG(" Numeric"); bool isNumber; const double value =3D locale.toDouble(valueString, &isNumber); static_cast*>(m_dataContainer[n])->operator[](curren= tRow) =3D (isNumber ? value : nanValue); - //qDebug() << "dataContainer[" << n << "] size:" << static_cast*>(m_dataContainer[n])->size(); + qDebug() << "dataContainer[" << n << "] size:" << static_cast*>(m_dataContainer[n])->size(); break; } case AbstractColumn::Integer: { + DEBUG(" Integer"); bool isNumber; const int value =3D locale.toInt(valueString, &isNumber); + DEBUG(" container size =3D " << m_dataContainer.size() << ", current= row =3D " << currentRow); static_cast*>(m_dataContainer[n])->operator[](currentRo= w) =3D (isNumber ? value : 0); - //qDebug() << "dataContainer[" << n << "] size:" << static_cast*>(m_dataContainer[n])->size(); + qDebug() << "dataContainer[" << n << "] size:" << static_cast*>(m_dataContainer[n])->size(); = break; } @@ -1089,7 +1114,8 @@ qint64 AsciiFilterPrivate::readFromLiveDevice(QIODevi= ce& device, AbstractDataSou //TODO break; } - } else { // missing columns in this line + } else { + DEBUG(" missing columns in this line"); switch (columnModes[n]) { case AbstractColumn::Numeric: static_cast*>(m_dataContainer[n])->operator[](curren= tRow) =3D nanValue;