VAL_TABLE_ support
This commit is contained in:
+7
-1
@@ -66,6 +66,13 @@ public:
|
|||||||
QString descript;
|
QString descript;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DBC_VAL_TABLE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString name;
|
||||||
|
QList<DBC_VAL_ENUM_ENTRY> valList;
|
||||||
|
};
|
||||||
|
|
||||||
class DBC_NODE
|
class DBC_NODE
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -176,4 +183,3 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
#endif // DBC_CLASSES_H
|
#endif // DBC_CLASSES_H
|
||||||
|
|
||||||
|
|||||||
+118
-18
@@ -16,6 +16,28 @@
|
|||||||
|
|
||||||
DBCHandler* DBCHandler::instance = nullptr;
|
DBCHandler* DBCHandler::instance = nullptr;
|
||||||
|
|
||||||
|
static bool parseValueDescriptions(QString tokenString, QList<DBC_VAL_ENUM_ENTRY> &values)
|
||||||
|
{
|
||||||
|
QRegularExpression regex;
|
||||||
|
QRegularExpressionMatch match;
|
||||||
|
DBC_VAL_ENUM_ENTRY val;
|
||||||
|
|
||||||
|
values.clear();
|
||||||
|
tokenString = tokenString.trimmed();
|
||||||
|
while (tokenString.length() > 2)
|
||||||
|
{
|
||||||
|
regex.setPattern("^([+-]?\\d+) \\\"(.*?)\\\"(.*)");
|
||||||
|
match = regex.match(tokenString);
|
||||||
|
if (!match.hasMatch()) return false;
|
||||||
|
|
||||||
|
val.value = match.captured(1).toInt();
|
||||||
|
val.descript = match.captured(2);
|
||||||
|
values.append(val);
|
||||||
|
tokenString = match.captured(3).trimmed();
|
||||||
|
}
|
||||||
|
return values.count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
DBC_SIGNAL* DBCSignalHandler::findSignalByIdx(int idx)
|
DBC_SIGNAL* DBCSignalHandler::findSignalByIdx(int idx)
|
||||||
{
|
{
|
||||||
if (sigs.count() == 0) return nullptr;
|
if (sigs.count() == 0) return nullptr;
|
||||||
@@ -316,6 +338,8 @@ DBCFile::DBCFile(const DBCFile& cpy) : QObject()
|
|||||||
assocBuses = cpy.assocBuses;
|
assocBuses = cpy.assocBuses;
|
||||||
dbc_nodes.clear();
|
dbc_nodes.clear();
|
||||||
dbc_nodes.append(cpy.dbc_nodes);
|
dbc_nodes.append(cpy.dbc_nodes);
|
||||||
|
dbc_value_tables.clear();
|
||||||
|
dbc_value_tables.append(cpy.dbc_value_tables);
|
||||||
dbc_attributes.clear();
|
dbc_attributes.clear();
|
||||||
dbc_attributes.append(cpy.dbc_attributes);
|
dbc_attributes.append(cpy.dbc_attributes);
|
||||||
isDirty = cpy.isDirty;
|
isDirty = cpy.isDirty;
|
||||||
@@ -331,6 +355,8 @@ DBCFile& DBCFile::operator=(const DBCFile& cpy)
|
|||||||
assocBuses = cpy.assocBuses;
|
assocBuses = cpy.assocBuses;
|
||||||
dbc_nodes.clear();
|
dbc_nodes.clear();
|
||||||
dbc_nodes.append(cpy.dbc_nodes);
|
dbc_nodes.append(cpy.dbc_nodes);
|
||||||
|
dbc_value_tables.clear();
|
||||||
|
dbc_value_tables.append(cpy.dbc_value_tables);
|
||||||
dbc_attributes.clear();
|
dbc_attributes.clear();
|
||||||
dbc_attributes.append(cpy.dbc_attributes);
|
dbc_attributes.append(cpy.dbc_attributes);
|
||||||
}
|
}
|
||||||
@@ -382,6 +408,19 @@ DBC_NODE* DBCFile::findNodeByNameAndComment(QString fullname)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBC_VAL_TABLE* DBCFile::findValueTableByName(QString name)
|
||||||
|
{
|
||||||
|
if (dbc_value_tables.length() == 0) return nullptr;
|
||||||
|
for (int i = 0; i < dbc_value_tables.length(); i++)
|
||||||
|
{
|
||||||
|
if (name.compare(dbc_value_tables[i].name, Qt::CaseInsensitive) == 0)
|
||||||
|
{
|
||||||
|
return &dbc_value_tables[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QString DBCFile::getFullFilename()
|
QString DBCFile::getFullFilename()
|
||||||
{
|
{
|
||||||
return filePath + fileName;
|
return filePath + fileName;
|
||||||
@@ -712,6 +751,29 @@ bool DBCFile::parseSignalValueTypeLine(QString line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DBCFile::parseValueTableLine(QString line)
|
||||||
|
{
|
||||||
|
QRegularExpression regex;
|
||||||
|
QRegularExpressionMatch match;
|
||||||
|
|
||||||
|
regex.setPattern("^VAL\\_TABLE\\_ ([-\\w]+) (.*);");
|
||||||
|
match = regex.match(line);
|
||||||
|
//captured 1 is the table name
|
||||||
|
//captured 2 is a series of values in the form (number "text")
|
||||||
|
if (match.hasMatch())
|
||||||
|
{
|
||||||
|
DBC_VAL_TABLE table;
|
||||||
|
table.name = match.captured(1);
|
||||||
|
if (!parseValueDescriptions(match.captured(2), table.valList)) return false;
|
||||||
|
|
||||||
|
DBC_VAL_TABLE *existingTable = findValueTableByName(table.name);
|
||||||
|
if (existingTable) existingTable->valList = table.valList;
|
||||||
|
else dbc_value_tables.append(table);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool DBCFile::parseValueLine(QString line)
|
bool DBCFile::parseValueLine(QString line)
|
||||||
{
|
{
|
||||||
QRegularExpression regex;
|
QRegularExpression regex;
|
||||||
@@ -733,25 +795,18 @@ bool DBCFile::parseValueLine(QString line)
|
|||||||
if (sig != nullptr)
|
if (sig != nullptr)
|
||||||
{
|
{
|
||||||
QString tokenString = match.captured(3);
|
QString tokenString = match.captured(3);
|
||||||
DBC_VAL_ENUM_ENTRY val;
|
QList<DBC_VAL_ENUM_ENTRY> values;
|
||||||
while (tokenString.length() > 2)
|
DBC_VAL_TABLE *valueTable = findValueTableByName(tokenString.trimmed());
|
||||||
|
if (valueTable)
|
||||||
{
|
{
|
||||||
regex.setPattern("(\\d+) \\\"(.*?)\\\"(.*)");
|
sig->valList = valueTable->valList;
|
||||||
match = regex.match(tokenString);
|
return true;
|
||||||
if (match.hasMatch())
|
}
|
||||||
{
|
if (parseValueDescriptions(tokenString, values))
|
||||||
val.value = match.captured(1).toULong() & 0x1FFFFFFFul;
|
{
|
||||||
val.descript = match.captured(2);
|
sig->valList.append(values);
|
||||||
//qDebug() << "sig val " << val.value << " desc " <<val.descript;
|
return true;
|
||||||
sig->valList.append(val);
|
|
||||||
int rightSize = tokenString.length() - match.captured(1).length() - match.captured(2).length() - 4;
|
|
||||||
if (rightSize > 0) tokenString = tokenString.right(rightSize);
|
|
||||||
else tokenString = "";
|
|
||||||
//qDebug() << "New token string: " << tokenString;
|
|
||||||
}
|
|
||||||
else tokenString = "";
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -919,6 +974,8 @@ bool DBCFile::loadFile(QString fileName)
|
|||||||
QString fileBaseName = QFileInfo(fileName).baseName();
|
QString fileBaseName = QFileInfo(fileName).baseName();
|
||||||
|
|
||||||
bool inMultilineBU = false;
|
bool inMultilineBU = false;
|
||||||
|
bool inMultilineValTable = false;
|
||||||
|
QString multilineValTable;
|
||||||
|
|
||||||
qDebug() << "DBC File: " << fileName;
|
qDebug() << "DBC File: " << fileName;
|
||||||
|
|
||||||
@@ -931,6 +988,7 @@ bool DBCFile::loadFile(QString fileName)
|
|||||||
|
|
||||||
qDebug() << "Starting DBC load";
|
qDebug() << "Starting DBC load";
|
||||||
dbc_nodes.clear();
|
dbc_nodes.clear();
|
||||||
|
dbc_value_tables.clear();
|
||||||
messageHandler->removeAllMessages();
|
messageHandler->removeAllMessages();
|
||||||
messageHandler->setMatchingCriteria(EXACT);
|
messageHandler->setMatchingCriteria(EXACT);
|
||||||
messageHandler->setFilterLabeling(false);
|
messageHandler->setFilterLabeling(false);
|
||||||
@@ -962,6 +1020,18 @@ bool DBCFile::loadFile(QString fileName)
|
|||||||
else inMultilineBU = false;
|
else inMultilineBU = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inMultilineValTable)
|
||||||
|
{
|
||||||
|
multilineValTable.append(" " + line);
|
||||||
|
if (line.endsWith(";"))
|
||||||
|
{
|
||||||
|
parseValueTableLine(multilineValTable);
|
||||||
|
multilineValTable.clear();
|
||||||
|
inMultilineValTable = false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!inMultilineBU)
|
if (!inMultilineBU)
|
||||||
{
|
{
|
||||||
if (line.startsWith("BO_ ")) //defines a message
|
if (line.startsWith("BO_ ")) //defines a message
|
||||||
@@ -1064,6 +1134,19 @@ bool DBCFile::loadFile(QString fileName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (line.startsWith("VAL_TABLE_ "))
|
||||||
|
{
|
||||||
|
if (line.endsWith(";"))
|
||||||
|
{
|
||||||
|
parseValueTableLine(line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
multilineValTable = line;
|
||||||
|
inMultilineValTable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//VAL_ (1090) (VCUPresentParkLightOC) (1 "Error present" 0 "Error not present") ;
|
//VAL_ (1090) (VCUPresentParkLightOC) (1 "Error present" 0 "Error not present") ;
|
||||||
if (line.startsWith("VAL_ "))
|
if (line.startsWith("VAL_ "))
|
||||||
{
|
{
|
||||||
@@ -1347,7 +1430,7 @@ bool DBCFile::saveFile(QString fileName)
|
|||||||
int msgNumber = 1;
|
int msgNumber = 1;
|
||||||
int sigNumber = 1;
|
int sigNumber = 1;
|
||||||
QFile *outFile = new QFile(fileName);
|
QFile *outFile = new QFile(fileName);
|
||||||
QString nodesOutput, msgOutput, commentsOutput, valuesOutput, extMultiplexOutput;
|
QString nodesOutput, msgOutput, commentsOutput, valuesOutput, valueTableOutput, extMultiplexOutput;
|
||||||
QString defaultsOutput, attrValOutput, sigValTypeOutput;
|
QString defaultsOutput, attrValOutput, sigValTypeOutput;
|
||||||
bool hasExtendedMultiplexing = false;
|
bool hasExtendedMultiplexing = false;
|
||||||
|
|
||||||
@@ -1433,6 +1516,23 @@ bool DBCFile::saveFile(QString fileName)
|
|||||||
nodesOutput.append("\n");
|
nodesOutput.append("\n");
|
||||||
outFile->write(nodesOutput.toUtf8());
|
outFile->write(nodesOutput.toUtf8());
|
||||||
|
|
||||||
|
for (int x = 0; x < dbc_value_tables.count(); x++)
|
||||||
|
{
|
||||||
|
DBC_VAL_TABLE table = dbc_value_tables[x];
|
||||||
|
valueTableOutput.append("VAL_TABLE_ " + table.name);
|
||||||
|
for (int v = 0; v < table.valList.count(); v++)
|
||||||
|
{
|
||||||
|
DBC_VAL_ENUM_ENTRY val = table.valList[v];
|
||||||
|
valueTableOutput.append(" " + QString::number(val.value) + " \"" + val.descript + "\"");
|
||||||
|
}
|
||||||
|
valueTableOutput.append(";\n");
|
||||||
|
}
|
||||||
|
if (!valueTableOutput.isEmpty())
|
||||||
|
{
|
||||||
|
outFile->write(valueTableOutput.toUtf8());
|
||||||
|
valueTableOutput.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//Go through all messages one at at time issuing the message line then all signals in there too.
|
//Go through all messages one at at time issuing the message line then all signals in there too.
|
||||||
for (int x = 0; x < messageHandler->getCount(); x++)
|
for (int x = 0; x < messageHandler->getCount(); x++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public:
|
|||||||
DBC_NODE *findNodeByName(QString name);
|
DBC_NODE *findNodeByName(QString name);
|
||||||
DBC_NODE *findNodeByNameAndComment(QString fullname);
|
DBC_NODE *findNodeByNameAndComment(QString fullname);
|
||||||
DBC_NODE *findNodeByIdx(int idx);
|
DBC_NODE *findNodeByIdx(int idx);
|
||||||
|
DBC_VAL_TABLE *findValueTableByName(QString name);
|
||||||
DBC_ATTRIBUTE *findAttributeByName(QString name, DBC_ATTRIBUTE_TYPE type = ATTR_TYPE_ANY);
|
DBC_ATTRIBUTE *findAttributeByName(QString name, DBC_ATTRIBUTE_TYPE type = ATTR_TYPE_ANY);
|
||||||
DBC_ATTRIBUTE *findAttributeByIdx(int idx);
|
DBC_ATTRIBUTE *findAttributeByIdx(int idx);
|
||||||
void findAttributesByType(DBC_ATTRIBUTE_TYPE typ, QList<DBC_ATTRIBUTE> *list);
|
void findAttributesByType(DBC_ATTRIBUTE_TYPE typ, QList<DBC_ATTRIBUTE> *list);
|
||||||
@@ -93,6 +94,7 @@ public:
|
|||||||
|
|
||||||
DBCMessageHandler *messageHandler;
|
DBCMessageHandler *messageHandler;
|
||||||
QList<DBC_NODE> dbc_nodes;
|
QList<DBC_NODE> dbc_nodes;
|
||||||
|
QList<DBC_VAL_TABLE> dbc_value_tables;
|
||||||
QList<DBC_ATTRIBUTE> dbc_attributes;
|
QList<DBC_ATTRIBUTE> dbc_attributes;
|
||||||
private:
|
private:
|
||||||
QString fileName;
|
QString fileName;
|
||||||
@@ -105,6 +107,7 @@ private:
|
|||||||
DBC_SIGNAL* parseSignalLine(QString line, DBC_MESSAGE *msg);
|
DBC_SIGNAL* parseSignalLine(QString line, DBC_MESSAGE *msg);
|
||||||
bool parseSignalMultiplexValueLine(QString line);
|
bool parseSignalMultiplexValueLine(QString line);
|
||||||
DBC_MESSAGE* parseMessageLine(QString line);
|
DBC_MESSAGE* parseMessageLine(QString line);
|
||||||
|
bool parseValueTableLine(QString line);
|
||||||
bool parseValueLine(QString line);
|
bool parseValueLine(QString line);
|
||||||
bool parseSignalValueTypeLine(QString line);
|
bool parseSignalValueTypeLine(QString line);
|
||||||
bool parseAttributeLine(QString line);
|
bool parseAttributeLine(QString line);
|
||||||
|
|||||||
Reference in New Issue
Block a user