From 4d4eabad7a09e45c8d234a50dd03e9d0ed1657e6 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Mon, 19 Dec 2016 21:34:22 -0500 Subject: [PATCH] Correction for GVRET time sync. Seems to be proper now (hopefully) --- connections/gvretserial.cpp | 10 ++++++---- connections/gvretserial.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/connections/gvretserial.cpp b/connections/gvretserial.cpp index b6940f0..af60a1e 100644 --- a/connections/gvretserial.cpp +++ b/connections/gvretserial.cpp @@ -20,6 +20,7 @@ GVRetSerial::GVRetSerial(QString portName) : timeBasis = 0; lastSystemTimeBasis = 0; + timeAtGVRETSync = 0; readSettings(); } @@ -445,6 +446,7 @@ void GVRetSerial::procRXChar(unsigned char c) case 3: buildTimeBasis += ((uint32_t)c << 24); qDebug() << "GVRET firmware reports timestamp of " << buildTimeBasis; + timeAtGVRETSync = QDateTime::currentMSecsSinceEpoch() * 1000; rebuildLocalTimeBasis(); @@ -578,19 +580,19 @@ void GVRetSerial::procRXChar(unsigned char c) void GVRetSerial::rebuildLocalTimeBasis() { - uint64_t currTime = QDateTime::currentMSecsSinceEpoch() * 1000; + qDebug() << "Rebuilding GVRET time base. GVRET local base = " << buildTimeBasis; /* our time basis is the value we have to modulate the main system basis by in order to sync the GVRET timestamps to the rest of the system. The rest of the system uses CANConManager::getInstance()->getTimeBasis as the basis. GVRET returns to us the current time since boot up in microseconds. - currTime stores the "system" timestamp when the GVRET timestamp was retrieved. + timeAtGVRETSync stores the "system" timestamp when the GVRET timestamp was retrieved. */ lastSystemTimeBasis = CANConManager::getInstance()->getTimeBasis(); - int64_t systemDelta = currTime - lastSystemTimeBasis; + int64_t systemDelta = timeAtGVRETSync - lastSystemTimeBasis; int32_t localDelta = buildTimeBasis - systemDelta; - timeBasis = localDelta; + timeBasis = -localDelta; } void GVRetSerial::handleTick() diff --git a/connections/gvretserial.h b/connections/gvretserial.h index 915af16..b4bfa4c 100644 --- a/connections/gvretserial.h +++ b/connections/gvretserial.h @@ -87,6 +87,7 @@ protected: uint32_t buildTimeBasis; int32_t timeBasis; uint64_t lastSystemTimeBasis; + uint64_t timeAtGVRETSync; }; #endif // GVRETSERIAL_H