be aware of enabled RLP communications protocols
This commit is contained in:
parent
52cdef90dd
commit
617b082f96
|
@ -12,8 +12,8 @@
|
|||
* @param cid
|
||||
* @param fctn
|
||||
*/
|
||||
QSacnNode::QSacnNode(QObject *parent, QUuid cid, QString fctn)
|
||||
: Component(UUID::uuid(cid.toString().toStdString()), fctn.toStdString())
|
||||
QSacnNode::QSacnNode(QObject *parent, QUuid cid, QString fctn, bool ipv4, bool ipv6)
|
||||
: Component(UUID::uuid(cid.toString().toStdString()), fctn.toStdString(), ipv4, ipv6)
|
||||
, QUdpSocket(parent)
|
||||
{
|
||||
bind(QHostAddress::AnyIPv4, sACN::ACN_SDT_MULTICAST_PORT);
|
||||
|
@ -43,6 +43,72 @@ QSacnNode::~QSacnNode()
|
|||
}
|
||||
|
||||
|
||||
void QSacnNode::setIPv4(const bool enable)
|
||||
{
|
||||
Node::setIPv4(enable);
|
||||
|
||||
QList<QHostAddress> groups;
|
||||
foreach (const auto & universe, rx_universes)
|
||||
groups.append(IPv4MulticastAddress(universe->number()));
|
||||
if (discoveryEnabled())
|
||||
groups.append(IPv4MulticastAddress(sACN::E131_DISCOVERY_UNIVERSE));
|
||||
|
||||
if (enable)
|
||||
{
|
||||
qDebug() << "Enabling IPv4";
|
||||
foreach (const auto & ip, groups)
|
||||
{
|
||||
qDebug() << "Joining IGMP Group" << ip.toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(ip, iface);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Disabling IPv4";
|
||||
foreach (const auto & ip, groups)
|
||||
{
|
||||
qDebug() << "Leaving IGMP Group" << ip.toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
leaveMulticastGroup(ip, iface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QSacnNode::setIPv6(const bool enable)
|
||||
{
|
||||
Node::setIPv6(enable);
|
||||
|
||||
QList<QHostAddress> groups;
|
||||
foreach (const auto & universe, rx_universes)
|
||||
groups.append(IPv6MulticastAddress(universe->number()));
|
||||
if (discoveryEnabled())
|
||||
groups.append(IPv6MulticastAddress(sACN::E131_DISCOVERY_UNIVERSE));
|
||||
|
||||
if (enable)
|
||||
{
|
||||
qDebug() << "Enabling IPv6";
|
||||
foreach (const auto & ip, groups)
|
||||
{
|
||||
qDebug() << "Joining MLD Group" << ip.toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(ip, iface);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Disabling IPv6";
|
||||
foreach (const auto & ip, groups)
|
||||
{
|
||||
qDebug() << "Leaving MLD Group" << ip.toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
leaveMulticastGroup(ip, iface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief QSacnNode::subscribe
|
||||
* @param num
|
||||
|
@ -70,12 +136,18 @@ void QSacnNode::subscribe(const uint16_t num)
|
|||
break;
|
||||
}
|
||||
|
||||
qDebug() << "Joining IGMP Group" << IPv4MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||
qDebug() << "Joining MLD Group" << IPv6MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(IPv6MulticastAddress(num), iface);
|
||||
if (enable_IPv4)
|
||||
{
|
||||
qDebug() << "Joining IGMP Group" << IPv4MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||
}
|
||||
if (enable_IPv6)
|
||||
{
|
||||
qDebug() << "Joining MLD Group" << IPv6MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(IPv6MulticastAddress(num), iface);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,12 +177,18 @@ void QSacnNode::unsubscribe(const uint16_t num)
|
|||
break;
|
||||
}
|
||||
|
||||
qDebug() << "Leaving IGMP Group" << IPv4MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
leaveMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||
qDebug() << "Leaving MLD Group" << IPv6MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
leaveMulticastGroup(IPv6MulticastAddress(num), iface);
|
||||
if (enable_IPv4)
|
||||
{
|
||||
qDebug() << "Leaving IGMP Group" << IPv4MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
leaveMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||
}
|
||||
if (enable_IPv6)
|
||||
{
|
||||
qDebug() << "Leaving MLD Group" << IPv6MulticastAddress(num).toString();
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
leaveMulticastGroup(IPv6MulticastAddress(num), iface);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -154,6 +232,19 @@ void QSacnNode::udpReceive()
|
|||
if (datagram.destinationPort() != sACN::ACN_SDT_MULTICAST_PORT)
|
||||
return;
|
||||
|
||||
switch (datagram.senderAddress().protocol()) {
|
||||
case QAbstractSocket::IPv4Protocol:
|
||||
if (!enable_IPv4)
|
||||
return;
|
||||
break;
|
||||
case QAbstractSocket::IPv6Protocol:
|
||||
if (!enable_IPv6)
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// wrap a PDU io stream around the QNetworkDatagram data buffer
|
||||
auto stream = std::make_shared<ACN::PDU::pdu_stream>(
|
||||
reinterpret_cast<uint8_t*>(datagram.data().data()),
|
||||
|
@ -174,9 +265,13 @@ void QSacnNode::sendUDP(const ACN::PDU::Stream stream,
|
|||
QHostAddress addr;
|
||||
switch (ip.type) {
|
||||
case ACN::SDT::SDT_ADDR_IPV4:
|
||||
if (!enable_IPv4)
|
||||
return;
|
||||
addr = QHostAddress(ip.address.ipv4.value);
|
||||
break;
|
||||
case ACN::SDT::SDT_ADDR_IPV6:
|
||||
if (!enable_IPv6)
|
||||
return;
|
||||
addr = QHostAddress(ip.address.ipv6.bytes);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -21,7 +21,8 @@ class QT_EXPORT QSacnNode
|
|||
|
||||
public:
|
||||
explicit QSacnNode(QObject *parent = nullptr,
|
||||
QUuid = QUuid::createUuid(), QString fctn = "OpenLCP QSacnNode");
|
||||
QUuid = QUuid::createUuid(), QString fctn = "OpenLCP QSacnNode",
|
||||
bool ipv4 = true, bool ipv6 = true);
|
||||
~QSacnNode();
|
||||
|
||||
// sACN::RLP::Component
|
||||
|
@ -32,6 +33,8 @@ public:
|
|||
QSacnUniverse* source(const uint16_t u);
|
||||
|
||||
public slots:
|
||||
void setIPv4(const bool) override;
|
||||
void setIPv6(const bool) override;
|
||||
void subscribe(const uint16_t) override;
|
||||
void unsubscribe(const uint16_t) override;
|
||||
void create(const uint16_t) override;
|
||||
|
|
Loading…
Reference in New Issue