diff --git a/src/Core.cc b/src/Core.cc index 7035d08c815bdc147efdf64e8a0567461087945f..d63bd0d919bda5645fbcd3f87a9e27aac3a393a5 100644 --- a/src/Core.cc +++ b/src/Core.cc @@ -114,6 +114,9 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv) // to make sure that all components are initialized when the // first messages arrive UDPLink* udpLink = new UDPLink(QHostAddress::Any, 14550); + // Listen on Multicast-Address 239.255.77.77, Port 14550 + //QHostAddress * multicast_udp = new QHostAddress("239.255.77.77"); + //UDPLink* udpLink = new UDPLink(*multicast_udp, 14550); mainWindow->addLink(udpLink); // Check if link could be connected diff --git a/src/comm/UDPLink.cc b/src/comm/UDPLink.cc index ebd768ec87059ab6d1389ec3d8f16f8cc69b341b..d0f6d1623dcc3166c376e5d34bf81da1b6259d6e 100644 --- a/src/comm/UDPLink.cc +++ b/src/comm/UDPLink.cc @@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project #include "UDPLink.h" #include "LinkManager.h" #include "MG.h" +#include UDPLink::UDPLink(QHostAddress host, quint16 port) { @@ -197,11 +198,46 @@ bool UDPLink::connect() { socket = new QUdpSocket(this); + //Check if we are using a multicast-address +// bool multicast = false; +// if (host.isInSubnet(QHostAddress("224.0.0.0"),4)) +// { +// multicast = true; +// connectState = socket->bind(port, QUdpSocket::ShareAddress); +// } +// else +// { + connectState = socket->bind(host, port); +// } + + //Provides Multicast functionality to UdpSocket + /* not working yet + if (multicast) + { + int sendingFd = socket->socketDescriptor(); + + if (sendingFd != -1) + { + // set up destination address + struct sockaddr_in sendAddr; + memset(&sendAddr,0,sizeof(sendAddr)); + sendAddr.sin_family=AF_INET; + sendAddr.sin_addr.s_addr=inet_addr(HELLO_GROUP); + sendAddr.sin_port=htons(port); + + // set TTL + unsigned int ttl = 1; // restricted to the same subnet + if (setsockopt(sendingFd, IPPROTO_IP, IP_MULTICAST_TTL, (unsigned int*)&ttl, sizeof(ttl) ) < 0) + { + std::cout << "TTL failed\n"; + } + } + } + */ + //QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); - connectState = socket->bind(host, port); - emit connected(connectState); if (connectState) { diff --git a/src/comm/UDPLink.h b/src/comm/UDPLink.h index 6682aae0009792707992105c639b91e1395b865a..fb1eb079c09cfbc57c209ebfe89c5f873cf4117e 100644 --- a/src/comm/UDPLink.h +++ b/src/comm/UDPLink.h @@ -46,6 +46,7 @@ class UDPLink : public LinkInterface public: UDPLink(QHostAddress host = QHostAddress::Any, quint16 port = 14550); + //UDPLink(QHostAddress host = "239.255.76.67", quint16 port = 7667); ~UDPLink(); bool isConnected();