diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 18d595e..40140e3 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets serialport printsupport qml + CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT CONFIG += c++11 qscintilla2 @@ -36,6 +37,7 @@ SOURCES += main.cpp\ mainsettingsdialog.cpp \ firmwareuploaderwindow.cpp \ discretestatewindow.cpp \ + connectionwindow.cpp \ scriptingwindow.cpp \ scriptcontainer.cpp \ canfilter.cpp \ @@ -65,6 +67,7 @@ HEADERS += mainwindow.h \ mainsettingsdialog.h \ firmwareuploaderwindow.h \ discretestatewindow.h \ + connectionwindow.h \ scriptingwindow.h \ scriptcontainer.h \ canfilter.h \ @@ -84,6 +87,7 @@ FORMS += mainwindow.ui \ mainsettingsdialog.ui \ firmwareuploaderwindow.ui \ discretestatewindow.ui \ + connectionwindow.ui \ scriptingwindow.ui \ rangestatewindow.ui diff --git a/config.h b/config.h index 6e1c7c4..4c832a0 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 144 +#define VERSION 145 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/connectionwindow.cpp b/connectionwindow.cpp new file mode 100644 index 0000000..5c5db26 --- /dev/null +++ b/connectionwindow.cpp @@ -0,0 +1,186 @@ +#include "connectionwindow.h" +#include "ui_connectionwindow.h" +#include + +ConnectionWindow::ConnectionWindow(QWidget *parent) : + QDialog(parent), + ui(new Ui::ConnectionWindow) +{ + ui->setupUi(this); + + //getSerialPorts(); + getSocketcanPorts(); + + ui->cbSpeed0->addItem(tr("")); + ui->cbSpeed0->addItem(tr("Disabled")); + ui->cbSpeed0->addItem(tr("125000")); + ui->cbSpeed0->addItem(tr("250000")); + ui->cbSpeed0->addItem(tr("500000")); + ui->cbSpeed0->addItem(tr("1000000")); + ui->cbSpeed0->addItem(tr("33333")); + + ui->cbSpeed1->addItem(tr("")); + 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")); + +#ifdef Q_OS_LINUX + ui->rbSocketCAN->setEnabled(true); +#endif + +#ifdef Q_OS_WIN + ui->rbKvaser->setEnabled(true); +#endif + + connect(ui->btnOK, SIGNAL(clicked(bool)), this, SLOT(handleOKButton())); +} + +ConnectionWindow::~ConnectionWindow() +{ + delete ui; +} + +void ConnectionWindow::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + qDebug() << "Show connectionwindow"; + if (ui->rbGVRET->isChecked()) getSerialPorts(); + if (ui->rbKvaser->isChecked()) getKvaserPorts(); + 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(); + ports = QSerialPortInfo::availablePorts(); + + for (int i = 0; i < ports.count(); i++) + { + ui->cbPort->addItem(ports[i].portName()); + } +} + +void ConnectionWindow::getKvaserPorts() +{ + +} + +void ConnectionWindow::getSocketcanPorts() +{ + QList interfaces = QNetworkInterface::allInterfaces(); + QString interfaceName; + + ui->cbPort->clear(); + + foreach (QNetworkInterface interface, interfaces) + { + interfaceName = interface.name().toLower(); + qDebug() << "Interface: " << interface.name(); + if (interfaceName.contains("can")) + { + ui->cbPort->addItem(interfaceName); + } + } +} + +void ConnectionWindow::setSpeeds(int speed0, int speed1) +{ + bool found = false; + + for (int i = 0; i < ui->cbSpeed0->count(); i++) + { + if (ui->cbSpeed0->itemText(i).toInt() == speed0) + { + ui->cbSpeed0->setCurrentIndex(i); + found = true; + } + } + if (!found) + { + ui->cbSpeed0->addItem(QString::number(speed0)); + ui->cbSpeed0->setCurrentIndex(ui->cbSpeed0->count() - 1); + } + + found = false; + for (int i = 0; i < ui->cbSpeed1->count(); i++) + { + if (ui->cbSpeed1->itemText(i).toInt() == speed1) + { + ui->cbSpeed1->setCurrentIndex(i); + found = true; + } + } + if (!found) + { + ui->cbSpeed1->addItem(QString::number(speed1)); + ui->cbSpeed1->setCurrentIndex(ui->cbSpeed1->count() - 1); + } +} + + +//-1 means leave it at whatever it booted up to. 0 means disable. Otherwise the actual rate we want. +int ConnectionWindow::getSpeed0() +{ + switch (ui->cbSpeed0->currentIndex()) + { + case -1: + return -1; + break; + case 0: + return -1; + break; + case 1: + return 0; + break; + default: + return (ui->cbSpeed0->currentText().toInt()); + break; + } +} + +int ConnectionWindow::getSpeed1() +{ + switch (ui->cbSpeed1->currentIndex()) + { + case -1: + return -1; + break; + case 0: + return -1; + break; + case 1: + return 0; + break; + default: + return (ui->cbSpeed1->currentText().toInt()); + break; + } +} + +QString ConnectionWindow::getPortName() +{ + return (ui->cbPort->currentText()); +} + +ConnectionType::ConnectionType ConnectionWindow::getConnectionType() +{ + if (ui->rbGVRET->isChecked()) return ConnectionType::GVRET_SERIAL; + if (ui->rbKvaser->isChecked()) return ConnectionType::KVASER; + if (ui->rbSocketCAN->isChecked()) return ConnectionType::SOCKETCAN; +} diff --git a/connectionwindow.h b/connectionwindow.h new file mode 100644 index 0000000..cb4a437 --- /dev/null +++ b/connectionwindow.h @@ -0,0 +1,53 @@ +#ifndef CONNECTIONWINDOW_H +#define CONNECTIONWINDOW_H + +#include +#include +#include + +namespace Ui { +class ConnectionWindow; +} + +namespace ConnectionType +{ + enum ConnectionType + { + GVRET_SERIAL, + KVASER, + SOCKETCAN + }; +} + +class ConnectionWindow : public QDialog +{ + Q_OBJECT + +public: + explicit ConnectionWindow(QWidget *parent = 0); + ~ConnectionWindow(); + void showEvent(QShowEvent *); + int getSpeed0(); + int getSpeed1(); + QString getPortName(); //name of port to connect to + ConnectionType::ConnectionType getConnectionType(); + +signals: + 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; + + void getSerialPorts(); + void getKvaserPorts(); + void getSocketcanPorts(); +}; + +#endif // CONNECTIONWINDOW_H diff --git a/connectionwindow.ui b/connectionwindow.ui new file mode 100644 index 0000000..a6e754d --- /dev/null +++ b/connectionwindow.ui @@ -0,0 +1,110 @@ + + + ConnectionWindow + + + + 0 + 0 + 335 + 235 + + + + Connection Settings + + + + + + Connection Type + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + GVRET Serial + + + true + + + + + + + false + + + Kvaser + + + + + + + false + + + SocketCAN + + + + + + + + + + + 0 + 0 + + + + Port: + + + + + + + + + + + + CAN0 Speed + + + + + + + CAN1 Speed + + + + + + + + + + + + + + + Update Settings + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 19f6bef..2358769 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -61,26 +61,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); @@ -109,6 +89,7 @@ MainWindow::MainWindow(QWidget *parent) : settingsDialog = NULL; firmwareUploaderWindow = NULL; discreteStateWindow = NULL; + connectionWindow = NULL; scriptingWindow = NULL; rangeWindow = NULL; dbcHandler = new DBCHandler; @@ -117,7 +98,8 @@ MainWindow::MainWindow(QWidget *parent) : model->setDBCHandler(dbcHandler); - connect(ui->btnConnect, &QAbstractButton::clicked, this, &MainWindow::connButtonPress); + connect(ui->actionSetup, SIGNAL(triggered(bool)), SLOT(showConnectionSettingsWindow())); + connect(ui->actionConnect, SIGNAL(triggered(bool)), this, SLOT(connButtonPress())); connect(ui->actionOpen_Log_File, &QAction::triggered, this, &MainWindow::handleLoadFile); connect(ui->actionGraph_Dta, &QAction::triggered, this, &MainWindow::showGraphingWindow); connect(ui->actionFrame_Data_Analysis, &QAction::triggered, this, &MainWindow::showFrameDataAnalysis); @@ -239,6 +221,12 @@ MainWindow::~MainWindow() delete discreteStateWindow; } + if (connectionWindow) + { + connectionWindow->close(); + delete connectionWindow; + } + if (scriptingWindow) { scriptingWindow->close(); @@ -307,6 +295,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) @@ -451,8 +489,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); } @@ -833,29 +871,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; @@ -876,7 +891,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 @@ -892,8 +907,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; } @@ -1081,6 +1097,7 @@ void MainWindow::exitApp() if (frameSenderWindow) frameSenderWindow->close(); if (dbcMainEditor) dbcMainEditor->close(); if (comparatorWindow) comparatorWindow->close(); + if (connectionWindow) connectionWindow->close(); this->close(); } @@ -1114,3 +1131,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 33ca328..38007f6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,6 +19,7 @@ #include "mainsettingsdialog.h" #include "firmwareuploaderwindow.h" #include "discretestatewindow.h" +#include "connectionwindow.h" #include "scriptingwindow.h" #include "rangestatewindow.h" @@ -58,7 +59,11 @@ private slots: void showComparisonWindow(); void showSettingsDialog(); void showFirmwareUploaderWindow(); +<<<<<<< HEAD + void showConnectionSettingsWindow(); +======= void showScriptingWindow(); +>>>>>>> WIP2 void exitApp(); void handleSaveDecoded(); void changeBaudRates(); @@ -81,6 +86,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); @@ -101,8 +107,7 @@ private: //canbus related data CANFrameModel *model; - DBCHandler *dbcHandler; - QList ports; + DBCHandler *dbcHandler; QThread serialWorkerThread; SerialWorker *worker; QByteArray inputBuffer; @@ -124,8 +129,12 @@ private: MainSettingsDialog *settingsDialog; DiscreteStateWindow *discreteStateWindow; FirmwareUploaderWindow *firmwareUploaderWindow; +<<<<<<< HEAD + ConnectionWindow *connectionWindow; +======= ScriptingWindow *scriptingWindow; RangeStateWindow *rangeWindow; +>>>>>>> WIP2 //various private storage QLabel lbStatusConnected; @@ -133,6 +142,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 09596fc..87b22e4 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 - - - @@ -335,9 +239,17 @@ + + + Connection + + + + + @@ -350,16 +262,6 @@ Custom - - - Single / Multi State - - - - - Range State - - Flow View @@ -445,6 +347,14 @@ Firmware Uploader + + + Setup + + + + + Connect Scripting Interface diff --git a/serialworker.cpp b/serialworker.cpp index 315a71f..51cea4a 100644 --- a/serialworker.cpp +++ b/serialworker.cpp @@ -82,7 +82,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