From e1f06be6fdf1746f30d26da0a3c1a77d154ed2ff Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 8 Dec 2022 20:35:33 -0500 Subject: [PATCH] Added a setting that allows for limiting the number of bytes per line. This is useful if you have a 1920x1080 monitor or smaller resolution but you want to capture 64 byte payloads. The default is 8 bytes but usually 16 bytes is fine. --- canframemodel.cpp | 10 +++++++++- canframemodel.h | 2 ++ mainsettingsdialog.cpp | 5 ++++- mainwindow.cpp | 2 ++ ui/mainsettingsdialog.ui | 26 +++++++++++++++++++++++++- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/canframemodel.cpp b/canframemodel.cpp index e41eb8c..4bd04c9 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -76,6 +76,12 @@ CANFrameModel::CANFrameModel(QObject *parent) lastUpdateNumFrames = 0; timeFormat = "MMM-dd HH:mm:ss.zzz"; sortDirAsc = false; + bytesPerLine = 8; +} + +void CANFrameModel::setBytesPerLine(int bpl) +{ + bytesPerLine = bpl; } void CANFrameModel::setHexMode(bool mode) @@ -514,6 +520,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const if (byt < 0x20) byt = 0x2E; //dot character if (byt > 0x7E) byt = 0x2E; tempString.append(QString::fromUtf8(&byt, 1)); + if (!((i+1) % bytesPerLine) && (i != (dataLen - 1))) tempString.append("\n"); } } if (thisFrame.frameType() == QCanBusFrame::ErrorFrame) @@ -531,7 +538,8 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const { if (useHexMode) tempString.append( QString::number(data[i], 16).toUpper().rightJustified(2, '0')); else tempString.append(QString::number(data[i], 10)); - tempString.append(" "); + if (!((i+1) % bytesPerLine) && (i != (dataLen - 1))) tempString.append("\n"); + else tempString.append(" "); } if (thisFrame.frameType() == thisFrame.ErrorFrame) { diff --git a/canframemodel.h b/canframemodel.h index be13888..df0d99c 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -55,6 +55,7 @@ public: void setAllFilters(bool state); void setSecondsMode(bool); void setTimeFormat(QString); + void setBytesPerLine(int bpl); void loadFilterFile(QString filename); void saveFilterFile(QString filename); void normalizeTiming(); @@ -101,6 +102,7 @@ private: int lastUpdateNumFrames; uint32_t preallocSize; bool sortDirAsc; + int bytesPerLine; }; diff --git a/mainsettingsdialog.cpp b/mainsettingsdialog.cpp index 7cd1230..ef6b293 100644 --- a/mainsettingsdialog.cpp +++ b/mainsettingsdialog.cpp @@ -21,7 +21,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : ui->comboSendingBus->addItem(tr("None")); ui->comboSendingBus->addItem(tr("0")); ui->comboSendingBus->addItem(tr("1")); - ui->comboSendingBus->addItem(tr("Both")); + ui->comboSendingBus->addItem(tr("All")); ui->comboSendingBus->addItem(tr("From File")); //update the GUI with all the settings we have stored giving things @@ -104,6 +104,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : } ui->spinMaximumFrames->setValue(settings.value("Main/MaximumFrames", maxFramesDefault).toInt()); + ui->spinBytesPerLine->setValue(settings.value("Main/BytesPerLine", 8).toInt()); //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())); @@ -134,6 +135,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) : connect(ui->cbIgnoreDBCColors, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->spinMaximumFrames, SIGNAL(valueChanged(int)), this, SLOT(updateSettings())); connect(ui->cbFontFixedWidth, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->spinBytesPerLine, SIGNAL(valueChanged(int)), this, SLOT(updateSettings())); installEventFilter(this); } @@ -201,6 +203,7 @@ void MainSettingsDialog::updateSettings() settings.setValue("Main/FilterLabeling", ui->cbFilterLabeling->isChecked()); settings.setValue("Main/IgnoreDBCColors", ui->cbIgnoreDBCColors->isChecked()); settings.setValue("Main/MaximumFrames", ui->spinMaximumFrames->value()); + settings.setValue("Main/BytesPerLine", ui->spinBytesPerLine->value()); settings.setValue("Main/FontFixedWidth", ui->cbFontFixedWidth->isChecked()); settings.sync(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 6383e1e..edb17bb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -392,6 +392,8 @@ void MainWindow::readUpdateableSettings() model->setTimeFormat(settings.value("Main/TimeFormat", "MMM-dd HH:mm:ss.zzz").toString()); ignoreDBCColors = settings.value("Main/IgnoreDBCColors", false).toBool(); model->setIgnoreDBCColors(ignoreDBCColors); + int bpl = settings.value("Main/BytesPerLine", 8).toInt(); + model->setBytesPerLine(bpl); if (settings.value("Main/FilterLabeling", false).toBool()) ui->listFilters->setMaximumWidth(250); diff --git a/ui/mainsettingsdialog.ui b/ui/mainsettingsdialog.ui index cb61d4d..a034b1c 100644 --- a/ui/mainsettingsdialog.ui +++ b/ui/mainsettingsdialog.ui @@ -7,7 +7,7 @@ 0 0 965 - 713 + 815 @@ -29,6 +29,30 @@ + + + + + + Maximum data bytes per line + + + + + + + 8 + + + 64 + + + 8 + + + + +