From 1b61ae6e2658a39217a9d820c53717fc7156d9aa Mon Sep 17 00:00:00 2001 From: Superwofy Date: Fri, 21 Jun 2024 12:55:26 +0100 Subject: [PATCH] Added/corrected timestamps for LAWICEL protocol. Fixed System Clock timestamps and added decoding for timestamps coming from the tool. --- connections/lawicel_serial.cpp | 21 ++++++++++++++++++++- connections/lawicel_serial.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/connections/lawicel_serial.cpp b/connections/lawicel_serial.cpp index 34b4fd4f..ddf9e4dd 100644 --- a/connections/lawicel_serial.cpp +++ b/connections/lawicel_serial.cpp @@ -491,7 +491,26 @@ void LAWICELSerial::readSerialData() { qDebug() << "Got CR!"; - buildFrame.setTimeStamp(QDateTime::currentMSecsSinceEpoch() * 1000l); + if (useSystemTime) + { + buildTimestamp = QDateTime::currentMSecsSinceEpoch() * 1000l; + } + else + { + //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)) + { + //Four bytes after the end of the data bytes. + buildTimestamp = mBuildLine.mid(5 + mBuildLine.mid(4, 1).toInt() * 2, 4).toInt(nullptr, 16) * 1000l; + } + else + { + //Default to system time if timestamps are disabled. + buildTimestamp = QDateTime::currentMSecsSinceEpoch() * 1000l; + } + } + buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, buildTimestamp)); + switch (mBuildLine[0].toLatin1()) { case 't': //standard frame diff --git a/connections/lawicel_serial.h b/connections/lawicel_serial.h index 3d32a886..cfee96db 100644 --- a/connections/lawicel_serial.h +++ b/connections/lawicel_serial.h @@ -61,6 +61,7 @@ private slots: QSerialPort *serial; int framesRapid; CANFrame buildFrame; + qint64 buildTimestamp; bool can0Enabled; bool can0ListenOnly; bool canFd;