Merge branch 'master' into add_nodenameinsignalviewer

This commit is contained in:
Andy Huska
2022-09-28 19:16:33 -05:00
18 changed files with 408 additions and 57 deletions
+43 -7
View File
@@ -4,6 +4,7 @@
#include <QApplication> #include <QApplication>
#include <QPalette> #include <QPalette>
#include <QDateTime> #include <QDateTime>
#include <QSettings>
#include "utility.h" #include "utility.h"
CANFrameModel::~CANFrameModel() CANFrameModel::~CANFrameModel()
@@ -45,24 +46,29 @@ int CANFrameModel::columnCount(const QModelIndex &index) const
CANFrameModel::CANFrameModel(QObject *parent) CANFrameModel::CANFrameModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
{ {
int maxFramesDefault;
if (QSysInfo::WordSize > 32) if (QSysInfo::WordSize > 32)
{ {
qDebug() << "64 bit OS detected. Requesting a large preallocation"; qDebug() << "64 bit OS detected. Requesting a large preallocation";
preallocSize = 10000000; maxFramesDefault = 10000000;
} }
else //if compiling for 32 bit you can't ask for gigabytes of preallocation so tone it down. else //if compiling for 32 bit you can't ask for gigabytes of preallocation so tone it down.
{ {
qDebug() << "32 bit OS detected. Requesting a much restricted prealloc"; qDebug() << "32 bit OS detected. Requesting a much restricted prealloc";
preallocSize = 2000000; maxFramesDefault = 2000000;
} }
QSettings settings;
preallocSize = settings.value("Main/MaximumFrames", maxFramesDefault).toInt();
//the goal is to prevent a reallocation from ever happening
frames.reserve(preallocSize); frames.reserve(preallocSize);
filteredFrames.reserve(preallocSize); //the goal is to prevent a reallocation from ever happening filteredFrames.reserve(preallocSize);
dbcHandler = DBCHandler::getReference(); dbcHandler = DBCHandler::getReference();
interpretFrames = false; interpretFrames = false;
overwriteDups = false; overwriteDups = false;
filtersPersistDuringClear = false;
useHexMode = true; useHexMode = true;
timeSeconds = false; timeSeconds = false;
timeOffset = 0; timeOffset = 0;
@@ -196,6 +202,11 @@ void CANFrameModel::setOverwriteMode(bool mode)
endResetModel(); endResetModel();
} }
void CANFrameModel::setClearMode(bool mode)
{
filtersPersistDuringClear = mode;
}
void CANFrameModel::setFilterState(unsigned int ID, bool state) void CANFrameModel::setFilterState(unsigned int ID, bool state)
{ {
if (!filters.contains(ID)) return; if (!filters.contains(ID)) return;
@@ -404,7 +415,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
const unsigned char *data = reinterpret_cast<const unsigned char *>(thisFrame.payload().constData()); const unsigned char *data = reinterpret_cast<const unsigned char *>(thisFrame.payload().constData());
int dataLen = thisFrame.payload().count(); int dataLen = thisFrame.payload().count();
if (role == Qt::BackgroundColorRole) if (role == Qt::BackgroundRole)
{ {
if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors) if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors)
{ {
@@ -437,7 +448,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const
} }
} }
if (role == Qt::TextColorRole) if (role == Qt::ForegroundRole)
{ {
if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors) if (dbcHandler != nullptr && interpretFrames && !ignoreDBCColors)
{ {
@@ -672,8 +683,11 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
} }
if (!overwriteDups) if (!overwriteDups)
{
try
{ {
frames.append(tempFrame); frames.append(tempFrame);
if (filters[tempFrame.frameId()] && busFilters[tempFrame.bus]) if (filters[tempFrame.frameId()] && busFilters[tempFrame.bus])
{ {
if (autoRefresh) beginInsertRows(QModelIndex(), filteredFrames.count(), filteredFrames.count()); if (autoRefresh) beginInsertRows(QModelIndex(), filteredFrames.count(), filteredFrames.count());
@@ -682,6 +696,11 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
if (autoRefresh) endInsertRows(); if (autoRefresh) endInsertRows();
} }
} }
catch (const std::exception& ex)
{
qDebug() << "addFrame failed to append. App is probably going to crash. frames.length(): " << frames.length() << " Exception: " << ex.what();
}
}
else //yes, overwrite dups else //yes, overwrite dups
{ {
bool found = false; bool found = false;
@@ -728,6 +747,20 @@ void CANFrameModel::addFrame(const CANFrame& frame, bool autoRefresh = false)
void CANFrameModel::addFrames(const CANConnection*, const QVector<CANFrame>& pFrames) void CANFrameModel::addFrames(const CANConnection*, const QVector<CANFrame>& pFrames)
{ {
if(frames.length() > frames.capacity() * 0.99)
{
qDebug() << "Frames count: " << frames.length() << " of " << frames.capacity() << " capacity, removing first " << (int)(frames.capacity() * 0.05) << " frames";
frames.remove(0, (int)(frames.capacity() * 0.05));
qDebug() << "Frames removed, new count: " << frames.length();
}
if(filteredFrames.length() > filteredFrames.capacity() * 0.99)
{
qDebug() << "filteredFrames count: " << filteredFrames.length() << " of " << filteredFrames.capacity() << " capacity, removing first " << (int)(filteredFrames.capacity() * 0.05) << " frames";
filteredFrames.remove(0, (int)(filteredFrames.capacity() * 0.05));
qDebug() << "filteredFrames removed, new count: " << filteredFrames.length();
}
foreach(const CANFrame& frame, pFrames) foreach(const CANFrame& frame, pFrames)
{ {
addFrame(frame); addFrame(frame);
@@ -754,8 +787,8 @@ void CANFrameModel::sendRefresh()
mutex.lock(); mutex.lock();
beginResetModel(); beginResetModel();
filteredFrames.clear(); filteredFrames.clear();
filteredFrames.reserve(preallocSize);
filteredFrames.append(tempContainer); filteredFrames.append(tempContainer);
filteredFrames.reserve(preallocSize);
lastUpdateNumFrames = 0; lastUpdateNumFrames = 0;
endResetModel(); endResetModel();
@@ -796,8 +829,11 @@ void CANFrameModel::clearFrames()
this->beginResetModel(); this->beginResetModel();
frames.clear(); frames.clear();
filteredFrames.clear(); filteredFrames.clear();
if(filtersPersistDuringClear == false)
{
filters.clear(); filters.clear();
busFilters.clear(); busFilters.clear();
}
frames.reserve(preallocSize); frames.reserve(preallocSize);
filteredFrames.reserve(preallocSize); filteredFrames.reserve(preallocSize);
this->endResetModel(); this->endResetModel();
+2
View File
@@ -46,6 +46,7 @@ public:
bool getInterpretMode(); bool getInterpretMode();
void setOverwriteMode(bool); void setOverwriteMode(bool);
void setHexMode(bool); void setHexMode(bool);
void setClearMode(bool mode);
void setSysTimeMode(bool); void setSysTimeMode(bool);
void setMillisMode(bool mode); void setMillisMode(bool mode);
void setIgnoreDBCColors(bool mode); void setIgnoreDBCColors(bool mode);
@@ -89,6 +90,7 @@ private:
QMutex mutex; QMutex mutex;
bool interpretFrames; //should we use the dbcHandler? bool interpretFrames; //should we use the dbcHandler?
bool overwriteDups; //should we display all frames or only the newest for each ID? bool overwriteDups; //should we display all frames or only the newest for each ID?
bool filtersPersistDuringClear;
QString timeFormat; QString timeFormat;
bool useHexMode; bool useHexMode;
bool timeSeconds; bool timeSeconds;
+2 -2
View File
@@ -245,11 +245,11 @@ CANCon::type CANConnection::getType() {
CANCon::status CANConnection::getStatus() { CANCon::status CANConnection::getStatus() {
return (CANCon::status) mStatus.load(); return (CANCon::status) mStatus.loadRelaxed();
} }
void CANConnection::setStatus(CANCon::status pStatus) { void CANConnection::setStatus(CANCon::status pStatus) {
mStatus.store(pStatus); mStatus.storeRelaxed(pStatus);
} }
bool CANConnection::isCapSuspended() { bool CANConnection::isCapSuspended() {
+2
View File
@@ -501,8 +501,10 @@ CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QS
void ConnectionWindow::loadConnections() void ConnectionWindow::loadConnections()
{ {
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
qRegisterMetaTypeStreamOperators<CANBus>(); qRegisterMetaTypeStreamOperators<CANBus>();
qRegisterMetaTypeStreamOperators<QList<CANBus>>(); qRegisterMetaTypeStreamOperators<QList<CANBus>>();
#endif
QSettings settings; QSettings settings;
+4
View File
@@ -351,7 +351,11 @@ DBC_NODE* DBCFile::findNodeByNameAndComment(QString fullname)
if (dbc_nodes.length() == 0) return nullptr; if (dbc_nodes.length() == 0) return nullptr;
for (int i = 0; i < dbc_nodes.length(); i++) for (int i = 0; i < dbc_nodes.length(); i++)
{ {
if(dbc_nodes[i].comment.isEmpty())
nameAndComment = dbc_nodes[i].name;
else
nameAndComment = dbc_nodes[i].name + " - " + dbc_nodes[i].comment; nameAndComment = dbc_nodes[i].name + " - " + dbc_nodes[i].comment;
if (fullname.compare(nameAndComment, Qt::CaseInsensitive) == 0) if (fullname.compare(nameAndComment, Qt::CaseInsensitive) == 0)
{ {
return &dbc_nodes[i]; return &dbc_nodes[i];
+3
View File
@@ -110,9 +110,12 @@ void DBCNodeEditor::showEvent(QShowEvent* event)
} }
void DBCNodeEditor::refreshView() void DBCNodeEditor::refreshView()
{
if(dbcNode)
{ {
ui->lineComment->setText(dbcNode->comment); ui->lineComment->setText(dbcNode->comment);
ui->lineMsgName->setText(dbcNode->name); ui->lineMsgName->setText(dbcNode->name);
}
//generateSampleText(); //generateSampleText();
} }
+16
View File
@@ -90,6 +90,20 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
ui->cbFilterLabeling->setChecked(settings.value("Main/FilterLabeling", true).toBool()); ui->cbFilterLabeling->setChecked(settings.value("Main/FilterLabeling", true).toBool());
ui->cbIgnoreDBCColors->setChecked(settings.value("Main/IgnoreDBCColors", false).toBool()); ui->cbIgnoreDBCColors->setChecked(settings.value("Main/IgnoreDBCColors", false).toBool());
int maxFramesDefault;
if (QSysInfo::WordSize > 32)
{
qDebug() << "64 bit OS detected. Requesting a large preallocation";
maxFramesDefault = 10000000;
}
else //if compiling for 32 bit you can't ask for gigabytes of preallocation so tone it down.
{
qDebug() << "32 bit OS detected. Requesting a much restricted prealloc";
maxFramesDefault = 2000000;
}
ui->spinMaximumFrames->setValue(settings.value("Main/MaximumFrames", maxFramesDefault).toInt());
//just for simplicity they all call the same function and that function updates all settings at once //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())); connect(ui->cbDisplayHex, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
connect(ui->cbFlowAutoRef, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->cbFlowAutoRef, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
@@ -117,6 +131,7 @@ MainSettingsDialog::MainSettingsDialog(QWidget *parent) :
connect(ui->cbHexGraphFlow, 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->cbHexGraphInfo, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
connect(ui->cbIgnoreDBCColors, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); connect(ui->cbIgnoreDBCColors, SIGNAL(toggled(bool)), this, SLOT(updateSettings()));
connect(ui->spinMaximumFrames, SIGNAL(valueChanged(int)), this, SLOT(updateSettings()));
installEventFilter(this); installEventFilter(this);
} }
@@ -183,6 +198,7 @@ void MainSettingsDialog::updateSettings()
settings.setValue("Remote/Pass", encPass); settings.setValue("Remote/Pass", encPass);
settings.setValue("Main/FilterLabeling", ui->cbFilterLabeling->isChecked()); settings.setValue("Main/FilterLabeling", ui->cbFilterLabeling->isChecked());
settings.setValue("Main/IgnoreDBCColors", ui->cbIgnoreDBCColors->isChecked()); settings.setValue("Main/IgnoreDBCColors", ui->cbIgnoreDBCColors->isChecked());
settings.setValue("Main/MaximumFrames", ui->spinMaximumFrames->value());
settings.sync(); settings.sync();
emit updatedSettings(); emit updatedSettings();
+34 -4
View File
@@ -30,8 +30,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
qRegisterMetaTypeStreamOperators<QVector<QString>>(); qRegisterMetaTypeStreamOperators<QVector<QString>>();
qRegisterMetaTypeStreamOperators<QVector<int>>(); qRegisterMetaTypeStreamOperators<QVector<int>>();
#endif
useHex = true; useHex = true;
@@ -55,7 +57,7 @@ MainWindow::MainWindow(QWidget *parent) :
verticalHeader->setSectionResizeMode(QHeaderView::Fixed); verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
QSettings settings; QSettings settings;
int fontSize = settings.value("Main/FontSize", 9).toUInt(); int fontSize = settings.value("Main/FontSize", 9).toUInt();
QFont sysFont = QFont(); //get default font QFont sysFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); //get default font
sysFont.setPointSize(fontSize); sysFont.setPointSize(fontSize);
verticalHeader->setDefaultSectionSize(sysFont.pixelSize()); verticalHeader->setDefaultSectionSize(sysFont.pixelSize());
ui->canFramesView->setFont(sysFont); ui->canFramesView->setFont(sysFont);
@@ -141,6 +143,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->cbInterpret, &QAbstractButton::toggled, this, &MainWindow::interpretToggled); connect(ui->cbInterpret, &QAbstractButton::toggled, this, &MainWindow::interpretToggled);
connect(ui->cbOverwrite, &QAbstractButton::toggled, this, &MainWindow::overwriteToggled); connect(ui->cbOverwrite, &QAbstractButton::toggled, this, &MainWindow::overwriteToggled);
connect(ui->cbPersistentFilters, &QAbstractButton::toggled, this, &MainWindow::presistentFiltersToggled);
connect(ui->listFilters, &QListWidget::itemChanged, this, &MainWindow::filterListItemChanged); connect(ui->listFilters, &QListWidget::itemChanged, this, &MainWindow::filterListItemChanged);
connect(ui->listBusFilters, &QListWidget::itemChanged, this, &MainWindow::busFilterListItemChanged); connect(ui->listBusFilters, &QListWidget::itemChanged, this, &MainWindow::busFilterListItemChanged);
@@ -177,7 +180,7 @@ MainWindow::MainWindow(QWidget *parent) :
updateTimer.setInterval(250); updateTimer.setInterval(250);
updateTimer.start(); updateTimer.start();
elapsedTime = new QTime; elapsedTime = new QElapsedTimer;
elapsedTime->start(); elapsedTime->start();
isConnected = false; isConnected = false;
@@ -616,6 +619,18 @@ void MainWindow::overwriteToggled(bool state)
} }
} }
void MainWindow::presistentFiltersToggled(bool state)
{
if (state)
{
model->setClearMode(true);
}
else
{
model->setClearMode(false);
}
}
void MainWindow::updateFilterList() void MainWindow::updateFilterList()
{ {
if (model == nullptr) return; if (model == nullptr) return;
@@ -1146,11 +1161,26 @@ void MainWindow::showTemporalGraphWindow()
//only create an instance of the object if we dont have one. Otherwise just display the existing one. //only create an instance of the object if we dont have one. Otherwise just display the existing one.
if (!temporalGraphWindow) if (!temporalGraphWindow)
{ {
const QVector<CANFrame> *frames;
if (!useFiltered) if (!useFiltered)
temporalGraphWindow = new TemporalGraphWindow(model->getListReference()); frames = model->getListReference();
else else
temporalGraphWindow = new TemporalGraphWindow(model->getFilteredListReference()); frames = model->getFilteredListReference();
if(frames->count() > 2000)
{
QMessageBox::StandardButton confirmDialog;
confirmDialog = QMessageBox::question(this, "Danger Will Robinson", "There are a lot of frames (>2000) to plot, this may take a while or crash the app. Crash likely with more than 10k frames. Continue?",
QMessageBox::Yes|QMessageBox::No);
if (confirmDialog == QMessageBox::No)
{
return;
} }
}
temporalGraphWindow = new TemporalGraphWindow(frames);
}
temporalGraphWindow->show(); temporalGraphWindow->show();
} }
+2 -1
View File
@@ -99,6 +99,7 @@ private slots:
void setupSendToLatestGraphWindow(); void setupSendToLatestGraphWindow();
void interpretToggled(bool); void interpretToggled(bool);
void overwriteToggled(bool); void overwriteToggled(bool);
void presistentFiltersToggled(bool state);
void logReceivedFrame(CANConnection*, QVector<CANFrame>); void logReceivedFrame(CANConnection*, QVector<CANFrame>);
void tickGUIUpdate(); void tickGUIUpdate();
void toggleCapture(); void toggleCapture();
@@ -137,7 +138,7 @@ private:
DBCHandler *dbcHandler; DBCHandler *dbcHandler;
QByteArray inputBuffer; QByteArray inputBuffer;
QTimer updateTimer; QTimer updateTimer;
QTime *elapsedTime; QElapsedTimer *elapsedTime;
int framesPerSec; int framesPerSec;
int rxFrames; int rxFrames;
bool inhibitFilterUpdate; bool inhibitFilterUpdate;
+16 -28
View File
@@ -156,26 +156,8 @@ class QCPPolarGraph;
It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject.
*/ */
#ifndef Q_MOC_RUN
namespace QCP { namespace QCP {
#else Q_NAMESPACE
class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace
Q_GADGET
Q_ENUMS(ExportPen)
Q_ENUMS(ResolutionUnit)
Q_ENUMS(SignDomain)
Q_ENUMS(MarginSide)
Q_FLAGS(MarginSides)
Q_ENUMS(AntialiasedElement)
Q_FLAGS(AntialiasedElements)
Q_ENUMS(PlottingHint)
Q_FLAGS(PlottingHints)
Q_ENUMS(Interaction)
Q_FLAGS(Interactions)
Q_ENUMS(SelectionRectMode)
Q_ENUMS(SelectionType)
public:
#endif
/*! /*!
Defines the different units in which the image resolution can be specified in the export Defines the different units in which the image resolution can be specified in the export
@@ -318,6 +300,20 @@ enum SelectionType { stNone ///< The plottable is not selectable
,stMultipleDataRanges ///< Any combination of data points/ranges can be selected ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected
}; };
Q_ENUM_NS(ExportPen)
Q_ENUM_NS(ResolutionUnit)
Q_ENUM_NS(SignDomain)
Q_ENUM_NS(MarginSide)
Q_FLAG_NS(MarginSides)
Q_ENUM_NS(AntialiasedElement)
Q_FLAG_NS(AntialiasedElements)
Q_ENUM_NS(PlottingHint)
Q_FLAG_NS(PlottingHints)
Q_ENUM_NS(Interaction)
Q_FLAG_NS(Interactions)
Q_ENUM_NS(SelectionRectMode)
Q_ENUM_NS(SelectionType)
/*! \internal /*! \internal
Returns whether the specified \a value is considered an invalid data value for plottables (i.e. Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
@@ -386,15 +382,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
Q_DECLARE_METATYPE(QCP::ExportPen) //no need to use Q_DECLARE_METATYPE on enum since Q_ENUM_NS adds enum as metatype automatically
Q_DECLARE_METATYPE(QCP::ResolutionUnit)
Q_DECLARE_METATYPE(QCP::SignDomain)
Q_DECLARE_METATYPE(QCP::MarginSide)
Q_DECLARE_METATYPE(QCP::AntialiasedElement)
Q_DECLARE_METATYPE(QCP::PlottingHint)
Q_DECLARE_METATYPE(QCP::Interaction)
Q_DECLARE_METATYPE(QCP::SelectionRectMode)
Q_DECLARE_METATYPE(QCP::SelectionType)
/* end of 'src/global.h' */ /* end of 'src/global.h' */
+2 -2
View File
@@ -2,7 +2,7 @@
#define SNIFFERITEM_H #define SNIFFERITEM_H
#include <QVariant> #include <QVariant>
#include <QTime> #include <QElapsedTimer>
#include "can_structs.h" #include "can_structs.h"
struct fstCan struct fstCan
@@ -50,7 +50,7 @@ private:
quint64 mCurrentTime; quint64 mCurrentTime;
quint64 mCurrSeqVal; quint64 mCurrSeqVal;
QTime mTime; QElapsedTimer mTime;
}; };
#endif // SNIFFERITEM_H #endif // SNIFFERITEM_H
+10 -1
View File
@@ -4,6 +4,9 @@
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QSettings> #include <QSettings>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 )
#include <QtCore/QRandomGenerator>
#endif
#include "connections/canconmanager.h" #include "connections/canconmanager.h"
#include "helpwindow.h" #include "helpwindow.h"
@@ -234,7 +237,13 @@ void ScriptingWindow::createNewScript()
container = new ScriptContainer(); container = new ScriptContainer();
container->fileName = "UNNAMED_" + QString::number((qrand() % 10000)) + ".js"; QString randomPart;
#if QT_VERSION < QT_VERSION_CHECK( 5, 10, 0 )
randomPart = QString::number((qrand() % 10000));
#else
randomPart = QString::number((QRandomGenerator::global()->bounded(10000)));
#endif
container->fileName = "UNNAMED_" + randomPart + ".js";
container->filePath = QString(); container->filePath = QString();
container->scriptText = QString(); container->scriptText = QString();
container->setScriptWindow(this); container->setScriptWindow(this);
+173 -1
View File
@@ -27,6 +27,10 @@ SignalViewerWindow::SignalViewerWindow(const QVector<CANFrame> *frames, QWidget
connect(ui->btnAdd, SIGNAL(clicked(bool)), this, SLOT(addSignal())); connect(ui->btnAdd, SIGNAL(clicked(bool)), this, SLOT(addSignal()));
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
connect(ui->btnRemove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedSignal())); connect(ui->btnRemove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedSignal()));
connect(ui->btnSave, SIGNAL(clicked(bool)), this, SLOT(saveSignalsFile()));
connect(ui->btnLoad, SIGNAL(clicked(bool)), this, SLOT(loadSignalsFile()));
connect(ui->btnAppend, SIGNAL(clicked(bool)), this, SLOT(appendSignalsFile()));
connect(ui->btnClear, SIGNAL(clicked(bool)), this, SLOT(clearSignalsTable()));
loadMessages(); loadMessages();
} }
@@ -137,11 +141,179 @@ void SignalViewerWindow::addSignal()
DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(ui->cbSignals->currentText()); DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(ui->cbSignals->currentText());
if (!sig) return; if (!sig) return;
addSignal(sig);
}
void SignalViewerWindow::addSignal(DBC_SIGNAL *sig)
{
signalList.append(sig); signalList.append(sig);
int rowIdx = ui->tableViewer->rowCount(); int rowIdx = ui->tableViewer->rowCount();
ui->tableViewer->insertRow(rowIdx); ui->tableViewer->insertRow(rowIdx);
QTableWidgetItem *item = new QTableWidgetItem(msg->sender->name + " - " + sig->name); QTableWidgetItem *item = new QTableWidgetItem(sig->parentMessage->sender->name + " - " + sig->name);
ui->tableViewer->setItem(rowIdx, 0, item); ui->tableViewer->setItem(rowIdx, 0, item);
}
void SignalViewerWindow::saveSignalsFile()
{
saveDefinitions();
}
void SignalViewerWindow::loadSignalsFile()
{
loadDefinitions(false);
}
void SignalViewerWindow::appendSignalsFile()
{
loadDefinitions(true);
}
void SignalViewerWindow::clearSignalsTable()
{
clearSignalsTable(true);
}
void SignalViewerWindow::clearSignalsTable(bool askForConfirmation)
{
if(askForConfirmation)
{
QMessageBox::StandardButton confirmDialog;
confirmDialog = QMessageBox::question(this, "Danger Will Robinson", "Are you sure you want to clear all of your signals?",
QMessageBox::Yes|QMessageBox::No);
if (confirmDialog == QMessageBox::No)
{
return;
}
}
signalList.clear();
ui->tableViewer->setRowCount(0);
}
void SignalViewerWindow::saveDefinitions()
{
QString filename;
QFileDialog dialog(this);
QSettings settings;
QStringList filters;
filters.append(QString(tr("SignalViewer definition (*.sdf)")));
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilters(filters);
dialog.setViewMode(QFileDialog::Detail);
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setDirectory(settings.value("SignalViewer/LoadSaveDirectory", dialog.directory().path()).toString());
if (dialog.exec() == QDialog::Accepted)
{
filename = dialog.selectedFiles()[0];
settings.setValue("SignalViewer/LoadSaveDirectory", dialog.directory().path());
if (!filename.contains('.')) filename += ".sdf";
QFile *outFile = new QFile(filename);
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
return;
DBC_SIGNAL *sig;
for (int i = 0; i < signalList.count(); i++)
{
sig = signalList.at(i);
outFile->write("SV1");
outFile->putChar(',');
outFile->write(QString::number(sig->parentMessage->ID, 16).toUtf8());
outFile->putChar(',');
outFile->write(sig->parentMessage->name.toUtf8());
outFile->putChar(',');
outFile->write(sig->name.toUtf8());
outFile->write("\n");
}
outFile->close();
}
}
void SignalViewerWindow::loadDefinitions(bool append)
{
QString filename;
QFileDialog dialog;
QSettings settings;
QStringList filters;
filters.append(QString(tr("SignalViewer definition (*.sdf)")));
QList<DBC_SIGNAL *> loadedSignals;
if (dbcHandler == nullptr) return;
if (dbcHandler->getFileCount() == 0) dbcHandler->createBlankFile();
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilters(filters);
dialog.setViewMode(QFileDialog::Detail);
dialog.setDirectory(settings.value("SignalViewer/LoadSaveDirectory", dialog.directory().path()).toString());
if (dialog.exec() == QDialog::Accepted)
{
filename = dialog.selectedFiles()[0];
settings.setValue("SignalViewer/LoadSaveDirectory", dialog.directory().path());
QFile *inFile = new QFile(filename);
QByteArray line;
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
return;
while (!inFile->atEnd()) {
line = inFile->readLine().simplified();
if (line.length() > 2)
{
QList<QByteArray> tokens = line.split(',');
DBC_SIGNAL *sig;
if (tokens[0] == "SV1") //signal viewer save format v1
{
// = tokens[1].toUInt(nullptr, 16);
int msgId = tokens[1].toUInt(nullptr, 16);
QString msgName = QString(tokens[2]);
QString sigName = QString(tokens[3]);
DBC_MESSAGE *msg;;
if (msg = dbcHandler->findMessage(msgName))
{
sig = msg->sigHandler->findSignalByName(sigName);
loadedSignals.append(sig);
}
else if(msg = dbcHandler->findMessage(msgId))
{
sig = msg->sigHandler->findSignalByName(sigName);
//fix anything up about the name?
loadedSignals.append(sig);
}
else
{
qDebug() << "Couldn't find the message by name! " << msgName << " " << sigName;
}
}
}
}
inFile->close();
if(loadedSignals.count() > 0)
{
if(append == false)
{
clearSignalsTable(false);
}
for (int i=0; i<loadedSignals.count(); i++)
{
addSignal(loadedSignals[i]);
}
}
}
} }
+8
View File
@@ -20,8 +20,16 @@ private slots:
void loadMessages(); void loadMessages();
void loadSignals(int idx); void loadSignals(int idx);
void addSignal(); void addSignal();
void addSignal(DBC_SIGNAL *sig);
void removeSelectedSignal(); void removeSelectedSignal();
void updatedFrames(int); void updatedFrames(int);
void saveSignalsFile();
void loadSignalsFile();
void appendSignalsFile();
void clearSignalsTable();
void clearSignalsTable(bool);
void saveDefinitions();
void loadDefinitions(bool);
private: private:
Ui::SignalViewerWindow *ui; Ui::SignalViewerWindow *ui;
+12
View File
@@ -31,6 +31,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QDateTime> #include <QDateTime>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDataStream> #include <QDataStream>
#include <QIODevice>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 )
#include <QtCore/QRandomGenerator>
#endif
SimpleCrypt::SimpleCrypt(): SimpleCrypt::SimpleCrypt():
m_key(0), m_key(0),
@@ -38,7 +42,9 @@ SimpleCrypt::SimpleCrypt():
m_protectionMode(ProtectionChecksum), m_protectionMode(ProtectionChecksum),
m_lastError(ErrorNoError) m_lastError(ErrorNoError)
{ {
#if QT_VERSION < QT_VERSION_CHECK( 5, 10, 0 )
qsrand(uint(QDateTime::currentMSecsSinceEpoch() & 0xFFFF)); qsrand(uint(QDateTime::currentMSecsSinceEpoch() & 0xFFFF));
#endif
} }
SimpleCrypt::SimpleCrypt(quint64 key): SimpleCrypt::SimpleCrypt(quint64 key):
@@ -47,7 +53,9 @@ SimpleCrypt::SimpleCrypt(quint64 key):
m_protectionMode(ProtectionChecksum), m_protectionMode(ProtectionChecksum),
m_lastError(ErrorNoError) m_lastError(ErrorNoError)
{ {
#if QT_VERSION < QT_VERSION_CHECK( 5, 10, 0 )
qsrand(uint(QDateTime::currentMSecsSinceEpoch() & 0xFFFF)); qsrand(uint(QDateTime::currentMSecsSinceEpoch() & 0xFFFF));
#endif
splitKey(); splitKey();
} }
@@ -113,7 +121,11 @@ QByteArray SimpleCrypt::encryptToByteArray(QByteArray plaintext)
} }
//prepend a random char to the string //prepend a random char to the string
#if QT_VERSION < QT_VERSION_CHECK( 5, 10, 0 )
char randomChar = char(qrand() & 0xFF); char randomChar = char(qrand() & 0xFF);
#else
char randomChar = char(QRandomGenerator::global()->bounded(256));
#endif
ba = randomChar + integrityProtection + ba; ba = randomChar + integrityProtection + ba;
int pos(0); int pos(0);
+33
View File
@@ -80,6 +80,39 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Maximum Frames to Capture</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMaximumFrames">
<property name="minimum">
<number>100000</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="singleStep">
<number>100000</number>
</property>
<property name="value">
<number>10000000</number>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox_6"> <widget class="QGroupBox" name="groupBox_6">
<property name="title"> <property name="title">
+7
View File
@@ -227,6 +227,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="cbPersistentFilters">
<property name="text">
<string>Keep Filters When Clearing</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="cbAutoScroll"> <widget class="QCheckBox" name="cbAutoScroll">
<property name="text"> <property name="text">
+28
View File
@@ -85,6 +85,34 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="btnSave">
<property name="text">
<string>Save View</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnLoad">
<property name="text">
<string>Load View</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnAppend">
<property name="text">
<string>Append to View</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClear">
<property name="text">
<string>Clear View</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>