Add files for a new window for connections (allows for different types
of connections and also makes auto refreshing the port list easier)
This commit is contained in:
@@ -0,0 +1,148 @@
|
|||||||
|
#include "connectionwindow.h"
|
||||||
|
#include "ui_connectionwindow.h"
|
||||||
|
|
||||||
|
ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::ConnectionWindow)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
getSerialPorts();
|
||||||
|
|
||||||
|
ui->cbSpeed0->addItem(tr("<Default>"));
|
||||||
|
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("<Default>"));
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
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::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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#ifndef CONNECTIONWINDOW_H
|
||||||
|
#define CONNECTIONWINDOW_H
|
||||||
|
|
||||||
|
#include <QSerialPortInfo>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setSpeeds(int speed0, int speed1);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ConnectionWindow *ui;
|
||||||
|
QList<QSerialPortInfo> ports;
|
||||||
|
|
||||||
|
void getSerialPorts();
|
||||||
|
void getKvaserPorts();
|
||||||
|
void getSocketcanPorts();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONNECTIONWINDOW_H
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ConnectionWindow</class>
|
||||||
|
<widget class="QWidget" name="ConnectionWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>335</width>
|
||||||
|
<height>235</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Connection Settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Connection Type</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rbGVRET">
|
||||||
|
<property name="text">
|
||||||
|
<string>GVRET Serial</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rbKvaser">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Kvaser</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rbSocketCAN">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>SocketCAN</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Port:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cbPort"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>CAN0 Speed</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>CAN1 Speed</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QComboBox" name="cbSpeed0"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="cbSpeed1"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnOK">
|
||||||
|
<property name="text">
|
||||||
|
<string>OK</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user