Fixed several seg faults and other errors in DBC code
This commit is contained in:
@@ -6,8 +6,30 @@
|
||||
DBC_MESSAGE::DBC_MESSAGE()
|
||||
{
|
||||
sigHandler = new DBCSignalHandler;
|
||||
ID = 0;
|
||||
len = 0;
|
||||
multiplexorSignal = nullptr;
|
||||
sender = nullptr;
|
||||
}
|
||||
|
||||
DBC_SIGNAL::DBC_SIGNAL()
|
||||
{
|
||||
bias = 0;
|
||||
isMultiplexed = false;
|
||||
isMultiplexor = false;
|
||||
max = 1;
|
||||
min = 0;
|
||||
multiplexValue = 0;
|
||||
factor = 1.0;
|
||||
intelByteOrder = false;
|
||||
parentMessage = nullptr;
|
||||
receiver = nullptr;
|
||||
signalSize = 1;
|
||||
startBit = 1;
|
||||
valType = DBC_SIG_VAL_TYPE::UNSIGNED_INT;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
The way that the DBC file format works is kind of weird... For intel format signals you count up
|
||||
from the start bit to the end bit which is (startbit + signallength - 1). At each point
|
||||
|
||||
@@ -106,6 +106,7 @@ public: //TODO: this is sloppy. It shouldn't all be public!
|
||||
QList<DBC_ATTRIBUTE_VALUE> attributes;
|
||||
QList<DBC_VAL_ENUM_ENTRY> valList;
|
||||
|
||||
DBC_SIGNAL();
|
||||
bool processAsText(const CANFrame &frame, QString &outString, bool outputName = true);
|
||||
bool processAsInt(const CANFrame &frame, int32_t &outValue);
|
||||
bool processAsDouble(const CANFrame &frame, double &outValue);
|
||||
|
||||
+46
-32
@@ -760,7 +760,7 @@ bool DBCFile::parseDefaultAttrLine(QString line)
|
||||
return false;
|
||||
}
|
||||
|
||||
void DBCFile::loadFile(QString fileName)
|
||||
bool DBCFile::loadFile(QString fileName)
|
||||
{
|
||||
QFile *inFile = new QFile(fileName);
|
||||
QString line, rawLine;
|
||||
@@ -778,7 +778,8 @@ void DBCFile::loadFile(QString fileName)
|
||||
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
delete inFile;
|
||||
return;
|
||||
qDebug() << "Could not load the file!";
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Starting DBC load";
|
||||
@@ -1040,6 +1041,7 @@ void DBCFile::loadFile(QString fileName)
|
||||
filePath = fileName.left(fileName.length() - this->fileName.length());
|
||||
assocBuses = -1;
|
||||
isDirty = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant DBCFile::processAttributeVal(QString input, DBC_ATTRIBUTE_VAL_TYPE typ)
|
||||
@@ -1157,7 +1159,7 @@ bool DBCFile::parseAttribute(QString inpString, DBC_ATTRIBUTE &attr)
|
||||
return goodAttr;
|
||||
}
|
||||
|
||||
void DBCFile::saveFile(QString fileName)
|
||||
bool DBCFile::saveFile(QString fileName)
|
||||
{
|
||||
int nodeNumber = 1;
|
||||
int msgNumber = 1;
|
||||
@@ -1169,7 +1171,7 @@ void DBCFile::saveFile(QString fileName)
|
||||
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
delete outFile;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
//right now it outputs a standard hard coded boilerplate
|
||||
@@ -1455,6 +1457,7 @@ void DBCFile::saveFile(QString fileName)
|
||||
QStringList fileList = fileName.split('/');
|
||||
this->fileName = fileList[fileList.length() - 1]; //whoops... same name as parameter in this function.
|
||||
filePath = fileName.left(fileName.length() - this->fileName.length());
|
||||
return true;
|
||||
}
|
||||
|
||||
void DBCHandler::saveDBCFile(int idx)
|
||||
@@ -1544,9 +1547,16 @@ int DBCHandler::createBlankFile()
|
||||
DBCFile* DBCHandler::loadDBCFile(QString filename)
|
||||
{
|
||||
DBCFile newFile;
|
||||
newFile.loadFile(filename);
|
||||
loadedFiles.append(newFile);
|
||||
return &loadedFiles.last();
|
||||
if (newFile.loadFile(filename))
|
||||
{
|
||||
loadedFiles.append(newFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
//createBlankFile();
|
||||
}
|
||||
if (loadedFiles.count()> 0) return &loadedFiles.last();
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
//the only reason to even bother sending the index is to see if
|
||||
@@ -1846,40 +1856,44 @@ DBCHandler::DBCHandler()
|
||||
// Load previously saved DBC file settings
|
||||
QSettings settings;
|
||||
int filecount = settings.value("DBC/FileCount", 0).toInt();
|
||||
qDebug() << "Previously loaded DBC file count: " << filecount;
|
||||
for (int i=0; i<filecount; i++)
|
||||
{
|
||||
QString filename = settings.value("DBC/Filename_" + QString(i),"").toString();
|
||||
DBCFile * file = loadDBCFile(filename);
|
||||
int bus = settings.value("DBC/AssocBus_" + QString(i),0).toInt();
|
||||
file->setAssocBus(bus);
|
||||
if (file)
|
||||
{
|
||||
int bus = settings.value("DBC/AssocBus_" + QString(i),0).toInt();
|
||||
file->setAssocBus(bus);
|
||||
|
||||
MatchingCriteria_t matchingCriteria = (MatchingCriteria_t)settings.value("DBC/MatchingCriteria_" + QString(i),0).toInt();
|
||||
MatchingCriteria_t matchingCriteria = (MatchingCriteria_t)settings.value("DBC/MatchingCriteria_" + QString(i),0).toInt();
|
||||
|
||||
DBC_ATTRIBUTE attr;
|
||||
DBC_ATTRIBUTE attr;
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = matchingCriteria;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "matchingcriteria";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setMatchingCriteria(matchingCriteria);
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = matchingCriteria;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "matchingcriteria";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setMatchingCriteria(matchingCriteria);
|
||||
|
||||
bool filterLabeling = settings.value("DBC/FilterLabeling_" + QString(i),0).toBool();
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = filterLabeling;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "filterlabeling";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setFilterLabeling(filterLabeling);
|
||||
bool filterLabeling = settings.value("DBC/FilterLabeling_" + QString(i),0).toBool();
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = filterLabeling;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "filterlabeling";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setFilterLabeling(filterLabeling);
|
||||
|
||||
qInfo() << "Loaded DBC file" << filename << " (bus:" << bus
|
||||
<< ", Matching Criteria:" << (int)matchingCriteria << "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")";
|
||||
qInfo() << "Loaded DBC file" << filename << " (bus:" << bus
|
||||
<< ", Matching Criteria:" << (int)matchingCriteria << "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -76,8 +76,8 @@ public:
|
||||
DBC_ATTRIBUTE *findAttributeByName(QString name);
|
||||
DBC_ATTRIBUTE *findAttributeByIdx(int idx);
|
||||
void findAttributesByType(DBC_ATTRIBUTE_TYPE typ, QList<DBC_ATTRIBUTE> *list);
|
||||
void saveFile(QString);
|
||||
void loadFile(QString);
|
||||
bool saveFile(QString);
|
||||
bool loadFile(QString);
|
||||
QString getFullFilename();
|
||||
QString getFilename();
|
||||
QString getPath();
|
||||
|
||||
@@ -370,8 +370,8 @@ void DBCMainEditor::updatedMessage(DBC_MESSAGE *msg)
|
||||
item->setText(0, msgInfo);
|
||||
//editor could have changed the parent Node too. Have to figure out which node
|
||||
//is parent in the GUI and compare that to parent in the data.
|
||||
DBC_NODE *oldParent = dbcFile->findNodeByName(item->parent()->text(0));
|
||||
if (oldParent != msg->sender)
|
||||
DBC_NODE *oldParent = dbcFile->findNodeByName(item->parent()->text(0).split(" - ")[0]);
|
||||
if (oldParent != msg->sender && oldParent)
|
||||
{
|
||||
qDebug() << "Changed parent of message. Trying to rehome it.";
|
||||
QTreeWidgetItem *newParent = nullptr;
|
||||
@@ -448,7 +448,11 @@ void DBCMainEditor::newMessage()
|
||||
nodeItem = msgItem->parent();
|
||||
}
|
||||
|
||||
DBC_NODE *node = dbcFile->findNodeByName(nodeItem->data(0, Qt::DisplayRole).toString());
|
||||
//if there was a comment this will find the location of the comment and snip it out.
|
||||
QString nodeName = nodeItem->data(0, Qt::DisplayRole).toString().split(" - ")[0];
|
||||
|
||||
DBC_NODE *node = dbcFile->findNodeByName(nodeName);
|
||||
if (!node) node = dbcFile->findNodeByIdx(0);
|
||||
DBC_MESSAGE msg;
|
||||
DBC_MESSAGE *msgPtr;
|
||||
if (msgItem)
|
||||
@@ -467,14 +471,14 @@ void DBCMainEditor::newMessage()
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.name = nodeItem->text(0) + "Msg" + QString::number(randGen.bounded(500));
|
||||
msg.name = nodeName + "Msg" + QString::number(randGen.bounded(500));
|
||||
msg.ID = 0;
|
||||
msg.len = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.name = nodeItem->text(0) + "Msg" + QString::number(randGen.bounded(500));
|
||||
msg.name = nodeName + "Msg" + QString::number(randGen.bounded(500));
|
||||
msg.ID = 0;
|
||||
msg.len = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user