Fixed several seg faults and other errors in DBC code

This commit is contained in:
Collin Kidder
2021-02-17 21:19:30 -05:00
parent a5cf484e7c
commit a8cde9fc5f
5 changed files with 81 additions and 40 deletions
+22
View File
@@ -6,8 +6,30 @@
DBC_MESSAGE::DBC_MESSAGE() DBC_MESSAGE::DBC_MESSAGE()
{ {
sigHandler = new DBCSignalHandler; 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 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 from the start bit to the end bit which is (startbit + signallength - 1). At each point
+1
View File
@@ -106,6 +106,7 @@ public: //TODO: this is sloppy. It shouldn't all be public!
QList<DBC_ATTRIBUTE_VALUE> attributes; QList<DBC_ATTRIBUTE_VALUE> attributes;
QList<DBC_VAL_ENUM_ENTRY> valList; QList<DBC_VAL_ENUM_ENTRY> valList;
DBC_SIGNAL();
bool processAsText(const CANFrame &frame, QString &outString, bool outputName = true); bool processAsText(const CANFrame &frame, QString &outString, bool outputName = true);
bool processAsInt(const CANFrame &frame, int32_t &outValue); bool processAsInt(const CANFrame &frame, int32_t &outValue);
bool processAsDouble(const CANFrame &frame, double &outValue); bool processAsDouble(const CANFrame &frame, double &outValue);
+20 -6
View File
@@ -760,7 +760,7 @@ bool DBCFile::parseDefaultAttrLine(QString line)
return false; return false;
} }
void DBCFile::loadFile(QString fileName) bool DBCFile::loadFile(QString fileName)
{ {
QFile *inFile = new QFile(fileName); QFile *inFile = new QFile(fileName);
QString line, rawLine; QString line, rawLine;
@@ -778,7 +778,8 @@ void DBCFile::loadFile(QString fileName)
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
{ {
delete inFile; delete inFile;
return; qDebug() << "Could not load the file!";
return false;
} }
qDebug() << "Starting DBC load"; qDebug() << "Starting DBC load";
@@ -1040,6 +1041,7 @@ void DBCFile::loadFile(QString fileName)
filePath = fileName.left(fileName.length() - this->fileName.length()); filePath = fileName.left(fileName.length() - this->fileName.length());
assocBuses = -1; assocBuses = -1;
isDirty = false; isDirty = false;
return true;
} }
QVariant DBCFile::processAttributeVal(QString input, DBC_ATTRIBUTE_VAL_TYPE typ) QVariant DBCFile::processAttributeVal(QString input, DBC_ATTRIBUTE_VAL_TYPE typ)
@@ -1157,7 +1159,7 @@ bool DBCFile::parseAttribute(QString inpString, DBC_ATTRIBUTE &attr)
return goodAttr; return goodAttr;
} }
void DBCFile::saveFile(QString fileName) bool DBCFile::saveFile(QString fileName)
{ {
int nodeNumber = 1; int nodeNumber = 1;
int msgNumber = 1; int msgNumber = 1;
@@ -1169,7 +1171,7 @@ void DBCFile::saveFile(QString fileName)
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
{ {
delete outFile; delete outFile;
return; return false;
} }
//right now it outputs a standard hard coded boilerplate //right now it outputs a standard hard coded boilerplate
@@ -1455,6 +1457,7 @@ void DBCFile::saveFile(QString fileName)
QStringList fileList = fileName.split('/'); QStringList fileList = fileName.split('/');
this->fileName = fileList[fileList.length() - 1]; //whoops... same name as parameter in this function. this->fileName = fileList[fileList.length() - 1]; //whoops... same name as parameter in this function.
filePath = fileName.left(fileName.length() - this->fileName.length()); filePath = fileName.left(fileName.length() - this->fileName.length());
return true;
} }
void DBCHandler::saveDBCFile(int idx) void DBCHandler::saveDBCFile(int idx)
@@ -1544,9 +1547,16 @@ int DBCHandler::createBlankFile()
DBCFile* DBCHandler::loadDBCFile(QString filename) DBCFile* DBCHandler::loadDBCFile(QString filename)
{ {
DBCFile newFile; DBCFile newFile;
newFile.loadFile(filename); if (newFile.loadFile(filename))
{
loadedFiles.append(newFile); loadedFiles.append(newFile);
return &loadedFiles.last(); }
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 //the only reason to even bother sending the index is to see if
@@ -1846,10 +1856,13 @@ DBCHandler::DBCHandler()
// Load previously saved DBC file settings // Load previously saved DBC file settings
QSettings settings; QSettings settings;
int filecount = settings.value("DBC/FileCount", 0).toInt(); int filecount = settings.value("DBC/FileCount", 0).toInt();
qDebug() << "Previously loaded DBC file count: " << filecount;
for (int i=0; i<filecount; i++) for (int i=0; i<filecount; i++)
{ {
QString filename = settings.value("DBC/Filename_" + QString(i),"").toString(); QString filename = settings.value("DBC/Filename_" + QString(i),"").toString();
DBCFile * file = loadDBCFile(filename); DBCFile * file = loadDBCFile(filename);
if (file)
{
int bus = settings.value("DBC/AssocBus_" + QString(i),0).toInt(); int bus = settings.value("DBC/AssocBus_" + QString(i),0).toInt();
file->setAssocBus(bus); file->setAssocBus(bus);
@@ -1881,6 +1894,7 @@ DBCHandler::DBCHandler()
qInfo() << "Loaded DBC file" << filename << " (bus:" << bus qInfo() << "Loaded DBC file" << filename << " (bus:" << bus
<< ", Matching Criteria:" << (int)matchingCriteria << "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")"; << ", Matching Criteria:" << (int)matchingCriteria << "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")";
} }
}
} }
DBCHandler* DBCHandler::getReference() DBCHandler* DBCHandler::getReference()
+2 -2
View File
@@ -76,8 +76,8 @@ public:
DBC_ATTRIBUTE *findAttributeByName(QString name); DBC_ATTRIBUTE *findAttributeByName(QString name);
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);
void saveFile(QString); bool saveFile(QString);
void loadFile(QString); bool loadFile(QString);
QString getFullFilename(); QString getFullFilename();
QString getFilename(); QString getFilename();
QString getPath(); QString getPath();
+9 -5
View File
@@ -370,8 +370,8 @@ void DBCMainEditor::updatedMessage(DBC_MESSAGE *msg)
item->setText(0, msgInfo); item->setText(0, msgInfo);
//editor could have changed the parent Node too. Have to figure out which node //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. //is parent in the GUI and compare that to parent in the data.
DBC_NODE *oldParent = dbcFile->findNodeByName(item->parent()->text(0)); DBC_NODE *oldParent = dbcFile->findNodeByName(item->parent()->text(0).split(" - ")[0]);
if (oldParent != msg->sender) if (oldParent != msg->sender && oldParent)
{ {
qDebug() << "Changed parent of message. Trying to rehome it."; qDebug() << "Changed parent of message. Trying to rehome it.";
QTreeWidgetItem *newParent = nullptr; QTreeWidgetItem *newParent = nullptr;
@@ -448,7 +448,11 @@ void DBCMainEditor::newMessage()
nodeItem = msgItem->parent(); 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 msg;
DBC_MESSAGE *msgPtr; DBC_MESSAGE *msgPtr;
if (msgItem) if (msgItem)
@@ -467,14 +471,14 @@ void DBCMainEditor::newMessage()
} }
else 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.ID = 0;
msg.len = 0; msg.len = 0;
} }
} }
else 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.ID = 0;
msg.len = 0; msg.len = 0;
} }