Controls and code for using a J1939 database.
This commit is contained in:
+58
-1
@@ -85,11 +85,36 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByID(uint32_t id)
|
||||
if (messages.count() == 0) return NULL;
|
||||
for (int i = 0; i < messages.count(); i++)
|
||||
{
|
||||
if (messages[i].ID == id)
|
||||
if (isJ1939Handler)
|
||||
{
|
||||
// include data page and extended data page in the pgn
|
||||
uint32_t pgn = (id & 0x3FFFF00) >> 8;
|
||||
if ( (pgn & 0xFF00) <= 0xEF00 )
|
||||
{
|
||||
// PDU1 format
|
||||
pgn &= 0x3FF00;
|
||||
if ((messages[i].ID & 0x3FF0000) == (pgn << 8))
|
||||
{
|
||||
return &messages[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// PDU2 format
|
||||
if ((messages[i].ID & 0x3FFFF00) == (pgn << 8))
|
||||
{
|
||||
return &messages[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( messages[i].ID == id )
|
||||
{
|
||||
return &messages[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -176,6 +201,16 @@ int DBCMessageHandler::getCount()
|
||||
return messages.count();
|
||||
}
|
||||
|
||||
bool DBCMessageHandler::isJ1939()
|
||||
{
|
||||
return isJ1939Handler;
|
||||
}
|
||||
|
||||
void DBCMessageHandler::setJ1939(bool j1939)
|
||||
{
|
||||
isJ1939Handler = j1939;
|
||||
}
|
||||
|
||||
DBCFile::DBCFile()
|
||||
{
|
||||
messageHandler = new DBCMessageHandler;
|
||||
@@ -187,6 +222,7 @@ DBCFile::DBCFile(const DBCFile& cpy)
|
||||
for (int i = 0 ; i < cpy.messageHandler->getCount() ; i++)
|
||||
messageHandler->addMessage(*cpy.messageHandler->findMsgByIdx(i));
|
||||
|
||||
messageHandler->setJ1939(cpy.messageHandler->isJ1939());
|
||||
fileName = cpy.fileName;
|
||||
filePath = cpy.filePath;
|
||||
assocBuses = cpy.assocBuses;
|
||||
@@ -764,12 +800,24 @@ void DBCFile::loadFile(QString fileName)
|
||||
fgAttr = findAttributeByName("GenMsgForegroundColor");
|
||||
}
|
||||
|
||||
DBC_ATTRIBUTE *j1939attr = findAttributeByName("isj1939dbc");
|
||||
if (j1939attr)
|
||||
{
|
||||
messageHandler->setJ1939(j1939attr->defaultValue > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
messageHandler->setJ1939(false);
|
||||
}
|
||||
|
||||
QColor DefaultBG = QColor(bgAttr->defaultValue.toString());
|
||||
QColor DefaultFG = QColor(fgAttr->defaultValue.toString());
|
||||
|
||||
DBC_ATTRIBUTE_VALUE *thisBG;
|
||||
DBC_ATTRIBUTE_VALUE *thisFG;
|
||||
|
||||
|
||||
|
||||
for (int x = 0; x < messageHandler->getCount(); x++)
|
||||
{
|
||||
DBC_MESSAGE *msg = messageHandler->findMsgByIdx(x);
|
||||
@@ -1237,6 +1285,15 @@ int DBCHandler::createBlankFile()
|
||||
attr.valType = QSTRING;
|
||||
newFile.dbc_attributes.append(attr);
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = 0;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "isj1939dbc";
|
||||
attr.valType = QINT;
|
||||
newFile.dbc_attributes.append(attr);
|
||||
|
||||
loadedFiles.append(newFile);
|
||||
return loadedFiles.count();
|
||||
}
|
||||
|
||||
@@ -40,8 +40,11 @@ public:
|
||||
bool removeMessage(QString name);
|
||||
void removeAllMessages();
|
||||
int getCount();
|
||||
bool isJ1939();
|
||||
void setJ1939(bool j1939);
|
||||
private:
|
||||
QList<DBC_MESSAGE> messages;
|
||||
bool isJ1939Handler;
|
||||
};
|
||||
|
||||
//technically there should be a node handler too but I'm sort of treating nodes as second class
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "dbcloadsavewindow.h"
|
||||
#include "ui_dbcloadsavewindow.h"
|
||||
#include <QCheckBox>
|
||||
|
||||
DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@@ -12,11 +13,13 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *p
|
||||
ui->setupUi(this);
|
||||
|
||||
QStringList header;
|
||||
header << "Filename" << "Associated Bus";
|
||||
ui->tableFiles->setColumnCount(2);
|
||||
header << "Filename" << "Associated Bus" << "J1939";
|
||||
ui->tableFiles->setColumnCount(3);
|
||||
ui->tableFiles->setHorizontalHeaderLabels(header);
|
||||
ui->tableFiles->setColumnWidth(0, 355);
|
||||
ui->tableFiles->setColumnWidth(0, 265);
|
||||
ui->tableFiles->setColumnWidth(1, 125);
|
||||
ui->tableFiles->setColumnWidth(2, 80);
|
||||
ui->tableFiles->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
connect(ui->btnEdit, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::editFile);
|
||||
connect(ui->btnLoad, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::loadFile);
|
||||
@@ -27,6 +30,7 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(const QVector<CANFrame> *frames, QWidget *p
|
||||
connect(ui->btnNewDBC, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::newFile);
|
||||
connect(ui->tableFiles, &QTableWidget::cellChanged, this, &DBCLoadSaveWindow::cellChanged);
|
||||
connect(ui->tableFiles, &QTableWidget::cellDoubleClicked, this, &DBCLoadSaveWindow::cellDoubleClicked);
|
||||
//connect(ui->tableFiles, &QTableWidget::cellActivated, this, &DBCLoadSaveWindow::cellChanged);
|
||||
|
||||
editorWindow = new DBCMainEditor(frames);
|
||||
}
|
||||
@@ -43,6 +47,10 @@ void DBCLoadSaveWindow::newFile()
|
||||
ui->tableFiles->insertRow(ui->tableFiles->rowCount());
|
||||
ui->tableFiles->setItem(idx, 0, new QTableWidgetItem("UNNAMEDFILE"));
|
||||
ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1"));
|
||||
|
||||
QTableWidgetItem *item = new QTableWidgetItem("");
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
ui->tableFiles->setItem(idx, 2, item);
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::loadFile()
|
||||
@@ -53,6 +61,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");
|
||||
QTableWidgetItem *item = new QTableWidgetItem("");
|
||||
ui->tableFiles->setItem(idx, 2, item);
|
||||
if (attr && attr->defaultValue > 0)
|
||||
{
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +129,35 @@ void DBCLoadSaveWindow::cellChanged(int row, int col)
|
||||
file->setAssocBus(bus);
|
||||
}
|
||||
}
|
||||
else if (col == 2)
|
||||
{
|
||||
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");
|
||||
if (attr)
|
||||
{
|
||||
attr->defaultValue = isj1939dbc ? 1 : 0;
|
||||
file->messageHandler->setJ1939(isj1939dbc);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBC_ATTRIBUTE attr;
|
||||
|
||||
attr.attrType = MESSAGE;
|
||||
attr.defaultValue = isj1939dbc ? 1 : 0;
|
||||
attr.enumVals.clear();
|
||||
attr.lower = 0;
|
||||
attr.upper = 0;
|
||||
attr.name = "isj1939dbc";
|
||||
attr.valType = QINT;
|
||||
file->dbc_attributes.append(attr);
|
||||
file->messageHandler->setJ1939(isj1939dbc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DBCLoadSaveWindow::cellDoubleClicked(int row, int col)
|
||||
|
||||
Reference in New Issue
Block a user