Add preliminaries for signal viewer, update version number, switch dbc handler to singleton pattern, changes to DBC attributes
This commit is contained in:
+28
-10
@@ -1,15 +1,17 @@
|
||||
#ifndef DBC_CLASSES_H
|
||||
#define DBC_CLASSES_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
#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<DBC_ATTRIBUTE> attributes;
|
||||
QList<DBC_ATTRIBUTE_VALUE> 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<DBC_ATTRIBUTE> attributes;
|
||||
QList<DBC_VAL> valList;
|
||||
QList<DBC_ATTRIBUTE_VALUE> attributes;
|
||||
QList<DBC_VAL_ENUM_ENTRY> 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<DBC_ATTRIBUTE> attributes;
|
||||
QColor bgColor;
|
||||
QColor fgColor;
|
||||
QList<DBC_ATTRIBUTE_VALUE> attributes;
|
||||
DBCSignalHandler *sigHandler;
|
||||
DBC_SIGNAL* multiplexorSignal;
|
||||
};
|
||||
|
||||
+32
-11
@@ -7,6 +7,8 @@
|
||||
#include <QFileDialog>
|
||||
#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;
|
||||
}
|
||||
|
||||
+6
-3
@@ -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_NODE> dbc_nodes;
|
||||
QList<DBC_ATTRIBUTE> 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<DBCFile> loadedFiles;
|
||||
|
||||
DBCHandler();
|
||||
static DBCHandler *instance;
|
||||
};
|
||||
|
||||
#endif // DBCHANDLER_H
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "dbcloadsavewindow.h"
|
||||
#include "ui_dbcloadsavewindow.h"
|
||||
|
||||
DBCLoadSaveWindow::DBCLoadSaveWindow(DBCHandler *handler, const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *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 QVector<CANFrame
|
||||
connect(ui->tableFiles, &QTableWidget::cellChanged, this, &DBCLoadSaveWindow::cellChanged);
|
||||
connect(ui->tableFiles, &QTableWidget::cellDoubleClicked, this, &DBCLoadSaveWindow::cellDoubleClicked);
|
||||
|
||||
editorWindow = new DBCMainEditor(handler, frames);
|
||||
editorWindow = new DBCMainEditor(frames);
|
||||
}
|
||||
|
||||
DBCLoadSaveWindow::~DBCLoadSaveWindow()
|
||||
|
||||
@@ -15,7 +15,7 @@ class DBCLoadSaveWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DBCLoadSaveWindow(DBCHandler *handler, const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
explicit DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
~DBCLoadSaveWindow();
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#define MT_COLUMN_COUNT 5
|
||||
|
||||
DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DBCMainEditor)
|
||||
{
|
||||
@@ -15,7 +15,7 @@ DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector<CANFrame> *frame
|
||||
|
||||
readSettings();
|
||||
|
||||
dbcHandler = handler;
|
||||
dbcHandler = DBCHandler::getReference();
|
||||
referenceFrames = frames;
|
||||
|
||||
QStringList headers;
|
||||
@@ -47,7 +47,7 @@ DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector<CANFrame> *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)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class DBCMainEditor : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DBCMainEditor(DBCHandler *handler, const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
explicit DBCMainEditor(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
~DBCMainEditor();
|
||||
void setFileIdx(int idx);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <QMenu>
|
||||
#include <QSettings>
|
||||
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user