From 74f6d7f9476fde927cd6e181a753acd0fbed6569 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 15 Jan 2017 16:30:08 -0500 Subject: [PATCH] Add preliminaries for signal viewer, update version number, switch dbc handler to singleton pattern, changes to DBC attributes --- SavvyCAN.pro | 9 +++-- canframemodel.cpp | 7 +--- canframemodel.h | 1 - config.h | 2 +- dbc/dbc_classes.h | 38 +++++++++++++----- dbc/dbchandler.cpp | 43 ++++++++++++++------ dbc/dbchandler.h | 9 +++-- dbc/dbcloadsavewindow.cpp | 6 +-- dbc/dbcloadsavewindow.h | 2 +- dbc/dbcmaineditor.cpp | 6 +-- dbc/dbcmaineditor.h | 2 +- dbc/dbcsignaleditor.cpp | 6 +-- dbc/dbcsignaleditor.h | 2 +- mainwindow.cpp | 20 +++++++--- mainwindow.h | 3 ++ re/graphingwindow.cpp | 4 +- re/graphingwindow.h | 2 +- signalviewerwindow.cpp | 18 +++++++++ signalviewerwindow.h | 22 +++++++++++ ui/mainwindow.ui | 6 +++ ui/signalviewerwindow.ui | 83 +++++++++++++++++++++++++++++++++++++++ 21 files changed, 236 insertions(+), 55 deletions(-) create mode 100644 signalviewerwindow.cpp create mode 100644 signalviewerwindow.h create mode 100644 ui/signalviewerwindow.ui diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 784936a..507299d 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -59,7 +59,8 @@ SOURCES += main.cpp\ connections/connectionwindow.cpp \ re/graphingwindow.cpp \ re/newgraphdialog.cpp \ - bisectwindow.cpp + bisectwindow.cpp \ + signalviewerwindow.cpp HEADERS += mainwindow.h \ can_structs.h \ @@ -107,7 +108,8 @@ HEADERS += mainwindow.h \ connections/connectionwindow.h \ re/graphingwindow.h \ re/newgraphdialog.h \ - bisectwindow.h + bisectwindow.h \ + signalviewerwindow.h FORMS += ui/candatagrid.ui \ ui/connectionwindow.ui \ @@ -132,7 +134,8 @@ FORMS += ui/candatagrid.ui \ ui/scriptingwindow.ui \ ui/snifferwindow.ui \ ui/udsscanwindow.ui \ - ui/bisectwindow.ui + ui/bisectwindow.ui \ + ui/signalviewerwindow.ui DISTFILES += diff --git a/canframemodel.cpp b/canframemodel.cpp index 5e9c816..9fff765 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -58,7 +58,7 @@ CANFrameModel::CANFrameModel(QObject *parent) frames.reserve(preallocSize); filteredFrames.reserve(preallocSize); //the goal is to prevent a reallocation from ever happening - dbcHandler = NULL; + dbcHandler = DBCHandler::getReference(); interpretFrames = false; overwriteDups = false; useHexMode = true; @@ -89,11 +89,6 @@ void CANFrameModel::setSecondsMode(bool mode) } } -void CANFrameModel::setDBCHandler(DBCHandler *handler) -{ - dbcHandler = handler; -} - void CANFrameModel::setInterpetMode(bool mode) { //if the state of interpretFrames changes then we need to reset the model diff --git a/canframemodel.h b/canframemodel.h index 5099e7c..ba36746 100644 --- a/canframemodel.h +++ b/canframemodel.h @@ -29,7 +29,6 @@ public: void sendRefresh(int); int sendBulkRefresh(); void clearFrames(); - void setDBCHandler(DBCHandler *); void setInterpetMode(bool); void setOverwriteMode(bool); void setHexMode(bool); diff --git a/config.h b/config.h index cb8e063..43c95b7 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 163 +#define VERSION 164 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/dbc/dbc_classes.h b/dbc/dbc_classes.h index bde4ead..fba92a4 100644 --- a/dbc/dbc_classes.h +++ b/dbc/dbc_classes.h @@ -1,15 +1,17 @@ #ifndef DBC_CLASSES_H #define DBC_CLASSES_H +#include #include #include +#include #include "can_structs.h" /*classes to encapsulate data from a DBC file. Really, the stuff of interest are the nodes, messages, signals, attributes, and comments. These things sort of form a hierarchy. Nodes send and receive messages. - Messages are comprised of signals. Signals and messages have attributes. + Messages are comprised of signals. Nodes, signals, and messages potentially have attribute values. All of them can have comments. */ @@ -30,17 +32,31 @@ enum DBC_ATTRIBUTE_VAL_TYPE ENUM }; +enum DBC_ATTRIBUTE_TYPE +{ + GENERAL, + NODE, + MESSAGE, + SIG +}; + class DBC_ATTRIBUTE { public: QString name; - DBC_ATTRIBUTE_VAL_TYPE type; - double startVal; - double endVal; - QStringList enumVals; //also used for STRING type but then you're assured to have only one + DBC_ATTRIBUTE_VAL_TYPE valType; + DBC_ATTRIBUTE_TYPE attrType; + double upper, lower; + QVariant defaultValue; }; -class DBC_VAL +class DBC_ATTRIBUTE_VALUE +{ + QString attrName; + QVariant value; +}; + +class DBC_VAL_ENUM_ENTRY { public: int value; @@ -52,7 +68,7 @@ class DBC_NODE public: QString name; QString comment; - QList attributes; + QList attributes; }; class DBC_MESSAGE; //forward reference so that DBC_SIGNAL can compile before we get to real definition of DBC_MESSAGE @@ -76,8 +92,8 @@ public: //TODO: this is sloppy. It shouldn't all be public! DBC_MESSAGE *parentMessage; QString unitName; QString comment; - QList attributes; - QList valList; + QList attributes; + QList valList; bool processAsText(const CANFrame &frame, QString &outString); bool processAsInt(const CANFrame &frame, int32_t &outValue); @@ -96,7 +112,9 @@ public: QString comment; unsigned int len; DBC_NODE *sender; - QList attributes; + QColor bgColor; + QColor fgColor; + QList attributes; DBCSignalHandler *sigHandler; DBC_SIGNAL* multiplexorSignal; }; diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index cc9d341..233adfe 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -7,6 +7,8 @@ #include #include "utility.h" +DBCHandler* DBCHandler::instance = NULL; + DBC_SIGNAL* DBCSignalHandler::findSignalByIdx(int idx) { if (sigs.count() == 0) return NULL; @@ -499,7 +501,7 @@ void DBCFile::loadFile(QString fileName) if (sig != NULL) { QString tokenString = match.captured(3); - DBC_VAL val; + DBC_VAL_ENUM_ENTRY val; while (tokenString.length() > 2) { regex.setPattern("(\\d+) \\\"(.*?)\\\"(.*)"); @@ -522,28 +524,36 @@ void DBCFile::loadFile(QString fileName) } } - /* if (line.startsWith("BA_DEF_ SG_ ")) { qDebug() << "Found a SG attribute line"; regex.setPattern("^BA\\_DEF\\_ SG\\_ +\\\"([A-Za-z0-9\-_]+)\\\" +(.+);"); match = regex.match(line); - //captured 1 is the Node name - //captured 2 is the comment itself + //captured 1 is the name of the attribute to set up + //captured 2 is the type of signal attribute to create. if (match.hasMatch()) { - qDebug() << "Comment was: " << match.captured(2); + } } - if (line.startsWith("BA_DEF_ BO_ ")) + if (line.startsWith("BA_DEF_ BO_ ")) //definition of a message attribute { } - if (line.startsWith("BA_DEF_ BU_ ")) + if (line.startsWith("BA_DEF_ BU_ ")) //definition of a node attribute + { + + } + + if (line.startsWith("BA_DEF_DEF_ ")) //definition of default value for an attribute + { + + } + + if (line.startsWith("BA_ ")) //set value of attribute { } -*/ } if (numSigFaults > 0 || numMsgFaults > 0) { @@ -551,7 +561,8 @@ void DBCFile::loadFile(QString fileName) QString msg = "DBC file loaded with errors!\n"; msg += "Number of faulty message entries: " + QString::number(numMsgFaults) + "\n"; msg += "Number of faulty signal entries: " + QString::number(numSigFaults) + "\n\n"; - msg += "Faulty entries have not been loaded."; + msg += "Faulty entries have not been loaded.\n\n"; + msg += "All other entries are, however, loaded."; msgBox.setText(msg); msgBox.exec(); } @@ -561,7 +572,6 @@ void DBCFile::loadFile(QString fileName) this->fileName = fileList[fileList.length() - 1]; //whoops... same name as parameter in this function. filePath = fileName.left(fileName.length() - this->fileName.length()); assocBuses = -1; - } void DBCFile::saveFile(QString fileName) @@ -684,7 +694,7 @@ void DBCFile::saveFile(QString fileName) valuesOutput.append("VAL_ " + QString::number(msg->ID) + " " + sig->name); for (int v = 0; v < sig->valList.count(); v++) { - DBC_VAL val = sig->valList[v]; + DBC_VAL_ENUM_ENTRY val = sig->valList[v]; valuesOutput.append(" " + QString::number(val.value) + " \"" + val.descript +"\""); } valuesOutput.append(";\n"); @@ -842,3 +852,14 @@ DBCFile* DBCHandler::getFileByName(QString name) } return NULL; } + +DBCHandler::DBCHandler() +{ + +} + +DBCHandler* DBCHandler::getReference() +{ + if (!instance) instance = new DBCHandler(); + return instance; +} diff --git a/dbc/dbchandler.h b/dbc/dbchandler.h index 5f74ee8..318f745 100644 --- a/dbc/dbchandler.h +++ b/dbc/dbchandler.h @@ -10,8 +10,6 @@ * Finish coding up the decoupled design * */ - - class DBCSignalHandler: public QObject { Q_OBJECT @@ -67,10 +65,11 @@ public: DBCMessageHandler *messageHandler; QList dbc_nodes; + QList dbc_attributes; private: QString fileName; QString filePath; - int assocBuses; //-1 = all buses, 0 = first bus, 1 = second bus + int assocBuses; //-1 = all buses, 0 = first bus, 1 = second bus, etc. }; class DBCHandler: public QObject @@ -87,9 +86,13 @@ public: DBCFile* getFileByIdx(int idx); DBCFile* getFileByName(QString name); int createBlankFile(); + static DBCHandler *getReference(); private: QList loadedFiles; + + DBCHandler(); + static DBCHandler *instance; }; #endif // DBCHANDLER_H diff --git a/dbc/dbcloadsavewindow.cpp b/dbc/dbcloadsavewindow.cpp index a37f813..d4790c3 100644 --- a/dbc/dbcloadsavewindow.cpp +++ b/dbc/dbcloadsavewindow.cpp @@ -1,12 +1,12 @@ #include "dbcloadsavewindow.h" #include "ui_dbcloadsavewindow.h" -DBCLoadSaveWindow::DBCLoadSaveWindow(DBCHandler *handler, const QVector *frames, QWidget *parent) : +DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::DBCLoadSaveWindow) { - dbcHandler = handler; + dbcHandler = DBCHandler::getReference(); referenceFrames = frames; ui->setupUi(this); @@ -28,7 +28,7 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(DBCHandler *handler, const QVectortableFiles, &QTableWidget::cellChanged, this, &DBCLoadSaveWindow::cellChanged); connect(ui->tableFiles, &QTableWidget::cellDoubleClicked, this, &DBCLoadSaveWindow::cellDoubleClicked); - editorWindow = new DBCMainEditor(handler, frames); + editorWindow = new DBCMainEditor(frames); } DBCLoadSaveWindow::~DBCLoadSaveWindow() diff --git a/dbc/dbcloadsavewindow.h b/dbc/dbcloadsavewindow.h index 41e33ac..5bbc3ff 100644 --- a/dbc/dbcloadsavewindow.h +++ b/dbc/dbcloadsavewindow.h @@ -15,7 +15,7 @@ class DBCLoadSaveWindow : public QDialog Q_OBJECT public: - explicit DBCLoadSaveWindow(DBCHandler *handler, const QVector *frames, QWidget *parent = 0); + explicit DBCLoadSaveWindow(const QVector *frames, QWidget *parent = 0); ~DBCLoadSaveWindow(); private slots: diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 16fe836..a6d63d0 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -7,7 +7,7 @@ #define MT_COLUMN_COUNT 5 -DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector *frames, QWidget *parent) : +DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::DBCMainEditor) { @@ -15,7 +15,7 @@ DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector *frame readSettings(); - dbcHandler = handler; + dbcHandler = DBCHandler::getReference(); referenceFrames = frames; QStringList headers; @@ -47,7 +47,7 @@ DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector *frame connect(ui->MessagesTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomMenuMessage(QPoint))); ui->MessagesTable->setContextMenuPolicy(Qt::CustomContextMenu); - sigEditor = new DBCSignalEditor(handler); + sigEditor = new DBCSignalEditor(); } void DBCMainEditor::showEvent(QShowEvent* event) diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index 4067693..055d512 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -16,7 +16,7 @@ class DBCMainEditor : public QDialog Q_OBJECT public: - explicit DBCMainEditor(DBCHandler *handler, const QVector *frames, QWidget *parent = 0); + explicit DBCMainEditor(const QVector *frames, QWidget *parent = 0); ~DBCMainEditor(); void setFileIdx(int idx); diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index 18efd7b..b8c660d 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -5,7 +5,7 @@ #include #include -DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : +DBCSignalEditor::DBCSignalEditor(QWidget *parent) : QDialog(parent), ui(new Ui::DBCSignalEditor) { @@ -15,7 +15,7 @@ DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : qsrand(QDateTime::currentMSecsSinceEpoch()); - dbcHandler = handler; + dbcHandler = DBCHandler::getReference(); dbcMessage = NULL; currentSignal = NULL; @@ -270,7 +270,7 @@ void DBCSignalEditor::onValuesCellChanged(int row,int col) if (row == ui->valuesTable->rowCount() - 1) { - DBC_VAL newVal; + DBC_VAL_ENUM_ENTRY newVal; newVal.value = 0; newVal.descript = "No Description"; currentSignal->valList.append(newVal); diff --git a/dbc/dbcsignaleditor.h b/dbc/dbcsignaleditor.h index 5d89e14..a3b47cd 100644 --- a/dbc/dbcsignaleditor.h +++ b/dbc/dbcsignaleditor.h @@ -14,7 +14,7 @@ class DBCSignalEditor : public QDialog Q_OBJECT public: - explicit DBCSignalEditor(DBCHandler *handler, QWidget *parent = 0); + explicit DBCSignalEditor(QWidget *parent = 0); void setMessageRef(DBC_MESSAGE *msg); void showEvent(QShowEvent*); void setFileIdx(int idx); diff --git a/mainwindow.cpp b/mainwindow.cpp index 2f02582..9af3409 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -82,14 +82,13 @@ MainWindow::MainWindow(QWidget *parent) : isoWindow = NULL; snifferWindow = NULL; bisectWindow = NULL; - dbcHandler = new DBCHandler; + signalViewerWindow = NULL; + dbcHandler = DBCHandler::getReference(); bDirty = false; inhibitFilterUpdate = false; rxFrames = 0; framesPerSec = 0; - model->setDBCHandler(dbcHandler); - connect(ui->actionSetup, SIGNAL(triggered(bool)), SLOT(showConnectionSettingsWindow())); connect(ui->actionOpen_Log_File, &QAction::triggered, this, &MainWindow::handleLoadFile); connect(ui->actionGraph_Dta, &QAction::triggered, this, &MainWindow::showGraphingWindow); @@ -128,6 +127,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionSniffer, &QAction::triggered, this, &MainWindow::showSnifferWindow); connect(ui->actionMotorControlConfig, &QAction::triggered, this, &MainWindow::showMCConfigWindow); connect(ui->actionCapture_Bisector, &QAction::triggered, this, &MainWindow::showBisectWindow); + connect(ui->actionSignal_Viewer, &QAction::triggered, this, &MainWindow::showSignalViewer); connect(CANConManager::getInstance(), &CANConManager::framesReceived, model, &CANFrameModel::addFrames); @@ -205,6 +205,7 @@ void MainWindow::killEmAll() killWindow(bisectWindow); killWindow(firmwareUploaderWindow); killWindow(motorctrlConfigWindow); + killWindow(signalViewerWindow); } //forcefully close the window, kill it, and salt the earth @@ -687,7 +688,7 @@ void MainWindow::showSettingsDialog() void MainWindow::showGraphingWindow() { if (!graphingWindow) { - graphingWindow = new GraphingWindow(dbcHandler, model->getListReference()); + graphingWindow = new GraphingWindow(model->getListReference()); connect(graphingWindow, SIGNAL(sendCenterTimeID(int32_t,double)), this, SLOT(gotCenterTimeID(int32_t,double))); connect(this, SIGNAL(sendCenterTimeID(int32_t,double)), graphingWindow, SLOT(gotCenterTimeID(int32_t,double))); } @@ -869,11 +870,20 @@ void MainWindow::showDBCFileWindow() { if (!dbcFileWindow) { - dbcFileWindow = new DBCLoadSaveWindow(dbcHandler, model->getListReference()); + dbcFileWindow = new DBCLoadSaveWindow(model->getListReference()); } dbcFileWindow->show(); } +void MainWindow::showSignalViewer() +{ + if (!signalViewerWindow) + { + signalViewerWindow = new SignalViewerWindow(); + } + signalViewerWindow->show(); +} + void MainWindow::showConnectionSettingsWindow() { if (!connectionWindow) diff --git a/mainwindow.h b/mainwindow.h index 35c2f82..8b90e4b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -29,6 +29,7 @@ #include "re/sniffer/snifferwindow.h" #include "re/isotp_interpreterwindow.h" #include "motorcontrollerconfigwindow.h" +#include "signalviewerwindow.h" class ConnectionWindow; @@ -73,6 +74,7 @@ private slots: void showISOInterpreterWindow(); void showSnifferWindow(); void showBisectWindow(); + void showSignalViewer(); void exitApp(); void handleSaveDecoded(); void connectionStatusUpdated(int conns); @@ -144,6 +146,7 @@ private: SnifferWindow* snifferWindow; MotorControllerConfigWindow *motorctrlConfigWindow; BisectWindow* bisectWindow; + SignalViewerWindow *signalViewerWindow; //various private storage QLabel lbStatusConnected; diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index a401eac..3cfe46f 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -4,7 +4,7 @@ #include "mainwindow.h" #include -GraphingWindow::GraphingWindow(DBCHandler *handler, const QVector *frames, QWidget *parent) : +GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::GraphingWindow) { @@ -13,7 +13,7 @@ GraphingWindow::GraphingWindow(DBCHandler *handler, const QVector *fra readSettings(); modelFrames = frames; - dbcHandler = handler; + dbcHandler = DBCHandler::getReference(); ui->graphingView->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables); diff --git a/re/graphingwindow.h b/re/graphingwindow.h index e3fad88..436a8c5 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -35,7 +35,7 @@ class GraphingWindow : public QDialog Q_OBJECT public: - explicit GraphingWindow(DBCHandler *handler, const QVector *, QWidget *parent = 0); + explicit GraphingWindow(const QVector *, QWidget *parent = 0); ~GraphingWindow(); void showEvent(QShowEvent*); diff --git a/signalviewerwindow.cpp b/signalviewerwindow.cpp new file mode 100644 index 0000000..dc53fc5 --- /dev/null +++ b/signalviewerwindow.cpp @@ -0,0 +1,18 @@ +#include "signalviewerwindow.h" +#include "ui_signalviewerwindow.h" + +SignalViewerWindow::SignalViewerWindow(QWidget *parent) : + QDialog(parent), + ui(new Ui::SignalViewerWindow) +{ + ui->setupUi(this); + + QStringList headers; + headers << "Signal" << "Value"; + ui->tableViewer->setHorizontalHeaderLabels(headers); +} + +SignalViewerWindow::~SignalViewerWindow() +{ + delete ui; +} diff --git a/signalviewerwindow.h b/signalviewerwindow.h new file mode 100644 index 0000000..e88f4e5 --- /dev/null +++ b/signalviewerwindow.h @@ -0,0 +1,22 @@ +#ifndef SIGNALVIEWERWINDOW_H +#define SIGNALVIEWERWINDOW_H + +#include + +namespace Ui { +class SignalViewerWindow; +} + +class SignalViewerWindow : public QDialog +{ + Q_OBJECT + +public: + explicit SignalViewerWindow(QWidget *parent = 0); + ~SignalViewerWindow(); + +private: + Ui::SignalViewerWindow *ui; +}; + +#endif // SIGNALVIEWERWINDOW_H diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index a0c47ee..083bca0 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -216,6 +216,7 @@ + @@ -419,6 +420,11 @@ Capture Bisector + + + Signal Viewer + + diff --git a/ui/signalviewerwindow.ui b/ui/signalviewerwindow.ui new file mode 100644 index 0000000..84b642b --- /dev/null +++ b/ui/signalviewerwindow.ui @@ -0,0 +1,83 @@ + + + SignalViewerWindow + + + + 0 + 0 + 975 + 424 + + + + Signal Viewer + + + + + + 2 + + + 300 + + + true + + + false + + + + + + + + + + + Message + + + + + + + + + + Signal + + + + + + + + + + Add To Viewer + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + +