Switched up the way time stamp formatting is done. Now tracked by an

enum for easier determination. Also changed graphing window to respect
"system clock" style timestamps and display them properly.
This commit is contained in:
Collin Kidder
2023-03-15 19:50:58 -04:00
parent 1e0cd3c14d
commit 39b43ebf38
9 changed files with 69 additions and 61 deletions
+6 -25
View File
@@ -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());
+3 -5
View File
@@ -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;
+1 -1
View File
@@ -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
+11 -6
View File
@@ -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();
-3
View File
@@ -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?
+24 -6
View File
@@ -3,6 +3,7 @@
#include "newgraphdialog.h"
#include "mainwindow.h"
#include "helpwindow.h"
#include "utility.h"
#include <QDebug>
#include <algorithm>
@@ -33,9 +34,16 @@ GraphingWindow::GraphingWindow(const QVector<CANFrame> *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<QCPAxisTickerTime> 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 &params, 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 &params, 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();
-1
View File
@@ -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;
+1 -3
View File
@@ -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;
+21 -9
View File
@@ -10,14 +10,20 @@
#include <QRect>
//#include <QDesktopWidget>
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,16 +159,22 @@ public:
static QVariant formatTimestamp(uint64_t timestamp)
{
if (!sysTimeMode) {
if (millisMode) return (double)timestamp / 1000.0;
if (!secondsMode) return (unsigned long long)(timestamp);
else
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
static QString grabAlphaNumeric(QString &input)