Allow hostname or ip address for radio.

merge-requests/1/head
Phil Taylor 2021-02-07 18:46:47 +00:00
rodzic 3fe60decea
commit 33821e0515
3 zmienionych plików z 26 dodań i 7 usunięć

Wyświetl plik

@ -83,7 +83,7 @@ void rigCommander::commSetup(unsigned char rigCivAddr, QString ip, int cport, in
this->username = username;
this->password = password;
if (udp == Q_NULLPTR) {
udp = new udpHandler(QHostAddress(ip), cport, sport, aport, username, password);
udp = new udpHandler(ip, cport, sport, aport, username, password);
connect(udp, SIGNAL(haveDataFromPort(QByteArray)), this, SLOT(handleNewData(QByteArray)));
// data from the program to the comm port:

Wyświetl plik

@ -4,28 +4,47 @@
#include "udphandler.h"
udpHandler::udpHandler(QHostAddress ip, int cport, int sport, int aport,QString username, QString password)
udpHandler::udpHandler(QString ip, int cport, int sport, int aport, QString username, QString password)
{
qDebug() << "Starting udpHandler";
radioIP = ip;
// Lookup IP address
this->port = cport;
this->aport = aport;
this->sport = sport;
this->username = username;
this->password = password;
// Try to set the IP address, if it is a hostname then perform a DNS lookup.
if (!radioIP.setAddress(ip))
{
QHostInfo remote = QHostInfo::fromName(ip);
if (remote.addresses().length() > 0)
{
radioIP = remote.addresses().first();
qDebug() << "Got IP Address for " << ip << " " << radioIP.toString();
}
else
{
qDebug() << ip << ": " << remote.errorString();
return;
}
}
// Convoluted way to find the external IP address, there must be a better way????
QString localhostname = QHostInfo::localHostName();
QList<QHostAddress> hostList = QHostInfo::fromName(localhostname).addresses();
foreach(const QHostAddress & address, hostList)
foreach(const QHostAddress & address, hostList)
{
if (address.protocol() == QAbstractSocket::IPv4Protocol && address.isLoopback() == false)
if (address.protocol() == QAbstractSocket::IPv4Protocol && address.isLoopback() == false)
{
localIP = QHostAddress(address.toString());
}
}
init(); // Perform connection
QUdpSocket::connect(udp, &QUdpSocket::readyRead, this, &udpHandler::DataReceived);
@ -649,8 +668,8 @@ void udpBase::init()
udpBase::~udpBase()
{
qDebug() << "Closing UDP stream :" << radioIP.toString() << ":" << port;
SendPacketDisconnect();
if (udp != Q_NULLPTR) {
SendPacketDisconnect();
udp->close();
delete udp;
}

Wyświetl plik

@ -138,7 +138,7 @@ class udpHandler: public udpBase
Q_OBJECT
public:
udpHandler(QHostAddress ip, int cport, int sport, int aport, QString username, QString password);
udpHandler(QString ip, int cport, int sport, int aport, QString username, QString password);
~udpHandler();
udpSerial *serial=Q_NULLPTR;