diff --git a/canframemodel.cpp b/canframemodel.cpp index 07e2869..985e7c2 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "utility.h" @@ -91,6 +92,16 @@ void CANFrameModel::setSecondsMode(bool mode) } } +void CANFrameModel::setSysTimeMode(bool mode) +{ + if (useSystemTime != mode) + { + this->beginResetModel(); + useSystemTime = mode; + this->endResetModel(); + } +} + void CANFrameModel::setInterpetMode(bool mode) { //if the state of interpretFrames changes then we need to reset the model @@ -237,8 +248,11 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const switch (index.column()) { case 0: //timestamp - if (!timeSeconds) return QString::number(thisFrame.timestamp); - else return QString::number((double)thisFrame.timestamp / 1000000.0, 'f', 6); + if (!useSystemTime) { + if (!timeSeconds) return QString::number(thisFrame.timestamp); + else return QString::number((double)thisFrame.timestamp / 1000000.0, 'f', 6); + } + else return QDateTime::fromMSecsSinceEpoch(thisFrame.timestamp / 1000).toString("MMM-dd HH:mm:ss.zzz"); break; case 1: //id return Utility::formatNumber(thisFrame.ID); diff --git a/canframemodel.h b/canframemodel.h index ba36746..a934eff 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -23,7 +23,7 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; int columnCount(const QModelIndex &) const; - int totalFrameCount(); + int totalFrameCount(); void sendRefresh(); void sendRefresh(int); @@ -32,6 +32,7 @@ public: void setInterpetMode(bool); void setOverwriteMode(bool); void setHexMode(bool); + void setSysTimeMode(bool); void setFilterState(unsigned int ID, bool state); void setAllFilters(bool state); void setSecondsMode(bool); @@ -63,6 +64,7 @@ private: bool overwriteDups; //should we display all frames or only the newest for each ID? bool useHexMode; bool timeSeconds; + bool useSystemTime; bool needFilterRefresh; uint64_t timeOffset; int lastUpdateNumFrames; diff --git a/config.h b/config.h index a9b6119..3967ab2 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 169 +#define VERSION 170 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/connections/canconmanager.cpp b/connections/canconmanager.cpp index 4484906..ef099c2 100644 --- a/connections/canconmanager.cpp +++ b/connections/canconmanager.cpp @@ -1,4 +1,5 @@ #include +#include #include "canconmanager.h" @@ -24,6 +25,14 @@ CANConManager::CANConManager(QObject *parent): QObject(parent) mNumActiveBuses = 0; resetTimeBasis(); + + QSettings settings; + + if (settings.value("Main/TimeClock", false).toBool()) + { + useSystemTime = true; + } + else useSystemTime = false; } void CANConManager::resetTimeBasis() @@ -168,7 +177,8 @@ bool CANConManager::sendFrame(const CANFrame& pFrame) { workingFrame.bus -= busBase; workingFrame.isReceived = false; - workingFrame.timestamp = ((QDateTime::currentMSecsSinceEpoch() * 1000) - mTimestampBasis); + workingFrame.timestamp = (QDateTime::currentMSecsSinceEpoch() * 1000); + if (!useSystemTime) workingFrame.timestamp -= mTimestampBasis; txFrame = conn->getQueue().get(); *txFrame = workingFrame; conn->getQueue().queue(); diff --git a/connections/canconmanager.h b/connections/canconmanager.h index 0918358..1056f5b 100644 --- a/connections/canconmanager.h +++ b/connections/canconmanager.h @@ -74,6 +74,7 @@ private: QTimer mTimer; uint64_t mTimestampBasis; uint32_t mNumActiveBuses; + bool useSystemTime; }; #endif // CANCONNECTIONMODEL_H diff --git a/connections/canconnection.cpp b/connections/canconnection.cpp index 1575492..049468e 100644 --- a/connections/canconnection.cpp +++ b/connections/canconnection.cpp @@ -1,3 +1,4 @@ +#include #include #include "canconnection.h" @@ -79,6 +80,14 @@ void CANConnection::start() /* set started flag */ mStarted = true; + QSettings settings; + + if (settings.value("Main/TimeClock", false).toBool()) + { + useSystemTime = true; + } + else useSystemTime = false; + /* in multithread case, this will be called before entering thread event loop */ return piStarted(); } diff --git a/connections/canconnection.h b/connections/canconnection.h index aaf7d9f..c659cab 100644 --- a/connections/canconnection.h +++ b/connections/canconnection.h @@ -237,6 +237,7 @@ protected: void setCapSuspended(bool pIsSuspended); protected: + bool useSystemTime; /**************************************************************/ /*********** protected interface to implement *******/ diff --git a/connections/gvretserial.cpp b/connections/gvretserial.cpp index ffcb5dd..b8f24c6 100644 --- a/connections/gvretserial.cpp +++ b/connections/gvretserial.cpp @@ -400,6 +400,10 @@ void GVRetSerial::procRXChar(unsigned char c) buildFrame.timestamp |= (uint)c << 24; buildFrame.timestamp += timeBasis; + if (useSystemTime) + { + buildFrame.timestamp = QDateTime::currentMSecsSinceEpoch() * 1000l; + } break; case 4: buildFrame.ID = c; diff --git a/connections/socketcan.cpp b/connections/socketcan.cpp index a653c27..63e7b4a 100644 --- a/connections/socketcan.cpp +++ b/connections/socketcan.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "socketcan.h" @@ -189,7 +190,10 @@ void SocketCan::framesReceived() frame_p->extended = false; frame_p->ID = recFrame.frameId(); frame_p->isReceived = true; - frame_p->timestamp = (recFrame.timeStamp().seconds()*1000000 + recFrame.timeStamp().microSeconds()) - timeBasis; + if (useSystemTime) { + frame_p->timestamp = QDateTime::currentMSecsSinceEpoch() * 1000ul; + } + else frame_p->timestamp = (recFrame.timeStamp().seconds() * 1000000ul + recFrame.timeStamp().microSeconds()) - timeBasis; checkTargettedFrame(*frame_p); diff --git a/mainsettingsdialog.cpp b/mainsettingsdialog.cpp index a4671cc..caa242a 100644 --- a/mainsettingsdialog.cpp +++ b/mainsettingsdialog.cpp @@ -26,7 +26,31 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : ui->cbRestorePositions->setChecked(settings->value("Main/SaveRestorePositions", true).toBool()); ui->cbValidate->setChecked(settings->value("Main/ValidateComm", true).toBool()); ui->spinPlaybackSpeed->setValue(settings->value("Playback/DefSpeed", 5).toInt()); - ui->cbTimeSeconds->setChecked(settings->value("Main/TimeSeconds", false).toBool()); + + bool secondsMode = settings->value("Main/TimeSeconds", false).toBool(); + bool clockMode = settings->value("Main/TimeClock", false).toBool(); + if (clockMode) + { + ui->rbSeconds->setChecked(false); + ui->rbMicros->setChecked(false); + ui->rbSysClock->setChecked(true); + } + else + { + if (secondsMode) + { + ui->rbSeconds->setChecked(true); + ui->rbMicros->setChecked(false); + ui->rbSysClock->setChecked(false); + } + else + { + ui->rbSeconds->setChecked(false); + ui->rbMicros->setChecked(true); + ui->rbSysClock->setChecked(false); + } + } + ui->comboSendingBus->setCurrentIndex(settings->value("Playback/SendingBus", 4).toInt()); ui->cbUseFiltered->setChecked(settings->value("Main/UseFiltered", false).toBool()); @@ -40,7 +64,9 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : connect(ui->cbRestorePositions, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->cbValidate, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->spinPlaybackSpeed, SIGNAL(valueChanged(int)), this, SLOT(updateSettings())); - connect(ui->cbTimeSeconds, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->rbSeconds, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->rbMicros, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->rbSysClock, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->comboSendingBus, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSettings())); connect(ui->cbUseFiltered, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); } @@ -68,7 +94,8 @@ void MainSettingsDialog::updateSettings() settings->setValue("Main/SaveRestorePositions", ui->cbRestorePositions->isChecked()); settings->setValue("Main/ValidateComm", ui->cbValidate->isChecked()); settings->setValue("Playback/DefSpeed", ui->spinPlaybackSpeed->value()); - settings->setValue("Main/TimeSeconds", ui->cbTimeSeconds->isChecked()); + settings->setValue("Main/TimeSeconds", ui->rbSeconds->isChecked()); + settings->setValue("Main/TimeClock", ui->rbSysClock->isChecked()); settings->setValue("Playback/SendingBus", ui->comboSendingBus->currentIndex()); settings->setValue("Main/UseFiltered", ui->cbUseFiltered->isChecked()); diff --git a/mainwindow.cpp b/mainwindow.cpp index b4b9778..da2d0b4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -52,13 +52,13 @@ MainWindow::MainWindow(QWidget *parent) : readSettings(); - ui->canFramesView->setColumnWidth(0, 110); + ui->canFramesView->setColumnWidth(0, 150); ui->canFramesView->setColumnWidth(1, 70); ui->canFramesView->setColumnWidth(2, 40); ui->canFramesView->setColumnWidth(3, 40); ui->canFramesView->setColumnWidth(4, 40); ui->canFramesView->setColumnWidth(5, 40); - ui->canFramesView->setColumnWidth(6, 275); + ui->canFramesView->setColumnWidth(6, 225); QHeaderView *HorzHdr = ui->canFramesView->horizontalHeader(); HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview @@ -256,19 +256,6 @@ void MainWindow::readSettings() ui->cbAutoScroll->setChecked(true); } - /* - int cType = settings.value("Main/DefaultConnectionType", 0).toInt(); - if (cType == 0) connType = "GVRET"; - if (cType == 1) connType = "KVASER"; - if (cType == 2) connType = "SOCKETCAN"; - portName = settings.value("Main/DefaultConnectionPort", "").toString(); - */ - - //qDebug() << connType; - //qDebug() << portName; - - //"Main/SingleWireMode" - readUpdateableSettings(); } @@ -280,6 +267,8 @@ void MainWindow::readUpdateableSettings() Utility::decimalMode = !useHex; secondsMode = settings.value("Main/TimeSeconds", false).toBool(); model->setSecondsMode(secondsMode); + useSystemClock = settings.value("Main/TimeClock", false).toBool(); + model->setSysTimeMode(useSystemClock); useFiltered = settings.value("Main/UseFiltered", false).toBool(); } diff --git a/mainwindow.h b/mainwindow.h index 4a03275..a75c9c6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -126,6 +126,7 @@ private: bool useHex; bool allowCapture; bool secondsMode; + bool useSystemClock; bool bDirty; //have frames been added or subtracted since the last save/load? bool useFiltered; //should sub-windows use the unfiltered or filtered frames list? diff --git a/ui/mainsettingsdialog.ui b/ui/mainsettingsdialog.ui index b7f15a3..b1f38d9 100644 --- a/ui/mainsettingsdialog.ui +++ b/ui/mainsettingsdialog.ui @@ -7,7 +7,7 @@ 0 0 400 - 580 + 687 @@ -42,10 +42,57 @@ - - - Display time in seconds + + + Time Keeping + + + + + Seconds/Microseconds are dongle based + + + + + + + + + Seconds + + + + + + + Microseconds + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + System Clock + + + + + +