From 5d1c35a1143bac430b3b6c863c0348effe9f32be Mon Sep 17 00:00:00 2001 From: Vladyslav Goncharuk Date: Thu, 16 Nov 2023 17:02:41 +0200 Subject: [PATCH] [ISSUE #188][FILES_VIEW] Update implementation of the 'CDLTFileItem::updateIndex' Change description: - Updated implementation of the 'CDLTFileItem::updateIndex' - Added nullptr check to the CMTAnalyzer - Fixed warning with the missing parameter in QString::arg call ---- Verification criteria: - Fix was verified on the Linux Signed-off-by: Vladyslav Goncharuk --- .../src/common/PlotDefinitions.cpp | 2 +- .../components/analyzer/src/CMTAnalyzer.cpp | 23 ++-- .../logsWrapper/src/CDLTFileWrapper.cpp | 101 ++++++++++++++---- .../searchView/src/CSearchResultView.cpp | 2 +- 4 files changed, 98 insertions(+), 30 deletions(-) diff --git a/dltmessageanalyzerplugin/src/common/PlotDefinitions.cpp b/dltmessageanalyzerplugin/src/common/PlotDefinitions.cpp index 151cd2fa..ebdef52c 100644 --- a/dltmessageanalyzerplugin/src/common/PlotDefinitions.cpp +++ b/dltmessageanalyzerplugin/src/common/PlotDefinitions.cpp @@ -720,7 +720,7 @@ static tPlotViewIDsMap createPlotIDsMap() item.id_type = ePlotViewIDType::e_Mandatory_Gantt; item.id_str = s_PLOT_GANTT_EVENT; formGanttParameters(item); - item.description = QString("Declares event of a certain type ( either \"start\" or \"end\" ). " + item.description = QString("Declares event of a certain type ( either \"start\" or \"end\" ). %1." "Used to identify start and end points of different events, which should " "be represented on the Gantt chart. " "Mandatory. One or more.").arg(item.getParametersDescription()); diff --git a/dltmessageanalyzerplugin/src/components/analyzer/src/CMTAnalyzer.cpp b/dltmessageanalyzerplugin/src/components/analyzer/src/CMTAnalyzer.cpp index d5a063e2..14042973 100644 --- a/dltmessageanalyzerplugin/src/components/analyzer/src/CMTAnalyzer.cpp +++ b/dltmessageanalyzerplugin/src/components/analyzer/src/CMTAnalyzer.cpp @@ -198,19 +198,22 @@ bool CMTAnalyzer::regexAnalysisIteration(tRequestMap::iterator& inputIt, const t auto pStringData = getDataStrFromMsg(msgIdx, pMsg, *iter); - pStr->append(*pStringData); - newRangeCounter += pStringData->size() - 1; - - if (std::next(iter) != searchColumnsSet.end()) + if(nullptr != pStringData) { - pStr->append(" "); - newRangeCounter += 2; - } + pStr->append(*pStringData); + newRangeCounter += pStringData->size() - 1; + + if (std::next(iter) != searchColumnsSet.end()) + { + pStr->append(" "); + newRangeCounter += 2; + } - tIntRange strRange(rangeCounter, rangeCounter + pStringData->size() - 1); - fieldRanges.insert(*iter, strRange); + tIntRange strRange(rangeCounter, rangeCounter + pStringData->size() - 1); + fieldRanges.insert(*iter, strRange); - rangeCounter = newRangeCounter; + rangeCounter = newRangeCounter; + } } tItemMetadata itemMetadata( msgIdx, diff --git a/dltmessageanalyzerplugin/src/components/logsWrapper/src/CDLTFileWrapper.cpp b/dltmessageanalyzerplugin/src/components/logsWrapper/src/CDLTFileWrapper.cpp index 9ba723cc..c26b1844 100644 --- a/dltmessageanalyzerplugin/src/components/logsWrapper/src/CDLTFileWrapper.cpp +++ b/dltmessageanalyzerplugin/src/components/logsWrapper/src/CDLTFileWrapper.cpp @@ -767,6 +767,10 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex() QByteArray buf; qint64 pos = 0; + quint16 last_message_length = 0; + quint8 version=1; + qint64 lengthOffset=2; + qint64 storageLength=0; /* open file */ if(false == mInfile.isOpen()) @@ -784,7 +788,39 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex() { /* move behind last found position */ const QVector* const_indexAll = &(mIndexAll); - pos = (*const_indexAll)[mIndexAll.size()-1] + 4; + pos = (*const_indexAll)[mIndexAll.size()-1]; + + // first move to beginnng of last found message + mInfile.seek(pos); + + // read and get file storage length + buf = mInfile.read(14); + if(((unsigned char)buf.at(3))==2) + { + storageLength = 14 + ((unsigned char)buf.at(13)); + } + else + { + storageLength = 16; + } + + // read and get last message length + mInfile.seek(pos + storageLength); + buf = mInfile.read(7); + version = (((unsigned char)buf.at(0))&0xe0)>>5; + if(version==2) + { + lengthOffset = 5; + } + else + { + lengthOffset = 2; // default + } + last_message_length = (unsigned char)buf.at(lengthOffset); // was 0 + last_message_length = (last_message_length<<8 | ((unsigned char)buf.at(lengthOffset+1))) + storageLength; // was 1 + + // move just behind the next expected message + pos += (last_message_length - 1); mInfile.seek(pos); } else { @@ -807,6 +843,7 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex() while(true) { + /* read buffer from file */ buf = mInfile.read(READ_BUF_SZ); if(buf.isEmpty()) @@ -822,16 +859,37 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex() if(counter_header>0) { counter_header++; - if (counter_header==16) + if(storageLength==13 && counter_header==13) + { + storageLength += ((unsigned char)cbuf[num]) + 1; + } + else if (counter_header==storageLength) + { + // Read DLT protocol version + version = (((unsigned char)cbuf[num])&0xe0)>>5; + if(version==1) + { + lengthOffset = 2; + } + else if(version==2) + { + lengthOffset = 5; + } + else + { + lengthOffset = 2; // default + } + } + else if (counter_header==(storageLength+lengthOffset)) // was 16 { // Read low byte of message length - message_length = static_cast(cbuf[num]); + message_length = (unsigned char)cbuf[num]; } - else if (counter_header==17) + else if (counter_header==(storageLength+1+lengthOffset)) // was 17 { // Read high byte of message length counter_header = 0; - message_length = static_cast((message_length<<8 | (static_cast(cbuf[num]))) + 16); + message_length = (message_length<<8 | ((unsigned char)cbuf[num])) + storageLength; next_message_pos = current_message_pos + message_length; if(next_message_pos==file_size) { @@ -840,11 +898,11 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex() break; } // speed up move directly to next message, if inside current buffer - if((message_length > 20)) + if((message_length > storageLength+2+lengthOffset)) // was 20 { - if((num+message_length-20 (pos+num-3)) @@ -920,7 +986,6 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex() } mInfile.close(); - bResult = true; } } diff --git a/dltmessageanalyzerplugin/src/components/searchView/src/CSearchResultView.cpp b/dltmessageanalyzerplugin/src/components/searchView/src/CSearchResultView.cpp index d0477fc7..7491bcb1 100644 --- a/dltmessageanalyzerplugin/src/components/searchView/src/CSearchResultView.cpp +++ b/dltmessageanalyzerplugin/src/components/searchView/src/CSearchResultView.cpp @@ -907,7 +907,7 @@ void CSearchResultView::copyMessageFiles() else if(selectedRowsSize == 1) { auto selectedRowModelIdx = selectedRows.front(); - auto selectedRowIdx = selectedRowModelIdx.sibling(selectedRowModelIdx.row(), static_cast(eSearchResultColumn::UML_Applicability)).data().value(); + auto selectedRowIdx = selectedRowModelIdx.sibling(selectedRowModelIdx.row(), static_cast(eSearchResultColumn::Index)).data().value(); mpFile->copyFileNameToClipboard(selectedRowIdx); }