Major revamp of the connection window. Hopefully it is more clear and

intuitive now.
This commit is contained in:
Collin Kidder
2019-03-05 21:25:32 -05:00
parent 70e8af85af
commit ec49413f61
17 changed files with 611 additions and 661 deletions
+6 -3
View File
@@ -66,7 +66,8 @@ SOURCES += main.cpp\
frameplaybackobject.cpp \
helpwindow.cpp \
blfhandler.cpp \
re/sniffer/SnifferDelegate.cpp
re/sniffer/SnifferDelegate.cpp \
connections/newconnectiondialog.cpp
HEADERS += mainwindow.h \
can_structs.h \
@@ -123,7 +124,8 @@ HEADERS += mainwindow.h \
frameplaybackobject.h \
helpwindow.h \
blfhandler.h \
re/sniffer/SnifferDelegate.h
re/sniffer/SnifferDelegate.h \
connections/newconnectiondialog.h
FORMS += ui/candatagrid.ui \
ui/connectionwindow.ui \
@@ -150,7 +152,8 @@ FORMS += ui/candatagrid.ui \
ui/udsscanwindow.ui \
ui/bisectwindow.ui \
ui/signalviewerwindow.ui \
helpwindow.ui
helpwindow.ui \
ui/newconnectiondialog.ui
DISTFILES +=
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CONFIG
#define CONFIG
#define VERSION 192
#define VERSION 193
//try to keep this in sync.
//SavvyCAN will complain if you connect a GVRET board with a revision
+1 -1
View File
@@ -40,7 +40,7 @@ void CANBus::setSingleWire(bool mode){
singleWire = mode;
}
void CANBus::setEnabled(bool mode){
void CANBus::setActive(bool mode){
//qDebug() << "CANBUS SetEnabled = " << mode;
active = mode;
}
+1 -1
View File
@@ -20,7 +20,7 @@ public:
void setSpeed(int); // new speed
void setListenOnly(bool); //bool for whether to only listen
void setSingleWire(bool); //bool for whether to use single wire mode
void setEnabled(bool); //whether this bus should be enabled or not.
void setActive(bool); //whether this bus should be enabled or not.
int getSpeed();
bool isListenOnly();
bool isSingleWire();
+11
View File
@@ -77,6 +77,17 @@ int CANConManager::getNumBuses()
return buses;
}
int CANConManager::getBusBase(CANConnection *which)
{
int buses = 0;
foreach(CANConnection* conn_p, mConns)
{
if (conn_p != which) buses += conn_p->getNumBuses();
else return buses;
}
return -1;
}
void CANConManager::refreshCanList()
{
QObject* sender_p = QObject::sender();
+1
View File
@@ -26,6 +26,7 @@ public:
void resetTimeBasis();
int getNumBuses();
int getBusBase(CANConnection *);
/**
* @brief sendFrame sends a single frame out the desired bus
+1 -1
View File
@@ -210,7 +210,7 @@ void CANConnection::setConfigured(int pBusId, bool pConfigured) {
bool CANConnection::getBusConfig(int pBusId, CANBus& pBus) {
if( pBusId < 0 || pBusId >= getNumBuses() || !isConfigured(pBusId))
return false;
qDebug() << "getBusConfig id: " << pBusId;
pBus = mBusData[pBusId].mBus;
return true;
}
+20 -134
View File
@@ -12,14 +12,11 @@ CANConnectionModel::~CANConnectionModel()
}
enum class Column {
Bus = 0, ///< A sequential number describing the bus
Type = 1, ///< The CAN driver/backend type, e.g. GVRET, peakcan, or socketcan
Type = 0, ///< The CAN driver/backend type, e.g. GVRET, peakcan, or socketcan
Subtype = 1, ///< Mostly used by SerialBus devices to pick the sub type
Port = 2, ///< The CAN hardware port, e.g. can0 for socketcan
Speed = 3, ///< The bus speed in bit/second
ListenOnly = 4, ///< True if the bus is in listen-only mode
SingleWire = 5, ///< True if the bus operates in single-wire mode
Active = 6, ///< True if the bus is activated for sending and receiving
Status = 7 ///< The bus status as text message
NumBuses = 3, ///< Number of buses exposed by this device. Usually non-GVRET devices will just have one
Status = 4 ///< The bus status as text message
};
QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -31,20 +28,14 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
{
switch (Column(section))
{
case Column::Bus:
return QString(tr("Bus"));
case Column::Type:
return QString(tr("Type"));
case Column::Subtype:
return QString(tr("Subtype"));
case Column::Port:
return QString(tr("Port"));
case Column::Speed:
return QString(tr("Speed"));
case Column::ListenOnly:
return QString(tr("Listen Only"));
case Column::SingleWire:
return QString(tr("Single Wire"));
case Column::Active:
return QString(tr("Active"));
case Column::NumBuses:
return QString(tr("Buses"));
case Column::Status:
return QString(tr("Status"));
}
@@ -59,7 +50,7 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
int CANConnectionModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 8;
return 5;
}
@@ -67,78 +58,9 @@ int CANConnectionModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
int rows = 0;
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
foreach(const CANConnection* conn_p, conns)
rows += conn_p->getNumBuses();
//qDebug() << "Num Rows: " << rows;
return rows;
}
Qt::ItemFlags CANConnectionModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemFlag::NoItemFlags;
int busId;
CANConnection *conn_p = getAtIdx(index.row(), busId);
if (!conn_p) return Qt::ItemFlag::NoItemFlags;
//socketcan is limited for what you can set but the other serialbus
//devices should be able to set the stuff. For now let anyone try
//and the underlying drivers can do with them as they will
bool editParams = true;
//if (conn_p->getType() == CANCon::GVRET_SERIAL) editParams = true;
switch (Column(index.column()))
{
case Column::Speed:
if (editParams) return Qt::ItemFlag::ItemIsEditable | Qt::ItemFlag::ItemIsEnabled;
return Qt::ItemFlag::NoItemFlags;
case Column::ListenOnly:
case Column::SingleWire:
if (editParams) return Qt::ItemFlag::ItemIsEditable | Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsUserCheckable;
return Qt::ItemFlag::NoItemFlags;
case Column::Active:
return Qt::ItemFlag::ItemIsEditable | Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsUserCheckable;
default:
return Qt::ItemFlag::ItemIsEnabled;
}
}
bool CANConnectionModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
qDebug() << "setData: " << index.row() << ":" << index.column() << " role: " << role << " Val: " << value;
int busId;
CANConnection *conn_p = getAtIdx(index.row(), busId);
if (!conn_p) return false;
CANBus bus;
bool ret;
ret = conn_p->getBusSettings(busId, bus);
if (!ret) return false;
switch (Column(index.column()))
{
case Column::Speed:
bus.speed = value.toInt();
break;
case Column::ListenOnly:
bus.listenOnly = value.toBool();
break;
case Column::SingleWire:
bus.singleWire = value.toBool();
break;
case Column::Active:
bus.active = value.toBool();
break;
default: {}
}
conn_p->setBusSettings(busId, bus);
return true;
return conns.count();
}
QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
@@ -147,23 +69,16 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
return QVariant();
//qDebug() << "Row: " << index.row();
int busId;
CANConnection *conn_p = getAtIdx(index.row(), busId);
CANBus bus;
CANConnection *conn_p = getAtIdx(index.row());
bool ret;
if (!conn_p) return QVariant();
ret = conn_p->getBusSettings(busId, bus);
bool isSocketCAN = (conn_p->getType() == CANCon::SERIALBUS) ? true: false;
//qDebug() << "ConnP: " << conn_p << " ret " << ret;
bool isSocketCAN = (conn_p->getType() == CANCon::SERIALBUS) ? true: false;
if (role == Qt::DisplayRole) {
switch (Column(index.column()))
{
case Column::Bus:
//return QString::number(busId);
return QString::number(index.row());
case Column::Type:
if (conn_p)
switch (conn_p->getType()) {
@@ -178,34 +93,16 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
if (conn_p) return conn_p->getPort();
else qDebug() << "Tried to show connection port but connection was NULL";
break;
case Column::Speed:
if(!ret) return QVariant();
if (!isSocketCAN) return QString::number(bus.speed);
else return QString("N/A");
case Column::ListenOnly:
return QVariant();
case Column::SingleWire:
return QVariant();
case Column::Active:
return QVariant();
case Column::Subtype:
return conn_p->getDriver();
break;
case Column::NumBuses:
return conn_p->getNumBuses();
break;
case Column::Status:
return (conn_p->getStatus()==CANCon::CONNECTED) ? "Connected" : "Not Connected";
}
}
if (role == Qt::CheckStateRole)
{
switch (Column(index.column()))
{
case Column::ListenOnly:
return (bus.listenOnly) ? Qt::Checked : Qt::Unchecked;
case Column::SingleWire:
return (bus.singleWire) ? Qt::Checked : Qt::Unchecked;
case Column::Active:
return (bus.active) ? Qt::Checked : Qt::Unchecked;
default: {}
}
}
return QVariant();
}
@@ -230,25 +127,14 @@ void CANConnectionModel::remove(CANConnection* pConn_p)
}
CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
CANConnection* CANConnectionModel::getAtIdx(int pIdx) const
{
if (pIdx < 0)
return NULL;
int i=0;
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
foreach(CANConnection* conn_p, conns)
{
if( i <= pIdx && pIdx < i+conn_p->getNumBuses() ) {
pBusId = pIdx - i;
return conn_p;
}
i+= conn_p->getNumBuses();
}
return NULL;
return conns.at(pIdx);
}
void CANConnectionModel::refresh(int pIndex)
+1 -4
View File
@@ -21,15 +21,12 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
void add(CANConnection* pConn_p);
void remove(CANConnection* pConn_p);
CANConnection* getAtIdx(int, int&) const;
CANConnection* getAtIdx(int) const;
void refresh(int pIndex=-1);
};
+120 -292
View File
@@ -10,6 +10,7 @@
#include "connections/canconmanager.h"
#include "canbus.h"
#include <QSettings>
#include <connections/newconnectiondialog.h>
ConnectionWindow::ConnectionWindow(QWidget *parent) :
QDialog(parent),
@@ -24,16 +25,15 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
qRegisterMetaType<const CANFrame *>("const CANFrame *");
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
//List of devices with details. None of it can be edited. connection type, serialbus type, port name, number of buses, status
connModel = new CANConnectionModel(this);
ui->tableConnections->setModel(connModel);
ui->tableConnections->setColumnWidth(0, 40);
ui->tableConnections->setColumnWidth(1, 70);
ui->tableConnections->setColumnWidth(2, 70);
ui->tableConnections->setColumnWidth(0, 100);
ui->tableConnections->setColumnWidth(1, 100);
ui->tableConnections->setColumnWidth(2, 100);
ui->tableConnections->setColumnWidth(3, 70);
ui->tableConnections->setColumnWidth(4, 70);
ui->tableConnections->setColumnWidth(5, 70);
ui->tableConnections->setColumnWidth(6, 70);
ui->tableConnections->setColumnWidth(7, 90);
ui->tableConnections->setColumnWidth(4, 200);
QHeaderView *HorzHdr = ui->tableConnections->horizontalHeader();
HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview
@@ -49,30 +49,28 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
loadConnections();
}
ui->rbSocketCAN->setEnabled(isSerialBusAvailable());
connect(ui->btnOK, &QAbstractButton::clicked, this, &ConnectionWindow::handleOKButton);
connect(ui->rbGVRET, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->rbSocketCAN, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->rbRemote, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->cbDeviceType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ConnectionWindow::handleDeviceTypeChanged);
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
connect(ui->btnReconnect, &QPushButton::clicked, this, &ConnectionWindow::handleReconnect);
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
connect(ui->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
connect(ui->btnDisconnect, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
connect(ui->btnSendHex, &QPushButton::clicked, this, &ConnectionWindow::handleSendHex);
connect(ui->btnSendText, &QPushButton::clicked, this, &ConnectionWindow::handleSendText);
connect(ui->ckEnableConsole, &QCheckBox::toggled, this, &ConnectionWindow::consoleEnableChanged);
connect(ui->btnClearDebug, &QPushButton::clicked, this, &ConnectionWindow::handleClearDebugText);
connect(ui->btnNewConnection, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
connect(ui->tabBuses, &QTabBar::currentChanged, this, &ConnectionWindow::currentTabChanged);
connect(ui->btnSaveBus, &QPushButton::clicked, this, &ConnectionWindow::saveBusSettings);
ui->lblDeviceType->setHidden(true);
ui->cbDeviceType->setHidden(true);
ui->cbBusSpeed->addItem("50000");
ui->cbBusSpeed->addItem("100000");
ui->cbBusSpeed->addItem("125000");
ui->cbBusSpeed->addItem("250000");
ui->cbBusSpeed->addItem("500000");
ui->cbBusSpeed->addItem("1000000");
rxBroadcast = new QUdpSocket(this);
rxBroadcast->bind(QHostAddress::AnyIPv4, 17222);
connect(rxBroadcast, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
}
@@ -114,7 +112,6 @@ void ConnectionWindow::showEvent(QShowEvent* event)
readSettings();
ui->tableConnections->selectRow(0);
currentRowChanged(ui->tableConnections->currentIndex(), ui->tableConnections->currentIndex());
handleConnTypeChanged();
}
void ConnectionWindow::closeEvent(QCloseEvent *event)
@@ -163,48 +160,6 @@ void ConnectionWindow::writeSettings()
}
}
void ConnectionWindow::setSuspendAll(bool pSuspend)
{
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
foreach(CANConnection* conn_p, conns)
conn_p->suspend(pSuspend);
connModel->refresh();
}
void ConnectionWindow::setActiveAll(bool pActive)
{
CANBus bus;
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
foreach(CANConnection* conn_p, conns)
{
for(int i=0 ; i<conn_p->getNumBuses() ; i++) {
if( conn_p->getBusSettings(i, bus) ) {
bus.active = pActive;
conn_p->setBusSettings(i, bus);
}
}
}
connModel->refresh();
}
void ConnectionWindow::handleReconnect()
{
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
if (selIdx <0) return;
int busId;
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
if(!conn_p) return;
conn_p->stop();
conn_p->start();
}
void ConnectionWindow::consoleEnableChanged(bool checked) {
ui->textConsole->setEnabled(checked);
ui->btnClearDebug->setEnabled(checked);
@@ -229,35 +184,21 @@ void ConnectionWindow::consoleEnableChanged(bool checked) {
void ConnectionWindow::handleNewConn()
{
ui->tableConnections->setCurrentIndex(QModelIndex());
currentRowChanged(ui->tableConnections->currentIndex(), ui->tableConnections->currentIndex());
}
NewConnectionDialog *thisDialog = new NewConnectionDialog(&remoteDeviceIP);
CANCon::type newType;
QString newPort;
QString newDriver;
CANConnection *conn;
void ConnectionWindow::handleEnableAll()
if (thisDialog->exec() == QDialog::Accepted)
{
setActiveAll(true);
newType = thisDialog->getConnectionType();
newPort = thisDialog->getPortName();
newDriver = thisDialog->getDriverName();
conn = create(newType, newPort, newDriver);
if (conn) connModel->add(conn);
}
void ConnectionWindow::handleDisableAll()
{
setActiveAll(false);
}
void ConnectionWindow::handleConnTypeChanged()
{
if (ui->rbGVRET->isChecked()) selectSerial();
if (ui->rbSocketCAN->isChecked()) selectSocketCan();
if (ui->rbRemote->isChecked()) selectRemote();
}
void ConnectionWindow::handleDeviceTypeChanged()
{
ui->cbPort->clear();
canDevices = QCanBus::instance()->availableDevices(ui->cbDeviceType->currentText());
for (int i = 0; i < canDevices.count(); i++)
ui->cbPort->addItem(canDevices[i].name());
delete thisDialog;
}
/* status */
@@ -269,22 +210,79 @@ void ConnectionWindow::connectionStatus(CANConStatus pStatus)
connModel->refresh();
}
void ConnectionWindow::handleOKButton()
void ConnectionWindow::saveBusSettings()
{
CANConnection* conn_p = nullptr;
int selIdx = ui->tableConnections->currentIndex().row();
int offset = ui->tabBuses->currentIndex();
if( ! CANConManager::getInstance()->getByName(getPortName()) )
{
/* create connection */
//qDebug() << "Create connection type: " << getConnectionType() << " port: " << getPortName() << " driver: " << getDriverName();
conn_p = create(getConnectionType(), getPortName(), getDriverName());
if(!conn_p)
/* set parameters */
if (selIdx == -1) {
return;
/* add connection to model */
connModel->add(conn_p);
consoleEnableChanged(ui->ckEnableConsole->isChecked());
}
else
{
CANConnection* conn_p = connModel->getAtIdx(selIdx);
CANBus bus;
if(!conn_p) return;
if (!conn_p->getBusSettings(offset, bus))
{
qDebug() << "Could not retrieve bus settings!";
return;
}
bus.setSpeed(ui->cbBusSpeed->currentText().toInt());
bus.setActive(ui->ckEnable->isChecked());
bus.setListenOnly(ui->ckListenOnly->isChecked());
conn_p->setBusSettings(offset, bus);
}
}
void ConnectionWindow::populateBusDetails(int offset)
{
int selIdx = ui->tableConnections->currentIndex().row();
/* set parameters */
if (selIdx == -1) {
return;
}
else
{
bool ret;
int numBuses;
CANConnection* conn_p = connModel->getAtIdx(selIdx);
CANBus bus;
if(!conn_p) return;
if (!conn_p->getBusSettings(offset, bus))
{
qDebug() << "Could not retrieve bus settings!";
return;
}
int busBase = CANConManager::getInstance()->getBusBase(conn_p);
ui->lblBusNum->setText(QString::number(busBase + offset));
ui->ckListenOnly->setChecked(bus.isListenOnly());
ui->ckEnable->setChecked(bus.isActive());
bool found = false;
for (int i = 0; i < ui->cbBusSpeed->count(); i++)
{
if (bus.getSpeed() == ui->cbBusSpeed->itemText(i).toInt())
{
found = true;
ui->cbBusSpeed->setCurrentIndex(i);
break;
}
}
if (!found) ui->cbBusSpeed->addItem(QString::number(bus.getSpeed()));
}
}
void ConnectionWindow::currentTabChanged(int newIdx)
{
populateBusDetails(newIdx);
}
void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
@@ -293,43 +291,33 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
int selIdx = current.row();
int busId;
disconnect(connModel->getAtIdx(previous.row(), busId), SIGNAL(debugOutput(QString)), 0, 0);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), connModel->getAtIdx(previous.row(), busId), SLOT(debugInput(QByteArray)));
return;
/* enable / diable connection type */
ui->stPort->setEnabled(selIdx==-1);
ui->gbType->setEnabled(selIdx==-1);
ui->lPort->setEnabled(selIdx==-1);
disconnect(connModel->getAtIdx(previous.row()), SIGNAL(debugOutput(QString)), 0, 0);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), connModel->getAtIdx(previous.row()), SLOT(debugInput(QByteArray)));
/* set parameters */
if (selIdx == -1)
{
ui->btnOK->setText(tr("Create New Connection"));
ui->rbGVRET->setChecked(true);
setSpeed(0);
setPortName(CANCon::GVRET_SERIAL, "", "");
if (selIdx == -1) {
ui->groupBus->setEnabled(false);
return;
}
else
{
bool ret;
CANBus bus;
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
ui->groupBus->setEnabled(true);
int numBuses;
CANConnection* conn_p = connModel->getAtIdx(selIdx);
if(!conn_p) return;
if (ui->ckEnableConsole->isChecked()) { //only connect if console is actually enabled
connect(conn_p, SIGNAL(debugOutput(QString)), this, SLOT(getDebugText(QString)));
connect(this, SIGNAL(sendDebugData(QByteArray)), conn_p, SLOT(debugInput(QByteArray)));
numBuses = conn_p->getNumBuses();
if (numBuses == 1) //remove all tabs if there is only one bus
{
for (int i = 0; i < ui->tabBuses->count(); i++) ui->tabBuses->removeTab(0);
}
ret = conn_p->getBusSettings(busId, bus);
if(!ret) return;
ui->btnOK->setText(tr("Update Connection Settings"));
setSpeed(bus.getSpeed());
setPortName(conn_p->getType(), conn_p->getPort(), conn_p->getDriver());
else
{
for (int i = 0; i < numBuses; i++) ui->tabBuses->addTab(QString::number(i+1));
}
populateBusDetails(0);
}
}
@@ -357,152 +345,6 @@ void ConnectionWindow::handleSendText() {
emit sendDebugData(bytes);
}
void ConnectionWindow::selectSerial()
{
ui->lPort->setText("Port:");
/* set combobox page visible */
ui->stPort->setCurrentWidget(ui->cbPage);
ui->lblDeviceType->setHidden(true);
ui->cbDeviceType->setHidden(true);
ui->cbPort->clear();
ports = QSerialPortInfo::availablePorts();
for (int i = 0; i < ports.count(); i++)
ui->cbPort->addItem(ports[i].portName());
}
void ConnectionWindow::selectSocketCan()
{
ui->lPort->setText("Port:");
/* set edit text page visible */
ui->stPort->setCurrentWidget(ui->cbPage);
ui->lblDeviceType->setHidden(false);
ui->cbDeviceType->setHidden(false);
ui->cbDeviceType->clear();
QStringList plugins;
plugins = QCanBus::instance()->plugins();
for (int i = 0; i < plugins.count(); i++)
ui->cbDeviceType->addItem(plugins[i]);
}
void ConnectionWindow::selectRemote()
{
ui->lPort->setText("IP Address:");
ui->stPort->setCurrentWidget(ui->cbPage);
ui->lblDeviceType->setHidden(true);
ui->cbDeviceType->setHidden(true);
ui->cbPort->clear();
foreach(QString pName, remoteDeviceIP)
{
ui->cbPort->addItem(pName);
}
}
void ConnectionWindow::setSpeed(int speed0)
{
Q_UNUSED(speed0);
}
void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName, QString pDriver)
{
switch(pType)
{
case CANCon::GVRET_SERIAL:
ui->rbGVRET->setChecked(true);
break;
case CANCon::SERIALBUS:
ui->rbSocketCAN->setChecked(true);
//you can't configure any of the below three with socketcan so dim them out
break;
default: {}
}
/* refresh names whenever needed */
handleConnTypeChanged();
switch(pType)
{
case CANCon::GVRET_SERIAL:
{
int idx = ui->cbPort->findText(pPortName);
if( idx<0 ) idx=0;
ui->cbPort->setCurrentIndex(idx);
break;
}
case CANCon::SERIALBUS:
{
int idx = ui->cbDeviceType->findText(pDriver);
if (idx < 0) idx = 0;
ui->cbDeviceType->setCurrentIndex(idx);
idx = ui->cbPort->findText(pPortName);
if( idx < 0 ) idx = 0;
ui->cbPort->setCurrentIndex(idx);
break;
}
case CANCon::REMOTE:
{
int idx = ui->cbPort->findText(pPortName);
if (idx > -1) ui->cbPort->setCurrentIndex(idx);
else ui->cbPort->addItem(pPortName);
break;
}
default: {}
}
}
//-1 means leave it at whatever it booted up to. 0 means disable. Otherwise the actual rate we want.
int ConnectionWindow::getSpeed()
{
return -1;
}
QString ConnectionWindow::getPortName()
{
switch( getConnectionType() ) {
case CANCon::GVRET_SERIAL:
case CANCon::SERIALBUS:
case CANCon::REMOTE:
return ui->cbPort->currentText();
default:
qDebug() << "getPortName: can't get port";
}
return "";
}
QString ConnectionWindow::getDriverName()
{
if (getConnectionType() == CANCon::SERIALBUS)
{
return ui->cbDeviceType->currentText();
}
return "";
}
CANCon::type ConnectionWindow::getConnectionType()
{
if (ui->rbGVRET->isChecked()) return CANCon::GVRET_SERIAL;
if (ui->rbSocketCAN->isChecked()) return CANCon::SERIALBUS;
if (ui->rbRemote->isChecked()) return CANCon::REMOTE;
qDebug() << "getConnectionType: error";
return CANCon::NONE;
}
void ConnectionWindow::setSWMode(bool mode)
{
Q_UNUSED(mode);
}
bool ConnectionWindow::getSWMode()
{
return false;
}
void ConnectionWindow::handleRemoveConn()
{
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
@@ -510,8 +352,7 @@ void ConnectionWindow::handleRemoveConn()
qDebug() << "remove connection at index: " << selIdx;
int busId;
CANConnection* conn_p = connModel->getAtIdx(selIdx, busId);
CANConnection* conn_p = connModel->getAtIdx(selIdx);
if(!conn_p) return;
/* remove connection from model & manager */
@@ -525,19 +366,6 @@ void ConnectionWindow::handleRemoveConn()
ui->tableConnections->selectRow(0);
}
void ConnectionWindow::handleRevert()
{
}
bool ConnectionWindow::isSerialBusAvailable()
{
if (QCanBus::instance()->plugins().count() > 0) return true;
return false;
}
CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver)
{
CANConnection* conn_p;
+4 -29
View File
@@ -3,8 +3,8 @@
#include <QSerialPortInfo>
#include <QDialog>
#include <QSerialPortInfo>
#include <QDebug>
#include <QSettings>
#include <QTimer>
@@ -30,61 +30,36 @@ public:
explicit ConnectionWindow(QWidget *parent = 0);
~ConnectionWindow();
CANCon::type getConnectionType();
bool getSWMode();
signals:
void updateBusSettings(CANBus *bus);
void updatePortName(QString port);
void sendDebugData(QByteArray bytes);
public slots:
void setSpeed(int speed0);
void setSWMode(bool mode);
void setSuspendAll(bool pSuspend);
void getDebugText(QString debugText);
private slots:
void handleOKButton();
void handleConnTypeChanged();
void handleDeviceTypeChanged();
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void currentTabChanged(int newIdx);
void consoleEnableChanged(bool checked);
void handleRemoveConn();
void handleEnableAll();
void handleDisableAll();
void handleReconnect();
void handleRevert();
void handleNewConn();
void handleClearDebugText();
void handleSendHex();
void handleSendText();
void saveBusSettings();
void connectionStatus(CANConStatus);
void readPendingDatagrams();
private:
Ui::ConnectionWindow *ui;
QList<QSerialPortInfo> ports;
QList<QCanBusDeviceInfo> canDevices;
QSettings *settings;
CANConnectionModel *connModel;
QUdpSocket *rxBroadcast;
QVector<QString> remoteDeviceIP;
void selectSerial();
void selectKvaser();
void selectSocketCan();
void selectRemote();
bool isSerialBusAvailable();
int getSpeed();
QString getPortName();
QString getDriverName();
void setPortName(CANCon::type pType, QString pPortName, QString pDriver);
void setActiveAll(bool pActive);
CANConnection* create(CANCon::type pTye, QString pPortName, QString pDriver);
void populateBusDetails(int offset);
void loadConnections();
void saveConnections();
void showEvent(QShowEvent *);
+3 -3
View File
@@ -819,8 +819,8 @@ void GVRetSerial::procRXChar(unsigned char c)
qDebug() << "Baud 1 = " << can1Baud;
mBusData[0].mBus.setSpeed(can0Baud);
mBusData[1].mBus.setSpeed(can1Baud);
mBusData[0].mBus.setEnabled(can0Enabled);
mBusData[1].mBus.setEnabled(can1Enabled);
mBusData[0].mBus.setActive(can0Enabled);
mBusData[1].mBus.setActive(can1Enabled);
mBusData[0].mConfigured = true;
mBusData[1].mConfigured = true;
@@ -962,7 +962,7 @@ void GVRetSerial::procRXChar(unsigned char c)
if (getNumBuses() > 2)
{
mBusData[2].mBus.setSpeed(swcanBaud);
mBusData[2].mBus.setEnabled(swcanEnabled);
mBusData[2].mBus.setActive(swcanEnabled);
}
setStatus(CANCon::CONNECTED);
+177
View File
@@ -0,0 +1,177 @@
#include <QCanBus>
#include "newconnectiondialog.h"
#include "ui_newconnectiondialog.h"
NewConnectionDialog::NewConnectionDialog(QVector<QString>* ips, QWidget *parent) :
QDialog(parent),
ui(new Ui::NewConnectionDialog),
remoteDeviceIP(ips)
{
ui->setupUi(this);
ui->rbSocketCAN->setEnabled(isSerialBusAvailable());
connect(ui->rbGVRET, &QAbstractButton::clicked, this, &NewConnectionDialog::handleConnTypeChanged);
connect(ui->rbSocketCAN, &QAbstractButton::clicked, this, &NewConnectionDialog::handleConnTypeChanged);
connect(ui->rbRemote, &QAbstractButton::clicked, this, &NewConnectionDialog::handleConnTypeChanged);
connect(ui->cbDeviceType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &NewConnectionDialog::handleDeviceTypeChanged);
connect(ui->btnOK, &QPushButton::clicked, this, &NewConnectionDialog::handleCreateButton);
ui->lblDeviceType->setHidden(true);
ui->cbDeviceType->setHidden(true);
selectSerial();
}
NewConnectionDialog::~NewConnectionDialog()
{
delete ui;
}
void NewConnectionDialog::handleCreateButton()
{
accept();
}
void NewConnectionDialog::handleConnTypeChanged()
{
if (ui->rbGVRET->isChecked()) selectSerial();
if (ui->rbSocketCAN->isChecked()) selectSocketCan();
if (ui->rbRemote->isChecked()) selectRemote();
}
void NewConnectionDialog::handleDeviceTypeChanged()
{
ui->cbPort->clear();
canDevices = QCanBus::instance()->availableDevices(ui->cbDeviceType->currentText());
for (int i = 0; i < canDevices.count(); i++)
ui->cbPort->addItem(canDevices[i].name());
}
void NewConnectionDialog::selectSerial()
{
ui->lPort->setText("Serial Port:");
ui->lblDeviceType->setHidden(true);
ui->cbDeviceType->setHidden(true);
ui->cbPort->clear();
ports = QSerialPortInfo::availablePorts();
for (int i = 0; i < ports.count(); i++)
ui->cbPort->addItem(ports[i].portName());
}
void NewConnectionDialog::selectSocketCan()
{
ui->lPort->setText("Port:");
ui->lblDeviceType->setHidden(false);
ui->cbDeviceType->setHidden(false);
ui->cbDeviceType->clear();
QStringList plugins;
plugins = QCanBus::instance()->plugins();
for (int i = 0; i < plugins.count(); i++)
ui->cbDeviceType->addItem(plugins[i]);
}
void NewConnectionDialog::selectRemote()
{
ui->lPort->setText("IP Address:");
ui->lblDeviceType->setHidden(true);
ui->cbDeviceType->setHidden(true);
ui->cbPort->clear();
foreach(QString pName, *remoteDeviceIP)
{
ui->cbPort->addItem(pName);
}
}
void NewConnectionDialog::setPortName(CANCon::type pType, QString pPortName, QString pDriver)
{
switch(pType)
{
case CANCon::GVRET_SERIAL:
ui->rbGVRET->setChecked(true);
break;
case CANCon::SERIALBUS:
ui->rbSocketCAN->setChecked(true);
//you can't configure any of the below three with socketcan so dim them out
break;
default: {}
}
/* refresh names whenever needed */
//handleConnTypeChanged();
switch(pType)
{
case CANCon::GVRET_SERIAL:
{
int idx = ui->cbPort->findText(pPortName);
if( idx<0 ) idx=0;
ui->cbPort->setCurrentIndex(idx);
break;
}
case CANCon::SERIALBUS:
{
int idx = ui->cbDeviceType->findText(pDriver);
if (idx < 0) idx = 0;
ui->cbDeviceType->setCurrentIndex(idx);
idx = ui->cbPort->findText(pPortName);
if( idx < 0 ) idx = 0;
ui->cbPort->setCurrentIndex(idx);
break;
}
case CANCon::REMOTE:
{
int idx = ui->cbPort->findText(pPortName);
if (idx > -1) ui->cbPort->setCurrentIndex(idx);
else ui->cbPort->addItem(pPortName);
break;
}
default: {}
}
}
QString NewConnectionDialog::getPortName()
{
switch( getConnectionType() ) {
case CANCon::GVRET_SERIAL:
case CANCon::SERIALBUS:
case CANCon::REMOTE:
return ui->cbPort->currentText();
default:
qDebug() << "getPortName: can't get port";
}
return "";
}
QString NewConnectionDialog::getDriverName()
{
if (getConnectionType() == CANCon::SERIALBUS)
{
return ui->cbDeviceType->currentText();
}
return "N/A";
}
CANCon::type NewConnectionDialog::getConnectionType()
{
if (ui->rbGVRET->isChecked()) return CANCon::GVRET_SERIAL;
if (ui->rbSocketCAN->isChecked()) return CANCon::SERIALBUS;
if (ui->rbRemote->isChecked()) return CANCon::REMOTE;
qDebug() << "getConnectionType: error";
return CANCon::NONE;
}
bool NewConnectionDialog::isSerialBusAvailable()
{
if (QCanBus::instance()->plugins().count() > 0) return true;
return false;
}
+47
View File
@@ -0,0 +1,47 @@
#ifndef NEWCONNECTIONDIALOG_H
#define NEWCONNECTIONDIALOG_H
#include <QDialog>
#include <QCanBusDeviceInfo>
#include <QSerialPortInfo>
#include <QDebug>
#include <QUdpSocket>
#include "canconnectionmodel.h"
#include "connections/canconnection.h"
namespace Ui {
class NewConnectionDialog;
}
class NewConnectionDialog : public QDialog
{
Q_OBJECT
public:
explicit NewConnectionDialog(QVector<QString>* ips, QWidget *parent = nullptr);
~NewConnectionDialog();
CANCon::type getConnectionType();
QString getPortName();
QString getDriverName();
public slots:
void handleConnTypeChanged();
void handleDeviceTypeChanged();
void handleCreateButton();
private:
Ui::NewConnectionDialog *ui;
QList<QSerialPortInfo> ports;
QList<QCanBusDeviceInfo> canDevices;
QVector<QString>* remoteDeviceIP;
void selectSerial();
void selectKvaser();
void selectSocketCan();
void selectRemote();
bool isSerialBusAvailable();
void setPortName(CANCon::type pType, QString pPortName, QString pDriver);
};
#endif // NEWCONNECTIONDIALOG_H
+2 -2
View File
@@ -46,7 +46,7 @@ void SerialBusConnection::piStarted()
mTimer.setInterval(1000);
mTimer.setSingleShot(false); //keep ticking
mTimer.start();
mBusData[0].mBus.setEnabled(true);
mBusData[0].mBus.setActive(true);
mBusData[0].mConfigured = true;
}
@@ -281,7 +281,7 @@ void SerialBusConnection::testConnection() {
CANBus bus;
if(getBusConfig(0, bus))
{
bus.setEnabled(true);
bus.setActive(true);
setBusSettings(0, bus);
}
+82 -166
View File
@@ -19,7 +19,7 @@
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Connections:</string>
<string>Connected Devices:</string>
</property>
</widget>
</item>
@@ -37,195 +37,104 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="btnReconnect">
<widget class="QPushButton" name="btnNewConnection">
<property name="text">
<string>Reconnect</string>
<string>Add New Device Connection</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemoveBus">
<widget class="QPushButton" name="btnDisconnect">
<property name="text">
<string>Remove Selected Connection</string>
<string>Disconnect Selected Device</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnActivateAll">
<widget class="QGroupBox" name="groupBus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Bus Details:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<layout class="QVBoxLayout" name="qhBox20">
<item>
<widget class="QTabBar" name="tabBuses" native="true"/>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Activate All Connections</string>
<string>CAN Bus Number:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnDeactivateAll">
<item row="0" column="1">
<widget class="QLabel" name="lblBusNum">
<property name="text">
<string>Deactivate All Connections</string>
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Speed:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbBusSpeed"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Listen Only:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="ckListenOnly">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Enable Bus:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="ckEnable">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="btnSaveBus">
<property name="text">
<string>Save Bus Settings</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="gbType">
<property name="title">
<string>Connection Type</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="rbGVRET">
<property name="text">
<string>GVRET Serial</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="rbSocketCAN">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>QT SerialBus Devices (SocketCAN, PeakCAN, etc)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbRemote">
<property name="text">
<string>Remote Host</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDeviceType">
<property name="text">
<string>Device Type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbDeviceType"/>
</item>
<item>
<widget class="QLabel" name="lPort">
<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="QStackedWidget" name="stPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="cbPage">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QComboBox" name="cbPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>341</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="etPage">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLineEdit" name="lePort">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="btnOK">
<property name="text">
<string>Create New Connection</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QCheckBox" name="ckEnableConsole">
<property name="text">
@@ -299,6 +208,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QTabBar</class>
<extends>QWidget</extends>
<header>qtabbar.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+109
View File
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewConnectionDialog</class>
<widget class="QDialog" name="NewConnectionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>282</height>
</rect>
</property>
<property name="windowTitle">
<string>New Connection</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="gbType">
<property name="title">
<string>Connection Type</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="rbGVRET">
<property name="text">
<string>Serial Connection</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="rbSocketCAN">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>QT SerialBus Devices (SocketCAN, PeakCAN, etc)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbRemote">
<property name="text">
<string>Network connection</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDeviceType">
<property name="text">
<string>SerialBus Device Type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbDeviceType"/>
</item>
<item>
<widget class="QLabel" name="lPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Serial Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>341</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOK">
<property name="text">
<string>Create New Connection</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>