use seperate sockets for rx and tx
This commit is contained in:
parent
fe8bc039bc
commit
1f57ef1029
|
@ -14,11 +14,14 @@
|
||||||
*/
|
*/
|
||||||
QSacnNode::QSacnNode(QObject *parent, QUuid cid, QString fctn, bool ipv4, bool ipv6)
|
QSacnNode::QSacnNode(QObject *parent, QUuid cid, QString fctn, bool ipv4, bool ipv6)
|
||||||
: Component(UUID::uuid(cid.toString().toStdString()), fctn.toStdString(), ipv4, ipv6)
|
: Component(UUID::uuid(cid.toString().toStdString()), fctn.toStdString(), ipv4, ipv6)
|
||||||
, QUdpSocket(parent)
|
, QObject(parent)
|
||||||
|
, rx_socket_(new QUdpSocket(this))
|
||||||
|
, tx_socket_(new QUdpSocket(this))
|
||||||
{
|
{
|
||||||
bind(QHostAddress::AnyIPv4, sACN::ACN_SDT_MULTICAST_PORT);
|
rx_socket_->bind(QHostAddress::AnyIPv4, sACN::ACN_SDT_MULTICAST_PORT);
|
||||||
|
tx_socket_->bind(QHostAddress::AnyIPv4);
|
||||||
|
|
||||||
connect(this, &QUdpSocket::readyRead,
|
connect(rx_socket_, &QUdpSocket::readyRead,
|
||||||
this, &QSacnNode::udpReceive);
|
this, &QSacnNode::udpReceive);
|
||||||
|
|
||||||
sACN::Receiver::onDiscovered([this](){ emit discoveryUpdates(); });
|
sACN::Receiver::onDiscovered([this](){ emit discoveryUpdates(); });
|
||||||
|
@ -58,7 +61,7 @@ void QSacnNode::setIPv4(const bool enable)
|
||||||
{
|
{
|
||||||
qDebug() << "Joining IGMP Group" << ip.toString();
|
qDebug() << "Joining IGMP Group" << ip.toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
joinMulticastGroup(ip, iface);
|
rx_socket_->joinMulticastGroup(ip, iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -68,7 +71,7 @@ void QSacnNode::setIPv4(const bool enable)
|
||||||
{
|
{
|
||||||
qDebug() << "Leaving IGMP Group" << ip.toString();
|
qDebug() << "Leaving IGMP Group" << ip.toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
leaveMulticastGroup(ip, iface);
|
rx_socket_->leaveMulticastGroup(ip, iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +94,7 @@ void QSacnNode::setIPv6(const bool enable)
|
||||||
{
|
{
|
||||||
qDebug() << "Joining MLD Group" << ip.toString();
|
qDebug() << "Joining MLD Group" << ip.toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
joinMulticastGroup(ip, iface);
|
rx_socket_->joinMulticastGroup(ip, iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -101,7 +104,7 @@ void QSacnNode::setIPv6(const bool enable)
|
||||||
{
|
{
|
||||||
qDebug() << "Leaving MLD Group" << ip.toString();
|
qDebug() << "Leaving MLD Group" << ip.toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
leaveMulticastGroup(ip, iface);
|
rx_socket_->leaveMulticastGroup(ip, iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,13 +141,13 @@ void QSacnNode::subscribe(const uint16_t num)
|
||||||
{
|
{
|
||||||
qDebug() << "Joining IGMP Group" << IPv4MulticastAddress(num).toString();
|
qDebug() << "Joining IGMP Group" << IPv4MulticastAddress(num).toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
joinMulticastGroup(IPv4MulticastAddress(num), iface);
|
rx_socket_->joinMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||||
}
|
}
|
||||||
if (enable_IPv6)
|
if (enable_IPv6)
|
||||||
{
|
{
|
||||||
qDebug() << "Joining MLD Group" << IPv6MulticastAddress(num).toString();
|
qDebug() << "Joining MLD Group" << IPv6MulticastAddress(num).toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
joinMulticastGroup(IPv6MulticastAddress(num), iface);
|
rx_socket_->joinMulticastGroup(IPv6MulticastAddress(num), iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,13 +182,13 @@ void QSacnNode::unsubscribe(const uint16_t num)
|
||||||
{
|
{
|
||||||
qDebug() << "Leaving IGMP Group" << IPv4MulticastAddress(num).toString();
|
qDebug() << "Leaving IGMP Group" << IPv4MulticastAddress(num).toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
leaveMulticastGroup(IPv4MulticastAddress(num), iface);
|
rx_socket_->leaveMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||||
}
|
}
|
||||||
if (enable_IPv6)
|
if (enable_IPv6)
|
||||||
{
|
{
|
||||||
qDebug() << "Leaving MLD Group" << IPv6MulticastAddress(num).toString();
|
qDebug() << "Leaving MLD Group" << IPv6MulticastAddress(num).toString();
|
||||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||||
leaveMulticastGroup(IPv6MulticastAddress(num), iface);
|
rx_socket_->leaveMulticastGroup(IPv6MulticastAddress(num), iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,9 +229,9 @@ void QSacnNode::terminate(const uint16_t num)
|
||||||
*/
|
*/
|
||||||
void QSacnNode::udpReceive()
|
void QSacnNode::udpReceive()
|
||||||
{
|
{
|
||||||
while (hasPendingDatagrams())
|
while (rx_socket_->hasPendingDatagrams())
|
||||||
{
|
{
|
||||||
auto datagram = receiveDatagram();
|
auto datagram = rx_socket_->receiveDatagram();
|
||||||
|
|
||||||
// expecting IANA registered Session Data Transport traffic
|
// expecting IANA registered Session Data Transport traffic
|
||||||
if (datagram.destinationPort() != sACN::ACN_SDT_MULTICAST_PORT)
|
if (datagram.destinationPort() != sACN::ACN_SDT_MULTICAST_PORT)
|
||||||
|
@ -236,11 +239,11 @@ void QSacnNode::udpReceive()
|
||||||
|
|
||||||
// only receive over configured protocols
|
// only receive over configured protocols
|
||||||
switch (datagram.senderAddress().protocol()) {
|
switch (datagram.senderAddress().protocol()) {
|
||||||
case IPv4Protocol:
|
case QUdpSocket::IPv4Protocol:
|
||||||
if (!enable_IPv4)
|
if (!enable_IPv4)
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case IPv6Protocol:
|
case QUdpSocket::IPv6Protocol:
|
||||||
if (!enable_IPv6)
|
if (!enable_IPv6)
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
@ -263,7 +266,7 @@ void QSacnNode::udpReceive()
|
||||||
* @param ip
|
* @param ip
|
||||||
*/
|
*/
|
||||||
void QSacnNode::sendUDP(const ACN::PDU::Stream stream,
|
void QSacnNode::sendUDP(const ACN::PDU::Stream stream,
|
||||||
const ACN::SDT::UDP::ipAddress& ip)
|
const ACN::SDT::UDP::ipAddress& ip) const
|
||||||
{
|
{
|
||||||
QHostAddress addr;
|
QHostAddress addr;
|
||||||
switch (ip.type) {
|
switch (ip.type) {
|
||||||
|
@ -281,7 +284,7 @@ void QSacnNode::sendUDP(const ACN::PDU::Stream stream,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeDatagram(reinterpret_cast<char*>(stream->base()), stream->size(), addr, ip.port);
|
tx_socket_->writeDatagram(reinterpret_cast<char*>(stream->base()), stream->size(), addr, ip.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,7 +294,7 @@ void QSacnNode::sendUDP(const ACN::PDU::Stream stream,
|
||||||
* @param ip
|
* @param ip
|
||||||
*/
|
*/
|
||||||
void QSacnNode::sendTCP(const ACN::PDU::Stream stream,
|
void QSacnNode::sendTCP(const ACN::PDU::Stream stream,
|
||||||
const ACN::SDT::UDP::ipAddress& ip)
|
const ACN::SDT::UDP::ipAddress& ip) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(stream)
|
Q_UNUSED(stream)
|
||||||
Q_UNUSED(ip)
|
Q_UNUSED(ip)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* @brief The QSacnNode class
|
* @brief The QSacnNode class
|
||||||
*/
|
*/
|
||||||
class QT_EXPORT QSacnNode
|
class QT_EXPORT QSacnNode
|
||||||
: public QUdpSocket
|
: public QObject
|
||||||
, public sACN::Node
|
, public sACN::Node
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -26,8 +26,8 @@ public:
|
||||||
~QSacnNode();
|
~QSacnNode();
|
||||||
|
|
||||||
// sACN::RLP::Component
|
// sACN::RLP::Component
|
||||||
void sendUDP(const ACN::PDU::Stream, const ACN::SDT::UDP::ipAddress&) override;
|
void sendUDP(const ACN::PDU::Stream, const ACN::SDT::UDP::ipAddress&) const override;
|
||||||
void sendTCP(const ACN::PDU::Stream, const ACN::SDT::UDP::ipAddress&) override;
|
void sendTCP(const ACN::PDU::Stream, const ACN::SDT::UDP::ipAddress&) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setIPv4(const bool) override;
|
void setIPv4(const bool) override;
|
||||||
|
@ -46,6 +46,8 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void udpReceive();
|
void udpReceive();
|
||||||
|
QUdpSocket * rx_socket_;
|
||||||
|
QUdpSocket * tx_socket_;
|
||||||
|
|
||||||
QHash<uint16_t, QSacnUniverse*> rx_universes;
|
QHash<uint16_t, QSacnUniverse*> rx_universes;
|
||||||
QHash<uint16_t, QSacnUniverse*> tx_universes;
|
QHash<uint16_t, QSacnUniverse*> tx_universes;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user