diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 4b1d730..8cda711 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -25,7 +25,9 @@ SOURCES += main.cpp\ candatagrid.cpp \ flowviewwindow.cpp \ framesenderwindow.cpp \ - dbchandler.cpp + dbchandler.cpp \ + dbcmaineditor.cpp \ + dbcsignaleditor.cpp HEADERS += mainwindow.h \ can_structs.h \ @@ -42,7 +44,9 @@ HEADERS += mainwindow.h \ framesenderwindow.h \ can_trigger_structs.h \ dbc_classes.h \ - dbchandler.h + dbchandler.h \ + dbcmaineditor.h \ + dbcsignaleditor.h FORMS += mainwindow.ui \ graphingwindow.ui \ @@ -51,7 +55,9 @@ FORMS += mainwindow.ui \ frameplaybackwindow.ui \ candatagrid.ui \ flowviewwindow.ui \ - framesenderwindow.ui + framesenderwindow.ui \ + dbcmaineditor.ui \ + dbcsignaleditor.ui DISTFILES += diff --git a/dbchandler.h b/dbchandler.h index 37780b2..83157dd 100644 --- a/dbchandler.h +++ b/dbchandler.h @@ -22,13 +22,14 @@ public: DBC_MESSAGE *findMsgByID(int id); DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name); + QList dbc_nodes; + QList dbc_messages; + signals: public slots: private: - QList dbc_nodes; - QList dbc_messages; unsigned char reverseBits(unsigned char); unsigned char processByte(unsigned char, int, int); diff --git a/dbcmaineditor.cpp b/dbcmaineditor.cpp new file mode 100644 index 0000000..53dd561 --- /dev/null +++ b/dbcmaineditor.cpp @@ -0,0 +1,144 @@ +#include "dbcmaineditor.h" +#include "ui_dbcmaineditor.h" + +DBCMainEditor::DBCMainEditor(DBCHandler *handler, QWidget *parent) : + QDialog(parent), + ui(new Ui::DBCMainEditor) +{ + ui->setupUi(this); + + dbcHandler = handler; + + QStringList headers; + headers << "Node Name" << "Comment"; + ui->NodesTable->setColumnCount(2); + ui->NodesTable->setColumnWidth(0, 240); + ui->NodesTable->setColumnWidth(1, 700); + ui->NodesTable->setHorizontalHeaderLabels(headers); + ui->NodesTable->horizontalHeader()->setStretchLastSection(true); + + QStringList headers2; + headers2 << "Msg ID" << "Msg Name" << "Data Len" << "Signals" << "Comment"; + ui->MessagesTable->setColumnCount(5); + ui->MessagesTable->setColumnWidth(0, 80); + ui->MessagesTable->setColumnWidth(1, 240); + ui->MessagesTable->setColumnWidth(2, 80); + ui->MessagesTable->setColumnWidth(3, 80); + ui->MessagesTable->setColumnWidth(4, 340); + ui->MessagesTable->setHorizontalHeaderLabels(headers2); + ui->MessagesTable->horizontalHeader()->setStretchLastSection(true); + + + refreshNodesTable(); + refreshMessagesTable(&dbcHandler->dbc_nodes.at(0)); + currRow = 0; + + connect(ui->NodesTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChangedNode(int,int))); + connect(ui->NodesTable, SIGNAL(cellClicked(int,int)), this, SLOT(onCellClickedNode(int,int))); + + connect(ui->MessagesTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChangedMessage(int,int))); + connect(ui->MessagesTable, SIGNAL(cellClicked(int,int)), this, SLOT(onCellClickedMessage(int,int))); + + sigEditor = new DBCSignalEditor(handler); +} + +DBCMainEditor::~DBCMainEditor() +{ + delete ui; + delete sigEditor; +} + +void DBCMainEditor::onCellChangedNode(int row,int col) +{ + +} + +void DBCMainEditor::onCellChangedMessage(int row,int col) +{ + +} + +void DBCMainEditor::onCellClickedNode(int row, int col) +{ + //reload messages list if the currently selected row has changed. + //qDebug() << "Entered at row " << row << " col " << col; + if (row != currRow) + { + currRow = row; + QString nodeName = ui->NodesTable->item(currRow, 0)->text(); + qDebug() << "Trying to find node with name " << nodeName; + DBC_NODE *node = dbcHandler->findNodeByName(nodeName); + //qDebug() << "Address of node: " << (int)node; + refreshMessagesTable(node); + } +} + +void DBCMainEditor::onCellClickedMessage(int row, int col) +{ + if (col == 3) //3 is the signals field. If clicked we go to the signals dialog + { + QString idString = ui->MessagesTable->item(row, 0)->text(); + DBC_MESSAGE *message = dbcHandler->findMsgByID(idString.toInt(NULL, 16)); + sigEditor->setMessageRef(message); + sigEditor->exec(); //blocks this window from being active until we're done + } +} + +void DBCMainEditor::refreshNodesTable() +{ + ui->NodesTable->clearContents(); //first step, clear out any previous crap + ui->NodesTable->setRowCount(0); + + int rowIdx; + + for (int x = 0; x < dbcHandler->dbc_nodes.count(); x++) + { + DBC_NODE node = dbcHandler->dbc_nodes.at(x); + QTableWidgetItem *nodeName = new QTableWidgetItem(node.name); + QTableWidgetItem *nodeComment = new QTableWidgetItem(node.comment); + rowIdx = ui->NodesTable->rowCount(); + ui->NodesTable->insertRow(rowIdx); + ui->NodesTable->setItem(rowIdx, 0, nodeName); + ui->NodesTable->setItem(rowIdx, 1, nodeComment); + } + + ui->NodesTable->insertRow(ui->NodesTable->rowCount()); +} + +void DBCMainEditor::refreshMessagesTable(const DBC_NODE *node) +{ + ui->MessagesTable->clearContents(); + ui->MessagesTable->setRowCount(0); + + int rowIdx; + + if (node != NULL) + { + for (int x = 0; x < dbcHandler->dbc_messages.count(); x++) + { + DBC_MESSAGE msg = dbcHandler->dbc_messages.at(x); + if (msg.sender == node) + { + //many of these are simplistic first versions just to test functionality. + QTableWidgetItem *msgID = new QTableWidgetItem(QString::number(msg.ID, 16)); + QTableWidgetItem *msgName = new QTableWidgetItem(msg.name); + QTableWidgetItem *msgLen = new QTableWidgetItem(QString::number(msg.len)); + QTableWidgetItem *msgSignals = new QTableWidgetItem(QString::number(msg.msgSignals.count())); + QTableWidgetItem *msgComment = new QTableWidgetItem(msg.comment); + + rowIdx = ui->MessagesTable->rowCount(); + ui->MessagesTable->insertRow(rowIdx); + ui->MessagesTable->setItem(rowIdx, 0, msgID); + ui->MessagesTable->setItem(rowIdx, 1, msgName); + ui->MessagesTable->setItem(rowIdx, 2, msgLen); + ui->MessagesTable->setItem(rowIdx, 3, msgSignals); + ui->MessagesTable->setItem(rowIdx, 4, msgComment); + //note that there is a sending node field in the structure but we're + //not displaying it. It has to be the node we selected from the node list + //so no need to show that here. + } + } + } + + ui->MessagesTable->insertRow(ui->MessagesTable->rowCount()); +} diff --git a/dbcmaineditor.h b/dbcmaineditor.h new file mode 100644 index 0000000..04d6241 --- /dev/null +++ b/dbcmaineditor.h @@ -0,0 +1,37 @@ +#ifndef DBCMAINEDITOR_H +#define DBCMAINEDITOR_H + +#include +#include +#include "dbchandler.h" +#include "dbcsignaleditor.h" + +namespace Ui { +class DBCMainEditor; +} + +class DBCMainEditor : public QDialog +{ + Q_OBJECT + +public: + explicit DBCMainEditor(DBCHandler *handler, QWidget *parent = 0); + ~DBCMainEditor(); + +private slots: + void onCellChangedNode(int,int); + void onCellClickedNode(int, int); + void onCellClickedMessage(int, int); + void onCellChangedMessage(int,int); + +private: + Ui::DBCMainEditor *ui; + DBCHandler *dbcHandler; + DBCSignalEditor *sigEditor; + int currRow; + + void refreshNodesTable(); + void refreshMessagesTable(const DBC_NODE *node); +}; + +#endif // DBCMAINEDITOR_H diff --git a/dbcmaineditor.ui b/dbcmaineditor.ui new file mode 100644 index 0000000..dedb4a2 --- /dev/null +++ b/dbcmaineditor.ui @@ -0,0 +1,49 @@ + + + DBCMainEditor + + + + 0 + 0 + 1103 + 571 + + + + DBC Editing Window + + + + + + + + Nodes + + + + + + + + + + + + + + Messages + + + + + + + + + + + + + diff --git a/dbcsignaleditor.cpp b/dbcsignaleditor.cpp new file mode 100644 index 0000000..c5533e7 --- /dev/null +++ b/dbcsignaleditor.cpp @@ -0,0 +1,65 @@ +#include "dbcsignaleditor.h" +#include "ui_dbcsignaleditor.h" + +DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : + QDialog(parent), + ui(new Ui::DBCSignalEditor) +{ + ui->setupUi(this); + dbcHandler = handler; + dbcMessage = NULL; +/* + QStringList headers; + headers << "Node Name" << "Comment"; + ui->signalsTable->setColumnCount(2); + ui->signalsTable->setColumnWidth(0, 240); + ui->signalsTable->setColumnWidth(1, 700); + ui->signalsTable->setHorizontalHeaderLabels(headers); + ui->signalsTable->horizontalHeader()->setStretchLastSection(true); + name, + a start bit, + a length, + byte order (intel or motorola), + a type (signed, unsigned, float, string), + a scaling factor, + a bias, + a minimum and + maximum, + a receiving node, + a unit name, + an optional comment, + and an optional value list + + + + + QStringList headers2; + headers2 << "Msg ID" << "Msg Name" << "Data Len" << "Signals" << "Comment"; + ui->MessagesTable->setColumnCount(5); + ui->MessagesTable->setColumnWidth(0, 80); + ui->MessagesTable->setColumnWidth(1, 240); + ui->MessagesTable->setColumnWidth(2, 80); + ui->MessagesTable->setColumnWidth(3, 80); + ui->MessagesTable->setColumnWidth(4, 340); + ui->MessagesTable->setHorizontalHeaderLabels(headers2); + ui->MessagesTable->horizontalHeader()->setStretchLastSection(true); + +*/ + +} + +DBCSignalEditor::~DBCSignalEditor() +{ + delete ui; +} + +void DBCSignalEditor::setMessageRef(DBC_MESSAGE *msg) +{ + dbcMessage = msg; +} + +void DBCSignalEditor::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + +} diff --git a/dbcsignaleditor.h b/dbcsignaleditor.h new file mode 100644 index 0000000..94bee7a --- /dev/null +++ b/dbcsignaleditor.h @@ -0,0 +1,27 @@ +#ifndef DBCSIGNALEDITOR_H +#define DBCSIGNALEDITOR_H + +#include +#include "dbchandler.h" + +namespace Ui { +class DBCSignalEditor; +} + +class DBCSignalEditor : public QDialog +{ + Q_OBJECT + +public: + explicit DBCSignalEditor(DBCHandler *handler, QWidget *parent = 0); + void setMessageRef(DBC_MESSAGE *msg); + void showEvent(QShowEvent*); + ~DBCSignalEditor(); + +private: + Ui::DBCSignalEditor *ui; + DBCHandler *dbcHandler; + DBC_MESSAGE *dbcMessage; +}; + +#endif // DBCSIGNALEDITOR_H diff --git a/dbcsignaleditor.ui b/dbcsignaleditor.ui new file mode 100644 index 0000000..3baea9d --- /dev/null +++ b/dbcsignaleditor.ui @@ -0,0 +1,41 @@ + + + DBCSignalEditor + + + + 0 + 0 + 884 + 530 + + + + Signal Editor + + + + + + Signals + + + + + + + + + + Value Table For Selected Signal: + + + + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 5f459f5..ae07bed 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -91,6 +91,7 @@ MainWindow::MainWindow(QWidget *parent) : playbackWindow = NULL; flowViewWindow = NULL; frameSenderWindow = NULL; + dbcMainEditor = NULL; dbcHandler = new DBCHandler; model->setDBCHandler(dbcHandler); @@ -111,6 +112,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->canFramesView, SIGNAL(clicked(QModelIndex)), this, SLOT(gridClicked(QModelIndex))); connect(ui->cbInterpret, SIGNAL(toggled(bool)), this, SLOT(interpretToggled(bool))); connect(ui->cbOverwrite, SIGNAL(toggled(bool)), this, SLOT(overwriteToggled(bool))); + connect(ui->actionEdit_Messages_Signals, SIGNAL(triggered(bool)), this, SLOT(showDBCEditor())); lbStatusConnected.setText(tr("Not connected")); updateBaudLabel(0,0); @@ -132,7 +134,6 @@ MainWindow::MainWindow(QWidget *parent) : normalRowHeight = ui->canFramesView->rowHeight(0); qDebug() << "normal row height = " << normalRowHeight; model->clearFrames(); - } MainWindow::~MainWindow() @@ -145,9 +146,12 @@ MainWindow::~MainWindow() if (playbackWindow) delete playbackWindow; if (flowViewWindow) delete flowViewWindow; if (frameSenderWindow) delete frameSenderWindow; + if (dbcMainEditor) delete dbcMainEditor; delete ui; delete dbcHandler; + model->clearFrames(); + delete model; } void MainWindow::gridClicked(QModelIndex idx) @@ -807,5 +811,13 @@ void MainWindow::showFlowViewWindow() flowViewWindow = new FlowViewWindow(model->getListReference()); } flowViewWindow->show(); +} +void MainWindow::showDBCEditor() +{ + if (!dbcMainEditor) + { + dbcMainEditor = new DBCMainEditor(dbcHandler); + } + dbcMainEditor->show(); } diff --git a/mainwindow.h b/mainwindow.h index 456fde1..d5e5f7d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -12,6 +12,7 @@ #include "flowviewwindow.h" #include "framesenderwindow.h" #include "dbchandler.h" +#include "dbcmaineditor.h" #define VERSION 105 @@ -47,6 +48,7 @@ private slots: void gridClicked(QModelIndex); void interpretToggled(bool); void overwriteToggled(bool); + void showDBCEditor(); public slots: void gotFrames(int, int); @@ -60,21 +62,30 @@ signals: private: Ui::MainWindow *ui; + + //canbus related data CANFrameModel *model; + DBCHandler *dbcHandler; QList ports; QThread serialWorkerThread; QByteArray inputBuffer; + + //References to other windows we can display GraphingWindow *graphingWindow; FrameInfoWindow *frameInfoWindow; FramePlaybackWindow *playbackWindow; FlowViewWindow *flowViewWindow; FrameSenderWindow *frameSenderWindow; - DBCHandler *dbcHandler; + DBCMainEditor *dbcMainEditor; + + //various private storage QLabel lbStatusConnected; QLabel lbStatusBauds; QLabel lbStatusDatabase; int normalRowHeight; bool isConnected; + + //private methods void loadCRTDFile(QString); void loadNativeCSVFile(QString); void loadGenericCSVFile(QString);