From 37e8ad5edc8a5cb70bca2c71e247f62b07001014 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Wed, 19 Jan 2022 21:34:49 -0500 Subject: [PATCH] Added two modes - millisecond timestamps for frames and a way to ignore colors set in DBC files --- canframemodel.cpp | 24 +++++++++++++++++++++-- canframemodel.h | 3 +++ mainsettingsdialog.cpp | 18 +++++++++++++++++- mainwindow.cpp | 9 +++++++++ mainwindow.h | 2 ++ ui/mainsettingsdialog.ui | 41 +++++++++++++++++++++++++++++++--------- utility.cpp | 1 + utility.h | 7 ++++++- 8 files changed, 92 insertions(+), 13 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index cf9eb93f..e053044d 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -103,6 +103,16 @@ void CANFrameModel::setSysTimeMode(bool mode) } } +void CANFrameModel::setMillisMode(bool mode) +{ + if (Utility::millisMode != mode) + { + this->beginResetModel(); + Utility::millisMode = mode; + this->endResetModel(); + } +} + void CANFrameModel::setInterpretMode(bool mode) { //if the state of interpretFrames changes then we need to reset the model @@ -127,6 +137,16 @@ void CANFrameModel::setTimeFormat(QString format) endResetModel(); } +void CANFrameModel::setIgnoreDBCColors(bool mode) +{ + if(ignoreDBCColors != mode) + { + beginResetModel(); //reset model to update the view + ignoreDBCColors = mode; + endResetModel(); + } +} + /* * Scan all frames for the smallest timestamp and offset all timestamps so that smallest one is at 0 */ @@ -385,7 +405,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const if (role == Qt::BackgroundColorRole) { - if (dbcHandler != nullptr && interpretFrames) + if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors) { DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame); if (msg != nullptr) @@ -418,7 +438,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const if (role == Qt::TextColorRole) { - if (dbcHandler != nullptr && interpretFrames) + if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors) { DBC_MESSAGE *msg = dbcHandler->findMessage(thisFrame); if (msg != nullptr) diff --git a/canframemodel.h b/canframemodel.h index 47ceed7c..edb65b59 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -47,6 +47,8 @@ class CANFrameModel: public QAbstractTableModel void setOverwriteMode(bool); void setHexMode(bool); void setSysTimeMode(bool); + void setMillisMode(bool mode); + void setIgnoreDBCColors(bool mode); void setFilterState(unsigned int ID, bool state); void setBusFilterState(unsigned int BusID, bool state); void setAllFilters(bool state); @@ -92,6 +94,7 @@ public slots: bool timeSeconds; bool useSystemTime; bool needFilterRefresh; + bool ignoreDBCColors; int64_t timeOffset; int lastUpdateNumFrames; uint32_t preallocSize; diff --git a/mainsettingsdialog.cpp b/mainsettingsdialog.cpp index ad851a39..77bf2577 100644 --- a/mainsettingsdialog.cpp +++ b/mainsettingsdialog.cpp @@ -17,7 +17,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : QSettings settings; ui->setupUi(this); - //TODO: This is still hard coded to support only two buses. Sometimes there is none, sometimes 1, sometimes much more than 2. Fix this. + //TODO: This is still hard coded to support only two buses. Sometimes there is none, sometimes 1, sometimes much more than 2. Fix this. ui->comboSendingBus->addItem(tr("None")); ui->comboSendingBus->addItem(tr("0")); ui->comboSendingBus->addItem(tr("1")); @@ -51,11 +51,13 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : bool secondsMode = settings.value("Main/TimeSeconds", false).toBool(); bool clockMode = settings.value("Main/TimeClock", false).toBool(); + bool milliMode = settings.value("Main/TimeMillis", false).toBool(); if (clockMode) { ui->rbSeconds->setChecked(false); ui->rbMicros->setChecked(false); ui->rbSysClock->setChecked(true); + ui->rbMillis->setChecked(false); } else { @@ -64,12 +66,21 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : ui->rbSeconds->setChecked(true); ui->rbMicros->setChecked(false); ui->rbSysClock->setChecked(false); + ui->rbMillis->setChecked(false); + } + else if (milliMode) + { + ui->rbSeconds->setChecked(false); + ui->rbMicros->setChecked(false); + ui->rbSysClock->setChecked(false); + ui->rbMillis->setChecked(true); } else { ui->rbSeconds->setChecked(false); ui->rbMicros->setChecked(true); ui->rbSysClock->setChecked(false); + ui->rbMillis->setChecked(false); } } @@ -77,6 +88,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : ui->cbUseFiltered->setChecked(settings.value("Main/UseFiltered", false).toBool()); ui->cbUseOpenGL->setChecked(settings.value("Main/UseOpenGL", false).toBool()); ui->cbFilterLabeling->setChecked(settings.value("Main/FilterLabeling", true).toBool()); + ui->cbIgnoreDBCColors->setChecked(settings.value("Main/IgnoreDBCColors", false).toBool()); //just for simplicity they all call the same function and that function updates all settings at once connect(ui->cbDisplayHex, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); @@ -91,6 +103,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : 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->rbMillis, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->comboSendingBus, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSettings())); connect(ui->cbUseFiltered, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->lineClockFormat, SIGNAL(editingFinished()), this, SLOT(updateSettings())); @@ -103,6 +116,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : connect(ui->cbFilterLabeling, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->cbHexGraphFlow, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->cbHexGraphInfo, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbIgnoreDBCColors, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); installEventFilter(this); } @@ -155,6 +169,7 @@ void MainSettingsDialog::updateSettings() settings.setValue("Main/ValidateComm", ui->cbValidate->isChecked()); settings.setValue("Playback/DefSpeed", ui->spinPlaybackSpeed->value()); settings.setValue("Main/TimeSeconds", ui->rbSeconds->isChecked()); + settings.setValue("Main/TimeMillis", ui->rbMillis->isChecked()); settings.setValue("Main/TimeClock", ui->rbSysClock->isChecked()); settings.setValue("Playback/SendingBus", ui->comboSendingBus->currentIndex()); settings.setValue("Main/UseFiltered", ui->cbUseFiltered->isChecked()); @@ -167,6 +182,7 @@ void MainSettingsDialog::updateSettings() QByteArray encPass = crypto.encryptToByteArray(ui->lineRemotePassword->text()); settings.setValue("Remote/Pass", encPass); settings.setValue("Main/FilterLabeling", ui->cbFilterLabeling->isChecked()); + settings.setValue("Main/IgnoreDBCColors", ui->cbIgnoreDBCColors->isChecked()); settings.sync(); emit updatedSettings(); diff --git a/mainwindow.cpp b/mainwindow.cpp index af8503d9..f32125af 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -361,6 +361,11 @@ void MainWindow::readSettings() readUpdateableSettings(); } + +/* + * TODO: The way the frame timing mode is specified is DEAD STUPID. There shouldn't be three boolean values + * for this. Instead switch it all to an ENUM or something sane. +*/ void MainWindow::readUpdateableSettings() { QSettings settings; @@ -371,8 +376,12 @@ void MainWindow::readUpdateableSettings() model->setSecondsMode(secondsMode); useSystemClock = settings.value("Main/TimeClock", false).toBool(); model->setSysTimeMode(useSystemClock); + millisMode = settings.value("Main/TimeMillis", false).toBool(); + model->setMillisMode(millisMode); 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(); + model->setIgnoreDBCColors(ignoreDBCColors); if (settings.value("Main/FilterLabeling", false).toBool()) ui->listFilters->setMaximumWidth(250); diff --git a/mainwindow.h b/mainwindow.h index f773ad59..0b0fd906 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -144,7 +144,9 @@ public slots: 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/ui/mainsettingsdialog.ui b/ui/mainsettingsdialog.ui index 1590d17f..586e4e04 100644 --- a/ui/mainsettingsdialog.ui +++ b/ui/mainsettingsdialog.ui @@ -7,7 +7,7 @@ 0 0 965 - 668 + 678 @@ -73,13 +73,6 @@ - - - - Label filters using messages from DBC files - - - @@ -96,7 +89,7 @@ - Seconds/Microseconds are dongle based + Seconds/Milli/Micro are dongle based @@ -116,6 +109,13 @@ + + + + Milliseconds + + + @@ -275,6 +275,29 @@ + + + + DBC Settings + + + + + + Label DBC Signals by default + + + + + + + Ignore DBC signal colors + + + + + + diff --git a/utility.cpp b/utility.cpp index fa1bf062..a6774272 100644 --- a/utility.cpp +++ b/utility.cpp @@ -3,4 +3,5 @@ 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"; diff --git a/utility.h b/utility.h index b050b0fc..0f31ca39 100644 --- a/utility.h +++ b/utility.h @@ -16,6 +16,7 @@ class Utility static bool decimalMode; static bool secondsMode; + static bool millisMode; static bool sysTimeMode; static QString timeFormat; @@ -148,8 +149,12 @@ class Utility 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; + else + { + return (double)timestamp / 1000000.0; + } } else return QDateTime::fromMSecsSinceEpoch(timestamp / 1000); }