fix: dynamic timestamp extraction for LAWICEL CAN frames
Fixed timestamp extraction in LAWICEL CAN frames by accounting for the CAN frame type.
This commit is contained in:
@@ -497,11 +497,29 @@ void LAWICELSerial::readSerialData()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
char offset;
|
||||||
|
char len_index;
|
||||||
|
switch(mBuildLine[0].toLatin1()) {
|
||||||
|
case 't':
|
||||||
|
case 'd':
|
||||||
|
offset = 5;
|
||||||
|
len_index = 4;
|
||||||
|
break;
|
||||||
|
case 'T':
|
||||||
|
case 'D':
|
||||||
|
offset = 10;
|
||||||
|
len_index = 9;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
offset = 5;
|
||||||
|
len_index = 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
//If total length is greater than command, header and data, timestamps must be enabled.
|
//If total length is greater than command, header and data, timestamps must be enabled.
|
||||||
if (data.length() > (5 + mBuildLine.mid(4, 1).toInt() * 2 + 1))
|
if (data.length() > (offset + mBuildLine.mid(len_index, 1).toInt() * 2 + 1))
|
||||||
{
|
{
|
||||||
//Four bytes after the end of the data bytes.
|
//Four bytes after the end of the data bytes.
|
||||||
buildTimestamp = mBuildLine.mid(5 + mBuildLine.mid(4, 1).toInt() * 2, 4).toInt(nullptr, 16) * 1000l;
|
buildTimestamp = mBuildLine.mid(offset + mBuildLine.mid(len_index, 1).toInt() * 2, 4).toInt(nullptr, 16) * 1000l;
|
||||||
buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, buildTimestamp));
|
buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, buildTimestamp));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user