Fix LAWICELL timestamping bug

This commit is contained in:
Tomasz Dobrowolski
2026-03-18 11:32:11 +01:00
parent ad65cf78a8
commit 5313faff69
2 changed files with 21 additions and 15 deletions
+18 -10
View File
@@ -474,8 +474,6 @@ void LAWICELSerial::readSerialData()
QByteArray data; QByteArray data;
unsigned char c; unsigned char c;
QString debugBuild; QString debugBuild;
CANFrame buildFrame;
QByteArray buildData;
if (serial) data = serial->readAll(); if (serial) data = serial->readAll();
@@ -491,22 +489,32 @@ void LAWICELSerial::readSerialData()
{ {
qDebug() << "Got CR!"; qDebug() << "Got CR!";
CANFrame buildFrame;
QByteArray buildData;
if (useSystemTime) if (useSystemTime)
{ {
buildFrame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(QDateTime::currentMSecsSinceEpoch() * 1000ul)); buildFrame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(QDateTime::currentMSecsSinceEpoch() * 1000ul));
} }
else else
{ {
bool isFD = false;
char offset; char offset;
char len_index; char len_index;
switch(mBuildLine[0].toLatin1()) { switch(mBuildLine[0].toLatin1()) {
case 't': case 'b':
case 'd': case 'd':
isFD = true;
[[fallthrough]];
case 't':
offset = 5; offset = 5;
len_index = 4; len_index = 4;
break; break;
case 'T': case 'B':
case 'D': case 'D':
isFD = true;
[[fallthrough]];
case 'T':
offset = 10; offset = 10;
len_index = 9; len_index = 9;
break; break;
@@ -515,16 +523,16 @@ void LAWICELSerial::readSerialData()
len_index = 4; len_index = 4;
break; break;
} }
//If total length is greater than command, header and data, timestamps must be enabled. int dlc = mBuildLine.mid(len_index, 1).toInt();
if (data.length() > (offset + mBuildLine.mid(len_index, 1).toInt() * 2 + 1)) int byteCount = isFD ? (int)dlc_code_to_bytes(dlc) : dlc;
int frameStringLen = offset + byteCount * 2;
bool hasTimestamp = mBuildLine.length() > frameStringLen + 1;
if (hasTimestamp)
{ {
//Four bytes after the end of the data bytes. buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, mBuildLine.mid(frameStringLen, 4).toInt(nullptr, 16) * 1000l));
buildTimestamp = mBuildLine.mid(offset + mBuildLine.mid(len_index, 1).toInt() * 2, 4).toInt(nullptr, 16);
buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, buildTimestamp));
} }
else else
{ {
//Default to system time if timestamps are disabled.
buildFrame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(QDateTime::currentMSecsSinceEpoch() * 1000ul)); buildFrame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(QDateTime::currentMSecsSinceEpoch() * 1000ul));
} }
} }
-2
View File
@@ -60,8 +60,6 @@ protected:
bool isAutoRestart; bool isAutoRestart;
QSerialPort *serial; QSerialPort *serial;
int framesRapid; int framesRapid;
CANFrame buildFrame;
qint64 buildTimestamp;
bool can0Enabled; bool can0Enabled;
bool can0ListenOnly; bool can0ListenOnly;
bool canFd; bool canFd;