Skip to content

Commit

Permalink
[ISSUE #188][FILES_VIEW] Update implementation of the 'CDLTFileItem::…
Browse files Browse the repository at this point in the history
…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 <vladyslav_goncharuk@epam.com>
  • Loading branch information
Vladyslav Goncharuk committed Nov 16, 2023
1 parent 673c99b commit 5d1c35a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dltmessageanalyzerplugin/src/common/PlotDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -784,7 +788,39 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex()
{
/* move behind last found position */
const QVector<qint64>* 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 {
Expand All @@ -807,6 +843,7 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex()

while(true)
{

/* read buffer from file */
buf = mInfile.read(READ_BUF_SZ);
if(buf.isEmpty())
Expand All @@ -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<unsigned char>(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<quint16>((message_length<<8 | (static_cast<unsigned char>(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)
{
Expand All @@ -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<cbuf_sz))
if((num+message_length-(storageLength+2+lengthOffset)<cbuf_sz)) // was 20
{
num+=message_length-20;
num+=message_length-(storageLength+2+lengthOffset); // was 20
}
}
}
Expand All @@ -861,36 +919,44 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex()
{
lastFound = 'T';
}
else if(lastFound == 'T' && cbuf[num] == 0x01)
else if(lastFound == 'T' && (cbuf[num] == 0x01 || cbuf[num] == 0x02))
{
if(next_message_pos == 0)
{
// first message detected or first message after error
current_message_pos = pos+num-3;
counter_header = 1;
counter_header = 3;
if(cbuf[num] == 0x01)
storageLength = 16;
else
storageLength = 13;
if(current_message_pos!=0)
{
// first messages not at beginning or error occured before
errors_in_file++;
}
// speed up move directly to message length, if inside current buffer
if(num+14<cbuf_sz)
if(num+9<cbuf_sz)
{
num+=14;
counter_header+=14;
num+=9;
counter_header+=9;
}
}
else if( next_message_pos == (pos+num-3) )
{
// Add message only when it is in the correct position in relationship to the last message
mIndexAll.append(current_message_pos);
current_message_pos = pos+num-3;
counter_header = 1;
counter_header = 3;
if(cbuf[num] == 0x01)
storageLength = 16;
else
storageLength = 13;
// speed up move directly to message length, if inside current buffer
if(num+14<cbuf_sz)
if(num+9<cbuf_sz)
{
num+=14;
counter_header+=14;
num+=9;
counter_header+=9;
}
}
else if(next_message_pos > (pos+num-3))
Expand Down Expand Up @@ -920,7 +986,6 @@ bool CDLTFileWrapper::CSubFilesHandler::CDLTFileItem::updateIndex()
}

mInfile.close();

bResult = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void CSearchResultView::copyMessageFiles()
else if(selectedRowsSize == 1)
{
auto selectedRowModelIdx = selectedRows.front();
auto selectedRowIdx = selectedRowModelIdx.sibling(selectedRowModelIdx.row(), static_cast<int>(eSearchResultColumn::UML_Applicability)).data().value<int>();
auto selectedRowIdx = selectedRowModelIdx.sibling(selectedRowModelIdx.row(), static_cast<int>(eSearchResultColumn::Index)).data().value<int>();

mpFile->copyFileNameToClipboard(selectedRowIdx);
}
Expand Down

0 comments on commit 5d1c35a

Please sign in to comment.