Refactor of previous commit to bring DBC functionality to its own class. Also, some misc bug fixing.
This commit is contained in:
+2
-2
@@ -25,7 +25,7 @@ SOURCES += main.cpp\
|
||||
candatagrid.cpp \
|
||||
flowviewwindow.cpp \
|
||||
framesenderwindow.cpp \
|
||||
dbcloader.cpp
|
||||
dbchandler.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
can_structs.h \
|
||||
@@ -42,7 +42,7 @@ HEADERS += mainwindow.h \
|
||||
framesenderwindow.h \
|
||||
can_trigger_structs.h \
|
||||
dbc_classes.h \
|
||||
dbcloader.h
|
||||
dbchandler.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
graphingwindow.ui \
|
||||
|
||||
+20
-11
@@ -24,7 +24,7 @@ enum DBC_SIG_VAL_TYPE
|
||||
enum DBC_ATTRIBUTE_VAL_TYPE
|
||||
{
|
||||
HEX,
|
||||
FLOAT,
|
||||
QFLOAT,
|
||||
QSTRING,
|
||||
ENUM
|
||||
};
|
||||
@@ -38,6 +38,12 @@ class DBC_ATTRIBUTE
|
||||
QStringList enumVals; //also used for STRING type but then you're assured to have only one
|
||||
};
|
||||
|
||||
class DBC_VAL
|
||||
{
|
||||
int value;
|
||||
QString descript;
|
||||
};
|
||||
|
||||
class DBC_NODE
|
||||
{
|
||||
public:
|
||||
@@ -46,16 +52,6 @@ public:
|
||||
QList<DBC_ATTRIBUTE> attributes;
|
||||
};
|
||||
|
||||
class DBC_MESSAGE
|
||||
{
|
||||
int ID;
|
||||
QString name;
|
||||
QString comment;
|
||||
int len;
|
||||
DBC_NODE *sender;
|
||||
QList<DBC_ATTRIBUTE> attributes;
|
||||
};
|
||||
|
||||
class DBC_SIGNAL
|
||||
{
|
||||
QString name;
|
||||
@@ -71,7 +67,20 @@ class DBC_SIGNAL
|
||||
QString unitName;
|
||||
QString comment;
|
||||
QList<DBC_ATTRIBUTE> attributes;
|
||||
QList<DBC_VAL> valList;
|
||||
};
|
||||
|
||||
class DBC_MESSAGE
|
||||
{
|
||||
int ID;
|
||||
QString name;
|
||||
QString comment;
|
||||
int len;
|
||||
DBC_NODE *sender;
|
||||
QList<DBC_ATTRIBUTE> attributes;
|
||||
QList<DBC_SIGNAL> msgSignals;
|
||||
};
|
||||
|
||||
|
||||
#endif // DBC_CLASSES_H
|
||||
|
||||
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
#include "dbchandler.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QDebug>
|
||||
|
||||
DBCHandler::DBCHandler(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DBCHandler::loadDBCFile(QString filename)
|
||||
{
|
||||
QFile *inFile = new QFile(filename);
|
||||
QString line;
|
||||
QRegularExpression regex;
|
||||
QRegularExpressionMatch match;
|
||||
|
||||
qDebug() << "DBC File: " << filename;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
qDebug() << "Starting DBC load";
|
||||
|
||||
while (!inFile->atEnd()) {
|
||||
line = QString(inFile->readLine().toUpper().simplified());
|
||||
if (line.startsWith("BO_ "))
|
||||
{
|
||||
qDebug() << "Found a BO line";
|
||||
regex.setPattern("^BO\\_ (\\w+) (\\w+) *: (\\w+) (\\w+)");
|
||||
match = regex.match(line);
|
||||
//captured 1 = the ID in decimal
|
||||
//captured 2 = The message name
|
||||
//captured 3 = the message length
|
||||
//captured 4 = the NODE responsible for this message
|
||||
if (match.hasMatch())
|
||||
{
|
||||
}
|
||||
}
|
||||
if (line.startsWith("SG_ "))
|
||||
{
|
||||
qDebug() << "Found a SG line";
|
||||
regex.setPattern("^SG\\_ (\\w+) : (\\d+)\\|(\\d+)@(\\d+)([\\+|\\-]) \\(([0-9.+\\-eE]+),([0-9.+\\-eE]+)\\) \\[([0-9.+\\-eE]+)\\|([0-9.+\\-eE]+)\\] \\\"(.*)\\\" (.*)");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the signal name
|
||||
//captured 2 is the starting bit
|
||||
//captured 3 is the length in bits
|
||||
//captured 4 is the byte order / value type
|
||||
//captured 5 specifies signed/unsigned for ints
|
||||
//captured 6 is the scaling factor
|
||||
//captured 7 is the offset
|
||||
//captured 8 is the minimum value
|
||||
//captured 9 is the maximum value
|
||||
//captured 10 is the unit
|
||||
//captured 11 is the receiving node
|
||||
|
||||
if (match.hasMatch())
|
||||
{
|
||||
}
|
||||
}
|
||||
if (line.startsWith("BU_:"))
|
||||
{
|
||||
qDebug() << "Found a BU line";
|
||||
regex.setPattern("^BU\\_\\:(.*)");
|
||||
match = regex.match(line);
|
||||
//captured 1 = a list of node names separated by spaces. No idea how many yet
|
||||
if (match.hasMatch())
|
||||
{
|
||||
QStringList nodeStrings = match.captured(1).split(' ');
|
||||
qDebug() << "Found " << nodeStrings.count() << " node names";
|
||||
for (int i = 0; i < nodeStrings.count(); i++)
|
||||
{
|
||||
qDebug() << nodeStrings[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line.startsWith("CM_ SG_ "))
|
||||
{
|
||||
qDebug() << "Found an SG comment line";
|
||||
regex.setPattern("^CM\\_ SG\\_ *(\\w+) *(\\w+) *\\\"(.*)\\\";");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against to get to the message
|
||||
//captured 2 is the signal name from that message
|
||||
//captured 3 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(3);
|
||||
}
|
||||
}
|
||||
if (line.startsWith("CM_ BO_ "))
|
||||
{
|
||||
qDebug() << "Found a BO comment line";
|
||||
regex.setPattern("^CM\\_ BO\\_ *(\\w+) *\\\"(.*)\\\";");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against to get to the message
|
||||
//captured 2 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(2);
|
||||
}
|
||||
|
||||
}
|
||||
if (line.startsWith("CM_ BU_ "))
|
||||
{
|
||||
qDebug() << "Found a BU comment line";
|
||||
regex.setPattern("^CM\\_ BU\\_ *(\\w+) *\\\"(.*)\\\";");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the Node name
|
||||
//captured 2 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(2);
|
||||
}
|
||||
}
|
||||
//VAL_ (1090) (VCUPresentParkLightOC) (1 "Error present" 0 "Error not present") ;
|
||||
if (line.startsWith("VAL_ "))
|
||||
{
|
||||
qDebug() << "Found a value definition line";
|
||||
regex.setPattern("^VAL\\_ (\\w+) (\\w+) (.*);");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against
|
||||
//captured 2 is the signal name to match against
|
||||
//captured 3 is a series of values in the form (number "text") that is, all sep'd by spaces
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Data was: " << match.captured(3);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(2);
|
||||
}
|
||||
}
|
||||
if (line.startsWith("BA_DEF_ BO_ "))
|
||||
{
|
||||
|
||||
}
|
||||
if (line.startsWith("BA_DEF_ BU_ "))
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
inFile->close();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef DBCHANDLER_H
|
||||
#define DBCHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "dbc_classes.h"
|
||||
|
||||
class DBCHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DBCHandler(QObject *parent = 0);
|
||||
void loadDBCFile(QString);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QList<DBC_NODE> dbc_nodes;
|
||||
QList<DBC_MESSAGE> dbc_messages;
|
||||
};
|
||||
|
||||
#endif // DBCHANDLER_H
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "dbcloader.h"
|
||||
|
||||
DBCLoader::DBCLoader(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#ifndef DBCLOADER_H
|
||||
#define DBCLOADER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "dbc_classes.h"
|
||||
|
||||
class DBCLoader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DBCLoader(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // DBCLOADER_H
|
||||
+8
-142
@@ -75,6 +75,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
playbackWindow = NULL;
|
||||
flowViewWindow = NULL;
|
||||
frameSenderWindow = NULL;
|
||||
dbcHandler = new DBCHandler;
|
||||
|
||||
connect(ui->btnConnect, SIGNAL(clicked(bool)), this, SLOT(connButtonPress()));
|
||||
connect(ui->actionOpen_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleLoadFile()));
|
||||
@@ -96,6 +97,12 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
if (graphingWindow) delete graphingWindow;
|
||||
if (frameInfoWindow) delete frameInfoWindow;
|
||||
if (playbackWindow) delete playbackWindow;
|
||||
if (flowViewWindow) delete flowViewWindow;
|
||||
if (frameSenderWindow) delete frameSenderWindow;
|
||||
|
||||
delete dbcHandler;
|
||||
|
||||
serialWorkerThread.quit();
|
||||
serialWorkerThread.wait();
|
||||
@@ -612,148 +619,7 @@ void MainWindow::handleLoadDBC()
|
||||
}
|
||||
|
||||
//right now there is only one file type that can be loaded here so just do it.
|
||||
QFile *inFile = new QFile(filename);
|
||||
QString line;
|
||||
QRegularExpression regex;
|
||||
QRegularExpressionMatch match;
|
||||
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
qDebug() << "Starting DBC load";
|
||||
|
||||
while (!inFile->atEnd()) {
|
||||
line = QString(inFile->readLine().toUpper().simplified());
|
||||
if (line.startsWith("BO_ "))
|
||||
{
|
||||
qDebug() << "Found a BO line";
|
||||
regex.setPattern("^BO\\_ (\\w+) (\\w+) *: (\\w+) (\\w+)");
|
||||
match = regex.match(line);
|
||||
//captured 1 = the ID in decimal
|
||||
//captured 2 = The message name
|
||||
//captured 3 = the message length
|
||||
//captured 4 = the NODE responsible for this message
|
||||
if (match.hasMatch())
|
||||
{
|
||||
}
|
||||
}
|
||||
if (line.startsWith("SG_ "))
|
||||
{
|
||||
qDebug() << "Found a SG line";
|
||||
regex.setPattern("^SG\\_ (\\w+) : (\\d+)\\|(\\d+)@(\\d+)([\\+|\\-]) \\(([0-9.+\\-eE]+),([0-9.+\\-eE]+)\\) \\[([0-9.+\\-eE]+)\\|([0-9.+\\-eE]+)\\] \\\"(.*)\\\" (.*)");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the signal name
|
||||
//captured 2 is the starting bit
|
||||
//captured 3 is the length in bits
|
||||
//captured 4 is the byte order / value type
|
||||
//captured 5 specifies signed/unsigned for ints
|
||||
//captured 6 is the scaling factor
|
||||
//captured 7 is the offset
|
||||
//captured 8 is the minimum value
|
||||
//captured 9 is the maximum value
|
||||
//captured 10 is the unit
|
||||
//captured 11 is the receiving node
|
||||
|
||||
if (match.hasMatch())
|
||||
{
|
||||
}
|
||||
}
|
||||
if (line.startsWith("BU_:"))
|
||||
{
|
||||
qDebug() << "Found a BU line";
|
||||
regex.setPattern("^BU\\_\\:(.*)");
|
||||
match = regex.match(line);
|
||||
//captured 1 = a list of node names separated by spaces. No idea how many yet
|
||||
if (match.hasMatch())
|
||||
{
|
||||
QStringList nodeStrings = match.captured(1).split(' ');
|
||||
qDebug() << "Found " << nodeStrings.count() << " node names";
|
||||
for (int i = 0; i < nodeStrings.count(); i++)
|
||||
{
|
||||
qDebug() << nodeStrings[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line.startsWith("CM_ SG_ "))
|
||||
{
|
||||
qDebug() << "Found an SG comment line";
|
||||
regex.setPattern("^CM\\_ SG\\_ *(\\w+) *(\\w+) *\\\"(.*)\\\";");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against to get to the message
|
||||
//captured 2 is the signal name from that message
|
||||
//captured 3 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(3);
|
||||
}
|
||||
}
|
||||
if (line.startsWith("CM_ BO_ "))
|
||||
{
|
||||
qDebug() << "Found a BO comment line";
|
||||
regex.setPattern("^CM\\_ BO\\_ *(\\w+) *\\\"(.*)\\\";");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against to get to the message
|
||||
//captured 2 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(2);
|
||||
}
|
||||
|
||||
}
|
||||
if (line.startsWith("CM_ BU_ "))
|
||||
{
|
||||
qDebug() << "Found a BU comment line";
|
||||
regex.setPattern("^CM\\_ BU\\_ *(\\w+) *\\\"(.*)\\\";");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the Node name
|
||||
//captured 2 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(2);
|
||||
}
|
||||
}
|
||||
//VAL_ (1090) (VCUPresentParkLightOC) (1 "Error present" 0 "Error not present") ;
|
||||
if (line.startsWith("VAL_ "))
|
||||
{
|
||||
qDebug() << "Found a value definition line";
|
||||
regex.setPattern("^VAL\\_ (\\w+) (\\w+) (.*);");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against
|
||||
//captured 2 is the signal name to match against
|
||||
//captured 3 is a series of values in the form (number "text") that is, all sep'd by spaces
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Data was: " << match.captured(3);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(2);
|
||||
}
|
||||
}
|
||||
if (line.startsWith("BA_DEF_ BO_ "))
|
||||
{
|
||||
|
||||
}
|
||||
if (line.startsWith("BA_DEF_ BU_ "))
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
inFile->close();
|
||||
|
||||
dbcHandler->loadDBCFile(filename);
|
||||
}
|
||||
|
||||
void MainWindow::handleSaveDBC()
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "frameplaybackwindow.h"
|
||||
#include "flowviewwindow.h"
|
||||
#include "framesenderwindow.h"
|
||||
#include "dbchandler.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -58,6 +59,7 @@ private:
|
||||
FramePlaybackWindow *playbackWindow;
|
||||
FlowViewWindow *flowViewWindow;
|
||||
FrameSenderWindow *frameSenderWindow;
|
||||
DBCHandler *dbcHandler;
|
||||
void loadCRTDFile(QString);
|
||||
void loadNativeCSVFile(QString);
|
||||
void loadGenericCSVFile(QString);
|
||||
|
||||
Reference in New Issue
Block a user