- Save DBC file configuration when changed, and restore it when restarting the application (no need for manual entry everytime app is launched)

- Add GMLAN 29bit filtering feature. In addition to J1939 matching, it is now possible to match DBC messages using only the Arbitration Id (bits 14-26 of CAN Address), since  Priority id (higher bits) and Sender Id (lowest 13 bits) are not relevant when interpreting the CAN message content. This allows to use the excellent GM Global A DBC files on https://github.com/commaai/opendbc. Just remember to select the "GMLAN" matching criteria on DBC File manager.
- Add "Filter labeling" feature. Using loaded DBC files, it matches the filter Ids with DBC messages and shows them in filter windows. Labeling works in the main window (no need to set "Frame interpret" on, since this is a separate feature), as well as in Flow view, Frame data analysis, Playback and Fuzzzing windows. This makes it so much easier to concentrate on those CAN messages that matter. To use this feature, select global "Label filters using messages from DBC files" on Main Configuration page, and then enable the feature on individual DBC files (on DBC file manager) as needed. This is needed if there's overlap in CAN addresses between DBC files, and because the filter labeler cannot tell apart anymore which Filter ID is associated to which bus, it might label them incorrectly. But usually it's ok to just enable the labeling with all the DBC files.
- In Frame data analysis window, in addition to J1939 decoding show also GMLAN (Priority bits, Arbitration Id, Sender Id) decoding.
- FilterUtility static class used for centralized ListWidgetItem creation and for other helper functions
- DBC handler: To allow setting bus numbers even before connection is configured, do not enforce "valid" bus numbers
This commit is contained in:
mjuhanne
2019-08-11 23:16:02 +03:00
parent 92048e31a1
commit 428b19c5c4
17 changed files with 515 additions and 93 deletions
+124 -19
View File
@@ -87,7 +87,7 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByID(uint32_t id)
if (messages.count() == 0) return nullptr;
for (int i = 0; i < messages.count(); i++)
{
if (isJ1939Handler)
if (matchingCriteria == J1939)
{
// include data page and extended data page in the pgn
uint32_t pgn = (id & 0x3FFFF00) >> 8;
@@ -109,6 +109,13 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByID(uint32_t id)
}
}
}
else if (matchingCriteria == GMLAN)
{
// Match the bits 14-26 (Arbitration Id) of GMLAN 29bit header
uint32_t arbId = id &0x3FFE000;
if ( (arbId != 0) && (messages[i].ID & 0x3FFE000) == arbId )
return &messages[i];
}
else
{
if ( messages[i].ID == id )
@@ -203,20 +210,31 @@ int DBCMessageHandler::getCount()
return messages.count();
}
bool DBCMessageHandler::isJ1939()
bool DBCMessageHandler::filterLabeling()
{
return isJ1939Handler;
return filterLabelingEnabled;
}
void DBCMessageHandler::setJ1939(bool j1939)
void DBCMessageHandler::setFilterLabeling(bool filterLabeling)
{
isJ1939Handler = j1939;
filterLabelingEnabled = filterLabeling;
}
MatchingCriteria_t DBCMessageHandler::getMatchingCriteria()
{
return matchingCriteria;
}
void DBCMessageHandler::setMatchingCriteria(MatchingCriteria_t _matchingCriteria)
{
matchingCriteria = _matchingCriteria;
}
DBCFile::DBCFile()
{
messageHandler = new DBCMessageHandler;
messageHandler->setJ1939(false);
messageHandler->setMatchingCriteria(EXACT);
messageHandler->setFilterLabeling(false);
}
DBCFile::DBCFile(const DBCFile& cpy) : QObject()
@@ -225,7 +243,8 @@ DBCFile::DBCFile(const DBCFile& cpy) : QObject()
for (int i = 0 ; i < cpy.messageHandler->getCount() ; i++)
messageHandler->addMessage(*cpy.messageHandler->findMsgByIdx(i));
messageHandler->setJ1939(cpy.messageHandler->isJ1939());
messageHandler->setMatchingCriteria(cpy.messageHandler->getMatchingCriteria());
messageHandler->setFilterLabeling(cpy.messageHandler->filterLabeling());
fileName = cpy.fileName;
filePath = cpy.filePath;
assocBuses = cpy.assocBuses;
@@ -293,9 +312,10 @@ int DBCFile::getAssocBus()
void DBCFile::setAssocBus(int bus)
{
int numBuses = CANConManager::getInstance()->getNumBuses();
if (bus < -1) return;
if (bus >= numBuses) return;
// To allow setting bus numbers even before connection is configured, do not enforce "valid" bus numbers
//int numBuses = CANConManager::getInstance()->getNumBuses();
//if (bus >= numBuses) return;
assocBuses = bus;
}
@@ -690,7 +710,8 @@ void DBCFile::loadFile(QString fileName)
qDebug() << "Starting DBC load";
dbc_nodes.clear();
messageHandler->removeAllMessages();
messageHandler->setJ1939(false);
messageHandler->setMatchingCriteria(EXACT);
messageHandler->setFilterLabeling(false);
DBC_NODE falseNode;
falseNode.name = "Vector__XXX";
@@ -884,14 +905,24 @@ void DBCFile::loadFile(QString fileName)
fgAttr = findAttributeByName("GenMsgForegroundColor");
}
DBC_ATTRIBUTE *j1939attr = findAttributeByName("isj1939dbc");
if (j1939attr)
DBC_ATTRIBUTE *mc_attr = findAttributeByName("matchingcriteria");
if (mc_attr)
{
messageHandler->setJ1939(j1939attr->defaultValue > 0);
messageHandler->setMatchingCriteria((MatchingCriteria_t)mc_attr->defaultValue.toInt());
}
else
{
messageHandler->setJ1939(false);
messageHandler->setMatchingCriteria(EXACT);
}
DBC_ATTRIBUTE *fl_attr = findAttributeByName("filterlabeling");
if (fl_attr)
{
messageHandler->setFilterLabeling(fl_attr->defaultValue.toInt());
}
else
{
messageHandler->setFilterLabeling(false);
}
QColor DefaultBG = QColor(bgAttr->defaultValue.toString());
@@ -1397,7 +1428,16 @@ int DBCHandler::createBlankFile()
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "isj1939dbc";
attr.name = "matchingcriteria";
attr.valType = QINT;
newFile.dbc_attributes.append(attr);
attr.attrType = MESSAGE;
attr.defaultValue = 0;
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "filterlabeling";
attr.valType = QINT;
newFile.dbc_attributes.append(attr);
@@ -1405,6 +1445,14 @@ int DBCHandler::createBlankFile()
return loadedFiles.count();
}
DBCFile* DBCHandler::loadDBCFile(QString filename)
{
DBCFile newFile;
newFile.loadFile(filename);
loadedFiles.append(newFile);
return &loadedFiles.last();
}
//the only reason to even bother sending the index is to see if
//the user wants to replace an already loaded DBC.
//Otherwise add a new one. Well, always add a new one.
@@ -1430,11 +1478,8 @@ DBCFile* DBCHandler::loadDBCFile(int idx)
{
filename = dialog.selectedFiles()[0];
//right now there is only one file type that can be loaded here so just do it.
DBCFile newFile;
newFile.loadFile(filename);
loadedFiles.append(newFile);
settings.setValue("DBC/LoadSaveDirectory", dialog.directory().path());
return &loadedFiles.last();
return loadDBCFile(filename);
}
return nullptr;
@@ -1483,6 +1528,29 @@ DBC_MESSAGE* DBCHandler::findMessage(const CANFrame &frame)
return nullptr;
}
// This function won't care which bus the DBC file is associated, but will return any message as long as ID matches and the file
// has filter labeling enabled.
// Returns the found message as well as the matching criteria (exact/J1939/GMLAN)
// Used for quickly populating the Frame Filtering section with interpreted values
DBC_MESSAGE* DBCHandler::findMessageForFilter(uint32_t id, MatchingCriteria_t * matchingCriteria)
{
for(int i = 0; i < loadedFiles.count(); i++)
{
if (loadedFiles[i].messageHandler->filterLabeling())
{
DBC_MESSAGE* msg = loadedFiles[i].messageHandler->findMsgByID(id);
if (msg != nullptr)
{
*matchingCriteria = loadedFiles[i].messageHandler->getMatchingCriteria();
return msg;
}
}
}
return nullptr;
}
/*
* As above, a real shortcut function that searches all files in order to try to find a message with the given name
*/
@@ -1526,7 +1594,44 @@ DBCFile* DBCHandler::getFileByName(QString name)
DBCHandler::DBCHandler()
{
// Load previously saved DBC file settings
QSettings settings;
int filecount = settings.value("DBC/FileCount", 0).toInt();
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);
MatchingCriteria_t matchingCriteria = (MatchingCriteria_t)settings.value("DBC/MatchingCriteria_" + QString(i),0).toInt();
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);
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") << ")";
}
}
DBCHandler* DBCHandler::getReference()
+15 -3
View File
@@ -5,6 +5,13 @@
#include "dbc_classes.h"
#include "can_structs.h"
typedef enum
{
EXACT,
J1939,
GMLAN
} MatchingCriteria_t;
/*
* TODO:
* Finish coding up the decoupled design
@@ -40,11 +47,14 @@ public:
bool removeMessage(QString name);
void removeAllMessages();
int getCount();
bool isJ1939();
void setJ1939(bool j1939);
MatchingCriteria_t getMatchingCriteria();
void setMatchingCriteria(MatchingCriteria_t mc);
void setFilterLabeling( bool labelFiltering );
bool filterLabeling();
private:
QList<DBC_MESSAGE> messages;
bool isJ1939Handler;
MatchingCriteria_t matchingCriteria;
bool filterLabelingEnabled;
};
//technically there should be a node handler too but I'm sort of treating nodes as second class
@@ -90,6 +100,7 @@ class DBCHandler: public QObject
{
Q_OBJECT
public:
DBCFile* loadDBCFile(QString filename);
DBCFile* loadDBCFile(int);
void saveDBCFile(int);
void removeDBCFile(int);
@@ -97,6 +108,7 @@ public:
void swapFiles(int pos1, int pos2);
DBC_MESSAGE* findMessage(const CANFrame &frame);
DBC_MESSAGE* findMessage(const QString msgName);
DBC_MESSAGE* findMessageForFilter(uint32_t id, MatchingCriteria_t * matchingCriteria);
int getFileCount();
DBCFile* getFileByIdx(int idx);
DBCFile* getFileByName(QString name);
+140 -20
View File
@@ -1,6 +1,6 @@
#include "dbcloadsavewindow.h"
#include "ui_dbcloadsavewindow.h"
#include <QCheckBox>
#include <QComboBox>
#include "helpwindow.h"
#include "connections/canconmanager.h"
@@ -18,14 +18,44 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *p
inhibitCellProcessing = false;
QStringList header;
header << "Filename" << "Associated Bus" << "J1939";
ui->tableFiles->setColumnCount(3);
header << "Filename" << "Associated Bus" << "Matching criteria" << "Label filters";
ui->tableFiles->setColumnCount(4);
ui->tableFiles->setHorizontalHeaderLabels(header);
ui->tableFiles->setColumnWidth(0, 265);
ui->tableFiles->setColumnWidth(1, 125);
ui->tableFiles->setColumnWidth(2, 80);
ui->tableFiles->setColumnWidth(2, 120);
ui->tableFiles->setColumnWidth(3, 90);
ui->tableFiles->horizontalHeader()->setStretchLastSection(true);
// Populate table
for (int idx=0; idx<dbcHandler->getFileCount(); idx++)
{
DBCFile * file = dbcHandler->getFileByIdx(idx);
ui->tableFiles->insertRow(ui->tableFiles->rowCount());
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem(file->getFullFilename()));
QString bus = QString::number(file->getAssocBus() );
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem(bus));
QComboBox * mc_item = addMatchingCriteriaCombobox(idx);
int mc = (int)file->messageHandler->getMatchingCriteria();
mc_item->setCurrentIndex(mc);
QTableWidgetItem *item = new QTableWidgetItem("");
ui->tableFiles->setItem(idx, 3, item);
bool filterLabeling = file->messageHandler->filterLabeling();
if (filterLabeling)
{
item->setCheckState(Qt::Checked);
}
else
{
item->setCheckState(Qt::Unchecked);
}
qDebug() << "Populate DBC table:" << file->getFullFilename() << " (bus:" << bus << " - Matching Criteria:" << mc
<< "Filter labeling: " << (filterLabeling?"enabled":"disabled") << ")";
}
connect(ui->btnEdit, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::editFile);
connect(ui->btnLoad, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::loadFile);
connect(ui->btnMoveDown, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::moveDown);
@@ -42,12 +72,42 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *p
installEventFilter(this);
}
QComboBox * DBCLoadSaveWindow::addMatchingCriteriaCombobox(int row)
{
QComboBox *item = new QComboBox();
item->addItem("Exact");
item->addItem("J1939");
item->addItem("GMLAN");
ui->tableFiles->setCellWidget(row, 2, item);
connect(item, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int box_idx) { matchingCriteriaChanged(box_idx); } );
return item;
}
DBCLoadSaveWindow::~DBCLoadSaveWindow()
{
removeEventFilter(this);
delete ui;
}
void DBCLoadSaveWindow::updateSettings()
{
QSettings settings;
int filecount = ui->tableFiles->rowCount();
settings.setValue("DBC/FileCount", filecount);
for (int i=0; i<filecount; i++)
{
DBCFile * file = dbcHandler->getFileByIdx(i);
if (file)
{
settings.setValue("DBC/Filename_" + QString(i), file->getFullFilename());
settings.setValue("DBC/AssocBus_" + QString(i), file->getAssocBus());
settings.setValue("DBC/MatchingCriteria_" + QString(i), file->messageHandler->getMatchingCriteria());
settings.setValue("DBC/FilterLabeling_" + QString(i), file->messageHandler->filterLabeling());
}
}
}
bool DBCLoadSaveWindow::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyRelease) {
@@ -74,9 +134,12 @@ void DBCLoadSaveWindow::newFile()
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem("UNNAMEDFILE"));
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1"));
QComboBox * mc_item = addMatchingCriteriaCombobox(idx);
mc_item->setCurrentIndex(EXACT);
QTableWidgetItem *item = new QTableWidgetItem("");
item->setCheckState(Qt::Unchecked);
ui->tableFiles->setItem(idx, 2, item);
item->setCheckState(Qt::Checked);
ui->tableFiles->setItem(idx, 3, item);
}
void DBCLoadSaveWindow::loadFile()
@@ -87,9 +150,17 @@ void DBCLoadSaveWindow::loadFile()
ui->tableFiles->insertRow(ui->tableFiles->rowCount());
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem(file->getFullFilename()));
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1"));
DBC_ATTRIBUTE *attr = file->findAttributeByName("isj1939dbc");
DBC_ATTRIBUTE *attr = file->findAttributeByName("matchingcriteria");
QComboBox * mc_item = addMatchingCriteriaCombobox(idx);
if (attr && attr->defaultValue > 0)
{
mc_item->setCurrentIndex(attr->defaultValue.toInt());
}
attr = file->findAttributeByName("filterlabeling");
QTableWidgetItem *item = new QTableWidgetItem("");
ui->tableFiles->setItem(idx, 2, item);
ui->tableFiles->setItem(idx, 3, item);
if (attr && attr->defaultValue > 0)
{
item->setCheckState(Qt::Checked);
@@ -98,6 +169,8 @@ void DBCLoadSaveWindow::loadFile()
{
item->setCheckState(Qt::Unchecked);
}
updateSettings();
}
}
@@ -131,6 +204,7 @@ void DBCLoadSaveWindow::removeFile()
dbcHandler->removeDBCFile(idx);
ui->tableFiles->removeRow(idx);
}
updateSettings();
}
void DBCLoadSaveWindow::moveUp()
@@ -139,6 +213,7 @@ void DBCLoadSaveWindow::moveUp()
if (idx < 1) return;
dbcHandler->swapFiles(idx - 1, idx);
swapTableRows(true);
updateSettings();
}
void DBCLoadSaveWindow::moveDown()
@@ -148,6 +223,7 @@ void DBCLoadSaveWindow::moveDown()
if (idx > (dbcHandler->getFileCount() - 2)) return;
dbcHandler->swapFiles(idx, idx + 1);
swapTableRows(false);
updateSettings();
}
void DBCLoadSaveWindow::editFile()
@@ -159,6 +235,42 @@ void DBCLoadSaveWindow::editFile()
editorWindow->show();
}
void DBCLoadSaveWindow::matchingCriteriaChanged(int index)
{
// We don't know which combobox changed, so we just update all of them
for (int row=0; row<ui->tableFiles->rowCount(); row++)
{
DBCFile *file = dbcHandler->getFileByIdx(row);
if (file)
{
QComboBox *item = (QComboBox*)ui->tableFiles->cellWidget(row, 2);
MatchingCriteria_t matchingCriteria = (MatchingCriteria_t) item->currentIndex();
DBC_ATTRIBUTE *attr = file->findAttributeByName("matchingcriteria");
if (attr)
{
attr->defaultValue = matchingCriteria;
file->messageHandler->setMatchingCriteria(matchingCriteria);
}
else
{
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);
}
}
}
updateSettings();
}
void DBCLoadSaveWindow::cellChanged(int row, int col)
{
if (inhibitCellProcessing) return;
@@ -167,39 +279,40 @@ void DBCLoadSaveWindow::cellChanged(int row, int col)
DBCFile *file = dbcHandler->getFileByIdx(row);
int bus = ui->tableFiles->item(row, col)->text().toInt();
int numBuses = CANConManager::getInstance()->getNumBuses();
if (bus > -2 && bus < numBuses)
if (bus > -2)
{
file->setAssocBus(bus);
}
}
else if (col == 2)
updateSettings();
}
else if (col == 3) // labelfilters
{
DBCFile *file = dbcHandler->getFileByIdx(row);
if (file)
{
//int isj1939dbc = ui->tableFiles->item(row, col)->text().toInt();
bool isj1939dbc = ui->tableFiles->item(row, col)->checkState() == Qt::Checked;
DBC_ATTRIBUTE *attr = file->findAttributeByName("isj1939dbc");
bool labelFilters = ui->tableFiles->item(row, col)->checkState() == Qt::Checked;
DBC_ATTRIBUTE *attr = file->findAttributeByName("filterlabeling");
if (attr)
{
attr->defaultValue = isj1939dbc ? 1 : 0;
file->messageHandler->setJ1939(isj1939dbc);
attr->defaultValue = labelFilters ? 1 : 0;
file->messageHandler->setFilterLabeling(labelFilters);
}
else
{
DBC_ATTRIBUTE attr;
attr.attrType = MESSAGE;
attr.defaultValue = isj1939dbc ? 1 : 0;
attr.defaultValue = labelFilters ? 1 : 0;
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
attr.name = "isj1939dbc";
attr.name = "labelfilters";
attr.valType = QINT;
file->dbc_attributes.append(attr);
file->messageHandler->setJ1939(isj1939dbc);
file->messageHandler->setFilterLabeling(labelFilters);
}
}
updateSettings();
}
}
}
@@ -222,10 +335,17 @@ void DBCLoadSaveWindow::swapTableRows(bool up)
QList<QTableWidgetItem*> sourceItems = takeRow(idx);
QList<QTableWidgetItem*> destItems = takeRow(destIdx);
// QCombobox needs separate handling
int sourceMC = ((QComboBox*)ui->tableFiles->cellWidget(idx,2))->currentIndex();
int destMC = ((QComboBox*)ui->tableFiles->cellWidget(destIdx,2))->currentIndex();
// set back in reverse order
setRow(idx, destItems);
setRow(destIdx, sourceItems);
((QComboBox*)ui->tableFiles->cellWidget(idx,2))->setCurrentIndex(destMC);
((QComboBox*)ui->tableFiles->cellWidget(destIdx,2))->setCurrentIndex(sourceMC);
inhibitCellProcessing = false;
}
+4
View File
@@ -3,6 +3,7 @@
#include <QDialog>
#include <QTableWidget>
#include <QComboBox>
#include "dbchandler.h"
#include "dbcmaineditor.h"
@@ -27,6 +28,7 @@ private slots:
void editFile();
void cellChanged(int row, int col);
void cellDoubleClicked(int row, int col);
void matchingCriteriaChanged(int index);
void newFile();
private:
@@ -41,6 +43,8 @@ private:
QList<QTableWidgetItem*> takeRow(int row);
void setRow(int row, const QList<QTableWidgetItem*>& rowItems);
bool eventFilter(QObject *obj, QEvent *event);
void updateSettings();
QComboBox * addMatchingCriteriaCombobox(int row);
};
#endif // DBCLOADSAVEWINDOW_H