Added ability to automatically find ESP32RET devices on the local network
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include <QCanBus>
|
#include <QCanBus>
|
||||||
|
#include <QNetworkDatagram>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#include "connectionwindow.h"
|
#include "connectionwindow.h"
|
||||||
@@ -67,8 +68,24 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
|
|||||||
|
|
||||||
ui->lblDeviceType->setHidden(true);
|
ui->lblDeviceType->setHidden(true);
|
||||||
ui->cbDeviceType->setHidden(true);
|
ui->cbDeviceType->setHidden(true);
|
||||||
|
|
||||||
|
rxBroadcast = new QUdpSocket(this);
|
||||||
|
rxBroadcast->bind(QHostAddress::AnyIPv4, 17222);
|
||||||
|
|
||||||
|
connect(rxBroadcast, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConnectionWindow::readPendingDatagrams()
|
||||||
|
{
|
||||||
|
while (rxBroadcast->hasPendingDatagrams()) {
|
||||||
|
QNetworkDatagram datagram = rxBroadcast->receiveDatagram();
|
||||||
|
if (!remoteDeviceIP.contains(datagram.senderAddress().toString()))
|
||||||
|
{
|
||||||
|
remoteDeviceIP.append(datagram.senderAddress().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
ConnectionWindow::~ConnectionWindow()
|
ConnectionWindow::~ConnectionWindow()
|
||||||
{
|
{
|
||||||
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
QList<CANConnection*>& conns = CANConManager::getInstance()->getConnections();
|
||||||
@@ -373,9 +390,14 @@ void ConnectionWindow::selectSocketCan()
|
|||||||
void ConnectionWindow::selectRemote()
|
void ConnectionWindow::selectRemote()
|
||||||
{
|
{
|
||||||
ui->lPort->setText("IP Address:");
|
ui->lPort->setText("IP Address:");
|
||||||
ui->stPort->setCurrentWidget(ui->etPage);
|
ui->stPort->setCurrentWidget(ui->cbPage);
|
||||||
ui->lblDeviceType->setHidden(true);
|
ui->lblDeviceType->setHidden(true);
|
||||||
ui->cbDeviceType->setHidden(true);
|
ui->cbDeviceType->setHidden(true);
|
||||||
|
ui->cbPort->clear();
|
||||||
|
foreach(QString pName, remoteDeviceIP)
|
||||||
|
{
|
||||||
|
ui->cbPort->addItem(pName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::setSpeed(int speed0)
|
void ConnectionWindow::setSpeed(int speed0)
|
||||||
@@ -421,7 +443,9 @@ void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName, QStrin
|
|||||||
}
|
}
|
||||||
case CANCon::REMOTE:
|
case CANCon::REMOTE:
|
||||||
{
|
{
|
||||||
ui->lePort->setText(pPortName);
|
int idx = ui->cbPort->findText(pPortName);
|
||||||
|
if (idx > -1) ui->cbPort->setCurrentIndex(idx);
|
||||||
|
else ui->cbPort->addItem(pPortName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {}
|
default: {}
|
||||||
@@ -440,9 +464,8 @@ QString ConnectionWindow::getPortName()
|
|||||||
switch( getConnectionType() ) {
|
switch( getConnectionType() ) {
|
||||||
case CANCon::GVRET_SERIAL:
|
case CANCon::GVRET_SERIAL:
|
||||||
case CANCon::SERIALBUS:
|
case CANCon::SERIALBUS:
|
||||||
return ui->cbPort->currentText();
|
|
||||||
case CANCon::REMOTE:
|
case CANCon::REMOTE:
|
||||||
return ui->lePort->text();
|
return ui->cbPort->currentText();
|
||||||
default:
|
default:
|
||||||
qDebug() << "getPortName: can't get port";
|
qDebug() << "getPortName: can't get port";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QItemSelection>
|
#include <QItemSelection>
|
||||||
#include <QCanBusDeviceInfo>
|
#include <QCanBusDeviceInfo>
|
||||||
|
#include <QUdpSocket>
|
||||||
#include "canconnectionmodel.h"
|
#include "canconnectionmodel.h"
|
||||||
#include "connections/canconnection.h"
|
#include "connections/canconnection.h"
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ private slots:
|
|||||||
void handleSendHex();
|
void handleSendHex();
|
||||||
void handleSendText();
|
void handleSendText();
|
||||||
void connectionStatus(CANConStatus);
|
void connectionStatus(CANConStatus);
|
||||||
|
void readPendingDatagrams();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConnectionWindow *ui;
|
Ui::ConnectionWindow *ui;
|
||||||
@@ -68,6 +70,8 @@ private:
|
|||||||
QList<QCanBusDeviceInfo> canDevices;
|
QList<QCanBusDeviceInfo> canDevices;
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
CANConnectionModel *connModel;
|
CANConnectionModel *connModel;
|
||||||
|
QUdpSocket *rxBroadcast;
|
||||||
|
QVector<QString> remoteDeviceIP;
|
||||||
|
|
||||||
void selectSerial();
|
void selectSerial();
|
||||||
void selectKvaser();
|
void selectKvaser();
|
||||||
|
|||||||
@@ -152,7 +152,7 @@
|
|||||||
<enum>Qt::LeftToRight</enum>
|
<enum>Qt::LeftToRight</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="cbPage">
|
<widget class="QWidget" name="cbPage">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -179,6 +179,9 @@
|
|||||||
<height>16777215</height>
|
<height>16777215</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
Reference in New Issue
Block a user