From 5fa1bb43ef290640418c7d247fa1b430f785d83f Mon Sep 17 00:00:00 2001 From: Tomasz Dobrowolski Date: Thu, 19 Mar 2026 11:59:31 +0100 Subject: [PATCH] simplify --- connections/lawicel_serial.cpp | 18 ++++++------------ connections/lawicel_serial.h | 1 - 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/connections/lawicel_serial.cpp b/connections/lawicel_serial.cpp index 89cd27f..cfd7d5a 100644 --- a/connections/lawicel_serial.cpp +++ b/connections/lawicel_serial.cpp @@ -209,7 +209,6 @@ void LAWICELSerial::rebuildLocalTimeBasis() timeBasis = 0; lastHWTimestamp = -1; wrapAdder = 0; - lastSysMs = 0; } void LAWICELSerial::readSettings() @@ -531,22 +530,17 @@ void LAWICELSerial::readSerialData() len_index = 4; break; } + int dlc = mBuildLine.mid(len_index, 1).toInt(); int byteCount = isFD ? (int)dlc_code_to_bytes(dlc) : dlc; int frameStringLen = offset + byteCount * 2; if (mBuildLine.length() > frameStringLen + 1) { - qint64 hwTs = mBuildLine.mid(frameStringLen, 4).toInt(nullptr, 16); - qint64 sysMs = QDateTime::currentMSecsSinceEpoch(); - if (lastHWTimestamp >= 0 && hwTs < lastHWTimestamp) { - qint64 sysDelta = sysMs - lastSysMs; - wrapAdder += lastHWTimestamp + sysDelta - hwTs; - } - lastHWTimestamp = hwTs; - lastSysMs = sysMs; - qint64 unwrappedMs = wrapAdder + hwTs; - if (timeBasis == 0) - timeBasis = sysMs - unwrappedMs; + qint64 hardwareMs = mBuildLine.mid(frameStringLen, 4).toInt(nullptr, 16); + if (lastHWTimestamp >= 0 && hardwareMs < lastHWTimestamp) { wrapAdder += 60000; } + lastHWTimestamp = hardwareMs; + qint64 unwrappedMs = wrapAdder + hardwareMs; + if (timeBasis == 0) { timeBasis = QDateTime::currentMSecsSinceEpoch() - unwrappedMs; } buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, (timeBasis + unwrappedMs) * 1000ll)); } } diff --git a/connections/lawicel_serial.h b/connections/lawicel_serial.h index d137fcc..77c52c1 100644 --- a/connections/lawicel_serial.h +++ b/connections/lawicel_serial.h @@ -63,7 +63,6 @@ protected: qint64 timeBasis; qint64 lastHWTimestamp; qint64 wrapAdder; - qint64 lastSysMs; bool can0Enabled; bool can0ListenOnly; bool canFd;