From 545f258b8ee9ab61920370d09f8464398a0a3349 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Wed, 8 Nov 2017 21:20:17 -0500 Subject: [PATCH] Make sent frames have a timestamp resolution of microseconds just like incoming frames. Previously sent frame time stamps were rounded to the nearest millisecond. Note, however, that this time stamp is when we first tried to send the frame to hardware, not when the hardware sent the frame. That will probably be later on but there's no way to know for sure if/when it will send the frame. --- connections/canconmanager.cpp | 12 ++++++++++-- connections/canconmanager.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/connections/canconmanager.cpp b/connections/canconmanager.cpp index e9c3736..b3428a3 100644 --- a/connections/canconmanager.cpp +++ b/connections/canconmanager.cpp @@ -36,6 +36,7 @@ CANConManager::CANConManager(QObject *parent): QObject(parent) void CANConManager::resetTimeBasis() { mTimestampBasis = QDateTime::currentMSecsSinceEpoch() * 1000; + mElapsedTimer.restart(); } CANConManager::~CANConManager() @@ -182,8 +183,15 @@ bool CANConManager::sendFrame(const CANFrame& pFrame) { workingFrame.bus -= busBase; workingFrame.isReceived = false; - workingFrame.timestamp = (QDateTime::currentMSecsSinceEpoch() * 1000); - if (!useSystemTime) workingFrame.timestamp -= mTimestampBasis; + if (useSystemTime) + { + workingFrame.timestamp = (QDateTime::currentMSecsSinceEpoch() * 1000); + } + else + { + workingFrame.timestamp = mElapsedTimer.nsecsElapsed() / 1000; + //workingFrame.timestamp -= mTimestampBasis; + } txFrame = conn->getQueue().get(); *txFrame = workingFrame; conn->getQueue().queue(); diff --git a/connections/canconmanager.h b/connections/canconmanager.h index 7d82bb2..26c6c76 100644 --- a/connections/canconmanager.h +++ b/connections/canconmanager.h @@ -3,6 +3,7 @@ #include #include +#include #include "canconnection.h" @@ -73,6 +74,7 @@ private: static CANConManager* mInstance; QList mConns; QTimer mTimer; + QElapsedTimer mElapsedTimer; uint64_t mTimestampBasis; uint32_t mNumActiveBuses; bool useSystemTime;