More implementation of DBC loader, added fields to status bar on main screen.

This commit is contained in:
Collin Kidder
2015-05-18 22:56:56 -04:00
parent dbf8507b28
commit 2841a2a72c
5 changed files with 107 additions and 1 deletions
+4
View File
@@ -31,6 +31,7 @@ enum DBC_ATTRIBUTE_VAL_TYPE
class DBC_ATTRIBUTE
{
public:
QString name;
DBC_ATTRIBUTE_VAL_TYPE type;
double startVal;
@@ -40,6 +41,7 @@ class DBC_ATTRIBUTE
class DBC_VAL
{
public:
int value;
QString descript;
};
@@ -54,6 +56,7 @@ public:
class DBC_SIGNAL
{
public:
QString name;
int startBit;
int signalSize;
@@ -72,6 +75,7 @@ class DBC_SIGNAL
class DBC_MESSAGE
{
public:
int ID;
QString name;
QString comment;
+87 -1
View File
@@ -15,6 +15,7 @@ void DBCHandler::loadDBCFile(QString filename)
QString line;
QRegularExpression regex;
QRegularExpressionMatch match;
DBC_MESSAGE *currentMessage;
qDebug() << "DBC File: " << filename;
@@ -36,6 +37,13 @@ void DBCHandler::loadDBCFile(QString filename)
//captured 4 = the NODE responsible for this message
if (match.hasMatch())
{
DBC_MESSAGE msg;
msg.ID = match.captured(1).toInt(); //the ID is always stored in decimal format
msg.name = match.captured(2);
msg.len = match.captured(3).toInt();
msg.sender = findNodeByName(match.captured(4));
dbc_messages.append(msg);
currentMessage = &dbc_messages.last();
}
}
if (line.startsWith("SG_ "))
@@ -57,6 +65,41 @@ void DBCHandler::loadDBCFile(QString filename)
if (match.hasMatch())
{
DBC_SIGNAL sig;
sig.name = match.captured(1);
sig.startBit = match.captured(2).toInt();
sig.signalSize = match.captured(3).toInt();
int val = match.captured(4).toInt();
if (val < 2)
{
if (match.captured(5) == "+") sig.valType = UNSIGNED_INT;
else sig.valType = SIGNED_INT;
}
switch (val)
{
case 0:
sig.intelByteOrder = true;
break;
case 1:
sig.intelByteOrder = false;
break;
case 2:
sig.valType = SP_FLOAT;
break;
case 3:
sig.valType = DP_FLOAT;
break;
case 4:
sig.valType = STRING;
break;
}
sig.factor = match.captured(6).toDouble();
sig.bias = match.captured(7).toDouble();
sig.min = match.captured(8).toDouble();
sig.max = match.captured(9).toDouble();
sig.unitName = match.captured(10);
sig.receiver = findNodeByName(match.captured(11));
currentMessage->msgSignals.append(sig);
}
}
if (line.startsWith("BU_:"))
@@ -71,7 +114,13 @@ void DBCHandler::loadDBCFile(QString filename)
qDebug() << "Found " << nodeStrings.count() << " node names";
for (int i = 0; i < nodeStrings.count(); i++)
{
qDebug() << nodeStrings[i];
//qDebug() << nodeStrings[i];
if (nodeStrings[i].length() > 1)
{
DBC_NODE node;
node.name = nodeStrings[i];
dbc_nodes.append(node);
}
}
}
}
@@ -155,3 +204,40 @@ void DBCHandler::loadDBCFile(QString filename)
}
inFile->close();
}
DBC_NODE *DBCHandler::findNodeByName(QString name)
{
for (int i = 0; i < dbc_nodes.length(); i++)
{
if (dbc_nodes[i].name == name)
{
return &dbc_nodes[i];
}
}
return NULL;
}
DBC_MESSAGE *DBCHandler::findMsgByID(int id)
{
for (int i = 0; i < dbc_messages.length(); i++)
{
if (dbc_messages[i].ID == id)
{
return &dbc_messages[i];
}
}
return NULL;
}
DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name)
{
for (int i = 0; i < msg->msgSignals.length(); i++)
{
if (msg->msgSignals[i].name == name)
{
return &msg->msgSignals[i];
}
}
return NULL;
}
+4
View File
@@ -18,6 +18,10 @@ public slots:
private:
QList<DBC_NODE> dbc_nodes;
QList<DBC_MESSAGE> dbc_messages;
DBC_NODE *findNodeByName(QString name);
DBC_MESSAGE *findMsgByID(int id);
DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name);
};
#endif // DBCHANDLER_H
+9
View File
@@ -91,6 +91,12 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionEdit_Messages_Signals, SIGNAL(triggered(bool)), this, SLOT(showEditSignalsWindow()));
connect(ui->actionSave_DBC_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveDBC()));
lbStatusConnected.setText(tr("Not connected"));
lbStatusBauds.setText(tr("Baud 1: 0 Baud 2: 0"));
lbStatusDatabase.setText(tr("No database loaded"));
ui->statusBar->addWidget(&lbStatusConnected);
ui->statusBar->addWidget(&lbStatusBauds);
ui->statusBar->addWidget(&lbStatusDatabase);
}
MainWindow::~MainWindow()
@@ -178,6 +184,8 @@ void MainWindow::changeBaudRates()
}
emit updateBaudRates(Speed1, Speed2);
lbStatusBauds.setText(tr("Baud 1: ") + QString::number(Speed1) + tr(" Baud 2:") + QString::number(Speed2));
}
//CRTD format from Mark Webb-Johnson / OVMS project
@@ -654,6 +662,7 @@ void MainWindow::connButtonPress()
if (ports.at(x).portName() == ui->cbSerialPorts->currentText())
{
emit sendSerialPort(&ports[x]);
lbStatusConnected.setText(tr("Connected to port ") + ports[x].portName());
return;
}
}
+3
View File
@@ -60,6 +60,9 @@ private:
FlowViewWindow *flowViewWindow;
FrameSenderWindow *frameSenderWindow;
DBCHandler *dbcHandler;
QLabel lbStatusConnected;
QLabel lbStatusBauds;
QLabel lbStatusDatabase;
void loadCRTDFile(QString);
void loadNativeCSVFile(QString);
void loadGenericCSVFile(QString);