From 4dc8c5b4343e0747af3e6efbd3f9ad336119c2c0 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 18 Oct 2015 15:34:40 -0400 Subject: [PATCH] Initial commit where connection window is active and it is possible to connect to GVRET but this time through the connection window and the menu option "Connect". --- SavvyCAN.pro | 9 ++-- connectionwindow.cpp | 15 ++++++ connectionwindow.h | 5 +- connectionwindow.ui | 2 +- mainwindow.cpp | 124 ++++++++++++++++++++++++++----------------- mainwindow.h | 10 +++- mainwindow.ui | 116 +++++++--------------------------------- serialworker.cpp | 2 +- 8 files changed, 129 insertions(+), 154 deletions(-) diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 434e9c1..f90fe66 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -36,7 +36,8 @@ SOURCES += main.cpp\ filecomparatorwindow.cpp \ mainsettingsdialog.cpp \ firmwareuploaderwindow.cpp \ - discretestatewindow.cpp + discretestatewindow.cpp \ + connectionwindow.cpp HEADERS += mainwindow.h \ can_structs.h \ @@ -61,7 +62,8 @@ HEADERS += mainwindow.h \ filecomparatorwindow.h \ mainsettingsdialog.h \ firmwareuploaderwindow.h \ - discretestatewindow.h + discretestatewindow.h \ + connectionwindow.h FORMS += mainwindow.ui \ graphingwindow.ui \ @@ -76,7 +78,8 @@ FORMS += mainwindow.ui \ filecomparatorwindow.ui \ mainsettingsdialog.ui \ firmwareuploaderwindow.ui \ - discretestatewindow.ui + discretestatewindow.ui \ + connectionwindow.ui DISTFILES += diff --git a/connectionwindow.cpp b/connectionwindow.cpp index 8bdbc5c..dbcca98 100644 --- a/connectionwindow.cpp +++ b/connectionwindow.cpp @@ -24,6 +24,8 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) : ui->cbSpeed1->addItem(tr("500000")); ui->cbSpeed1->addItem(tr("1000000")); ui->cbSpeed1->addItem(tr("33333")); + + connect(ui->btnOK, SIGNAL(clicked(bool)), this, SLOT(handleOKButton())); } ConnectionWindow::~ConnectionWindow() @@ -40,6 +42,19 @@ void ConnectionWindow::showEvent(QShowEvent* event) if (ui->rbSocketCAN->isChecked()) getSocketcanPorts(); } +void ConnectionWindow::handleOKButton() +{ + QString conn; + + if (ui->rbGVRET->isChecked()) conn = "GVRET"; + if (ui->rbKvaser->isChecked()) conn = "KVASER"; + if (ui->rbSocketCAN->isChecked()) conn = "SOCKETCAN"; + + emit updateConnectionSettings(conn, getPortName(), getSpeed0(), getSpeed1()); + + this->close(); +} + void ConnectionWindow::getSerialPorts() { ui->cbPort->clear(); diff --git a/connectionwindow.h b/connectionwindow.h index e4eedd3..cb4a437 100644 --- a/connectionwindow.h +++ b/connectionwindow.h @@ -33,11 +33,14 @@ public: ConnectionType::ConnectionType getConnectionType(); signals: - void updateConnectionSettings(); + void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1); public slots: void setSpeeds(int speed0, int speed1); +private slots: + void handleOKButton(); + private: Ui::ConnectionWindow *ui; QList ports; diff --git a/connectionwindow.ui b/connectionwindow.ui index 57a4839..a6e754d 100644 --- a/connectionwindow.ui +++ b/connectionwindow.ui @@ -99,7 +99,7 @@ - OK + Update Settings diff --git a/mainwindow.cpp b/mainwindow.cpp index c86fc22..c68358a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -63,26 +63,6 @@ MainWindow::MainWindow(QWidget *parent) : //enabling the below line kills performance in every way imaginable. Left here as a warning. Do not do this. //ui->canFramesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - ports = QSerialPortInfo::availablePorts(); - - for (int i = 0; i < ports.count(); i++) - { - ui->cbSerialPorts->addItem(ports[i].portName()); - } - - ui->cbSpeed1->addItem(tr("Disabled")); - ui->cbSpeed1->addItem(tr("125000")); - ui->cbSpeed1->addItem(tr("250000")); - ui->cbSpeed1->addItem(tr("500000")); - ui->cbSpeed1->addItem(tr("1000000")); - ui->cbSpeed1->addItem(tr("33333")); - ui->cbSpeed2->addItem(tr("Disabled")); - ui->cbSpeed2->addItem(tr("125000")); - ui->cbSpeed2->addItem(tr("250000")); - ui->cbSpeed2->addItem(tr("500000")); - ui->cbSpeed2->addItem(tr("1000000")); - ui->cbSpeed2->addItem(tr("33333")); - worker = new SerialWorker(model); worker->moveToThread(&serialWorkerThread); connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater); @@ -110,13 +90,13 @@ MainWindow::MainWindow(QWidget *parent) : settingsDialog = NULL; firmwareUploaderWindow = NULL; discreteStateWindow = NULL; + connectionWindow = NULL; dbcHandler = new DBCHandler; bDirty = false; inhibitFilterUpdate = false; model->setDBCHandler(dbcHandler); - connect(ui->btnConnect, SIGNAL(clicked(bool)), this, SLOT(connButtonPress())); connect(ui->actionOpen_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleLoadFile())); connect(ui->actionGraph_Dta, SIGNAL(triggered(bool)), this, SLOT(showGraphingWindow())); connect(ui->actionFrame_Data_Analysis, SIGNAL(triggered(bool)), this, SLOT(showFrameDataAnalysis())); @@ -126,7 +106,6 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionLoad_Filter_Definition, SIGNAL(triggered(bool)), this, SLOT(handleLoadFilters())); connect(ui->actionSave_Filter_Definition, SIGNAL(triggered(bool)), this, SLOT(handleSaveFilters())); connect(ui->action_Playback, SIGNAL(triggered(bool)), this, SLOT(showPlaybackWindow())); - connect(ui->btnBaudSet, SIGNAL(clicked(bool)), this, SLOT(changeBaudRates())); connect(ui->actionFlow_View, SIGNAL(triggered(bool)), this, SLOT(showFlowViewWindow())); connect(ui->action_Custom, SIGNAL(triggered(bool)), this, SLOT(showFrameSenderWindow())); connect(ui->actionLoad_DBC_File, SIGNAL(triggered(bool)), this, SLOT(handleLoadDBC())); @@ -150,6 +129,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->btnFilterAll, SIGNAL(clicked(bool)), this, SLOT(filterSetAll())); connect(ui->btnFilterNone, SIGNAL(clicked(bool)), this, SLOT(filterClearAll())); connect(ui->actionFirmware_Uploader, SIGNAL(triggered(bool)), this, SLOT(showFirmwareUploaderWindow())); + connect(ui->actionSetup, SIGNAL(triggered(bool)), SLOT(showConnectionSettingsWindow())); + connect(ui->actionConnect, SIGNAL(triggered(bool)), this, SLOT(connButtonPress())); lbStatusConnected.setText(tr("Not connected")); updateFileStatus(); @@ -237,6 +218,12 @@ MainWindow::~MainWindow() delete discreteStateWindow; } + if (connectionWindow) + { + connectionWindow->close(); + delete connectionWindow; + } + delete ui; delete dbcHandler; model->clearFrames(); @@ -293,6 +280,56 @@ void MainWindow::writeSettings() } } +void MainWindow::updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1) +{ + connType = connectionType; + portName = port; + + canSpeed0 = speed0; + canSpeed1 = speed1; + if (isConnected) + { + emit updateBaudRates(speed0, speed1); + } +} + +void MainWindow::connButtonPress() +{ + if (!isConnected) + { + if (connType == "GVRET") + { + QList ports; + ports = QSerialPortInfo::availablePorts(); + + for (int i = 0; i < ports.count(); i++) + { + if (ports[i].portName() == portName) + { + portInfo = ports[i]; + emit sendSerialPort(&portInfo); + lbStatusConnected.setText(tr("Attempting to connect to port ") + portName); + } + } + } + else if (connType == "KVASER") + { + + } + else if (connType == "SOCKETCAN") + { + + } + } + else + { + emit closeSerialPort(); + isConnected = false; + lbStatusConnected.setText(tr("Not Connected")); + ui->actionConnect->setText(tr("Connect")); + } +} + void MainWindow::gridClicked(QModelIndex idx) { if (ui->canFramesView->rowHeight(idx.row()) > normalRowHeight) @@ -437,8 +474,8 @@ void MainWindow::changeBaudRates() { int Speed1 = 0, Speed2 = 0; - Speed1 = ui->cbSpeed1->currentText().toInt(); - Speed2 = ui->cbSpeed2->currentText().toInt(); + //Speed1 = ui->cbSpeed1->currentText().toInt(); + //Speed2 = ui->cbSpeed2->currentText().toInt(); emit updateBaudRates(Speed1, Speed2); } @@ -804,29 +841,6 @@ Data Bytes: 88 10 00 13 BB 00 06 00 outFile->close(); } -void MainWindow::connButtonPress() -{ - if (!isConnected) - { - for (int x = 0; x < ports.count(); x++) - { - if (ports.at(x).portName() == ui->cbSerialPorts->currentText()) - { - emit sendSerialPort(&ports[x]); - lbStatusConnected.setText(tr("Attempting to connect to port ") + ports[x].portName()); - return; - } - } - } - else - { - emit closeSerialPort(); - isConnected = false; - lbStatusConnected.setText(tr("Not Connected")); - ui->btnConnect->setText(tr("Connect to GVRET")); - } -} - void MainWindow::toggleCapture() { allowCapture = !allowCapture; @@ -847,7 +861,7 @@ void MainWindow::connectionSucceeded(int baud0, int baud1) lbStatusConnected.setText(tr("Connected to GVRET")); //finally, find the baud rate in the list of rates or //add it to the bottom if needed (that'll be weird though... - +/* int idx = ui->cbSpeed1->findText(QString::number(baud0)); if (idx > -1) ui->cbSpeed1->setCurrentIndex(idx); else @@ -863,8 +877,9 @@ void MainWindow::connectionSucceeded(int baud0, int baud1) ui->cbSpeed2->addItem(QString::number(baud1)); ui->cbSpeed2->setCurrentIndex(ui->cbSpeed2->count() - 1); } + */ //ui->btnConnect->setEnabled(false); - ui->btnConnect->setText(tr("Disconnect from GVRET")); + ui->actionConnect->setText(tr("Disconnect")); isConnected = true; } @@ -1038,6 +1053,7 @@ void MainWindow::exitApp() if (frameSenderWindow) frameSenderWindow->close(); if (dbcMainEditor) dbcMainEditor->close(); if (comparatorWindow) comparatorWindow->close(); + if (connectionWindow) connectionWindow->close(); this->close(); } @@ -1071,3 +1087,13 @@ void MainWindow::showDBCEditor() } dbcMainEditor->show(); } + +void MainWindow::showConnectionSettingsWindow() +{ + if (!connectionWindow) + { + connectionWindow = new ConnectionWindow(); + connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int))); + } + connectionWindow->show(); +} diff --git a/mainwindow.h b/mainwindow.h index 6149657..dcd29b3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,6 +19,7 @@ #include "mainsettingsdialog.h" #include "firmwareuploaderwindow.h" #include "discretestatewindow.h" +#include "connectionwindow.h" namespace Ui { class MainWindow; @@ -56,6 +57,7 @@ private slots: void showComparisonWindow(); void showSettingsDialog(); void showFirmwareUploaderWindow(); + void showConnectionSettingsWindow(); void exitApp(); void handleSaveDecoded(); void changeBaudRates(); @@ -78,6 +80,7 @@ public slots: void gotFrames(int, int); void updateSettings(); void gotCenterTimeID(int32_t ID, double timestamp); + void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1); signals: void sendSerialPort(QSerialPortInfo *port); @@ -98,8 +101,7 @@ private: //canbus related data CANFrameModel *model; - DBCHandler *dbcHandler; - QList ports; + DBCHandler *dbcHandler; QThread serialWorkerThread; SerialWorker *worker; QByteArray inputBuffer; @@ -121,6 +123,7 @@ private: MainSettingsDialog *settingsDialog; DiscreteStateWindow *discreteStateWindow; FirmwareUploaderWindow *firmwareUploaderWindow; + ConnectionWindow *connectionWindow; //various private storage QLabel lbStatusConnected; @@ -128,6 +131,9 @@ private: QLabel lbStatusDatabase; int normalRowHeight; bool isConnected; + QSerialPortInfo portInfo; + QString connType, portName; + int canSpeed0, canSpeed1; //private methods void saveDecodedTextFile(QString); diff --git a/mainwindow.ui b/mainwindow.ui index 57cbb8e..9226a3e 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -46,102 +46,6 @@ - - - - - 0 - 0 - - - - Serial Port - - - - - - - - - - Connect To GVRET - - - - - - - - 0 - 0 - - - - CANBus Speeds: - - - - - - - QLayout::SetDefaultConstraint - - - - - - - - 0 - 0 - - - - First Bus: - - - - - - - - - - - - 7 - - - QLayout::SetDefaultConstraint - - - - - - 0 - 0 - - - - Second Bus: - - - - - - - - - - - - - - Set CANBUS Speeds - - - @@ -293,7 +197,7 @@ 0 0 800 - 21 + 27 @@ -336,9 +240,17 @@ + + + Connection + + + + + @@ -446,6 +358,16 @@ Firmware Uploader + + + Setup + + + + + Connect + + diff --git a/serialworker.cpp b/serialworker.cpp index 096675f..be2f63e 100644 --- a/serialworker.cpp +++ b/serialworker.cpp @@ -69,7 +69,7 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port) delete serial; } - serial = new QSerialPort(*port); + serial = new QSerialPort(*port); qDebug() << "Serial port name is " << port->portName(); //serial->setBaudRate(10000000); //more speed! probably does nothing for USB serial