More implementation of DBC loader. The loading is pretty much complete now.
This commit is contained in:
+92
-15
@@ -23,12 +23,19 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
return;
|
||||
|
||||
qDebug() << "Starting DBC load";
|
||||
dbc_nodes.clear();
|
||||
dbc_messages.clear();
|
||||
|
||||
DBC_NODE falseNode;
|
||||
falseNode.name = "Vector__XXX";
|
||||
falseNode.comment = "Default node if none specified";
|
||||
dbc_nodes.append(falseNode);
|
||||
|
||||
while (!inFile->atEnd()) {
|
||||
line = QString(inFile->readLine().toUpper().simplified());
|
||||
line = QString(inFile->readLine().simplified());
|
||||
if (line.startsWith("BO_ "))
|
||||
{
|
||||
qDebug() << "Found a BO line";
|
||||
//qDebug() << "Found a BO line";
|
||||
regex.setPattern("^BO\\_ (\\w+) (\\w+) *: (\\w+) (\\w+)");
|
||||
match = regex.match(line);
|
||||
//captured 1 = the ID in decimal
|
||||
@@ -48,7 +55,7 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
}
|
||||
if (line.startsWith("SG_ "))
|
||||
{
|
||||
qDebug() << "Found a SG line";
|
||||
//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
|
||||
@@ -104,7 +111,7 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
}
|
||||
if (line.startsWith("BU_:"))
|
||||
{
|
||||
qDebug() << "Found a BU line";
|
||||
//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
|
||||
@@ -126,7 +133,7 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
}
|
||||
if (line.startsWith("CM_ SG_ "))
|
||||
{
|
||||
qDebug() << "Found an SG comment line";
|
||||
//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
|
||||
@@ -134,38 +141,56 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
//captured 3 is the comment itself
|
||||
if (match.hasMatch())
|
||||
{
|
||||
qDebug() << "Comment was: " << match.captured(3);
|
||||
//qDebug() << "Comment was: " << match.captured(3);
|
||||
DBC_MESSAGE *msg = findMsgByID(match.captured(1).toInt());
|
||||
if (msg != NULL)
|
||||
{
|
||||
DBC_SIGNAL *sig = findSignalByName(msg, match.captured(2));
|
||||
if (sig != NULL)
|
||||
{
|
||||
sig->comment = match.captured(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line.startsWith("CM_ BO_ "))
|
||||
{
|
||||
qDebug() << "Found a BO comment line";
|
||||
//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);
|
||||
//qDebug() << "Comment was: " << match.captured(2);
|
||||
DBC_MESSAGE *msg = findMsgByID(match.captured(1).toInt());
|
||||
if (msg != NULL)
|
||||
{
|
||||
msg->comment = match.captured(2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (line.startsWith("CM_ BU_ "))
|
||||
{
|
||||
qDebug() << "Found a BU comment line";
|
||||
//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);
|
||||
//qDebug() << "Comment was: " << match.captured(2);
|
||||
DBC_NODE *node = findNodeByName(match.captured(1));
|
||||
if (node != NULL)
|
||||
{
|
||||
node->comment = match.captured(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
//VAL_ (1090) (VCUPresentParkLightOC) (1 "Error present" 0 "Error not present") ;
|
||||
if (line.startsWith("VAL_ "))
|
||||
{
|
||||
qDebug() << "Found a value definition line";
|
||||
//qDebug() << "Found a value definition line";
|
||||
regex.setPattern("^VAL\\_ (\\w+) (\\w+) (.*);");
|
||||
match = regex.match(line);
|
||||
//captured 1 is the ID to match against
|
||||
@@ -173,7 +198,32 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
//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);
|
||||
//qDebug() << "Data was: " << match.captured(3);
|
||||
DBC_MESSAGE *msg = findMsgByID(match.captured(1).toInt());
|
||||
if (msg != NULL)
|
||||
{
|
||||
DBC_SIGNAL *sig = findSignalByName(msg, match.captured(2));
|
||||
if (sig != NULL)
|
||||
{
|
||||
QString tokenString = match.captured(3);
|
||||
DBC_VAL val;
|
||||
while (tokenString.length() > 2)
|
||||
{
|
||||
regex.setPattern("(\\d+) \\\"(.*?)\\\" (.*)");
|
||||
match = regex.match(tokenString);
|
||||
if (match.hasMatch())
|
||||
{
|
||||
val.value = match.captured(1).toInt();
|
||||
val.descript = match.captured(2);
|
||||
//qDebug() << "sig val " << val.value << " desc " <<val.descript;
|
||||
sig->valList.append(val);
|
||||
tokenString = tokenString.right(tokenString.length() - match.captured(1).length() - match.captured(2).length() - 4);
|
||||
//qDebug() << "New token string: " << tokenString;
|
||||
}
|
||||
else tokenString = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,14 +249,13 @@ void DBCHandler::loadDBCFile(QString filename)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
inFile->close();
|
||||
}
|
||||
|
||||
DBC_NODE *DBCHandler::findNodeByName(QString name)
|
||||
{
|
||||
if (dbc_nodes.length() == 0) return NULL;
|
||||
for (int i = 0; i < dbc_nodes.length(); i++)
|
||||
{
|
||||
if (dbc_nodes[i].name == name)
|
||||
@@ -219,6 +268,7 @@ DBC_NODE *DBCHandler::findNodeByName(QString name)
|
||||
|
||||
DBC_MESSAGE *DBCHandler::findMsgByID(int id)
|
||||
{
|
||||
if (dbc_messages.length() == 0) return NULL;
|
||||
for (int i = 0; i < dbc_messages.length(); i++)
|
||||
{
|
||||
if (dbc_messages[i].ID == id)
|
||||
@@ -231,6 +281,7 @@ DBC_MESSAGE *DBCHandler::findMsgByID(int id)
|
||||
|
||||
DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name)
|
||||
{
|
||||
if (msg->msgSignals.length() == 0) return NULL;
|
||||
for (int i = 0; i < msg->msgSignals.length(); i++)
|
||||
{
|
||||
if (msg->msgSignals[i].name == name)
|
||||
@@ -241,3 +292,29 @@ DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Dumps the messages, signals, values structs out in order to debugging console. Used only for debugging
|
||||
//not really meant for general consumption.
|
||||
void DBCHandler::listDebugging()
|
||||
{
|
||||
for (int i = 0; i < dbc_messages.length(); i++)
|
||||
{
|
||||
DBC_MESSAGE msg = dbc_messages.at(i);
|
||||
qDebug() << " ";
|
||||
qDebug() << "Msg ID: " << msg.ID << " Name: " << msg.name;
|
||||
|
||||
for (int j = 0; j < msg.msgSignals.length(); j++)
|
||||
{
|
||||
DBC_SIGNAL sig;
|
||||
sig = msg.msgSignals.at(j);
|
||||
qDebug() << " Signal Name: " << sig.name;
|
||||
qDebug() << " Start bit: " << sig.startBit;
|
||||
qDebug() << " Bit Length: " << sig.signalSize;
|
||||
if (sig.valList.length() > 1) qDebug() << " Values: ";
|
||||
for (int k = 0; k < sig.valList.length(); k++)
|
||||
{
|
||||
DBC_VAL val = sig.valList.at(k);
|
||||
qDebug() << " " << val.value << " Description: " << val.descript;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user