diff --git a/canframemodel.cpp b/canframemodel.cpp index e02d425..ef2ccf8 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -76,7 +76,7 @@ CANFrameModel::CANFrameModel(QObject *parent) overwriteDups = false; filtersPersistDuringClear = false; useHexMode = true; - timeSeconds = false; + timeStyle = TS_MICROS; timeOffset = 0; needFilterRefresh = false; lastUpdateNumFrames = 0; @@ -101,32 +101,13 @@ void CANFrameModel::setHexMode(bool mode) } } -void CANFrameModel::setSecondsMode(bool mode) +void CANFrameModel::setTimeStyle(TimeStyle newStyle) { - if (Utility::secondsMode != mode) + if (timeStyle != newStyle) { this->beginResetModel(); - Utility::secondsMode = mode; - this->endResetModel(); - } -} - -void CANFrameModel::setSysTimeMode(bool mode) -{ - if (Utility::sysTimeMode != mode) - { - this->beginResetModel(); - Utility::sysTimeMode = mode; - this->endResetModel(); - } -} - -void CANFrameModel::setMillisMode(bool mode) -{ - if (Utility::millisMode != mode) - { - this->beginResetModel(); - Utility::millisMode = mode; + timeStyle = newStyle; + Utility::timeStyle = newStyle; this->endResetModel(); } } @@ -487,7 +468,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const //Reformatting the output a bit with custom code if (overwriteDups) { - if (timeSeconds) return QString::number(thisFrame.timedelta / 1000000.0, 'f', 5); + if (timeStyle == TS_SECONDS) return QString::number(thisFrame.timedelta / 1000000.0, 'f', 5); return QString::number(thisFrame.timedelta); } else ts = Utility::formatTimestamp(thisFrame.timeStamp().microSeconds()); diff --git a/canframemodel.h b/canframemodel.h index df0d99c..6a6bc54 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -9,6 +9,7 @@ #include "can_structs.h" #include "dbc/dbchandler.h" #include "connections/canconnection.h" +#include "utility.h" enum class Column { TimeStamp = 0, ///< The timestamp when the frame was transmitted or received @@ -47,13 +48,11 @@ public: void setOverwriteMode(bool); void setHexMode(bool); void setClearMode(bool mode); - void setSysTimeMode(bool); - void setMillisMode(bool mode); + void setTimeStyle(TimeStyle newStyle); void setIgnoreDBCColors(bool mode); void setFilterState(unsigned int ID, bool state); void setBusFilterState(unsigned int BusID, bool state); void setAllFilters(bool state); - void setSecondsMode(bool); void setTimeFormat(QString); void setBytesPerLine(int bpl); void loadFilterFile(QString filename); @@ -93,9 +92,8 @@ private: bool overwriteDups; //should we display all frames or only the newest for each ID? bool filtersPersistDuringClear; QString timeFormat; + TimeStyle timeStyle; bool useHexMode; - bool timeSeconds; - bool useSystemTime; bool needFilterRefresh; bool ignoreDBCColors; int64_t timeOffset; diff --git a/config.h b/config.h index 01c1845..7849af8 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 212 +#define VERSION 213 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/mainwindow.cpp b/mainwindow.cpp index d52b53d..302b380 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -387,12 +387,17 @@ void MainWindow::readUpdateableSettings() useHex = settings.value("Main/UseHex", true).toBool(); model->setHexMode(useHex); Utility::decimalMode = !useHex; - secondsMode = settings.value("Main/TimeSeconds", false).toBool(); - model->setSecondsMode(secondsMode); - useSystemClock = settings.value("Main/TimeClock", false).toBool(); - model->setSysTimeMode(useSystemClock); - millisMode = settings.value("Main/TimeMillis", false).toBool(); - model->setMillisMode(millisMode); + + bool tempBool; + TimeStyle ts = TS_MICROS; + tempBool = settings.value("Main/TimeSeconds", false).toBool(); + if (tempBool) ts = TS_SECONDS; + tempBool = settings.value("Main/TimeClock", false).toBool(); + if (tempBool) ts = TS_CLOCK; + tempBool = settings.value("Main/TimeMillis", false).toBool(); + if (tempBool) ts = TS_MILLIS; + model->setTimeStyle(ts); + useFiltered = settings.value("Main/UseFiltered", false).toBool(); model->setTimeFormat(settings.value("Main/TimeFormat", "MMM-dd HH:mm:ss.zzz").toString()); ignoreDBCColors = settings.value("Main/IgnoreDBCColors", false).toBool(); diff --git a/mainwindow.h b/mainwindow.h index 24eb2da..8cee46c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -147,9 +147,6 @@ private: bool inhibitFilterUpdate; bool useHex; bool allowCapture; - bool secondsMode; - bool millisMode; - bool useSystemClock; bool ignoreDBCColors; 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/re/graphingwindow.cpp b/re/graphingwindow.cpp index b66f9a3..d6221b4 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -3,6 +3,7 @@ #include "newgraphdialog.h" #include "mainwindow.h" #include "helpwindow.h" +#include "utility.h" #include #include @@ -33,9 +34,16 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) ui->graphingView->xAxis->setLabel("Time Axis"); ui->graphingView->yAxis->setLabel("Value Axis"); ui->graphingView->xAxis->setNumberFormat("f"); - if (secondsMode) ui->graphingView->xAxis->setNumberPrecision(6); + if (Utility::timeStyle == TS_SECONDS) ui->graphingView->xAxis->setNumberPrecision(6); else ui->graphingView->xAxis->setNumberPrecision(0); + if (Utility::timeStyle == TS_CLOCK) + { + QSharedPointer timeTicker(new QCPAxisTickerTime); + timeTicker->setTimeFormat("%h:%m:%s.%z"); + ui->graphingView->xAxis->setTicker(timeTicker); + } + ui->graphingView->legend->setVisible(true); QFont legendFont = font(); legendFont.setPointSize(10); @@ -154,7 +162,7 @@ void GraphingWindow::readSettings() resize(settings.value("Graphing/WindowSize", QSize(800, 600)).toSize()); move(Utility::constrainedWindowPos(settings.value("Graphing/WindowPos", QPoint(50, 50)).toPoint())); } - secondsMode = settings.value("Main/TimeSeconds", false).toBool(); + useOpenGL = settings.value("Main/UseOpenGL", false).toBool(); } @@ -267,7 +275,7 @@ void GraphingWindow::plottableDoubleClick(QCPAbstractPlottable* plottable, int d //apply transforms to get the X axis value where we double clicked double coord = plottable->keyAxis()->pixelToCoord(event->localPos().x()); id = plottable->property("id").toInt(); - if (secondsMode) emit sendCenterTimeID(id, coord); + if (Utility::timeStyle == TS_SECONDS) emit sendCenterTimeID(id, coord); else emit sendCenterTimeID(id, coord / 1000000.0); double x, y; @@ -298,7 +306,7 @@ void GraphingWindow::gotCenterTimeID(uint32_t ID, double timestamp) QCPRange range = ui->graphingView->xAxis->range(); double offset = range.size() / 2.0; - if (!secondsMode) timestamp *= 1000000.0; //timestamp is always in seconds when being passed so convert if necessary + if (Utility::timeStyle != TS_SECONDS) timestamp *= 1000000.0; //timestamp is always in seconds when being passed so convert if necessary ui->graphingView->xAxis->setRange(timestamp - offset, timestamp + offset); ui->graphingView->replot(); } @@ -1242,10 +1250,15 @@ void GraphingWindow::appendToGraph(GraphParams ¶ms, CANFrame &frame, QVector int64_t tempVal; //64 bit temp value. tempVal = Utility::processIntegerSignal(frame.payload(), params.startBit, params.numBits, params.intelFormat, params.isSigned); //& params.mask; double xVal, yVal; - if (secondsMode) + if (Utility::timeStyle == TS_SECONDS) { xVal = ((double)(frame.timeStamp().microSeconds()) / 1000000.0 - params.xbias); } + else if (Utility::timeStyle == TS_CLOCK) + { + QDateTime dt = QDateTime::fromMSecsSinceEpoch((frame.timeStamp().microSeconds() / 1000) - params.xbias); + xVal = (dt.time().second() + dt.time().minute() * 60 + dt.time().hour() * 3600); + } else { xVal = (frame.timeStamp().microSeconds() - params.xbias); @@ -1375,10 +1388,15 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) y = (tempVal * params.scale) + params.bias; params.y.append( y ); - if (secondsMode) + if (Utility::timeStyle == TS_SECONDS) { x = (frameCache[k].timeStamp().microSeconds()) / 1000000.0; } + else if (Utility::timeStyle == TS_CLOCK) + { + QDateTime dt = QDateTime::fromMSecsSinceEpoch((frameCache[k].timeStamp().microSeconds() / 1000) - params.xbias); + x = (dt.time().msecsSinceStartOfDay() / 1000.0); + } else { x = frameCache[k].timeStamp().microSeconds(); diff --git a/re/graphingwindow.h b/re/graphingwindow.h index e1c8cac..0735153 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -102,7 +102,6 @@ private: QCPItemText *locationText; QCPItemTracer *itemTracer; bool needScaleSetup; //do we need to set x,y graphing extents? - bool secondsMode; bool useOpenGL; bool followGraphEnd; diff --git a/utility.cpp b/utility.cpp index a677427..f1b10a6 100644 --- a/utility.cpp +++ b/utility.cpp @@ -1,7 +1,5 @@ #include "utility.h" bool Utility::decimalMode = false; -bool Utility::secondsMode = true; -bool Utility::sysTimeMode = false; -bool Utility::millisMode = false; QString Utility::timeFormat = "MMM-dd HH:mm:ss.zzz"; +TimeStyle Utility::timeStyle = TS_MICROS; diff --git a/utility.h b/utility.h index d70c074..bd30f0d 100644 --- a/utility.h +++ b/utility.h @@ -10,14 +10,20 @@ #include //#include +enum TimeStyle +{ + TS_SECONDS, + TS_MICROS, + TS_MILLIS, + TS_CLOCK +}; + class Utility { public: static bool decimalMode; - static bool secondsMode; - static bool millisMode; - static bool sysTimeMode; + static TimeStyle timeStyle; static QString timeFormat; //determines whether the window position is within any available screens. If it is not we default @@ -153,15 +159,21 @@ public: static QVariant formatTimestamp(uint64_t timestamp) { - if (!sysTimeMode) { - if (millisMode) return (double)timestamp / 1000.0; - if (!secondsMode) return (unsigned long long)(timestamp); - else - { - return (double)timestamp / 1000000.0; - } + switch (timeStyle) + { + case TS_CLOCK: + return QDateTime::fromMSecsSinceEpoch(timestamp / 1000); + break; + case TS_MILLIS: + return (double)timestamp / 1000.0; + break; + case TS_MICROS: + return (unsigned long long)(timestamp); + break; + case TS_SECONDS: + return (double)timestamp / 1000000.0; + break; } - else return QDateTime::fromMSecsSinceEpoch(timestamp / 1000); } //parses the input string to grab as much of it as possible while staying alpha numeric